Skip to content

Instantly share code, notes, and snippets.

View jeremywrowe's full-sized avatar
❤️
Coding

Jeremy W. Rowe jeremywrowe

❤️
Coding
View GitHub Profile
@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
require "spec_helper"
describe FuManchu do
let(:something_expensive) { Record.new.tap(&:save) }
let(:something_inexpensive) { OpenStruct.new(cheap: true) }
context "a stash" do
it "uses the something expensive" do
describe Wombat do
let(:active_user) do
user = User.new
user.tap(&:make_active)
end
context "with an active user" do
it "is a cuddly creator" do
expect(Wombat.new(active_user)).to be_cuddly
end
describe Wombat do
context "with an active user" do
let(:active_user) do
user = User.new
user.tap(&:make_active)
end
it "is a cuddly creator" do
expect(Wombat.new(active_user)).to be_cuddly
end
@jeremywrowe
jeremywrowe / status_code.php
Last active December 20, 2015 15:19
This is an example of querying the chargify api and retrieving the status code of the response
<?php
$api_key = "";
$subdomain = "";
$handle = curl_init('https://'.$subdomain.'.chargify.com/customers/100000.json');
curl_setopt($handle, CURLOPT_USERPWD, $api_key . ":x");
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);