Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fahied's full-sized avatar

Muhammad Fahied fahied

  • Emirates Airlines
  • Dubai
View GitHub Profile
@fahied
fahied / gist:b1389a04a0207448aa50
Last active August 29, 2015 14:01
installing pod : permission denied
sudo chown -R `whoami` path/to/project/
if that doesn't help, you can also try
sudo chown -R `whoami` ~/.cocoapods
sudo chown -R `whoami` ~/Library/Caches/CocoaPods
# Copyright: Benjamin Weiss (keyboardsurfer) https://github.com/keyboardsurfer
# Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
# built application files
*.apk
*.ap_
*.jar
!gradle/wrapper/gradle-wrapper.jar
# lint folder
@fahied
fahied / play2
Created June 26, 2014 09:05
Play framework 2.x.x Best Practices
########### Useful Commands ###########
# Download source code for Java API used in project
$ play "eclipse with-source=true"
# Run Play in https mode
$ JAVA_OPTS=-Dhttps.port=9001 play start
########### Useful Liberaries ###########
# Mongodb Wrapper for JAVA
http://jongo.org/
@fahied
fahied / gitcheat
Last active August 29, 2015 14:03
GIT Cheatsheet
# Change the current branch to master in git #
You can rename/remove master on remote, but this will be an issue if lots of people have based their work on the remote master branch and have pulled that branch in their local repo.
That might not be the case here since everyone seems to be working on branch 'seotweaks'.
In that case you can:
(Make a git remote --show to check how your remote is declared within your local repo. I will assume 'origin')
(Regarding GitHub, house9 comments: "I had to do one additional step, click the 'Admin' button on GitHub and set the 'Default Branch' to something other than 'master', then put it back afterwards")
@fahied
fahied / jquery-uiwebview
Created August 26, 2014 09:55
jquery hash or query in UIWebview
// set path for the file to load in uiwebview
NSString *filePath = [resourceDir stringByAppendingPathComponent:@"index.html"];
// convert to NSURL object, remember not to incoude #tag yet, as fileURLWithPath will replacce jquery # with %23
// and will cause trouble to load your page properly
NSURL *fileURL = [NSURL fileURLWithPath:menuPath];
// add hash here
fileURL = [NSURL URLWithString:@"#menu" relativeToURL:fileURL];

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
@fahied
fahied / multipartPutAFN
Last active August 29, 2015 14:05
Multipart-formdata PUT using AFNetworking
+(void)putMultipartWhereRoute:(NSString*)route jsonData:(NSData*)jsonData images:(NSArray*)images completion:(void (^)(NSError *error, NSDictionary *response))completion
{
NetworkManager *networkManger = [NetworkManager sharedManager];
NSString *serviceURL = [[networkManger.baseURL absoluteString] stringByAppendingString:route];
NSMutableURLRequest *request = [networkManger.requestSerializer multipartFormRequestWithMethod:@"PUT" URLString:serviceURL parameters:nil constructingBodyWithBlock:^(id formData) {
//append json data
[formData appendPartWithFormData:jsonData name:@"note"];
//append images
@fahied
fahied / logger.xml
Created August 28, 2014 13:06 — forked from saml/logger.xml
<configuration>
<!-- this is plain logback config.
documentation: http://logback.qos.ch/manual/appenders.html
set -Dlogger.level like this:
/usr/java/latest/bin/java -Dconfig.file=/apps/YOURAPP/conf/application.conf -cp /apps/YOURAPP/staged/* -Dlogger.level=WARN play.core.server.NettyServer /apps/YOURAPP
-->
@fahied
fahied / afn_authentication
Created September 23, 2014 08:59
add Authentication to AFHTTPRequestOperation
//1. using completion block
[operation setAuthenticationChallengeBlock:
^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
NSURLCredential *cred = [NSURLCredential
credentialWithUser:@"username"
password:@"password"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}];
@fahied
fahied / delay
Created October 7, 2014 08:28
delay execution for time
double delayInSeconds = 600.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakself success:vc];
});