Skip to content

Instantly share code, notes, and snippets.

@hamiltop
hamiltop / gist:0fc3dd68825536a06a24
Created August 12, 2014 21:53
Snippet of Elixir
Stream.interval(1000)
|> Stream.map fn(_) -> get_memory_usage end
|> Stream.chunk(60) # group every 60 seconds together
|> Stream.map &( {Enum.min(&1), Enum.max(&1)} )
|> Enum.each fn ({min, max) ->
send_to_graphite("min_memory_usage", min)
send_to_graphite("max_memory_usage", max)
end
defmodule Coercion do
defmacro get({:when, _, [path, {:is_integer, _, [{val, _, _}]}]}) do
{path, [{val, :integer}]}
end
defmacro get(route) do
{route, []}
end
end
defmodule Route do
defmodule ConcatTest do
def append do
1..10000 |> Enum.reduce([], fn (x, acc) ->
acc ++ [x]
end)
end
def prepend do
1..10000 |> Enum.reduce([], fn (x, acc) ->
[x] ++ acc
end) |> Enum.reverse
@hamiltop
hamiltop / reduce_comprehensions.ex
Last active August 29, 2015 14:18
Reduce Comprehension
reduce for x <- [1,2,3],
y <- [3,4,5],
{n,m} = {2,3},
x != 2,
acc: {sum, product} = {0,1} do
{sum + x + y + n + m, product*x*y*n*m}
end
@hamiltop
hamiltop / selSort.hs
Last active August 29, 2015 14:22
Haskell Selection Sort
selSort [] = []
selSort l = let
x = minimum l
in x : selSort $ delete x l
defmodule Test do
defmacro foo_macro(bar, block) do
IO.inspect bar
IO.inspect block
end
def foo(bar, block) do
IO.inspect bar
IO.inspect block
end
Flask:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
@hamiltop
hamiltop / Backbone.RaphaelView.js.coffee
Created April 5, 2012 15:44
Raphael and Backbone events
class Backbone.RaphaelView extends Backbone.View
delegateRaphaelEvents: (elements)->
for name,element of elements
@delegateRaphaelElementEvents name, element
delegateRaphaelElementEvents: (name, element) ->
events = [
"mouseup"
"mousedown"
"mousemove"
"mouseover"
It's a mostly empty database with only 4 records being emitted from the view (with reduce=false)
curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=false
{"total_rows":4,"offset":0,"rows":[
{"id":"22b7dd2f647009d2161c42bb46d6c5e7","key":["Peter",1338416091.0237810612],"value":10},
{"id":"5c7c2731a493d8cfafd036a7a93415fc","key":["Peter",1338416093.9606831074],"value":30},
{"id":"8d2c99d15c9f37e0af0244c643fe7c84","key":["Peter",1338416096.3526899815],"value":22},
{"id":"22b7dd2f647009d2161c42bb46da3b52","key":["Peter",1338416107.6635489464],"value":19}
]}
# my goal is for one module (of many) to use https://webcache.foo.com/ in place of /common/ for a set of static assets.
#here's what I have:
# root __init__.py
config.add_static_view('common', 'foo_web.layout:static/', cache_max_age=3600)
# my module __init__.py
config.add_static_view('https://webcache.foo.com/', 'foo_web.layout:cloudfront/', cache_max_age=3600)
config.override_asset(