Skip to content

Instantly share code, notes, and snippets.

View theotherzach's full-sized avatar

Zach Briggs theotherzach

View GitHub Profile
@theotherzach
theotherzach / gist:3739279
Created September 17, 2012 19:31
OSX Hbase/ Pig/ JRuby setup
Note:
This is the bare minimum to get hbase, pig, and JRuby talking. Follow the link for further configs.
brew doctor
brew install hadoop
brew install hbase
brew install pig
in your .zshrc (or .bash_profile if you insist on BASH)
class Comment < ActiveRecord::Base
attr_accessible :subject, :body, :category, :reply_to
belongs_to :user
has_many :replies, :class_name => 'Comment',
:foreign_key => 'reply_to'
has_many :tags
scope :root, -> { where("reply_to = ?", 0 }
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xvzf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure
make
make install
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
source ~/.bashrc
@theotherzach
theotherzach / app.js
Created February 16, 2013 19:40
2 route hello world Ember App
var App = Ember.Application.create();
//Router
App.Router.map(function () {
this.resource('tables');
});
App.TablesRoute = Ember.Route.extend({
model: function () {
return App.Table.find();
class RockScore
NoScore = Class.new
def self.for_term(term)
positive = SearchEngine.count_results(%{"#{term} rocks"}).to_f
negative = SearchEngine.count_results(%{"#{term} sucks"}).to_f
score = 10 * positive / (positive + negative)
score.nan? ? NoScore : score
end
end
@theotherzach
theotherzach / .vimrc
Created February 25, 2013 22:28
vim setup packages: pathogen, rails-vim, ruby-vim, ctrlp, vim-commentary
call pathogen#runtime_append_all_bundles()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC EDITING CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
" allow unsaved background buffers and remember marks/undo for them
set hidden
" remember more commands and search history
set history=10000
@theotherzach
theotherzach / first_names.rb
Last active December 14, 2015 11:28
Find the first name
names = ['Last, First M', 'Last,First!@#$']
def word_after_comma
/(?<=[,])(\s?)(\w*)/
end
first_names = names.map { |x| x.slice(word_after_comma).strip }
#=> ["First", "First"]
path = "#{Rails.root}/config/mysweetconfig.yml"
configfile = YAML.load_file(path)[Rails.env]
MySweetModule::MySweetClass.setup do |config|
config.host = configfile['host']
config.port = configfile['port']
config.database = configfile['database']
end
config = YAML.load_file(path)
# => {"ip" => "0.0.0.0", "port" => "3000"}
# each_with_object for 1.9+
config.each_with_object({}) { |(k,v),memo| memo[k.to_sym] = v }
# => {:ip=>"0.0.0.0", :port=>"3000"}
# inject for 1.8
config.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
# => {:ip=>"0.0.0.0", :port=>"3000"}
@theotherzach
theotherzach / 20130310141955_add_hstore_extension.rb
Last active May 29, 2020 17:30
Rails 4 and Postgres: Getting HStore and Array
class AddHstoreExtension < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION hstore'
end
def down
execute 'DROP EXTENSION hstore'
end
end