Skip to content

Instantly share code, notes, and snippets.

View arjunvenkat's full-sized avatar

Arjun Venkataswamy arjunvenkat

View GitHub Profile
@arjunvenkat
arjunvenkat / gist:4075116
Created November 14, 2012 21:56
ruby challenge wk 7
# Gene Sequencing
# Given an input array and a test array, create a method that takes in
# two arrays as inputs, named 'input' and 'test,' respectively.
# 'input' is an array of any number of letters
# 'test' is an array of 4 letters
# The method returns 'match!' if the 'test' array is found inside the
# 'input' array and returns 'no match =(' if the 'test' array is not found
# Bonus: Try to make the script work even if your test sequence is reversed
@arjunvenkat
arjunvenkat / benfords_data.rb
Last active October 13, 2015 09:57
Benfords Data
# Try to figure out which dataset is real and which dataset is fake
# Hint: http://en.wikipedia.org/wiki/Benford's_law
data1 = ["2", "3", "8", "1", "3", "1", "8", "599", "1", "5", "7", "7", "8", "7", "6", "1", "1", "1", "5", "596", "7", "1", "7", "1", "1", "1", "7", "2", "1", "4", "542", "7", "1", "1", "3", "3", "2", "1", "7", "2", "2", "510", "1", "1", "1", "2", "2", "1", "3", "2", "557", "7", "2", "7", "2", "1", "7", "7", "5", "7", "2", "595", "2", "1", "4", "3", "2", "1", "2", "8", "1", "563", "2", "1", "3", "2", "2", "2", "7", "1", "569", "7", "1", "1", "1", "2", "3", "7", "538", "3", "2", "2", "3", "2", "3", "3", "1", "1", "8", "40239", "502", "5", "9", "1", "1", "7", "1", "8", "7", "568", "1", "2", "1", "1", "7", "1", "2", "7", "1", "2", "501", "1", "8", "7", "2", "1", "2", "1", "1", "1", "2", "509", "9", "2", "1", "1", "2", "2", "7", "1", "2", "541", "2", "2", "1", "8", "1", "2", "2", "2", "3", "525", "2", "7", "1", "1", "3", "2", "2", "1", "1", "479", "3", "2", "1", "8", "2", "3", "2", "2", "5", "2",
@arjunvenkat
arjunvenkat / scraper_lab_p1.rb
Created December 12, 2012 17:07
build a scraper using Nokogiri
# nokogiri requires open-uri to work properly
require 'nokogiri'
require 'open-uri'
# Putting it all together
# ===============================================
# initialize a url and feed into Nokogiri
url = "http://www.rottentomatoes.com/m/lincoln_2011/"
doc = Nokogiri::HTML(open(url))
@arjunvenkat
arjunvenkat / scraper_lab_p2.rb
Created December 12, 2012 17:48
scrape multiple pages using Nokogiri and Mechanize
# nokogiri requires open-uri
require 'nokogiri'
require 'open-uri'
# csv will be used to export data
require 'csv'
require 'mechanize'
# pp is useful to display mechanize objects
require 'pp'
@arjunvenkat
arjunvenkat / chord_scraper.rb
Created December 12, 2012 19:02
scraper to save chord information for songs on ultimate guitar
require 'open-uri'
require 'csv'
require 'Mechanize'
require 'awesome_print'
# letter_array = ['0-9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
# 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
# 'u', 'v', 'w', 'x', 'y', 'z']
letter_array = ['b']
letter_array.each do |letter|
@arjunvenkat
arjunvenkat / apprenticeship_scraper.rb
Created December 12, 2012 19:03
scraper to save apprenticeship info from department of labor site
namespace :apprenticeships do
desc "scrapes DOL site for apprenticeship data by state"
task :scrape => :environment do
require 'mechanize'
require 'open-uri'
require 'csv'
apprenticeships_in_state_array = []
# states = ["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","WI","WY"]
@arjunvenkat
arjunvenkat / gist:4954307
Created February 14, 2013 17:05
challenge so far
class DrawShape
def line(user_num=9)
"*" * user_num
end
def number_line(input)
input.times do |number|
print number unless number == 0
end
end
@arjunvenkat
arjunvenkat / gist:4954644
Created February 14, 2013 17:50
Draw shape challenges
class DrawShape
def line(user_num=9)
"*" * user_num
end
def number_line(input)
input.times do |number|
print number unless number == 0
end
end
@arjunvenkat
arjunvenkat / reddit_scraper.rb
Last active December 14, 2015 06:28
first and second part of the scraper lab. We scraped data from craigslist and saved it into a csv file
require 'open-uri'
require 'nokogiri'
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://www.reddit.com/')
count = 0
# prints out the first link for the first five pages
@arjunvenkat
arjunvenkat / gist:5222129
Created March 22, 2013 15:25
KeyRemap4Macbook private.xml content
<?xml version="1.0"?>
<root>
<item>
<name>Remap Right Option to Hyper</name>
<appendix>OS X doesn't have a Hyper. This maps Right Option to Control + Shift + Option + Command.</appendix>
<identifier>space_cadet.right_option_to_hyper</identifier>
<autogen>
--KeyToKey--