Skip to content

Instantly share code, notes, and snippets.

View svschannak's full-sized avatar

Sven Schannak svschannak

View GitHub Profile
{{gravatar-image email="[email protected]"}}
class CORSResource(object):
"""
Adds CORS headers to resources that subclass this.
"""
def create_response(self, *args, **kwargs):
response = super(CORSResource, self).create_response(*args, **kwargs)
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Headers'] = 'Content-Type'
return response
@svschannak
svschannak / unicode_bs.py
Last active January 13, 2016 08:56
Python BeautifulSoup Unicode Problems UTF-8
# don't use this
bs4(response.content)
# use this
bs4(response.content, fromEncoding='utf8')
@svschannak
svschannak / .gitignore
Created January 13, 2016 11:59
gitignore for python pycharm iypthon projects
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@svschannak
svschannak / gunicorn_python34.sh
Last active January 20, 2016 10:21
Gunicorn Python 3.4
sudo apt-get install build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python3-dev
apt-get install libffi-dev
pip3 install setuptools cffi tox 'cython>=0.23.4' git+git://github.com/gevent/gevent.git#egg=gevent
pip3 install gunicorn
@svschannak
svschannak / gist:4f8d3805fcc472b2222a
Created January 20, 2016 10:23
Virtualenv Python 3.4
virtualenv --no-site-packages -p /usr/bin/python3.4 venv
@svschannak
svschannak / maximizepoints.js
Created February 19, 2016 13:01
Codefights Maximizepoints Challenge
function maximizePoints(team1, team2) {
var team2_copy = team2;
var len_team2 = team2.length;
best_points = 0;
for (i = 0; i < len_team2; i++){
highest_number = Math.max(...team2_copy);
index_of_highest_number = team2_copy.indexOf(Math.max.apply(Math, team2_copy));
higher_array = [];
@svschannak
svschannak / backup_psql.sh
Created March 22, 2016 10:45
Backup PostgreSQL
pg_dump NAME_OF_DATABASE > NAME_OF_BACKUP_FILE
@svschannak
svschannak / restore_psql.sh
Created March 22, 2016 10:46
Restore PostgreSQL Database
psql NAME_OF_NEW_DATABASE < NAME_OF_BACKUP_FILE
@svschannak
svschannak / minicron.toml
Created April 15, 2016 11:31
Config for a minicron client
# Client options
[client]
[client.server]
scheme = "http" # [http, https]
host = "IP_ADDRESS_OF_HUB_SERVER"
port = 9292
path = "/"
connect_timeout = 5
inactivity_timeout = 5
# CLI options