Skip to content

Instantly share code, notes, and snippets.

View BenMorganIO's full-sized avatar
😀
Why is this here?

Ben A. Morgan BenMorganIO

😀
Why is this here?
View GitHub Profile
@BenMorganIO
BenMorganIO / bower.json
Last active August 29, 2015 14:18
ember idempotent-rerender
{
"name": "ember-app",
"dependencies": {
"ember": "emberjs/ember.js#idempotent-rerender",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-data": "1.0.0-beta.15",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.1",
"ember-qunit-notifications": "0.0.7",
@BenMorganIO
BenMorganIO / preload.js
Created April 14, 2015 00:59
Preload Initializer
export function initialize(container, application) {
application.deferReadiness();
Ember.$.getJSON("/api/preload.json", function(json) {
var store = container.lookup('store:main');
store.load(application.Product, json.products); // undefined is not a function.
application.advanceReadiness();
});
}
export default {
@BenMorganIO
BenMorganIO / index.embl
Last active August 29, 2015 14:19
Listing Products
# app/templates/products/index.embl
section.container
h1 Products
ul
each product in products
li = link-to product.name 'products.show' product
= outlet
@BenMorganIO
BenMorganIO / current-user.js
Created April 14, 2015 21:37
Current User Initializer
// app/initializers/current-user.js
export function initialize(container, application) {
var store = container.lookup('store:main');
console.log(store);
}
export default {
name: 'current-user',
after: 'preload',
@BenMorganIO
BenMorganIO / sessions_controller.rb
Created April 15, 2015 21:01
Spree User Sessions API
module Spree
module Api
module V2
class SessionsController < Spree::UserSessionsController
def create
authenticate_spree_user!
if spree_user_signed_in?
render json: try_spree_current_user, serializer: Spree::UserSerializer
else
@BenMorganIO
BenMorganIO / manifest.yml
Created May 17, 2015 05:52
Permit the tmp folder
production:
classic:
after_symlink:
- command: cd $STACK_PATH && mkdir -p tmp && mkdir -p tmp/production-class-after-symlink && chmod 777 -R tmp/
target: rails
apply_during: all
run_on: all_servers
after_rails:
- command: sudo mkdir $STACK_PATH/tmp && sudo mkdir $STACK_PATH/tmp/production-class-after-rails && sudo chmod 0775 -R $STACK_PATH/tmp
product_filter_copy: .........................................................................................
product_master: .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@BenMorganIO
BenMorganIO / arel_paranoia.rb
Last active September 23, 2015 22:08
arel with deleted_at with paranoia
# Adding general indexes:
deleted_at = User.arel_table[:deleted_at]
da_is_null = Arel::Nodes::Equality.new(deleted_at, nil).to_sql
# => "\"users\".\"deleted_at\" IS NULL"
remove_index :users, :email
add_index :users, :email, where: da_is_null
# Adding unique indexes:
@BenMorganIO
BenMorganIO / my_controller.rb
Created September 30, 2015 02:15
base controller example usage
class MyController < BaseController
def index
super MyModel
end
end
@BenMorganIO
BenMorganIO / row_to_json.rb
Created February 1, 2016 00:54
JSON parsing in Postgres instead of Ruby.
ActiveRecord::Base.class_eval do
class << self
delegate :row_to_json, to: :all
end
end
ActiveRecord::Relation.class_eval do
def row_to_json
'[' + row_to_json_result.values.join(',') + ']'
end