Skip to content

Instantly share code, notes, and snippets.

View kylewelsby's full-sized avatar
🏠
Working from home

Kyle Welsby kylewelsby

🏠
Working from home
View GitHub Profile
@kylewelsby
kylewelsby / miniapp.coffee
Last active December 17, 2015 16:59
Association resource.
app = angular.module('app', ['ngResource'])
app.factory("Result", ["$resource", ($resource) ->
$resource("/scrapes/:scrape_id/results/:id", {scrape_id: "@scrape_id", id: "@id"})
])
app.controller("MainCtrl", ['$scope','Result',($scope,Result)->
$scope.scrape = {id: 1}
$scope.results = []
$scope.getResults = (->
@kylewelsby
kylewelsby / sessions_controller.rb
Created April 30, 2013 10:48
user session logout to send new CSRF token upon logout
def destroy
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
current_user.update_column(:authentication_token, nil)
sign_out
render :status => 200,
:json => { :success => true,
:info => "Logged out",
:csrfParam => request_forgery_protection_token,
:csrfToken => form_authenticity_token
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<base href="http://localhost:3000/proxy/">
</head>
<body>
<p>Open the console and notice the following error
<code>
app = angular.module('Simple')
@SimpleCtrl = ['$scope', ($scope) ->
$scope.data = {output: 'hello world'}
doSomething = () ->
$scope.data.output => "hello application."
]
###
@kylewelsby
kylewelsby / client_controller.rb
Created February 27, 2013 10:10
Simple RSpec Controller Examples
class ClientController < ApplicationController
respont_to :html
def show
@client = Client.find(params[:id])
respond_with @client
end
end
require 'capistrano/ext/multistage'
require "rvm/capistrano"
require "bundler/capistrano"
require "delayed/recipes"
require 'new_relic/recipes'
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
set :default_environment, {
'PATH' => "/home/rails/.rvm/gems/ruby-1.8.7-p370@appname/bin:/home/rails/.rvm/bin:/home/rails/.rvm/rubies/ruby-1.8.7-p370/bin:$PATH",
@kylewelsby
kylewelsby / risk.rb
Created October 18, 2012 18:04
Example for NWRUG visitor
require 'rspec'
class Risk
def code(user)
user_site = user.site[0..1]
if department
department_name = department.name[0..1]
end
[user_site,department_name,"001"].compact.join('-').upcase
@kylewelsby
kylewelsby / application_helper.rb
Created October 2, 2012 14:46
testing a application helper
def active_tab
link_to("Homepage", root_path, :class => ("active" if current_page? root_path))
end
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics.
@kylewelsby
kylewelsby / index.json.rabl
Created April 11, 2012 17:08
View Specs Real Example
if @grouped
object @days
node do |date|
node(:changed) { date[:changed].format }
node(:balance) { date[:balance].format }
child date[:transactions] => :transactions do
extends 'transactions/show'
end
node(:date) { date[:date] }