Skip to content

Instantly share code, notes, and snippets.

@habnabit
habnabit / shell.py
Created November 10, 2010 19:28 — forked from gregglind/shell.py
import shlex as shlex_
from subprocess import Popen, PIPE
def shell(args, input=None, stdout=PIPE, stderr=PIPE, shlex=False, **kwargs):
"""Gets the output of a command run in a subprocess.
Arguments:
args: A sequence of strings, or a single string if shlex=True.
input: A string to be written to the process's stdin.
Any extra keyword arguments are forwarded to Popen.
@habnabit
habnabit / pygame_twisted.py
Created September 12, 2012 16:50 — forked from RyanHope/pygame_twisted.py
PyGame / Twisted integration with fixed fps screen updating and fast as possible event processing.
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.internet.task import LoopingCall, Cooperator
import pygame
import pygame.font
pygame.display.init()
pygame.font.init()
@habnabit
habnabit / tcp-proxy.py
Last active December 11, 2015 22:38 — forked from fiorix/tcp-proxy.py
import sys
from twisted.internet import defer, protocol, task, endpoints
from twisted.python import log
class ProxyClientProtocol(protocol.Protocol):
def connectionMade(self):
log.msg("Client: connected to peer")
# -*- coding: utf-8 -*-
#
# Copyright 2013 Liftoff Software Corporation
#
# For license information see LICENSE.txt
# Meta
__version__ = '1.0.0'
__version_info__ = (1, 0, 0)
__license__ = "Apache 2.0"
import sqlite3
from collections import defaultdict
DATABASE = 'C:/Misc/myscripts/workprototype/workprototype.db'
conn = sqlite3.connect(database=DATABASE)
curs = conn.cursor()
prod_dict = {}
curs.execute('select name, desc from companies')
from ometa.grammar import OMeta
from ometa.interp import TrampolinedGrammarInterpreter
from parsley import makeGrammar
import sys
grammar = """
hex_digit = digit | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
class Foo():
@classmethod
def _fetch(cls, data):
response = requests.get("http://example.com/my/fun/data", data=data)
return cls(response.json())
class ChildFoo(Foo):
@classmethod
def get_latest(cls):
return cls._fetch({'fleeb':'farb', 'can':'dog'})
import treq
from twisted.internet import defer, task
def testD():
def makeRequest():
d = treq.get('http://example.com/')
d.addErrback(handleError)
return d
use sodiumoxide::crypto::box_::{SecretKey, PublicKey};
use typemap::TypeMap;
use std::sync::{Arc, RwLock};
use llsd::frames::{Frame, FrameKind};
use llsd::session::server::Session;
use llsd::session::Sendable;
use llsd::sessionstore::SessionStore;
use llsd::authenticator::Authenticator;
use errors::{AWResult, AWErrorKind};
for location in locations:
for mode in ['driving', 'transit']:
row = [place, mytime, mode]
for i in range(10):
mytime += timedelta(minutes=20)
row.append(get_directions(location, (lat,lon), mytime, mode, gmaps))
csv_file.writerow(row)