Homebrew and Macports

January 10th, 2012

1) Safely install Homebrew into into its own directory (downloaded bottles will be downloaded into here)

cd ~
mkdir ~/Developer
cd ~/Developer
git clone https://github.com/mxcl/homebrew.git

2) To set up the symlinks without having to chown /usr/local, just use chmod o+w

sudo chmod -R o+w /usr/local

3) Symlink the Cellar from /usr/local to ~/Developer/homebrew. This is necessary so that installed bottles can reference Cellar correctly.

ln -s ~/Developer/homebrew/Cellar /usr/local/Cellar

4) Install the bottle, in this case I used erlang. Be aware that Homebrew will still create symlinks into /usr/local

brew install erlang

5) Now that the bottle is installed, change the permissions on /usr/local back using chmod o-w

sudo chmod -R o-w /usr/local

Note: When installing more bottles, just do step 2, then step 4, and finally step 5.

git merge two repos

January 4th, 2012

To merge two different repos and keep histories is very easy with git:

First create a branch for the other project

git checkout master
git checkout -b other-project-branch

Then add a remote that points to the other project

git remote add remote-repo gitosis@myserver.com:otherproject.git

Finally, fetch and merge

git fetch remote-repo
git merge remote-repo/other-project-branch #SEE NOTE BELOW!

NOTE: If you know that the other project will cause a merge conflict and you want to force the merge then use:

git merge -s recursive -X theirs remote-repo/other-project-branch

git merge force overwrite

January 4th, 2012

Sometimes, it is necessary to force merge another branch that is known to be the latest source code. This is especially the case where certain files are huge textual, but non-human parseable and therefore a normal git merge is not feasible.

Git merge the branch and prefer the changes within the branch:

git merge -s recursive -X theirs branch

RAD 0.3.1 and Arduino Duemilanove

September 12th, 2011

RAD is a framework for programming the Arduino physcial computing platform using Ruby. RAD converts Ruby scripts written using a set of Rails-like conventions and helpers into C source code which can be compiled and run on the Arduino microcontroller. It also provides a set of Rake tasks for automating the compilation and upload process.

Gem List

Please note that Rad 0.3.0 requires ParseTree version 2.2.0, since Rad 0.3.1 is not fully compatible with ParseTree v3.0.x

hoe (2.12.3)
ParseTree (2.2.0) 
rad (0.2.2)
rake (0.9.2)
RubyInline (3.10.0)
RubyToC (1.0.0.5)
sexp_processor (3.0.6)
ZenTest (4.6.2)

Source

Original Source Code: atduskgreg / rad

My Fork (rake 0.9.2+ with rspec 2.6.0) rdegraci / rad

OSX Instructions

Download and install the latest OSX Arduino Dev Environment

Download and install the arduino-012 and install into your /Applications folder

rvm gemset create rad031dev
gem install rake -v 0.9.2
git clone git://github.com/rdegraci/rad.git
rake install_gem --trace
...
gem uninstall ParseTree
gem install ParseTree -v 2.2.0
rake #run the tests
rake install_gem --trace #install the gem locally
mkdir ~/testing
cd ~/testing
rad BasicBlink
cd BasicBlink
vi BasicBlink.rb #edit the file to match the sample code below
rake make:upload --trace

Sample Code

Be sure you’ve edited BasicBlink.rb and inserted the sample code below:

#
# NOTE: The class is named Basicblink with a lowercase 'b' in the blink :)
#
class Basicblink < ArduinoSketch
  # hello world (uncomment to run)

  output_pin 13, :as => :led

  def loop
    blink led, 100 
    x = 4
  end
end

Software projects are displayed by Gource as an animated tree with the root directory of the project at its centre. Directories appear as branches with files as leaves. Developers can be seen working on the tree at the times they contributed to the project.

sudo port install gource
sudo port install ffmpeg

