Register now and start sharing your code snippets.

Mounting a remote network drive with SSHFS on OSX

Shell Script (Bash) posted 23 days ago by christian
  1. Install SSHFS

http://code.google.com/p/macfuse/

  1. Read documentation

http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS

  1. Create symlink

   1  ln -s /Applications/sshfs.app/Contents/Resources/sshfs-static /usr/local/bin/sshfs

  1. Mount drive

   1  mkdir /Volumes/mount_name
   2  sshfs -p 666 server:/ /Volumes/mount_name -oreconnect,ping_diskarb,volname=mount_name

  1. References

http://lifehacker.com/software/ssh/geek-to-live—mount-a-file-system-on-your-mac-over-ssh-246129.php

Tagged sshfs, mount, remote, drive, osx

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

Ruby posted 5 months ago by christian

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:

   1  sudo port install tiff -macosx  #disables the linkage with Apple's open gl
   2  sudo port install ImageMagick
   3  
   4  sudo gem install rmagick
   5  sudo gem install mini_magick

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

   1  require 'rubygems'
   2  require 'mini_magick'
   3  
   4  path = "public/images/0000/0003/logo.jpg"
   5  image = MiniMagick::Image.new(path)
   6  
   7  #print width and height
   8  puts image[:width]
   9  puts image[:height]

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

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

Ruby posted 5 months ago by christian

The stemmer4r gem is fubar. Warning draft snippet…

   1  # gem install stemmer4r
   2  Bulk updating Gem source index for: http://gems.rubyforge.org
   3  Building native extensions.  This could take a while...
   4  ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
   5      ERROR: Failed to build gem native extension.
   6  
   7  ruby extconf.rb install stemmer4r
   8  
   9  Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6 for inspection.
  10  Results logged to /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/gem_make.out
  11  
  12  
  13  1. Change path of Ruby executable
  14  
  15  cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/
  16  vim extconf.rb
  17  
  18  #!/usr/bin/ruby -w
  19  
  20  to
  21  
  22  #ruby -w
  23  
  24  2. Compile libstemmer_c
  25  
  26  cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/libstemmer/
  27  make
  28  
  29  3. Compile stemmer4r
  30  
  31  cd /usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/
  32  
  33  Change path:
  34  /usr/local/ruby/lib/ruby/1.8/i686-linux/
  35  To:
  36  /usr/lib/ruby/1.8/x86_64-linux/
  37  
  38  Or wherever you have it installed
  39  
  40  ruby extconf.rb
  41  
  42  
  43  4. Build stemmer4r gem
  44  
  45  
  46  gem build stemmer4r.gemspec
  47  
  48  gem install stemmer4r-0.6.gem
  49  
  50  
  51  Problems
  52  
  53  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
  54  /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
  55  libstemmer_c/libstemmer.o: could not read symbols: Bad value
  56  collect2: ld returned 1 exit status
  57  make: *** [stemmer4r.so] Error 1
  58  
  59  
  60  Add CFLAGS:
  61  
  62  root@aktagon:/usr/lib/ruby/gems/1.8/gems/stemmer4r-0.6/ext/stemmer4r/libstemmer_c# make
  63  include mkinc.mak
  64  CFLAGS   =  -fPIC
  65  libstemmer.o: $(snowball_sources:.c=.o)
  66          $(AR) -cru $@ $^
  67  

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

Installing/compiling and using git with Ruby on Rails (on Mac OS X Leopard and Debian Linux)

Shell Script (Bash) posted 6 months ago by christian

Git is a good alternative to Mercurial, and of course SVN or CVS if you’re still using stone age tools, so in this post I’ll show you how to compile, install and use git with Rails.

Installing git on Mac OS X

First compile and install git:

   1  cd /usr/local/src
   2  wget http://kernel.org/pub/software/scm/git/git-1.5.4.4.tar.bz2
   3  tar jxvf git-1.5.4.4.tar.bz2
   4  cd git-1.5.4.4
   5  make prefix=/usr/local all
   6  make prefix=/usr/local test && echo $?
   7  sudo make prefix=/usr/local install

Installing git on Debian

On a Debian installation install git by first executing the following commands:

$ sudo apt-get install git-core

Note that the package name is git-core not git.

If you want the latest and greatest version, you first need to install the dependencies (note that you can leave out tk and expat):

   1  sudo apt-get install curl
   2  sudo apt-get install libcurl3
   3  sudo apt-get install libcurl3-dev
   4  sudo apt-get install tk8.4
   5  sudo apt-get install cpio expat
   6  sudo apt-get install zlib
   7  sudo apt-get install build-essential
   8  sudo apt-get install zlib1g-dev 
   9  sudo apt-get install asciidoc
  10  sudo apt-get install xmlto

Then compile and install:

   1  NO_EXPAT=yes NO_SVN_TESTS=yes NO_IPV6=yes NO_TCLTK=yes make -j2 prefix=/usr all
   2  NO_EXPAT=yes NO_SVN_TESTS=yes NO_IPV6=yes NO_TCLTK=yes make -j2 prefix=/usr install

Configuring git

Run these commands to tell git your name and email:

   1  git config --global user.name "u name"
   2  git config --global user.email x@x.com

