Skip to content

Instantly share code, notes, and snippets.

View aaronlifton's full-sized avatar
:octocat:
AstroJS

Aaron Lifton aaronlifton

:octocat:
AstroJS
View GitHub Profile
@aaronlifton
aaronlifton / base_controller.rb
Created March 28, 2017 22:20 — forked from dhoelzgen/base_controller.rb
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'
@aaronlifton
aaronlifton / Gemfile
Created April 19, 2017 17:38 — forked from skolf/Gemfile
A Rake task for precompiling assets in a Sinatra app using Sprockets.
source 'http://rubygems.org'
# app base
gem 'logger'
gem 'rack'
gem 'sinatra'
gem 'sinatra-assetpack'
gem 'sprockets'
gem 'sprockets-helpers'
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@aaronlifton
aaronlifton / callbacks.rb
Created May 2, 2017 18:41
active support callbacks example
class V
include ActiveSupport::Callbacks
define_callbacks :derp
set_callback :derp, :after, :after_derp
attr_accessor :x
def derp
run_callbacks :derp do
@x = 1
puts @x
end
@aaronlifton
aaronlifton / extended_original_payment.rb
Created May 2, 2017 19:48
extending spree original payment reimbursement type
module Spree::ReimbursementType::ExtendedOriginalPayment
def self.included(base)
class << base
include ClassMethods
end
end
module ClassMethods
def reimburse(reimbursement, return_items, simulate)
if simulate
@aaronlifton
aaronlifton / optparse-template.rb
Created May 17, 2017 21:00 — forked from rtomayko/optparse-template.rb
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@aaronlifton
aaronlifton / Enhance.js
Created May 30, 2017 18:08 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@aaronlifton
aaronlifton / routes.elm
Created May 30, 2017 19:52 — forked from hallettj/routes.elm
Example of a graph in Elm
import Html exposing (text)
import List exposing (concatMap, filter)
import List.Extra exposing (uniqueBy)
type alias CityId = Int
type alias City =
{ id: CityId
, name: String
}
@aaronlifton
aaronlifton / installing-node-for-ubuntu-with-nvm.md
Created September 11, 2017 20:26 — forked from d2s/installing-node-with-nvm.md
Installing Node.js for Ubuntu with nvm
@aaronlifton
aaronlifton / describe_ec2_instances.sh
Created September 27, 2017 00:48
describe ec2 instances in all regions
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region
done