Skip to content

Instantly share code, notes, and snippets.

@alecperkins
alecperkins / gist:943636
Created April 27, 2011 02:47
Translate mobile Safari touch events to mouse events
// from http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
@alecperkins
alecperkins / style.css
Created July 13, 2011 22:02
Basic variable-length args for a Sass mixin
div.foo-section h2, div.bar-section h2 { height: 20px; padding-left: 30px; background-position: left top; }
div.foo-section h2.my { background-image: url("images/my.png"); }
div.foo-section h2.very { background-image: url("images/very.png"); }
div.foo-section h2.excellent { background-image: url("images/excellent.png"); }
div.foo-section h2.mother { background-image: url("images/mother.png"); }
div.foo-section h2.just { background-image: url("images/just.png"); }
div.foo-section h2.sent { background-image: url("images/sent.png"); }
div.foo-section h2.us { background-image: url("images/us.png"); }
div.foo-section h2.nine { background-image: url("images/nine.png"); }
@alecperkins
alecperkins / app.coffee
Created July 15, 2011 20:01
3-player ROCKPAPERSCISSORSLIZARDSPOCK, a Pad Hacker test
choices = [
{ name: 'rock', beats: ['scissors', 'lizard'] }
{ name: 'paper', beats: ['rock', 'spock'] }
{ name: 'scissors', beats: ['paper', 'lizard'] }
{ name: 'lizard', beats: ['paper', 'spock'] }
{ name: 'spock', beats: ['rock', 'scissors'] }
]
tbody = $('tbody')
thead = $('thead')
@alecperkins
alecperkins / _normalize.sass
Created October 15, 2011 22:49
Sass version of normalize.css
// generated using `sass-convert normalize.css`
/*! normalize.css 2011-08-12T17:28 UTC · http://github.com/necolas/normalize.css
/* =============================================================================
* HTML5 display definitions
* ==========================================================================
/*
* Corrects block display not defined in IE6/7/8/9 & FF3
@alecperkins
alecperkins / templates.coffee
Created October 21, 2011 15:40
Backbone template…template
###
## Partials
Included in templates using CoffeeScript's string interpolation:
partial = "<partial>content {{ foo }}</partial>"
template = """
<template>
<stuff>#{ partial }</stuff>
"""
This fabric file makes setting up and deploying a django application much
easier, but it does make a few assumptions. Namely that you're using Git,
Apache and mod_wsgi and your using Debian or Ubuntu. Also you should have
Django installed on your local machine and SSH installed on both the local
machine and any servers you want to deploy to.
_note that I've used the name project_name throughout this example. Replace
this with whatever your project is called._
@alecperkins
alecperkins / gist:1364430
Created November 14, 2011 16:56
Simulated ForeignKeys from MongoEngine Document to Django Models
# Using the `@property` decorator allows the MongoEngine Document object to have
# properties that reference Models, and be got/set like normal foreign keys.
# This same pattern can work the other way and allow Models interface with
# Documents.
class Foo(mongoengine.Document):
# The `id` of the property is stored in the Document.
user_id = mongoengine.IntField()
# Setters and getters to interface with the SQL DB and set Users to the
@alecperkins
alecperkins / gist:1725637
Created February 2, 2012 20:40
Script usability functions
import sys
def yellow(*args):
some_string = ' '.join([str(arg) for arg in args])
return '\033[93m%s\033[0m' % (some_string,)
def green(*args):
some_string = ' '.join([str(arg) for arg in args])
return '\033[92m%s\033[0m' % (some_string,)
@alecperkins
alecperkins / gist:2083178
Created March 18, 2012 22:30
Dump content from posterous
"""
# Dump your data from Posterous.
Requires:
* Posterous username and password
* An API Token from http://posterous.com/api
* Posterous site id also from http://posterous.com/api
* The Python libraries requests and python-dateutil
@alecperkins
alecperkins / gist:2251600
Created March 30, 2012 13:35
Retina images with CSS background-image
<!doctype html>
<html>
<head>
<style>
div.image, div.image1x {
width: 1024px;
height: 768px;
background: url(image_1x.jpg) no-repeat;
-webkit-background-size: cover;
}