Skip to content

Instantly share code, notes, and snippets.

View jinthagerman's full-sized avatar

Jin Budelmann jinthagerman

View GitHub Profile
@jinthagerman
jinthagerman / silly
Last active August 29, 2015 14:05
My GOTO moment
if (isSometimesTrue) {
// Sometimes do something
} if (isAlsoSometimesTrue) {
// Sometimes do something else
} else {
// Only do if others fail, but is instead always executed.
}
@jinthagerman
jinthagerman / gist:bcb00f95ebf5adb9e5aa
Created February 9, 2015 20:57
Unannotated single-expression closures with non-Void return types can now be used in Void contexts
// This
self.label.snp_makeConstraints { make in
make.edges.equalTo(self.view)
}
// Instead of this
self.label.snp_makeConstraints { make in
make.edges.equalTo(self.view)
return
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.vendhq.ci</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-Djava.awt.headless=true</string>
@jinthagerman
jinthagerman / UIColor+Addition.m
Created May 16, 2012 05:26
UIColor from hex
// http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
+ (UIColor *) colorWithHex:(int)hex {
return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0
green:((float)((hex & 0xFF00) >> 8))/255.0
blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
}
@jinthagerman
jinthagerman / IMDB250TallyDirectors.py
Created August 3, 2012 05:03
Find the directors with the most movies in the IMDB top 250
#!/usr/bin/env python
# encoding: utf-8
"""
IMDB250TallyDirectors.py
Created by Jin Budelmann on 2012-08-03.
"""
import sys
import os
@jinthagerman
jinthagerman / IMDB250TallyDirectors.py
Created August 3, 2012 05:04
Find the directors with the most movies in the IMDB top 250
#!/usr/bin/env python
# encoding: utf-8
"""
IMDB250TallyDirectors.py
Created by Jin Budelmann on 2012-08-03.
"""
import sys
import os
@jinthagerman
jinthagerman / gist:3815780
Created October 2, 2012 02:13
Singletons
@implementation MySingleton
+ (MySingleton*)singleton {
static MySingleton* __singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__singleton = [[MySingleton alloc] init];
});
return __singleton;
}
@jinthagerman
jinthagerman / APMacros.h
Created November 22, 2012 22:49
Simply create associated property with one line of code using a reusable preproc macro
#import <objc/runtime.h>
#define ASSOCIATIVE_PROPERTY(GET_NAME, SET_NAME, TYPE, ASSOCIATION_POLICY) \
static char GET_NAME##Key; \
- (TYPE) GET_NAME \
{ \
return objc_getAssociatedObject(self, & GET_NAME##Key); \
} \
\
- (void) SET_NAME:(TYPE)value\
@jinthagerman
jinthagerman / gist:4133720
Created November 23, 2012 02:15
Simplify ratio
int n1 = 320;
int n2 = 480;
simplifyRatio(&n1, &n2);
printf("%d %d", &n1, &n2);
int highestCommonFactor(int n1, int n2) {
int remainder = n1%n2;
@jinthagerman
jinthagerman / gist:4209797
Created December 4, 2012 22:49
Atrocity
//receive loop(timeout=1000ms)
long long starttime = [self currentTimeMillis];
while(true){
//timeout check
long long readTimeout = SEND_RESPONSE_TIMEOUT - ([self currentTimeMillis] - starttime);
if(readTimeout < 0){
break;
}