Skip to content

Instantly share code, notes, and snippets.

View gist:160145
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
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
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
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
#+++ 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
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
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
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);
@aconbere
aconbere / rotate.py
Created Jan 15, 2010 — forked from zane/rotate.py
removing temp variable
View rotate.py
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
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