Skip to content

Instantly share code, notes, and snippets.

View alexeckermann's full-sized avatar

Alex Eckermann alexeckermann

View GitHub Profile
/*
Example custom UIView implementation
------------------------------------
Used as a custom UITableView header cell.
*/
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
userName = [[UILabel alloc] initWithFrame:CGRectMake(70, 16, (self.bounds.size.width - 70), 28)];
int (^minusOne)(int);
minusOne = ^(int myNumber) {
return myNumber - 1;
};
NSLog(@"%d", minusOne(3)); // Will print: 2
@alexeckermann
alexeckermann / AFTER_main.m
Created January 12, 2011 08:00
Before and after going XIB-less
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"LapTimerAppDelegate");
[pool release];
return retVal;
}
@alexeckermann
alexeckermann / server.rb
Created May 14, 2011 06:59
Webrick Server for TumblrThemr
#!/usr/bin/ruby
require 'webrick'
include WEBrick
s = HTTPServer.new(:Port => 3000, :DocumentRoot => Dir::pwd)
['INT', 'TERM'].each { |sig| trap(sig) { s.shutdown } }
s.start
@alexeckermann
alexeckermann / category_list_block.rb
Created June 27, 2011 11:46
The Jekyll plugins used on alexeckermann.com
module Jekyll
class CategoryListBlock < Liquid::Block
include Liquid::StandardFilters
def render(context)
categories = context.registers[:site].categories.keys
result = []
context.stack do
@alexeckermann
alexeckermann / 404.js
Created June 27, 2011 12:34
The 404 RedirectOMatic 3000
$(function(){
// Fade the page, hide the 'Not found' message a little, there's still hope!
$('#title, #page').css('opacity', 0.3);
// If the JSON is taking its time or fail then reset
var timeout = setTimeout(function(){
$('#page, #title').css('opacity', 1);
}, 2000);
// Get the JSON. Using jQuery.
@alexeckermann
alexeckermann / jq.customfile.js
Created July 4, 2011 02:54
Custom file input style
jQuery.fn.customfile = function(opts){
var options = $.extend({ text: 'Upload file' }, opts),
wrapper = $('<div />').addClass('jq-link-file-field-wrapper'),
hitarea = $('<div />').addClass('jq-link-file-field-hitarea'),
link = $('<a />').attr({'class': 'jq-link-file-field-link', href: 'javascript:void(0);'}).html(options['text']);
this.after(wrapper.append(hitarea.append(link)));
wrapper.css('position', 'relative').prepend(this);
this.css({opacity: 0.0, 'z-index': 100}); hitarea.css({'z-index': 10});
$([this[0], hitarea[0]]).css({position: 'absolute', left: 0, top: 0, display: 'block'});
/*
* _mixins.scss
* ============
* Some mixins I am using at work. Giving < CSS3 support where I can.
*
*/
$golden-ratio: 1.61803399; // Everyone is doing it
$base-spacing: 20px;
@reward = place.rewards.active
@reward = at_place ? @reward.cellar_door.first : @reward.regular.first
# better?
@alexeckermann
alexeckermann / MyViewController_excerpt.m
Created August 19, 2011 05:48
How to access the previous UIViewController from a pushed UIViewController your about to close
- (void)closeThisViewController {
// Lets retain an instance of the current navigation controller
UINavigationController *navController = [self.navigationController retain];
// When this is called self.navigationController is no longer available
[self.navigationController popViewControllerAnimated: YES];
// To talk to that previous VC here's what you do
[[navController topViewController] doSomethingHere:YES];