Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# You need stereovision package to run this. Try "sudo pip install stereovision"
import cv2
from stereovision.blockmatchers import StereoBM, StereoSGBM
from stereovision.calibration import StereoCalibration
from stereovision.stereo_cameras import CalibratedPair
from stereovision.ui_utils import STEREO_BM_FLAG, BMTuner
jQuery.ajax({
type: "GET",
url: "http://www.geobeats.com/js/selectDropDown.js",
data: "cachePreventor=1918606547",
async: false,
dataType: "text",
success: function(data){
var i = "new_cities_array = []; _gbstr = ''; \n";
var f1 = "function addListGroup(a,b){}\n";
var f2 = "function addList(a,b,c,d){ if(a == 'country-place' && b != 'Destination') {var splits = b.split(' - '); new_cities_array.push(splits[1] + ' - ' + splits[0]); _gbstr += (\"<br/>\" + b);} }\n";
@nileshtrivedi
nileshtrivedi / patch for enum fields in scaffolding_extensions.rb
Created July 24, 2009 09:32
Patch scaffolding_extensions gem for supporting enum fields
# The patch
# In the scaffold_field_tags method in helper.rb
when :enum
# array of select options will be passed in the options hash for this column
select_options = options[:select_options] || []
# each item in select_options is like [ option_label, option_value ]
s = {value.to_s => "selected='selected'"}
options.delete :select_options #we don't want to show this as an attribute in the generated HTML
"<select #{scaffold_options_to_html(options)}><option></option>#{select_options.collect{|o| "<option value='#{o[1]}' #{s[o[1]]}>#{o[0].to_s}</option>"}.join}</select>"
@nileshtrivedi
nileshtrivedi / Scraping fun with Google, Flipkart and Ruby.rb
Created December 1, 2010 18:43
Scraping fun with Google, Flipkart and Ruby
require 'net/http'
require 'uri'
require 'csv'
google_url = "http://www.google.com/search?q=%22public+wishlist%22+site:flipkart.com&hl=en&site=webhp&prmd=iv&ei=ZYL2TOr3KYLyrQfv4dzWBg&start=NNNN&sa=N&fp=1b624545158a7512&tch=1&ech=1&psi=MX_2TOSlL82BrQegxqDYBg129122283549813"
File.open("flipkart-public-wishlists.txt","w") { |f|
(0..54).to_a.each { |page|
puts "scraping page #{page} from google web search"
start = page * 10
@nileshtrivedi
nileshtrivedi / scrape-indiantrains.org.rb
Created December 1, 2010 19:04
Scraping trains and stations list from indiantrains.org
require 'net/http'
require 'uri'
# Fetch list of all stations with their codes
File.open("all_stations.csv","w") { |f|
(?A..?Z).to_a.collect(&:chr).each { |c|
puts "Starting #{c}"
sleep(3) #wait for 3 seconds
uri = URI.parse("http://www.indiantrains.org/station-list/?navigate=" << c)
response = Net::HTTP.get_response(uri)
@nileshtrivedi
nileshtrivedi / syllogism.rb
Created December 1, 2010 20:47
syllogisms in ruby (incomplete)
class Syllogism
attr_accessor :first, :second, :relation, :matrix
def initialize(first_term,relation,second_term)
@first = first_term
@second = second_term
@relation = relation
@matrix = { @first => :unknown, @second => :unknown, :both => :unknown, :neither => :unknown }
@matrix = { @first => :absent, @second => :unknown, :both => :unknown, :neither => :unknown } if @relation == :all_are
@matrix = { @first => :unknown, @second => :unknown, :both => :present, :neither => :unknown } if @relation == :some_are
@matrix = { @first => :present, @second => :unknown, :both => :unknown, :neither => :unknown } if @relation == :some_are_not
@nileshtrivedi
nileshtrivedi / mmacmd.rb
Created February 12, 2011 21:03
Quick Ruby script to play a simple accompanying track on command-line using MMA
#!/usr/bin/env ruby
#Example usage: mmacmd.rb basicrock 120 4 Bm Bm A A G Em Bm Bm
#MMA Website is here: http://www.mellowood.ca/mma/index.html
groove = ARGV.slice!(0)
tempo = ARGV.slice!(0)
count = ARGV.slice!(0)
puts "Generating MMA file"
File.open("/tmp/mmaout.mma","w") { |f|
@nileshtrivedi
nileshtrivedi / jdbcmysql_adapter.rb
Created June 29, 2011 20:16
Make enum-column plugin for Rails work with JDBC MySQL adapter as well
module ActiveRecord
module ConnectionAdapters
class MysqlAdapter
alias __native_database_types_enum native_database_types
def native_database_types #:nodoc
types = __native_database_types_enum
types[:enum] = { :name => "enum" }
types
end
@nileshtrivedi
nileshtrivedi / symbolic.rb
Created October 11, 2011 15:38
Simple symbolic math implementation in Ruby (Work in progress)
# TODO
# if a var has a value, it also needs a name. This should not be necessary. Variable.initialize should accept hashargs
# Expression.to_s should output in infix-notation (like normal humans)
# add more syntactic sugar by manipulating Ruby Numeric classes. Add symbolic operators to Ruby's Numeric
# If symbolic expression contains variables without value then it should return nil (should it, really?)
# Implement additional operators like **
# All symbolic expression should be automatically simplified when created:
# cons(0) * x # => 0
# 2 + x + 1 # => x + 3
# -(x-y) + 2*x # => x + y
@nileshtrivedi
nileshtrivedi / deploy.rb
Last active January 16, 2016 21:01
Deploy a Play framework app with SSHKit
require 'sshkit'
require 'sshkit/dsl'
# Once "bundle install" has been run, this script can be run as "ruby deploy.rb staging" or "ruby deploy.rb prod"
if ARGV.first == "prod"
servers = ['deploy@prod1.example.com', 'deploy@prod2.example.com']
elsif ARGV.first == "staging"
servers = ['deploy@staging.example.com']
else