Otherwise, you might get this error:

   1  *** Environment problem:
   2  *** Your name cannot be determined from your system services (gecos).
   3  *** You would need to set GIT_AUTHOR_NAME and GIT_COMMITTER_NAME
   4  *** environment variables; otherwise you won't be able to perform
   5  *** certain operations because of "empty ident" errors.
   6  *** Alternatively, you can use user.name configuration variable.
   7  
   8  fatal: empty ident  <........@........com> not allowed
   9  fatal: The remote end hung up unexpectedly

If you like colorized command output execute these commands:

   1  git config --global color.diff auto
   2  git config --global color.status auto
   3  git config --global color.branch auto

Using git

If all goes well, change to your project directory and run the following commands:

   1  git init

This creates the git repository, so we’re now ready to start adding files to it, but first we need to create the git ignore file, which tells git to ignore certain files completely:

   1  cat <<EOF<<EOF > .gitignore 
   2  config/database.yml
   3  db/*.sqlite3
   4  log/*.log
   5  tmp/**/*
   6  .DS_Store
   7  doc/api
   8  doc/app
   9  EOFEOF

By default git doesn’t add empty directories—sucks if you ask me—so we’ll create a dummy file in all empty directories with the find and touch commands:

   1  find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \; 

Importing files

We’re now ready to start adding and commiting files, so without thinking execute:

   1  git add .
   2  git commit -m 'initial import'

This creates the git repository, adds and commits all files that are in the current folder.

Using remote repositories

If you’re like me you’ll want to use a remote repository, so let’s continue the exercise by creating the repository folder on the remote server (Note that commands are executed on the remote server from now on):

   1  mkdir /var/lib/git/repositories/project_name

We want the folder to be accessible by users belonging to the git group only:

   1  addgroup git
   2  chown root.git /var/lib/git/repositories/project_name
   3  chmod 770 /var/lib/git/repositories/project_name

Now add yourself—or the user you’ll be using to connect to the remote server—to the git group:

   1  usermod -a -G git your_username

Alternatively create a new user:

   1  useradd -g git your_username

Now we’re finally ready to copy the local repository to the remote server, which is done with the scp command (Note that commands are executed locally again from now on):

   1  scp -rp .git user@server://var/lib/git/repositories/project_name

To let git know that this repository exists we’ll use the git remote command:

   1  git remote add project_name ssh://server/var/lib/git/repositories/project_name

This adds the information to .git/config, which might be good to have a quick look at.

Note that if you’re using a non-standard SSH port you need to add the following to your ~/.ssh/config file:

   1  Host server
   2    Port 1234

Commit files and push them to the remote server

Now change a file and commit and push the changes to the remote server:

   1  git commit -m "Me be sleepy"
   2  git push project_name

If you get an error such as this it means you need to install git:

   1  $ git push project_name
   2  username@server's password: 
   3  sh: git-receive-pack: command not found
   4  fatal: The remote end hung up unexpectedly

That’s all…

Miscellaneous problems

error: unable to create temporary sha1 filename ./objects/obj_FUu2jb: Permission denied

Resources

http://jointheconversation.org/railsgit

http://devblog.michaelgalero.com/2007/12/17/my-git-notes-for-rails/

http://railscasts.com/episodes/96

http://groups.google.com/group/rails-oceania/browse_thread/thread/2c8611dc93917952/e175f72310823547

http://www.kernel.org/pub/software/scm/git/docs/tutorial.html

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

Tagged git, osx, mac, compile, ruby, rails, remote, linux

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

Shell Script (Bash) posted 7 months ago by christian

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:

   1  # Move ffmpeg to /usr/local/bin:
   2  sudo mv /tmp/ffmpeg /usr/local/bin/
   3  
   4  # Change owner and make executable
   5  sudo chown root:wheel /usr/local/bin/ffmpeg
   6  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:

   1  ffmpeg -formats

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

   1  fmpeg -i mymovie.avi -s 320x240 -ar 44100 -r 12 mymovie.flv
   2  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):

   1  sudo gem install flvtool2

Now add the metadata to the FLV file:

   1  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:

   1  <html>
   2  	<head>
   3  		<script type="text/javascript" src="../flowplayer/html/swfobject.js"></script>
   4  	</head>
   5  <body>
   6  	<div id="flowplayerholder">
   7  		This will be replaced by the player. 
   8  	</div>
   9  	
  10  <script type="text/javascript">
  11  // <![CDATA[
  12  var fo = new SWFObject("../flowplayer/FlowPlayerDark.swf", "FlowPlayer", "468", "350", "7", "#000000", true);
  13  	// need this next line for local testing, it's optional if your swf is on the same domain as your html page
  14  	fo.addParam("allowScriptAccess", "always");
  15  	fo.addVariable("config", "{ countryCode: 'fi', playList: [ {overlayId: 'play' }, { url: '/mockup/mymovie.flv' } ], initialScale: 'scale',  fullScreenScriptURL: 'fullscreen.js' }");
  16  	fo.write("flowplayerholder");
  17  // ]]>
  18  </script>
  19  </body>
  20  </html>

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:

   1  sudo mv /tmp/mencoder /usr/local/bin/
   2  
   3  sudo chown root:wheel /usr/local/bin/mencoder
   4  sudo chmod 755 /usr/local/bin/mencoder

Next transcode the video to FLV format using mencoder:

   1  mencoder mymovie.avi -ofps 12 -o mymovie.flv -of lavf -lavfopts \
   2  i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc -lavcopts \
   3  acodec=mp3:abitrate=32 -srate 22050  -ovc lavc -lavcopts vcodec=flv:\
   4  vbitrate=100:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:\
   5  vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 \
   6  -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.

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