Browsing articles in "Blog"

Navigation Controller inside a Tab Bar Controller

Jun 11, 2013   //   by admin   //   iOS  //  Comments Off

When you are using a Tab View controller based project it doesn’t come with a navigation stack by default. So if you would like have a navigation view on each tab, with a tab bar and back button, when navigating in the stack, here is the code to do so. All you need to do is modify the function: didFinishLaunchingWithOptions.

Standard Code

This is the standard code that you get when you create a tab view project:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

Modified Function to add a Navigation Stack

All you simply need to do is embed the main view controllers for each tab inside a navigation view controller.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UINavigationController *navController1, *navController2, *navController3;

UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}

navController1 = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
    navController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];
    navController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease];
    
    // navigation bar color
    navController1.navigationBar.tintColor = [UIColor blackColor];
    navController2.navigationBar.tintColor = [UIColor blackColor];
    navController3.navigationBar.tintColor = [UIColor blackColor];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[navController1, navController2, navController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

Any problems, please feel free to send me an email.

How to do a CSS Drop Shadow, you a web page.

May 31, 2013   //   by admin   //   Web Development  //  Comments Off

Here is a page explaining how to create a drop shadow:

http://phoenity.com/newtedge/drop_shadow/

Creating a File System on an external drive.

May 31, 2013   //   by admin   //   Linux  //  Comments Off

mkfs.ext3 -j /dev/sdb1

Got sdb1 from fdisk -l or dmesg (from when the disk is enumerated)

(This probably wipes the disk)

Then you can mount it

mount -t ext3 /dev/sdb1 /mnt/usb-backup (make sure usb-backup exists)

I carried out the above when I was trying to mount an external hard disk and getting the following error:

mount: wrong fs type, bad option, bad superblock on ext3 partition….

Creating a Samba Folder

May 31, 2013   //   by admin   //   Linux  //  Comments Off

In the file:

$ sudo vi /etc/samba/smb.conf

Add the lines:
[folder-name]
comment = Shared reference data (will not be backed up)
path = /home/john/sambafolder
writeable = yes
browseable = yes
valid users = john

$  sudo service smbd restart

If a file exists in Perl

May 31, 2013   //   by admin   //   Perl  //  Comments Off
 #!/usr/bin/perl -w $filename = '/path/to/your/file.doc'; if (-e $filename) { print "File Exists!"; } 
 Also get the file size:
 #!/usr/bin/perl -w $filename = '/path/to/your/file.doc'; $filesize = -s $filename; print $filesize;

Samba file share with a Windows Server

May 31, 2013   //   by admin   //   Linux  //  Comments Off
You may need to install smbfs:
sudo apt-get install smbfs 
 
I assume samba is already installed, if not:
sudo apt-get install samba 
 
 
Create directory to mount 
$mkdir -p /mnt/win

Mount windows server to the newly created directory$mount -t smbfs -o username=winntuser,password=mypassword //windowsserver/sharename /mnt/win
(Source
Next create the password file /etc/sambapasswords:cat > /etc/sambapasswords username = winntuserpassword = mypasswordmake sure that only root have access to itchown root:root /etc/sambapasswordschmod 600 /etc/sambapasswords 
Add an entry to your /etc/fstab: 
//windowserver/share /mnt/win smbfs
auto,gid=users,fmask=0664,dmask=0775,iocharset=iso8859-15, credentials=/etc/sambapasswords 0 0
 

Call Sudo from a Perl Script

May 31, 2013   //   by admin   //   Perl  //  Comments Off
use Sudo; my $password = '*****';my $su = Sudo->new( { sudo => '/usr/bin/su', username => "*****" , password => $password, program => "/tmp/test.sh" , program_args => '' } ); $result = $su->sudo_run();print "$result \n";if (exists($result->{error}) ){ &handle_error($result);}else{ printf "STDOUT: %s\n",$result->{stdout}; printf "STDERR: %s\n",$result->{stderr}; printf "return: %s\n",$result->{rc};}

Install a Perl Module

May 31, 2013   //   by admin   //   Perl  //  Comments Off

$sudo perl -MCPAN -e shell

cpan> install Sudo
cpan>  exit

It will ask you for a username and password, enter something you can remember.

For the Sudo Module, which is the module I was trying to install:

http://search.cpan.org/~landman/Sudo/lib/Sudo.pm#NAME

Returning a value from Perl Script

May 31, 2013   //   by admin   //   Perl  //  Comments Off
#!/usr/bin/perl -wuse strict; print "This is going to exit\n";exit 2;
$> perl aboveProgram.plThis is going to exit$> echo $?2$>

Howto set-up a crontab file

May 31, 2013   //   by admin   //   Linux  //  Comments Off

To edit crontab:

$crontab -e

16 18 * * * /home/user/backup_script.pl > /home/user/backup_script.log

Use ‘>’ to output standard output to a log file.

See below for the sterling explaination I found (thank you to corenominal.org):

(Source: http://corenominal.org/howto-setup-a-crontab-file/)

In Linux, Cron is a daemon/service that executes shell commands periodically on a given schedule. Cron is driven by a crontab, a configuration file that holds details of what commands are to be run along with a timetable of when to run them.

Creating a crontab file

You can create a crontab file by entering the following terminal command:
crontab -e
Entering the above command will open a terminal editor with a new blank crontab file, or it will open an existing crontab if you already have one. You can now enter the commands to be executed, see syntax below, before saving the file and exiting the editor. As long as your entries were entered correctly your commands should now be executed at the times/dates you specified. You can see a list of active crontab entries by entering the following terminal command:
crontab -l

Crontab syntax

A crontab file has six fields for specifying minute, hour, day of month, month, day of week and the command to be run at that interval. See below:
* * * * * command to be executed- - - - -| | | | || | | | +----- day of week (0 - 6) (Sunday=0)| | | +------- month (1 - 12)| | +--------- day of month (1 - 31)| +----------- hour (0 - 23)+------------- min (0 - 59)

Crontab examples

Writing a crontab file can be a somewhat confusing for first time users, therefore I have listed below some crontab examples:
* * * * *  #Runs every minute30 * * * *  #Runs at 30 minutes past the hour45 6 * * *  #Runs at 6:45 am every day45 18 * * *  #Runs at 6:45 pm every day00 1 * * 0  #Runs at 1:00 am every Sunday00 1 * * 7  #Runs at 1:00 am every Sunday00 1 * * Sun  #Runs at 1:00 am every Sunday30 8 1 * *  #Runs at 8:30 am on the first day of every month00 0-23/2 02 07 *  #Runs every other hour on the 2nd of July
As well as the above there are also special strings that can be used:
@reboot  #Runs at boot@yearly  #Runs once a year [0 0 1 1 *]@annually  #Runs once a year [0 0 1 1 *]@monthly  #Runs once a month [0 0 1 * *]@weekly  #Runs once a week [0 0 * * 0]@daily  #Runs once a day [0 0 * * *]@midnight  #Runs once a day [0 0 * * *]@hourly  #Runs once an hour [0 * * * *]

Multiple commands

A double-ampersand “&&” can be used to run multiple commands consecutively. The following example would run command_01 and then command_02 once a day:
@daily  && 

Disabling email notifications

By default a cron job will send an email to the user account executing the cronjob. If this is not needed put the following command at the end of the cron job line:
>/dev/null 2>&1

Specifying a crontab file to use

As mentioned at the top of this post, you can create a new crontab file with the “crontab -e” command. However, you may already have a crontab file, if you do you can set it to be used with the following command:
crontab -u  
Therefore the following command…
crontab -u tux ~/crontab
…would set Tux’s crontab file to that of the file named “crontab” residing in Tux’s home directory.

Removing a crontab file

To remove your crontab file simply enter the following terminal command:
crontab -r

Further information

Refer to the man page for further information about crontab. Enter the terminal command:
man crontab

sudo: /etc/sudoers is mode 0640, should be 0440

May 31, 2013   //   by admin   //   Linux  //  Comments Off
Firstly you shouldn’t change the permissions of your sudoers file!!! However, if for whatever reason you do change the permissions, it turns into a bit of a catch 22 problem:
sudo: /etc/sudoers is mode 0640, should be 0440
sudo: no valid sudoers sources found, quitting
To sort this out reboot, press “Esc” at the grub loader screen, and when linux is booting and enter into the latest recovery mode. On the next menu, select the option that allows you to enter into a command line as root. Then change your file permissions, so in this case:

Or

You can use the live ubuntu CD, and mount the hard disk’s file system, then do the following:

$ chmod 0440 /etc/sudoers

Reboot normally

Working out disk usage on Linux

May 31, 2013   //   by admin   //   Linux  //  Comments Off

If you are running our of space on a linux box, then the following command will tell you 20 largest folders:

du -a /home | sort -n -r | head -n 20


A report of the overall disk space, for all the connected hard disks:

df

Very useful!

Pages:123456789»