mysql-ruby-2.6 patch for ruby 1.9.1rc1

Posted by Antonin AMAND Sat, 03 Jan 2009 18:40:00 GMT

Here is a patch to make mysql works with ruby 1.9.1rc1 until it is fixed.

You can clone the full patched library from here.

  git clone git://github.com/gwik/mysql-ruby-191-compat.git

First release of ffmpeg-ruby 1

Posted by Antonin AMAND Sun, 12 Oct 2008 18:47:00 GMT

ffmpeg-ruby is a ruby C extension binding to ffmpeg/libav* library.

It's main purpose (at least for now) is to extract frame in order to make video thumbnails. It also give access to main video attributes (frame rate, bit rate, duration, codecs, ...)

I've been working on this for some time now but I finally took the time to clean and package it

So here it is version 0.1.0

You can checkout the code with git :

git clone git://github.com/gwik/ffmpeg-ruby.git

Here is a example of what it can do : creating an animated gif from a video

Git and Rails : Switch your database.yml when changing branch 1

Posted by Antonin AMAND Wed, 09 Jul 2008 10:01:00 GMT

As a lot of people, I think, I have different database.yml file according to git branch I'm working on. I was constantly switching it manually until I discovered that git has more hooks that I thought.

I set up a post-checkout hooks script to automagically switch my database.yml when checking out a branch.

It is a simple script that recover the branch name a do a symlink.

if i checkout branch master it will look for a file named config/database.master.yml and create a symlink to config/database.yml

here it is :


#! /bin/sh
#
# .git/hooks/post-checkout

BRANCH=`git symbolic-ref HEAD 2> /dev/null | sed -e 's/^.*\///'`
GITPATH="`git rev-parse --git-dir 2>/dev/null`/.."

if [ "$BRANCH" == "" ]; then
        echo "no branch name. do nothing"
        exit 0
fi

if [ -f "$GITPATH/config/database.yml" ] && [ ! -L "$GITPATH/config/database.yml" ]; then
        echo "database.yml exists and not a symlink. do nothing."
        exit 0
fi

echo "look for $GITPATH/config/database.$BRANCH.yml"

if [ -f "$GITPATH/config/database.$BRANCH.yml" ]; then
        echo "switch database configuration file to config/database.$BRANCH.yml"
        rm -f "$GITPATH/config/database.yml";
        ln -s "$GITPATH/config/database.$BRANCH.yml" \
        "$GITPATH/config/database.yml"
fi
 

or on Pastie

Using git to mirror a SVN repository on Leopard 3

Posted by Antonin AMAND Mon, 04 Feb 2008 10:20:00 GMT

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 +svn

This 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.../trunk
I can now fetch the sources.
git-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}
EOF

I 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 HEAD

This 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 commit
will only commit files you added with git add. Or you can use
git commit -a
will commit every modified files.

Now 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 rebase

This 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 patch
git format-patch remotes/git-svn
This creates a traditional UNIX patch.

Then 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-branch

Now I need to apply the patch.

patch -p1 < /path/to/thepatch
All I have to do now is to commit to the svn.
svn commit

Now 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.

Rails : convert all tables to utf8 2

Posted by Antonin AMAND Tue, 06 Nov 2007 15:42:00 GMT

I sometimes need to convert old rails mysql databases to use unicode (utf8)

here is a way to do this quickly :

require 'rubygems'
require 'active_record'

db = "my_database"

sqlconn = ActiveRecord::Base.establish_connection(
  :adapter  => "mysql", 
  :host     => "localhost", 
  :username => "root", 
  :password => "", 
  :database => db
)

conn = ActiveRecord::Base.send(sqlconn.adapter_method,sqlconn.config)

conn.tables.each do |table|
    q = "ALTER TABLE #{table} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"
    puts q
    conn.execute q
end 
conn.execute("ALTER DATABASE #{db} DEFAULT CHARACTER SET utf8 ;")

edit : see Agouti’s comment

Enable backspace when ssh into a debian machine with zsh 2

Posted by Antonin AMAND Tue, 30 Oct 2007 12:16:00 GMT

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" >> ~/.zshrc

Use ctrl+v [key] to generate the ^... characters.

New syntax for DefaultOrder plugin 2

Posted by Antonin AMAND Mon, 15 Oct 2007 13:51:00 GMT

I’ve updated the DefaultOrder plugin that now have a new syntax.


class Contact < ActiveRecord::Base 

 order_by :fields => ['last_name', 'first_name'], :mode => :desc

end

More details.

Rails : Validate availablity of a distant ressource over HTTP

Posted by Antonin AMAND Wed, 18 Jul 2007 22:39:00 GMT

Sometimes you may host some ressources on a different website and you may want to validate the availability of it when creating a Rails model object (ActiveRecord::Base).

It would be dramatically unefficient to download the full media with a GET request. So, to achieve this we will use the HEAD http request that act as the GET request but return only the HTTP header without the body.

Here is a exemple of an ActiveRecord::Base object that validates the presence of the ressource among the Internet.


require 'net/http'

# the class is supposed to have a "media" attribute
# that is a relative url to a ressource hosted an a different
# website
class Article < ActiveRecord::Base

  RESOURCE_HOST = "flickr.com"
  RESOURCE_PORT = 80

  validate :validates_presence_of_external_media

  protected

  def validates_presence_of_external_media
    response = nil
    # initiating the HTTP connection
    Net::HTTP.start(RESOURCE_HOST, RESOURCE_PORT) do |http|
      # doing the HEAD request
      response = http.head(media)
    end
    # add an error if the request is not successful
    errors.add :media, "ressource unavailable : #{response.code} #{response.msg}" unless
      responce.kind_of?(Net::HTTPSuccess)
  end

end

This is a very minimalist example, but this kind of technic may have a lot of uses.

Extract an image screenshot from a Video with ffmpeg 3

Posted by Antonin AMAND Mon, 27 Nov 2006 18:17:00 GMT

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.

Default Order Plugin for Ruby On Rails

Posted by Antonin AMAND Mon, 16 Oct 2006 18:40:00 GMT

I’ve started the development of Default Order Plugin for Ruby on Rails

more…

Older posts: 1 2 3