Saare Jahan Se Accha Tabs

January 26, 2010 vinaychavan22 Leave a comment

On Our Republic Day…This is the only song that comes to my mind, really sounds too good on my electric guitar.

Saare Jahan Se Accha

----------------------

4---------------------

---7--5-7---4--5--5---

----------------------

----------------------

----------------------

Hindostaan Hamara...

-----------------------------

----------5-6-5-5---6-5------

-----5--7---------7-----7-5--

5--7-------------------------

-----------------------------

-----------------------------

Hum Bulbule Hai Isaki

-----------------5------

--6-8---8-8-5--6---8----

7-----------------------

------------------------

------------------------

------------------------

Yeh Gulsitan Hamara Hamara....

-------------------------------

5-6-8--6-----------------------

----------8--7-5-5--5-5-4------

--------------------------7-5--

-------------------------------

-------------------------------

Enjoy playing the tune…

Original version … link

NSDate and Sqlite3 in iPhone

January 5, 2010 vinaychavan22 Leave a comment

While working with NSDate and sqlite3 on iPhone the common problem many people face is about storing and retrieving NSDate from sqlite3 database. There are mainly two methods to do so, one is to get the time interval (timeIntervalSince1970) from reference date and save the interval as double value in the database, second is to convert date into string using NSDateFormatter and save the text value in the database.

NOTE: The type of column where we want to store NSDate should be DATETIME in both the methods.

Method 1: using timeIntervalSince1970

Writing NSDate to sqlite3 DB

NSDate *dateToWrite = [NSDate date]; // current date

double valueToWrite = [date timeIntervalSince1970];

// save “valueToWrite” in DB as DOUBLE

Read NSDate from sqlite3 DB

//read double from sqlite3 DB n store it in valueFromDB(double)

NSDate *dateFromDB = [NSDate dateWithTimeIntervalSince1970:valueFromDB];

Method 2: using NSDateFormatter ( i prefer )

Writing NSDate to sqlite3 DB

NSDate *dateToWrite = [NSDate date]; // current date

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSString *stringToWrite = [dateFormatter stringFromDate:dateToWrite];

//save “stringToWrite” in DB as TEXT

[dateFormatter release], dateFormatter = nil;

Reading NSDate from sqlite3 DB

//read TEXT from sqlite3 DB n store it in stringFromDB(NSString*)

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSDate *dateFromDB = [dateFormatter dateFromString:stringFromDB];

[dateFormatter release], dateFormatter = nil;

I personally prefer the 2nd method here though it takes more number of lines to do it. ( sometimes it’s better to write more number of lines )

While accessing database file from terminal we can easily read the stored date as it is very much humanly readable.

Happy Coding…

Kal Ho Naa Ho (tabs)

November 28, 2009 vinaychavan22 Leave a comment

These are the tabs for one of my all time fav song. Tuned up my guitar and played it after real long time.

E-------------------10-8------------------ 2 times
B--11--10-11-10-11-------11-10--8-10-8-10-

E------6^------------------6^-------------
B--6-8----8----6-8~-6--6-8----8--9-8---6--
G------------8-----------------------8----

E-------------------10-8------------------ 2 times
B--11--10-11-10-11-------11-10--8-10-8-10-

E-------11-10-8---------------------11-10-8-----------------
B-10-11---------11-10-10-11~---10-11---------11-10-10-11-8\6-

E------6^------------------6^-------------
B--6-8----8----6-8~-6--6-8----8--9-8---6--
G------------8-----------------------8----

Thanks and enjoy the song…. :)


How to enable emoji on iPhone (programatically)

November 7, 2009 vinaychavan22 Leave a comment

Emoji is the Japanese term for the picture characters or emoticons used in Japanese wireless messages and webpages. Originally meaning pictograph, the word literally means e “picture” + moji “letter”. The characters are used much like emoticons elsewhere, but a wider range is provided, and the icons are standardized and built into the handsets. The three main Japanese operators, NTT DoCoMo, au and SoftBank Mobile (formerly Vodafone), have each defined their own variants of emoji. – Wikipedia

emoji keypad iPhone

Ok enough of this….Lets see how to enable this keyboard to be used everywhere. (By default this keyboard is only works on iPhones from Japan)

Step1:

- (void)enableEmoji {

#define kPreferencesFilePath @"/private/var/mobile/Library/Preferences/com.apple.Preferences.plist"

#define kEmojiKey @"KeyboardEmojiEverywhere"

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:kPreferencesFilePath];

if (!dict) return;

// Toggle the setting from on to off or vice versa

BOOL isSet = [[dict objectForKey:kEmojiKey] boolValue];

if (!isSet) {

[dict setObject:[NSNumber numberWithBool:YES] forKey:kEmojiKey];

[dict writeToFile:kPreferencesFilePath atomically:NO];

}

}

Note: This code does not work on iPhone Simulators, Works only on devices.

Step2: After running this code for once, go into “Settings” > “General” > “Keyboard” > “Japanese Keyboard”. Enable the “Emoji” keyboard.

Step3: Open any Notes.app & see the magic.

Note: According to Apple Forums its a private API, then how does applications on appStore are allowed to use it?

Flipping bar button like iTunes

September 3, 2009 vinaychavan22 1 comment

This is the example for how to create flipping bar button like iTunes. I faced the same problem while developing solutions for first time, after looking at iTunes app more closely..it seems the flipping thing in Navigation Bar is not a BarButton but button with images ( It does not show highlighted effect ).

Image showing flipping view

Image showing flipping view

All we need to do is use custom UIBarButtonItem with CustomView for this.

Step 1: Create UIBarButton with CustomView

//initialize bar button views

barButtonSuperView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 34, 30)];

barButtonPrimaryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 34, 30)];

UIButton * primaryButton = [UIButton buttonWithType:UIButtonTypeCustom];

primaryButton.frame = CGRectMake(0, 0, 34, 30);

[primaryButton setBackgroundColor:[UIColor greenColor]];

[primaryButton addTarget:self action:@selector(flipAction:) forControlEvents:UIControlEventTouchUpInside];

[barButtonPrimaryView addSubview:primaryButton];

barButtonSecondaryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 34, 30)];

UIButton * secondaryButton = [UIButton buttonWithType:UIButtonTypeCustom];

secondaryButton.frame = CGRectMake(0, 0, 34, 30);

[secondaryButton setBackgroundColor:[UIColor redColor]];

[secondaryButton addTarget:self action:@selector(flipAction:) forControlEvents:UIControlEventTouchUpInside];

[barButtonSecondaryView addSubview:secondaryButton];

// self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:barButtonSuperView] autorelease];

UIView * barButtonSuperSuperView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 34, 30)];

barButtonSuperSuperView.backgroundColor = [UIColor viewFlipsideBackgroundColor];

[barButtonSuperSuperView addSubview:barButtonSuperView];

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:barButtonSuperSuperView] autorelease];

[barButtonSuperSuperView release], barButtonSuperSuperView = nil;

Step 2: Use UIView transition effects

[UIView beginAnimations:@"BarButtonViewAnimation" context:NULL];

[UIView setAnimationDuration:kTransitionDuration];

[UIView setAnimationTransition:([barButtonPrimaryView superview] ?

UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)

forView:barButtonSuperView cache:YES];

if ([barButtonPrimaryView superview])

{

[barButtonPrimaryView removeFromSuperview];

[barButtonSuperView addSubview:barButtonSecondaryView];

}

else

{

[barButtonPrimaryView removeFromSuperview];

[barButtonSuperView addSubview:barButtonPrimaryView];

}

[UIView commitAnimations];


Here is the complete demo code. link

UITableViewCell Selection

August 15, 2009 vinaychavan22 Leave a comment

I have seen many many applications so far, i mean really awesome applications. Still one thing  i see which is almost common with all of them except few one is that Custom UITableViewCells does not change text color when selected/highlighted. I am also a developer and i know these kind of things miss out while developing applications in rapid development cycles and under timeline pressure :(. but then it really shows high level of ignorance from developers side.

The solution is simple. Generally what we do is we create custom UIView and add it inside UITableViewCell. Just we need to do some extra coding in UIView. as shown in TableViewSuite.

CustomCellView.h

#import <UIKit/UIKit.h>

@interface CustomCellView : UIView {

BOOL highlighted;

}

@property (nonatomic, getter=isHighlighted) BOOL highlighted;

@end

CustomCellView.m

#import "CustomCellView.h"

@implementation CustomCellView

@synthesize highlighted;

- (id)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

// Initialization code

}

return self;

}

- (void)setHighlighted:(BOOL)isHighlighted {

// If highlighted state changes, need to redisplay.

if (highlighted != isHighlighted) {

highlighted = isHighlighted;

[self setNeedsDisplay];

}

}

- (void)drawRect:(CGRect)rect {

UIColor *nameTextColor;

if( self.highlighted ) {

nameTextColor = [UIColor whiteColor];

}else {

nameTextColor = [UIColor blackColor];

}

// Draw code

}

- (void)dealloc {

[super dealloc];

}

@end

Happy Coding..

Socha hai(Rock On) tabs

August 1, 2009 vinaychavan22 1 comment

I didn find good tabs for it anywhere so here i am posting my own version…

PART1
E--5----------------------------------------------------
B--7--------------------------3--------------2-3--------
G--7------4~----4-6-7---------2--0-2-4-----4-----2h4p2--
D--5--5-7-------------7h9p7~~---------------------------
A--5----------------------------------------------------
E--5----------------------------------------------------

PART2
E-------------------------------------
B---3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3---
G----2-2-2-2-0-0-0-0-4-4-4-4-2-2-2-2--
D-------------------------------------
A-------------------------------------
E-------------------------------------

PART1 & PART2 together 2 times

D
aasma hai neela kyun
Bm
paani geela geela kyun
G            A
gol kyun hai zamee
D
silk mein hai narmi kyun
Bm
aag mein hai garmi kyun
G                A
do aur do paanch kyun nahi
.. and so on

Very soon ill be posting full version. :)

YMSG16 Authentication

The new Yahoo messenger v9.0 uses ymsg 16 protocol. For login process client sends username and password to yahoo login server: https://login.yahoo.com, and in response server sends Token which is then used for client authentication process on scs.msg.yahoo.com:5050
This login process goes through multiple steps as follows..

Step 1: Send username and password to login server

Https request url:
https://login.yahoo.com/config/pwtoken_get?src=ymsgr&login=<username>&passwd=<password>
Https response and meaning:

  • Invalid username  : 1235
  • Wrong password  : 1212
  • Information Valid : 0 ymsgr= <token>partnerid=<pid>

data is used in step 2 for further processing.
Note: and seem to appear in pair for given username and password

Step 2: Send token to login server

Https request url:
https://login.yahoo.com/config/pwtoken_login?src=ymsgr&token=<token>
Https response and meaning:

  • Invalid ymsgr  : 100
  • Information Valid : 0 crumb=<crumb> Y=<Y-Cookie> T=<T-Cookie> cookievalidfor=

<crumb>, <Y_Cookie>, <T_Cookie> and <B_Cookie> are used in client authentication on receiving challenge string from Pager server.
Note: is received in header of the reponse.

Step 3: After receiving challenge string from pager server

When client receives challenge string from pager server, it sends encrypted response to server. This response is formed using received in Step 2 and challenge received from pager server.
Process for forming response:

  • crypt = crumb + challenge
  • hash = MD5(crypt)
  • response = BASE64(hash)
  • replace ‘+’ by ‘.’ in response
  • replace ‘/’ by ‘_’ in response
  • replace ‘=’ by ‘-’ in response

Client sends this calculated response for received challenge along with <Y_Cookie>, <T_Cookie> and <B_Cookie>.