Skip to content

Instantly share code, notes, and snippets.

@cronin101
cronin101 / y.rb
Last active August 29, 2015 13:56
Y Combinator example in Ruby
def apply_lots(function: ->(x) { x }, times: 1, initial: nil)
y_combinator = ->(f) {
->(x) { x.(x) }.(
->(x) { f.(->(*v) { x.(x).(*v) }) }
)
}
times_step = ->(partial_fn) {
->(fn, rem, acc) { rem.zero? ? acc : partial_fn.(fn, rem - 1, fn.(acc)) }
}
@cronin101
cronin101 / product.rb
Last active August 29, 2015 13:56
Array#Product
people = %i{Jacob James Maithu}
# => [:Jacob, :James, :Maithu]
bike_colours = %i{Red Black White}
# => [:Red, :Black, :White]
helmet_choices = [true, false]
# => [true, false]
people.product(bike_colours, helmet_choices).map do |p, c, h|
@cronin101
cronin101 / filter.clj
Last active August 29, 2015 13:56
I have no idea what I am doing
(defn my_even? [n]
(= 0 (rem n 2)))
(defn my_filter [test_fn input_list]
(defn recstep [remaining_input acc]
(if (= 0 (count remaining_input))
acc
@cronin101
cronin101 / y_com.clj
Last active August 29, 2015 13:56
Y Combinator Example in Clojure
(defn Y [f]
((fn [x] (x x))
(fn [x]
(f (fn [& args]
(apply (x x) args))))))
;; Recursive step for apply_lots function:
; Return accumulator if no iterations remaning otherwise call self with modified stack.
(defn lots_step [partial_fn]
(fn [f r a]
@cronin101
cronin101 / smj.py
Last active August 29, 2015 13:57
Sort-Merge Join, from ADBS Lecture 10
class MergeJoiner(object):
def __init__(self, input_a, input_b):
self.input_a, self.input_b = input_a, input_b
def joined(self):
# Using relation names from slides
R, S = self.input_a[:], self.input_b[:]
join = []
@cronin101
cronin101 / ruby_developers.rb
Last active August 29, 2015 13:57
What is scope? Baby don't hurt me.
main ⭔ magic_word = 'boomstick'
#=> "boomstick"
main ⭔ String.class_eval { define_method(:say_the_magic_word) { puts magic_word } }
#=> :say_the_magic_word
main ⭔ "wat".say_the_magic_word
#> boomstick
#=> nil
@cronin101
cronin101 / decorator_assertions.rb
Last active August 29, 2015 13:57
Test Driven Definition: Behaviour assertions in decorators example.
def must_contain_plus meth
raise unless RubyVM::InstructionSequence.disasm(method(meth)).include? 'opt_plus'
meth
end
must_contain_plus(
def add(x, y)
x + y
end)
#=> :add
@cronin101
cronin101 / codez.rb
Last active August 29, 2015 13:57
yum, code generation.
main ⭔ (1..100)[Int].map { |x| x + 10 }.map { |y| y * y}.filter { |x| x.even? }.filter { |y| y < 200 }[Fixnum]
#[2014-03-23 14:44:27 +0000] Simplify!: Simplified from [["x = x >> 1", "x = x + 10", "x = x * x"], ["x = x + 10"], ["x = x * x"], ["((x % 2 == 0)) && (x < 200)"], ["x < 200"], ["x = (x << 1) | 0x01"]], to [["x = x >> 1", "x = x + 10", "x = x * x", "?{((x % 2 == 0)) && (x < 200)}?", "x = (x << 1) | 0x01"]].
#[2014-03-23 14:44:27 +0000] Executing filter kernel:
# __kernel void hadopemappingfilter7(__global int *data_array, __global int *presence_array) {
# int x;
# int global_id = get_global_id(0);
# x = data_array[global_id];
#
# x = x >> 1;
# x = x + 10;
@cronin101
cronin101 / rspec.txt
Created March 23, 2014 20:01
rpsec --format documentation
Hadope
Showcasing features
can complete an Integer pipeline computation
can complete a Double pipeline computation
returns the correct result
can #zip and #braid
Top level namespace
is defined
Devices
@cronin101
cronin101 / hints.md
Last active August 29, 2015 13:57
Hints possibly required for user evaluation task.

##Initiating a RubiCL computation pipeline To start a pipeline, annotate the dataset with the corresponding C-type. This is done using the square bracket notation shown below. All questions in the evaluation will use integers.

# Array support
big_array_of_numbers = [1, 2, 3, 4]
big_array_of_numbers[Int].further.method.calls.go.here