Skip to content

Instantly share code, notes, and snippets.

View n37r06u3's full-sized avatar
🏠
Working from home

N37R09U3 n37r06u3

🏠
Working from home
  • China
View GitHub Profile

Install virtualenv nginx, Supervisor, PostgreSQL, and uwsgi

I recommend the latest versions for Supervisor and uwsgi. I am using nginx 1.4.7 as that is the latest available on Gentoo (unmasked for ~amd64).

Gentoo

Unmask app-admin/supervisor and www-servers/uwsgi. In the case of x86-64:

app-admin/supervisor ~amd64
# Get and install logutils
# pip install logutils
# === settings.py ===
class PseudoTTY(object):
"""This allows a a fake tty which will allow PyCharm to always say its a tty"""
def __init__(self, underlying):
"""Define my underlying class"""
@n37r06u3
n37r06u3 / gist:4b8216de0be4c966e13b
Created October 4, 2014 02:02
django logging for windows debug
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},

Use Django Fixtures to Automatically Load Data when You Install an App

First, load some data via the admin that should always be there when someone installs the app.

Next, dump that data out into JSON format into a fixture:

$ ./manage.py dumpdata [app_name] > [app_name]/fixtures/initial_data.json
@n37r06u3
n37r06u3 / gist:4d6a60442ebb74b42dbb
Created October 4, 2014 11:21
access request object in django template
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
)
// This is shamelessly copied from http://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea#answer-3373056
function getInputSelection(el) {
var start = 0, end = 0, normalizedValue, range, textInputRange, len, endRange;
if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
start = el.selectionStart;
end = el.selectionEnd;
}
else {
range = document.selection.createRange();
if (range && range.parentElement() == el) {
// ==UserScript==
// @name 400gb.com Ads Remover
// @description Yes
// @version 0.1
// @author halfcoder
// @namespace http://github.com/halfcoder
// @include http://www.400gb.com/file/*
// ==/UserScript==
setTimeout(function() {
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Threading;
using System.Collections.Generic;
namespace Ownskit.Utils
{
@n37r06u3
n37r06u3 / gunicorn_conf.py
Last active August 29, 2015 14:18
web server config(nginx + gunicorn+ django)
import multiprocessing
import os
bind = "127.0.0.1:8080"
workers = multiprocessing.cpu_count()*2
worker_class = 'gevent'
timeout = 10000
daemon = True
pidfile = os.path.join(os.path.dirname(__file__), '..', 'log','gunicorn_server.pid')
errorlog = os.path.join(os.path.dirname(__file__), '..','log','gunicorn_server.log')
loglevel = "error"

Crawling Anonymously with Tor in Python

adapted from the article "Crawling anonymously with Tor in Python" by S. Acharya, Nov 2, 2013.

The most common use-case is to be able to hide one's identity using TOR or being able to change identities programmatically, for example when you are crawling a website like Google and you don’t want to be rate-limited or blocked via IP address.

Tor

Install Tor.