Skip to content

Instantly share code, notes, and snippets.

@scragg0x
scragg0x / gist:3738408
Created September 17, 2012 16:42
Tornado: Connection Reset By Peer
Traceback (most recent call last):
File "/usr/local/lib/pypy2.7/dist-packages/tornado/iostream.py", line 355, in _handle_read
if self._read_to_buffer() == 0:
File "/usr/local/lib/pypy2.7/dist-packages/tornado/iostream.py", line 422, in _read_to_buffer
chunk = self._read_from_socket()
File "/usr/local/lib/pypy2.7/dist-packages/tornado/iostream.py", line 403, in _read_from_socket
chunk = self.socket.recv(self.read_chunk_size)
File "/usr/lib/pypy/lib-python/modified-2.7/socket.py", line 188, in recv
return self._sock.recv(buffersize, flags=flags)
error: [Errno 104] Connection reset by peer
@scragg0x
scragg0x / gist:3738771
Created September 17, 2012 17:56
Tornados Signed Value Functions
def _time_independent_equals(a, b):
if len(a) != len(b):
return False
result = 0
if type(a[0]) is int: # python3 byte strings
for x, y in zip(a, b):
result |= x ^ y
else: # python2
for x, y in zip(a, b):
result |= ord(x) ^ ord(y)
@scragg0x
scragg0x / gist:3739107
Created September 17, 2012 18:56
Tornado Signed Value Implementation in PHP
<?php
/* Python Version: https://gist.github.com/3738771 */
function _time_independent_equals($a, $b){
if (strlen($a) !== strlen($b)){
return;
}
$result = 0;
for($i=0; $i<strlen($a); $i++){
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)
#!/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 <scragg@gmail.com>
"""
@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