Skip to content

Instantly share code, notes, and snippets.

View davidahouse's full-sized avatar

David House davidahouse

View GitHub Profile
@davidahouse
davidahouse / gist:3609804
Created September 3, 2012 14:42
UITableView Simple DataSource & Delegate
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
@davidahouse
davidahouse / gist:4565554
Created January 18, 2013 15:56
dispatch_once to run a block of code only one time ever
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// your code here
});
@davidahouse
davidahouse / gist:4565614
Created January 18, 2013 16:04
singleton using dispatch_once
+ (<class> *)shared<whatever> {
static <class> *shared<class> = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared<class> = [[self alloc] init];
});
return shared<class>;
}
@davidahouse
davidahouse / gist:5477208
Created April 28, 2013 15:25
Upload an image using Rails & Parse
# Add image field to model
# fields :title, :some_image_field
# Create a form for uploading the image
<%= form_tag({ :action => :upload_image_save}, :multipart => true) do %>
<%= file_field_tag 'image' %>
<div class="actions">
<%= submit_tag %>
</div>
# This is a sample command for compiling a swift file that requires an external framework.
#
#
#
xcrun swift -i swifthello.swift -framework DHTest2 -F /Users/davidahouse/Projects/swift -sdk $(xcrun --show-sdk-path --sdk macosx)
@davidahouse
davidahouse / gist:3eb5e9dd8bb08972b53a
Created June 21, 2014 21:55
Proposed tag syntax for DHStyleString
//
// Basic replacement of a variable with no specified style attribute
// #{field}
//
// Replacement with variable and style
// #{field:style}
//
// Push a style on the stack
// #{+style}
//
@davidahouse
davidahouse / gist:3269f60fe9a9d17649ce
Last active August 29, 2015 14:02
Playing around with Swift and subscripts
import UIKit
extension Array {
subscript(index:Int,defaultValue def:T) -> T {
if ( (0 <= index) && (index < self.count) ) {
return self[index]
}
else {
return def
@davidahouse
davidahouse / gist:783254e6861f87003548
Created May 17, 2015 20:03
NSPathControlItem weirdness
import Cocoa
import AppKit
let item1 = NSPathControlItem()
item1.title = "This is the title"
let title1 = item1.title
@davidahouse
davidahouse / gist:17f352dfae023e6f337a
Created June 14, 2015 01:31
Trying out arrays filled with things conforming to a Protocol
//: Playground demonstrating how to deal with an Array containing items that conform
//: to a protocol.
import Cocoa
/*:
Just a basic protocol with a single function that has to be implemented.
*/
protocol Nameable {
@davidahouse
davidahouse / Person.swift
Created July 22, 2015 17:13
Simple NSCoding with Swift example, using enum & rawValue for the key names.
@objc(Person)
final public class Person : NSCoding {
public var firstName:String
public var lastName:String
private enum SerializationKeys : String {
case FirstName
case LastName
}