Skip to content

Instantly share code, notes, and snippets.

View cppforlife's full-sized avatar
👉
building Kubernetes tools in https://github.com/k14s

Dmitriy Kalinin cppforlife

👉
building Kubernetes tools in https://github.com/k14s
View GitHub Profile
COLOR_RED="\[\e[31;40m\]"
COLOR_GREEN="\[\e[32;40m\]"
COLOR_CYAN="\[\e[36;40m\]"
COLOR_RESET="\[\e[0m\]"
function git_branch_name {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}")"
# possible to use __git_ps1 here
}
@cppforlife
cppforlife / gist:1018032
Created June 10, 2011 00:07
query trace
alias disable_query_trace='cd ~/workspace/project/vendor/plugins/ ; rm -rf query_trace ; cd ~/workspace/project'
alias enable_query_trace='cd ~/workspace/project/vendor/plugins/ ; git clone http://github.com/ntalbott/query_trace.git ; cd ~/workspace/project'
@cppforlife
cppforlife / gist:1175040
Created August 27, 2011 05:47
Comparing UIImages
@interface UIImage (ToEqualByBytes)
- (BOOL)toEqualByBytes:(UIImage *)otherImage;
@end
@implementation UIImage (ToEqualByBytes)
- (BOOL)toEqualByBytes:(UIImage *)otherImage {
@cppforlife
cppforlife / gist:1175046
Created August 27, 2011 05:52
Reset NSNotificationCenter
// Useful in specs for debugging ran away NSNotifications.
// This code should not be used in production!
// NSNotificationCenter source: http://svn.opengroupware.org/SOPE/releases/4.4rc.1-rock/libFoundation/Foundation/NSNotificationCenter.m
static NSNotificationCenter *otherDefaultCenter;
@interface NSNotificationCenter (Reset)
+ (void)reset;
@cppforlife
cppforlife / links
Created September 23, 2011 06:17
Useful links
@cppforlife
cppforlife / gist:1266570
Created October 6, 2011 05:13
Run OCUnit application tests from the command line
// Run application tests from the command line:
// xcodebuild -project project.xcodeproj -target projectTests -configuration Release -sdk iphonesimulator4.3 -arch i386 TEST_HOST= BUNDLE_LOADER= TEST_AFTER_BUILD=YES build
// (How to set up: http://pivotallabs.com/users/dmitriy/blog/articles/1879-run-ocunit-application-tests-from-the-command-line)
#import <SenTestingKit/SenTestingKit.h>
#import <objc/runtime.h>
@implementation NSBundle (MainBundleHijack)
static NSBundle *mainBundle__ = nil;
@cppforlife
cppforlife / gist:1269501
Created October 7, 2011 05:09
objective-c debugging env variables
[schwa@ungoliant] ~$ export OBJC_HELP=1
[schwa@ungoliant] ~$ /Applications/Safari.app/Contents/MacOS/Safari
objc[10559]: Objective-C runtime debugging. Set variable=YES to enable.
objc[10559]: OBJC_HELP: describe available environment variables
objc[10559]: OBJC_PRINT_OPTIONS: list which options are set
objc[10559]: OBJC_PRINT_IMAGES: log image and library names as they are loaded
objc[10559]: OBJC_PRINT_LOAD_METHODS: log calls to class and category +load methods
objc[10559]: OBJC_PRINT_INITIALIZE_METHODS: log calls to class +initialize methods
objc[10559]: OBJC_PRINT_RESOLVED_METHODS: log methods created by +resolveClassMethod: and +resolveInstanceMethod:
objc[10559]: OBJC_PRINT_CLASS_SETUP: log progress of class and category setup
@cppforlife
cppforlife / FakeRunLoop.h
Created November 9, 2011 08:21
FakeRunLoop class useful in specs when code under test relies on NSRunLoop
#import <Foundation/Foundation.h>
typedef void(^VoidBlock)(void);
@interface FakeRunLoop : NSObject
+ (void)run:(VoidBlock)block;
@end
@cppforlife
cppforlife / gist:3731520
Created September 16, 2012 08:09
log all notifications going through NSNotificationCenter
void MyCallBack (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
NSLog(@"---\n name: %@\n info: %@", name, userInfo);
}
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), NULL, MyCallBack, NULL, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
@cppforlife
cppforlife / gist:3731529
Created September 16, 2012 08:12
menu items for NSApp
- (void)_listMenuItems {
NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
for (NSMenuItem *item in [mainMenu itemArray]) {
NSLog(@"Menu %@:", [item title]);
for (NSMenuItem *subitem in [item.submenu itemArray]) {
NSLog(@"\t%@\n\t\t%@ - %@ - %@\n",
[subitem title],
NSStringFromSelector([subitem action]),
subitem.target,