Skip to content

Instantly share code, notes, and snippets.

View D3MZ's full-sized avatar
😎

Demetrius Michael D3MZ

😎
View GitHub Profile
@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
# 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?}
@coll = MongoClient.new('localhost', 27017)['db_name']['collection_name']
already_emailed = Array.new
@coll.find("$and"=>[{"email"=>{"$not"=>{"$in"=>already_emailed}}},{"email"=>{"$exists"=>true}}])
@D3MZ
D3MZ / haystackdb.rb
Last active December 11, 2015 03:58
Export Mongo to AWS Cloud Search
require 'mongo'
require 'pp'
require 'json'
class HaystackDB
include Mongo
def initialize
mongo = MongoClient.new('localhost', 27017)['twitter']
@whois = mongo['whois']
end
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
# create a table (50 read and 50 write capacity units)
# create primary key index using hash_key (:id)
#table = dynamo_db.tables.create("tweets", 10, 5,
# :hash_key => { :user_id => :number },
# :range_key => { :created_at => :number })
@D3MZ
D3MZ / git
Created December 11, 2012 19:38
Git giving you headaches? Scrap it all.
git fetch --all
git reset --hard origin/master
@D3MZ
D3MZ / fix
Created December 7, 2012 16:45
Oh my zsh breaks RVM. Great what else is new?
1. open ~/.zshrc in your favorite editor
2. change "export PATH=/path/to/something" to "export PATH=$PATH:/path/to/something"
@D3MZ
D3MZ / inline-ruby.html.erb
Created December 5, 2012 03:18
More HAML goodness
<% if @user.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@user.errors.count, "error") %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
@D3MZ
D3MZ / gunzip_recursive.sh
Created December 4, 2012 06:26
How to gunzip files recursively inside folders
find . -name "*.gz" -exec gunzip {} \; -exec /bin/rm {} \;
@D3MZ
D3MZ / delete_empty.sh
Created December 4, 2012 06:19
Delete Empty Folders
find . -type d -empty -exec rmdir {} \;