Skip to content

Instantly share code, notes, and snippets.

View radiosilence's full-sized avatar
🔥

James Cleveland radiosilence

🔥
View GitHub Profile
@radiosilence
radiosilence / chains.coffee
Last active December 24, 2015 11:39
A faster pattern of doing chained/changeable sequences and flattening out callback hell.
module.exports =
errback: (cargs..., {callbacks, error: [eb, args...]}) ->
eb(args..., cargs..., {callbacks: callbacks, error: [eb, args...]})
callback: (cargs..., {callbacks, error}) ->
[cb, args...] = callbacks.shift()
cb(args..., cargs..., {callbacks: callbacks, error: error})
@radiosilence
radiosilence / 1-vanilla.coffee
Last active December 24, 2015 09:59
Three ways of chaining callbacks that are dependant on the previous one. In CoffeeScript.
http = require 'http'
yellIP = (callbacks, data) ->
console.log "OI!! YOUR IP IS #{data.ip}!!!"
printIP = (callbacks, data) ->
console.log "Your IP address: #{data.ip}"
parseJSON = (callbacks, string) ->
callbacks.shift()(callbacks, JSON.parse(string))
@radiosilence
radiosilence / gist:6780195
Created October 1, 2013 15:24
How do I make callback chaining/injection happen in a cleaner/testable way?
var
http = require('http'),
async = require('async'),
printIP = function(cbs, data) {
console.log("Your IP address: " + data.ip);
},
yellIP = function(cbs, data) {
console.log("OI!!! IP!!! " + data.ip);
},
http = require 'http'
util = require 'util'
net = require 'net'
pg = require 'pg'
conString = "postgres://qrs:qrs@localhost/qrs"
httpServer = http.Server (req, res) ->
pg.connect conString, (err, client, done) ->
@radiosilence
radiosilence / Cakefile
Last active December 20, 2015 16:39
Some useful stuff for CoffeeScript/LiveReload, etc.
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
browserify = require 'browserify'
colors = require 'colors'
UglifyJS = require "uglify-js"
mold = require 'mold-source-map'
path = require 'path'
jsRoot = path.join(__dirname)
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
browserify = require 'browserify'
colors = require 'colors'
UglifyJS = require "uglify-js"
mold = require 'mold-source-map'
path = require 'path'
jsRoot = path.join(__dirname)
var f_list, food, msg, parallelSearch, rankPopularity, tweets, w_list, weather, __iced_deferrals, __iced_k, __iced_k_noop,
_this = this;
__iced_k = __iced_k_noop = function() {};
parallelSearch = function(keywords, cb) {
var i, k, out, ___iced_passed_deferral, __iced_deferrals, __iced_k,
_this = this;
__iced_k = __iced_k_noop;
___iced_passed_deferral = iced.findDeferral(arguments);
# Search for 'keywords' in parallel, then callback
# 'cb' with an array of the parallel results
parallelSearch = (keywords, cb) ->
out = []
await
for k,i in keywords
search k, defer out[i]
cb out
rankPopularity = (keywords, cb) ->
class MyClass:
def my_function(self, nice_verbose_variable):
some_other_variable = another_fairly_long_function(nice_verbose_variable,
"oh look, here's a str" +
"ing how great a layou" +
"idea this is!")
some_other_variable = another_fairly_long_function(
nice_verbose_variable,
"oh look, here's a string, how great a layout idea this is!"
# Contributor: Jean-Sébastien Ney <[email protected]>
# Contributor: James Cleveland <[email protected]>
_cfgdir=/usr/local/openresty/nginx/conf
_tmpdir=/var/lib/openresty
pkgname=openresty
_pkgname=ngx_openresty
pkgver=1.2.8.5
pkgrel=1
pkgdesc="a powerful web app server by extending nginx"
arch=('i686' 'x86_64')