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 / listmethodsObjC
Created November 6, 2014 10:22
Listing Methods at Runtime in Objective C
-(void)listAllClassMethods
{
// Iterate over the class and all superclasses
Class currentClass = [self class];
while (currentClass) {
// Iterate over all instance methods for this class
unsigned int methodCount;
Method *methodList = class_copyMethodList(currentClass, &methodCount);
unsigned int i = 0;
for (; i < methodCount; i++) {
@fahied
fahied / poodsWarning
Created November 7, 2014 10:42
Ignore Xcode warnings when using Cocoapods
Add to your Podfile:
platform :ios
# ignore all warnings from all pods
inhibit_all_warnings!
# ignore warnings from a specific pod
@fahied
fahied / blockInjection
Last active August 29, 2015 14:08
Injecting block in Objective C Methods using RUNTIME
#import <BILib.h>
#import <objc/runtime.h>
// customClass.m
// under @implementation
//override
+(void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@fahied
fahied / lics
Created December 2, 2014 13:07
to find the longest increasing contiguous subsequence
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define ARRAY_SIZE(A) sizeof(A)/sizeof(A[0])
@fahied
fahied / pairsum
Last active August 29, 2015 14:10
Given two sorted arrays of integers, find the pair of indices (one into each array) which identify elements which sum to a given integer
import java.util.ArrayList;
public class SearchMe {
static int[] intArrayA = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
static int[] intArrayB = {3,4,9,14};
public static void main (String[] args) throws java.lang.Exception
@fahied
fahied / requestAlwaysAuthorization
Created February 26, 2015 16:36
NSLocationWhenInUseUsageDescription
/*
So the first thing you need to do is to add one or both of the following keys to your Info.plist file:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
Both of these keys take a string which is a description of why you need location services. You can enter a string like “Location is required to find out where you are” which, as in iOS 7,
can be localized in the InfoPlist.strings file.
*/
@fahied
fahied / MACROS
Created June 22, 2015 05:10
iOS Useful Macros
// Constants
#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
#define APP_NAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]
#define APP_DELEGATE [[UIApplication sharedApplication] delegate]
#define USER_DEFAULTS [NSUserDefaults standardUserDefaults]
#define APPLICATION [UIApplication sharedApplication]
#define BUNDLE [NSBundle mainBundle]
#define MAIN_SCREEN [UIScreen mainScreen]
#define DOCUMENTS_DIR [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]
@fahied
fahied / collectionAccessibility
Created July 1, 2015 10:11
add UIAccessiblity to UICollectionViewCell
// Option 1: In ViewController, set the cell instance to have accessibility.
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell setIsAccessibilityElement:YES];
// Option 2: Implement the accessibility interface in the cell object:
// implementation file of Cusome CollectionViewCell
- (BOOL)isAccessibilityElement
{
return YES;
}
@fahied
fahied / 3DAnimation
Created August 23, 2015 04:31
Animate UITableViewCell along with Scrolling
/*
You have to hijack the scrollView (Add yourself as a ScrollViewDelegate alongside TableViewDelegate)
and the table view will automatically forward scrollview events along side tableview events.
(self.tableView.delegate = self) is really talking to both
<UIScrollViewDelegate, UITableViewDelegate>
I have a helper function in the example that also calculates distance to the top of the cell.
*/
package controllers;
import play.mvc.*;
import com.google.gson.*;
import models.*;
public class Application extends Controller {