19 July 2010

Tired of killing browsers?

Launching the browser a lot from your IDE while working on / developing <some> web app?

Getting zillions of tabs or new browser instances?

Killing them all by hand every now and then?

Small trick which tells Firefox to put all URL requests in the same tab, reusing one tab.

in the URL type: about:config
find the property browser.link.open_newwindow
change the value to 1

Follow up tip: Keep some Firefox fork/clone (or whatever) installation which you use just for development, and apply this setting to it. This way you don't mess up your Firefox for normal surfing. I keep swiftweasel in /opt/swiftweasel

02 June 2010

watch your code do actual work - in runtime

Short version: Use AOP to log your method invocations. Store method input parameters and result object, serialized to XML. Put it all into context with a Graphviz file generated as a side-effect.

Visual beats plain old text for a lot of purposes. So why not generate something visual from your running code, showing you what's happening using boxes and arrows. I've had tons of fun (and not too much sleep) lately digging into this using Graphviz.

The value of this is to track that the flow is as expected, and if you need to you can investigate the input and output data going into your ex. repositories or "logical services". The limitation of this is that all needs to run within the same VM and thread.

Here is what the proof of concept app produced from a dummy java stack in a unit test.

The text on the arrows are clickable links and gives the user this if clicking the "0.Arguments":

Okok, the arguments and results are just boring serialized XML data. They could probably be graphs too, but I haven't come around to that and that isn't really what I'm after.

I also made a simple Servlet, which lists all generated graphs and makes you able to click and view any of these.

the code
The rest of this blog will be slightly in-depth and describing the knots and bolts of this.

The main idea is to accumulate a graphviz dot -file a cross a call-stack. At the points you want as opposed to everything (using reflection and looking at your entire call stack).

Aspect point cuts (Spring and AspectJ) is perfect for the job. I use ThreadLocal to keep a graph context/handler and simply append to it every time the aspect is invoked. The context saves a file and is released when the call-stack is done.

The Servlet in the proof of concept code is just a nice-to-have and requires graphviz to be installed on the "server". It invokes the 'dot' executable and pushes the output svg (or pdf / png / whatever you want) to the user.

You probably don't want this logging done all the time, due to performance and extensive logging to your temp. So I've stuck a check for an environment variable in the aspect - so you can enable and disable when you need this.

That's it really. You can check out the proof of concept from github and run the tests to see the graph-files get generated. Use the code as you please. Check out the README and please comment if you see any weaknesses or have any opinions.


12 May 2010

+rw clipboard

I saw some guy do a cat on some file (directly into his clipboard) and then paste/ctrl-v the text into his editor. My brain immediataly went "gimme! gimme! gimme!"

After a little googling around I found that his tools, pbcopy/pbpaste, was exclusively for OS X. A few minutes more with google showed me that the tool for the job in Ubuntu was xsel

#apt-cache search xsel
xsel - command-line tool to access X clipboard and selection buffers

However xsel covers both read and write and uses parameter to distinct them. My brain isn't up for the job remembering parameters so I decided Steve Jobs'es command was my way. Alias will fix this right up and I have pbcopy and pbpaste and feel happy and warm inside.

get xsel
#sudo apt-get install xsel

Here are the commands:
#cat myfile.txt | xsel -ib
#xsel -o > mycopy.txt

put these two lines into ~/.bashrc if you want this the OS X -way.

alias pbcopy='xsel -ib'
alias pbpaste='xsel -ob'

Do it like apple does:
#cat myfiles.txt | pbcopy
#pbpaste > mycopy.txt


edit.(15.04.2011) For some reason the xsel with Ubuntu 10.10. needs xsel -ib (not just xsel -i). No idea why, but blog post is updated accordingly.

24 April 2010

Spotify links in Ubuntu & Chrome

Spotify doesn't work in Linux, natively. (edit: it does now) So it's done using wine following this excellent howto.

This means however, that Chrome (and your Ubuntu) is unaware of spotify running "under the radar" as a wine/spotify.exe process. So when clicking a link, like this one: http://open.spotify.com/track/61K2lUXbNSvhEIOkhcozK4 spotify doesn't react.

I've Copy&Paste this dead-on recipe from another blog I found, just so I don't loose it in the future. I can confirm it's working on my Ubuntu 10.04 x64 desktop machine.

