osx snippets

How to install fink on Mac OSX Leopard

Tagged fink, osx, apt-get  Languages bash
tar zxvf fink*
cd fink*

# Run following command, and answer the questions to your best knowledge, use defaults if uncertain
./bootstrap /sw

source /sw/bin/init.sh 

fink selfupdate

How to install ffmpeg, mencoder and flvtool2 on Mac OSX Leopard, convert an AVI to FLV, and view the FLV video with FlowPlayer

Tagged ffmpeg, osx, leopard, flvtool2, flv, mencoder, h.264  Languages bash

This is a short tutorial on how to quickly get up to speed with FLV movie creation (transcoding) and viewing (Flash player).

I tried to install ffmpeg using ports and fink, but had problems. The instructions I found here work though.

The following is my adaptation of the instruction, where I show you how to install both ffmpeg and flvtool2.

First, download ffmpegx, which contains ffmpeg from http://ffmpegx.com/download.html

Then, mount the .dmg file, navigate to the mounted disk, and control-click on the ffmpegX application (ffmpegX.app), choose Show Package Contents from the pop-up menu, and copy the ffmpeg binary to, for example, /tmp.

Now execute the following commands in a terminal shell:

# Move ffmpeg to /usr/local/bin:
sudo mv /tmp/ffmpeg /usr/local/bin/

# Change owner and make executable
sudo chown root:wheel /usr/local/bin/ffmpeg
sudo chmod 755 /usr/local/bin/ffmpeg

You're now ready to use ffmpeg; the following command lists all the supported input and output formats:

ffmpeg -formats

Use the following command to transcode an AVI to FLV (Flash video) format:

fmpeg -i mymovie.avi -s 320x240 -ar 44100 -r 12 mymovie.flv
cat mymovie.flv | flvtool2 -U stdin mymovie.flv

To add metadata to the FLV file—such as video length, which is required for the Flash player progress bar—you need to install flvtool2.

This is done with the following command (note this requires Ruby and RubyGems, which are not part of all OSX Leopard installations):

sudo gem install flvtool2

Now add the metadata to the FLV file:

flvtool2 -UP mymovie.flv

To test the FLV movie you just created, download and extract FlowPlayer to your folder of choice. Now create a page that loads your FLV movie; note that you need to update the paths:

        <script type="text/javascript" src="../flowplayer/html/swfobject.js"></script>
    <div id="flowplayerholder">
        This will be replaced by the player. 
<script type="text/javascript">
// <![CDATA[
var fo = new SWFObject("../flowplayer/FlowPlayerDark.swf", "FlowPlayer", "468", "350", "7", "#000000", true);
    // need this next line for local testing, it's optional if your swf is on the same domain as your html page
    fo.addParam("allowScriptAccess", "always");
    fo.addVariable("config", "{ countryCode: 'fi', playList: [ {overlayId: 'play' }, { url: '/mockup/mymovie.flv' } ], initialScale: 'scale',  fullScreenScriptURL: 'fullscreen.js' }");
// ]]>

I've been told that mencoder produces higher quality FLV videos, so lets compare the mencoder output to ffmpeg by first downloading and extracting mencoder to /tmp.

Now move mencoder to /usr/local/bin:

sudo mv /tmp/mencoder /usr/local/bin/

sudo chown root:wheel /usr/local/bin/mencoder
sudo chmod 755 /usr/local/bin/mencoder

Next transcode the video to FLV format using mencoder:

mencoder mymovie.avi -ofps 12 -o mymovie.flv -of lavf -lavfopts \
i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc -lavcopts \
acodec=mp3:abitrate=32 -srate 22050  -ovc lavc -lavcopts vcodec=flv:\
vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 \
-vop scale=360:240

View the video in the Flash player; you should notice the difference in quality...

For even higher quality encode the videos using the H.264 format, which FlowPlayer also supports; instructions can be found here.

How to install the stemmer4r gem on Mac OS X and Linux

