Skip to content

Instantly share code, notes, and snippets.

View hezi's full-sized avatar

Jorge (Hezi) Cohen hezi

View GitHub Profile
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@jbenet
jbenet / simple-git-branching-model.md
Last active April 9, 2024 03:31
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@tonymillion
tonymillion / gist:6716935
Last active June 6, 2018 08:37
force decoding of UIImage on load on iOS7 (so it can be done on a background thread not the UI thread).
+(UIImage*)immediateImageWithData:(NSData*)data
{
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (__bridge CFDictionaryRef)@{(id)kCGImageSourceShouldCacheImmediately: (id)kCFBooleanTrue});
UIImage *temp = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CFRelease(source);
@alanzeino
alanzeino / Strong UINavigationBar colour
Last active April 26, 2020 23:34
Combining a strong colour with a blurred and translucent UINavigationBar in iOS 7.
// cheers to @stroughtonsmith for helping out with this one
UIColor *barColour = [UIColor colorWithRed:0.13f green:0.14f blue:0.15f alpha:1.00f];
UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];
colourView.opaque = NO;
colourView.alpha = .7f;
colourView.backgroundColor = barColour;
self.navigationBar.barTintColor = barColour;
@steipete
steipete / UIKitLegacyDetector.m
Last active March 12, 2024 13:57
A simple way to detect at runtime if we're running in UIKit legacy mode or the new "flat" variant. Written for our PDF iOS SDK (http://pspdfkit.com), where the precompiled binary needs to detect at runtime in what variant it's running. Want more stuff like that? Follow me on Twitter: http://twitter.com/steipete
// Taken from http://PSPDFKit.com. This snippet is under public domain.
#define UIKitVersionNumber_iOS_7_0 0xB57
BOOL PSPDFIsUIKitFlatMode(void) {
static BOOL isUIKitFlatMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// We get the modern UIKit if system is running >= iOS 7 and we were linked with >= SDK 7.
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
isUIKitFlatMode = (NSVersionOfLinkTimeLibrary("UIKit") >> 16) >= UIKitVersionNumber_iOS_7_0;
}
@enaeseth
enaeseth / objectid_to_uuid.py
Created June 12, 2013 19:29
Convert a MongoDB ObjectID to a valid, semantically similar UUID.
"""
Convert a MongoDB ObjectID to a version-1 UUID.
Python 2.7+ required for datetime.timedelta.total_seconds().
ObjectID:
- UNIX timestamp (32 bits)
- Machine identifier (24 bits)
- Process ID (16 bits)
- Counter (24 bits)
@ryankennedy
ryankennedy / asmifier.c
Last active January 4, 2017 13:27
Quickly creating a command line utility to run ASMifier (http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/util/ASMifier.html).
#include <stdio.h>
#include <errno.h>
int main(int argc, char* argv[]) {
int i;
char* argv2[argc+3];
argv2[0] = "java";
argv2[1] = "-cp";
argv2[2] = argv[0];
argv2[3] = "org.objectweb.asm.util.ASMifier";
@boredzo
boredzo / PRHOverlayLayer.m
Created May 9, 2013 01:31
Method that implements Python-style string formatting in NSString.
//Formats a string in which format specifiers look like %(key)@, similar to Python's %(key)s.
//Currently does not work with any other specifiers (i/d/u/x/f/g/e/s/c/C) or formatting guidance (space-padding, justification, etc.), and probably will never allow mixing positional and keyed format specifiers, just as Python doesn't.
- (NSString *) stringWithFormat:(NSString *)format values:(NSDictionary *)values {
NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"%\\(([a-z_][a-z0-9_]*)\\)@"
options:NSRegularExpressionCaseInsensitive
error:NULL];
NSMutableString *resultString = [NSMutableString stringWithCapacity:format.length
+ [[[values allValues] valueForKeyPath:@"@sum.length"] unsignedIntegerValue]];
__block NSRange rangeSinceLastMatch = { 0, 0 };
@beaufour
beaufour / todo-check.py
Created April 2, 2013 13:39
Git commit hook to check for lines with "TODO" in them
#!/usr/bin/python
import logging
import re
import sys
import envoy
def _exec_git(cmd, args=''):
cmd = 'git {0} --color=never {1}'.format(cmd, args)
@steipete
steipete / gist:4233987
Created December 7, 2012 15:32
Print a CGPath
extern void CGPathPrint(CGPathRef path, FILE* file);
CGPathPrint(path.CGPath, NULL);
Path 0xb44e380:
moveto (-12, 295)
lineto (115, 295)
lineto (108, -12)
lineto (235, -12)