Skip to content

Instantly share code, notes, and snippets.

View Pretz's full-sized avatar

Alex Pretzlav Pretz

View GitHub Profile
@Pretz
Pretz / static_const.m
Created October 9, 2013 22:33
C macro for creating handy static constants in obj-c. Is this a bad or good idea?
#define STATIC_CONST(name) static NSString * const name = @#name;
STATIC_CONST(LearningNavRestorationIdentifier)
STATIC_CONST(ProfileNavRestorationIdentifier)
STATIC_CONST(ReservationsNavRestorationIdentifier)
#undef STATIC_CONST
// Becomes:
@Pretz
Pretz / bluetoot.py
Last active December 24, 2015 08:49
Reads the blutooth link key from the windows registry for a given paired bluetooth device (specified via MAC). Useful for multi-pairing with OS X and Loonix.
import winreg
import itertools
import binascii
import array
def hexlify(_bytes, reverse=True):
a = array.array('b', _bytes)
if swap:
a.reverse()
return binascii.hexlify(a.tobytes()).decode('utf-8')
@Pretz
Pretz / dynamictype.swift
Created December 21, 2015 02:58
Example of using `===` to compare Types in Swift
class Obj {}
class Obj2: Obj {}
let item1 = Obj(), item2 = Obj2()
if item1.dynamicType === item2.dynamicType {
print("Same subclass")
} else {
print("Different subclass")
}
+ (NSDateFormatter *)dateFormatter {
return [[ISO8601DateFormatter alloc] init];
}
+ (NSValueTransformer *)jsonDateValueTransformer {
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSString *str) {
return [self.dateFormatter dateFromString:str];
} reverseBlock:^(NSDate *date) {
return [self.dateFormatter stringFromDate:date];
}];
@Pretz
Pretz / comprehension.m
Last active December 20, 2015 05:59
draft of a dictionary comprehension idea for obj-c: generating dictionaries over collections using simple-ish block syntax.
- (NSDictionary *)dictionaryOfPeople:(NSArray *)people {
return [people dictionaryViaEnumeration:^(Person *person, id *key, id *value) {
*key = person.identifier;
*value = person.name;
}];
}
////////////////////
typedef void (^TransformBlock)(id obj, id *key, id *value);
@Pretz
Pretz / genstrings
Created March 18, 2013 16:38
Apparently Apple doesn't understand how command line arguments work
alex@alex-silvercar:~/dev/mobile/driverapp/driverapp $ genstrings --help
alex@alex-silvercar:~/dev/mobile/driverapp/driverapp $ genstrings -h
alex@alex-silvercar:~/dev/mobile/driverapp/driverapp $ genstrings -help
alex@alex-silvercar:~/dev/mobile/driverapp/driverapp $ genstrings
Usage: genstrings [OPTION] file1.[mc] ... filen.[mc]
Options
-j sets the input language to Java.
-a append output to the old strings files.
-s substring substitute 'substring' for NSLocalizedString.
collisionMatrix = new boolean[160][90];
Pixmap backgroundMap = new Pixmap(Gdx.files.internal("data/warehouse-map.png"));
for (int y = 0; y < 90; y++) {
for (int x = 0; x < 160; x++) {
// Get the pixel, shifting off the alpha value
int pixel = backgroundMap.getPixel(x, y) >>> 8;
if (pixel == 0x000000) {
// true means impassible, also invert y to match our coordinate system
collisionMatrix[x][90 - y] = true;
}
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar (160 KB at 125.9 KB/sec)
[INFO] Compiling 11 source files to /home/alex/apk2gold/jd-cli/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.568s
[INFO] Finished at: Fri Jan 25 15:58:50 CST 2013
[INFO] Final Memory: 10M/115M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project jd-core-java: Compilation failure: Compilation failure:
@Pretz
Pretz / controller-sample.java
Last active December 11, 2015 06:58
samples for a blog post on LibGDX programming targeting OUYA
public class Cursor {
public static float DEFAULT_VELOCITY = 500f;
private final Vector2 position;
public final Vector2 velocity;
public Cursor() {
position = new Vector2(0, 0);
velocity = new Vector2(0, 0);
@Pretz
Pretz / keyboardInfoFromNotification.swift
Last active December 9, 2015 21:41
Gets the info from a UIKeyboardWill(Show/Hide)Notification and returns it in a not-terrible tuple
public func keyboardInfoFromUserInfo(userInfo: [NSObject: AnyObject]) -> (beginFrame: CGRect, endFrame: CGRect, animationCurve: UIViewAnimationOptions, animationDuration: Double)? {
if let beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue,
let endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue,
let animationCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber,
let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber {
return (
beginFrame: beginFrameValue.CGRectValue(),
endFrame: endFrameValue.CGRectValue(),
animationCurve: UIViewAnimationOptions(rawValue: animationCurve.unsignedIntegerValue << 16),
animationDuration: animationDuration.doubleValue)