View gist:268add01dc4287553820
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// is there a way to make this an awesome for comprehension or whatever? | |
// or maybe a built in Map method to do what I want? ;p | |
val codes: List[String] = ... | |
val configs: Map[String, Configuration] = ... | |
val defaultConfig: Configuration = ... | |
val config: Configuration = codes | |
.find(configs.contains) // find the first code that the configs map contains | |
.flatMap(configs.get) // grab the config for that first code |
View request.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:name nil | |
:description nil | |
:email nil | |
:repositories {:count nil | |
:filters {:first {:count 50} | |
:after {:cursor 22046023}} | |
:edges {:cursor nil | |
:node {:id nil | |
:name nil | |
:full_name nil |
View stream.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn paged-http-get | |
([url] | |
(paged-http-get url 1)) | |
([url page] | |
(let [sink (s/stream)] | |
(d/loop [page page] | |
(d/chain (http-get url {:query-params {"page" page}}) | |
(fn [response] | |
(let [body (:body response)] | |
(if (seq body) |
View getter.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def graph {:roots {} :nodes {}}) | |
;; end up wit ha structure like this after adding a node | |
(def graph {:roots {} :nodes {'Organization {:fields {:id {}}}}}) | |
;; do I do this? | |
(let [field (get-in graph [:nodes 'Organization :fields :id])] | |
;; ... | |
) |
View gist:731468
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct foo { | |
float *stuff; | |
int offset; | |
float operator[](size_t i) const | |
{ | |
return stuff[i + offset]; | |
} | |
float &operator[](size_t i) |
View gist:969602
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scala's for comprehensions can be used like Haskell's do notation for monadic code, ie. its a compact way to string together computations sequentially. | |
val f = for { | |
a <- Future(10 / 2) // 10 / 2 = 5 | |
b <- Future(a + 1) // 5 + 1 = 6 | |
c <- Future(a - 1) // 5 - 1 = 4 | |
} yield b * c // 6 * 4 = 24 | |
val result = f.get() |
View gist:1016863
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventBus | |
def self.publish event args | |
@subscribers[event].each do |sub| | |
# whatever meta stuff sends event to method on object (handler) :p | |
end | |
end | |
def self.subscribe event, handler, method | |
@subscribers[event] = { :handler => handler, :method => method } |
View gist:1034701
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MessageBus | |
class MessageBus | |
@handlers = {} | |
def self.subscribe message, handler, method | |
@handlers[message] ||= [] | |
@handlers[message] << { :handler => handler, :method => method } | |
end | |
def self.send message, args |
View gist:1205296
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// controller | |
[CanViewProfile] | |
public ActionResult Show(int id) | |
{ | |
var view = new ShowProfileQuery(id).Execute(); | |
return View(view); | |
} | |
// before filter |
View attempt1.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// possibly tail recursive :p | |
open System.IO | |
// Seq.toList because I don't know how to pattern match an empty sequence :) | |
let folderWithDepth' path depth = | |
try | |
System.IO.Directory.EnumerateDirectories(path) |> Seq.toList |> List.map (fun d -> (d, depth)) | |
with | |
| _ -> [] |
OlderNewer