Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
c0ldlimit / gist:f2e7f52d323bfce9bf6e
Created July 18, 2014 13:44
#python relative import
sys.path.append(os.path.abspath('../triangle-project'))
@c0ldlimit
c0ldlimit / gist:a3a89410eabf1e2bb169
Created July 17, 2014 21:41
#python installing exe in windows
# http://www.lfd.uci.edu/~gohlke/pythonlibs/
pip install wheel
wheel convert INSTALLER.EXE
pip install NEW_FILE_CREATED_IN_LAST_STEP.whl
@c0ldlimit
c0ldlimit / gist:6781549fc52a259f3c73
Last active August 29, 2015 14:04
#sphinx python notes
# embedding some arbitrary rst file
.. include:: some_table.txt
# embedding arbitrary html from a file
# http://docutils.sourceforge.net/docs/ref/rst/directives.html#include
.. raw:: html
# creating pdf with Sphinx and rst2pdf
# http://thyagjs.blogspot.com/2012/05/create-pdf-document-from-your-sphinx.html
@c0ldlimit
c0ldlimit / gist:892a6d65eef08a92fb4e
Created July 14, 2014 15:35
#sql select by max(date) - select the max entry date row
--http://stackoverflow.com/questions/7836036/how-to-select-by-maxdate
SELECT report_id, computer_id, date_entered
FROM reports AS a
WHERE date_entered = (
SELECT MAX(date_entered)
FROM reports AS b
WHERE a.report_id = b.report_id
AND a.computer_id = b.computer_id
)
@c0ldlimit
c0ldlimit / gist:61c7059534ea25af773b
Created July 8, 2014 21:00
virtualenv install without first installing pip
# http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
@c0ldlimit
c0ldlimit / gist:f6e04e764d6635942662
Created July 8, 2014 15:22
cron and virtualenv #python
# http://stackoverflow.com/questions/3287038/cron-and-virtualenv
/home/my/virtual/bin/python /home/my/project/manage.py command arg
# http://stackoverflow.com/questions/15864082/python-equivalent-of-matlabs-ismember-function
def ismember(a, b):
bind = {}
for i, elt in enumerate(b):
if elt not in bind:
bind[elt] = i
return [bind.get(itm, None) for itm in a] # None can be replaced by any other "not in b" value
def merge_candidates(left, right, identical_left_flag, identical_right_flag):
candidates = []
if identical_left_flag or identical_right_flag:
if identical_left_flag and not identical_right_flag:
candidates.append(left[0])
if not identical_left_flag and identical_right_flag:
candidates.append(right[0])
elif left[0] == right[0]:
return left, True
import os
import random
from scrapy.conf import settings
class RandomUserAgentMiddleware(object):
def process_request(self, request, spider):
ua = random.choice(settings.get('USER_AGENT_LIST'))
if ua:
request.headers.setdefault('User-Agent', ua)
class ProxyMiddleware(object):
@c0ldlimit
c0ldlimit / gist:5953014
Created July 8, 2013 22:25
#python multiple #tor workers
#!/usr/bin/python
import httplib
import socks
import urllib2
from Queue import Queue
from threading import Thread, Condition, Lock
from threading import active_count as threading_active_count
import time