Skip to content

Instantly share code, notes, and snippets.

View domgetter's full-sized avatar

Dominic Muller domgetter

View GitHub Profile
pascal = Enumerator.new do |y|
a = [1,1]
y << [1]
y << [1,1]
loop do
y << a = [1,(a.each_cons(2).map {|p| p[0]+p[1]}),1].flatten
end
end
1
512
130816
22238976
2830007680
287548742912
24300687609984
1756899020502400
110931407479018176
6214192137669063424
@domgetter
domgetter / even_fib.rb
Last active August 29, 2015 14:23
AKA: Making your own enumerators is awesome
def even_fib(m)
return 0 if m <= 2
even_fibs = Enumerator.new do |yielder|
a, b, c = 1, 0, 1
loop do
yielder << (a, b, c = 3*a + 2*b, 3*b + 2*c, 2*b + c)[1]
end
end
@domgetter
domgetter / more_enumeration.rb
Created June 13, 2015 12:43
What in the world have I done?
module Enumerable
def until(&block)
sofar = []
each do |element|
ret = block.call(element)
break if ret
sofar << element
end
sofar
end
@domgetter
domgetter / list_monad.rb
Created June 5, 2015 12:22
List Monad (sort of) in Ruby
def f(a)
a + 2
end
def g(a)
3*a
end
def h(a)
a - 7
@domgetter
domgetter / bytes_to_utf8.rb
Last active August 29, 2015 14:21
How to turn any list of bytes into the unicode character encoding in Ruby.
def dec_to_binary_string(number)
number.to_s(2).rjust(8,"0")
end
def leader_byte?(byte)
!(byte[0].eql?("0") || byte[0..1].eql?("10"))
end
def utf8_to_binary_string(char_array)
char_array.map { |byte| byte[(byte.index("0")+1)..-1] }.join
@domgetter
domgetter / mandelbrot.rs
Created May 25, 2015 12:31
Mandelbrot implemented recursively in Rust
fn mandel(e: f64, f: f64, a: f64, b: f64, its: u64, dwell: u64) -> u64 {
if e > 4f64 || its >= dwell {
its
} else {
mandel(e*e + f*f + a, 2f64*e*f + b, a, b, its + 1, dwell)
}
}
fn mandelbrot(a: f64, b: f64) -> u64 {
mandel(0f64,0f64,a,b,0,12918) // > 12918 blows the stack. LLVM not TCO :(
@domgetter
domgetter / roadmap
Last active August 29, 2015 14:21 — forked from odaba/roadmap
I don't have a good name for it yet, webstorage git?
I want it to be kinda up-and-running for v0.1, so major sections are omitted intentionally.
basics:
config: object: key/val -> preference/state
{ 'branchname': 'master' }
tags: object: key/val -> tagname/(commit/tree/blob)hash
{ 'head': '' }
directory: object: key/val -> fullpathfilename/contents
{}
@domgetter
domgetter / practices.txt
Last active August 29, 2015 14:21
Programming Language Documentation Best Practices
Documentation Best practices
- Consider your audience.
- Beginners and experts alike come to the docs.
- Readability.
- Make sure that the presentation of information aligns with the context.
- In a list of methods to a module, embolden the method name.
- make the examples syntax highlighted
- put a line or other visible separator between elements of a list.
- as a bonus, consider those browsing on different sizes of screens.
@domgetter
domgetter / non-unique-refs.txt
Last active August 29, 2015 14:21
non-unique refs
(Kuespert, 1990)
(Scheirer and Magoon, 2007)
(Scheirer and Magoon, 2007)
(Bowersox, 1990)
(Horton, et al., 2009)
(Horton et al., 1990)
(Schmidt and McDonald, 1979)
(Horton et al., 2009)
(Ali, 1981)
(California Division of Oil and Gas, 1998)