Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
@mark
mark / array_methods.rb
Created July 26, 2011 17:47
New array methods
class Array
def hashify
Hash.new.tap do |hash|
each { |obj| hash[obj] = yield(obj) }
end
end
def reverse_hashify
Hash.new.tap do |hash|
Topic
- [ ] Code Katas
- [ ] Find all the unique sequences of digits, like [1, 1, 2, 3, 8] that have the following properties:
Each element of the sequence is a digit between 1 and 9
The digits add to 15
There is at least digit that appears exactly twice
No digit appears more than twice
Order is irrelevant [1, 1, 2, 3, 8] and [1, 3, 2, 1, 8] are the same sequence and only count once.
I believe the original problem did specify that there are 38 sequences that match.
- [ ] Bowling Scores
@mark
mark / subsets.rb
Created September 21, 2011 15:50
Different ways of generating subsets of a Ruby array
require 'benchmark'
require 'test/unit'
class Array
def map_with_index
ary = []
each_with_index { |elt, i| ary << yield(elt, i) }
ary
end
@mark
mark / gist:1265415
Created October 5, 2011 19:31 — forked from zobar/gist:1265410
select:
applicants:
- cas_id
- last_name
- first_name
designations:
- date_locked
statuses:
- name
join:
@mark
mark / gist:1389177
Created November 23, 2011 16:46
Who needs if/then/else statements?
class Object
def truthy
self && yield
self
end
def falsy
self || yield
self
@mark
mark / gist:1730601
Created February 3, 2012 15:08 — forked from anonymous/gist:1730590
git config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@git.amsapps.com:cpi2.git
[branch "master"]
remote = origin
def foo
1
end
def meth(arg)
"Arg = #{ arg }"
end
def same_line
foo = meth foo
@mark
mark / psr.rb
Created March 9, 2012 15:22
Paper Scissors Rock
def evaluate_game(game)
"PSRP"[ "#{ game[0][1] }#{ game[1][1] }" ] ? game[1] : game[0]
end
def report_game(game)
puts "#{ game[0][0] } vs. #{ game[1][0] }"
puts "\tWinner = #{ evaluate_game(game)[0] }\n\n"
end
paper1 = [ "Papa Err", "P" ]
<!DOCTYPE html>
<head>
<title>and my axe</title>
<style type="text/css">
* { text-align: center; }
a {
text-decoration: none;
color: #000;
}
h1 {
@mark
mark / send_key_path.rb
Created April 3, 2012 17:49
Send an array of method names
class Object
def send_key_path(key_path)
key_path.inject(self) { |current, method| current.send(method) }
end
end
class Foo
def bar