Skip to content

Instantly share code, notes, and snippets.

View gerad's full-sized avatar

Gerad Suyderhoud gerad

View GitHub Profile
class ServerJuice
attr_reader :script_name, :server, :hostname
def initialize(script_name, server, hostname, mysql_password = "")
@script_name = script_name
@server = server
@hostname = hostname
@mysql_password = mysql_password
end
@gerad
gerad / memcache.py
Created September 11, 2009 15:52
memcache wrapper for google appengine
def memcache(func):
def cached(*args):
key = pickle.dumps((func.__name__, args))
cache = Memcache.get(key)
if (cache):
logging.info("cache hit for %s" % func.__name__)
return pickle.loads(cache)
value = func(*args)
test("pass through", function() {
function increment(i) { return i + 1; }
function asyncIncrement(i, callback) {
async(function() { callback(i + 1); });
}
function asyncIncrement2(i) {
var d = new Deferred().pause();
async(function() { d.restart(i + 1); });
return d;
}
@gerad
gerad / itunes_to_android.rb
Created November 26, 2009 21:26
Copy iTunes playlists to Android with Ruby
require 'rubygems'
require 'appscript'
require 'ftools'
it = Appscript.app('iTunes')
['80s Mix', 'Ridiculously awesome'].each do |playlist|
it.playlists[playlist].tracks.get.each do |track|
from = track.location.get.to_s
to = '/Volumes/ANDROID/Music' +
var view = new View();
view.template("show", function() { /*
Hello World
*/ });
view.template("edit", function() { /*
<%= str %>
*/ });
test("can render", function() {
@gerad
gerad / pre-commit.sh
Created December 3, 2009 01:01
git pre-commit hook that checks for debugger / console.log and trailing commas - install at PROJECT/.git/hooks/pre-commit
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, make this file executable.
# This is slightly modified from Andrew Morton's Perfect Patch.
@gerad
gerad / gae_json_rest.py
Created December 16, 2009 01:29
turn google app engine to a big json db in the cloud
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from django.utils import simplejson as json
from google.appengine.ext import db
import re
import pdb, sys
debugger = pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__)
@gerad
gerad / encrypter.rb
Created February 2, 2010 02:07
simple encrypted fields in rails
# extend Encrypter::Encryptable
# encrypt :email, :password
class Encrypter
def self.encrypt val
encrypter.encrypt val
end
def self.decrypt val
encrypter.decrypt val
@gerad
gerad / application.js
Created February 5, 2010 22:55
hoptoad report javascript errors
// in application.js
window.onerror = function(msg, url, line) {
var location = String(window.location);
new Ajax.Request('/error/error', {
method: 'POST',
parameters: {
message: msg,
url: url || location,
line: line,
location: location,
@gerad
gerad / appengine_console.py
Created April 28, 2010 20:48
Setup an interactive console for Google AppEngine - similar to script/console in Rails.
"""Convenience wrapper for starting an interactive appengine console."""
import os
import sys
from subprocess import call
DIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath('/usr/local/bin/dev_appserver.py')))
EXTRA_PATHS = [
DIR_PATH,