Skip to content

Instantly share code, notes, and snippets.

View Austio's full-sized avatar

Austin Story Austio

View GitHub Profile
@apneadiving
apneadiving / before.rb
Last active August 29, 2015 14:07
The before is some standard code, `with_waterfall` presents another way to write it (fully chainable)
# In controller
result = TaxCalculator.new(order).call
if result[:success]
render json: { value: result[:value] }
else
render json: { errors: result[:errors] }, status: 422
end
# The service
class TaxCalculator
@boriscy
boriscy / application_controller.rb
Created April 28, 2012 15:11
General module for multitenant
# encoding: utf-8
# app/controllers/application_controller.rb
# author: Boris Barroso
# email: boriscyber@gmail.com
class ApplicationController < ActionController::Base
layout lambda{ |c|
if (c.request.xhr? or params[:xhr])
false
elsif params[:print].present?
"print"
<h2>Sign up</h2>
<div id="stripe_error" class="alert alert-error" style="display:none" >
</div>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'card_form form-vertical' }) do |f| %>
<h3><%= params[:plan].titleize if params[:plan] %> Subscription Plan</h3>
<%= hidden_field_tag 'plan', params[:plan] %>
<%= f.error_notification %>
<%= f.input :f_name, :autofocus => true %>
<%= f.input :l_name %>
<%= f.input :email, :required => true %>
@jonyt
jonyt / connect_heroku_to_amazon_rds
Last active April 13, 2017 00:11
How to connect a Heroku application to an Amazon RDS Postgresql instance
Download the certificate with:
`wget -O config/rds-combined-ca-bundle.pem http://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem`
Then connect with:
`postgres://user:password@amazon-host/db_name?sslmode=require&sslrootcert=config/rds-combined-ca-bundle.pem`
References:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.SSL
https://github.com/jeremyevans/sequel/issues/897
http://www.postgresql.org/docs/9.3/static/libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT
http://dba.stackexchange.com/questions/77811/how-to-connect-to-an-amazon-postgresql-database-using-ssl
@cjohansen
cjohansen / gist:739589
Created December 13, 2010 20:55
Showing how to fake server requests with Sinon.JS and Jasmine
/*
Load Sinon.JS in the SpecRunner:
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script>
http://cjohansen.no/sinon/
*/
@theorygeek
theorygeek / caching_instrumentation.rb
Last active April 28, 2020 12:40
GraphQL Caching
# Define an instrumentation that performs the caching
class CachingInstrumentation
def instrument(_type, field)
return field unless field.metadata.include?(:cache_proc)
old_resolver = field.resolve_proc
new_resolver = -> (obj, args, ctx) do
# Get the caching key
cache_key = field.metadata[:cache_proc].call(obj, args, ctx)
@paulsturgess
paulsturgess / service_spec.js
Created February 8, 2017 20:51
Test Axios promise with jasmine-ajax
import Service from 'path/to/service';
import 'jasmine-ajax'
describe('Service', () => {
let request, promise;
let instance = Service;
let payload = {foo:'bar'};
let path = '/path';
let callback = jasmine.createSpy('callback');
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@furi2
furi2 / gist:1378595
Created November 19, 2011 07:36
Uploading multipart/form-data type data from Titanium
var content = '';
var boundary = '---------------------------170062046428149';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="uploadToken"\r\n';
content += '\r\n';
content += upload_token + '\r\n';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="destFolderPath"\r\n';
content += '\r\n';
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################