Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
codeswimmer / git_reset2head_recursive
Created November 18, 2011 19:11
git: recursively reset a git submodule hierarchy to HEAD
git submodule foreach git submodule init && git submodule update --recursive
@codeswimmer
codeswimmer / gist:1427977
Created December 3, 2011 19:59
iOS: segue connection checklist
Here’s a handy checklist for setting up the connections between two scenes:
1. Create a segue from a button or other control on the source scene to the destination scene.*
2. Give the segue a unique Identifier.It only has to be unique in the source scene
different scenes can use the same identifier.
3. Create a delegate protocol for the destination scene.
4. Call the delegate methods from the Cancel and Done buttons**
@codeswimmer
codeswimmer / iOS_mirror_image.m
Created December 17, 2011 17:56
iOS: mirror an image
-(UIImage *)makeMirroredImage:(UIImage *)image
{
UIImageOrientation flippedOrientation = UIImageOrientationUpMirrored;
switch (image.imageOrientation) {
case UIImageOrientationDown:
flippedOrientation = UIImageOrientationDownMirrored;
break;
case UIImageOrientationLeft:
flippedOrientation = UIImageOrientationLeftMirrored;
break;
@codeswimmer
codeswimmer / gist:1490890
Created December 17, 2011 18:03
iOS_tip: Use CGAffineTransform, not CGAffineTransformMake
for example,
CGAffineTransformScale, not CGAffineTransformMakeScale
CGAffineTransformRotate, not CGAffineTransformMakeRotate
CGAffineTransformTranslate, not CGAffineTransformMakeTranslate
"""
This provides a simple implementation of the 'Chaocipher' encryption
algorithm described at:
http://www.ciphermysteries.com/2010/07/03/the-chaocipher-revealed
Example usage:
import chaocipher
sender = chaocipher.Wheels(CtWheel='QYNBOWTGIRJFEPKLSDMAVZCUXH', PtWheel='JGUACNQLTDHKSOPZFYMXWRVEBI')
receiver = chaocipher.Wheels(CtWheel='QYNBOWTGIRJFEPKLSDMAVZCUXH', PtWheel='JGUACNQLTDHKSOPZFYMXWRVEBI')
cyphertext = sender.encipher("Green eggs and spam")
@codeswimmer
codeswimmer / chaocipher.perl
Created December 17, 2011 22:12
perl: Chaocipher
# ChaoSim.pl : Simulation of Chaocipher enciphering/deciphering
# (c) Moshe Rubin, August 2010
# email: mosher@mountainvistasoft.com
use strict;
use diagnostics;
use warnings;
my $left = uc($ARGV[1]);
my $right = uc($ARGV[2]);
my $mode = $ARGV[3];
@codeswimmer
codeswimmer / ios_get_bytes_from_image.m
Created December 19, 2011 16:56
iOS: How to get bytes from an image
CGDataRef imageDataRef = CGDataProviderCopyData(CGImageGetDataProvider(myCGImageRef)));
// CGDataProviderCopyData copies underlying bytes
@codeswimmer
codeswimmer / ios_draw_shadowed_text.m
Created December 19, 2011 17:02
iOS: How to draw shadowed text
// How to draw shadowed text
// color = [[UIColor orangeColor] CGColor]; best to cache this
CGContextSaveGState(context);
CGFloat shadowHeight = 2.0;
CGContextSetShadowWithColor(context, CGSizeMake(1.0, -shadowHeight), 0.0, <color>);
[<string>, drawInRect:<rect> withFont:<font>];
CGContextRestoreGState(context);
@codeswimmer
codeswimmer / ios_coreanimation_eggs.m
Created January 7, 2012 20:44
iOS: Core Animation Example: eggs falling out of a tree
// Core Animation Example: eggs falling out of a tree
// This was glommed from iphonedevsdk: http://www.iphonedevsdk.com/forum/iphone-sdk-development/65632-animation-sample-code-our-newest-app.html
// This is the main animation routine.
- (IBAction) doorEasterEggAction;
{
//treeDoorImageView
CATransform3D theTransform;
UIImageView* anEgg;
@codeswimmer
codeswimmer / ios_random_nonrepeating_text.m
Created January 7, 2012 20:49
iOS: Generating random, non-repeating text
// iOS: Generating random, non-repeating text
/*
Selects random words or phrases from an array, and only select any given word/phrase once.
To use it:
-Create a file called words.txt containing a list of words or phrases separated by carriage returns.
-Drag that file into the resources portion of your project, so it will be included in the bundle.
-Call [self buildRandomWordArray] to do the initial setup. That reads the file and populates an array of random indexes.