Make Better Things

I like to make better things.

Node.js not linked error

Here is list of commands worked for me -

sudo brew uninstall node
brew update
brew upgrade
brew cleanup
brew install node
sudo chown -R $(whoami) /usr/local
brew link --overwrite node
brew postinstall node

How to share text and Image on WhatsApp in iOS

Sharing text and Images on WhatsApp is now possible through Open URL Scheme (deep linking).

Send Text -

NSString * msg = @"YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
    // Cannot open whatsapp

Send Image -

– in .h file

@property (retain) UIDocumentInteractionController * documentInteractionController;

– in .m file

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

    UIImage     * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
    NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.jpg”];

    [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.image";
    _documentInteractionController.delegate = self;

    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];

} else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@“No WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];

You need add these lines in .plist file for iOS 9:


How to delete a folder from git history

You can follow these steps to delete a folder from git history.

#Removing folder from git history
git filter-branch --tree-filter 'rm -rf node_modules' --prune-empty HEAD
#Adding removed folder in ".gitignore" file so that we don't track it anymore
echo node_modules/ >> .gitignore
#Adding .gitignore and committing this change in repo
git add .gitignore
git commit -m 'Removing node_modules from git history'
#Now freeing up spaces from removed references
git gc
#Pushing changes to server forcefully
git push origin master --force

Clone a Git repo without history (just latest commit)

One common problem with big git repos is it takes a lot of time to clone, because in cloning git download everything beginning form the first commit. Sometimes we don’t need that much of history with code.

We can use “–depth” option in “git clone” command to specify how many commits we need. By providing an argument of “–depth 1″ to the clone command, the process will copy only the latest revision of everything in the repository.

For example -

git clone --depth 1 jquery

This command only clones the HEAD of the jqueyr repository.

Note: Prior to git 1.9 we can’t use do pull or push on such repos.

How to show GPS strength value in iOS SDK

To show the signal strength of GPS we can use the properties of CLLocation like horizontalAccuracy and verticalAccuracy which indicate how accurate the device believes that location fix to be.

Here is some sample code -

if (someLocation.horizontalAccuracy < 0)
// No Signal
else if (someLocation.horizontalAccuracy > 163)
// Poor Signal
else if (someLocation.horizontalAccuracy > 48)
// Average Signal
// Full Signal