Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
jaytaylor / railgun.c
Created December 23, 2013 18:38
A blend of the famous Karp-Rabin-Boyer-Moore-Horspool-Sunday algorithms named Railgun.
// Originally found at: http://www.sanmayce.com/Railgun/index.html
// ---------------------------------------------------------------
// All Railgun variants are written by Georgi 'Kaze', they are free, however I expect the user to mention its homepage, that is: http://www.sanmayce.com/Railgun/index.html
// Author's email: [email protected]
// Caution: For better speed the case 'if (cbPattern==1)' was removed, so Pattern must be longer than 1 char.
char * Railgun_Doublet (char * pbTarget, char * pbPattern, uint32_t cbTarget, uint32_t cbPattern)
{
char * pbTargetMax = pbTarget + cbTarget;
register uint32_t ulHashPattern;
uint32_t ulHashTarget, count, countSTATIC;
@jaytaylor
jaytaylor / .gitconfig
Last active August 29, 2015 13:55
My .gitconfig file. Don't forget to install p4merge from http://filehost.perforce.com/perforce/r13.4/bin.macosx106x86/P4V.dmg and follow the instructions at http://www.andymcintosh.com/?p=33
# NB: Don't forget to install p4merge from
# http://filehost.perforce.com/perforce/r13.4/bin.macosx106x86/P4V.dmg
# and follow the configuration instructions at http://www.andymcintosh.com/?p=33
# Some interesting .git_config files here:
# http://stackoverflow.com/questions/267761/what-does-your-gitconfig-contain
[user]
name = YOUR NAME HERE
email = YOUR EMAIL HERE
@jaytaylor
jaytaylor / ipv4AddressToNumber.pl
Created February 4, 2014 21:28
IPv4 addressing tools to convert between IP address <=> IP Number.
#!/usr/bin/env perl
##
# @author Jay Taylor [@jtaylor]
#
# @date 2014-02-04
#
# @description Converts an IPv4 address into an IP number, the unsigned 32-bit numeric representation of an IPv4 address.
#
@jaytaylor
jaytaylor / alexa_top_1m_archiver.py
Last active February 19, 2024 03:06
Alexa top 1-million websites daily snapshot historical archival system
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Alexa top 1-million websites daily snapshot historical archival system."""
__author__ = 'Jay Taylor [@jtaylor]'
import datetime, hashlib, logging, os, urllib2
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=logging.INFO)
@jaytaylor
jaytaylor / softdeletion.py
Last active August 29, 2015 14:00
Django soft-deletion module.
# -*- coding: utf-8 -*-
"""
Soft-deletion for django resources.
Originally found at: http://datahackermd.com/2013/django-soft-deletion/
"""
import logging
@jaytaylor
jaytaylor / django_postgres_cidr_example.py
Created May 21, 2014 21:06
Django + Postgres CIDR filtering
ip_column_name = 'ip'
keyword = '63.0.0.0/24'
where = '{}::inet << %s::inet::cidr'.format(ip_column_name)
match = MyDjangoModel.objects.all()
match = match.extra(where=[where], params=[keyword])
@jaytaylor
jaytaylor / AutoFkShifterMixIn.py
Created May 21, 2014 22:31
Mix-in class for Django ORM objects to allow for more robust object instantiation from keyword arguments.
class AutoFkShifterMixIn(object):
def __init__(self, *args, **kw):
"""Automatically translate any foreign keys to the the *_id field if an id rather than an object has been provided. Also removes m2m kwargs (they'll cause Django ORM to error out)."""
for m2m_field in filter(lambda f: f.name in kw, self._meta.many_to_many):
del kw[m2m_field.name]
for fk_field in filter(lambda f: isinstance(f, models.ForeignKey), self._meta.fields):
if fk_field.name in kw and isinstance(kw[fk_field.name], (int, long, str)):
kw['{}_id'.format(fk_field.name)] = kw.pop(fk_field.name)
super(AutoFkShifterMixIn, self).__init__(*args, **kw)
@jaytaylor
jaytaylor / git-stats-overview.sh
Last active December 19, 2025 18:38
Git repository statistics: Get # of commits and lines changed since some previous point in time
#!/usr/bin/env bash
set -e
##
# @author Jay Taylor [@jtaylor]
#
# @date 2014-06-28
#
# @description Git repository statistics: Get # of commits and lines changed since some previous point in time.
#
@jaytaylor
jaytaylor / asana_dump.py
Last active August 29, 2015 14:03 — forked from gjlondon/asana_dump.py
Use Asana's "export project to JSON" function and copy-paste contents to an "X.json" file. *Note* Requires external library: "unicdecode", available from https://pypi.python.org/pypi/Unidecode
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Use Asana's "export project to JSON" function and copy-paste contents to an "X.json" file."""
import codecs
import csv
import json
import pprint
import re
@jaytaylor
jaytaylor / get_hn_saved_stories.sh
Created July 9, 2014 20:16
Get all your saved stories from HN
#!/usr/bin/env bash
username='YOUR_HN_USERNAME'
cookie='user=HN_AUTH_COOKIE'
next="saved?id=${username}"
while ! [[ -z "${next}" ]]; do
echo "next=${next}"
next=$(curl "https://news.ycombinator.com/${next}" \