echo '#!/bin/sh' > ~/.browser2spotify
echo 'wine "$HOME/.wine/drive_c/Program Files/Spotify/spotify.exe" /uri "$@"' >> ~/.browser2spotify
chmod 755 ~/.browser2spotify
gconftool-2 -t string -s /desktop/gnome/url-handlers/spotify/command "/home/${USER}/.browser2spotify %s"
gconftool-2 -s /desktop/gnome/url-handlers/spotify/needs_terminal false -t bool
gconftool-2 -s /desktop/gnome/url-handlers/spotify/enabled true -t bool

The clue with this is to make gnome pass URLs starting with spotify: to the script which passes the URL to spotify.exe

This will do the job until Spotify makes a proper native linux client. Id'e think that wouldn't be too hard as it's an Adobe Air application, which is flash, which is pretty platform independent and very capable of running properly on Linux.


13 April 2010

sshfs - brilliantly simple

Got another linux/unix -box sitting somewhere in your home? I do, and I want _everything_ available to me from where I sit at my desktop.

I've used nfs quite a bit in the past, while quite easy to set-up it's a hassle compared to the simpleness of sshfs. And setting up samba is like getting skinned alive on this scale.

#apt-get install sshfs

(ubuntu, the other machine / slave)
#apt-get install openssh-server

put this in /etc/fstab, and you can on-demand mount/unmount the other computer when you see fit:

sshfs#finn@ /home/finn/theslavecomputer fuse noauto,defaults,users,idmap=user 0 0

Now you have the root of the filesystem of the other machine sitting in your home directory. Sweet?

#mount theslavecomputer
... any time you need it. I prefer not using auto mount as I only need access to the other machine like 1 in 20 times I boot. A good rule on fstab in my experience is to not put a lot of stuff on auto-mount. It will get you in trouble when booting eventually which makes you so miserable you'll not click 'like' on any comments you'll read Facebook that day.

Tip: make this password less by uploading the public certificate. Google it and you'll get a step-by-step in a sec.


07 April 2010

Synergy between Ubuntu and OS X

I use Synergy to share one set of mouse and keyboard between my workstation PC, running Ubuntu 10.04 and my laptop sitting on my desk next to my workstation screen. The laptop is running OS X.

How about not raising your hands off your keyboard and mouse when you have to do stuff on that laptop? Greetings Synergy

Here is how I configured it.

On OS X, the keboard+mouse -client
... I followed one of the suggested steps on synergys website. Copy&Paste:

# sudo su -
# defaults read com.apple.loginwindow LoginHook
# sudo mkdir -p /Library/LoginWindow
# sudo vi LoginHook.sh

killall ${prog[0]##*/}
exec "${prog[@]}"

# sudo chmod 755 /Library/LoginWindow/LoginHook.sh
# defaults write com.apple.loginwindow LoginHook /Library/LoginWindow/LoginHook.sh

On Ubuntu, the server with mouse+keyboard attached
... the guide wasn't that much help as it wasn't specific for any distribution, so I decided to just put the startup after gdm is fired up.
# sudo vi /etc/gdm/PostLogin/Default

killall synergys
sleep 1
/usr/bin/synergys -c /etc/synergy.conf &

My /etc/synergy.conf looks like this:

section: screens

section: links
right = finnmac.local
left = finnbuntu


Rescue Ubuntu 10.04 graphics crash after grub

This is a note to self, in case I run into this problem again. Obviously a (beta) problem with the nvidia -driver.

The symptoms is that you get the grub chooser showing just fine, but get a distorted strange looking graphics crash screen directly after - when it's supposed to show the boot splash. Turned out I had to disable nvidia to find my underlying problem which prevented me booting. This was a error in /etc/fstab, my own fault entirely.

This is a very generic and nice way to mount up and rescue your system, and using chroot you've almost got your system running as if you've booted it off your hard drive. (well, not entirely true)

Boot off the Ubuntu the 10.04 CD and open a terminal

#mount /dev/sda1 /mnt
#mount -o bind /proc /mnt/proc
#mount -o bind /dev /mnt/dev
#sudo chroot /mnt
#apt-get remove nvidia-96 --purge
#apt-get remove nvidia-173 --purge

11 March 2010

Android Market - The power of the latest comment

I've watched my download statistics closely about a month for Workout Rotation Diary on Android Market.

I've seen a clear pattern telling me that the latest comment has a huge of impact on daily downloads. When the latest comment and rating is positive, the app can do 100-200 downloads a day. With a loud negative comment being the newest (like at the time of writing I have 2 really negative, the latest being: "USELESS!") it's down to 10-50 a day.

My comfort is that it has 2k active installations and 5k downloads, so maybe there are some individuals who find it useful.

... so not going to kill myself quite yet.

23 February 2010

Developing Android apps -> the android.jar source #2

edit: this method is outdated. This one works now (16 April 2011).

For some reason, I've had a fight or two with eclipse on getting these sources right. Even after completing the steps I've mentioned in the other blog post.

The steps I'll describe now makes a fake android-src.jar, and fixed it for me tonight. *puh*

(requires you've done everything else I've mentioned)
#ln -s ~/src/android-sources android-src.jar
In eclipse
  • Select your project on the right menu of eclipse
  • Choose Properties
  • Select Android on the left hand list.
  • Choose a different SDK version, 1.6 for example.
  • Click Apply.
  • Wait for building workspace (on the bottom right side of the eclipse window).
  • Choose your correct SDK version again. 1.5 in my example.
  • Click Apply.
Note that the dummy android-src-jar we've made by sym-link needs to be replaced if you're swapping SDK versions.

This is a bit fuzzy and I'm not sure why these sources are causing such grief. There may be better ways of doing this, please tell me if you come across one.


13 February 2010

Android -> SDK provided icons, images and such

Another fairly beginner thing I thought I'd toss out there. I found this out by chance after doing stuff the hard way for a while.

I've spent (aka wasted) time finding my icon this way: changing the icon, launched the app in the emulator, changed the icon, launched the app. Until I finally was pleased with the icon.

... well, like I said, waste of time. The icons are in the open in the SDK in data/res/drawable ex (/opt/android-sdk-linux/platforms/android-1.5/data/res/drawable)


08 February 2010

bit.ly for android

I want to use the url shortening service bit.ly in an android app I'm working on, and was looking for a .jar or something to help me.

Couldn't find anything made for Android which used the httpclient and json -stuff we have bundled with the the Dalvik vm, so I made one myself today and put it on github.

Easiest way is just go grab the BitlyAndroid.java, put it into your source code and start making short URLs. The github project is just a "proof of concept" android junit project.


BitlyAndroid bitly = new BitlyAndroid("bitlyapidemo","R_0da49e0a9118ff35f52f629d2d71bf07");
String shortUrl = bitly.getShortUrl("http://johnsenf.blogspot.com/2009/12/android-sources-and-javadoc-in-eclipse.html");
//shortUrl = "http://bit.ly/9LSEfV"


24 January 2010

Android app published 1 week ago

I'm trying to figure out what to make of the download/active installs figures I get in the Android Market -console. As to how much activity there really is in the android market.

After exactly 1 week from publishing, the new free app workout rotation diary has 941 downloads and 578 current installs.

It's not much, but not terrible either. I've made no effort in promoting or marketing it anywhere. Except my personal Twitter and Facebook, which spans a maximum total of 200 people. Where I figure less than 10% to be people who remotely care about the subject.

In as little as a week no active installs can be regarded as users. So I figured the downloads being mere curiosity downloads or try-outs.

The category for the app is Health, which is not the hottest category in android market. At least not in my view. It's a boring category for most people who want cool gadgets and show-offs in these early days of Android. (this is purely based on gut feeling on my part of course).

Most people using android phones are tech heads and early adapters. The non-tech moms and dads will hopefully come around in.... a year(?)

We'll see what happens, and what feedback it gets (comments and the ratings). I'll keep posting about it if it takes any turns. I'm considering promoting it in various health and fitness forums and sites, but haven't decided if I'll bother yet.


13 January 2010

Developing Android apps -> get familiar with ApiDemos

... just another beginner tip I thought Id'e put out there in case it saves anyone some time.

When starting off with Android development, you'll immediately start wondering how basic stuff is done and you'll need example code. Like how to get a menu in your app, how to launch new Activities and how to get data into your Spinner (aka drop down)

My second best tip for this is to get ApiDemos into your workspace.

You'll find it here:android-sdk/platforms/android-2.0/samples/ApiDemos
(replace the SDK version for what you're using obviously)

File -> New -> Other -> Android Project.
Select "Create project from existing sample"

Fire it up in your emulator and start clicking about. The app is brilliantly organized and you'll find everything pretty quickly after spending a few minutes toying with it. I got quite few ideas and gotchas just by clicking around looking.

The only downside with ApiDemo that it has complex reflection-like bootstrap, which makes it a bit hard to see how they actually start activities. So sometimes it's hard to find the source by tracking it. I ignored the bootup and took up the habbit of just doing a source search based on guessing, or click through the namespaces - you'll figure it out as I did I'm sure.

The silly #1 tip you already know: Google it ffs ;)

Lastly I'll add that the Common Tasks -page on the android site is quite useful.