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-git-patch-diff.md
Last active July 24, 2025 12:15
How to generate and apply patches with git? — First published in fullweb.io issue #33

How to generate and apply patches with git?

It sometimes happen you need change code on a machine from which you cannot push to the repo. You’re ready to copy/paste what diff outputs to your local working copy.

You think there must be a better way to proceed and you’re right. It’s a simple 2 steps process:

1. Generate the patch:

git diff > some-changes.patch
@nepsilon
nepsilon / how-to-list-ssh-tunnel.md
Last active May 22, 2023 16:10
How to list open SSH tunnels — First published in fullweb.io issue #34

How to list open SSH tunnels?

Very often a database in production only accept connections from localhost, and we resort to use SSH tunneling to access it remotely. While tunnels are running in the background and we connect to the database on localhost, we need to know if we’re really talking to our localhost or to the remote machine.

List all open SSH tunnels with:

sudo lsof -i -n | grep ssh
@nepsilon
nepsilon / how-to-debug-python-pdb.md
Last active July 8, 2016 06:12
How to debug Python programs? — First published in fullweb.io issue #35

How to debug Python programs?

When we can’t understand the execution path or behaviour of our program we better use a debugger. Python offers pdb, a full featured debugger. Here is how to get started.

Import it with:

import pdb 
@nepsilon
nepsilon / how-to-bash-batch-rename.md
Last active July 7, 2016 06:15
How to batch rename files with bash? — First published in fullweb.io issue #36

How to batch rename files with bash?

Let’s say we have these files:

ls 
to_be_renamed_1.txt 
to_be_renamed_2.txt 
to_be_renamed_3.txt 
@nepsilon
nepsilon / how-to-detach-process.md
Last active October 3, 2023 09:59
How to detach a process from the current terminal? — First published in fullweb.io issue #37

How to detach a process from the current terminal?

Closing the terminal will kill all processes launched from its shell instance that are still running. Here is how to detach a running process and run+detach a new process:

Scenario 1:

Let’s say we have ./long.sh running, and we want to detach it:

./long.sh
@nepsilon
nepsilon / 3-postgres-tips.md
Last active February 19, 2017 13:19
3 tips for a better PostgreSQL usage — First published in fullweb.io issue #38

3 tips for a better PostgreSQL usage

We’ll see how to write queries in your editor, format output based on content and how to get info on everything.

1. Use your editor to write queries:

Tell the terminal what editory to use with from your bash shell export EDITOR=subl, then in psql type:

psql> \e
@nepsilon
nepsilon / custom-ssh-banner.md
Last active December 22, 2018 17:50
Display a cool banner when you log in with SSH — First published in fullweb.io issue #39

Display a cool banner when you log in with SSH

SSH gives us a way to displaya custom welcome message when a user log in. You can make this message dynamic thanks to update-motd, but here we’ll talk about the SSH built-in feature.

Here is how to do in 3 steps:

Put your message in /etc/issue.net:

$ vim /etc/issue.net
@nepsilon
nepsilon / postgresql-no-password.md
Last active July 7, 2016 05:49
PostgreSQL password-less authentication — First published in fullweb.io issue #40

PostgreSQL password-less authentication

Contributed by Fabien Loudet, Linux SysAdmin at Rosetta Stone

The format to use for each line in the file:

hostname:port:database:username:password

Only the owner of the file should have read and write access to it:

@nepsilon
nepsilon / fuzzy-search-postgres.md
Last active December 13, 2023 14:16
PostgreSQL: Native fuzzy search with levenshtein() — First published in fullweb.io issue #41

PostgreSQL: Fuzzy search with levenshtein()

Ever wanted to implement a “Did you mean?” feature in your search results? Google is said to have greatly increased its user engagement with it. Here is how to implement it simply in Postgres (v9.1+):

Install the extension:

CREATE EXTENSION fuzzystrmatch;
#!/bin/bash
#
# When you are working on your macbook sitting in cafe and you have to go pee,
# you need some way to guard you machine.
#
# Start this script, remove any earphones, and go do the job.
# The assumption is the thief will close the lid of the laptop before taking it away.
# This script detects the closing of the lid and plays some loud audio that will
# likely distract the thief and/or grab attention of nearby people, making the