Skip to content

Instantly share code, notes, and snippets.

View aidano's full-sized avatar

Aidan O'Loan aidano

  • USA, N.Ireland
View GitHub Profile
@mxriverlynn
mxriverlynn / 1-ModelWithChangedEvents.js
Created June 15, 2011 03:12
simple backbone.js examples
var SomeModel = Backbone.Model.extend({});
someModel = new SomeModel();
someModel.bind("change", function(model, collection){
alert("You set some_attribute to " + model.get('some_attribute'));
});
someModel.set({some_attribute: "some value"});
@chrishulbert
chrishulbert / uibutton_on_uitoolbar.m
Created May 30, 2011 04:48
Putting a UIButton on a UIToolbar
UIButton *myBn = [UIButton buttonWithType:UIButtonTypeCustom];
[myBn setTitle:@"Blah" forState:UIControlStateNormal];
myBn.frame = CGRectMake(0, 0, 100, 44);
[myBn addTarget:self action:@selector(myBnWasClicked:) forControlEvents:UIControlEventTouchUpInside];
myBn.titleLabel.font = [UIFont fontWithName:@"Some Font" size:16];
[myBn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
myBn.showsTouchWhenHighlighted = YES;
UIBarButtonItem *myBbi = [[[UIBarButtonItem alloc] initWithCustomView:sortCustomButton] autorelease];
@chrishulbert
chrishulbert / SizableImageCell.m
Created April 21, 2011 06:18
Make a UITableViewCell with a resized image
@interface SizableImageCell : UITableViewCell {}
@end
@implementation SizableImageCell
- (void)layoutSubviews {
[super layoutSubviews];
float desiredWidth = 80;
float w=self.imageView.frame.size.width;
if (w>desiredWidth) {
float widthSub = w - desiredWidth;
@chrishulbert
chrishulbert / buildquerystring.m
Created April 13, 2011 02:17
Build a url query string in obj-c from a dictionary of params like jquery does
+(NSString*)urlEscape:(NSString *)unencodedString {
NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8);
return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it
}
// Put a query string onto the end of a url
@chrishulbert
chrishulbert / radial.m
Created April 11, 2011 23:08
Rendering a radial gradient on the iphone
- (UIImage *)radialGradientImage:(CGSize)size start:(float)start end:(float)end centre:(CGPoint)centre radius:(float)radius {
// Render a radial background
// http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html
// Initialise
UIGraphicsBeginImageContextWithOptions(size, YES, 1);
// Create the gradient's colours
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };