Skip to content

Instantly share code, notes, and snippets.

View atnan's full-sized avatar

Nathan de Vries atnan

View GitHub Profile
@atnan
atnan / CameraTestAppDelegate.h
Created June 15, 2009 10:53
Sample use of PLCameraController, with snapshots and video
#import <UIKit/UIKit.h>
@interface CameraTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
- (void) cameraControllerReadyStateChanged:(NSNotification*)aNotification;
- (void) cameraController:(id)sender tookPicture:(UIImage*)picture withPreview:(UIImage*)preview jpegData:(NSData*)rawData imageProperties:(struct __CFDictionary*) imageProperties;
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 \
green:((c>>16)&0xFF)/255.0 \
blue:((c>>8)&0xFF)/255.0 \
alpha:((c)&0xFF)/255.0];
UIColor* myColor = HEXCOLOR(0xff0000);
class Job < ActiveRecord::Base
STATUS_READY, STATUS_IN_PROGRESS, STATUS_DONE = 1, 2, 3
def self.fetch(pid)
update_all(
{ :status => STATUS_IN_PROGRESS,
:pid => pid },
{ :status => STATUS_READY },
{ :limit => 1,
def measure_time task_description
beginning = Time.now
yield
puts "Time to #{task_description}: #{Time.now - beginning} seconds"
end
def add a, i
a << i
end
dpkg --get-selections > packages.txt
dpkg --set-selections < packages.txt
apt-get dselect-upgrade
# Checking out
git svn init <svn url> <checkout directory>
git svn fetch
git repack -d
# Working
git checkout -b some-feature
git commit -a -m "Some feature"
# Commiting
@interface UIView (Debugging)
-(void)inspectWithDepth:(int)depth path:(NSString *)path;
@end
Finding the H.264 format of a Vimeo video:
1. Fetch the clip XML metadata (e.g. "http://vimeo.com/moogaloop/load/clip:5531123")
2. Grab the value of "request_signature" and "request_signature_expires" from the XML
3. Use the URL "http://vimeo.com/moogaloop/play/clip:5531123/REQUEST_SIG/REQUEST_SIG_EXPIRES/?q=hd"
@implementation NSArray(Filtering)
- (NSArray*)arrayByMappingArrayUsingSelector:(SEL)selector, ... {
NSInvocation* invocation;
va_list arguments;
if (selector && [self lastObject]) {
va_start(arguments, selector);
invocation = [NSInvocation invocationUsingSelector:selector onTarget:[self lastObject] argumentList:arguments];
va_end(arguments);
}
var ify = function() {
return {
"link": function(t) {
return t.replace(/(^|\s+)(https*\:\/\/\S+)/g, function(m, m1, link) {
return m1.concat('<a href="', link, '">', link.substr(0, 24), 25 < link.length ? '...' : '', '</a>');
});
},
"at": function(t) {
return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, ‘$1@<a href=”http://twitter.com/$2″>$2</a>’);
},