Skip to content

Instantly share code, notes, and snippets.

View maxp's full-sized avatar

Maxim Penzin maxp

View GitHub Profile
fp = open(msgfile)
msg = email.message_from_file(fp)
fp.close()
counter = 1
for part in msg.walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
select array_to_string(array_agg(chr(a[s])),'') "I wish you" from (
select a, generate_series(1,array_length(foo.a,1)) s from (
select array[72,97,112,112,121,32,88,109,97,115,33] as a
) foo
) bar;
@maxp
maxp / yamlnode.java
Created February 22, 2010 07:27
yanmnode helper for SnakeYAML
//
// YamlNode helper
// author: mpenzin@gmail.com
// date: 2010-02-22
//
package util;
import java.util.ArrayList;
import java.util.Collection;
# Use a flag to indicate the state of the bus.
class _StateEnum(object):
class State(object):
name = None
def __repr__(self):
return "states.%s" % self.name
def __setattr__(self, key, value):
if isinstance(value, self.State):
import math
class ImmutableVector(object):
__slots__ = ('_d',)
def __init__(self, x, y):
object.__setattr__(self, _d, (x, y))
def __setattr__(self, n, v):
raise ValueError("Can't alter instance of %s" % type(self))
@property
def x(self):
A basic FastCGI configuration for nginx looks like this:
location /yourapplication/ {
include fastcgi_params;
if ($uri ~ ^/yourapplication/(.*)?) {
set $path_url $1;
}
fastcgi_param PATH_INFO $path_url;
fastcgi_param SCRIPT_NAME /yourapplication;
fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
# werkzeug.contrib
try:
import cPickle as pickle
except ImportError:
import pickle
import memcache
class MemcacheSessionStore(SessionStore):
#!/bin/bash
grep -v \"Yandex/ |grep -v \"YaDirectBot/ |grep -v \"msnbot/ | grep -v Mediapartners-Google | grep -v Googlebot/ | \
grep -v "Yahoo! Slurp" | grep -v \"LinkWalker | grep -v \"Python-urllib | grep -v \"StackRambler/ | grep -v \"Aport\" | \
grep -v \"MLBot | grep -v \"Gigabot | grep -v \"COMODOSpider | grep -v \"ia_archiver | grep -v \"Java | \
grep -v \"Begun\ Robot\ Crawler | grep -v MJ12bot/ | grep -v Mail.Ru/ | grep -v " (Twiceler-" | \
grep -v \"Yangai\ WorldSearch\ Bot | grep -v \ DotBot/ | grep -v \ WebDataCentreBot/ | \
grep -v \ TIC/ | grep -v \ spbot/ | grep -v \"Mail.Ru/ | grep -v \ Exabot/ | grep -v \ Nigma.ru/ | \
grep -v \ Purebot/
[i+2 for i, numberList in enumerate([[i for x in range(2, i+1) if i % x == 0 and i != x] for i in range(2,100)]) if not numberList]
#!/bin/env python
import memcache
import random
import time
mc = memcache.Client(["127.0.0.1:11211"])
pc = {}
data = dict( a="abc", b=["def",123,('1','2')] )