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 / sqlite2pg.sh
Last active January 23, 2024 08:35 — forked from eclubb/sqlite2pg.sh
#!/bin/bash
# This script will migrate schema and data from a SQLite3 database to PostgreSQL.
# Schema translation based on http://stackoverflow.com/a/4581921/1303625.
# Some column types are not handled (e.g blobs).
#
# See also:
# - http://stackoverflow.com/questions/4581727/convert-sqlite-sql-dump-file-to-postgresql
# - https://gist.github.com/bittner/7368128
@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 / gnu-tools-for-mac.sh
Last active December 11, 2021 20:05
Cross-OS compatibility with GNU tools (readlink, sed, zcat, zless, zdiff, ...) for Mac OS X towards Linux
# DESCRIPTION OF PROBLEM: Implementations of sed, readlink, zcat, etc. are different on OS X and Linux.
# NOTE: Put this on top of your script using sed, readlink, zcat, etc. that should work alike on Mac OS X.
# cross-OS compatibility (greadlink, gsed, zcat are GNU implementations for OS X)
[[ `uname` == 'Darwin' ]] && {
which greadlink gsed gzcat > /dev/null && {
unalias readlink sed zcat
alias readlink=greadlink sed=gsed zcat=gzcat
} || {
echo 'ERROR: GNU utils required for Mac. You may use homebrew to install them: brew install coreutils gnu-sed'
@bittner
bittner / django-csrftoken-login-demo.bash
Last active August 15, 2022 23:45
Login and perform actions in a Django site (now with less security issues)
# source this code in a Bash shell ($ . django-csrftoken-login-demo.bash),
# and run with a DB name as parameter (e.g. $ django-csrftoken-login-demo demo)
django-csrftoken-login-demo() {
# -- CHANGE THESE VALUES TO MATCH YOUR ACCOUNT --
local HOSTING_USERID=9988
local HOSTING_PANEL_USER='customer@email.address'
local HOSTING_PANEL_PASS='my secret login password'
local HOSTING_DB_PREFIX='username_'
local DB_NAME=$HOSTING_DB_PREFIX$1
@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'
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 / .bash_aliases
Created July 9, 2015 11:45
.bash_aliases for Mac
# .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