Skip to content

Instantly share code, notes, and snippets.

Avatar
Always shipping.

Dan Loewenherz dlo

Always shipping.
View GitHub Profile
View UpdatePinboardTags.py
#coding: utf-8
import console
import keychain
import pickle
import requests
import json
from urllib import quote
import webbrowser
@dlo
dlo / prefixes.sql
Last active Aug 29, 2015
PostgreSQL procedure that concatenates all prefix substrings for a given string. Helpful for generating full-text search indices.
View prefixes.sql
CREATE FUNCTION prefixes(varchar, integer) RETURNS varchar AS $$
DECLARE
result varchar;
minlength integer;
BEGIN
SELECT GREATEST($2, 0) INTO length;
WITH RECURSIVE t(value, n) AS (
SELECT $1, length($1)
UNION ALL
SELECT substring(value for n-1), n-1 FROM t WHERE n>minlength
View .pythonrc
# vim: set ft=python :
from __future__ import print_function
import json
import sys
import datetime
from redis import StrictRedis as Redis
View mock_dates.py
import datetime
class FakeDateTime(datetime.datetime):
def __eq__(self, instance):
try:
return (self.year, self.month, self.day, self.hour, self.minute, self.second) == (instance.year, instance.month, instance.day, instance.hour, instance.minute, instance.second)
except:
return False
@classmethod
View gist:9f6ef1754aa56f36a15d
- (void)cancelLongRunningTasks:(id)sender {
NSDate *date = [NSDate date];
void (^CompletionHandler)(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) = ^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
for (NSURLSessionDownloadTask *task in downloadTasks) {
if (task.state == NSURLSessionTaskStateRunning) {
NSDate *startDate = self.sessionDownloadTaskStartDates[@(task.taskIdentifier)];
if (startDate) {
NSTimeInterval interval = [date timeIntervalSinceDate:startDate];
if (interval > 30) {
View patch.sh
#!/bin/sh
# Ref: http://ubuntuforums.org/showthread.php?t=1751455
# Install required libs
apt-get -y install build-essential python-dev libjpeg62-dev zlib1g-dev libfreetype6-dev liblcms1-dev
# Link to correct location
if [ -d /usr/lib/x86_64-linux-gnu ]; then
# Ubuntu 11.04 64bit
ln -sf /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
ln -sf /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
ln -sf /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
View protocolequatable.swift
//: Playground - noun: a place where people can play
import UIKit
protocol AccountLike: Equatable {
var accountID: String {get}
}
class Account : AccountLike {
let accountID = nil
@dlo
dlo / wsp.py
Created Nov 11, 2009
Shorthand for Go compilation.
View wsp.py
#!/usr/bin/env python
import sys
from os import system
prog = sys.argv[1]
pos = prog.find(".")
name = prog[:pos]
system("8g " + prog)
system("8l -o %s.out %s.8" % (name, name))
@dlo
dlo / README.md
Created Nov 18, 2009
A bare-bones tweet notifier for OS X.
View README.md

Growl Tweet Notifier

This gist has graduated into a real repository! Check it out at dlo/growltweet.

@dlo
dlo / textile.py
Created Nov 21, 2009
Textile 2.1.3
View textile.py
#!/usr/bin/env python
"""
PyTextile
A Humane Web Text Generator
"""
__version__ = '2.1.3'
__date__ = '2009/02/07'
You can’t perform that action at this time.