Skip to content

Instantly share code, notes, and snippets.

@mzemel
mzemel / reddit.rb
Created June 29, 2013 05:38
Reddit upvote bot
#This script requires ruby and the watir-webdriver gem (http://watirwebdriver.com/)
#When you enter a username, it will upvote all of their comments/posts
#You may get IP-banned
require 'watir-webdriver'
puts "Please enter a user"
user = gets
user.chomp!
require 'watir-webdriver'
puts "Please enter a user"
user = gets
user.chomp!
profile = Selenium::WebDriver::Firefox::Profile.new
#profile.proxy = Selenium::WebDriver::Proxy.new :http => '127.0.0.1:8118'
b = Watir::Browser.new :firefox, :profile => profile
@mzemel
mzemel / hs_cityscraper.sh
Created July 2, 2013 01:57
Gets all cities (messy)
#!/bin/bash
for a in {a..z}
do
for b in {a..z}
do
q=$a$b
curl "http://www.homeseekers.com/Include/AJAX/MapSearch/GetLocations.aspx?q="$q"&type=city" >> cities.txt
done
done
@mzemel
mzemel / hs_citycleaner.rb
Created July 2, 2013 01:58
Messily cleans cities
cities_array = IO.readlines('cities.txt')
cities_array.each do |entry|
entry.gsub!("\\n","")
entry.gsub!("{\"Name\":\"","")
entry.gsub!(/\",\"Type\":\"City\",\"BID\":null,\"City\":null,\"State\":\"..\"}/,"")
entry.gsub!("][","],[")
end
cities_array = cities_array.first.split(",").select{ |i| i != "[]" }
cities_array.each do |city|
city.gsub!("[","")
10.times do
@rate ||= 0.0
start_time = Time.now.to_i
start_count = Property.external.count.to_f
sleep rand(30..60)
end_time = Time.now.to_i
end_count = Property.external.count.to_f
properties_per_second = ((end_count - start_count) / (end_time - start_time) )
@rate += properties_per_second
end
@mzemel
mzemel / hangman.rb
Created July 14, 2014 03:52
Hangman program
# Let's play hangman!
module HangmanErrors
class YaDunGoofedError < StandardError; end
class HolyShitYouWon < StandardError; end
end
class TheGame
include HangmanErrors
attr_accessor :round
@mzemel
mzemel / meta.rb
Created September 26, 2014 21:01
META
methods = ['foo', 'bar', 'baz']
methods.each do |method_name|
define_method(method_name) do |arg|
puts arg.upcase
end
end
foo("hi")
# => HI
@mzemel
mzemel / send.rb
Created September 26, 2014 21:45
class Person
attr_accessor :name, :age, :weight
def initialize(hash)
hash.each do |key, value|
setter_method = key.to_s + "="
send(setter_method, value)
end
end
end
@mzemel
mzemel / sinatra.rb
Created October 3, 2014 18:16
Sinatra Example
# gem install sinatra
# sinatra.rb
require 'rubygems'
require 'sinatra'
get "/" do
"This is the main page"
end
@mzemel
mzemel / attr_accessor.rb
Created October 4, 2014 06:50
Implementation of attr_accessor
module Fatter
def self.included(base)
base.class_eval do
def self.fattr_accessor(_symbol)
raise "NotASymbol" unless _symbol.is_a? Symbol
ivar_as_symbol = ("@" + _symbol.to_s).to_sym
define_method(_symbol.to_s) do
self.instance_variable_get(ivar_as_symbol)
end