Skip to content

Instantly share code, notes, and snippets.

@jkongie
jkongie / Pass form as GET request
Created December 4, 2009 01:13
Remove the submit param from a get form
<% form_tag( '/search', :method => 'get' ) do %>
<%= text_field_tag :search_str %>
<%= submit_tag "Search", :name => nil %>
<% end %>
@jkongie
jkongie / polymorphic_factory.rb
Created March 1, 2010 05:53
Factory Girl - Polymorphic Factory
# Setting up a polymorphic factory for a join table
# Since rosterable is not the default name of the model we are calling, we can't use the convenience method
# that is used for area (f.association)
# All we have to do is fall back to the block way of doing it, calling f.rosterable and passing in the
# object you want to populate it with ( in this case a template). This will fill in both rosterable_id
# and rosterable_type for us
Factory.define(:template_rostered_area, :class => RosteredArea) do |f|
f.association :area
f.rosterable { |a| a.association(:template)}
//Use this to align the text in a text view where you want it
textView.contentInset = UIEdgeInsetsMake(-8,-8,0,0);
@jkongie
jkongie / Spinner.m
Created March 16, 2010 00:50
Add a spinner to a button in Objective C iPhone Development
//How to add a spinner onto a button
- (IBAction)deleteAction:(id)sender {
[self.navigationController.view addSubview:activityIndicator];
[activityIndicator startAnimating];
// Spinner won't start spinning until we finish processing this event, so
// we're just going to schedule the rest of what we need to do.
// doDelete: will run when the main thread gets its next event.
@jkongie
jkongie / button.css
Created May 12, 2010 04:07
Create an image button with text inside
a.add_btn
:background url('/images/btn.add.left.png') no-repeat
:padding
:left 30px
:top 10px
:bottom 10px
:text-decoration none
:color #FFF
span
CGSize dyn_size = [title sizeWithFont:self.font];
CGRect frame = self.frame;
frame.size.width = dyn_size.width;
self.frame = frame;
@jkongie
jkongie / Dynamic defination of methods
Created August 5, 2010 01:55
Dynamically define methods
# Dynamically define whether a user has a role methods in a nice query language based on User::ROLES
# Eg. Can now call user.admin? or user.billing?
ROLES.each do |role|
method_name = (role + '?').to_sym
send :define_method, method_name do
self.role == role
end
end
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
@jkongie
jkongie / rename_show.rb
Created September 9, 2011 02:06
TV Show Renaming Script
#!/usr/bin/env ruby
require 'highline/import'
require 'sofa'
class NoMatchFoundError < StandardError; end;
class EpisodeFile
attr_accessor :file, :season, :episode, :extension, :high_def, :valid
@jkongie
jkongie / edit.html.haml
Created November 14, 2011 03:25
has many :through nested attributes with checkboxes
# Using formtastic but can easily converted to use standard rails form helpers
= semantic_form_for [ @user ] do |f|
= f.semantic_fields_for :user_specialities do |user_speciality|
= user_speciality.inputs do
= user_speciality.input :speciality_id, :as => :hidden
= user_speciality.input :_destroy, :label => user_speciality.object.speciality.name, :as => :boolean, :checked_value => 0, :unchecked_value => 1, :input_html => { checked: !user_speciality.object.new_record? }