Skip to content

Instantly share code, notes, and snippets.

@jrivero
jrivero / UK POSTCODE PATTERN
Created August 23, 2016 10:25 — forked from spc16670/UK POSTCODE PATTERN
UK Postcode Regex pattern
(GIR 0AA)
| (((XX[0-9][0-9]?)
| ([A-Z-[QVX]][0-9][0-9]?)
| (([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)
| (([A-Z-[QVX]][0-9][A-HJKSTUW])
| ([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@jrivero
jrivero / hack.sh
Created March 31, 2012 13:32 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jrivero
jrivero / index.php
Created March 14, 2012 22:40
Implementing Twitter sign-in with Silex and PHP
<?php
define('CONS_KEY', 'Application consumer key');
define('CONS_SECRET', 'Application consumer secret');
require_once __DIR__.'/silex.phar';
$app = new Silex\Application();
// register the session extension
$app->register(new Silex\Extension\SessionExtension());
@jrivero
jrivero / gist:1387602
Created November 23, 2011 00:54 — forked from jsl/gist:1387560
SELECT DISTINCT message_id
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NULL AS initial_messages
UNION
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NOT NULL AS replies;
@jrivero
jrivero / versionIE.js
Created July 17, 2011 01:38 — forked from padolsey/gist:527683
A short snippet for detecting versions of IE in JavaScript without resorting to user-agent sniffing
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@jrivero
jrivero / csv_splitter.py
Created July 15, 2011 20:33 — forked from palewire/csv_splitter.py
A Python CSV splitter
import os
def split(filehandler, delimiter=',', row_limit=10000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
"""
Splits a CSV file into multiple pieces.
A quick bastardization of the Python CSV library.
Arguments:
@jrivero
jrivero / csv_to_xml.py
Last active September 25, 2015 00:57 — forked from gcollazo/csvtoxml.py
#!/usr/bin/env python
# encoding: utf-8
"""
csv_to_xml.py
This script coverts a csv file to an XML.
The script takes 2 paramenters
* filename
* row node name
<?php
class GenericVariable
{
private $var;
function __construct($variable)
{
$this->var = $variable;
}
function __get($var)
from django.core.paginator import ObjectPaginator
class QuickObjectPaginator(ObjectPaginator):
max_safe_pages = 0
def __init__(self, object_list, per_page, orphans=0, max_safe_pages=0):
self.max_safe_pages = max_safe_pages
super(QuickObjectPaginator, self).__init__(object_list, per_page, orphans)
def validate_page_number(self, page_number):