Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
main = do
xmonad $ defaultConfig {
modMask = mod4Mask -- Rebind Mod to the Windows key
@almost
almost / boids.js
Created September 8, 2011 21:25
Javascript Jungle Boids!
// Boids
// Thomas Parslow
// [email protected]
//
// Adapted from: http://www.kfish.org/boids/pseudocode.html
(function() {
var SCALE = 20;
var HOW_MANY = 8;
var RULE_SCALE = 250;
var CLOSE_ENOUGH = 150*4;
@almost
almost / models.coffee
Created November 26, 2011 20:02
The beginnings of a declarative model syntax for CoffeeScript.
# The beginnings of a declarative model syntax for CoffeeScript.
# SEE: http://almostobsolete.net/declarative-models-in-coffeescript.html
# Thomas Parslow
# Email: [email protected]
# Twitter: @almostobsolete
# The top part is the setup, see below that for the demo
# To see this run right away try copy pasting it into the 'Try
# CoffeeScript' box at http://jashkenas.github.com/coffee-script/
class Post extends Model
@field 'title', default: 'New post!'
@field 'body'
# the default is supplied as a closure which is evaluated at object
# creation time
@field 'created_at', default: -> new Date()
class User extends Model
@field 'username'
@field 'twitter'
# Create a new user
user = new User(username: 'tom', twitter: 'almostobsolete')
# Bind to the change event for the title property
user.bind 'change:username', (value) =>
alert "Username updated to #{value}"
# Print out details of posts when they are created by the user
user.bind 'posts:add', (post) =>
alert "Post '#{post.get('title')}' created at #{post.get('created_at')}"
# Change the user's username (which will trigger the event bound above)
class Model
# This is the CoffeeScript syntax to declare a class method
@field: (name, options) ->
@fields ?= {}
@fields[name] = options || {}
constructor: (attributes) =>
@attributes = {}
# Copy in attributes passed in or defaults from the fields as
# appropriate
for name, options of @constructor.fields
## chainDeferred
# Take two jQuery Deferred objects and chain one on to the other. So
# anything that happens to the first one is proxied on the second one.
# Returns the source (for method call chaining)
module.chainDeferred = (source, destination) ->
source.then(
-> destination.resolveWith(@, arguments),
-> destination.rejectWith(@, arguments),
@almost
almost / agggh
Created February 13, 2012 12:18 — forked from alexanderhosford/agggh
Browser detection?
<script type="text/javascript">
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ffversion>=5)
document.write(" FF 5.x or above")
else if (ffversion>=4)
document.write(" FF 4.x or above")
else if (ffversion>=3)
document.write(" FF 3.x or above")
@almost
almost / gist:1884579
Created February 22, 2012 12:16
CouchDB: M2M link via non-primary keys.
// I have meetings like this:
{
"type": "meeting"
"_id": "MEETINGID",
"emails": ["[email protected]", "[email protected]"]
// Lots of others things
}
// I have users like this:
@almost
almost / gist:1887280
Created February 22, 2012 21:08
Here you go josh
//
// ViewTestViewController.m
// ViewTest
//
// Created by Joshua Theed on 10/01/2012.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "ViewRecordsViewController.h"
#import "CustomTableViewCell.h"