Skip to content

Instantly share code, notes, and snippets.

View DanielOchoa's full-sized avatar

Daniel Ochoa DanielOchoa

View GitHub Profile
( () ->
if typeof angular is 'undefined'
return
module = angular.module 'ViewModel', []
module.factory 'View', () ->
{
( () ->
if typeof angular is 'undefined'
return
module = angular.module 'MessageModel', []
module.factory 'Message', () ->
{
steroids.on 'ready', ->
height = screen.height - 70
ele = document.getElementById 'scroll_wrap'
ele.style.height = height + 'px'
defaults: &defaults
adapter: postgresql
host: localhost
encoding: unicode
pool: 5
development:
<<: *defaults
database: fip_dev
def transaction_reports(sort, direction)
gift_type_names = GiftType.select(:name).map(&:name)
gift_type_names.unshift('Untracked Transactions')
reports = gift_type_names.map {|g| { name: g, object: Array.new }}
# Transaction type sql based on event type
transaction_type_sql = case event_type
when 1 # Gala
{:event_id => self.id, :transaction_type_id => 66}
when 2 # Luncheon
( () ->
if typeof angular is 'undefined'
return
module = angular.module 'ApiModel', []
module.factory 'Api', ($http) ->
baseURL = 'http://asset-campus-housing.herokuapp.com/api/v2/'
@DanielOchoa
DanielOchoa / gist:7125160
Created October 23, 2013 19:32
Remote authentication with Devise and auth_token
class Api::V1::SessionsController < Devise::SessionsController
respond_to :json
before_filter :authenticate_user!, :except => [:create, :destroy]
skip_before_action :verify_authenticity_token
def create
resource = User.find_for_database_authentication(email: params[:user][:email])
return invalid_login_attempt unless resource
if resource.valid_password?(params[:user][:password])
# Generate authentication token unless already exists and save the record.
@DanielOchoa
DanielOchoa / gist:7967035
Created December 15, 2013 00:40
Converts a hash of camel case and string keys into a hash of snake case keys as symbols. It's recursive.
def underscore_and_symbolize(obj)
obj.inject({}) do |hash, (key, val)|
if val.kind_of? Hash
val = underscore_and_symbolize(val)
end
hash[key.underscore.to_sym] = val
hash
end
end
@DanielOchoa
DanielOchoa / database.yml
Created February 18, 2014 16:31
database.yaml example
defaults: &defaults
adapter: postgresql
host: localhost
encoding: unicode
pool: 5
# port: 15432
development:
<<: *defaults
database: worthit_development
@DanielOchoa
DanielOchoa / gist:9749028
Last active December 22, 2015 02:48
underscore and symbolize recursively a Ruby hash
def underscore_and_symbolize(obj)
obj.inject({}) do |hash, (key, val)|
val = underscore_and_symbolize(val) if val.kind_of? Hash
hash[key.underscore.to_sym] = val
hash
end
end