Skip to content

Instantly share code, notes, and snippets.

View turtlesoupy's full-sized avatar
😶‍🌫️

Thomas Dimson turtlesoupy

😶‍🌫️
View GitHub Profile
@turtlesoupy
turtlesoupy / s3put.coffee
Created November 8, 2011 07:13
Robust node.js s3 put
fs = require 'fs'
http = require 'http'
https = require 'https'
crypto = require 'crypto'
mime = require 'mime'
xml2js = require 'xml2js'
delayTimeout = (ms, func) -> setTimeout func, ms
class @S3Put
@turtlesoupy
turtlesoupy / distanceOfTimeInWords
Created January 6, 2012 08:00
Simple CoffeeScript distanceOfTimeInWords and distanceOfTimeInWordsToNow
distanceOfTimeInWords = (dateDiff) ->
seconds = Math.abs(dateDiff) / 1000
minutes = seconds / 60
hours = minutes / 60
days = hours / 24
years = days / 365
words = switch
when seconds < 45 then "less than a minute"
when seconds < 90 then "about a minute"
@turtlesoupy
turtlesoupy / pg_pool.coffee
Created June 10, 2012 23:34
node-postgres pooled function decorator
pg = require 'pg'
module.exports = pooler =
#Get a connection from the pool
acquire: (callback) -> pg.connect "tcp://postgres:postgres@localhost/dummy_db", callback
#Decorate a function to use the de-pooled connection as a first argument
pooled: (fn) -> ->
callerCallback = arguments[arguments.length - 1]
callerHasCallback = typeof callerCallback == 'function'
@turtlesoupy
turtlesoupy / child_monitor.coffee
Created June 25, 2012 01:12
A node.js process supervisor and a sample use with health checks - see http://blog.argteam.com/coding/hardening-nodejs-production-process-supervisor/
{_} = require 'underscore'
child_process = require 'child_process'
async = require 'async'
healthCheckInterval = 60 * 1000
bounceInterval = 60 * 1000
bounceWait = bounceInterval + 30 * 1000
delayTimeout = (ms, func) -> setTimeout func, ms
class MonitoredChild
@turtlesoupy
turtlesoupy / nginx.conf
Created July 8, 2012 21:16
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
@turtlesoupy
turtlesoupy / sfs_bot.coffee
Created August 17, 2012 05:34
Cosbybot / Urkelbot implementation for the Silly Face Society
{config, glb} = require("../lib/bootstrap")("sfs_bot")
fs = require 'fs'
http = require 'http'
winston = require 'winston'
async = require 'async'
utils = require '../lib/utils'
querystring = require 'querystring'
request = require('request').defaults
headers:
@turtlesoupy
turtlesoupy / SFSViewController.m
Created September 16, 2012 08:16
Really cruddy iOS particle system to demo emissionLongitude
//
// SFSViewController.m
// AmazingParticleSpinner
//
// Created by Thomas Dimson on 9/15/12.
// Copyright (c) 2012 Thomas Dimson. All rights reserved.
//
#import "SFSViewController.h"
#import <QuartzCore/QuartzCore.h>
@turtlesoupy
turtlesoupy / SFSSmokeScreen.m
Created September 16, 2012 08:50
Psychedelic smoke CAEmitterLayer particle effect
#import "SFSSmokeScreen.h"
#import <QuartzCore/QuartzCore.h>
@implementation SFSSmokeScreen {
__weak CAEmitterLayer*smokeEmitter;
}
-(id)initWithFrame:(CGRect)frame emitterFrame:(CGRect)emitterFrame{
if ((self = [super initWithFrame:frame])) {
self.backgroundColor = [UIColor clearColor];
@turtlesoupy
turtlesoupy / SFSConfettiScreen.m
Created September 16, 2012 09:11
Confetti particle system for iOS5+
//
// Created by tdimson on 8/15/12.
#import <QuartzCore/QuartzCore.h>
#import "SFSConfettiScreen.h"
@implementation SFSConfettiScreen {
__weak CAEmitterLayer *_confettiEmitter;
CGFloat _decayAmount;
@turtlesoupy
turtlesoupy / SFSChickenScreen.m
Created September 16, 2012 09:18
Ultra chicken CAEmitterLayer particle system
//
// Created by tdimson on 9/5/12.
#import <QuartzCore/QuartzCore.h>
#import "SFSChickenScreen.h"
@implementation SFSChickenScreen {
__weak CAEmitterLayer *_chickenEmitter;
CGFloat _decayAmount;