Commandline to output to a .mp4 video file
gource --hide filenames --file-idle-time 0 --seconds-per-day 0.25 -1280x720 -o - | ffmpeg -y -b 10000K -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -fpre /opt/local/share/ffmpeg/libx264-lossless_slow.ffpreset -threads 0 -bf 0 ~/Desktop/gource.x264.mp4

LAN device IP lookup OSX

August 16th, 2011

If the device is viewable in the Finder then you should be able to do the following:

ping devicename.local.

For example, let’s say you have a Network Attached Storage device named, nas

MyWorkstation:~ rdegraci$ ping nas.local.
PING nas.local (192.168.1.250): 56 data bytes
64 bytes from 192.168.1.250: icmp_seq=0 ttl=64 time=1.067 ms
64 bytes from 192.168.1.250: icmp_seq=1 ttl=64 time=7.846 ms

OSX memcached

May 1st, 2011

Easy installation and startup via Mac Ports

sudo port install memcached
memcached -d -m 24 -p 11211

iPhone Tracking

April 24th, 2011

Much has been written about the secret, so called tracking information, that is stored by the iPhone. But actually the technical reason is not clearly written by the bloggers and pundits. Here is my explanation:

It’s simple: iPhone has a battery. Using GPS radio consumes the battery. Using Cell Tower locations and calculating approximate location consumes less battery, giving you more time to play MP3s or listen to iTunes or watch youTube; whatever.

Apple’s solution to saving the battery: cache as much cell tower location as possible, when the iPhone is used, so that when it comes time for an App to get location, it can triangulate the position without have to use up your battery by activating your GPS radio when it can just calculate via triangulation (if the App requests to force use the GPS radio, then the GPS radio is used).

If Apple limited the cache to only let’s say 3 days, but the end-user travels a lot to-from the same set of cities (let’s say NY and Jersey) , the end result is that the end-user would be using up more battery; she would be freshing the cache with data it already had 4 days earlier and you’d be using the GPS radio to request information that the cached info could have answered via triangulation easily.

Apple could sidestep this whole issue by: Letting the User choose to keep the cache for: 0 hours, 24 hours, 72 hours, 1 week, 1 month, 6 months, or 1 year. And let the User know that the shorter the cache purge rate, the more battery will be used since the iPhone would have to rely more on the GPS radio instead of the cache.

My opinion, Apple decided it was too technical an issue for the end-user to decide and just decided to go with saving battery life by keeping the cache as long as possible.

git-svn workflow

April 5th, 2011

In this article, we will discuss the workflow for using git-svn. We will use a local merge branch named ‘local-staging’ as the branch into which we will merge our feature branches and from which to dcommit to the remote svn repository. The ‘master’ branch will always track the remote svn repository. This is just a description of what works for me, but should not be considered best-practice.

1) Clone the svn repository

git svn clone -s https://server/svn/product/

2) Create a local-staging branch. The master branch will always track the svn repository, therefore we do not merge anything into the local master. The local-staging branch is used as the trunk into which all feature branches are merged into, before dcommitting to the remote svn repository master.

git checkout master
git branch local-staging
git checkout local-staging

3) Let’s say we want to create feature branch. We update the local-staging branch and create a local feature branch

git checkout local-staging
git svn rebase   #update from remote svn
git branch my-feature
git checkout my-feature

4) Let’s say that a co-developer has updated the remote svn repository and we need to update our local feature-branch. We use the rebase command and it will roll-back your code changes, then download the latest changes from the remote repository, then roll-forward the code by re-applying your code changes.

git checkout my-feature
git svn rebase

5) Let’s say we write code within the local feature branch and we wish to commit to the local feature branch. We then create a commit on the local feature branch:

git checkout my-feature
hack hack hack
git add .
git commit -m "my commit message" 

6) When the local feature branch is complete, merge it into the local-staging branch. Then create a commit and then push to the remote svn repository master. Be sure to use the—squash to squash all the commits of the local feature branch into a single commit

git checkout local-staging
git svn rebase
git merge --squash -m "merge message"  my-feature 
git commit -m "my commit message" 
git svn dcommit 
git -d my-feature   #highly suggested

NOTE: we delete the my-feature branch since it has been squashed and merged into local-staging and dcommitted to the remote svn repository.

If you don’t delete my-feature, then REMEMBER: A local feature branch that has been squashed into the local merge branch and dcommitted, must be considered frozen! If you need to update/change a local feature-branch that has been merged/squashed, DON’T; instead create a new local feature-branch from the local-staging branch.

7) Update the local master branch with the latest changes from the remote svn repository

git checkout master
git svn rebase

When you have completed steps 6 and 7 and you are ready to create a new feature branch, proceed back to step 3.

PostGIS + Rails + iOS

April 3rd, 2011

PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS “spatially enables” the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI’s SDE or Oracle’s Spatial extension.

I spent a few hours testing a PostGIS server setup. I’ve determined how to execute the stored-procedure queries against the PostGIS server from Rails.

Details to follow…

Debian PostgreSQL Superuser

April 1st, 2011

PostgreSQL creates a postgres user for you. It’s simpler to create a new database user as superuser, for example using your user_name

su - postgresql
createuser --superuser your_username -U postgres

Now you can create your database

createdb my_database

According to PostgreSQL docs, “A procedural language must be “installed” into each database where it is to be used. But procedural languages installed in the database template1 are automatically available in all subsequently created databases. So the database administrator can decide which languages are available in which databases and can make some languages available by default if he chooses.”

su - postgres
createlang plpgsql template1

To upgrade from Rubygems v1.5.1 that comes with jRuby 1.6.0 simply do the following:

gem install rubygems-update -v 1.5.2
update_rubygems

Once you are on Rubygems 1.5.2 then you can update using:

gem update --system -v 1.x.x

If you need to downgrade:

gem install rubygems-update -v 1.5.1
gem uninstall rubygems-update -v 1.5.2
update_rubygems

Hudson is a good CI server. The configuration and set up under Debian has some challenges because the Hudson server runs as hudson:nogroup. You have to setup permissions on the Postgres server correctly.

Luckily, PostgreSQL can be installed as part of the Debian installation, however to get it working with Rails you will need to install libpq-dev

apt-get install libpq-dev

Create the hudson postgresql acct as super user. This is necessary since postgres will check the ident of the account trying to create/modify the databases and simply setting that information in the database.yml file is not enough. Hudson runs, under Debian, as hudson:nogroup

createuser --superuser hudson -U postgres

By default the password will be empty, so log into psql and set the password of the hudson user.

/usr/bin/psql
ALTER ROLE hudson WITH ENCRYPTED PASSWORD 'hudsonpw';

Finally in your database.yml file use:

username: hudson
password: hudsonpw

Now you can run rake db:create etc and you should be able to build the project using Hudson.

Install Tomcat via Ports

sudo port install tomcat6
sudo touch /opt/local/share/java/tomcat6/conf/local.env

Create an environment file

sudo vi /opt/local/share/java/tomcat6/conf/local.env 

and adjust the memory limits by editing the local.env

export JAVA_JVM_VERSION=CurrentJDK
export JAVA_OPTS="-Xmx3000M -Xms3000M -Djava.awt.headless=true -Duser.timezone=UTC" 

Add Hudson as a servlet

cd /opt/local/share/java/tomcat6/webapps
wget http://hudson-ci.org/latest/hudson.war
chown _www:_www hudson.war

Startup Tomcat

sudo /opt/local/share/java/tomcat6/bin/startup.sh

Use your webbrowser to log into http://localhost:8080/hudson

The Hudson server runs as root, so if you want to push to a remote git repository then you’ll need to create ssl credentials for root:

sudo bash
su -
ssh-keygen -t rsa

No need to set a passphrase