Skip to content

Instantly share code, notes, and snippets.

View hopsoft's full-sized avatar

Nate Hopkins hopsoft

View GitHub Profile
@hopsoft
hopsoft / assets.rb
Last active August 29, 2015 14:25
Module Asset Config
# config/initializers/assets.rb
Rails.application.config.tap do |config|
config.assets.version = "1.0"
paths = Dir[
Rails.root.join("app/assets/javascripts/modules/**/*"),
Rails.root.join("lib/assets/javascripts/modules/**/*"),
Rails.root.join("vendor/assets/javascripts/modules/**/*")
]
@hopsoft
hopsoft / lodash.js
Created July 18, 2015 11:36
Lodash Manifest File
// vendor/assets/javascripts/modules/lodash.js
//= require lodash
@hopsoft
hopsoft / gist:c7a2dd88b50039ed4eb9
Created July 18, 2015 11:32
Module Directories
app/assets/javascripts/modules
lib/assets/javascripts/modules
vendor/assets/javascripts/modules
@hopsoft
hopsoft / Gemfile
Last active December 26, 2015 12:03
Rails Assets
source 'https://rubygems.org'
source 'https://rails-assets.org' do
gem 'rails-assets-requirejs', '2.1.19'
gem 'rails-assets-bootstrap', '3.3.5'
gem 'rails-assets-font-awesome', '4.3.0'
gem 'rails-assets-jquery', '2.1.4'
gem 'rails-assets-jquery-ujs', '1.0.4'
gem 'rails-assets-lodash', '3.10.0'
gem 'rails-assets-classnames', '2.1.3'
@hopsoft
hopsoft / example_component.js
Last active August 29, 2015 14:24
React Component Structure
(function (app) {
var components = (app.components || (app.components = {}));
app.components.ExampleComponent = React.createClass(
mixins: [],
propTypes: {...},
getInitialState: function () {
return {
@hopsoft
hopsoft / some_controller_test.rb
Last active August 29, 2015 14:13
Fix routing for engine controller tests in Rails 4.0.xxx
require 'test_helper'
module ExampleEngine
class SomeControllerTest < ActionController::TestCase
setup do
@routes = ExampleEngine::Engine.routes
end
test "index response" do
@hopsoft
hopsoft / gist:2452e372572a15f4b1ad
Created January 15, 2015 18:31
Easy way to create a Rails fixture stub
require "model_probe"
User.extend ModelProbe
User.fixture
@hopsoft
hopsoft / gist:7a2afcb46ce14b5441ff
Created December 15, 2014 03:32
Rails Modeling Example
# Models
# app/models/user.rb
class User < ActiveRecord::Base
has_many :articles
has_many :videos
has_many :photos
end
# app/models/article.rb
@hopsoft
hopsoft / transition.rb
Last active August 29, 2015 14:10
Han Transition Wrapper in Ruby
require "active_support/all"
require "forwardable"
class Transition
extend Forwardable
def_delegators :params, :to_query, :to_json
def initialize(han_transition)
@han_transition = han_transition.symbolize_keys
@params = han_transition[:params].symbolize_keys
@hopsoft
hopsoft / api_tokens.md
Last active April 19, 2019 14:28
Simple API security with Rails

Simple API security with Rails

API clients set an HTML header.

Authorization: Token token="SECRET_API_KEY"

Your ApplicationController can then restrict access based on the token.