Skip to content

Instantly share code, notes, and snippets.

View gnurag's full-sized avatar

Anurag gnurag

  • Red Hat, Inc.
  • Far far away land
View GitHub Profile
#!/usr/bin/env ruby
require 'net/http'
require 'rss'
if ARGV.length.zero?
puts "Usage: twit.rb [twitter_handle]"
exit
end
@gnurag
gnurag / trace.rb
Created December 14, 2011 19:08
Tracing ruby programs with set_trace_func
set_trace_func proc { |event, file, line, id, binding, classname|
printf "%28s %8s %s:%-2d %10s %8s\n", Time.now, event, file, line, id, classname
}
puts "*** Hello World\n"
@gnurag
gnurag / votes.rb
Created December 29, 2011 08:36
Sorts and prints highest votes pics.
# Paste all the urls (newline separated) into a file named "urls" in the following format.
# [http://www.flickr.com/photos/example/123456789]
u = File.open('urls').readlines
h = {}
u.each{|url| url.strip!; h[url].nil? ? h[url]=1 : h[url]+=1 }
h.sort{|a,b| a[1] <=> b[1]}.reverse.each{|x| puts "#{x[0].chomp} => #{x[1]}"}
@gnurag
gnurag / userdir.conf
Created April 18, 2012 12:35
Setting up UserDir on Nginx
# userdir simulation
location ~ /~([^/]+)($|/.*)$ {
alias /home/$1/public_html$2;
error_page 404 = @404;
autoindex on;
}
location @404 {
return 404;
}
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@gnurag
gnurag / gist:3897763
Created October 16, 2012 07:25
Capfile
set :application, "brogram"
# more configs
set :deploy_to, "/deploy/path/webapps/#{application}"
set :shared_path, "#{deploy_to}/shared"
set :etc_path, "/etc/brogram"
# more configs
@gnurag
gnurag / test_rogit.rb
Created April 12, 2013 06:48
Experiment to study Grit's behavior on a readonly filesystem.
#!/usr/bin/env ruby
require 'grit'
require 'test/unit'
REPO_PATH = ARGV[0]
if ARGV.empty?
puts "Usage: test_rogit.rb [PATH_TO_GIT_REPO]"
exit
@gnurag
gnurag / auto_test.py
Created May 3, 2013 12:18
Auto adding tests.
import unittest
class AutoTest(unittest.TestCase):
def check(self, x, y):
self.assertEquals(x, y)
for x in xrange(0,4):
for y in xrange(0, 4):
def lcheck(x, y):
return lambda self: self.check(x, y)
#!/usr/bin/env ruby
tag1 = ARGV[0]
tag2 = ARGV[1]
cmd=`git log #{tag1}..#{tag2} --pretty='format:%ci::%an <%ae>::%s'`
list = {}
list_order = []
cmd.split("\n").each do |l|
date, author, subject = l.chomp.split("::")
date, time, zone = date.split(" ")
@gnurag
gnurag / treetop-mode.el
Created June 7, 2013 20:31
treetop-mode.el --- Major mode for editing Treetop files
;;; treetop-mode.el --- Major mode for editing Treetop files
;; Copyright (C) 1994, 1995, 1996 1997, 1998, 1999, 2000, 2001,
;; 2002,2003, 2004, 2005, 2006, 2007, 2008
;; Free Software Foundation, Inc.
;; Author: Anurag Patel
;; Adapted from original work by: Yukihiro Matsumoto, Nobuyoshi Nakada
;; URL: http://www.emacswiki.org/cgi-bin/wiki/TreetopMode
;; Created: Fri Jun 8 02:01:00 IST 2013