Using git to mirror a SVN repository on Leopard 3
Working for a new client on a Rails project, I decided to give a shot at Git.
I’m working with an other developer who holds the svn repository. He is the only person allowed to commit to the trunk and I have to commit to my own branch. At first, this doesn’t seemed to be a problem. But there is a lot of files modified every day on the trunk and I’m constantly merging from the trunk to keep my branch up to date. Git seems to have some nice features that could help me to avoid those constant merges.
I writing this article while installing git so I don’t already know if it is the solution to my troubles. I just read this article and it convinced me to give git a try.
I have to mention that I never worked with git before so I will discover git with this project and we’ll see if it’s reasonable. I heard about git on rubyinside blog a few weeks ago.
So, as I’m on leopard, the easiest way (for me) to build git is macports so let’s do it.
sudo port install git-core +svnThis installs all git git-svn and gitk. All ran smoothly for me. If it fails try this install tutorial for leopard.
Now it’s installed properly I need to build my git project from subversion repository
daiquiri% git svn init https://repos.../trunk
Initialized empty Git repository in .git/It doesn’t checkout the sources so let’s check this previously mentioned article to see what I do next.
All right, I need to figured what is the HEAD revision number to go next :svn info https://repos.../trunkgit-svn fetch -r3741
.
.
...The checkout happens...
.
.
r3741 = b444a88efc7248dfdd5f96a7dd7e36165a0f3ed6 (git-svn)
Checking 4130 files out...
100% (4130/4130) done
Checked out HEAD:
https://82.240.32.108/svn/eco-sys/trunk r3741
It seems all went ok and that my git project is ready to go.
I little config seems to make things a little prettier. I took this from here
git config --global user.name "Antonin Amand"
git config --global user.email "aamand@gwikzone.org"
git config --global color.status auto
git config --global color.diff auto
git config --global color.diff auto
git config --global color.branch auto
git config --global merge.tool opendiff
git config --global core.excludesfile ~/.gitignore
echo ".DS_Store" >> ~/.gitignore
cat > ~/.gitk <<EOF
set mainfont {Monaco 10}
set textfont {Monaco 10}
set uifont {Monaco 10}
EOFI will know do some changes in the configuration to get the working on my mac. I understood that the best practice is to create a new branch.
git checkout -b localconfig HEADThis creates a new branch a switch in it immediatly.
I’ve modified some files into my local branch, and have commit to the localconfig branch.git add mymodifiedfile
git add ...
git commitgit commit -aNow I’ve seen that the other developer add update a lot of files in the trunk. So I will try to update my git branch.
git svn rebaseThis first revert your repository before my modifications update from subversion and apply again my commit. All went nicely. Notice that it is extremely more powerfull that trying to apply the update directly on the modified sources.
Now I want to commit to the remote svn, but the other developer don’t allow me to commit to the trunk. I will create a patch with git, create a new branch in the subversion repository from the trunk, apply the patch and then ask for the developer to merge changes from the new branch to the trunk.
So, let’s create the patchgit format-patch remotes/git-svnThen I create the branch into the subversion repository and checkout.
svn copy http://repos/trunch http://repos/branches/merge-branch
svn checkout http://repos/branches/merge-branch
cd merge-branchNow I need to apply the patch.
patch -p1 < /path/to/thepatchsvn commitNow I just have to send an email to the other developer.
With this first shot, I am conviced that git will improve my merging process and be a lot more flexible that SVN.
Now that I will play a lot with patches, next time I’ll probably take a look at StGIT (Stacked Git), patch management utility.
Enable backspace when ssh into a debian machine with zsh 2
As many users of mac OS X, I’ve encountered some troubles with the backspace key when ssh into a debian machine.
Reading some posts on the web, I was thinking that the problem was about the shell or the tty. But in fact it was related to zsh.
The default zsh map on debian is not correct for mac users. The solution is to tell zsh how to bind keys.
echo "bindkey ^? backward-delete-char" >> ~/.zshrc
echo "bindkey ^[[3~ delete-char" >> ~/.zshrcUse ctrl+v [key] to generate the ^... characters.
Extract an image screenshot from a Video with ffmpeg 3
Here is a way to extract a sample image from a video with ffmpeg :
$ ffmpeg -itsoffset -4 -i sample.mov -vcodec png -vframes 1 -an -f rawvideo -s 320x240 test.png- -itsoffset -4 : means that you want to extract the image 4 seconds after video starts.
Easy setup a Mongrel cluster with Apache 2.2 on Mac OS X
Mongrel is a very fast and secure server for Ruby On Rails applications. It also supports Nitro and Camping. Setting up a mongrel_cluster on Mac OS X is not very difficult but it is a bit different from other Unix platforms.
What you need to start :Step 1 : Install Mongrel
Mongrel is available for unix platform and Win32 systems as a gem.
$ sudo gem install mongrel mongrel_clusterInstalling Apache 2.2
You can compile it from sources. But it is easier to install it via MacPorts.
$ sudo port install apache2All apache2 files will be installed in /opt/local/apache2, including binaries and configuration files.
Setting up Apache 2.2
chdir to /opt/local/apache2/conf and copy the sample file to httpd.conf$ cd /opt/local/apache2/conf
$ sudo cp httpd.conf.sample httpd.confCreate a new directory that will contain your application specific configuration files for Apache.
$ sudo mkdir myapp
$ cd myappCreate 3 files for your new application. (adapted from codahale blog)
$ sudo touch myapp.common myapp.conf myapp.cluster.confHere is the files content :
myapp.common :
ServerName www.myserver.com
DocumentRoot /path/to/my/app/public
<Directory "/path/to/my/app/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
# Make sure people go to www.myapp.com, not myapp.com
RewriteCond %{HTTP_HOST} ^myapp.com$ [NC]
RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
# Yes, I've read no-www.com, but my site already has much Google-Fu on
# www.blah.com. Feel free to comment this out.
# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflatemyapp.conf :
<VirtualHost *:80>
Include /opt/local/apache2/conf/myapp/myapp.common
ErrorLog /path/to/logs/error.log
CustomLog /path/to/logs/access.log combined
</VirtualHost>myapp.cluster.conf :
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>Now that your files are created. at this to the bottom of /opt/local/apache2/conf/httpd.conf
NameVirtualHost *:80
Include conf/myapp/myapp.conf
Include conf/sites/myapp.cluster.confApache is now ready to run.
Setting up Mongrel cluster
Create a new dir for mongrel cluster config
mkdir /opt/local/etc/mongrel
cd /opt/local/etc/mongrelAnd create a new file “myapp.yml”
---
user: www
group: www
port: "8000"
cwd: /path/to/your/app/root
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3Setting up Startup Scripts
Enable apache startup script
$ sudo vi /etc/hostconfig
#add the following lines
APACHE2=-YES-
MONGREL=-YES-Copy the following into /Library/StartupItems/mongrel_cluster/mongrel_cluster
(adapted from original mongrel init script)#!/bin/bash
#
# Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com
#
# mongrel_cluster Startup script for Mongrel clusters.
#
# chkconfig: - 85 15
# description: mongrel_cluster manages multiple Mongrel processes for use \
# behind a load balancer.
#
[ -r "/etc/hostconfig" ] && . "/etc/hostconfig"
CONF_DIR="/opt/local/etc/mongrel"
RETVAL=0
ENABLE_FLAG=${MONGREL:=-NO-}
if [ "${ENABLE_FLAG}" = "-NO-" ]; then
echo "Mongrel is disabled. see /etc/hostconfig"
exit 0
fi
case "$1" in
start)
mongrel_cluster_ctl start -c $CONF_DIR
RETVAL=$?
;;
stop)
mongrel_cluster_ctl stop -c $CONF_DIR
RETVAL=$?
;;
restart)
mongrel_cluster_ctl restart -c $CONF_DIR
RETVAL=$?
;;
*)
echo "Usage: mongrel_cluster {start|stop|restart}"
exit 1
;;
esac
exit $RETVALFLV encoding with ffmpeg 15
ffmeg is a command-line tool for video encoding which has the ability to encode videos in FLV format (Macromedia plugin for direct-streaming).
First, you need to install ffmpeg with liblame support.
You may grab it as package or compile from sources.
We will compile from sources in this article for more compatibility.
first step : Installing lame get sources at http://lame.sourceforge.net, untar the archive and chdir to unpacked sources directory.
$ ./configure && make && sudo make installsecond step : Installing ffmpeg
Getting sources from svn :
$ svn export svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpegChange dir to ffmpeg and compile with liblame
$ ./configure --enable-mp3lame && make && sudo make installYour now setup. You can continue with encoding your first video
$ /usr/local/bin/ffmpeg -i input.mov -ar 22050 -ab 56 -aspect 4:3 \
-b 200 -r 12 -f flv -s 320x240 -acodec mp3 -ac 1 output.flvto view the result download a swf FLV player and create a html file :
<html>
<head>
<title>Flash FLV Player</title>
</head>
<body>
<h3>My First FLV video</h3>
<object type="application/x-shockwave-flash" width="320" height="260" wmode="transparent" data="flvplayer.swf?file=output.flv&autoStart=false">
<param name="movie" value="flvplayer.swf?file=output.flv&autoStart=false" />
<param name="wmode" value="transparent" />
</object>
</body>
</html>Enjoy !
Creating favicon.ico on Unix machines
Favicon are little icons that you can see in your browser before URL address.
To create this icons on unix-likes proceed as follow.
Open your favourite Image manipulator program, for me It will be The GIMP.
Create a 16×16 px PNG, and optionally a 32×32 px PNG.
Install png2ico from sources, package or compile it via darwinports.
For OS X with darwinports :
$ sudo port install png2icoand create your favicon file :
$ png2ico favicon.ico favicon16.png favicon32.pngNow that you have your favicon file, just put it in your web server root directory.
You can had the following for IE compatibily in your web pages :
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
Mac OS X : change lookup order, files comes first
I’m originally a Linux user. Then, in Linux lookup default order is to look first in /etc/hosts file and then to launch the dns query.
But In OS X default is to search to into NetInfo DB first.
To change this behaviour you have to change the configuration of the lookup daemon.
$ cd /etc
#if lookupd directory doesn't exists create it
$ sudo mkdir lookupd
$ cd lookupd
$ sudo echo LookupOrder Cache FF NI DNS DS > /tmp/hosts
$ sudo mv /tmp/hosts .
# reload configuration of lookupd
$ sudo lookupd -configurationAll right, you’re now setup the old fashion way.
Mac OS X : Restart ARDAgent from ssh
ARDAgent (Apple Remote Desktop Agent) sometimes freeze and then it may be impossible to control your remote server.
Here is the command line to restart it.
# ssh into you machine
$ ssh user@host
# locate the restart script
$ locate kickstart
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart
# restart the agent
$ cd /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources
$ sudo ./kickstart -restart -agent
Buying a mac, being lucky...
The point of this blog is not to talk about my life but for this time I’ll make an exception.
Luck comes when you doesn’t expect it.
After six month of great frustration with my iBook cause it doesn’t stop to crash, I decide to buy the new Macbook.
So, I go to my favorite store with the intention to buy the cheapest macbook. But when i arrive to the shelf, I discover that the 1GBram – DVDWriter – 2Ghz intel is sold at a reduced price (about less $150). It’s still more expensive but I decide to buy it. Unfortunatly, they doesn’t have it anymore, I have to go an other store (30 miles further) which is supposed to have it at the same price.
But when i arrive, they don’t have anymore. Sadly, I decide to take the one i came for at the first time, the cheapest. I’m not so sad, I have my new Macbook anyway, and I spent less money.
I come back home, unpack, plug, configure, and start to look at the system info tool. This is a this moment that I figure out there where a mistake in the labelling and that I have bought the more expensive one at the price of the cheapest.

Yes, this happens only to others, except for me ;)
Mac OS X : properly change shell when using zsh from darwinports/macports
If like me you use a up to date zsh shell under Mac OS X installed via DarwinPorts (which change name to MacPorts) you may want to set it as your default shell.
To do this in a proper way (not by changing it in Terminal.app Preferences) you should proceed as following.
$ sudo vi /etc/shells
# add the following line :
/opt/local/bin/zsh
$chsh
# and change /bin/bash to /opt/local/bin/zsh
