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:
@ivandeex
ivandeex / pdf_2_html.py
Last active September 9, 2022 12:22
convert pdf to html or xml
# https://github.com/scraperwiki/pdfminer/blob/scraperwiki/tools/pdf2html.cgi
import pdfminer
from pdfminer.pdfinterp import PDFResourceManager, process_pdf
from pdfminer.converter import HTMLConverter, TextConverter
from pdfminer.layout import LAParams
rsrcmgr = PDFResourceManager()
laparams = LAParams()
converter = HTMLConverter if format == 'html' else TextConverter
device = converter(rsrcmgr, out_file, codec='utf-8', laparams=laparams)
process_pdf(rsrcmgr, device, in_file, pagenos=[1,3,5], maxpages=9)
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