Tagged stemming, stemmer4r, install, osx, linux, gem  Languages ruby

The stemmer4r gem is fubar. Warning draft snippet...

# gem install stemmer4r
Bulk updating Gem source index for: http://gems.rubyforge.org
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.

ruby extconf.rb install stemmer4r

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/gem_make.out

1. Change path of Ruby executable

cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/
vim extconf.rb

#!/usr/bin/ruby -w


#ruby -w

2. Compile libstemmer_c

cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/libstemmer/

3. Compile stemmer4r

cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/

Change path:

Or wherever you have it installed

ruby extconf.rb

4. Build stemmer4r gem

gem build stemmer4r.gemspec

gem install stemmer4r-0.6.gem


gcc -shared -rdynamic -Wl,-export-dynamic   -L"/usr/lib" -o stemmer4r.so stemmer4r.o libstemmer_c/libstemmer.o  -lruby1.8  -lpthread -ldl -lcrypt -lm   -lc
/usr/bin/ld: libstemmer_c/libstemmer.o(libstemmer.o): relocation R_X86_64_32 against a local symbol' can not be used when making a shared object; recompile with -fPIC
libstemmer_c/libstemmer.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [stemmer4r.so] Error 1


root@aktagon:/usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/libstemmer_c# make
include mkinc.mak
libstemmer.o: $(snowball_sources:.c=.o)
        $(AR) -cru $@ $^

Installing ImageMagick, mini-magick and rmagick on Mac OS X Leopard

Tagged imagemagick, attachment_fu, rails, ruby, mac, osx, leopard, mini-magick, rmagick  Languages ruby

I had no success installing ImageMagick and mini-magick with the instructions I found on this page but after some googling I found this blog post, which had the magic commands that worked for me:

sudo port install tiff -macosx  #disables the linkage with Apple's open gl
sudo port install ImageMagick

sudo gem install rmagick
sudo gem install mini_magick

To test mini-magick, open an irb console and paste in the following code:

require 'rubygems'
require 'mini_magick'

path = "public/images/0000/0003/logo.jpg"
image = MiniMagick::Image.new(path)

#print width and height
puts image[:width]
puts image[:height]

Mounting a remote network drive with SSHFS on OSX

Tagged sshfs, mount, remote, drive, osx  Languages bash
  1. Install SSHFS


  1. Read documentation


  1. Create symlink
ln -s /Applications/sshfs.app/Contents/Resources/sshfs-static /usr/local/bin/sshfs
  1. Mount drive
mkdir /Volumes/mount_name
sshfs -p 666 server:/ /Volumes/mount_name -oreconnect,ping_diskarb,volname=mount_name
  1. References


Rails+Mongrel+Apache 2 on Mac OSX Leopard

Tagged apache, mongrel, osx, rails  Languages apacheconf

I use this configuration on my development machine when I need mod_rewrite; it's not meant for production:

<VirtualHost *:80>
ServerName dev.xxx.com

# Enable URL rewriting
RewriteEngine On

# Rewrite index to check for static pages
RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

DocumentRoot  "/Users/christian/Documents/Projects/xxx/public"
<Directory "/Users/christian/Documents/Projects/xxx/public">
     Options Indexes FollowSymLinks

     AllowOverride None
     Order allow,deny
     Allow from all


<Proxy balancer://mongrel_cluster>

Deleting favicons in Firefox 3

Tagged mac, osx, firefox, favicon  Languages bash

To force Firefox to show your updated favicon (updating favicon.ico is not enough), first quit Firefox. Then issue the following commands in the terminal:

$ cd /Volumes/Macintosh\ HD/Users/christian/Library/Application\ Support/Firefox/Profiles/46xov8kt.default
$ sqlite3 places.sqlite 
SQLite version 3.5.0
Enter ".help" for instructions
sqlite> delete from moz_favicons;
sqlite> update moz_places set favicon_id = NULL;
sqlite> .quit