Skip to content

Instantly share code, notes, and snippets.

View philippeowagner's full-sized avatar

Philippe O. Wagner philippeowagner

View GitHub Profile
@philippeowagner
philippeowagner / .bashrc
Last active December 25, 2015 14:09
Aliasse für mehr Sicherheit in die Bash. Siehe auch https://www.arteria.ch/blog/mehr-sicherheit-dank-bash-aliasse/.
# ...
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
alias crontab='crontab -i'
@philippeowagner
philippeowagner / gist:7248858
Created October 31, 2013 12:27
Iterate over kwargs and write to file
f = open (...)
for k,v in kwargs.iteritems():
f.write("%s = <%s>\n" % (str(k), str(v)))
import redis
import threading
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)
@philippeowagner
philippeowagner / gist:7265120
Last active December 27, 2015 04:09
SettingsBackend (login from django settings)
class SettingsBackend(object):
"""
Authenticate against the settings ADMIN_LOGIN and ADMIN_PASSWORD.
Use the login name, and a hash of the password. For example:
ADMIN_LOGIN = 'admin'
ADMIN_PASSWORD = 'sha1$4e987$xxxxx'
"""
@philippeowagner
philippeowagner / gist:7321439
Created November 5, 2013 16:11
Simple example showing how to add a ``toDict`` and a ``toJSON`` method to a python class. Implement a ``toJSON`` is straightforward by importing ``simplejson`` and using ``dumps`` on the result of ``toDict``.
class MyClass(object):
''' Example class for the toDict method. '''
# We want these in our JSON result.
place = "World"
name = "Steve Jobs"
# We do not want these in our JSON result.
tmpdata = None
connection = None
@philippeowagner
philippeowagner / install.sh
Last active December 28, 2015 10:19
MySQL Database clone/sync script To install use install.sh :) Usage ./mysqlsyncdb <password> <source db> <target db>
#!/bin/sh
TARGET=/usr/local/bin/mysqlsyncdb
wget https://gist.github.com/philippeowagner/7485160/raw/mysqlsyncdb -O $TARGET
chmod 755 $TARGET
@philippeowagner
philippeowagner / index.html
Created November 19, 2013 20:54
Visual dev-warning stolen from the Django project page. https://docs.djangoproject.com/en/dev/
...
<div id="dev-warning">
dev-warning
</div>
...
@philippeowagner
philippeowagner / gist:7989384
Created December 16, 2013 15:59
Dump an object into an alert like it would be done by (similar to) console.log.
var output = '';
for (property in objects) {
output += property + ': ' + objects[property]+'; ';
}
alert(output);
@philippeowagner
philippeowagner / gist:8055537
Created December 20, 2013 14:33
HTTP 307 (Temporary Redirect) in Django
from django.http import HttpResponse, iri_to_uri
class HttpResponseTemporaryRedirect(HttpResponse):
status_code = 307
def __init__(self, redirect_to):
HttpResponse.__init__(self)
self['Location'] = iri_to_uri(redirect_to)
(*
Applescript to launch a diff tool to compare two notes in Evernote.
Useful to compare conflicting notes
1. Place the script file in ~/Library/Scripts/Applications/Evernote
2. Ensure Applescript menu bar item is on. Option to turn on/off is under General Preferences in AppleScript Editor
3. The variable difftool can be change to any command line tool you require
*)
-- opendiff launches FileMerge.app developer tool