Skip to content

Instantly share code, notes, and snippets.

from collections import defaultdict
class Dog(object):
__instance_count = defaultdict(int)
def __init__(self):
self.__instance_count[self.__class__.__name__] += 1
def __del__(self):
from collections import defaultdict
class Dog(object):
__instance_count = defaultdict(int)
def __init__(self, colour='white', breed='mutt'):
self.colour = colour
self.breed = breed
class RegexDict(dict):
def __get_regex_keys(self, pattern):
return (key for key in self.keys() if pattern.match(key))
def __getitem__(self, key):
if hasattr(key, 'match'):
return [self[matched_key] for matched_key in self.__get_regex_keys(key)]
else:
return super(RegexDict, self).__getitem__(key)
@mtomwing
mtomwing / user.php
Last active December 18, 2015 13:19
Found this script on a client's Wordpress install. I'm still not entirely sure how it got there yet, but I do know that it was sending out large amounts of spam email. /wp-includes/Text/Diff/.svn/props/user.php is where it was relative to their document root. However my best guess is that they managed to upload this script via some Wordpress exp…
<snip from Nginx logs>
190.141.110.70 - - [15/Jun/2013:19:16:45 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:46 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:47 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:48 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:49 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:51 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:52 +0000] "POST /wp-includes/Text/Diff/.svn/props/user.php HTTP/1.1" 200 50 "-" "Mozilla/5.0" "-"
190.141.110.70 - - [15/Jun/2013:19:16:53 +0000] "
Standings:
1) Chris (0+0-0-0) [0.00%] => 0 points
2) Trevor (0+0-0-0) [0.00%] => 0 points
3) Michael (0+0-0-0) [0.00%] => 0 points
4) Angus (0+0-0-0) [0.00%] => 0 points
5) Sam (0+0-0-0) [0.00%] => 0 points
6) Ben (0+0-0-0) [0.00%] => 0 points
7) Jake (0+0-0-0) [0.00%] => 0 points
Round 1
from freeseer.framework.config.options import StringOption, IntegerOption
from freeseer.framework.config.persist import ParserConfig
class FreeseerConfig(ParserConfig):
name = StringOption('Michael Tom-Wing')
age = IntegerOption(0)
if __name__ == '__main__':
import ConfigParser
from ..core import ConfigManager
class ConfigParserManager(ConfigManager):
def __init__(self, manager, filename):
super(ConfigParserManager, self).__init__(manager, filename)
self.parser = ConfigParser.ConfigParser()
self.parser.read([self.filepath])
from freeseer.framework.config.core import Config, ProfileManager
from freeseer.framework.config.persist import (
ConfigParserManager,
JSONConfigManager,
)
import freeseer.framework.config.options as options
class FreeseerConfig(Config):
videodir = options.FolderOption('/home/mtomwing/Videos', auto_create=True)
@mtomwing
mtomwing / test.py
Last active December 22, 2015 06:48
from freeseer.framework.config.core import Config, ProfileManager
from freeseer.framework.config.persist import (
ConfigParserManager,
JSONConfigManager,
)
import freeseer.framework.config.options as options
class FreeseerConfig(Config):
videodir = options.FolderOption('/home/mtomwing/Videos', auto_create=True)
from functools import reduce
import sys
from grammar import (
Program,
Statement,
Function,
ArgumentList,
Argument,
Integer,