Handy Snippets

A collection of useful bits that I use in my everyday life

Inspect disappearing elements in Chrome

There are times when you want to inspect elements that only appear when you hover over them. For instance, tooltips or inputs which gets hidden on focus out or blur. It’s difficult to inspect them due to this behaviour.

Thankfully in Chrome, this can be circumvented using an option called “Emulate a focused page” in Dev Tools.

Open Dev Tools, press Ctrl / Cmd + Shift + P, and toggle this option. You should be able to inspect the disappearing elements now.

How to run un-notarized macOS apps

If you are trying to run an un-notarized macOS app and you are getting the error message “App can’t be opened because it is from an unidentified developer”, you can run the following simple command in the terminal to allow the app to run.

xattr -dr com.apple.quarantine /Applications/Dinky.app

Replace /Applications/Dinky.app with the path to the app you are trying to run. This command removes the quarantine attribute from the app and allows it to run without any issues.

Prevent Git from tracking file permissions

Here’s one of the most useful commands if you want to prevent Git from tracking file permissions. This is the sceanrio where all the files shown as modified in Git is when you change the file permissions, but you don’t want to commit those changes.

git config core.fileMode false

This is especially useful when you have to deal with changing file permissions for your projects frequently.

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'