Skip to content

Instantly share code, notes, and snippets.

View alexeckermann's full-sized avatar

Alex Eckermann alexeckermann

View GitHub Profile
@alexeckermann
alexeckermann / postcodes.rb
Last active November 7, 2017 07:44
Australian Postcode regex hellhole
StatePostcodeMatchers = { SA: /^5([0-9]){3}/, ACT: /^[2](?:[6](?:[0][0-9]|[1][0-8])|[9](?:[0-1][0-9]|20))/,
VIC: /^3([0-9]){3}/, QLD: /^4([0-9]){3}/, NT: /^08(?:[0-9]){2}/, TAS: /^7[0-7](?:[0-9]){2}/, WA: /^6(?:[0-6](?:[0-9]){2}|[7](?:[0-8][0-9]|[9][0-7]))/,
NSW: /^2(?:[0-6](?:[0-9]){2}|[6](?:[1][9]|[2-7][0-9])|[7](?:[0-9]{2})|[8](?:[0-8](?:[0-9]){1}|[9][0-8])|[9](?:[2][1-9]|[3-9][0-9]))/ }
# Probably dont do this.
@alexeckermann
alexeckermann / doesnt_work_1.rb
Created March 1, 2012 00:14
How can this be done without calling a private method?
# app/models/registration.rb
class Registration
attr_accessor :current_step
end
# Registration then ONLY has :current_step in it and the other methods from the engine are blasted
@alexeckermann
alexeckermann / golden.scss
Created January 24, 2012 05:55
Golden CSS3-POINT-OH
$golden-ratio: 1.61803399; // Everyone's doing it!
@function golden-division($value, $times: 1) {
@for $i from 1 through $times {
$value: $value / $golden-ratio;
}
@return round($value);
}
@alexeckermann
alexeckermann / oauth_mocking.rb
Created September 8, 2011 12:56
OmniAuth testing in RSpec + Capybara
module OauthMocking
def login_with_oauth(provider = :twitter)
visit "/auth/#{provider}"
end
end
@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];
@reward = place.rewards.active
@reward = at_place ? @reward.cellar_door.first : @reward.regular.first
# better?
/*
* _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;
@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'});
@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 / 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