This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My attempt to implement a simple virtual machine with a minimal instruction set | |
# 8-bit computer, fixed-size memory, single cpu, 0-registers, based on von-neumann architecture | |
# No support for interrupts or I/O although we cheat and provide a "print" instruction :) | |
# The goal is to find a minimal, but turing-complete, instruction set | |
# For simplicity, every instruction has two operands, which are located adjacent to it in the memory | |
# This code is just to experiment with various instruction sets and not to be taken seriously | |
# Next fun step would be to develop a language/compiler for this virtual machine | |
class Memory | |
def initialize(size, program) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allows you to build a Hash in a fashion very similar to Builder. Example: | |
# Fork of https://gist.github.com/360506 by BrentD with some enhancements | |
# | |
# HashBuilder.build! do |h| | |
# h.name "Nilesh" | |
# h.skill "Ruby" | |
# h.skill "Rails" # multiple calls of the same method will collect the values in an array | |
# h.location "Udaipur, India" do # If a block is given, first argument will be set as value for :name | |
# h.location do | |
# h.longitude 24.57 |
OlderNewer