Skip to content

Instantly share code, notes, and snippets.

View nepsilon's full-sized avatar

James Pudson nepsilon

View GitHub Profile
@nepsilon
nepsilon / how-to-use-mac-keychain-to-store-github-repos-credentials.md
Created July 18, 2017 06:50
How to use Mac KeyChain to store GitHub repos credentials? — First published in fullweb.io issue #108

How to use Mac KeyChain to store GitHub repos credentials?

You know the pain, you cloned a repo over HTTPS, and now Git asks you for your password each time you want to push or pull.

Chances are you already have the git credential-osxkeychain command installed. If not, just install Git with brew: brew install git.

Once installed, just tell Git to use the KeyChain to store your credentials:

git config --global credential.helper osxkeychain
@nepsilon
nepsilon / how-to-output-a-range-of-lines-from-a-file.md
Created July 12, 2017 04:56
How to output a range of lines from a file? — First published in fullweb.io issue #107

How to output a range of lines from a file?

Easy enough with sed:

sed -n	123,230p filename

This will output filename content, from line 123 to line 230, inclusives. Notice the p letter after the last line number, this is what instruct sed to print to stdout.

@nepsilon
nepsilon / how-and-why-to-sign-your-commits-with-gpg.md
Last active June 30, 2017 22:21
How and why to sign your commits with GPG? — First published in fullweb.io issue #105

How and why to sign your commits with GPG?

When a team signs their commits, it’s easy to verify the commits are actually from the team members.

If you don’t have a GPG key yet, generate one with gpg --gen-key. Enter the info at the prompt, and then type gpg --list-secret-keys --keyid-format LONG to view your key info. At the line starting with sec, the string between the / and the space is your PUBLIC_KEY_ID. Note it down, and add run the following command to instruct git to use it:

git config user.signingkey PUBLIC_KEY_ID
git config gpg.program gpg
git config commit.gpgsign true
@nepsilon
nepsilon / how-to-kill-a-frozen-ssh-session.md
Last active March 12, 2024 09:44
How to kill a frozen SSH session? — First published in fullweb.io issue #104

How to kill a frozen SSH session?

No need to close your terminal tab anymore (or furiously hitting your keyboard) when your SSH session frozen. SSH has an escape sequence that will let you properly close the connection and give you back the prompt. In order, type: Return, ~, .

That’s it! This will send an escape sequence to your local SSH socket and close the connection.

SSH has more escape sequences under the hood, hit Return ~ ? to display the full list:

@nepsilon
nepsilon / how-to-track-large-files-in-git.md
Created June 6, 2017 10:54
How to track large files (database, PSD, bin) in Git? — First published in fullweb.io issue #103

How to track large files (database, PSD, bin) in Git?

Sometimes you have PSD or a small-ish SQLite file you’d like to track with Git. The problem is Git is bad at tracking changes in big binary files by default. With Git Large File Storage (LFS) you can replace these large files with text pointers while storing the file contents on a remote server. Both GitHub and BitBucket support it. Here is how to get started:

1. Install Git LFS extension (Mac here):

brew install git-lfs
@nepsilon
nepsilon / how-to-preserve-user-environment-when-using-sudo.md
Last active June 2, 2017 07:58
How to preserve user environment when using sudo? — First published in fullweb.io issue #102

How to preserve user environment when using sudo?

By Fabien Loudet, Senior SysOps at Rosetta Stone

Say you want to execute a command with elevated privileges (root), but also want to keep your environment variables (HTTP_PROXY for instance).

sudo offers this feature through its -E option, from the manpage:

-E   The -E (preserve environment) option indicates to the 
 security policy that the user wishes to preserve their
@nepsilon
nepsilon / how-to-secure-your-site-with-https.md
Last active August 9, 2018 11:19
How to secure your site with HTTPS? — First published in fullweb.io issue #101

How to secure your site with HTTPS?

With HTTP everything is visible when traveling on the Internet. By generating an SSL certificate and configuring your webserver you can force browsers to use HTTPS. Here is how to proceed:

# 1. Install letsencrypt
sudo pip install letsencrypt
@nepsilon
nepsilon / how-to-prevent-accidental-shutdowns-and-reboots.md
Created May 11, 2017 01:39
How to prevent accidental shutdowns and reboots? — First published in fullweb.io issue #99

How to prevent accidental shutdowns and reboots?

By Fabien Loudet, Senior SysOps at Rosetta Stone

Debian based distributions offers a package named molly-guard. It is a utility preventing yourself to accidentally reboot or shutdown the wrong system.

Once installed, it will override the existing shutdown, reboot, halt and poweroff commands by asking you to type the hostname of the machine, in order to confirm that it is really what you intended to do.

$ sudo reboot
W: molly-guard: SSH session detected!
@nepsilon
nepsilon / how-to-create-a-read-only-user-for-your-database.md
Last active March 20, 2019 10:31
How to create a read-only user for your database? — First published in fullweb.io issue #97

How to create a read-only user for your database?

If your app is about searching (business directories, dictionaries, etc) or a catalog of browsable items, it’s always a good idea to let your API use a read-only database user. Another use case would be for doing backups, no write permissions needed either.

Here is how to do that for PostgreSQL v9.0+ (syntax quasi-similar for MySQL):

-- Say we just created the user "pouet"

-- Allow the user to CONNECT
GRANT CONNECT ON DATABASE mydb TO pouet;
@nepsilon
nepsilon / how-to-edit-data-inside-a-pipe.md
Created April 25, 2017 14:16
How to edit data inside a pipe? — First published in fullweb.io issue #97

How to edit data inside a pipe?

Recommended by Fabien Loudet, Senior SysOps at Rosetta Stone

The vipe program from the moreutils package allows to "insert a text editor into a pipe". That is, run your EDITOR in the middle of a unix pipeline and edit the data that is piped.

command1 | vipe | command2