Skip to content

Instantly share code, notes, and snippets.

View michaelcontento's full-sized avatar
🎯
Focusing

Michael Contento michaelcontento

🎯
Focusing
View GitHub Profile
@michaelcontento
michaelcontento / prime_neighbours.py
Created January 20, 2011 14:35
Detect prime twins in python
#!/usr/bin/env python
from itertools import izip, tee
from sys import argv, exit
def pairwise(iter):
# See: http://docs.python.org/library/itertools.html#recipes
a, b = tee(iter)
next(b, None)
return izip(a, b)
@michaelcontento
michaelcontento / prime_neighbours.sh
Created January 21, 2011 10:16
Detect prime twins in bash
#!/usr/bin/env bash
START=2
STOP=300
lastprime=2
primes=$(wget -O - -q http://www.math.utah.edu/~alfeld/math/p10000.html \
| cut -c8- \
| egrep -o '^ [0-9 ]+$' \
| awk '{ list = list $0 } END { print list }')
@michaelcontento
michaelcontento / google-grabber.sh
Created May 26, 2011 18:29
Grab profile URLs from Google and extract the users email (if public)
time curl -s http://www.gstatic.com/s2/sitemaps/sitemap-[001-002].txt \
| xargs -P10 -L1 -I{} sh -c "curl -s {} | egrep -o 'profiles.google.com/[^&\"]+' | cut -d'/' -f2 | egrep -v '^[0-9]+$'"
@michaelcontento
michaelcontento / .htaccess
Created May 30, 2011 16:02
RewriteRule with md5 cachebusting
RewriteEngine On
# Rewrite all URLs with md5 cachebusting
# e.g. /e0d97534e77671a12012a9a1effc3bda/css/style.css -> /css/style.css
RewriteRule ^[A-Z0-9]{32}/(.*)$ $1 [NC,N]
# Based on the Zend Framework manual
# see: http://framework.zend.com/manual/1.11/en/project-structure.rewrite.html
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
@michaelcontento
michaelcontento / joe.php
Created June 9, 2011 09:38
Simple regex for @joemanaco
<?php
$input = <<<EOF
### Section: Imports ###
text....
foo
### End Section ###
@michaelcontento
michaelcontento / test.sh
Created June 9, 2011 10:19
Simple combination of inotifywait and phpunit
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 TEST-DIR"
exit 1
fi
testsDir=$1
if [ ! -d $testsDir ]; then
@michaelcontento
michaelcontento / demo.sql
Created June 20, 2011 08:32
MySQL: Insert utf8 via latin1-connection into utf8
--
-- First we create the table with charset=utf8
--
mysql> create table utf8 (msg varchar(10)) default charset=utf8;
Query OK, 0 rows affected (0.00 sec)
--
-- This is out demo-character (remember the hex value!)
--
@michaelcontento
michaelcontento / primary_keys.sql
Created June 20, 2011 08:33
Shows combined primary keys on innodb
create table bla(
b int,
id int not null auto_increment,
primary key (b, id),
unique key (id)
) engine=innodb;
insert into bla (b) values (1), (2), (1), (2);
/* this looks like "order by id, b" because with small tables mysql doesn't use the primary key */
@michaelcontento
michaelcontento / game.coffee
Created July 3, 2011 19:50
Backbone models connected with Faye based backend (frontend written in CoffeeScript)
$ ->
# === CONFIGURATION
GAME_DIV_ID = '#game'
FAYE_URL = 'http://localhost:9292/faye'
# === APPLICATION
GameModel = Backbone.Model.extend {}
GameView = Backbone.View.extend {
el: $(GAME_DIV_ID)
@michaelcontento
michaelcontento / cake-some-fixture-wtf.php
Created December 19, 2011 10:29
CakePHP Fixture "Fun"
<?php
class SomeFixture extends CakeTestFixture
{
public $name = 'Table';
public $records = array(
array('A' => 1, 'B' => 2),
array('B' => 2, 'A' => 1)
);
}