Skip to content

Instantly share code, notes, and snippets.

@wess
wess / gist:1949952
Created March 1, 2012 13:53
Macro for Singleton with GCD
#define SINGLETON(classname) \
+(classname *)instance { \
static dispatch_once_t onetime; \
static classname *shared = nil; \
dispatch_once(&onetime, ^{ \
shared = [[classname alloc] init]; \
}); \
return shared; \
}
@blakewatters
blakewatters / gist:1994289
Created March 7, 2012 16:44
iOS 5 Interface Builder, View Controller and ARC Best Practices

Now that the GateGuru team has been developing on the iOS 5 SDK for awhile, I thought I'd pull together some lessons learned.

  • Declare your IBOutlet and IBActions within the private category within your implementation file. This makes them visible to interface builder without cluttering up the external interfaces and leaking implementation details.
  • Declare your IBOutlet properties as (nonatomic, weak). The weak reference implies a non-owning reference and ARC will nil it as necessary.
  • Delegate properties should be (nonatomic, weak) as well.
  • The designated initializer for UIView's is initWithFrame: when initialized programmatically. When loaded from a Storyboard or custom Nib, it is initWithCoder:
  • The designated initializer for UIViewController's is initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil when initialized programmatically. It is initWithCoder: when loaded from a Storyboard or Nib.
@zbowling
zbowling / gist:2356293
Created April 11, 2012 01:48
WWDC dates
Year Days Announcement Day Start of WWDC Venue
2012 ?? ????????? ??? 11-Jun-12??? Moscone West
2011 70 28-Mar-11 Mon 06-Jun-11 Moscone West
2010 40 28-Apr-10 Wed 07-Jun-10 Moscone West
2009 74 26-Mar-09 Thu 08-Jun-09 Moscone West
2008 88 13-Mar-08 Thu 09-Jun-08 Moscone West
2007 126 05-Feb-07 Mon 11-Jun-07 Moscone West
2006 153 07-Mar-06 Tue 07-Aug-06 Moscone West
2005 111 15-Feb-05 Tue 06-Jun-05 Moscone West
2004 123 26-Feb-04 Thu 28-Jun-04 Moscone West
@jboner
jboner / latency.txt
Last active May 13, 2025 17:54
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@motionbug
motionbug / gist:3085136
Created July 10, 2012 17:55 — forked from jamesez/gist:3085058
Build Chrome dmg
#!/bin/bash -ex
# Mount disk image on temp space
mountpoint=`hdiutil attach -mountrandom /tmp -nobrowse googlechrome.dmg | awk '/private\/tmp/ { print $3 } '`
echo Mounted on $mountpoint
# Determine version number
version=`defaults read "$mountpoint/Google Chrome.app/Contents/Info.plist" CFBundleShortVersionString`
echo Google Chrome version $version
window.onkeydown = function(event){
keyboard.press(event.keyCode);
}
}());
var $panes = $(".waypoint").length-1;
var $currentPane = $(".waypoint").first();
var keyboard = {
press:function(keycode){
console.log(keycode);
@kaorimatz
kaorimatz / tags-java.sh
Created July 10, 2012 18:01
Generate a cross reference for the maven project
#!/bin/sh
CSCOPE_OUT_DIR=$HOME/.cscope
CTAGS_OUT_DIR=$HOME/.tags
NAMEFILE=/tmp/java.files
if [ $# != 1 ]; then
echo "usega: $0 project_dir"
exit 1
fi;
@fousa
fousa / content.m
Created July 12, 2012 10:09
GCD Singleton
+ (MyClass *)sharedInstance {
static dispatch_once_t _predicate;
static MyClass *_sharedInstance = nil;
dispatch_once(&_predicate, ^{
_sharedInstance = [self new];
});
return _sharedInstance;
}
@jake7864
jake7864 / StopWatch.java
Created July 14, 2012 13:53
a small simple stop watch program, you specify a time and when started it will decrease the time by 1 a second
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@kenota
kenota / gist:3157873
Created July 22, 2012 01:33
builder vs buffer
package com.binarybuffer.test.bufferbuilder;
import org.apache.commons.math3.stat.descriptive.StatisticalSummary;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.junit.Test;
/**
* Unit test for simple App.