Skip to content

Instantly share code, notes, and snippets.

View nepsilon's full-sized avatar

James Pudson nepsilon

View GitHub Profile
@nepsilon
nepsilon / do-you-know-chrome-web-console.md
Last active February 19, 2017 13:50
You think you know the Chrome Web console? — First published in fullweb.io issue #7

You think you know the Chrome Web console?

There is more than console.log() to the Chrome Web Console:

Output debug, info, warnings and errors:

console.debug('Just so that the dev know') 
console.info('Here is some info') 
console.warn('This may be a problem') 
console.error('This must not happen')
@nepsilon
nepsilon / 3-bash-best-practices.md
Last active February 19, 2017 13:49
3 bash best practices — First published in fullweb.io issue #9

3 bash best practices

Exit immediately if a command exits with a non-zero status:

set -e

Display the next command to be executed:

set -x
@nepsilon
nepsilon / search-bash-zsh-history.md
Last active February 19, 2017 13:48
Searching bash or zsh history — First published in fullweb.io issue #55

Searching bash or zsh history

More often than not, you already typed yesterday the commands you’re about to use today. Wouldn’t it be handy to be able to retrieve the long command instead of typing them yet another time?

Hit Ctrl+R, you’ll see:

(reverse-i-search)`':
@nepsilon
nepsilon / git-change-commit-messages.md
Last active November 19, 2024 18:18
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

@nepsilon
nepsilon / gitignore.md
Last active July 9, 2024 19:14
Understand what .gitignore rule is ignoring your files — First published in fullweb.io issue #54

Understand what .gitignore rule is ignoring your files

Ready to commit, you fire your git status and you don’t see your files 🤔.

Use this command to ask Git what rule is causing this ignore:

$ git check-ignore -v filename

For instance to see what rule ignores tests.pyc:

@nepsilon
nepsilon / periodic-query.md
Last active July 6, 2016 01:23
Periodically run a query with PostgreSQL — First published in fullweb.io issue #53

Periodically run a query with PostgreSQL

If you ever used watch -n 3 ... to run your SQL query every 3 seconds, rejoice because Postgres provides a way to do this without leaving the psql prompt.

First run the command you’d like to repeat:

test-db=# SELECT now();
@nepsilon
nepsilon / pip-mirror.md
Last active June 18, 2020 21:10
Use another mirror when PyPI go down — First published in fullweb.io issue #52

Use another mirror when PyPI go down

Find a mirror geographically close to you and use it like this:

pip install -i https://[mirror-url]/simple package

For instance, using a Beijing mirror:

pip install -i https://pypi.douban.com/simple package
@nepsilon
nepsilon / pg-backup.md
Last active November 21, 2017 00:27
Proper way to do backup (and restore!) with PostgreSQL 🐘 — First published in fullweb.io issue #51

Proper way to do backup (and restore!) with PostgreSQL 🐘

Postgres provides us several options to do backup just like we want. I’ve tried several strategies in the past, and here is the one I stick to now, for both its simplicity and efficiency.

Backup your database with:

# This is using Postgres custom format
pg_dump -Fc dbname > filename
@nepsilon
nepsilon / python-timeit.md
Last active July 6, 2016 01:24
A simple way to benchmark your code in Python — First published in fullweb.io issue #50

A simple way to benchmark your code in Python

You’re working on your script and want to see how fast a function would be. Here’s how to do that with the timeit module, included in the standard library.

Let’s say you have the following script:

import random
@nepsilon
nepsilon / 5-handy-javascript-one-liners.md
Last active March 23, 2019 18:09
5 handy Javascript one-liners — First published on fullweb.io issue #48

5 handy JavaScript one-liners

1. Generate a random string:

Math.random().toString(36).substr(2); 

This simply generates a random float, casts it into a String using base 36 and remove the 2 first chars 0 and. Note that this is not a replacement for UUID generation.

2. Clone an array: