Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
codeswimmer / gist:3129509
Created July 17, 2012 13:55 — forked from harichinthalapale/gist:3129471
Right align view
CGRect _f = CGRectMake(0, 0, 200, 200);
CGFloat xPosition = CGRectGetWidth(self.view.frame) - CGRectGetWidth(_f);
_f.origin = CGPointMake(ceil(xPosition), 0.0);
@codeswimmer
codeswimmer / NSNumber+Ranges.m
Created July 22, 2012 02:31 — forked from pcperini/NSNumber+Ranges.m
Quick Ranges from NSNumbers
// .h
@interface NSNumber (Ranges)
- (NSRange)to:(NSNumber *)rangeEnd;
- (BOOL)isInRange:(NSRange)range;
@end
// .m
@implementation NSNumber (Ranges)
@codeswimmer
codeswimmer / DebugAlert.h
Created July 24, 2012 01:01 — forked from chunkyguy/DebugAlert.h
Debugging with UIAlertViews
#define POP_ALERT(title, msg) [[[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]autorelease] show]
/*
Usage:
POP_ALERT(@"Title Here", @"Message Here");
*/
@codeswimmer
codeswimmer / fun.m
Created August 4, 2012 21:28 — forked from evanlong/fun.m
ParticleFun
- (void)viewDidLoad {
[super viewDidLoad];
UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 200.0f, 200.0f)];
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
emitterLayer.emitterSize = CGSizeMake(20.0f, 20.0f);
emitterLayer.emitterPosition = CGPointMake(90.0f, 90.0f);
@codeswimmer
codeswimmer / save_cancel_toolbar.rb
Created August 12, 2012 17:15 — forked from sxross/save_cancel_toolbar.rb
UIToolbar Subclass to Include Save and Done Buttons
class SaveCancelToolbar < UIToolbar
attr_writer :delegate
def initWithFrame frame, andTitle: title
super
items = []
spacer = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, target:nil, action:nil)
@cancel_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemCancel, target:self, action:'on_cancel:')
@codeswimmer
codeswimmer / gist:3333522
Created August 12, 2012 18:11
Check for multiple assignment to an ivar
NSString *const ASMultipleAssignmentException = @"Multiple Assignment Exception";
#ifndef CHECK_FOR_MULTI_ASSIGN
#define CHECK_FOR_MULTI_ASSIGN(ivar) \
do { \
if (ivar) { \
NSString *AS_reason = @"Cannot assign to " #ivar " more than once"; \
@throw [NSException exceptionWithName:ASMultipleAssignmentException \
reason:AS_reason \
userInfo:nil]; \
@codeswimmer
codeswimmer / accelerometer.ino
Created August 12, 2012 18:38 — forked from tlevine/accelerometer.ino
Basic accelerometer CSV output
#include <Time.h>
/*
I have an accelerometer plugged into pins A0, A1 and A2 of an Arduino,
and I'm writing a CSV file (well the line breaks are wrong) to serial.
It depends on the time library (http://www.arduino.cc/playground/Code/Time),
which you install by extracting the download in the arduino `libraries`
directory and restarting arduino. (This actually provides three libraries.)
@codeswimmer
codeswimmer / save_cancel_toolbar.rb
Created August 12, 2012 18:41 — forked from sxross/save_cancel_toolbar.rb
UIToolbar Subclass to Include Save and Done Buttons
class SaveCancelToolbar < UIToolbar
attr_writer :delegate
def initWithFrame frame, andTitle: title
super
items = []
spacer = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, target:nil, action:nil)
@cancel_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemCancel, target:self, action:'on_cancel:')
@codeswimmer
codeswimmer / DE12_800px_infographic.html
Created August 13, 2012 11:56
Developer Economics 2012 - The Rise of the New App Economy - 800px infographic
<p><a href="http://www.visionmobile.com/blog/2012/08/the-rise-of-the-new-app-economy/" mce_href="http://www.visionmobile.com/blog/2012/08/the-rise-of-the-new-app-economy/"><img src="http://www.visionmobile.com/uploads/infographics/8/VMInfographic_DE12_800.png" mce_src="http://www.visionmobile.com/uploads/infographics/8/VMInfographic_DE12_800.png" border="0" alt="Developer Economics 2012 - The Rise of the New App Economy" /></a></p>
@codeswimmer
codeswimmer / zombie.c
Created August 13, 2012 20:51 — forked from akahn/zombie.c
Simulate a zombie process on Linux
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main ()
{
pid_t child_pid;
child_pid = fork ();
if (child_pid > 0) {