Skip to content

Instantly share code, notes, and snippets.

View bittner's full-sized avatar
🐍
Python is my love affair

Peter Bittner bittner

🐍
Python is my love affair
View GitHub Profile
@bittner
bittner / .bash_virtenv
Last active August 29, 2015 13:56
Automatically activate virtualenv in Python development. (Source this file from within .bashrc)
# 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 August 29, 2015 13:56
Quick test project generator for Django package development
#!/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 August 29, 2015 13:58
Bootstrap-Sass JavaScript generation (combine + minify) using vanilla Compass
# 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 November 14, 2014 17:47
Apache Status Remote Querying
#!/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 August 29, 2015 14:16
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
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 November 6, 2015 15:39
Generated by SassMeister.com.
// ----
// 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
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
# 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 March 17, 2017 16:47
DjangoEurope: Celery + RabbitMQ
#!/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 November 5, 2017 11:52
Check files for DOS/Windows line endings.
#!/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 || {