Skip to content

Instantly share code, notes, and snippets.

View oubiwann's full-sized avatar
💭
🌌

Duncan McGreggor oubiwann

💭
🌌
View GitHub Profile
@oubiwann
oubiwann / 01-one-to-many.sql
Created October 14, 2012 01:41
MySQL, Storm, and Relationships
CREATE TABLE parent (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50),
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child (
id INT NOT NULL AUTO_INCREMENT,
parent_id INT,
name VARCHAR(50),
@oubiwann
oubiwann / 01-myweb.tac.py
Created October 14, 2012 01:50
Native LoadBalancing for Twisted Apps
from twisted.web import static, server
from twisted.application import service, internet
application = service.Application("Demo Web Server")
web = server.Site('/home/oubiwann/public_html')
service = internet.TCPServer(7001, web)
service.setServiceParent(application)
@oubiwann
oubiwann / 01-interactive.py
Created October 14, 2012 01:56
zope.testbrowser: Automating the Web
>>> from zope.testbrowser.browser import Browser
>>> b = Browser('http://google.com')
>>> b.title
'Google'
>>> b.getLink('About Google')
<Link text='About Google' url='http://www.google.com/intl/en/about.html'>
@oubiwann
oubiwann / 01-interactive.py
Created October 14, 2012 06:28
Twisted's filepath Module
>>> from twisted.python.filepath import FilePath
>>> tmp = FilePath('/tmp')
>>> tmp.exists()
True
>>> bogus = tmp.child('bogus')
>>> bogus.exists()
False
@oubiwann
oubiwann / model.py
Created October 14, 2012 21:09
trac Stats Gathering with Storm
class Revision(object):
"""
A storm ORM object representing a row in the trac 'revsion' SQLite table.
"""
__storm_table__ = 'revision'
rev = Unicode(primary=True)
time = Int()
author = Unicode()
message = Unicode()
@oubiwann
oubiwann / 01-install.txt
Created October 18, 2012 03:24
Getting Started with cl-async
$ git clone https://github.com/orthecreedence/cl-async.git
$ cd cl-async
$ tar cvzf libevent2.tgz ./libevent2
$ start-sbcl
* (require 'asdf-install)
("ASDF-INSTALL")
* (asdf-install:install "libevent2.tgz")
Install where?
1) System-wide install:
@oubiwann
oubiwann / klein-templates.py
Created October 20, 2012 16:32
A template manager for Klein created anonymously on the net somewhere.
# template loader framework
from twisted.internet.defer import maybeDeferred
from twisted.web.template import tags, Element, TagLoader, renderer, slot
from twisted.python.util import mergeFunctionMetadata
def withTemplate(templateTag):
templateTag.render = "__top__"
def deco(x):
def it(request):
e = Element(loader=TagLoader(templateTag))
@oubiwann
oubiwann / 01-agent.clj
Created October 28, 2012 02:48
Exploring Agents in Clojure, Part I
(def read-agent (agent nil))
@oubiwann
oubiwann / 01-validation.clj
Created October 30, 2012 00:03
Agents in Clojure, Part II
(def read-agent (agent "" :validator string?))
@oubiwann
oubiwann / echo-server.lisp
Created November 7, 2012 18:30
cl-async example
(defun my-echo-server ()
(format t "Starting server.~%")
(as:tcp-server nil 9003 ; nil is "0.0.0.0"
(lambda (socket data)
;; echo the data back into the socket
(as:write-socket-data socket data))
(lambda (err) (format t "listener event: ~a~%" err)))
;; catch sigint
(as:signal-handler 2 (lambda (sig)
(declare (ignore sig))