Skip to content

Instantly share code, notes, and snippets.

@chrisfarms
chrisfarms / xmlparser.go
Created November 18, 2011 17:59
Really rough example of using xml.Parser
package main
import (
"fmt";
"io"
"xml"
"strings"
)
@chrisfarms
chrisfarms / console.py
Created August 10, 2011 14:41
An appengine python console
#!/usr/bin/env python
import getopt
import os
import ae
import sys
import code
def usage():
print """

Keybase proof

I hereby claim:

  • I am chrisfarms on github.
  • I am chrisfarms (https://keybase.io/chrisfarms) on keybase.
  • I have a public key ASDaE75jPl2n3qQPaB7TUu81ZrH2KVczT8TUir6eNTDdYQo

To claim this, I am signing this object:

CREATE OR REPLACE FUNCTION time_ago_in_words(timestamp with time zone)
RETURNS text
LANGUAGE SQL
AS $$
SELECT CASE
WHEN date_part('year', age(current_timestamp, $1)) = 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' year ago')
WHEN date_part('year', age(current_timestamp, $1)) > 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' years ago')
WHEN date_part('month', age(current_timestamp, $1)) = 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' month ago')
WHEN date_part('month', age(current_timestamp, $1)) > 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' months ago')
WHEN date_part('day', age(current_timestamp, $1)) = 1 THEN concat(date_part('day', age(current_timestamp, $1)), ' day ago')
#!/bin/bash
# Author: slowpoke <proxypoke at lavabit dot com>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#
# A pre-commit hook for go projects. In addition to the standard
@chrisfarms
chrisfarms / pingo.go
Created August 22, 2011 10:45
"ping" a site over HTTP every few seconds and check for status code 200 - just a little play in go
package main
import (
"fmt"
"http"
"time"
)
type Site struct {
url string
@chrisfarms
chrisfarms / ae.py
Created August 10, 2011 14:37
An google-appengine loading module to aid writing scripts for GAE
######################################################
# allow scripts to use appengine apis
#
# assumes you store your data in a "data" directory
# in your app directory. See connect_local_datastore()
# and assumes that you have a HRD app id with "~"
######################################################
#
# locate app-engine SDK:
AE_PATH = "/your/path/to/sdk/google_appengine/"
@chrisfarms
chrisfarms / HookedModel.py
Created May 22, 2011 21:33
async safe before and after save hooks for AppEngine db.Model
class HookedModel(db.Model):
def before_put(self):
logging.error("before put")
def after_put(self):
logging.error("after put")
def before_delete(self):
@chrisfarms
chrisfarms / sencha-multiple-dv.js
Created May 3, 2011 11:14
Issue with multiple DataViews with one store
// Create a model (with any proxy)
Ext.regModel('Car', {
fields: ['id', 'name', 'sports'],
proxy: {
type: 'localstorage',
id : 'cars'
}
});
// Create a store to access the records
@chrisfarms
chrisfarms / basemodel.py
Created March 22, 2011 19:50
GAE base model class with to_json serialisation
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
class BaseModel(db.Model):
def to_json_friendly_value(self, v):
if v is None or isinstance(v, SIMPLE_TYPES):
value = v
elif isinstance(v, datetime.date):
# Convert date/datetime to ms-since-epoch ("new Date()").
ms = time.mktime(v.utctimetuple()) * 1000