Git hints

Here are some hints I find very useful for working with git.

More colour

To get a colourful output in your terminal.

$ git config --global color.branch auto
$ git config --global color.status auto
$ git config --global color.diff true

Merging

For merging I like to use the program `meld`. Add any merge tool you want, such as kdiff3 or xxdiff.

$ git config --global merge.tool meld

For conflicts, you can solve the mess, with your favourite merge program.

$ git mergetool

meld

Checking the logs

Shows the commit log like `git log` including a listing of which files had modifications in a particular commit.

$ git whatchanged

Reset a file to an old revision

Overwrite the file `foobar` with the third last revision of `foobar`.

$ git show HEAD~3:foobar > foobar

Writing a hook

Remove all compiled python files (pyc) before a commit start. To activate a hook you have to make the hook you want in `.git/hooks/` executable.

$ echo "find -name '*.pyc' -delete" >> .git/hooks/pre-commit
$ chmod u+x .git/hooks/pre-commit

Exporting

Create a clean repository export to a folder `foo` in a compressed archive.

$ git archive --format=tar --prefix=foo/ HEAD | gzip -c > foo.tar.gz

That’s not so handy like in svn, I know. Maybe you want to use rsync instead?

$ rsync --exclude='.git'

Blame with GUI

You must install the git-gui package for using it.

$ git gui blame file

git-gui-blame

Mit GNOME Do produktiver am GNOME-Desktop (freiesMagazin)

GNOME Do erlaubt den Anwendern, sehr schnell durch heterogene Daten zu navigieren, Anwendungen und Skripte zu starten sowie Aktionen auszuführen. Ein ähnliches Programm existiert für Mac OS X und heißt Quicksilver. GNOME Do ist einfach, wenn gewollt komplett ohne Maus zu bedienen und sieht auch grafisch hervorragend aus. Nicht zu Unrecht heißt es auf der Entwickler-Website „A powerful, speedy, and sexy remote control for your GNOME Desktop“.

erschienen im freiesMagazin November 2008

http://www.freiesmagazin.de/mobil/freiesMagazin-2008-11-bilder.html#08_11_gnomedo

Gnome Deskbar Applet plugins

This is a collection of my plugins, I wrote for the Gnome Deskbar Applet. Feel free to use them!
You can find the code repository on launchpad https://code.launchpad.net/~bernde/+junk/deskbar-plugins.

leo de/en translate – plugin

Queries the online dictionary of dict.leo.org, only for english or german words.

deskbar-leo

Read more »

Praxiswissen Ruby

Sascha Kersken hilft mit seinem leicht verständlichen Buch “Praxiswissen Ruby” AnfängerInnen und UmsteigerInnen mit praktischen Beispielen in die Welt der Ruby-Programmierung einzusteigen.

Den Anfang machen die Geschichte von Ruby, die Installation und das klassische “Hello World”-Skript. In den nächsten Kapiteln geht es darum, sich mit den Sprachgrundlagen und jeder Menge Ruby-typischem “syntactic sugar” vertraut zu machen. Nach funktionalen und prozeduralen Programmier-Beispielen geht es im dritten Kapitel um Objektorientierte Programmierung. Dabei wird das Verwenden von eingebauten Ruby-Klassen (Ein- und Ausgabe, Datum und Zeit usw.) sowie der Ruby-Hilfe “ri” vermittelt. Im nächsten Kapitel beginnen die LeserInnen mit dem Erstellen eigener Klassen. Dabei bleiben keine Fragen rund um die Objektorientiertung von Ruby offen. Nach einer sehr kurzen und gelungenen Einführung in die Netzwerk-Topologie werden Netzwerkanwendungen mit Ruby gebaut, etwa ein Browser und ein Server. Einer der bekanntesten Bereiche von Ruby ist eindeutig das Web-Framework Ruby on Rails, das im letzten Kapitel eingesetzt wird um eine Webanwendung zu bauen, mit der sich die CD-Sammlung verwalten lässt. Um Webanwendungen ging es schon im Kapitel davor, allerdings um einfachere, ohne Ruby on Rails, mittels CGI. Ebenso ging es um Zugriffe auf MySQL-Datenbanken. Ganz hinten befindet sich eine hilfreiche Kurzreferenz.

