Skip to content

Instantly share code, notes, and snippets.

View Austio's full-sized avatar

Austin Story Austio

View GitHub Profile
@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
@Austio
Austio / NGINX on Ruby on Rails with Unicorn and GZIP assets
Last active September 3, 2018 19:22
Configure NGINX for SSL using unicorn and gzip assets optimizations
1. Open a command prompt and navigate to /etc/nginx/ssl
2. Issue "openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr"
3. Get your certificate issued - Go to your certificate authority and give them the CSR (server.csr)
4. Copy your new crt (that the certificate authority issued) to the /etc/nginx/ssl and give it read priveledges
5. Reconfigure your nginx.conf, here is mine. The first part redirects 80 to 443, the second part listens to 443 and is optimized to return Ruby on Rails application requests using gzip and unicorn.
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
<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