John Anderson sontek

View fdserver.py
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env python
"""This is a demonstration of sharing file descriptors across processes.
 
It uses Tornado (need a recent post-2.0 version from github) and the
multiprocessing module (from python 2.6+). To run it, start one copy
of fdserver.py and one or more copies of testserver.py (in different
terminals, or backgrounded, etc). Fetch http://localhost:8000 and
you'll see the requests getting answered by different processes (it's
normal for several requests to go to the same process under light
load, but under heavier load it tends to even out).
View gist:5986226
1 2 3 4 5 6 7 8 9 10
_complete_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
host_list=`{
for c in /etc/ssh_config /etc/ssh/ssh_config ~/.ssh/config
do [ -r $c ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' $c
done
for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts ~/.ssh/known_hosts
do [ -r $k ] && egrep -v '^[#\[]' $k|cut -f 1 -d ' '|sed -e 's/[,:].*//g'
done
View threads_requests.py
1 2 3 4 5 6 7 8 9
import threading
import requests
import logging
 
 
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
View threadpool_requests.py
1 2 3 4 5 6 7 8 9 10
import threading
import requests
import logging
from threadpool import ThreadPool
from threadpool import makeRequests
pool = ThreadPool(4)
 
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
View gist:5660624
1 2 3 4 5 6 7 8 9 10
from wsgiref.simple_server import make_server
 
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.compat import text_type
 
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
View gist:4150023
1 2 3 4 5 6 7 8 9
Things with $ at the beginning are commands you run
 
$ sudo yum install python-virtualenv openssl-devel zeromq-devel gcc
 
$ mkvirtualenv datanommer
 
$ cdvirtualenv
 
$ mkdir src
View gist:3936459
1 2 3 4 5 6 7 8 9 10
import ctypes
import os
import sys
 
here = os.path.dirname(__file__)
cpath = os.path.abspath(os.path.join(here, "fib.so"))
fiblib = ctypes.CDLL(cpath)
 
def fib(n):
if n == 0:
View gist:3809010
1 2 3 4 5 6 7 8 9 10
class JsonSerializableMixin(object):
"""
Converts all the properties of the object into a dict for use in json.
You can define the following as your class properties.
 
_json_eager_load :
list of which child classes need to be eagerly loaded. This applies
to one-to-many relationships defined in SQLAlchemy classes.
 
_base_blacklist :
View gist:3697998
1 2 3 4 5 6 7 8 9
Layout = Backbone.View.extend({
initialize: function() {
var me = this;
 
this.setViews(_.extend({}, this.views, this.options.views));
 
if (this.options.template) {
this.template = this.options.template;
}
View gist:3661788
1 2 3 4 5 6 7 8 9 10
/*
* Copyright 2011 Twitter, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Something went wrong with that request. Please try again.