Skip to content

Instantly share code, notes, and snippets.

View kagemusha's full-sized avatar

Michael kagemusha

View GitHub Profile
@kagemusha
kagemusha / gist:8626265
Created January 26, 2014 00:54
Rails Cors
1. install rack-cors gem (https://github.com/cyu/rack-cors)
gem 'rack-cors', :require => 'rack/cors'
2. add to application.rb
config.middleware.insert_before "Rack::Lock", "Rack::Cors", :debug => true, :logger => Rails.logger do
allow do
origins '*'
@kagemusha
kagemusha / gist:1568446
Created January 6, 2012 01:36
JQuery Datatables: Show/Hide controls
Tested on: Databables 1.8.2
Datatables comes with controls for filtering and pagination. These can be shown and hidden in a couple of ways (all examples in coffeescript):
Way 1
$("#myTable").dataTable
"bPaginate": false, #hide pagination control
"bFilter": false #hide filter control
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@kagemusha
kagemusha / gist:1444076
Created December 7, 2011 18:50
Install Rails 3.1 Mongoid Mongo on Heroku
Tested on: Rails 3.1.x, Heroku Cedar stack
1. Generate/develop local Rails app, add mongoid gem, bundle install etc.
2. Git the App
3. Generate Heroku Cedar App:
heroku create --stack cedar
4. Rename app
heroku rename <newname>
5. Install heroku mongoHQ or mongolab:
heroku addons:add mongohq:free
@kagemusha
kagemusha / gist:8b95b93cfac710c7dd387f750432d1ed
Last active April 2, 2016 15:48
Updating an association with Elixir Ecto
defmodule PhoenixTimeline.Game do
...
schema "games" do
belongs_to :winner, PhoenixTimeline.Player
has_many :players, PhoenixTimeline.Player
...
end
...
end
@kagemusha
kagemusha / gist:6783059
Created October 1, 2013 18:40
Ember Data Store Synchronous Methods - not a complete list
store.getById
sync return rec from store if avail or return null
e.g.
var post = store.getById('post', 1);
filter: function(type, query, filter)
@param {Class} type
@param {Function} filter
@kagemusha
kagemusha / gist:6769178
Created September 30, 2013 19:50
Ember linkTo => link-to (c. Em.v1.0 9/26/2013)
In general:
1. somepropBinding=val => someprop=val
2. except for classNameBindings
e.g. classNameBindings=":option isSelected:selected"
for example:
{{#linkTo
option.path
typeBinding=option.value
@kagemusha
kagemusha / gist:6716491
Created September 26, 2013 16:18
Query Params in Ember
https://github.com/emberjs/ember.js/pull/3182
@kagemusha
kagemusha / gist:5708254
Created June 4, 2013 18:25
Postgres Selects with Booleans
v: 9.1.4
if have table users:
id is_admin
-- --------
1 t
2 f
3
@kagemusha
kagemusha / gist:1568472
Created January 6, 2012 01:42
JQuery Datatables, Rails Basic Server-side processing Example with Json obj, Custom Data Display
Tested on: Datatable 1.8.2, Rails 3.1.3
This example uses Coffeescript and Haml (you should too :-) )
The following is an example of Datatables server-side processing of a table
which displays a user's song list including the songs' artist names. In
Rails, Song and Artist are ActiveRecord models in a one artist-many song relat.
1a. the Rails controller code
class SongsController < ApplicationController