Skip to content

Instantly share code, notes, and snippets.

Brandon Trussell NorrinRadd

View GitHub Profile
View vimrc
" Configuration file for vim
" Took some cues from https://github.com/staticshock/dotfiles/blob/master/.vim/vimrc
set modeline
set modelines=4
autocmd FileType gitcommit,gitrebase setlocal nomodeline
" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible " Use Vim defaults instead of 100% vi compatibility
View gist:56d212e4996561df060f
let p = UILabel()
var prompt: NSString?
p.text = (prompt != nil) ? prompt! : "This is a prompt question"
let enter = UIButton.buttonWithType(UIButtonType.System) as UIButton
let bt = (buttonText != nil) ? buttonText : "Enter"
enter.setTitle(bt, forState: UIControlState.Normal)
var buttonTextColor: UIColor?
(buttonTextColor != nil) ? enter.setTitleColor(buttonTextColor, forState: UIControlState.Normal) : {};
@NorrinRadd
NorrinRadd / gist:3a461fe7bc714757b4b6
Created Jul 14, 2014
crazy interview questions
View gist:3a461fe7bc714757b4b6
Q: What’s wrong with this code?
NSLock* arrayLock = GetArrayLock();
NSMutableArray* myArray = GetSharedArray();
id anObject;
[arrayLock lock];
anObject = [myArray objectAtIndex:0];
[arrayLock unlock];
View gist:e6cab8715c18048d506e
/* Native binding */
extern "C" {
void _requestProducts(
char** sProductIdentifiers, uint32_t rp_len,
ManagedRequestCallback callback) {
NSMutableSet* productIdentifiers = [[NSMutableSet alloc] initWithCapacity:20];
for (int i=0; i<rp_len; i++) {
[productIdentifiers addObject:GetStringParam(sProductIdentifiers[i])];
View gist:96ba3aba63e221072c94
public class MonoPInvokeCallbackAttribute : System.Attribute
{
private Type type;
public MonoPInvokeCallbackAttribute( Type t ) { type = t; }
}
@NorrinRadd
NorrinRadd / gist:e4f2ce9694d3b28a751c
Last active Aug 29, 2015
description of mixing pointer and array syntax
View gist:e4f2ce9694d3b28a751c
[18:15:43] <Chris> Norrin: it's, like all C declarations, "declaration follows use".
[18:16:14] <Chris> So consider char (*x)[42]; You can then reason that *x is a char[42]. And (*x)[3] is a char.
[18:16:46] <Chris> Norrin: and in the case of char *x[42]; you can say that x[3] is a char * and *x[3] is a char.
so [] has precedence over *. hence why the () are required depending on intention.
[18:14:32] <Chris> Norrin: char *(*a)[42]; is a pointer to array of 42 char pointers.
@NorrinRadd
NorrinRadd / singleton
Last active Aug 29, 2015
singleton using init override
View singleton
@interface blah : blah
-(id)init NS_UNAVAILABLE;
@end
@implementation
-(id)init{abort();}
-(instancetype)internalInit {
return [super init];
}
View gist:481c2815b7435c66a5c6
func PrintableClassName<T>(variable : T) -> String
{
// Test for ObjC
if let v = variable as? NSObject
{
return v.classForCoder.description()
}
// If the object *can* be converted to ObjC type, do so
// However you lose any specifics as to type
@NorrinRadd
NorrinRadd / gist:f6073fc721224d69bc9f
Created Jun 12, 2014
Swift functions on all types
View gist:f6073fc721224d69bc9f
extension T! {
typealias ObjectiveCType = AnyObject
static func getObjectiveCType() -> Any.Type
func bridgeToObjectiveC() -> AnyObject
static func bridgeFromObjectiveC(x: AnyObject) -> T!?
static func isBridgedToObjectiveC() -> Bool
}
@NorrinRadd
NorrinRadd / SlideKeyboard.m
Created Feb 11, 2014
slide keyboard in from the right. Looks for UITextEffectsWindow in jacky way.
View SlideKeyboard.m
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note)
{
NSLog(@"Windows: %@", [UIApplication sharedApplication].windows);
for (UIWindow *window in [UIApplication sharedApplication].windows)
{
if ([window.class.description rangeOfString:@"Text"].location != NSNotFound)
{
window.alpha = 0.0f;
You can’t perform that action at this time.