Skip to content

Instantly share code, notes, and snippets.

View Austio's full-sized avatar

Austin Story Austio

View GitHub Profile
<script>
// Configure recurly.js
recurly.configure('<%= @recurly_public_key %>');
//grab some dom
var form = $('form');
//var methodRadio = $('input[name=payment-method-select]');
var box = form.find('.payment');
var inputs = form.find('input, select, button');
var submit = form.find('button');
<div class="payment">
<%= javascript_include_tag 'https://js.recurly.com/v3/recurly.js' %>
<%= stylesheet_link_tag "creditcard" %>
<section class="credit-card visa gr-visa">
<header class="payment-top">
This is a secure 128-bit SSL encrypted payment form
</header>
<!--- <div class="logo">Visa</div> --->
<h2>Payment Details</h2>
def self.create_subscription(recurrance, recurly_token, paysysid)
response = Recurly::Subscription.create! plan_code: "premium-#{recurrance}",
account: {
account_code: paysysid,
billing_info: { token_id: recurly_token }
}
if response.is_a? Recurly::Subscription
return paysysid if response.state == "active"
app/policies/court_policy.rb
```
class CourtPolicy < ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
@Austio
Austio / gist:34e44ca30ba9a3ee8275
Created August 11, 2014 16:44
Simple Multi-tenancy
class SomeController < ApplicationController
before filter :check_authorized
authorized_roles = ["platinum", "gold"]
def check_authorized
redirect_to no_way_sucka_path, :notice => "No Way!" unless authorized_roles.include? current_user.role
end
end
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
# Command Line to run from terminal
# Logs result to file s3_backup.log
# Command will run in the background
s3cmd sync -v /path/to/folder/ s3://s3-bucket/folder/ > s3_backup.log 2>&1 &
# Crontab command to sync folder to S3
# Command will run 1am every day and logs result to /root/s3_backup.log
0 1 * * * /usr/bin/s3cmd sync -rv /path/to/folder/ s3://s3-bucket/folder/ >> /root/s3_backup.log
@Austio
Austio / Enum
Last active December 2, 2015 15:24
Error occuring when using active record enum inside of a nested active record class.
From: /../gems/activerecord-4.1.11/lib/active_record/attribute_methods.rb @ line 129 ActiveRecord::AttributeMethods::ClassMethods#method_defined_within?:
128: def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
=> 129: if klass.method_defined?(name) || klass.private_method_defined?(name)
130: if superklass.method_defined?(name) || superklass.private_method_defined?(name)
131: klass.instance_method(name).owner != superklass.instance_method(name).owner
132: else
133: true
134: end
135: else
@Austio
Austio / f.collection_select
Created June 4, 2013 18:52
f.collection_select explained
f.collection_select :x, query, :y, :z
:x = the value of the select id and name
query = the query sent to the database to return values
:y = the values in the options
:z = what you want displayed in the drop down menu
So if you have a Model that has an alias and an ID you would render it like this