Skip to content

Instantly share code, notes, and snippets.

View D3MZ's full-sized avatar

Demetrius Michael D3MZ

View GitHub Profile
require 'httparty'
require 'pp'
API_KEY = 'string'
#outputs filesize in bytes
module StreetView
include HTTParty
def self.image location
File.open(ENV['HOME']+"/#{location}.jpeg", 'w') { |file| file.write get('http://maps.googleapis.com/maps/api/streetview', :query => {:size => '1200x1200', :location => location, key: API_KEY, sensor: false}) }
@D3MZ
D3MZ / scraping_ruby_tapas.rb
Created August 1, 2013 21:19
unnecessarily complicated, but W/E.
require 'mechanize'
require 'pp'
require 'logger'
require 'pry'
require 'youtube_it'
#This is a great lesson of overcoding, I started with RubyTapas's boiler plate code thinking it'll be faster to code
#on top of his own stuff. But it ended up being overkill and terribly verbose.
#Abstracting the session is not necessary in this case and a terrible amount of overhead for a simple script.
#Especially when I use "click" on Mechanize::Link class. Which uses the same fucking session anyway!
@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
@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}
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 / gov.rb
Last active December 19, 2015 07:59
#Demetrius Michael
#arrrwalktheplank@gmail.com
require 'require_all'
require_all './lib/'
require 'string_scorer'
require 'active_support/core_ext/string'
require 'pp'
require 'parallel'
#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 / 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
"
@D3MZ
D3MZ / lbzip_symlink.sh
Created April 12, 2013 00:18
Parallel *zip