Skip to content

Instantly share code, notes, and snippets.

from tornado.web import create_signed_value, decode_signed_value
secret = 'blah'
val = create_signed_value(secret, 'foo', 'bar')
print val
print decode_signed_value(secret, 'foo', val)
@scragg0x
scragg0x / gist:3746209
Created September 18, 2012 22:01
Tornado Traceback: Exception in callback tornado.stack_context._StackContextWrapper object
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x000000002054c1a8>
Traceback (most recent call last):
File "/usr/local/lib/pypy2.7/dist-packages/tornado/ioloop.py", line 421, in _run_callback
callback()
File "/usr/lib/pypy/lib_pypy/_functools.py", line 22, in __call__
return self.func(*(self.args + fargs), **fkeywords)
File "/usr/local/lib/pypy2.7/dist-packages/tornado/iostream.py", line 305, in wrapper
callback(*args)
File "/usr/lib/pypy/lib_pypy/_functools.py", line 22, in __call__
return self.func(*(self.args + fargs), **fkeywords)
@scragg0x
scragg0x / gist:3894835
Created October 15, 2012 19:47
Unserialize PHP Session in Python
def unserialize_session(val):
if not val:
return
session = {}
groups = re.split("([a-zA-Z0-9_]+)\|", val)
if len(groups) > 2:
groups = groups[1:]
groups = map(None, *([iter(groups)] * 2))
for i in range(len(groups)):
#!/usr/bin/env python
"""
Check status of a 3ware RAID and alert using AMAZON SES
Requires tw_cli binary
http://www.cyberciti.biz/files/tw_cli.8.html
Author: Matthew Scragg <[email protected]>
"""
@scragg0x
scragg0x / gist:3936144
Created October 23, 2012 01:33
Tornado AssertionError: Request closed
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x0000000009ea86b0>
Traceback (most recent call last):
File "/usr/local/lib/pypy2.7/dist-packages/tornado/ioloop.py", line 421, in _run_callback
callback()
File "/usr/lib/pypy/lib_pypy/_functools.py", line 22, in __call__
return self.func(*(self.args + fargs), **fkeywords)
File "/usr/local/lib/pypy2.7/dist-packages/tornado/iostream.py", line 305, in wrapper
callback(*args)
File "/usr/lib/pypy/lib_pypy/_functools.py", line 22, in __call__
return self.func(*(self.args + fargs), **fkeywords)
@scragg0x
scragg0x / gist:3940151
Created October 23, 2012 17:14
DB Server Specs
SAMSUNG 830 Series MZ-7PC128D/AM 2.5" 128GB SATA III MLC Internal Solid State Drive (SSD)
SAMSUNG 830 Series MZ-7PC128D/AM 2.5" 128GB SATA III MLC Internal Solid State Drive (SSD)
SAMSUNG 830 Series MZ-7PC128D/AM 2.5" 128GB SATA III MLC Internal Solid State Drive (SSD)
SAMSUNG 830 Series MZ-7PC128D/AM 2.5" 128GB SATA III MLC Internal Solid State Drive (SSD)
Intel Xeon E3-1230 V2 Ivy Bridge 3.3GHz (3.7GHz Turbo) 8MB L3 Cache LGA 1155 69W Quad-Core Server Processor BX80637E31230V2 2L218Y30A3539
Kingston 8GB 240-Pin DDR3 SDRAM ECC Unbuffered DDR3 1333 (PC3 10600) Server Memory Model
Kingston 8GB 240-Pin DDR3 SDRAM ECC Unbuffered DDR3 1333 (PC3 10600) Server Memory Model
Kingston 8GB 240-Pin DDR3 SDRAM ECC Unbuffered DDR3 1333 (PC3 10600) Server Memory Model
Kingston 8GB 240-Pin DDR3 SDRAM ECC Unbuffered DDR3 1333 (PC3 10600) Server Memory Model
Integrated IPMI 2.0 X9SCM-F Winbond KVM/LAN card
@scragg0x
scragg0x / gist:4043814
Created November 9, 2012 05:05
ZMQ wrapper, lazy connect
<?php
// Just a wrapper class for ZMQ PECL extension
class ZMQ_Socket {
private $_context;
private $_socket;
private $_connected = false;
@scragg0x
scragg0x / gist:4710045
Created February 4, 2013 21:52
Python rotate bits to the right
def rotr(x, n=1, bits=8):
while True:
x = ((x & 1) << bits-1 | x >> 1)
n -= 1
if not n:
break
return x
ubuntu@domU-12-31-39-06-8C-30:~$ sudo salt '*' grains.items
domU-12-31-39-02-74-91.compute-1.internal:
cpu_flags: fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc up rep_good nopl pni ssse3 cx16 sse4_1 hypervisor lahf_lm
cpu_model: Intel(R) Xeon(R) CPU E5430 @ 2.66GHz
cpuarch: x86_64
defaultencoding: None
defaultlanguage: None
domain: compute-1.internal
fqdn: domU-12-31-39-02-74-91.compute-1.internal
gpus:
deploy:
user.present:
- fullname: Deploy
- shell: /bin/bash
- home: /home/deploy
- groups:
- deploy
ssh_auth:
- present