Skip to content

Instantly share code, notes, and snippets.

@commanda
commanda / lunar-lander-update.m
Created March 26, 2012 15:07
Fill in the blanks, Stevenson Symposium
-(void)update:(ccTime)dt
{
// Only run the update if we haven't already landed
if(!didLand)
{
// We accelerate downward at 10 pixels per second per second.
// "dt" stands for "delta time" is how much time has passed since the last time this function
// was called, so it's around 0.05 seconds
// Using our number 10, and our number dt, how do we create the value that we're going to
@commanda
commanda / gitlog.sh
Last active May 18, 2016 02:02
A bash script that opens the github.com commits page for the project you're sitting in (nicer than looking at git log)
#!/bin/bash
URL=`git config remote.origin.url`
# if its a git@, replace that with https://
URL=`echo $URL | sed -e "s/git@/https:\/\//g"`;
URL=`echo $URL | sed -e "s/com:/com\//g"`;
# remove the .git at the end
URL=`echo $URL | sed -e "s/.git$//g"`;
@commanda
commanda / gist:5053654
Last active December 14, 2015 07:49
Create a proportional S-shaped bezier curve between any two points. Objective-C, Cocos2d, iOS.
-(ccBezierConfig)bezierForStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint curviness:(CGFloat)alpha
{
CGPoint basis1 = ccpLerp(startPoint, endPoint, 0.3333);
CGPoint basis2 = ccpLerp(startPoint, endPoint, 0.6666);
// Get a point on the perpendicular line of each of the control points
CGPoint vector = ccpSub(endPoint, startPoint);
// First point is to the right, second is to the left, of the line between the start point and end point
CGPoint v1 = ccpRPerp(vector);
@commanda
commanda / gist:5069840
Created March 2, 2013 05:33
How to select the target for invoking an IMP of a super class?
-(IBAction)cancelPressed:(id)sender
{
void (^onComplete)(void) = ^{
IMP superCancelPressed = class_getMethodImplementation([MCDialogView class], @selector(cancelPressed:));
superCancelPressed(<what goes here?>, @selector(cancelPressed:), nil);
//[super cancelPressed:sender];
};
//...
@commanda
commanda / del
Last active May 18, 2016 01:02
A bash script that moves the given file or directory into the Trash.
#!/bin/sh
TRASH="$HOME/.Trash/";
args=("$@");
for f in $args; do
base=$(basename $f);
if [ -e "$TRASH$base" ] ; then
TS=`date`;
@commanda
commanda / timey
Created April 27, 2016 19:52
a bash script that i use to tell me to get back to work after a set number of minutes
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "usage: timey <number of minutes> &";
exit;
fi
SECONDS=$(($1 * 60))
echo "Timey set for $1 minutes, which is $SECONDS seconds"
sleep $SECONDS
open -a "Google Chrome.app" https://media.giphy.com/media/yWh7b6fWA5rJm/giphy.gif
@commanda
commanda / gist:250419ae9b386fa05e47bc38d3931507
Created May 30, 2016 20:55
A recursive block in Objective-C
- (void)runRecursiveBlock
{
void(^ completionBlock) ();
void(^ __block __weak weakCompletionBlock) ();
weakCompletionBlock = completionBlock = ^{
NSLog(@"%@", NSStringFromSelector(_cmd));
void(^ strongCompletionBlock)() = weakCompletionBlock;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
strongCompletionBlock();
});
@commanda
commanda / gist:62cd8bd1928306329b5e3fe02edd51ef
Created June 2, 2016 16:18 — forked from quietcricket/gist:1593632
Fuzzy string match objective-c (Levenshtein Distance Algorithm)
-(float)compareString:(NSString *)originalString withString:(NSString *)comparisonString
{
// Normalize strings
[originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[comparisonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
originalString = [originalString lowercaseString];
comparisonString = [comparisonString lowercaseString];
// Step 1 (Steps follow description at http://www.merriampark.com/ld.htm)
@commanda
commanda / _clang_format
Last active June 26, 2016 07:08
My _clang_format file for formatting Objective-C code
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
@commanda
commanda / traverse.py
Created July 27, 2016 15:48
traverse a json-esque structure in python
def value_generator(data):
if isinstance(data, dict):
for key, value in data.iteritems():
for element in value_generator(value):
yield element
elif isinstance(data, list):
for sublist in data:
for element in value_generator(sublist):
yield element
else: