Skip to content

Instantly share code, notes, and snippets.

View indragiek's full-sized avatar

Indragie Karunaratne indragiek

View GitHub Profile
//
// FGOManagedObjectContextStack.h
//
// Created by Indragie Karunaratne on 2012-12-23.
// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FGOManagedObjectContextStack : NSObject
@indragiek
indragiek / main.c
Created November 29, 2012 01:10
Simple key logger for OS X using CGEventTap
// Super simple key logger that uses a CGEventTap to log
// the unicode strings for each key down event
// Doesn't handle special keys (enter, backspace, etc.)
#include <stdio.h>
#import <Carbon/Carbon.h>
#import <ApplicationServices/ApplicationServices.h>
CGEventRef loggerCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* context)
{
@indragiek
indragiek / SNRDiscogsEngine.h
Created August 19, 2012 23:28
API wrapper for the Discogs API built on AFNetworking
//
// SNRDiscogsEngine.h
// Sonora
//
// Created by Indragie Karunaratne on 11-11-18.
//
#import <Foundation/Foundation.h>
@interface SNRDiscogsEngine : NSObject
@indragiek
indragiek / SNRRestorationManager.h
Created August 19, 2012 20:16
Simple Cocoa state restoration
//
// SNRRestorationManager.h
// Sonora
//
// Created by Indragie Karunaratne on 2012-08-19.
//
#import <Foundation/Foundation.h>
@protocol SNRRestorableState <NSObject>
@indragiek
indragiek / NSImage+PrefPane.h
Created May 24, 2012 20:42
NSImage loading in pref panes
@interface NSImage (PrefPaneExtensions)
+ (NSImage*)prefPaneImageNamed:(NSString*)name;
@end
@indragiek
indragiek / gist:2772551
Created May 23, 2012 00:30
Application support folder
- (NSURL *)applicationSupportDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
NSString *path = [basePath stringByAppendingPathComponent:@"YourAppName"];
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:path isDirectory:NULL]) {
[fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
}
return [NSURL fileURLWithPath:path];
@indragiek
indragiek / NSWindow+Fade.h
Created November 27, 2011 05:55
NSWindow+Fade - Animator proxy based NSWindow fading
@interface NSWindow (Fade)
- (IBAction)fadeIn:(id)sender;
- (IBAction)fadeOut:(id)sender;
@end
@indragiek
indragiek / gist:1397046
Created November 27, 2011 05:50
NSWindow -isFullscreen
@interface NSWindow (Fullscreen)
- (BOOL)isFullscreen;
@end
@implementation NSWindow (Fullscreen)
- (BOOL)isFullscreen
{
return ([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask;
}
@end
@indragiek
indragiek / Autoscroll.m
Created November 19, 2011 20:15
AppKit autoscroll implemented in UIKit
@interface UIView (Autoscroll)
- (void)autoscroll:(UITouch*)touch;
@end
@implementation UIView (Autoscroll)
- (void)autoscroll:(UITouch*)touch
{
// Pass the autoscroll messages onto the superview until it reaches a view that handles the message
// If you want to pass the messages through the responder chain then this category would need to be
// implemented on UIResponder instead of UIView and you would call [self.nextResponder autoscroll:touch]
@indragiek
indragiek / BadgeCount.m
Created November 19, 2011 20:04
Automatically updating NSDockTile with badge count
@interface AppDelegate : NSObject
@property (nonatomic, assign) NSInteger badgeCount;
@end
@implementation AppDelegate
@synthesize badgeCount;
// Override the badgeCount setter to update the dock tile whenever the count is set
- (void)setBadgeCount:(NSInteger)count
{