View gist:160145
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
from __future__ import with_statement | |
from os import path, makedirs | |
def render_template(doc, env, template_path): | |
template = env.get_template(template_path) | |
return template.render(doc=doc, **doc.headers) | |
def publish(doc, env, publish_dir): | |
out = render_template(doc, env, doc.template) | |
publish_dir = path.join(publish_dir, doc.publish_directory()) |
View print_http_json.hs
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 Main where | |
import Network.HTTP | |
import Text.JSON | |
import System.Environment | |
get :: String -> IO String | |
get url = do simpleHTTP (getRequest url) >>= getResponseBody | |
main :: IO () |
View gist:205458
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 Pubsub_presenceController < Babylon::Base::Controller | |
@@nodes = [] | |
@@listeners = Subscribers.new | |
@@pubsub_subscribers = Subscribers.new | |
def on_connected | |
# send a node request | |
@from = Babylon.config[:jid] | |
@to = Babylon.config[:pubsub_jid] | |
@id = "nodereq1" |
View gist:205485
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 PubsubNode | |
include SAXMachine | |
element :item, :as => :jid, :value => :jid | |
element :item, :as => :node, :value => :node | |
element :item, :as => :name, :value => :name | |
end | |
class DiscoItems < Babylon::Base::Stanza | |
element :iq, :as => :to, :value => :to | |
element :iq, :as => :from, :value => :from |
View gist:205507
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
#+++ pubsub_presence_controller.rb | |
class Pubsub_presenceController < Babylon::Base::Controller | |
@@nodes = [] | |
def nodes | |
Babylon.logger.debug { "NODES" } | |
@from = Babylon.config["jid"] | |
@to = Babylon.config["pubsub_jid"] | |
@id = "nodereq" |
View gist:225522
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
buildNode = function(tag, attrs){ | |
var node = document.createElement(tag); | |
for(var k in attrs) { | |
node.setAttribute(k, attrs[k]) | |
} | |
return node; | |
}; | |
text = function(text) { | |
return document.createTextNode(text); |
View gist:225546
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
var iq = xml('iq', {xmlns: "http:..."}, function() { | |
this.xml('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: "root"}, function() { | |
for(var i = 0; i < 10; i++){ | |
this.xml('item', {}, function() { | |
this.text('item-' + i); | |
}); | |
} | |
}); | |
}); |
View gist:225553
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
build = function(tag, attrs){ | |
var node = document.createElement(tag); | |
for(var k in attrs) { | |
node.setAttribute(k, attrs[k]) | |
} | |
return node; | |
}; | |
text = function(text) { | |
return document.createTextNode(text); |
View rotate.py
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 math | |
def rotate(array, steps): | |
steps = steps % len(array) | |
reverse(array, 0, len(array) - 1) | |
reverse(array, 0, steps - 1) | |
reverse(array, steps, len(array) - 1) | |
return array | |
def reverse(array, start=0, end=None): |
View http method
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
data Method = Get | Head | Post | Put | Options | Delete | Trace | Connect deriving (Show) | |
m name ctor = ctor <$ string name <* (char ' ') | |
parseMethod = m "GET" Get | |
<|> m "HEAD" Head | |
<|> try (m "POST" Post) <|> m "PUT" Put | |
<|> m "OPTIONS" Options | |
<|> m "DELETE" Delete | |
<|> m "TRACE" Trace |
OlderNewer