Skip to content

Instantly share code, notes, and snippets.

@ionrock
ionrock / gist:1303189
Created October 21, 2011 05:52
there was a couple logic errors. Here is a working version with some tests.
<?php
class IPRange {
private $BITS = 256;
public function __construct($start, $end) {
$this->start = $start;
$this->end = $end;
}
@ionrock
ionrock / cp_quick_test.py
Created October 25, 2011 05:16
CherryPy Quick Tests
import cherrypy
from pprint import pformat
class Root(object):
"""A default class for cherrypy that prints the request env.
"""
@cherrypy.expose
def index(self, *args, **kw):
make[1]: Entering directory `/home/eric/Source/temp/xpyb/src'
/usr/bin/python ./py_client.py -p /usr/local/lib/python2.7/site-packages /usr/local/share/xcb/dri2.xml
Traceback (most recent call last):
File "./py_client.py", line 620, in <module>
module.resolve()
File "/usr/lib/pymodules/python2.7/xcbgen/state.py", line 94, in resolve
item.resolve(self)
File "/usr/lib/pymodules/python2.7/xcbgen/xtypes.py", line 405, in resolve
self.reply.resolve(module)
File "/usr/lib/pymodules/python2.7/xcbgen/xtypes.py", line 369, in resolve
/usr/bin/python ./py_client.py -p /usr/local/lib/python2.7/site-packages /usr/local/share/xcb/dri2.xml
Traceback (most recent call last):
File "./py_client.py", line 620, in <module>
module.resolve()
File "/usr/lib/pymodules/python2.7/xcbgen/state.py", line 94, in resolve
item.resolve(self)
File "/usr/lib/pymodules/python2.7/xcbgen/xtypes.py", line 405, in resolve
self.reply.resolve(module)
File "/usr/lib/pymodules/python2.7/xcbgen/xtypes.py", line 369, in resolve
ComplexType.resolve(self, module)
@ionrock
ionrock / lockfile.py
Created June 29, 2012 04:14
A file locking example
"""
A file lock implementation that tries to avoid platform specific
issues. It is inspired by a whole bunch of different implementations
listed below.
- https://bitbucket.org/jaraco/yg.lockfile/src/6c448dcbf6e5/yg/lockfile/__init__.py
- http://svn.zope.org/zc.lockfile/trunk/src/zc/lockfile/__init__.py?rev=121133&view=markup
- http://stackoverflow.com/questions/489861/locking-a-file-in-python
- http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/
- http://packages.python.org/lockfile/lockfile.html
@ionrock
ionrock / cpcluster.py
Created August 23, 2012 06:32
Trying out an idea where a single cherrypy process clones itself in order to serve the same application on different ports. Signals sent to the initial process would be propagated to the children via ZeroMQ and the Web Site Process Bus in CherryPy (cherry
"""
CP Cluster
Create a cluster of CherryPy application processes. This will take an
single cherrypy application and create multiple instances on
difference processes using sequential port numbers.
"""
from __future__ import print_function
import os
import tempfile
@ionrock
ionrock / circus_log_to_pub_sub.diff
Created January 16, 2013 07:41
Some code to turn on and off logging to the pub/sub socket in circus as well as being able to log to the stdout of the circusd process. I've included a example config with details on how to turn on/off sending stdout/err to the pub/sub socket as well as a plugin to read a watchers stdout/err from the pub/sub socket. The config format is just a f…
Changes in HEAD
Modified circus/config.py
diff --git a/circus/config.py b/circus/config.py
index abce19a..d789545 100644
--- a/circus/config.py
+++ b/circus/config.py
@@ -28,8 +28,7 @@ def watcher_defaults():
'max_retry': 5,
'graceful_timeout': 30,
'rlimits': dict(),
@ionrock
ionrock / gist:5445934
Created April 23, 2013 18:06
Select some code and open that code in another frame for reference.
(defun narrow-to-region-indirect (start end)
"Restrict editing in this buffer to the current region, indirectly."
(interactive "r")
(let ((buf (clone-indirect-buffer nil nil)))
(with-current-buffer buf
(narrow-to-region start end))
(select-frame (make-frame))
(switch-to-buffer buf)))
(global-set-key (kbd "C-c \"") 'narrow-to-region-indirect)
@ionrock
ionrock / gist:7091839
Created October 21, 2013 22:11
An example from my init.org
* My Emacs Customizations
** The Vendor Directory
I keep all my non-packages in =.emacs.d/vendor=.
#+begin_src emacs-lisp
(add-to-list 'load-path "~/.emacs.d/vendor")
#+end_src
** Packages
@ionrock
ionrock / gist:7993530
Last active December 31, 2015 13:29
Adding some functions to read a project's procfile entries into prodigy. I use a tool called "xe" that does something similar to projectile in that it looks for a project root and appends venv/bin to your path before running commands. It also has some helpers to bootstrap a python virtualenv and run django manage commands. It makes these sorts o…
(defun my-procfile-name-from-line (line)
(car (split-string line ":")))
(defun my-procfile-names (procfile)
(with-temp-buffer
(insert-file-contents procfile)
(-map 'my-procfile-name-from-line (split-string (buffer-string) "\n" t))))
(defun my-procfile-cmd (procfile name)
(with-temp-buffer