27 September 2014

Ifelse shortcut

if (testCondition() && executeMe() || executeMeOtherwise());

Origin come from bash, to execute if else on a single line:
[ $# == 0 ]  && echo 'invalid input' || processInput($*)
If no parameters passed, the echo 'Invalid input' else, start processing the input.

02 September 2014

Objective-c delegates

It is a long time I since I stopped working on iPhone and objc.

But some collage is working and we was discussing about objc delegates and what is it and how it is related to categories.

Following is an example illustrate how things going from Categories to Delegates.

// NSObject+TurnLights.h
// a Category on NSObject to allow any subclass to turn on/off lights
@interface NSObject (TurnLights)

-(void) turnLightsOn;
-(void) turnLightsOff;


// this is the lights class that delegate its work to some object (of type id) to do the on/off instead of itself
@implementation Lights

@synthesize id delegate;

-(void) doLightings{
      [delegate turnLightsOn];
      [delegate turnLightsOff];

// is my controller class that decided to be a delegate for the Lights class

#import "NSObject+TurnLights.h"

@implementation MyController

-(void) btnClicked:(id) sender{
      Lights* lights = ...
      [lights setDelegate: self];

-(void) turnLightsOn{

-(void) turnLightsOff{

30 May 2014

continually monitor CPU usage for a command

cmd=[m]oviecrawler;while :; do echo -ne "CPU: `ps aux | grep $cmd | awk '{print $3}'`\\r" ;  sleep 1; done

11 May 2014

Banshee souldcloud integeration

I wanted to play sounds from soundcloud on banshee...

I found source code on githug, I've forked to fit my needs

Project at github

10 May 2014

refactor (find and replace in files)

If you want to refactor (find and replace in files) , you could use the following script (on your own)


07 May 2014

Obtain the best look ever for Intellj on Linux

(1) install freetype
$ sudo apt-get install libfreetype6

(2) install infinality patch (https://launchpad.net/~no1wantdthisname/+archive/ppa)
$ sudo add-apt-repository ppa:no1wantdthisname/ppa
$ sudo apt-get update
$ sudo apt-get install fontconfig-infinality

I had to do the following afterwards:
$ sudo rm /etc/fonts/conf.avail/52-infinality.conf
$ sudo ln -s /etc/fonts/infinality/infinality.conf /etc/fonts/conf.avail/52-infinality.conf

To use Windows 7 like font rendering do the following:
$ sudo /etc/fonts/infinality/infctl.sh setstyle osx
Set USE_STYLE to "osx" in /etc/profile.d/infinality-settings.sh

(3) install font fixed OpenJDK (https://launchpad.net/~no1wantdthisname/+archive/openjdk-fontfix)
$ sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

To use this JDK only for IntelliJ, prepend this line to bin/idea.sh:

(4) JVM options
Add the following options to the .vmoptions file of IntelliJ

Perform a reboot

See the result with default Darcula theme in attachment.

Hope this helps someone!


BTW, I've tried this on Idea 13.1 on Ubuntu 14.04 and it works like a charm ... here's an screenshot ..