computer, travel, movies, music, cuisine and more
tips & howtos
Sparkle script in XCode
May 27th
So,
for a project that I’m working on (Reader Notifier Reloaded, more about it in a following post), I’ve been using Sparkle. It is a great tool for providing updates to the users.
Since Sparkle is using public/private key cryptography in order to sign the updates and guarantee their authenticity there is some “fiddling” one has to do in order to push out an update. Marc Liyanage provides us with a great way to do all the signing, packaging and xml generation for updates.
I’ve been using his technique and just adapted the shell script to make it work on my Snow Leopard 10.6.3 without the need of the libxml perl library.
In particular I’ve changed the SIGNATURE part to:
SIGNATURE=$( myvar=$(security find-generic-password -g -s "Sparkle Private Key" 2>&1 1>/dev/null | sed 's/.*-----BEGIN DSA PRIVATE KEY-----\\012\(.*\)\\012-----END DSA PRIVATE KEY-----.*/-----BEGIN DSA PRIVATE KEY-----\ \1\ -----END DSA PRIVATE KEY-----/g' | sed 's/\\012/\ /g') echo "$myvar" > tmp.tmp openssl dgst -sha1 -binary < "$ARCHIVE_FILENAME" \ | openssl dgst -dss1 -sign tmp.tmp \ | openssl enc -base64 rm tmp.tmp )
So, here’s the script I’m using, if anyone wants it!
set -o errexit
if [[ $BUILD_STYLE != "Deploy" ]]; then
echo Distribution target requires "'Deploy'" build style
exit
fi
VERSION=$(defaults read "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Info" CFBundleVersion)
DOWNLOAD_BASE_URL="http://www.example.com/some_product"
RELEASENOTES_URL="http://www.example.com/some_product/$VERSION.html"
ARCHIVE_FILENAME="${PRODUCT_NAME}_$VERSION.zip"
DOWNLOAD_URL="$DOWNLOAD_BASE_URL/$ARCHIVE_FILENAME"
KEYCHAIN_PRIVKEY_NAME="Sparkle Private Key"
WD=$PWD
cd "$BUILT_PRODUCTS_DIR"
rm -f "$PRODUCT_NAME"*.zip
ditto -ck --keepParent "$PRODUCT_NAME.app" "$ARCHIVE_FILENAME"
SIZE=$(stat -f %z "$ARCHIVE_FILENAME")
PUBDATE=$(LC_TIME=en_US date +"%a, %d %b %G %T %z")
SIGNATURE=$(
myvar=$(security find-generic-password -g -s "Sparkle Private Key" 2>&1 1>/dev/null | sed 's/.*-----BEGIN DSA PRIVATE KEY-----\\012\(.*\)\\012-----END DSA PRIVATE KEY-----.*/-----BEGIN DSA PRIVATE KEY-----\
\1\
-----END DSA PRIVATE KEY-----/g' | sed 's/\\012/\
/g')
echo "$myvar" > tmp.tmp
openssl dgst -sha1 -binary < "$ARCHIVE_FILENAME" \
| openssl dgst -dss1 -sign tmp.tmp \
| openssl enc -base64
rm tmp.tmp
)
[ $SIGNATURE ] || { echo Unable to load signing private key with name "'$KEYCHAIN_PRIVKEY_NAME'" from keychain; false; }
cat > $VERSION.xml <<EOF
<item>
<title>Version $VERSION</title>
<sparkle:releaseNotesLink>$RELEASENOTES_URL</sparkle:releaseNotesLink>
<pubDate>$PUBDATE</pubDate>
<enclosure
url="$DOWNLOAD_URL"
sparkle:version="$VERSION"
type="application/octet-stream"
length="$SIZE"
sparkle:dsaSignature="$SIGNATURE"
/>
</item>
EOF
XCode custom templates
Mar 11th
I’ve been developing some iPhone applications both for fun and profit. Always I haven’t liked the way XCode creates new files in a project. Not only I didn’t like the formatting of the top comment (where your name shows and so on) but also I most of the times found myself deleting all the pre-generated contents.
For this reason I’ve investigated a bit in how to create custom templates and, starting from Apple defaults and the work done by jad I put up a simple project that anyone can edit to change to their own preferences and a simple script that links the templates so that XCode can (and will!) show them when you create new files.
I hope someone will find it useful, if no-one does no big problems, I still use it for myself and my collaborators :)
You can find the project and installation instructions (just running the script) on github
~C
ImageMagick for iPhone via SnowLeopard
Feb 10th
1.5.2010 – UPDATE: for the latest compiled libraries and test project please refer to: Latest ImageMagick
Hi all ImageMagick developers!
It has been a long time since my last update to my script for building ImageMagick and having it running as a statically compiled library so that you can use it in all your iPhone applications! To make up for the delay I have made some improvements:
- Script now working on Snow Leopard (tested on 10.6.2 against iPhone SDK 3.1.3)
- Script better organized (although I want to make it even better!)
- Script available through github, so if you want to help me updating it, know some bash scripting, and willing to help, just contact me!
- Updated libpng to v1.4.0 and libtiff to v1.9.2
As usual I also link you a .zip containing all the .a universal (iPhone + iPhoneSimulator) libraries that you can use right away in your projects! I’ve also updated the test project, just minor changes, and the new libraries!
I hope you are happy with the update, and I would like to thank:
Verdier Christophe for a much better script stub posted in the comments
Cocoawithlove.com for a good guide on understanding why the heck the iPhoneSimulator libraries weren’t working at all!
Don’t be shy and comment, also pointing me to some cool iPhone Apps that you’ve been working on that use ImageMagick!
~C
ImageMagick on iPhone – update with TIFF
Jul 28th
>> PLEASE READ THE UPDATE <<
Here I go again with an update to the ImageMagick on iPhone saga.
As requested by a few people here on the site, I’ve added TIFF functionality to the compiled library. If you’re interested in reviewing the all process to compile ImageMagick for the iPhone please refer to my two previous posts where that’s described in detail: first and second.
TIFF is compiled with ZIP functionality, so you can compress your TIFF files.
As usual I’ve provided you with an updated script which now enables the compilation of tiff-3.8.2 alongside jpeg and png to have it supported in ImageMagick.
For the lazy there’s always the compiled static libraries and includes. But remember to take as well the *.xml configuration files for some ImageMagick functionality!
And the IM_Test Xcode project has been updated as well where the TIFF functionality is tested.
I guess I’ve updated everything accordingly. Please let me know if anything isn’t working for you. As usual contacting me here on the site.
ciop ciop
ImageMagick on iPhone – Xcode
Jul 9th
>> PLEASE READ THE UPDATE <<
UPDATE! (30.08.09)
Thanks to Jon Kean (see comments) the downloadable project now shows how to use images with unusual number of bits per component. As usual look at the defines at the top to check the functionality you want.
UPDATE! (14.07.09)
Thanks to Karl (see comments) the downloadable project now shows different ways of integrating ImageMagick with Objective-C UIImages offering both compressed methods, using JPEG compression as an example, and raw-data methods. Look at the define at the top to change which method the program will be using.
Many of you have asked me if I could post an Xcode project example to use the libraries and ImageMagick, and so, here it is.
The code is self-describing so I didn’t comment it much, it’s just a few functions call. All it does in this case is loading an image from an UIImage (Objective-C) into a format that ImageMagick (C) understands and can manipulate. Then it applies an ImageMagick filter (OrderedPosterize), which uses a configuration file (thresholds.xml).
Everything is working fine, and you have the complete set of libraries, headers and configuration files, and a configured XCode project right at hand.
If you still have any problem, don’t hesitate to contact me!
ciop ciop
ImageMagick on iPhone – UPDATE
Jun 26th
>> PLEASE READ THE UPDATE <<
I’ve been busy working on an iPhone project using ImageMagick the last month, and one thing has kept on bugging me: Some functionality just wasn’t working!!!
In particular I discovered that ImageMagick uses some XML configuration files for some of its internal operations. You can find the whole reading about them on ImageMagick site.
After fiddling, deciding to not care, re-deciding that I WANTED THE FUNCTIONALITY here’s the solution (as usual in steps):
-
The Files that need to be copied over are stored, if you use my script to compile ImageMagick under the installation directory:
~/Desktop/tmp_target/imagemagick/lib/ImageMagick-6.5.3/config
~/Desktop/tmp_target/imagemagick/share/ImageMagick-6.5.3/config -
XCode needs to import such files, so that they can be copied over to the destination application. In particular add them to the Resources directory with the usual method for adding files:
Right click on the Resources folder -> Add -> Existing Files…
and select all the.xmlfiles in the two folders above. -
The Code somewhere, like in a function that gets called only once (
viewDidLoad, for instance), this may vary depending on your program, add the two following lines:NSString * path = [[NSBundle mainBundle] resourcePath]; setenv("MAGICK_CONFIGURE_PATH", [path UTF8String], 1);
Done, now ImageMagick knows where to look for the needed configuration files and will work like a breeze for you.
YES! It was this easy. But not to discover, trust me! :P
ImageMagick on iPhone (with jpeg + png)
Jun 9th
>> PLEASE READ THE UPDATE <<
I’m working on some iPhone applications, which need some image filtering. For now, I won’t say more! Stay tuned for the news when it comes out!
Long story short, I soon found the need (ant the challenge was a good one) to get ImageMagick static libraries so that I can use it on the iPhone. Not only that, but with jpeg and png support. That’s what I need.
After a fast search through the net, I couldn’t find a single _GOOD_ post on how to do that. Just some bits and bytes – Nothing complete.
I soon set on a mission to get ImageMagick to work on the iPhone, as a library. And here’s the result of my quest (around 1 day of search, trials and errors, and at last some light!)
Setting
I’m running MacOSX 10.5.7, with the latest MacPorts installed. If you don’t, get it! I have many ports installed, the ones I “think” are important are:
- jpeg
- libpng
Also, I’m testing everything with the latest beta of the iPhoneOS 3.0 – It should be working also for 2.2.1 and the final 3.0 when it comes out.
The Script
I now provide you with a shell script that should do the whole trick of creating the static libraries needed in Xcode for iPhone development.
Just download it, give it run permission (chmod +x ./compile_im.sh), and launch it. It will ask for your password because it needs to copy a file that is not owned by you, the user.
Before complaining that it’s not working, open it, and look at the required directory structure for it to work.
In particular you will need:
- a Desktop folder named cross_compile
- ImageMagick source: ImageMagick
- jpeg source: jpeg
- libpng source: libpng
- Untar ImageMagick source and place it into ~/Desktop/cross_compile/i_m
- Untar/Unzip jpeg/libpng source and place it into: ~/Desktop/cross_compile/i_m/IMDelegates/jpeg-6b and ~/Desktop/cross_compile/i_m/IMDelegates/libpng-1.2.37
– to which I’ve added the MacPorts patches
Now you can run the script :)
Result
The result will be stored under: ~/Desktop/tmp_target. In particular you can find all the header files needed while developing your application under: ~/Desktop/tmp_target/im_libs/includes (divided by library). While all the static libraries are inside ~/Desktop/tmp_target/im_libs/:
- libjpeg.a
- libpng.a
- libMagickCore.a
- libMagickWand.a
Please note that the script joins both the i386 and the arm build inside one single .a static library to ease up developing (for testing both on the Simulator and on the device itself. When finishing up the application you may want to put only the arm library to make the overall application lighter.
XCode configuration
Step 1
To work with your libraries you need to put some easy adjustments to your Project in XCode. I’ve found that the best thing to do, especially in a shared environment with multiple developers, to just put everything inside the XCode project. To do so do:
- Project->Add To Project->Select all the .a libraries->Click ‘ADD’
- Project->Add To Project->Select the folders inside the ~/Desktop/tmp_target/im_libs/include->Click ‘ADD’
Step 2
Click on Project->Edit Project Settings and edit (in the Build:
- Other Linker Flags: -lMagickCore -lMagickWand -lz -lbz2 -ljpeg -lpng
- Header Search Paths: $(SRCROOT) – make it Recursive
- Library Search Paths: $(SRCROOT) – make it Recursive
- On the lower left click on the small-wheel and select: Add User-Defined Setting
- Key: OTHER_CFLAGS
- Value: -Dmacinsoth=1
This should be enough to make you start.
For the Lazy
If you’re lazy, don’t manage or for whatever other reason you can just download the whole compiled package
Last note
In case the script doesn’t work, you have questions/suggestions/support please don’t hesitate to contact me, and in case you need help with the script please send me the FULL output in a file.
./compile_im.sh > file_to_send.txt
ROR on Xampp on Win
May 17th
For those who don’t understand the title don’t worry, this is a “technical” post: installing Ruby on Rails (ROR) over an existing XAMPP (Apache, PHP, MySQL, …) installation in Windows. For all of those who have somehow a Windows “server” used to test websites and want to install Ruby and the fantastic Ruby on Rails framework.
Prerequisites: a working installation of XAMPP, in my example installed under: C:\xampp.
- Install ROR via the “one click installer” which can be found on the ROR site: installers list. To have everything in one “web-development directory” when prompted by the installer choose C:\xampp\ruby
- Open the dreaded DOS-prompt or cmd: Start->Run->cmd
- First off update gem, The version installed will stop whenever an update fails, to solve this update gem first. Let’s navigate to the ruby bin directory:
cd C:\xampp\ruby\bin
and then the command:gem update --system - Now all the gems are updated, install rails with this command:
gem install rails --include-dependencies
This will take a while especially for generating the whole documentation, don’t worry, everything is going all right, wait and be patient - Create a test application with the command:
rails C:/xampp/htdocs/testapp
If all went fine you will see some output saying that some files have been created. Rails is installed all fine - Now it’s time to create a Virtual Host in apache to test out our installation. Edit the file: C:xamppapacheconfextrahttpd-vhosts.conf with your favourite good editor. I always have installed Notepad++ and at the end add the following lines:
## ROR Listen 3000 <VirtualHost *:3000> ServerName ROR DocumentRoot "C:\xampp\htdocs" <Directory "C:\xampp\htdocs"> Options ExecCGI FollowSymLinks AllowOverride all Allow from all Order allow,deny AddHandler cgi-script .cgi AddHandler fastcgi-script .fcgi </Directory> </VirtualHost> ## END-ROR
- Restart apache from the XAMPP control panel and then go, on your favorite browser to:
http://localhost:3000/testapp/public
To see if everything went fine, the page should look like this screenshot
Versions
At the moment of this writing this is the list of version numbers for the installed applications running and working as configured in this post:
- XAMPP: 1.6.6a
- ruby -v: ruby 1.8.6 <2008-08-11 patchlevel 287> [i386-mswin32]
- gem -v: 1.3.3
- rails -v: Rails 2.3.2
I would like to thank the author of this post which is the starting point of my post. I just did some minor changes to remove some errors, especially when updating gems. Also I changed the file to edit to add the Virtual Host to keep things more clean in the http.conf file.
For any trouble don’t hesitate to contact me!
Webradios on OSX: guide to easy listening
Apr 17th
I’m a huge fan of some radios which I’ve been listening to in my life. For example, while driving in Italy I usually listen to virginradio, while being in Sydney I used to listen to tripleM, both of which usually air good rock music without too much DJs and ads.
YES! I want to listen to music, not ads or people speaking!
Thankfully most radio stations nowadays also spot an internet streaming. Nightmarefully usually it’s a flash or WMP (Windows Media Player) streaming. Being a MacOSX user (mostly) or a Linux user (always – mostly: so basically the time I’m not on MacOSX) I found both formats bad. The first because it works once and not the other time, the second because while more or less working with Quicktime (+ some weird nasty plugin [flip4Mac])
ATTEMPTED SOLUTION
What I usually do is easy – with example:
- Go to the webpage of the radio – http://www.triplem.com.au/sydney
- Find the ‘listen online’ button
- Open up the source code for the page that the ‘listen online’ opens up (usually they use pop-ups windows for such streamings) when there’s some kind of streaming going on
- Search for something like:
asx
Or alternatively if you don’t find any entry:
embed -
If in the step before you found the asx copy all the link, following our example:
... id="WMPlayer" name="WMPlayer" src="http://resources.triplem.com.au/listenfeed/2mmmlivestream.asx" type="video/quicktime" ...
let’s copy:
http://resources.triplem.com.au/listenfeed/2mmmlivestream.asxIf instead in the step before we found the embed keyword let’s look around it to find something like:
... <EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="http://151.1.245.1/20" name="nnrVideoPlayer" autostart="1" width="400" height="70" showcontrols="1"> </EMBED> ...
around the code there should be the src tag, such as in the example. Let’s therefore copy:
http://151.1.245.1/20 - Open your favorite video/audio player, not iTunes, such as VLC and search for something called like ‘Open Network’. In our example, using VLC it’s: File->Open Network… or even faster the shortcut ⌘N and paste what you just copied:
- Press OK and after some buffering time you should be listening to your favorite radio! And without any ads or needing to keep your browser or anything!
This is clearly and hack solution which may work for you or not. If you have problems with your radio streaming and the above solution don’t hesitate to contact me and I’ll look into it (whenever I’ll find some time).
Hope it helped!
ciop ciop



