Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
[alias]
st = status
ci = commit
co = checkout
br = branch
d = diff
dc = diff --cached
lg = log -p
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
@ei-grad
ei-grad / charon.py
Created November 27, 2011 02:05
Small and ugly but working HTTP proxy based on Tornado.
#!/usr/bin/env python
# coding: utf-8
import logging
from functools import partial
import http.client
from tornado.httputil import HTTPHeaders
HTTPHeaders._normalize_name = lambda x: x
@ei-grad
ei-grad / example.py
Created November 30, 2011 01:46
threaded decorator for tornado
from time import sleep
from tornado import gen
import tornado.ioloop
import tornado.web
from tornado_threaded import threaded, inline_threaded
@threaded
def slow_func(callback):
@ei-grad
ei-grad / dntree.py
Created February 2, 2012 20:30
DNTree class. Represents a set of distinguished names as tree. Can be used to build a hierarchy of Internet Domain names or LDAP DN.
#!/usr/bin/env python
# coding: utf-8
#
# Copyright (c) 2009 Andrew Grigorev <andrew@ei-grad.ru>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
import imp
import os
import stat
import string
import sys
from default_settings import *
def get_arg(key):
return sys.argv[sys.argv.index(key) + 1]
@ei-grad
ei-grad / rc4brute.py
Created May 21, 2012 05:24
RC4 bruteforce using entropy and file type signatures
#!/usr/bin/env python
# coding: utf-8
import sys
from Crypto.Cipher import ARC4
import numpy
import magic
import string
fname = sys.argv[1] if len(sys.argv) > 1 else 'videostream'
@ei-grad
ei-grad / get_bound_objects.py
Created July 5, 2012 18:44
get_bound_objects
#!/usr/bin/env python
# coding: utf-8
def get_bound_objects(queryset, classes):
"""
Helper function to map a list of objects to corresponding classes in Django ORM.
It is a simple and stupid alternative to django_polymorphic.
Good to use with custom Paginator class. Example usage:
@ei-grad
ei-grad / apache_combined.py
Last active November 18, 2015 19:40
Regular expression to parse apache combined log in python
import re
apache_combined = re.compile(
'(?P<clientip>[\d\.]+) (?P<ident>\S+) (?P<auth>\S+) '
'\[(?P<timestamp>.*?)\] '
'"(?P<verb>\S+) (.*) HTTP/(?P<httpversion>\d\.\d)" '
'(?P<response>\d+|-) (?P<bytes>\d+|-)'
'( "(?P<referrer>.*?)")?'
'( "(?P<agent>.*)")?'
)
import subprocess
from datetime import datetime
from time import sleep, time
import locale
import psutil
locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
{
"template": "mixpanel-*",
"settings": {"index.refresh_interval": "1m"},
"mappings": {
"_default_": {
"_all": {"enabled": false},
"date_detection": false,
"dynamic_templates": [
{"string_fields": {
"match": "*",