Skip to content

Instantly share code, notes, and snippets.

View sumardi's full-sized avatar
🏠
Working from home

Sumardi Shukor sumardi

🏠
Working from home
View GitHub Profile
@sumardi
sumardi / gist:794644
Created January 25, 2011 08:01
How to convert an sqlite 2 database into an sqlite 3
sqlite2 path/to/olddb .dump > backupfile
sqlite3 path/to/newdb < backupfile
@sumardi
sumardi / gist:805694
Created February 1, 2011 10:45
iPhoneDev - Change views to landspace mode
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
@sumardi
sumardi / gist:805697
Created February 1, 2011 10:49
iPhoneDev - An example of UIActionSheet
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"What to do?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove" otherButtonTitles:@"Landscape", @"Portrait", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
@sumardi
sumardi / gist:805738
Created February 1, 2011 11:33
iPhoneDev - Creating and showing an alert.
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
[alert addButtonWithTitle:@"Yes"];
[alert show];
@sumardi
sumardi / gist:807496
Created February 2, 2011 10:10
iPhoneDev - Custom background for navigation bar
- (void)viewDidLoad {
self.navigationItem.title = @"Title Here"
// for landscape mode use - CGRectMake(0.0, 0.0, 480, 44.0)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 44.0)];
[imgView setImage:[UIImage imageNamed:@"navbar_bg.png"]];
// this puts image view under all other views and all the default elements (title, buttons etc)
[self.navigationController.navigationBar insertSubview:imgView atIndex:0];
@sumardi
sumardi / gist:830908
Created February 17, 2011 03:27
iPhoneDev - Tint color
- (void)viewDidLoad {
[super viewDidLoad];
// Navigation bar
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.6 green:.3 blue:.2 alpha:1];
// Search bar
self.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:.6 green:.3 blue:.2 alpha:1];
}
@sumardi
sumardi / gist:893020
Created March 29, 2011 19:04
PHP : Extract user agent
<?php
$browser = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";
function extract_user_agent($agent)
{
$found = array();
$pattern = "([^/[:space:]]*)" . "(/([^[:space:]]*))?";
$pattern .= "([[:space:]]*\[[a-zA-Z][a-zA-Z]\])?" . "[[:space:]]*";
$pattern .= "(\\((([^()]|(\\([^()]*\\)))*)\\))?" . "[[:space:]]*";
@sumardi
sumardi / gist:1175468
Created August 27, 2011 14:44
iPhoneDev - Limit the size of text field.
// Text field delegates
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([[textField text] length] + [string length] - range.length > MAX_LENGTH) {
return NO;
} else {
return YES;
}
}
@sumardi
sumardi / gist:1304290
Created October 21, 2011 16:39
Basic branching & merging
$ git branch experimental
$ git branch
$ git checkout experimental
(edit file)
$ git commit -a
$ git checkout master
(edit file)
$ git commit -a
$ git merge experimental
$ git diff
@sumardi
sumardi / gist:1305706
Created October 22, 2011 06:18
Xcode 4 : How to set/change default company name.
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME="YourNameHere";}'