Skip to content

Instantly share code, notes, and snippets.

@mgamba
mgamba / spark-shark-ec2
Last active December 22, 2015 04:08
spark/shark ec2
from http://aws.amazon.com/articles/4926593393724923
http://elasticmapreduce.s3.amazonaws.com/samples/spark/0.7.3/install-spark-shark.sh
elastic-mapreduce --create --alive --name "Spark/Shark Cluster" --bootstrap-action s3://elasticmapreduce/samples/spark/0.7.3/install-spark-shark.sh --bootstrap-name "Mesos/Spark/Shark" --instance-type m1.xlarge --instance-count 3
replace ec2-keypair in above command
commit to propagate credentials: https://github.com/amplab/shark/commit/70ddf149ea720fdfe76ae39cacbbac344be8402b
@mgamba
mgamba / hash pluck
Created February 10, 2014 23:35
method to pluck values from a hash
def hash_pluck(hash, keys)
HashWithIndifferentAccess[keys.zip(hash.values_at(*keys.map(&:to_s)))]
end
@mgamba
mgamba / waste cycles
Last active August 29, 2015 13:56
function to waste cycles
cycles = (wastefulness) ->
t1 = new Date
for x in [0..Math.pow(wastefulness,2)]
Math.pow(Math.random*Math.random)
(new Date) - t1
# >> cycles(100)
# 18
# >> cycles(1000)
@mgamba
mgamba / camelToSnake
Last active August 29, 2015 13:57
convert camelcase to snakecase in coffeescript
obj = {'someThing':'else',"BlahBlah":"bLah","sealTeam":6}
defaults = {'some_thing':'more',"seal_team":2}
camelToSnake = (s)->
s = s.replace /^([A-Z]+)/, (match) ->
if match.length == 1
match.toLowerCase()
else
"#{match.slice(0,match.length-1).toLowerCase()}_#{match.slice(match.length-1).toLowerCase()}"
s = s.replace /([A-Z]+)$/, (match) ->
@mgamba
mgamba / watch_functions.sh
Created March 22, 2014 20:30
os x doesn't have watch
function watch {
while sleep 1; do $@; done
}
function watchr {
while sleep 1; do if [ "$d" != "$(stat $1 | cut -d'"' -f4)" ];then echo && date && d=`stat $1 | cut -d'"' -f4` && ruby $1 ; fi; done
}
@mgamba
mgamba / beautiful_iterative.rb
Last active August 29, 2015 13:57
quick and dirty beautiful finder
#s = "ABCDEFABDC".split("")
s = "nlhthgrfdnnlprjtecpdrthigjoqdejsfkasoctjijaoebqlrgaiakfsbljmpibkidjsrtkgrdnqsknbarpabgokbsrfhmeklrle".split("")
ans = 'tsocrpkijgdqnbafhmle'
#s = "CABDBACBAB".split("")
#ans = "DCBA"
h = {}.tap do |h|
s.each_with_index do |c,i|
h[c] ||= []
h[c] << i
@mgamba
mgamba / beautiful_recursive.rb
Last active August 29, 2015 13:57
recursive version of beautiful string finder
#s = "ABCDEFABDC".split("")
s = "nlhthgrfdnnlprjtecpdrthigjoqdejsfkasoctjijaoebqlrgaiakfsbljmpibkidjsrtkgrdnqsknbarpabgokbsrfhmeklrle".split("")
ans = 'tsocrpkijgdqnbafhmle'
#s = "CABDBACBAB".split("")
#ans = "DCBA"
h = {}.tap do |h|
s.each_with_index do |c,i|
h[c] ||= []
h[c] << i
@mgamba
mgamba / .gitconfig
Last active August 29, 2015 14:00
git config file
[user]
name = <YOUR> <NAME>
email = <YOUR EMAIL>
[github]
user = <YOUR HANDLE>
[alias]
st = status
c = commit
ci = commit
b = branch
require 'rack-proxy'
require 'rack'
RemoteHostForName = {
'simple' => "localhost:4567"
}
class ExternalProxy < Rack::Proxy
def rewrite_env(env)
#request = Rack::Request.new(env)
require 'sinatra'
use Rack::CommonLogger
use Rack::Logger
require 'json'
post '/hi/there' do
request.logger.info JSON.pretty_generate(request.env)
"success\n"
end