Skip to content

Instantly share code, notes, and snippets.

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(
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var LastSeen = 1;
var waiting = 0;
var to_travel = 0;
@hamiltop
hamiltop / gist:5234986
Created March 25, 2013 04:48
I am trying to build a datamapper adapter and I'm having trouble getting started. With the following files, I get the resulting NameError when I run rspec spec/dm-mongolitedb-adapter_spec.rb
lib/dm-mongolitedb-adapter.rb
1 require 'dm-core'
2 require 'dm-core/adapters/abstract_adapter'
3 require 'mongolitedb'
4
5 module DataMapper
6 module Adapters
7 class MongoLiteDBAdapter < AbstractAdapter
8 private
@hamiltop
hamiltop / gist:5689406
Created June 1, 2013 05:44
"Copy as CURL" option in Google Chrome. This is from customizing a Macbook Pro at apple.com
curl "http://store.apple.com/us/configUpdate/Z0PZ?option.macbookpro_processor_17=065-C1T0&option.macbookpro_storage=065-C1T5&option.macbookpro_usb_superdrive=none&option.apple_thunderbolt_display=none&option.macbook_pro_keyboard_and_os=065-C1TQ&option.iwork_keynote=065-C13G&option.iwork_pages=065-C13D&option.iwork_numbers=065-C13F&option.macbookpro_applecare=none&option.one_to_one=none&option.thunderbolt_to_gigabit_ethernet_adapter=065-C1T6&option.thunderbolt_to_firewire_adapter=065-C1T8&option.vga_adapter=065-C1TC&option.dvi_adapter=none&option.dual_link_dvi_adapter=none&option.magsafe_2_power_adapter_85w=none&option.magsafe_to_magsafe_2_converter=none&option.apple_thunderbolt_cable=none&option.external_storage=none&option.time_capsule=none&option.apple_tv_mac=none&option.printer_offers=none&fcs1=&fcs2=" -H "Cookie: ccl=tBtBE3lJ4LMSEepGlEUjGGOfRSsgiBpkseqQEyb0CJc=; geo=US; s_orientation=%5B%5BB%5D%5D; s_pathLength=homepage%3D1%2Cmac.tab%2Bother%3D1%2Cmacbookpro%3D1%2C; s_invisit_n2_us=3%2C0%2C26; s_vnum_n2_u
curl "http://store.apple.com/us/configUpdate/Z0PZ?option.macbookpro_processor_17=065-C1T0&option.macbookpro_storage=065-C1T5&option.macbookpro_usb_superdrive=none&option.apple_thunderbolt_display=none&option.macbook_pro_keyboard_and_os=065-C1TQ&option.iwork_keynote=065-C13G&option.iwork_pages=065-C13D&option.iwork_numbers=065-C13F&option.macbookpro_applecare=none&option.one_to_one=none&option.thunderbolt_to_gigabit_ethernet_adapter=065-C1T6&option.thunderbolt_to_firewire_adapter=065-C1T8&option.vga_adapter=065-C1TC&option.dvi_adapter=none&option.dual_link_dvi_adapter=none&option.magsafe_2_power_adapter_85w=none&option.magsafe_to_magsafe_2_converter=none&option.apple_thunderbolt_cable=none&option.external_storage=none&option.time_capsule=none&option.apple_tv_mac=none&option.printer_offers=none&fcs1=&fcs2=" -H "Cookie: ccl=tBtBE3lJ4LMSEepGlEUjGGOfRSsgiBpkseqQEyb0CJc=; geo=US; s_orientation=%5B%5BB%5D%5D; s_pathLength=homepage%3D1%2Cmac.tab%2Bother%3D1%2Cmacbookpro%3D1%2C; s_invisit_n2_us=3%2C0%2C26; s_vnum_n2_u
@hamiltop
hamiltop / gist:5977833
Created July 11, 2013 18:19
Use logic in select fields
I would like to go from:
Bundle.find_by_sql("select bundles.name, bundles.id, if(bundles.max_count > 100, 1, 0) as big from bundles;")
to something more like:
Bundle.select([:name,:id,"if(bundles.max_count > 100, 1, 0)"]).all
That way I could continue to chain on where clauses and such.
@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