Skip to content

Instantly share code, notes, and snippets.

def run(self):
self.conn.send('220 Welcome!\r\n')
while True:
if not isinstance(self.conn, ssl.SSLSocket): # Can't PEEK at ssl sockets
if self.conn.recv( 1, socket.MSG_PEEK ) == "\x16":
self.conn = ssl.wrap_socket(self.conn, certfile="cert.pem", server_side=True)
cmd=self.conn.recv(256)
if not cmd: break
@stevommmm
stevommmm / SmartServerSocket.py
Created January 13, 2015 03:22
sslablesockets
class SmartServerSocket:
def __init__( self, sock ):
self.sock = sock
# delegate methods as needed
_delegate_methods = [ "fileno" ]
for method in _delegate_methods:
setattr( self, method, getattr( sock, method ) )
def accept( self ):
(conn, addr) = self.sock.accept()
if conn.recv( 1, socket.MSG_PEEK ) == "\x16":
SELECT type, SUM(created) AS created, SUM(destroyed) AS destroyed FROM (
(SELECT type, count(type) AS created, 0 AS destroyed FROM `lb-world` INNER JOIN `lb-players` USING (playerid) WHERE playername = 'DOKDOR' AND type > 0 AND type != replaced $dateClause GROUP BY type)
UNION
(SELECT replaced AS type, 0 AS created, count(replaced) AS destroyed FROM `lb-world` INNER JOIN `lb-players` USING (playerid) WHERE playername = 'DOKDOR' AND replaced > 0 AND type != replaced $dateClause GROUP BY replaced)
) AS t GROUP BY type ORDER BY SUM(created) + SUM(destroyed) DESC
@stevommmm
stevommmm / multi_sock.py
Last active August 29, 2015 14:07
Mutliprocessing thread socket pool
#!/usr/bin/env python
import select
import socket
from multiprocessing import current_process, active_children
from multiprocessing.pool import ThreadPool
class SockPool(object):
"""Threaded socket pool making use of multiprocessing.pool.ThreadPool and select.select"""
def __init__(self, host, port, poolsize=10, backlog=10, readsize=1024):
@stevommmm
stevommmm / funcman.py
Last active August 29, 2015 14:06
funcs to forms in python
import logging
import types
funcs = []
def decorator(func, *args, **kwargs):
if type(func) != types.FunctionType:
return decorator
funcs.append(func)
@stevommmm
stevommmm / .bashrc
Created September 1, 2014 23:38
.bashrc
# Exit if we aren't interactive
[ -z "$PS1" ] && return
shopt -s checkwinsize
lowpriv="\[\033[1;48;5;32m\]"
rootpriv="\[\033[1;48;5;1m\]"
dirpath="\[\033[38;5;220;48;5;238m\]"
reset="\[\033[00m\]"
@stevommmm
stevommmm / style.css
Created July 23, 2014 00:17
williammck.net style
html {
height: 100%;
-webkit-font-smoothing: antialiased;
}
body {
font-family: 'Open Sans', sans-serif;
color: #888;
font-weight: 400;
font-size: 12px;
@stevommmm
stevommmm / core.css
Created July 17, 2014 10:23
netchat.io alternate stylesheet
@font-face {
font-family: "Lato";
font-style: normal;
font-weight: 400;
src: local("Lato Regular"), local("Lato-Regular"), url("http://themes.googleusercontent.com/static/fonts/lato/v7/9k-RPmcnxYEPm8CNFsH2gg.woff") format("woff");
}
@font-face {
font-family: "Lato";
font-style: normal;
#header {
animation-name: hue_span;
animation-duration: 20s;
animation-timing-function: ease-out;
animation-iteration-count: infinite;
animation-direction: normal;
animation-play-state: running;
}
@keyframes hue_span {
@stevommmm
stevommmm / keybase.md
Created May 19, 2014 23:43
keybase.md

Keybase proof

I hereby claim:

  • I am stevommmm on github.
  • I am c45y (https://keybase.io/c45y) on keybase.
  • I have a public key whose fingerprint is 1EA9 9344 5B7C 9817 0AC0 4135 5243 019A 99B7 B1A3

To claim this, I am signing this object: