Obtain the root logger programmatically in log4net

If you use log4net, you could have the need to configure the loggers programamtically. The problem arise when you want access to the root logger, since the documentation does not explain well how to obtain it.
So, here’s a snippet that show how to do it. Don’t forget to imort the log4net namespaces.

  1. using log4net;
  2. using log4net.Core;
  3. using log4net.Appender;
  4. using log4net.Layout;
  5. using log4net.Repository.Hierarchy;
  6. using log4net.Config;
  1. Hierarchy h = (Hierarchy)log4net.LogManager.GetRepository();
  2. Logger rootLogger = h.Root;

SSH Cheat Sheet

SSH

Login to host:

  1. ssh <host> -l <user> -p <port>

Login to host using an configured alias:

  1. ssh <host_alias>

SSH User Config File

A typical SSH configuration file usally stored in <home>/.ssh/

host <host_alias>
	Hostname <host>
	Port <port>
	ForwardAgent <yes|no>
	ForwardX11 <yes|no>
	User <user>

Enable SSH key authentication

To do on host

  • Transfer the public key of the user that want to login to the host in his home directory on the host
  • Add the public key to the list of the authorized ones
    cat <ssh_public_key>.pub >> ~/.ssh/authorized_keys
    

SCP

Copying file to host:

scp SourceFile user@host:directory/TargetFile

Copying file from host:

scp user@host:directory/SourceFile TargetFile
Blogged with the Flock Browser

First Facebook application

My first Facebook application “Car Pooling”, developed at Tmind, is currently on line and available to you all. Just browse to the following link http://apps.facebook.com/car_pooling/. I hope you’ll enjoy it. And if you have a comment, please let me know!

Good environment variable values during iPhone development

Directly from GHUnit, a small note about which variables to set during iPhone development.

Environment Variable:                 Default:  Set to:
NSDebugEnabled                           NO       YES
NSZombieEnabled                          NO       YES
NSDeallocateZombies                      NO       NO (or YES)
NSHangOnUncaughtException                NO       YES
NSAutoreleaseFreedObjectCheckEnabled     NO       YES

Actually, I keep forgetting them, so I hope this will be useful to me.

Rails ans SQLite3 on Ubuntu

To configure a Rails application in order to use SQLite3 please follow the following steps:

sudo apt-get install  sqlite3 swig libsqlite3-ruby libsqlite3-dev
 sudo gem install sqlite3-ruby

Then create a Rails application as usual and update the environment.rb file in the following way

Rails::Initializer.run do |config|
...
config.gem 'sqlite3-ruby', :lib => "sqlite3"
...
end

Get rid of folder that should not be versioned

If you work with subversion, for sure you had the problem to tell to subversion to ignore a folder inside your working copy. This happens for example if your IDE builds the sources in a folder inside your working copy. From the very first commit you’ll start noticing that subversion wants to add that “build” folder to your repository. But, obviously, this is not a good practice.

So you can tell subversion to ignore a folder. Just move in the folder that contains the folder you want to be ignored by subversion and type the following command.

svn propset svn:ignore <dir_you_want_to_be_ignored> .

The “dot” at the end is important! It means you’re specifying which folders of the current folder you want to be ignored.

Please note that <dir_you_want_to_be_ignored> should be written without trailing slashes. So for example if you want the build directory not to be managed by subversion, type…

svn propset svn:ignore build .

And not…

svn propset svn:ignore build/ .

This is a quick tip. I always forget how to do it, so I wrote that little note.

iPhone screen dimensions

This picture can be useful to those of you that develop graphics targeted to the iPhone platform. Here you see the dimensions in pixel of an iPhone windows in some of the most common configurations. Click on the image to enlarge it.

iphone dimensions

Chosing the number of decimal digits when printing a number with iPhone

This is a small snippet, useful whenever you want to convert a floating point number in a string with a fixed number of decimal digits.

NSNumberFormatter *format = [NSNumberFormatter new];
 [format setMaximumFractionDigits:1];
 NSNumber *aNumber = [[NSNumber alloc ] initWithDouble:54.4235264];
 NSString label = [[NSString alloc] initWithFormat:@"The number is %@", [format stringForObjectValue:aNumber]];
 [distance release];
 [format release];

Obviously the NSNumberFormatter class offers plenty of other method you can use to customize the way your numbers should be rendered.

iPhone: how to select a UITabBarItem programmatically

I’m working to an iPhone application with a TabBar on the footer area. Among the others there are a “Home” button and an “Account” button. The first allows the user to see a view that gives an overview of the application. The latter shows the view that the user uses to manage his/her account.

If the user is not currently logged in, in the “Home” view a warning message is displayed. There is also a button that is supposed to show the “Account” view. In that way it’s more clear for the user that he/she should log in.

How can you accomplish that task ? That post shows you the way I followed.

The big idea is to retrieve the TabBarController from the “Home” controller, and programmatically change the current view. To do that, the “Home” controller should get a reference to the TabBarController. But you can easily set that dependency in Interface Builder. You only need to provide a suited IBOutlet to the Home controller.

That is the tree structure of the controllers and views, as built in the interface builder.

iphone_change_tabbar_programmatically_0

So, that’s an excerpt of the HomeController showing you only what is really needed to reach our goal. The goToRegistrationPage method will execute programmatically the switch to the account page.

@interface HomeViewController : UIViewController {
UITabBarController *mainTabBarController;
}
@property(nonatomic, retain) IBOutlet UITabBarController *mainTabBarController;
-(IBAction) goToRegistrationPage;

Now, we only need to set in Interface Builder the link between the the IBOutlet we just created and the Tab Bar Controller. Here’s the result.

iphone_change_tabbar_programmatically_1As you can see the mainTabBarController outlet is linked to the Tab Bar Controller we want to manage programmatically. That’s not difficult at all. Let’s give a look to the goToRegistrationPage method.

-(IBAction) goToRegistrationPage {
 mainTabBarController.selectedIndex=3;
}

Quite easy, isn’t it ?

Now the user click on the button on the Home view and he/she get exactly the same result of touching the tab bar button in the footer.

Hope you can find it useful.

Iscrizione nell'elenco certificatori CENED

E’ arrivata oggi conferma della mia iscrizione all’elenco certificatori CENED, con numero 11810. Date un’occhiata su http://www.cened.it/elenco_certificatori.