Skip to content

Instantly share code, notes, and snippets.

View nepsilon's full-sized avatar

James Pudson nepsilon

View GitHub Profile
@nepsilon
nepsilon / simple-cache-busting-with-nginx.md
Created September 20, 2016 03:39
Simple cache busting with Nginx — First published in fullweb.io issue #66

Simple cache busting with Nginx

You update your app.js or styles.css, but have a caching of 30 days and none of the clients will get the latest version? 😟

While the best would be to use a build mechanism to generate new filenames on the server, here is how to ensure clients get your last updates:

1. Change the name of the files in the HTML, for example styles.css to styles.123.css

2. Add this cache busting snippet in your nginx conf:

@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 / bash-remove-spaces-in-filename.md
Last active March 9, 2023 12:30
How to remove spaces in filenames and lowercasing — First published in fullweb.io issue #20

How to remove spaces in filename and lowercasing

A short script this week to replace spaces in filenames in a given folder:

# Looping over files, forging new filename, and then renaming it.
# Spaces will be replaced by underscores (_).
for oldname in * 
do 
 newname=`echo $oldname | sed -e 's/ /_/g'` 
@nepsilon
nepsilon / postgres-import-export-csv.md
Last active September 23, 2022 14:57
Importing and Exporting CSV files with PostgreSQL — First published in fullweb.io issue #19

Importing and exporting CSV files with PostgreSQL

Let’s see how to use PostgreSQL to import and export CSV files painlessly with the COPY command.

Import CSV into table t_words:

COPY t_words FROM '/path/to/file.csv' DELIMITER ',' CSV;

You can tell quote char with QUOTE and change delimiter with DELIMITER.

@nepsilon
nepsilon / email-address-syntax-validation-let-the-browser-do-it.md
Last active August 14, 2022 18:34
Email address syntax validation? Let the browser do it (without regexp) — First published in fullweb.io issue #77

Email address syntax validation? Let the browser do it (without regexp)

Here is a simple and robust way to check for the validity of an email address syntax directly in the browser. No need for crazy regular expressions.

e = document.createElement('input')
e.type = 'email'
// check some email addresses
e.value = 'hi@'
@nepsilon
nepsilon / where-to-find-changes-due-to-git-fetch.md
Created December 12, 2016 10:14
Where to find changes due to git fetch — First published in fullweb.io issue #78

Where to find changes due to git fetch

fetch is useful to pull changes from an upstream repo to merge some changes. By default git fetch upstream will update or create all the remote branches locally.

Say you have upstream/master tracked by your local master branch. Here is how to see the changes between both:

git log master..upstream/master
@nepsilon
nepsilon / using-auto-backup-vim.md
Last active February 24, 2022 15:21
Using auto backup with Vim — First published in fullweb.io issue #3

Using auto backup with Vim

Not using versioning on your configuration files and editing them with Vim? Use Vim’s backup option to automatically keep a copy of past versions:

To put in your ~/.vimrc:

"Turn on backup option
set backup
@nepsilon
nepsilon / python-how-to-print-the-full-traceback-without-exiting-the-program.md
Created January 3, 2017 06:24
Python: How to print the full traceback without exiting the program? — First published in fullweb.io issue #81

Python: How to print the full traceback without exiting the program?

The exception handling block except Exception as ex: print(ex) will only print the exception message and not its traceback.

That’s good to know, but we need more info than this to debug properly. Namely the line that raised the exception, together with its stack trace.

The traceback module, part of the stdlib, will help us with this:

@nepsilon
nepsilon / how-to-force-a-file-download-with-ningx.md
Last active January 10, 2022 05:29
How to force a file download with Nginx? — First published in fullweb.io issue #73

How to force a file download with Nginx?

In short:

add_header Content-Disposition 'attachment; filename="foo.txt"';

We’re just adding a Content-Disposition header in the response. You can specify the file name, here we’re using foo.txt.

@nepsilon
nepsilon / bash-zsh-useful-aliases.md
Last active December 25, 2021 08:20
Useful aliases for bash and zsh — First published in fullweb.io issue #17

Useful aliases for bash and zsh

Using aliases to give commands useful options by default is a good way to boost productivity.

Here are 5 aliases to put in your ~/.bashrc or ~/.zshrc to keep them permanently:

1. ls:

# ls: adding colors, verbose listign
# and humanize the file sizes: