Skip to content

Instantly share code, notes, and snippets.

Avatar
🐍
Python is my love affair

Peter Bittner bittner

🐍
Python is my love affair
View GitHub Profile
@bittner
bittner / .bash_virtenv
Last active Aug 29, 2015
Automatically activate virtualenv in Python development. (Source this file from within .bashrc)
View .bash_virtenv
# From: "Automatically activate virtualenv" by Kurt Neufeld
# URL: http://www.burgundywall.com/tech/automatically-activate-virtualenv/
# Date: 16-Oct-2013
#
# Usage:
#
# 1. Create an empty .venv file in your project home: touch .venv
# 2. Put this file in your home directory: cp .bash_virtenv ~/
# 3. Include it in ~/.bashrc as follows:
#
@bittner
bittner / restart.sh
Last active Aug 29, 2015
Quick test project generator for Django package development
View restart.sh
#!/bin/bash
# Make sure you've created a VirtualEnv beforehand: $ mkvirtualenv test && workon test
# @author Peter Bittner <django@bittner.it>
# @license GPLv3, https://www.gnu.org/copyleft/gpl.html
PROJECT=ascalcio
printf 'Uninstalling Django, please wait ...'
pip uninstall -q Django
rm -rfv manage.py $PROJECT
# As an alternative to above, the following will uninstall all packages:
@bittner
bittner / javascript.rb
Last active Aug 29, 2015
Bootstrap-Sass JavaScript generation (combine + minify) using vanilla Compass
View javascript.rb
# Copyright 2014 Peter Bittner <django@bittner.it>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@bittner
bittner / apache-status.bash
Created Nov 14, 2014
Apache Status Remote Querying
View apache-status.bash
#!/bin/bash
# Show the Apache status diagram (free and occupied connections). Ctrl+C to exit.
# usage: apache-status servername
apache-status() {
while true; do
ssh -t $1 "TERM=xterm-color && clear && apache2ctl status && sleep 2"
done
}
@bittner
bittner / charm.diff
Last active Aug 29, 2015
Add merge command to PyCharm again (including PEP8 corrections), see comments in https://www.jetbrains.com/pycharm/help/running-pycharm-as-a-diff-or-merge-command-line-tool.html
View charm.diff
17,21c17,22
< if arg == '-h' or arg == '-?' or arg == '--help':
< print(('Usage:\n' + \
< ' {0} -h |-? | --help\n' + \
< ' {0} [-l|--line line] file[:line]\n' + \
< ' {0} diff file1 file2').format(sys.argv[0]))
---
> if arg in ['-h', '-?', '--help']:
> print('Usage:\n'
> ' {0} -h |-? | --help\n'
@bittner
bittner / SassMeister-input.scss
Created Nov 6, 2015
Generated by SassMeister.com.
View SassMeister-input.scss
// ----
// libsass (v3.2.5)
// ----
/*
* From pelican theme Cid
* original: https://github.com/hdra/Pelican-Cid/blob/master/src/sass/_manni.scss
* compiled: https://github.com/hdra/Pelican-Cid/blob/master/static/css/cid.css
*/
.highlight
View dict_utils.py
def merge_dicts(*dict_args):
"""
Given any number of dicts, shallow copy and merge into a new dict,
precedence goes to key value pairs in latter dicts.
"""
result = {}
for dictionary in dict_args:
result.update(dictionary)
return result
View python_str_concat_performance.sh
# Python string concatenation
# Appending strings to an existing string is way faster than prepending.
# Source: https://groups.google.com/d/msg/comp.lang.python/AzYJ0LAWe-w/wBLtn5BJIBsJ
python -m timeit -s "v = 'x' * 10; out = ''" "out = out + v"
# prints: 10000000 loops, best of 3: 0.0511 usec per loop
python -m timeit -s "v = 'x' * 10; out = ''" "out = v + out"
# prints: 100000 loops, best of 3: 52.7 usec per loop
python -m timeit -s "v = 'x' * 10; out = ''" "out += v"
# prints: 10000000 loops, best of 3: 0.053 usec per loop
@bittner
bittner / rabbitmq-setup.sh
Last active Mar 17, 2017
DjangoEurope: Celery + RabbitMQ
View rabbitmq-setup.sh
#!/bin/bash
#
# RabbitMQ setup for DjangoEurope
# (c) 2017 Peter Bittner <django@bittner.it>
# based on instruction provided by DjangoEurope
# MIT license
RABBITMQ_HOME=$HOME/rabbitmq
RABBITMQ_ENV=$HOME/.rabbitmq_env
RABBITMQ_NODE_PORT=62024
@bittner
bittner / check-CRLF.bash
Created Nov 5, 2017
Check files for DOS/Windows line endings.
View check-CRLF.bash
#!/usr/bin/env bash
# -----------
# Check files for DOS/Windows line endings.
# -----------
[ -a "$1" ] || {
echo 'Check files for DOS/Windows line endings.'
echo "Usage: ${0##*/} {filename}"
exit 0
}
which dos2unix > /dev/null || {