This file contains hidden or 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
# encoding: UTF-8 | |
%w{mechanize pp mongo peach}.each { |x| require x } | |
include Mongo | |
@agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } | |
@coll = MongoClient.new('localhost', 27017)['google']['cities'] | |
def states_in page | |
page.links.reject {|l| l.to_s.length > 2 || l.to_s.empty?} |
This file contains hidden or 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
#!/bin/bash | |
export LC_ALL=en_US.UTF-8 | |
sudo apt-get --yes update | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 | |
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen | |
sudo apt-get --yes --fix-missing install lbzip2 pigz mongodb language-pack-en ruby-full build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config tcptrack | |
reboot | |
#While logged on | |
cd /usr/local/bin |
This file contains hidden or 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
#Now when tar**iping, you can do it in parallel! Like a boss. | |
sudo apt-get install lbzip2 pigz | |
cd /usr/local/bin | |
sudo ln -s /usr/bin/lbzip2 bzip2 | |
sudo ln -s /usr/bin/lbzip2 bunzip2 | |
sudo ln -s /usr/bin/lbzip2 bzcat | |
sudo ln -s /usr/bin/pigz gzip |
This file contains hidden or 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
#They have really stupid encoding, and Ruby's CSV parser is equally as retarded. | |
#This script won't generate cleanest data because I'm ignoring whatever encoding they're using, but it's okay to insert into Mongo. | |
require 'pp' | |
require 'mongo' | |
require 'iso_country_codes' | |
require 'parallel' | |
class Maxmind | |
include Mongo |
This file contains hidden or 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
screen -L | |
wget http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz | |
gunzip worldcitiespop.txt.gz | |
mv worldcitiespop.txt worldcitiespop.csv | |
ruby -e " | |
require ENV['HOME']+'/maxmind_csv_to_mongo.rb' | |
puts Maxmind.new('worldcitiespop.csv').parallel_dump_into_database | |
" |
This file contains hidden or 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
#For Growth Hacking Services/Consulting, feel free to shoot me an Email :) | |
#Author: Demetrius Michael | |
#Contact: arrrwalktheplank (at) gmail.com | |
#http://www.demetriusmichael.com/ | |
require 'mechanize' | |
require 'peach' | |
require 'pathname' | |
def get_images_from_ page |
This file contains hidden or 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
#Demetrius Michael | |
#[email protected] | |
require 'require_all' | |
require_all './lib/' | |
require 'string_scorer' | |
require 'active_support/core_ext/string' | |
require 'pp' | |
require 'parallel' |
This file contains hidden or 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 File.expand_path('../../../load_paths', __FILE__) | |
require "active_record" | |
require 'benchmark/ips' | |
TIME = (ENV['BENCHMARK_TIME'] || 20).to_i | |
RECORDS = (ENV['BENCHMARK_RECORDS'] || TIME*1000).to_i | |
conn = { adapter: 'sqlite3', database: ':memory:' } | |
ActiveRecord::Base.establish_connection(conn) |
This file contains hidden or 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
#instead of writing | |
def square number | |
number * number | |
end | |
#you can write | |
square = lambda {|number| number * number} | |
#or | |
square = ->(number) {number * number} |
This file contains hidden or 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
def save_errors | |
yield | |
rescue => e | |
{error: e} | |
end | |
save_errors {raise('REALLY BIG MASSIVE ERROR')} #programmer | |
raise('REALLY BIG MASSIVE ERROR') rescue {error:$!} #hacker | |
raise('REALLY BIG MASSIVE ERROR') rescue nil #retard |