Skip to content

Instantly share code, notes, and snippets.

View python-consulting's full-sized avatar

python-consulting

View GitHub Profile
@python-consulting
python-consulting / git_init.sh
Created January 21, 2014 14:46
git init bare repository
mkdir test_repo.git
cd test_repo.git
git --bare init
@python-consulting
python-consulting / __init__.py
Created January 21, 2014 14:57
utf-8 encoding specifier
# -*- coding: utf-8 -*-
@python-consulting
python-consulting / gist:8669066
Last active January 4, 2016 19:39
Python basic argument parser
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("arg1", help="contextual help for arg1")
args = parser.parse_args()
@python-consulting
python-consulting / gist:8669532
Created January 28, 2014 15:22
Python string template
>>> from string import Template
>>> s = Template('$who likes $what')
>>> s.substitute(who='tim', what='kung pao')
'tim likes kung pao'
@python-consulting
python-consulting / gist:8669651
Created January 28, 2014 15:29
Python create and write file
def create_and_write_file(filename, data):
fd = open(filename, "w")
if not fd:
raise Exception("Unable to create %s. Check for read-write permissions." % filename)
fd.write(data)
fd.close()
@python-consulting
python-consulting / gist:8861203
Last active August 29, 2015 13:56
SQL Database + User creation
# Database name : db_name
# Password : db_pwd
CREATE DATABASE db_name;
ALTER DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL ON db_name.* TO 'db_name_user'@'localhost' IDENTIFIED BY 'db_pwd';
FLUSH PRIVILEGES;
@python-consulting
python-consulting / default.pa
Created February 25, 2014 21:38
pulseaudio default raspberry
#!/usr/bin/pulseaudio -nF
#
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
@python-consulting
python-consulting / daemon.conf
Created February 25, 2014 21:39
pulseaudio daemon conf raspberry
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@python-consulting
python-consulting / python_startup.py
Last active August 29, 2015 13:56
Enable interactive python auto completion on any platform
# -*- coding: utf-8 -*-
import sys
if sys.platform.startswith('linux'):
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
@python-consulting
python-consulting / gist:9485242
Created March 11, 2014 13:07
Instant ssh rsa key copy
cat | ssh user@server 'cat - >> ~/.ssh/authorized_keys'