Skip to content

Instantly share code, notes, and snippets.

@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 / 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 August 29, 2015 14:03
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}" \
@jaytaylor
jaytaylor / dataloop_post_install.sh
Last active August 29, 2015 14:04
DataLoop ubuntu post-install cleanup script.
#!/usr/bin/env bash
set -e -x
# Shutdown the dataloop agent.
sudo service dataloop-agent stop || true
# Kill stragglers in the even that the service control didn't work right.
agentPids=$(ps -ef | grep 'dataloop-lin-agent' | grep -v 'grep' | sed 's/ \+/ /g' | cut -d' ' -f2)
test -n "${agentPids}" && sudo kill -9 ${agentPids}
@jaytaylor
jaytaylor / build.sbt
Created July 31, 2014 20:35
Scala SBT `build.sbt` example of hooking/injecting arbitrary shell commands and using non-native libraries in the build definition via a task run after successful compilation.
organization := "org.foo.bar"
name := "JustAnExample"
version := "1.0"
scalaVersion := "2.10.3"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")