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 / 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
@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 / common.rb
Created June 14, 2013 13:49
Find common items within two arrays.
a1 = ["html", "body", "ul", "li", "a"]
a2 = ["html", "body", "ul", "li", "p"]
a1.zip(a2).map{|n| n.first if n.first == n.last}.compact
@kylewelsby
kylewelsby / array.rb
Created June 14, 2013 14:22
is there any cleaner way of writing this.
# example 1
array = [1] # input value is a single item in aray
array = array.size == 1 ? array.first : array
# => 1
# example 2
array = [1,2,3] # input value is a collection of items in a array
array = array.size == 1 ? array.first : array
# => [1,2,3]
@kylewelsby
kylewelsby / capybara_selecting_test.rb
Created June 14, 2013 14:52
Selecting content from a page and rendering it into an array of hashes `ruby server.rb` to start the server before running test.
require_relative 'test_helper'
require 'capybara'
require 'capybara/poltergeist'
class ArraySotringTest < MiniTest::Test
def test_drill_down
session = Capybara::Session.new(:poltergeist)
session.visit "http://0.0.0.0:9494/"
/* global module:false */
module.exports = function(grunt) {
grunt.initConfig({
karma:{
unit: {
configFile: 'karma.conf.js'
}
},
watch: {
files: [
@kylewelsby
kylewelsby / ability.rb
Created July 19, 2013 14:01
RSpec to test a cancan ability of 'create'
class Ability
include CanCan::Ability
def initialize(user)
can :create, Something
end
end
@kylewelsby
kylewelsby / Dockerfile
Created August 7, 2013 16:56
Proposed docker module syntax
# vi: expandtab filtype=dockerfile
FROM base
MAINTAINER Lee Hambley "[email protected]"
# Debian isn't too smart, there's no tty dude!
ENV DEBIAN_FRONTEND noninteractive
# Update Apt, never a bad move
RUN apt-get update
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Page</title>
</head>
<body>
<div>
<div>
<strong>Hello World</strong>
@kylewelsby
kylewelsby / prepare
Created September 25, 2013 12:02
prepare rails application with ProstgreSQL and Redis
#!/bin/bash -e
cp config/database.yml.example config/database.yml
# bundle install
postgres -D /usr/local/var/postgres > /dev/null 2>&1 &
POSTGRES_PID=$!
redis-server > /dev/null 2>&1 &