Skip to content

Instantly share code, notes, and snippets.

View robertobarreda's full-sized avatar

Roberto Barreda robertobarreda

View GitHub Profile
/* crc64.c -- compute CRC-64
* Copyright (C) 2013 Mark Adler
* Version 1.4 16 Dec 2013 Mark Adler
*/
/*
This software is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
#!/usr/bin/env python
import argparse
import csv
import gzip
import sys
import re
from contextlib import closing
# This prevents prematurely closed pipes from raising
# an exception in Python
from signal import signal, SIGPIPE, SIG_DFL
@robertobarreda
robertobarreda / mysql_to_redshift.py
Created December 19, 2014 10:34
mysql to postresql schema converter
#!/usr/bin/env python
"""
Fixes a MySQL dump made with the right format so it can be
imported to a Redshift database.
Dump using:
mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root databasename tablename
"""
@robertobarreda
robertobarreda / is_mobile.py
Created October 3, 2013 14:09
django.request is_mobile?
import re
USER_AGENT_REGEX = re.compile(
r"android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|"
r"ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|"
r"phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|"
r"vodafone|wap|indows (ce|phone)|xda|xiino", re.M)
def is_mobile(request):
ua = request.META.get('HTTP_USER_AGENT', '').lower()
@robertobarreda
robertobarreda / latency_numbers.txt
Last active November 17, 2016 14:23
Latency numbers every programmer should know
### Latency numbers every programmer should know
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs