Thursday, 17 February 2011

How to hide .svn folders from file search in Eclipse

By default, whenever you do a file search in Eclipse, it'll search inside .svn folders too. This is obviously very irrititating!

Here's how to turn it off:
  • Click on the root of your project in the Package Explorer window
  • On the main manu, select Project / Properties / resource / Resource Filters
  • Click Add..
  • Set 'Filter Type' to 'Exclude all'
  • Set 'Applies to' to 'Folders'
  • Check 'All Children (recursive)' (this is essential!)
  • Under File and Folder Attributes, type .svn. This should work for CVS folders too (type .cvs)
  • Click OK
  • Repeat for all projects in your workspace


Apparently installing subclipse (subversion plugin for eclipse) will also solve this problem but I haven't tried it myself.

Wednesday, 16 February 2011

Android: Adding a new Activity using Eclipse

To add a new screen to your android app you'll want to add a new activity. This is a slightly manual process however, so I've noted down here for future reference.

This example will add a new activity called 'Foo'.

Step 1 - Add the activity class
  • In the Package Explorer, right click your main package (e.g. com.calvium.myApp) and select New / Class
  • Set the new class Name (e.g. Foo.java), and set it the superclass to android.app.Activity
  • Add an override for the onCreate method.
  • Easy method: Open the new file and place your cursor inside the main { } block. Press CTRL-SPACE and up pops a list of possibilities. Type 'onCreate' and hit enter to generate the method stub.
  • After super.onCreate add:

setContentView(R.layout.foo);

Step 2 - Create the Activity Layout File
  • Back in the package explorer, right-click res / layout.
  • Select New / Other / Android / Android XML File
  • Call the new file foo.xml
  • Add whatever controls you want to the xml file using the designer tool in eclipse, or by typing stuff manually.
Step 3 - Register the new activity in the AndroidManifest.xml file
  • Open AndroidManifest.xml
  • Just before the closing tag insert:

<activity android:name=".Foo">activity>

Thursday, 13 January 2011

Installing an archived application to an iPhone from XCode Organizer


The organizer window in Xcode has a handy feature where all the versions of applications you have submitted to the App Store are listed.
Today I needed to install an old version of an app to my iPhone in order to reproduce an issue a customer was having. It wasn’t as easy as I was expecting so I thought it was worth recording the process. Essentially you cannot simply copy the archived app to your device manually, as it was signed using the App Store certificate. We need to re-sign it using an Ad Hoc certificate instead - then it’ll run.
First up you need to make sure that you have an Ad Hoc distribution certificate handy, and that said certificate includes the device that you’re trying to distribute to.

UPDATE: August 2012: This process is far easier if you use this free open-source app called iResign.  This great app lets you take an existing IPA and re-sign it with your own certificate. Much, much simpler

Making the Ad Hoc Certificate
Ignore this part if you already have an Ad Hoc distribution certificate.
  1. Get your team agent to log into the iOS provisioning portal
  2. Go to provisioning / distribution tab
  3. Hit New Profile
  1. Choose ‘Ad Hoc’ as the distribution method
  2. Choose the relevant app ID (I chose an app id that allows any application by Calvium)
  3. Select the devices you want to be able to run on. I just chose all by selecting the select all button.
  4. Hit ok. Wait a minute or so, and hit refresh to be sure that the certificate is ready.
Re-signing the app using the Ad Hoc Certificate
  1. Go back to Xcode organizer. Open the ‘archived application’ section and choose the app you want to use.
  2. On the right-hand panel, choose the version to use. I’ve chosen 1.2. Apologies for the censorship in the images here..
  1. Click Share
  1. Click the ‘identity’ drop-down and under the heading ‘Ad Hoc Distribution’, select ‘iPhone Distribution’
  2. Now click ‘Save to Disk’
  3. Choose a filename (doesn’t matter what it is)
  4. Xcode will grind away for a bit re-signing the app, and then save a .ipa file containing the app.
Installing the app on your device (the .ipa file)
There are various ways of installing the ipa on the device, including via iTunes. I find this method by far the easiest - no syncing required.
  1. Open Xcode organizer again
  2. Attach the device
  3. Open the ‘Devices’ section, and select the device
  1. Under the Applications box, click the + arrow.
  2. Select the .ipa file you just saved, and lo and behold the app will be installed
  3. If it fails with an ‘no provisioning profile found’ or ‘invalid entitlements’ or similar, check that the ‘Provisioning’ box above contains the Ad Hoc profile you created earlier. If not, download it from the iOS provisioning portal, and manually upload it by clicking the + button under provisioning.

Screen sharing on Mac OS X Server using VNC

Chicken of the VNC is a free open-source Mac application that allows you to view a remote desktop on another networked machine.

Here's how I set it up on my Mac running 10.6, and our Mac Server (10.6 too).
  • Run Server Admin on your local machine
  • Open up the server you want to connect to
  • Select Firewall.
  • Go to Settings / Services tab
  • If 'Allow traffic only to these ports' is selected we need to add the ports that VNC will use.
  • Click the little + button at the bottom-left of the list of services
  • Add a new service called VNC 1, using port 5800, TCP + UDP
  • Add a second service, VNC 2, using port 5900, TCP + UDP
  • Stop and restart the firewall
  • Download Chicken of the VNC and install it.
  • Run the app
  • Go to Connection / New Connection
  • Enter the IP address or name of your server
  • Leave 'display' as 0 (if you choose 1 you'd have needed to open ports 5801/5901 above for example)
  • Leave 'profile' as 'default profile'
  • Check the 'save server' box.
  • Hit connect.
If all goes well you should have a window pop up displaying the screen of the server.

Thursday, 23 December 2010

Building FFMPEG on Mac OSX Snow Leopard

FFMPEG is an amazing set of video and audio conversion tools, accessible via the command-line. It's rather fiddly to use, but being a command-line program it can be easily integrated into your server-side tools. The sequence of steps below worked perfectly for me on Snow Leopard with XCode 3.2.4 installed.

cd ~
# checkout the latest version of the source
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg

# enable mp3 support (you need to install lame first. omit --enable-libmp3lame to build without it)
./configure --enable-libmp3lame --enable-shared --disable-mmx --arch=x86_64

# compile
make

# install
sudo make install



Example Commands


Here are some of the commands I've run so far..

Rotate a video 90 degrees clockwise (good for films shot in portrait


ffmpeg -vf "transpose=1" -i input.mp4 output.mp4

Note that there are many tutorials on the web that suggest you should use --vfilter "rotate=90" to rotate a video. This no longer works, as vfilters has been renamed vf, and the rotate option has been removed. As of Dec 2010, the above command does work.

Convert a mp3 to a flv audio file


ffmpeg -y -i myfile.mp3 -f flv -acodec libmp3lame -ab 64 -ac 1 myfile.flv

I'm using this command as part of a project I'm working on, flv is better than mp3 as you can stream (using flowplayer) an flv in such a way that user can jump around to any point of the audio without needing to download it all to that point. However, this is quite fiddly, a future blog post will explain how I did this!

Tuesday, 7 December 2010

find command - search ignoring svn folders

find . -not \( -name .svn -prune \) -name 'search-pattern'


Very handy.

Syncing web servers with rsync

rsync is an amazing useful file tree synchronisation command-line tool. It's included by default on mac OS X.
Essentially you point it at a remote source directory and a local directory and it'll make the local directory reflect the remote one exactly in an amazingly fast manner. It is able to do this by only sending the changes to files across, and even then it compresses those changes so downloads are super-quick.

This means it's an excellent tool for updating the contents of remote web servers.

Now in a standard linux way, rsync is incredibly flexible and Google searches give you tons of seriously complicated stuff on it, most of which can be ignored if you just want to sync folders. For instance most tutorials include how to set up the rsync deamon, and how to make that secure.
In fact you don't need to do this at all (though I'm sure it's really useful in some circumstances), you can simply run rsync directly. It'll log in using ssh, so make sure you have a ssh user set up.

The best way to use rsync is to perform a PULL from your remote server..

eg

  • ssh to your remote server

  • run rsync pointing it at the machine holding the data to sync



Example Command



Log into the remote machine (e.g. the web server) and type:

rsync -avz --exclude '.svn/*' -v --delete user@example.com:path-on-example-server/ /path-on-this-server/


This command connects to example.com as the user 'user' and will sync the folder path-on-this-server with the path-on-example server on example.com. --delete means delete any files on this server that are not on the one we're syncing with. --exclude '.svn/*' will ensure that any svn folders are not copied. This is really handy.