Skip to content

Instantly share code, notes, and snippets.

@desaiashu
desaiashu / gist:4710037
Created February 4, 2013 21:51
Feed dialog to post on wall in Facebook SDK 3.1
1. Add the deprecated header "Facebook.h" to your project (it is included in the .framework)
2. In the completion handler of opening the session, create a facebook variable and set it's info to the session's info
facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
// Store the Facebook session information
facebook.accessToken = FBSession.activeSession.accessToken;
facebook.expirationDate = FBSession.activeSession.expirationDate;
3. To post to wall use this line (if you add a "to" key to the params dictionary you can post on a friend's wall):
[facebook dialog:@"feed" andParams:params andDelegate:self];
@desaiashu
desaiashu / Epoch to NSDate
Created January 11, 2013 01:01
Convert NSNumber representing epoch time to NSDate
// Epoch time (or unix time) is the number of seconds since Jan 1st 1970 00:00:00 UTC
// To convert an NSNumber representing epoch time to an NSDate object:
NSNumber *epochTimeOfSomeEvent = [NSNumber numberWithDouble:1357865700];
NSDate * dateOfThatSameEvent = [NSDate dateWithTimeIntervalSince1970:epochTimeOfSomeEvent];
// You can then compare this NSDate to the current date to get useful information from it
@desaiashu
desaiashu / gist:3495208
Created August 28, 2012 05:27
Method to replace all instances of a string in an arbitrary object containing dictionaries, arrays, strings and numbers
def replaceStringInObject(obj, old, new):
if isinstance(obj, list):
for i in range(len(obj)):
if isinstance(obj[i], str) and obj[i] == old:
obj[i] = new
else:
replacestrinobj(obj[i], old, new)
elif isinstance(obj, dict):
for k in obj:
if isinstance(obj[k], str) and obj[k] == old:
@desaiashu
desaiashu / app.py
Last active August 15, 2023 18:27
Sample Heroku Flask app with MongoHQ
import os
from urlparse import urlparse
from flask import Flask
from pymongo import MongoClient
MONGO_URL = os.environ.get('MONGOHQ_URL')
if MONGO_URL:
# Get client
client = MongoClient(MONGO_URL)