Skip to content

Instantly share code, notes, and snippets.

View defndaines's full-sized avatar

Michael S. Daines defndaines

View GitHub Profile
@defndaines
defndaines / curry-example.rb
Last active August 29, 2015 14:07
Ruby Curry Example
def three(a, b, c)
puts "a: #{a}, b: #{b}, c: #{c}"
end
def four(a, b, c, d)
puts "a: #{a}, b: #{b}, c: #{c}, d: #{d}"
end
three(:x, :y, :z)
# a: x, b: y, c: z
@defndaines
defndaines / curry-failure.rb
Last active August 29, 2015 14:07
Curry Failure
application_type = 'application/json; charset-utf-8'
request = AJAX.method(:get).to_proc.curry.(conn).(address).(application_type)
# … GET request to … failed.
# from …/ajax.rb:154:in `_request’
# from …/ajax.rb:31:in `get’
@defndaines
defndaines / curry-hope.rb
Created October 16, 2014 03:33
Curry Follow-on
parameters = { … }
response = request.(parameters)
@defndaines
defndaines / lambda-instead.rb
Created October 16, 2014 03:35
Using Lambdas Instead
if post
request = lambda { |p| AJAX.form_post(conn, address, p) }
else
request = lambda { |p| AJAX.get(conn, address, AJAX::CONTENT_TYPE::JSON, p) }
end
response = request.(parameters)
# ...
while # ...
# Change parameters
@defndaines
defndaines / fizz-buzz.clj
Last active August 29, 2015 14:09
Unconditional Fizz Buzz
; Inspired by https://twitter.com/gigasquid/status/530699466891067392 ...
; An implementation of the Fizz Buzz Kata with no conditionals.
(defn fb-gen
[step value]
(into (sorted-map) (zipmap (range step 101 step) (repeat value))))
(def nums (into (sorted-map) (zipmap (range 1 101) (range 1 101))))
(def threes (fb-gen 3 "fizz"))
(def fives (fb-gen 5 "buzz"))
(def fifteens (fb-gen 15 "fizzbuzz"))
@defndaines
defndaines / repl-next-link.clj
Created November 28, 2014 00:24
next-link Function for REPL
@defndaines
defndaines / next-link.clj
Created November 28, 2014 00:25
next-link Function for Light Table
resolve(Str) ->
lists:foldl(fun combine/2, [""], Str).
combine($?, Acc) ->
[E ++ [N] || E <- Acc, N <- "01"];
combine(C, Acc) ->
[E ++ [C] || E <- Acc].
(defn combine [acc e]
(if (= e \?)
(for [l acc n "01"] (conj l n))
(for [l acc] (conj l e))))
(defn translate [phrase]
(map #(apply str %)
(reduce combine [[]] phrase)))
package rtb.onezero;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
public final class Parser {
private static BiFunction<List<String>, Character, List<String>> appender