Skip to content

Instantly share code, notes, and snippets.

🐍
Python is my love affair

Peter Bittner bittner

🐍
Python is my love affair
Block or report user

Report or block bittner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bittner
bittner / keyboard-keys.md
Created Feb 28, 2019
Keyboard keys markup in MarkDown
View keyboard-keys.md

Ctrl + Alt + Space

@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 || {
@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
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 / toggle-sshd.sh
Last active Feb 11, 2016
How can I access my Ubuntu phone over ssh? (no `adb shell` required)
View toggle-sshd.sh
#!/bin/bash
# GNU GPL v3 license, (c) 2016 by Alexander Kinne, Peter Bittner
# http://askubuntu.com/questions/601910/ssh-ubuntu-touch/653595#653595
IP_ADDRESS=$(ip addr show primary | grep wlan | grep 'inet ' | sed -e 's/^\s*inet //' -e 's/ brd .*$//' -e 's#/.*##')
echo "Your IP address: $IP_ADDRESS (wlan)"
if [[ "$(android-gadget-service status ssh)" == "ssh enabled" ]]; then
sudo android-gadget-service disable ssh
else
@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
@bittner
bittner / 60-jetbrains.conf
Created Sep 25, 2015
Inotify configuration for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm). Create this file with e.g. `sudo vim /etc/sysctl.d/60-jetbrains.conf`
View 60-jetbrains.conf
# Set inotify watch limit high enough for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm).
# Create this file as /etc/sysctl.d/60-jetbrains.conf (Debian, Ubuntu), and
# run `sudo service procps start` or reboot.
# Source: https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit
#
# More information resources:
# -$ man inotify # manpage
# -$ man sysctl.conf # manpage
# -$ cat /proc/sys/fs/inotify/max_user_watches # print current value in use
@bittner
bittner / .bash_aliases
Created Jul 9, 2015
.bash_aliases for Mac
View .bash_aliases
# .bash_aliases
# Source: http://techie-notebook.blogspot.ch/2012/04/making-your-terminal-look-pretty-on-mac.html
# enables color in the terminal bash shell
export CLICOLOR=1
# sets up the color scheme for list
export LSCOLORS=gxfxcxdxbxegedabagacad
# enables color for iTerm
export TERM=xterm-color
# Color Prompt
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
@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'
You can’t perform that action at this time.