Das Buch bietet einen guten und vor allem schnellen Einstieg in die Sprache Ruby und schneidet dabei auch das Web-Framework Ruby on Rails kurz an. Der Aufbau ist logisch und die Beispiele praxisnahe. Damit ist es für jedeN, egal mit welchem Vorwissen, eine ausgezeichnete und flott durchgearbeitete Lektüre, die mit Ruby vertraut macht.

Sascha Kersken
Praxiswissen Ruby
O’Reilly Verlag 2008
408 Seiten
EUR 29.90
ISBN: 978-3-89721-478-1

rezensiert von Bernd Essl (November 2008)

Different templates for iPhone/iPod in Django

I use this Django Middleware for detecting iPhones or iPods and for setting the template directory dynamically. If the user agent is an iPhone or iPod, the template directory is changed, so that different templates for the iProducts can be used. The idea is taken from this snippet, but it only detects iPhones and I had some troubles with caching so I wrote one myself.

from django.conf import settings
import re

class iPhoneMiddleware(object):
    """
    If the Middleware detects an iPhone/iPod the template dir changes to the
    iPhone template folder.
    """

    def __init__(self):
        self.normal_templates = settings.TEMPLATE_DIRS
        self.iphone_templates = (settings.TEMPLATE_DIRS[0] + '/iphone',)

    def process_request(self, request):
        p = re.compile('iPhone|iPod', re.IGNORECASE)
        if p.search(request.META['HTTP_USER_AGENT']):
            # user agent looks like iPhone or iPod
            settings.TEMPLATE_DIRS = self.iphone_templates
        else:
            # other user agents
            settings.TEMPLATE_DIRS = self.normal_templates
        return

tips and tricks with .htaccess

.htaccess (hypertext access) is the default name of Apache’s directory-level configuration file. .htaccess is placed in a particular directory, and the directives in the .htaccess file apply to that directory, and all subdirectories thereof.

The most common feature is to restrict access to a folder by force the user to a login prompt, but there are some other helpful things also that I show you in this posting.

Read more »

Protect your application against SQL injections (2)

In part 1 we made sure that the value is an integer, but what if a value could be a string?
You have to escape special characters in a string for using in a SQL statement. This means that a single quote (‘) get a backslash before (\’).

There are escape functions for each popular database:

Read more »

Protect your application against SQL injections (1)

Many applications use a database to store data. Popular products are MySQL, SQLite and PostgreSQL.
A lot websites use a number called ID in the URL to get more information to a dataset like a product or a posting.

The problem of using ID’s is if they aren’t validated, bad guys and girls can spy, change or destroy your database by manipulating the SQL query.
This attack is called SQL injection.

An example to get the field “title” in the row with the value of $_GET['id']

Read more »

Train websecurity with WebGoat

WebGoat is a insecure web application which is designed to teach web application security concepts.
You can try hacking: Access Control Flaws, Authentication Flaws, Session Management Flaws, Cross-Site Scripting (XSS), Buffer Overflows, Injection Flaws, Improper Error Handling, Insecure Storage, Denial of Service, Insecure Configuration, Web Services and AJAX Security.

There is a “Lesson Plan” a kind of tutorial and in the “Hints Menu” you can view the parameters, cookies, the Code and the solution.
It’s a lot of fun and you learn more about web application security.

Read more »

Some notes on handling Development and Production Servers with Django.

How to find out if we are on development or production?

The first thing I do is to define a variable “DEVELOPMENT_MODE“ in settings.py, that checks if the server is running on my local machine or not. I found this nice idea on the djangoproject.com website: http://code.djangoproject.com/browser/djangoproject.com/django_website/settings.py

Read more »

Next Page »