Skip to content

Instantly share code, notes, and snippets.

View fahied's full-sized avatar

Muhammad Fahied fahied

  • Emirates Airlines
  • Dubai
View GitHub Profile
package controllers;
import play.mvc.*;
import com.google.gson.*;
import models.*;
public class Application extends Controller {
@fahied
fahied / Example1.js
Created March 19, 2012 19:04 — forked from tolmasky/Example1.js
On HTML5 Drag and Drop
document.addEventListener("dragstart", function(event)
{
event.dataTransfer.setData("image/png", slides.imageRep());
event.dataTransfer.setData("slides", slides.serializedRep());
// etc.
}, false);
@fahied
fahied / Global.java
Created May 4, 2012 20:05 — forked from joergviola/Global.java
Basic Auth a whole Play 2.0 Application
public class Global extends GlobalSettings {
@Override
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)
return delegate.call(ctx);
String auth = ctx.request().getHeader("Authorization");
@interface NSManagedObject (Serialization)
- (NSDictionary*) toDictionary;
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (NSManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict
inContext:(NSManagedObjectContext*)context;
@end
# 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

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 / 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 / gist:9f7f8b7323641e4f44b4
Created October 5, 2015 15:59 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

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
@fahied
fahied / etag
Created May 28, 2017 08:01 — forked from kevindelord/etag
How to integrate Etag in Swift
let API_HEADER_FIELD_NONE_MATCH : String = "If-None-Match"
let API_HEADER_FIELD_ETAG : String = "Etag"
let API_REQUEST_SUCCESS : Int = 200
func ETagForURL(urlString: String) -> String? {
// return the saved ETag value for the given URL
return NSUserDefaults.standardUserDefaults().objectForKey(urlString) as String?
}

iOS Swift - Cancellable Task with GCD

#iOSBySheldon

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