Skip to content

Instantly share code, notes, and snippets.

@zenhob
zenhob / gist:77193
Created March 10, 2009 22:59
Extract the current revision on Rails initialization.
# Attempt to extract the currently running revision number.
# In production mode, attempts to use the Capistrano REVISION file.
# If development mode, attempts to use the .svn/entries file, then git-svn, and finally git-describe.
# If a revision can't be determined, the value is 'x'.
REVISION = begin
revision_path = Rails.root + '/REVISION'
entries_path = '.svn/entries'
if ENV['RAILS_ENV'] == 'production'
if File.exists?(revision_path)
File.open(revision_path, "r") do |rev|
namespace :remote do
desc "Open a screen on the deploy target server."
task :screen do
system "ssh -t #{user}@#{server_name} screen"
end
end
# example of a method definition with a name that isn't an identifier
x = :'this is some crazy a$$ shit!'
self.class.send(:define_method, x) do
puts 'crazy!'
end
send x
/**
* discount.ooc
* copyright 2010 Zack Hobson <zack@zackhobson.com>
*
* This is an interface to the discount markdown library in the ooc
* programming language.
*
* http://www.pell.portland.or.us/~orc/Code/markdown/
* http://ooc-lang.org/
*
@zenhob
zenhob / tweetshouter.js
Created February 4, 2010 20:13
tweet shouter!
var TwitterNode = require( 'twitter-node' ).TwitterNode,
sys = require( 'sys' )
var keywords = process.ARGV.slice(2),
twit = new TwitterNode({
user: 'LOGIN',
password: 'PASSWORD',
track: keywords
})
var fs = require("fs"),
sys = require("sys"),
path = require("path");
exports.MIME_TYPES = {
".txt" : "text/plain",
".html" : "text/html",
".css" : "text/css",
".js" : "application/x-javascript",
".manifest" : "text/cache-manifest"
#!/usr/bin/env ruby -rubygems
require 'faraday'
require 'trollop'
require 'fileutils'
class ZenDesk2Tender
include FileUtils
attr_reader :opts, :conn
EXPORT_DIR = '.export-data'
@zenhob
zenhob / days_since.coffee
Created January 18, 2012 23:07
hubot script for tracking days since an event
# Generates commands to track days since an event
#
# it's been <number> days since <event> - Set the day when the event happened
# how long since <event>? - Display the number of days since the event
module.exports = (robot) ->
robot.respond /it's been (\d+) days since\s+(.*?)[.?!]?$/i, (msg) ->
date = new Date
date.setTime(date.getTime() - (parseInt(msg.match[1])*1000*24*60*60))
robot.brain.data.days_since ||= {}
@zenhob
zenhob / days_since.coffee
Created January 19, 2012 00:02 — forked from ajacksified/days_since.coffee
hubot script for tracking days since an event
# Generates commands to track days since an event
#
# it's been <number> days since <event> - Set the day when the event happened
# <event> on <date> - Set the date the event happened (yyyy-mm-dd)
# how long since <event>? - Display the number of days since the event
module.exports = (robot) ->
robot.respond /(.*?) on ((19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))/, (msg) ->
event = msg.match[1]
date = new Date(msg.match[2])

AccessibleFor: key-based hash sanitizer for Ruby

This is a simple mass-assignment security module loosely based on [ActiveModel::MassAssignmentSecurity][1]. It attempts to steal the good ideas and some of the API while being compatible with Rails 2.3-based applications.

Only attr_accessible (or its equivalent, keep reading) is implemented, because attr_protected is just a bad ActiveRecord API that hung around for some reason, and we don't want it stinking up the place.