Skip to content

Instantly share code, notes, and snippets.

View ivandeex's full-sized avatar
:octocat:
¯\_(ツ)_/¯ BUSY

Ivan Andreev ivandeex

:octocat:
¯\_(ツ)_/¯ BUSY
View GitHub Profile
# method 1
import ctypes
obj = ctypes.cast(id(orig_obj), ctypes.py_object).value
# method 2
import gc
for obj in gc.get_objects():
if id(obj) == id_:
yield obj
else:
schtasks /Create /SC HOURLY {DAILY,WEEKLY} /TN My_Task /TR "C:\python27\python.exe C:\dir\task1.py"
@ivandeex
ivandeex / scrapy_random_proxy.py
Last active August 29, 2015 14:25 — forked from therg/randomproxy.py
scrapy middleware for proxy rotation with status checks and retries; http://www.reddit.com/r/Python/comments/2p3z4u/scrapy_how_to_retry_a_302_redirect_with_a_new/
import re
import random
import base64
from scrapy import log
class RandomProxy(object):
def __init__(self, settings):
self.proxy_list = settings.get('PROXY_LIST')
fin = open(self.proxy_list)
wordlist = (w.strip() for f in wordlistfiles for w in open(f))
@ivandeex
ivandeex / member_lookup_optimizations.py
Last active August 29, 2015 14:25
member_lookup_optimizations.py
# lookup optimizations (ugly but fast)
queue = collections.deque()
queue_append, queue_popleft = queue.append, queue.popleft
queue_appendleft, queue_pop = queue.appendleft, queue.pop
@ivandeex
ivandeex / win_reg.py
Created July 23, 2015 14:54
windows registry
# general docs:
# https://docs.python.org/2/library/_winreg.html#module-_winreg
# usage example:
# http://www.blog.pythonlibrary.org/2010/03/20/pythons-_winreg-editing-the-windows-registry/
# reading
from _winreg import *
key = OpenKey(HKEY_LOCAL_MACHINE, r'Software\Microsoft\Outlook Express', 0, KEY_ALL_ACCESS)
QueryValueEx(key, "InstallRoot")
[program:tornado]
environment=PATH="/home/vanko/.virtualenvs/env1/bin"
command=/home/vanko/.virtualenvs/env1/bin/python /home/vanko/app1/app.py --port=%(process_num)s
# supervisord service for sysstemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Exec]
User=vanko
WorkDir=/home/vanko
[Service]
@ivandeex
ivandeex / supervisor_cron.py
Last active August 29, 2015 14:25
supervisor cron
from crontab import CronTab
from datetime import datetime, timedelta
import time
import os
import xmlrpclib
import urlparse
import logging
import json
import shlex
@ivandeex
ivandeex / borg.py
Last active August 29, 2015 14:25
Python Borg vs singleton: we all are one and all that jazz -- http://code.activestate.com/recipes/66531/
class Borg:
__shared_state = {}
def __init__(self):
self.__dict__ = self.__shared_state
# and whatever else you want in your class -- that's all!