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
#!/usr/bin/env python | |
from flask import Flask, request | |
app = Flask(__name__) | |
idx = 0 | |
fnids = {} | |
def new_fnid(fn): | |
""" | |
Generate id for closures. |
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
require 'sinatra' | |
$fnids = {} | |
$counter = 0 | |
def store_fn(fn) | |
($fnids[$counter += 1] = fn) and $counter | |
end | |
def dispatch_fn(fnid) |
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_search(graph, initial, queue) | |
queue.enqueue(initial) | |
seen = {} | |
while not queue.empty? | |
node = queue.dequeue | |
puts node | |
seen[node] = true | |
if graph[node] | |
graph[node].each {|child| queue.enqueue child unless seen[child] } | |
end |
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
$graph = {a: [:b, :c], b: [:d, :e], c: [:f, :g]} | |
def dfs_nr(node) | |
queue = [node] | |
seen = {} | |
while not queue.empty? | |
node = queue.pop | |
puts node | |
seen[node] = true | |
if $graph[node] |
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
require 'set' | |
require 'test/unit' | |
def match(str, start, finish, trans) | |
state = [start] | |
str.each_char do |c| | |
# Obtain next states. | |
state = state.map {|s| trans[s][c] if trans[s] and trans[s][c] }.flatten | |
break if state.nil? | |
end or return false |
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
--type-add=ruby=.haml,.rake,.slim |
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
#!/usr/bin/env ruby | |
class BrainFuck | |
def initialize | |
@ops = create_ops | |
@tape = Array.new(1024,0) | |
@tp = 0 | |
@code = [] | |
@cp = 0 | |
end |
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
import mimetypes | |
def encode_multipart_formdata(fields=None, files=None): | |
""" | |
fields is a sequence of (name, value) elements for regular form fields. | |
files is a sequence of (name, filename, value) elements for data to be uploaded as files | |
Return (content_type, body) ready for httplib.HTTP instance | |
""" | |
if not (fields or files): | |
return None, None |
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
https://plus.google.com/_/notifications/emlink?emrecipient=110980919682495338132&emid=CMjztYPM3KkCFQx97AodHlxyGA&path=%2Fwelcome%3Fgpinv%3DAGXbFGxRQi9hP6iVrph0RQI3p0sp7UaxptyD4JGxhl293nTm5jRDbJuTQGzZjpPnz_Rs8MZJDWegy2OwWkhMQ4IF7Sk4eNVPDWbkQAL7mNkK9cpmiHKKFjw%26hl%3Den_US | |
https://plus.google.com/_/notifications/emlink?emrecipient=110980919682495338132&emid=CLiQyP_L3KkCFcK17AodRzRKGA&path=%2Fwelcome%3Fgpinv%3DAGXbFGxmaqZZV0ORRozZDf54-2dmPa-lB4xdQ46J4UfrSCnR64biZKLtwfeL2VIzS04Dxa67NeLcp8aaiAIj8LnavLkCZXH0GXCuh0xmmN7OpsgIKkEITWA%26hl%3Den_US | |
https://plus.google.com/_/notifications/emlink?emrecipient=110980919682495338132&emid=CNi0pu7L3KkCFUS_7Aod2RpqGA&path=%2Fwelcome%3Fgpinv%3DAGXbFGxvrJoIrDz4x57z2gceG1EaTvVgmWU-dbFUC7UjZhR73Jq5w9TwRDPwbOokAZ5sJeXVkkMtty96x860j2TyXP0aHaDK3RCwKbla9Ji-ihBsKnO-BVU%26hl%3Den_US | |
https://plus.google.com/_/notifications/emlink?emrecipient=110980919682495338132&emid=COj2qZjM3KkCFWe97AodWsulGA&path=%2Fwelcome%3Fgpinv%3DAGXbFGwxW0wLj-T5ILxFLTzKW_xdqkliLiFn5-l9VnGoRq9whW5g7A7GvoIZCLuyz9 |
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
user=> (source output-stream) | |
(defn ^OutputStream output-stream | |
"Attempts to coerce its argument into an open java.io.OutputStream. | |
Default implementations always return a java.io.BufferedOutputStream. | |
Default implementations are defined for OutputStream, File, URI, URL, | |
Socket, and String arguments. | |
If the argument is a String, it tries to resolve it first as a URI, then | |
as a local file name. URIs with a 'file' protocol are converted to |