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 / 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");
@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 / aps-node
Last active October 6, 2015 10:11
Preparing APS Certificates for node-apn
After requesting the certificate from Apple, export your private key as a .p12 file and
download the .cer file (usually named aps_production.cer or aps_development.cer) from
the iOS Provisioning Portal.
Now, in the directory containing cert.cer and key.p12 execute the following commands to
generate your .pem files:
openssl x509 -in aps_development.cer -inform DER -outform PEM -out aps_development.pem
@interface NSManagedObject (Serialization)
- (NSDictionary*) toDictionary;
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (NSManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict
inContext:(NSManagedObjectContext*)context;
@end
@fahied
fahied / bitmask
Created January 2, 2016 09:44
Typical Bit Mask Operations
Typical Bit Mask Operations
Set a flag or overlay multiple values
flags | flagbitN
Unset a flag (zero-out a bit or set a bit to zero)
flags & ~flagbitN
Check if a bit is set
(flags & flagbitN) == flagbitN
@fahied
fahied / iosFonts.m
Created March 23, 2016 13:48
How to find available fonts in iOS app
Following is code for find all fonts from the system:
for(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"Family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"~~~~~~~~");
@fahied
fahied / storyboard
Created December 12, 2016 13:33
Convert iPhone storyboard to iPad (Universal) storyboard
After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?
The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:
From Xcode, right-click on the storyboard and choose Open As -> Source code
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Right-click on the storyboard again and choose Open As -> iOS Storyboard
The storyboard will now show all views in the correct size.
@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?
}
@fahied
fahied / hackerRank.swift
Last active July 4, 2017 06:14
HackerRank Read Input with Swift
//Read String array separated by new line character
func readInput () -> [String]{
let n: Int = Int(readLine()!)!
var strs = [String]()
(0...n-1).map { _ in
strs.append(readLine()!.lowercased())
}
return strs
}