Skip to content

Instantly share code, notes, and snippets.

View shanlalit's full-sized avatar

Lalit Shandilya shanlalit

View GitHub Profile
module AssertionExtensions
def method_missing(method_id, *arguments, &block)
return super unless method_id.to_s =~ /^assert_(not_)?(.*)$/
method = "#{$2}?"
object = arguments.first
if $1
arguments.each do |object|
assert ! object.send(method), "#{method} is not false for #{object}"
#
# Usage:
# rake db:rollback_to_common branch=production
# git checkout -m production
# rake db:migrate
#
namespace :db do
desc 'Rolls back database to common migration state between current branch and another'
task :rollback_to_common do
FileUtils.cd(RAILS_ROOT) do
require 'net/http'
require 'uri'
require 'time'
class Time
def self.gcalschema(tzid) # We may not be handling Time Zones in the best way...
tzid =~ /(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)Z/ ? # yyyymmddThhmmss
# Strange, sometimes it's 4 hours ahead, sometimes 4 hours behind. Need to figure out the timezone piece of ical.
# Time.xmlschema("#{$1}-#{$2}-#{$3}T#{$4}:#{$5}:#{$6}") - 4*60*60 :
Time.xmlschema("#{$1}-#{$2}-#{$3}T#{$4}:#{$5}:#{$6}") :
@shanlalit
shanlalit / hax.js
Created April 16, 2009 16:04 — forked from wycats/hax.js
// Takes a bucket of behaviors and runs them with optional options.
//
// Example:
// $("div").setupExtras({fun: [function(options) {
// if(options.fun) console.log("OMG FUN");
// delete options.fun;
// }]}, options);
//
// The purpose of this method is to allow users to extend a plugin
// with additional behaviors that are potentially dependent on the
// Creating a new dialog plugin
var dialog = new $.Widget("<div class='dialog'></div>");
dialog.insertInto = "body";
dialog.listen({
open: function() {
if(dialog.state == "closed") {
dialog.show(); // Triggers another event
dialog.state = "open";
}
/*
On the page, there will be a number of tabs. Each of the tabs will correspond with a panel.
When a tab is selected, it becomes "active" -- the previously active tab becomes inactive.
When a tab becomes active, its associated panel is shown. When a tab becomes inactive, its
associated panel is hidden.
By default, the first tab is active when the tabs are created.
*/
var tabs = new $.Widget("ul.tabs");
def run_spellcheck(file,interactive=false)
if interactive
cmd = "aspell -p ./config/devver_dictionary -H check #{file}"
puts cmd
system(cmd)
[true,""]
else
cmd = "aspell -p ./config/devver_dictionary -H list < #{file}"
puts cmd
results = `#{cmd}`
namespace :tags do
task :generate do
puts 'Generating tags...'
require 'rubygems'
require 'jekyll'
include Jekyll::Filters
options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true