Skip to content

Instantly share code, notes, and snippets.

Muhammad Fahied fahied

Block or report user

Report or block fahied

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View iOS Swift - Cancellable Task with

iOS Swift - Cancellable Task with GCD


I think most of you guys know GCD pretty well. Basically, GCD is a high level API to handle multi-threading operations. We use GCD almost on daily basis to switch thread and execute codes like:

DispatchQueue.main.async { //execute some codes here } 
//switch to main queue and execute codes asynchronously

DispatchQueue.main.sync { //execute some codes here } 
//switch to main queue and execute codes synchronously
fahied / etag
Created May 28, 2017 — forked from kevindelord/etag
How to integrate Etag in Swift
View etag
let API_HEADER_FIELD_NONE_MATCH : String = "If-None-Match"
let API_HEADER_FIELD_ETAG : String = "Etag"
func ETagForURL(urlString: String) -> String? {
// return the saved ETag value for the given URL
return NSUserDefaults.standardUserDefaults().objectForKey(urlString) as String?
fahied / gist:9f7f8b7323641e4f44b4
Created Oct 5, 2015 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan
View gist:9f7f8b7323641e4f44b4

OS X Preferences

most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
View logger.xml
<!-- this is plain logback config.
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

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) {
View .gitignore
# Copyright: Benjamin Weiss (keyboardsurfer)
# Under CC-BY-SA V3.0 (
# built application files
# lint folder
View NSManagedObject+Serialization.h
@interface NSManagedObject (Serialization)
- (NSDictionary*) toDictionary;
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (NSManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict
fahied /
Created May 4, 2012 — forked from joergviola/
Basic Auth a whole Play 2.0 Application
public class Global extends GlobalSettings {
public Action onRequest(Request arg0, Method arg1) {
return new Action.Simple() {
public Result call(Context ctx) throws Throwable {
String authConf = Config.getString("basic.auth");
if (authConf == null)
String auth = ctx.request().getHeader("Authorization");
fahied / Example1.js
Created Mar 19, 2012 — forked from tolmasky/Example1.js
On HTML5 Drag and Drop
View Example1.js
document.addEventListener("dragstart", function(event)
event.dataTransfer.setData("image/png", slides.imageRep());
event.dataTransfer.setData("slides", slides.serializedRep());
// etc.
}, false);
package controllers;
import play.mvc.*;
import models.*;
public class Application extends Controller {
You can’t perform that action at this time.