Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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