Handy Snippets

Count number of lines in a file in terminal

To check the number of LINES in a file (robots.txt in the following example), run the following command in your terminal.

wc -l robots.txt

# 15 robots.txt
This will return the number of lines in the file robot.txt along with the filename. Useful probably for checking length of CSVs or similar.

Force HTTPS for all the URLs in Laravel

Here’s how you can do it using the URL::forceHttps() method. Set this in your app’s boot() method of the service provider.

use Illuminate\Support\Facades\URL;

URL::forceHttps(app()->isProduction());

Temporarily disable timestamps in Laravel

Here’s how you can temporarily disable timestamps (created_at and updated_at fieldss) in Laravel.

$post = Post::find(1);
$post->timestamps = false;
$post->title = 'New Title';
$post->save();

Enable design mode on the document

Just run the following command in the console and you’ll be able to edit the webpage you’re on.

document.designMode = 'on'