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-remove-duplicated-rows-postgres.md
Last active July 9, 2016 00:42
How to remove duplicated rows in a PostgreSQL table? — First published in fullweb.io issue #23

How to remove duplicated rows in a PostgreSQL table?

The simplest and certainly safest way remains to copy data from a DISTINCT query to a new table, and to rename it to the original table.

Here our table with duplicated rows is named t_word:

STEP 1:

Create a new table without the duplicated rows:

@nepsilon
nepsilon / how-to-app-siege-load-test.md
Last active February 19, 2017 12:45
How to test your webapp for heavy traffic? — First published in fullweb.io issue #24

How to test your web app for heavy traffic?

Load testing is a good way to understand your website or web app behaviour under high traffic. Here is how to use siege, a simple CLI tool.

Note: Use siege only on sites you own as its traffic could be interpreted as a DDOS attack.

Using 100 concurrent requests and up to 3 seconds between requests:

@nepsilon
nepsilon / pg-unique.md
Last active July 9, 2016 00:35
How to force UNIQUE on a combination of columns, with PostgreSQL? — First published in fullweb.io issue #25

How to force UNIQUE on a combination of columns with PostgreSQL?

Sometimes you want 2 columns to be UNIQUE, but together, not each on their side. Here is how to add this constraint with PostgreSQL:

Given the following table:

CREATE TABLE t_word (
  id serial primary key,
 col1 int NOT NULL,
@nepsilon
nepsilon / 3-reg-exp-traps.md
Last active July 9, 2016 00:29
3 Regular Expressions traps to avoid — First published in fullweb.io issue #26

3 Regular Expressions traps to avoid

Regular Expressions often appear daunting with their Perl-esque syntax. You will find countless tutorials online to get started, but few will highlight the traps most of us will fall into.

Note: Using JavaScript-friendly syntax

We'll be using this text:

@nepsilon
nepsilon / 3-xargs-tips.md
Last active July 19, 2017 05:28
3 xargs usage tips — First published in fullweb.io issue #26

3 xargs tips on the road to CLI mastery

xargs can be used to process output from other commands (such as find) as argument to a new commands. It can come very handy in many cases, here are 3:

1. Finding and deleting .zip files:

$ find . -name "*.zip" -type f -print | xargs /bin/rm -f 
@nepsilon
nepsilon / css-how-to-box-sizing.md
Last active February 19, 2017 12:48
CSS: Using `box-sizing` to better control elements size — First published in fullweb.io issue #28

Using box-sizing to better control elements size

Ever wanted a 500px wide div, but then realized you had to subtract the left and right padding to its width? And then subtract the border width?

That’s when the box-sizing property will your hero, it’s supported on every browser (IE8+):

We start with that HTML:

 fullweb 
@nepsilon
nepsilon / how-to-faster-page-rendering-with-async-defer.md
Last active June 29, 2021 04:00
Faster page rendering with async and defer for script loading — First published in fullweb.io issue #29

Faster page rendering with async and defer

HTML5 gave us async and defer to better control the browser page rendering flow. By default when the browser sees a <script> tag’s src link, it will pause the HTML parsing, download the script, execute it, and only then resume the HTML parsing. Putting your <script> tags at the bottom of your HTML is a good practice, but async and defer provide us with more control.

Here is how to use them and what are their differences:

Using async:

@nepsilon
nepsilon / how-to-git-merge-commits.md
Last active December 13, 2019 04:10
Git merge commits — First published in fullweb.io issue #30

How to merge commits in Git?

Sometimes, you commit something and realize it needs some more fixing, and then some more. Resulting in 3 or more commits for the same task.

You like to keep your git log clean and want to merge your commits. Here is how to do just that:

Suppose we have this history:

@nepsilon
nepsilon / how-to-ssh-agent.md
Last active April 10, 2025 17:16
Remember passphrases with ssh-agent — First published in fullweb.io issue #31

How to use ssh-agent to cache your SSH credentials?

Contributed by Fabien Loudet, Linux SysAdmin at Rosetta Stone

Tired of always having to enter your SSH key passphrase when logging in to remote machines? Here comes ssh-agent. Enter the passphrase once and it will keep it in memory for you

Using ssh-agent in your shell session:

@nepsilon
nepsilon / python-better-flow-control.md
Last active July 8, 2016 06:20
Better Flow Control with Python — First published in fullweb.io issue #32

Better Flow Control with Python

I recently interviewed 4 developers for a Python programming position They all knew how to use requests, call APIs and worked either with Django or Flask, but I saw all of them ignoring most of Python’s specific control flow.

Here are two of them, try/except/else/finally and for/else:

try: 
    # What you want to do, which might