Skip to content

Instantly share code, notes, and snippets.

View maxchuquimia's full-sized avatar

Max Chuquimia maxchuquimia

  • Sydney, Australia
View GitHub Profile
@maxchuquimia
maxchuquimia / sprite-collisions.mm
Last active August 29, 2015 14:00
Cocos2D/Box2D/LevelHelper Manual Collision Detection
/* Put this in a subclass of LHSprite!
* Then, in your layer's update: method you can check if a sprite is touching another sprite:
* [mySpriteClassInstance isCollidedWithSprite:anotherSprite];
*/
- (BOOL)isCollidedWithSprite:(LHSprite *)spriteB
{
BOOL isTouching = FALSE;
for (b2Fixture *fA = self.body->GetFixtureList(); fA; fA = fA->GetNext())
@maxchuquimia
maxchuquimia / qt_convert.applescript
Created October 4, 2014 07:12
A script that literally uses QuickTime to convert videos
-- commandline `avconvert` didn't want to work and I was desperate, so I wrote this.
-- Use it at your own risk
-- Do what you want with it
tell application "Finder" to set chosenFiles to every file of (choose folder)
repeat with aFile in chosenFiles
-- Change to suit your extension
if name of aFile ends with ".MPG" then
@maxchuquimia
maxchuquimia / keyboard-extension
Created November 13, 2014 20:52
Print personal information as a list on a custom keyboard
[self requestSupplementaryLexiconWithCompletion:^(UILexicon *lex){
NSMutableString *s = [NSMutableString new];
for (UILexiconEntry *e in lex.entries)
{
[s appendFormat:@"%@ -> %@\n", e.userInput, e.documentText];
}
dispatch_async(dispatch_get_main_queue(), ^{
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.text = s;
[self.view addSubview:textView];
@maxchuquimia
maxchuquimia / NSUserDefaults+Extension.h
Last active August 29, 2015 14:09
iOS - Handy way to run a code block once, based on dispatch_once()
#import <Foundation/Foundation.h>
@interface NSUserDefaults (Extension)
/*!
* Associates a block of code with a token. If the token has not been used the code block will run immediately.
*
* @param token A token unique to the code block
* @param block A block of code to run
*
@maxchuquimia
maxchuquimia / gist:e227234bd77db0808fa2
Last active August 29, 2015 14:16
Determine Portrait or Landscape from iOS Extension
//This is currently working in my Keyboard Extension (not upside-down friendly)
- (BOOL)isPortrait {
CGFloat portraitWidth = [[UIScreen mainScreen] nativeBounds].size.width/[UIScreen mainScreen].scale;
CGFloat thisWidth = [[UIScreen mainScreen] bounds].size.width;
return portraitWidth == thisWidth;
}
@maxchuquimia
maxchuquimia / audiostream.m
Last active August 29, 2015 14:17
Because sometimes you don't want to tab to iTunes when you're listening to a stream.
//gcc -o audiostream audiostream.m -framework Foundation -framework AppKit -framework AVFoundation
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AppKit/AppKit.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
@maxchuquimia
maxchuquimia / toDict.swift
Created September 29, 2015 04:05
Map an array into a dictionary with Swift 2.0
extension Array {
/*!
Convert an array to a dictionary of two of it's element's properties
- parameter f: the parse block
- returns: a dictionary of the type of the tuple returned by the parse block
*/
func toDict<K, V>(f: (Element -> (K, V))) -> [K: V] {
@maxchuquimia
maxchuquimia / GTINCalculator.swift
Created October 23, 2015 08:51
Swiftly calculates a check-digit for GTIN-8, GTIN-12, GTIN-13, GTIN-14 and SSCC codes.
import Foundation
@objc class GTINCalculator: NSObject {
/*!
An exception thrown when there is a calculation error
- BadDigit: a substring of the input string could not be read as an `Int`
*/
enum GTINCalculatingError: ErrorType {
@maxchuquimia
maxchuquimia / download-classic.sh
Created November 29, 2015 11:15
Downloads audio from an m3u8 index (protip: works with ABC "Listen Later")
#!/bin/bash
INDEX=$1
if [ -z "${INDEX}" ]
then
echo "Sample usage: \`bash $0 http://abcradiomodhls.abc-cdn.net.au/i/classic/audio/srl-2015-11-22.m4a/index_0_a.m3u8\`"
echo "You can find the location of the index.m3u8 file by viewing requests made by your browser "
exit 1
fi
@maxchuquimia
maxchuquimia / broken.swift
Last active January 12, 2016 00:59
Things that don't work in Swift but should
//MARK: instancetype
//Xcode 7A176x
extension UIViewController {
class func fromStoryboard(named name: String) -> Self {
let storyboard = UIStoryboard(name: name, bundle: NSBundle.mainBundle())
let classname = NSStringFromClass(self) as NSString //Error: Type 'Self" does not conform to protocol 'AnyObject'
return storyboard.instantiateViewControllerWithIdentifier(classname.pathExtension)
}
}