Skip to content

Instantly share code, notes, and snippets.

@jackcallister
jackcallister / sublime-config.js
Last active October 12, 2015 00:38
Sublime Text 2 Config
{
"auto_complete": true,
"check_for_rbenv": true,
"close_windows_when_empty": false,
"color_scheme": "Packages/RailsCasts Colour Scheme/RailsCastsColorScheme.tmTheme",
"default_encoding": "UTF-8",
"draw_white_space": "all",
"file_exclude_patterns":
[
"*.pyc",
@jackcallister
jackcallister / _flash_message.html.erb
Created April 15, 2013 23:34
Twitter Bootstrap flash partial for Rails
<% [:notice, :error, :alert, :success].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert alert-<%= flash_class(level) %>">
<a class="close" href="#" data-dismiss="alert">&times;</a>
<%= flash[level] %>
</div>
<% end %>
<% end %>
@jackcallister
jackcallister / params.rb
Created April 17, 2013 09:57
View Rails params in the browser
render :text => params.inspect
@jackcallister
jackcallister / _form.html.erb
Created May 15, 2013 03:13
Get Bootstrap and Rails error messages to play nicely together.
<div class="control-group <%= control_group_error(@model, :field_name) %>">
<%= f.label :field_name, :class => "control-label" %>
<div class="controls">
<%= f.text_field :field_name %>
<%= error_help_text(@model, :field_name) %>
</div>
</div>
@jackcallister
jackcallister / define_method.rb
Created August 7, 2013 01:58
Generatively defining a method
self.markdownable_columns.each do |markdown_column|
define_method :"#{markdown_column}_html" do
if value = send(markdown_column)
<Application>::Application.config.markdown_renderer.render(value).html_safe
end
end
end
@jackcallister
jackcallister / spaces.css.scss
Created August 7, 2013 02:26
Spaces utility
// Should be used to modify the default spacing between objects (not between nodes of * the same object)
// p,m = padding,margin
// a,t,r,b,l,h,v = all,top,right,bottom,left,horizontal,vertical
// x,s,m,l,n = extra-small($x),small($s),medium($m),large($l),none(0px)
$x: 3px;
$s: 5px;
$m: 10px;
$l: 20px;
.ptn, .pvn, .pan {
@jackcallister
jackcallister / model.rb
Created August 9, 2013 01:18
Model method delegation
# Delegate in a block to set up multiple delegations
with_options allow_nil: true do |product_delegate|
product_delegate.delegate :fields, to: :product_type
end
# Delegate as a method call
delegate :fields, to: :product_type, allow_nil: true
@jackcallister
jackcallister / publishable.rb
Created November 12, 2013 04:29
Pending changes
def pending_changes?
return false if !status.published?
original_attributes = Product.last.attributes.symbolize_keys.except(*publish_excluded_attributes)
published_attributes = Product.last.published_record.attributes.symbolize_keys.except(*publish_excluded_attributes)
original_attributes == published_attributes ? false : update_attribute(:published_status, 'changed')
end
@jackcallister
jackcallister / ViewController.m
Created December 17, 2013 21:13
Tim, help me. Animating with Objective-C
-(void)animateButton:(UIButton *)sender
{
CGRect originalFrame = sender.frame;
CGRect newFrame = CGRectMake(originalFrame.origin.x - 3, originalFrame.origin.y - 3, originalFrame.size.width + 6, originalFrame.size.height + 6);
[UIView animateWithDuration:0.4 delay:0 options:(UIViewAnimationOptionAutoreverse)
animations:^{
sender.frame = newFrame;
}
completion:^(BOOL finished){
@jackcallister
jackcallister / build.rake
Created April 23, 2014 10:53
Turn Rails into a SPA generator
namespace :app do
desc "Build static distrubution"
task :build do
puts "Building..."
# Shell out for now...
`bundle exec rake assets:clean`
puts "Compiling"
`bundle exec rake assets:precompile`
puts "Starting web get"