Skip to content

Instantly share code, notes, and snippets.

View jeremywrowe's full-sized avatar
❤️
Coding

Jeremy W. Rowe jeremywrowe

❤️
Coding
View GitHub Profile
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
require 'active_support/core_ext/string/inquiry.rb'
def speak_like_a(val)
is = val.inquiry
if is.chicken?
puts "bagaaawk"
elsif is.pig?
puts "oink"
else
puts "sorry don't know what tongue that speak in"
@jeremywrowe
jeremywrowe / saving_private_ruby.rb
Created January 6, 2014 14:13
This is a display of taking advantage of ruby 2.1 returning a symbol representation of methods when created and passing it to private as a single argument.
class Test
# :( wish this worked
private def self.bar
puts "self bar"
end
# would be nice to not have to do this
class << self
private def nook
puts "self nook"
@jeremywrowe
jeremywrowe / refinement.rb
Last active January 2, 2016 09:29
Example of ruby 2.1 refinements and their glory. Use with caution -- They are kind of code stinkies.
module Refinement
refine String do
def reverse
self[0..1]
end
end
end
class Boom
@jeremywrowe
jeremywrowe / require_billing_zip.js
Created November 21, 2013 14:44
This is an example of requiring a non required field on Chargify hosted pages through the use of our custom javascript. (this example demonstrates required billing zip with all other billing fields not required. This script can be utilized by adding it to your "Custom Javascript" on the "Hosted Pages Settings" found under the "Settings" tab. Exa…
$(function() {
var $form = $("form#hosted-payment-form"),
$submit = $form.find("input[type='submit']"),
$label = $form.find("label[for='subscription_payment_profile_attributes_billing_zip']"),
submitText = $submit.val();
// Mark billing zip as required
$label.text("*" + $label.text());
@jeremywrowe
jeremywrowe / single-on-off-components.js
Created November 16, 2013 14:55
This is an example of limiting selection of a set of on/off components on Chargify hosted pages to select only a single component. This script can be utilized by adding it to your "Custom Javascript" on the "Hosted Pages Settings" found under the "Settings" tab. Example Video: http://cl.ly/2237413N071y/on-off-components-single-selection.mov
$(function() {
var updatingCheckboxes = false,
$components = $('.component-checkbox');
$components.change(function(e) {
if(updatingCheckboxes) { return; }
var $el = $(this),
checked = $el.attr("checked");
if(checked) {
e.preventDefault();
updatingCheckboxes = true;
@jeremywrowe
jeremywrowe / bypass_auth.rb
Created September 2, 2013 23:57
Getting current user in tests is slow and painful.. but you can do something like this to speed up your test suite. Writing a blog about it sometime in the future.
def bypass_current_user(user, &block)
raise "Block must be given.." unless block_given?
$current_user = user
begin
ApplicationController.class_exec do
alias original_current_user current_user
def current_user
$current_user
end
yield
@jeremywrowe
jeremywrowe / rant.md
Last active December 21, 2015 16:48
Overuse of convenience methods

I have been doing a lot of about convience methods in Ruby lately. I have, noticed others that over use the convience of creating a class with instance level methods and wrapping all of it in a class level method for convience. (this is not new to me - just to be clear. Rather something I am reflecting on)

consider:

class FunkyBusiness
  attr_reader :initial_state

  def initialize(initial_state)
    @initial_state = initial_state
require "minitest/autorun"
class ALongTest < Minitest::Test
def setup
@this_is_cool = true
end
def test_this_is_cool
assert @this_is_cool
require "spec_helper"
# I would like to..
describe "a story." do
# there once was a chicken
it "was a lovely chicken" do
# you could always
expect(the_chicken).to cluck
end