Skip to content

Instantly share code, notes, and snippets.

View cablehead's full-sized avatar

Andy Gayton cablehead

View GitHub Profile
struct LeveeMiddle {
struct LeveeEnd* ends[2];
}
struct LeveeEnd {
struct LeveeMiddle middle;
}
local ev = require("ev")
ev.run(function(h)
function echo(conn)
for message in conn do
print("Echo:", message)
end
end
local serve = h.tcp:listen(8000)
import json
import vanilla
h = vanilla.Hub()
users = ['antirez', 'justinrosenthal', 'jverkoey']
done = (
import vanilla
h = vanilla.Hub()
serve = h.http.listen()
client = h.http.connect('http://localhost:%s' % serve.port)
response = client.get('/')
conn = serve.recv() # recvs http connection
import vanilla
h = vanilla.Hub()
def handle_request(request):
print request
request.reply(vanilla.http.Status(200), {}, "Hello")
lines = h.pipe()
@h.spawn
def _():
while True:
line = child.stdout.recv_partion('\n')
lines.send(line)
lines.pipe(out)
import vanilla
h = vanilla.Hub()
b = h.bean(8080)
@b.websocket('/')
def _(ws):
child = h.process.execv(['/usr/bin/env', 'grep', '--line-buffered', 'foo'])
child.stdout.pipe(ws)
import vanilla
h = vanilla.Hub()
b = h.bean(8080)
@b.websocket('/')
def _(ws):
child = h.process.execv(['/usr/bin/env', 'grep', '--line-buffered', 'foo'])
child.stdout.pipe(ws)
> python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vanilla
>>> h = vanilla.Hub()
>>> child = h.process.execv(['/usr/bin/env', 'grep', '--line-buffered', 'foo'])
>>> child.stdin.send('foo1\n')
>>> child.stdout.recv()
'foo1\n'
@cablehead
cablehead / gist:668a410b464642c81870
Created March 12, 2015 06:10
Google API OAuth from Command Line
import argparse
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client import tools
def main():
storage = Storage('a_credentials_file')
creds = storage.get()