triptico.com

Un naufragio personal

Notes

More on Apache's mod_rewrite

Links:

What I use here to emulate static pages:

 RewriteEngine On
 RewriteRule /(img|download)/.* - [L]
 RewriteRule ^/(.+)/index\.html$ /?t=TOPIC&topic=$1       [PT]
 RewriteRule ^/(.+)/(.+)\.html$  /?t=STORY&topic=$1&id=$2 [PT]
 RewriteRule ^/(.+)/$            /?t=TOPIC&topic=$1       [PT]
 RewriteRule ^/rss\.xml$         /?t=RSS                  [PT]
 RewriteRule ^/sitemap\.xml$     /?t=SITEMAP              [PT]

Sharing code via email with git

In a clone of a remote repository, start a branch to hold your code:

 git-checkout -b my-changes

Do your work and commit changes as you like.

When you are happy with your work, create a temporary directory:

 mkdir /tmp/patches

Then change back to the master branch and build a set of patches from your branch with git-format-patch:

 git-checkout master
 git-format-patch -n master..my-changes -o /tmp/patches

A bunch of files, one per changeset, have been created in /tmp/patches. Now, use the git-send-email to send them, one per email, to the original author.

 git-send-email --no-thread --from me@here --to author@remote /tmp/patches

If author@remote acknowledges your changes, you can just merge your changes to the current master head and delete your temporary branch:

 git-merge my-changes
 git-branch -d my-changes

On the remote machine

If author@remote uses mutt, he can move to his working copy, call it and type |git-am on each message.

Matching git-svn strange authors to useful email addresses

Git-svn is a useful tool to communicate with a Subversion repository from git. You usually clone a repository with a command like:

 git-svn clone svn+ssh://angel@svn.example.com/path/to/prj/trunk prj

And a prj directory is created with a full git repository. Then, you get another people changes with git-svn rebase and commit yours with git-svn dcommit.

It has one drawback, though; authors are mangled to something like

 Author: angel <angel@2e99d34b-3c1d-0410-9ca7-923d03b5684e>

which is not only ugly but completely useless.

To map this monstrosity to real user email addresses and names, use the following steps:

First, create the file ~/.gitusers with content like this:

 angel = Ángel Ortega <angel@triptico.com>
 otheruser = Other User <ouser@example.net>

If you converted your SVN repository from CVS with something like cvs2svn you'll also find entries like this:

 Author: (no author) <(no author)@2e99d34b-3c1d-0410-9ca7-923d03b5684e>

Those ones can be converted with another line in ~/.gitusers.

 (no author) = Really Me <email@example.org>

And now, instead of the usual git-svn clone command, use the following ones:

 mkdir prj
 cd prj
 git-svn init svn+ssh://angel@svn.example.com/path/to/prj/trunk
 git config svn.authorsfile ~/.gitusers
 git-svn fetch

Always maximized X11 terminal emulators

Add this to your ~/.bashrc:

 [ -z "$DISPLAY" ] || wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz

Desactivación de servicios telefónicos molestos

Telefónica (fijo)

Contestador
Llamar al #10#

Movistar

Buzón
Llamar al 537
Avísame
Llamar al 579

My preferred way of C code formatting

They mean: Kerninghan & Ritchie indentation, 4 spaces, no cuddled else, no tabs.

 indent -kr -i4 -nce -nut *.c

I previously used:

 indent -kr -i8 -nce *.c

Setting global git variables

 git config --global user.name "Angel Ortega"
 git config --global user.email angel@triptico.com

Building a point-to-point VPN (SSH tunnel) in one line

 pppd noauth 192.168.33.1:192.168.33.2 \
     pty 'ssh root@REMOTE_HOST pppd notty noauth'

The remote host needs a passwordless authorized key.

Redirecting a full site to https

 <Location />
        RewriteEngine on
        RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1
 </Location>

Perl one-liner to know the length of an MP3 song

 perl -MMP3::Info -e '$i = get_mp3info($ARGV[0]); \
   printf "%d:%d", $i->{MM}, $i->{SS};' song.mp3