Skip to content

Instantly share code, notes, and snippets.

View technoweenie's full-sized avatar
👾
beep boop

technoweenie

👾
beep boop
View GitHub Profile
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
# utility lib for random OAuth2 crap.
module OauthUtil
extend self
def bad_redirect_uri?(app, url)
return false if url.blank? || url =~ /^https?:\/\/github\.com\/login\/oauth\/success$/
uri = URI.parse(url)
uri.host != app.callback_uri.host ||
uri.port != app.callback_uri.port ||
(uri.path =~ %r{#{app.callback_uri.path}(\/|$)}) != 0
@technoweenie
technoweenie / parslet_test.rb
Created January 12, 2011 12:11
quick JSON example parser using parslet
require 'rubygems'
require 'parslet'
require 'pp'
def parse(klass, str)
parser = klass.new
puts "parsing #{str}"
pp parser.parse(str)
puts
rescue Parslet::ParseFailed => err
Queueing SELECT for next server connection.
Queueing FLUSHDB for next server connection.
Queueing QUIT for next server connection.
Stream connected
Sending offline command: SELECT
send command: *2
$6
SELECT
$2
// multi api proposal
// http://github.com/mranney/node_redis
// old and busted
client.multi([
["incr", ["multibar"], function (err, res) {
console.log(err || res);
}],
["incr", ["multifoo"], function (err, res) {
console.log(err || res);
@technoweenie
technoweenie / step.coffee
Created August 26, 2010 22:26
Step.js ported to coffeescript, with fewer features
# Step(
# () -> redis.select 15, @
# () -> redis.flushdb @
# () -> redis.rpush 'fakelist', '1', @
# () -> redis.rpush 'fakelist', '2', @
# () -> redis.rpush 'fakelist', '3', @
# () -> redis.lrange 'fakelist', 0, 1, @
# (err, arr) ->
# console.log arr.length
# console.log arr[0].toString()
@technoweenie
technoweenie / mapper.coffee
Created August 15, 2010 08:28
Javascript => Coffeescript screencast: http://screenr.com/xd0
#
# Module dependencies
#
utils = require './utils'
#
# @api private
#
class Mapper
constructor: (phases, riak) ->
task :finish do
next if ENV['NOCAMPFIRE']
require "#{rails_root}/lib/campfire"
branch_name = branch.split('/', 2).last
msg = "#{deploying_user}'s #{rails_env} deployment of #{branch_name} is done!"
if rand > 0.7
msg.sub! /done\!$/, 'NOW DIAMONDS!'
end
Campfire.notify msg
end
@technoweenie
technoweenie / gist:498995
Created July 29, 2010 19:30
less crappy implementation that fixed a bug if the base64 included whitespace in the middle
@@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization)
# gets BASIC auth info
def get_auth_data
auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
if auth_key.present? && request.env[auth_key].to_s =~ /^Basic\s+(.*)/m
Base64.decode64($1).split(':')[0..1]
else
[nil, nil]
end
end
addHttpOptions: function(bucket, key, options) {
if(!options.headers) options.headers = {};
var queryProperties = {};
// known url params are added to the query
['r', 'w', 'dw', 'keys', 'props', 'vtag', 'nocache', 'returnbody'].forEach(function(p) {
if (options[p] !== undefined) {
queryProperties[p] = options[p];
}