Skip to content

Instantly share code, notes, and snippets.

View D3MZ's full-sized avatar
😎

Demetrius Michael D3MZ

😎
View GitHub Profile
# 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?}
@D3MZ
D3MZ / ubuntu_setup.sh
Last active December 15, 2015 14:49
WIP
#!/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
@D3MZ
D3MZ / lbzip_symlink.sh
Created April 12, 2013 00:18
Parallel *zip
@D3MZ
D3MZ / maxmind_csv_to_mongo.rb
Last active December 16, 2015 06:19
Maxmind
#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
@D3MZ
D3MZ / maxmind_cloud_sequence.sh
Last active December 16, 2015 06:19
cloud script.
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
"
#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
@D3MZ
D3MZ / gov.rb
Last active December 19, 2015 07:59
#Demetrius Michael
#[email protected]
require 'require_all'
require_all './lib/'
require 'string_scorer'
require 'active_support/core_ext/string'
require 'pp'
require 'parallel'
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)
@D3MZ
D3MZ / lambda.rb
Last active December 20, 2015 06:09
#instead of writing
def square number
number * number
end
#you can write
square = lambda {|number| number * number}
#or
square = ->(number) {number * number}
@D3MZ
D3MZ / better_rescue.rb
Last active December 20, 2015 09:28
dollar bang good for rescue
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