Skip to content

Instantly share code, notes, and snippets.

class Herp
def derp
Derp.new
end
end
class Derp
def derp
'lol derp derp'
end
@biscuitvile
biscuitvile / ternary.rb
Created May 21, 2014 18:46
Ternary Operator
# your familiar basic if else
if pup_is_cute?
scratch_behind_ear
else
ignore_bad_breath_poodle
end
# ternary operator does the exact same thing with a ? and : like this
@biscuitvile
biscuitvile / product.rb
Last active August 29, 2015 14:00
Increment all attributes in a relation with two queries using ActiveRecord increment_counter and pluck methods
class Product < ActiveRecord::Base
# we could use the below version to acheive
# the desired result in a single statement
# with raw sql, however this solution
# wouldn't be database agnostic and I think
# most developers would prefer the ruby
# version as two queries is still very
# fast.
#

This pizza is a life-changer. If it's not already I highly recommend promoting homemade vegan pizza to a first class fixture in your life. The secret to this recipe is the sauce; it's a good idea to make extra as it keeps well in the freezer.

Vegan Dad Sausage:

1/2 cup pinto beans
1 cup vegetable broth
1 T. olive oil
2 T. soy sauce
2 cloves garlic minced

When the attached test is run using minitest-reporters DefaultReporter I get the following output:


# Running tests:

EF

Finished tests in 0.068895s, 14.5148 tests/s, 0.0000 assertions/s.
@biscuitvile
biscuitvile / helper.rb
Last active August 29, 2015 13:57
Helper
def stats_panel_toggle
title = i18n_concat(
t('admin.dashboard.visitors-daily'),
t('admin.dashboard.visitors')
)
link_to 'Y', '#daily_stat',
class: 'icon panel_toggle_trigger',
data: { title: title }
end
@biscuitvile
biscuitvile / template.html.haml
Created March 31, 2014 21:02
Nested hash args in HAML
= link_to 'Y', '#daily_stats',
class: 'icon panel_toggle_trigger',
data: {
title: "#{ t('admin.dashboard.visitors-daily') } #{ t('admin.dashboard.visitors') }"
}
@biscuitvile
biscuitvile / new.html.haml
Created March 31, 2014 20:50
Haml example with line breaking
%section
%article.admin.narrow
%header
%h1 Sign in
= form_tag sessions_path do
%fieldset
%dl
%dt= label_tag :email
%dd= text_field_tag :email, nil,
autocapitalze: 'off',
@biscuitvile
biscuitvile / form.html.haml
Created March 31, 2014 17:12
Advanced Form Builder
= form_for [:admin, @account], url: :admin_settings, class: 'settings' do |f|
%section.panel.panel_form
= f.input :store_name
= f.input :description, type: :textarea
= f.input :contact_email
%section.panel
%p.input.text
= f.submit t('admin.settings.save'), class: 'action_button success'
@biscuitvile
biscuitvile / form.html.haml
Last active August 29, 2015 13:57
Basic Form Builder For Simpler Templates
= form_for [:admin, @account], url: :admin_settings, class: 'settings' do |f|
%section.panel.panel_form
= f.wrapper :store_name do
= f.label :store_name
= f.text_field :store_name
= f.wrapper :description, :textarea do
= f.label :description
= f.text_field :description