Skip to content

Instantly share code, notes, and snippets.

@miebach
miebach / print_environ.py
Created July 2, 2011 13:26
Print the environment array in python
import os
for param in os.environ.keys():
print "%20s %s" % (param,os.environ[param])
# from http://www.wellho.net/resources/ex.php4?item=y115/penv.py
@miebach
miebach / dos2unix_using_tr.sh
Created July 11, 2011 12:07
Convert a DOS text-file to unix by removing cr and ^Z characters
#!/bin/sh
# remove cr and ^Z characters from a dos file:
# the codes are octal, oct15 = dec13 and oct32 = dec26
tr -d '\15\32' < winfile.txt > unixfile.txt
@miebach
miebach / create-ram-disk.sh
Created July 12, 2011 01:14
Create a ramdisk in linux on th fly
#!/bin/sh
mkdir -p /tmp/ramdisk
sudo mount -t tmpfs -o size=512M tmpfs /tmp/ramdisk
#sudo mount -t tmpfs -o size=1G tmpfs /tmp/ramdisk
@miebach
miebach / gist:1083152
Created July 14, 2011 18:58
Show only relevant lines in linux config files
cat some.conf | sed 's/^[ \t]*//' |grep -v ^# | sed '/^$/d'
# as result all non-blank lines from some.conf that do not start with a "#" (which means this only a comment line) are printed to the terminal
# in short: show the lines that contain something relevant
# the first sed removes trailing spaces from all lines
# the grep removes all lines that start with a "#"
# the second sed removes all blank lines
@miebach
miebach / gist:1083216
Created July 14, 2011 19:22
Permissions and config file contents of a clean postgres 8.4 install on fedora14
We couldn’t find that file to show.
@miebach
miebach / mysql_test_db_connection.php
Created October 7, 2011 11:45
Testing MySQL connection and select DB with PHP
<?php
echo "Connecting to MySQL Server ... ";
mysql_connect(
"localhost",
"admin",
"pass123")
or die(mysql_error());
echo "[OK]<br />";
@miebach
miebach / dump_object.py
Created October 16, 2011 15:42
Python debugging and inspection: print (or return as string) a nicely formatted overview of a python object. Works on a module, class or instance.
# recipe-137951-1.py
# from http://code.activestate.com/recipes/137951-dump-all-the-attributes-of-an-object/
# created by (C) Philip Kromer http://code.activestate.com/recipes/users/552075/
# forked as https://gist.github.com/1291055
# licence = psf http://code.activestate.com/recipes/tags/meta:license=psf/
# On python attributes and methods read: http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html
from cStringIO import StringIO
import sys
@miebach
miebach / docprint.py
Created November 2, 2011 17:54
docprint - python helper function to print to sys.stderr
import sys
"""
Save this file as c:\Python24\Lib\docprint.py or in your application or library directory.
File is maintained as a gist at github: https://gist.github.com/1334355
"""
def write(txt):
@miebach
miebach / decode_guess.py
Created December 5, 2011 15:03
Guess the encoding of a python string
def decode_guess(s, etypes=('utf8','latin1','ascii')):
"""
Returns an unicode object
"""
for et in etypes:
try:
return s.decode(et)
except UnicodeDecodeError:
pass
return s.decode('ascii', 'ignore')
@miebach
miebach / index.html
Created February 11, 2012 19:09
Html-Parkschild
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Hier entsteht eine neue Internetpräsenz!</title>
<style type="text/css">
#message {
font-size: 250%;
color: #546354;
font-family: Arial, Helvetica, sans-serif;