Skip to content

Instantly share code, notes, and snippets.

View indyfromoz's full-sized avatar
🏠
Working from home

Indrajit Chakrabarty indyfromoz

🏠
Working from home
View GitHub Profile
@ducas
ducas / MongoApiController.cs
Created April 10, 2014 23:53
Generic WebAPI controller to provide a REST interface for MongoDB collections
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace Web.Core
{
public abstract class MongoApiController<T> : ApiController
@tapsandswipes
tapsandswipes / gist:7e10da769b07c030c1e4
Last active August 29, 2015 14:01
Show/Hide chrome in UINavigationViewController on iOS 7
@property (nonatomic, assign, getter = isChromeHidden) BOOL chromeHidden;
- (BOOL)prefersStatusBarHidden {
return self.isChromeHidden;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationSlide;
}
@ulrikdamm
ulrikdamm / gist:a9edb3516db7e9a13829
Created May 26, 2014 11:17
Xcide quicklook for UIColor
@interface UIColor (WBDebugExtensions)
@end
@implementation UIColor (DebugExtensions)
- (id)debugQuickLookObject {
UIGraphicsBeginImageContext(CGSizeMake(128, 128));
[self setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 128, 128)] fill];
@jspahrsummers
jspahrsummers / gist:7061ea467b767c4ae604
Created June 16, 2014 05:05
How a Functor hypothetically should be implemented in Swift(?)
protocol Functor {
typealias Element
func map<U, UF: Functor where UF.Element == U>(f: Element -> U) -> UF
}
struct FunctorImpl<T>: Functor {
typealias Element = T
var value: T
// from https://twitter.com/ashfurrow/status/482488815266045952
func foo (closure: (Array<Int> -> ()) -> ()) {
closure({ (array: Array<Int>) -> () in
for i in array {
i
}
})
}
!!! There's a better solution here now, that doesn't require swizzling:
!!! http://www.splinter.com.au/2014/09/10/afnetworking-error-bodies/
!!! But i'll leave the below swizzling solution up for old time's sake
// AFURLSessionManager+ErrorResponse.h
// This hacks AFURLSessionManager so that it returns the error response in failure callbacks, in the error's userInfo.
// Usage:
// [mySessionManager POST:@"some_api_endpoint" parameters:params success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
@interface UIView (LayoutConvenience)
- (NSLayoutConstraint *)constraintAligningAttribute:(NSLayoutAttribute)attr withView:(UIView *)otherView;
@end
@implementation UIView (LayoutConvenience)
- (NSLayoutConstraint *)constraintAligningAttribute:(NSLayoutAttribute)attr withView:(UIView *)otherView {
return [NSLayoutConstraint constraintWithItem:self attribute:attr relatedBy:NSLayoutRelationEqual toItem:otherView attribute:attr multiplier:1.0 constant:0.0];
}
@end
@steipete
steipete / FullscreenWindow.m
Created November 7, 2014 18:11
Workaround for rdar://18906964: Moving UIViewController from one window to another breaks rotation in iOS 8.1
@interface FullscreenWindow : UIWindow @end
@implementation FullscreenWindow
- (void)setRootViewController:(UIViewController *)rootVC {
// Try to clear the existing interface orientation, fixes rdar://18906964.
// Apparantly in iOS 8.1 the interface orientation doesn't correctly clears out,
// which then leads to weird rotation issues.
@try {[rootVC setValue:@(UIInterfaceOrientationPortrait) forKey:NSStringFromSelector(@selector(interfaceOrientation))];}
@catch (NSException *exception) {}
[super setRootViewController:rootVC];
@onyxmueller
onyxmueller / strip_google_play_services.gradle
Last active August 29, 2015 14:09
Strip Google Play Services Packages
import groovy.transform.Field
// This is a drop-in Gradle script that allows you to easily strip out the packages you don't need
// from the Google Play Services library. The script will keep track of previous runs to prevent
// restripping each time you build.
// HOW TO USE THIS
//
// 1) Download/copy this strip_google_play_services.gradle file into the same location of your app's
// build.gradle file.
@kongtomorrow
kongtomorrow / gist:80ff47743d2c63355c42
Last active August 29, 2015 14:09
Swift + Unicode evilness :-D
let é = "precomposed character!"
let é = "decomposed characters!"
println(é) // prints "precomposed character!"
println(é) // prints "decomposed characters!"