Skip to content

Instantly share code, notes, and snippets.

@ianschenck
ianschenck / dhcp
Created August 3, 2016 07:07
Captive Portal on TP-Link TL-WA7210N using CHAOS CALMER (15.05.1, r48532), Files under /etc/config/
config dnsmasq
option domainneeded '1'
option boguspriv '1'
option filterwin2k '0'
option localise_queries '1'
option rebind_protection '1'
option rebind_localhost '1'
option local '/lan/'
option domain 'lan'
option expandhosts '1'
@ianschenck
ianschenck / example.py
Last active August 29, 2015 14:21
interfaces
import interface
class IFoo(interface.Interface):
def foo(self):
"""foo this object."""
class IBar(interface.Interface):
@ianschenck
ianschenck / run.py
Last active August 29, 2015 14:19
Run twisted wsgi like an old-school, socket sharing fcgi subprocess
# Many very old fcgi containers had a trick probably inherited from old
# inetd, where a socket is syscall dup2'd onto fd 0 of a subprocess.
# The parent creates and binds the socket while the children then just
# listen on it.
#
# Something to note is that supervisord provides this facility with its
# [fcgi-program] configuration section. The benefit here is simple inet
# or fcgi style graceful restarts. Anyhow, here is how you grab a
# socket that is fd 0 and start your twisted wsgi container on it. The
# wsgi application here is `application`.
@ianschenck
ianschenck / new_app.py
Last active July 30, 2023 03:00
Run your flask app under twisted wsgi, ALWAYS.
if __name__ == "__main__":
reactor_args = {}
def run_twisted_wsgi():
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource
resource = WSGIResource(reactor, reactor.getThreadPool(), app)
site = Site(resource)
class Pool(object):
def __init__(self, factory, size, finalizer=None):
self._factory = factory
self._finalizer = finalizer or lambda x: None
self._pool = list()
self._pool_sema = threading.Semaphore()
for _ in range(size):
self.put(self._factory())
go install path/to/main -ldflags "-X path/to/main.commit $(git rev-parse HEAD)"
@ianschenck
ianschenck / go-misc.el
Created July 4, 2014 22:32
emacs and go
(defun go-build ()
"Build a go package"
(interactive)
(compile "go build"))
(defun go-test ()
"Test a go packages"
(interactive)
(compile "go test -v"))
(defun go-vet ()
"Vet a go package"
@ianschenck
ianschenck / gist:7238329
Last active December 27, 2015 00:29
Mesos/Marathon/Docker on 12.04 with 3.8+ kernel.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: mesos-docker-setup
Installs tools for running Docker under Mesos with Marathon.
USAGE
}; function --help { -h ;}
@ianschenck
ianschenck / fabfile.py
Created August 2, 2013 20:18
Fabric file to setup ceph quicky.
"""
Deploy Ceph.
"""
import base64
import ConfigParser
import os
import StringIO
import struct
import time