Skip to content

Instantly share code, notes, and snippets.

View nepsilon's full-sized avatar

James Pudson nepsilon

View GitHub Profile
@nepsilon
nepsilon / gist:7562120
Last active December 28, 2015 21:09
Font size px to em reference table with 16px as default font size.

Font size table

Browser default 16px

pixels relative
36px 2.25em
31px 0.5161em
24px 1.5em
21px 1.3125em

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@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 / 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 / csvkit.md
Last active July 7, 2016 05:34
Need to make sense of large CSV files? — First published on fullweb.io issue #44

Need to make sense of large CSV files?

Often you are handed-out big CSV files and need to sort, filter, update some cells or other tedious work. You tried sed, jq, and maybe the mighty awk.

But at the end of the day: You’re using the wrong tool for the job.

Here come csvkit’s csvsql, a small Python script to parse your CSV files and create the corresponding database. You now have the best tool, SQL, to answer your data questions:

@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 / 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-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 / 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
@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: