Skip to content

Instantly share code, notes, and snippets.

View D3MZ's full-sized avatar

Demetrius Michael D3MZ

View GitHub Profile
@D3MZ
D3MZ / railcasts_episodes.rb
Created November 14, 2012 22:37
grab links for railcasts episodes
require 'mechanize'
@agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
url = "http://railscasts.com/episodes/13-dangers-of-model-in-session"
page = @agent.get url
links = []
while page.link_with(:text => /next/i)
break if page.search("//*[@id=\"episode\"]/div[1]/ul/li[2]/a").first.nil?
links << page.search("//*[@id=\"episode\"]/div[1]/ul/li[2]/a").first.attributes["href"].value
page = page.link_with(:text => /next/i).click
@D3MZ
D3MZ / application.html.erb
Created December 3, 2012 03:10
Haml rocks.
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
@D3MZ
D3MZ / delete_empty.sh
Created December 4, 2012 06:19
Delete Empty Folders
find . -type d -empty -exec rmdir {} \;
@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 / 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 / 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 / git
Created December 11, 2012 19:38
Git giving you headaches? Scrap it all.
git fetch --all
git reset --hard origin/master
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 / 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
@coll = MongoClient.new('localhost', 27017)['db_name']['collection_name']
already_emailed = Array.new
@coll.find("$and"=>[{"email"=>{"$not"=>{"$in"=>already_emailed}}},{"email"=>{"$exists"=>true}}])