Skip to content

Instantly share code, notes, and snippets.

@willawill
willawill / capybara.md
Last active August 28, 2015 14:01 — forked from steveclarke/capybara.md
RSpec Matchers

Capybara

save_and_open_page

Matchers

have_button(locator)
@willawill
willawill / gulpfile.coffee
Created June 4, 2014 19:53
gulpfile.coffee with Karma
gulp = require 'gulp'
coffee = require 'gulp-coffee'
coffeelint = require 'gulp-coffeelint'
compass = require 'gulp-compass'
connect = require 'gulp-connect'
cached = require 'gulp-cached'
clean = require 'gulp-clean'
rjs = require 'gulp-requirejs'
karma = require('karma').server
karmaRunner = require('karma').runner
@willawill
willawill / karma.conf.coffee
Created June 4, 2014 19:54
karma.conf.coffee
module.exports = (config) ->
config.set({
# base path, that will be used to resolve files and exclude
basePath: '../'
frameworks: ['jasmine', 'mocha', 'chai'],
files: [
{pattern: 'app/**/*.js', included: true, served: true, watched: false}
{pattern: 'tests/**/*.js', included: true, served: true, watched: false}
@willawill
willawill / index.md
Last active August 31, 2015 14:53 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

it "sorts the applications by the stage" do
+ first_stage = create(:phone_interview_stage, :hiring_plan => hiring_plan)
+ second_stage = create(:face_to_face_stage, :hiring_plan => hiring_plan)
+
+ first_application = create(:application)
+ first_application.current_application_stage = ApplicationStage.create(hiring_plan_interview_stage: first_stage, application: first_application)
+ first_application.save!
+ second_application = create(:application)
+ second_application.current_application_stage = ApplicationStage.create(hiring_plan_interview_stage: second_stage, application: second_application)
+ second_application.save!
@willawill
willawill / lockit.sh
Created August 21, 2012 10:44 — forked from quad/lockit.sh
Achtung: a not very nice hotdog
#!/bin/sh
#
# We have a few repeat customers here at the TWU 27 hotdog shack.
#
# They've decided it's FUN to visit our stand.
#
# So, we've cooked up something a little special for our valued customers.
set -e
@willawill
willawill / gist:4076771
Created November 15, 2012 05:07
Haml indentation.
#asks
%h2= "ASKS"
-@campaign.asks.each do |ask|
=haml :ask, locals: {ask: ask, type: ask.class.typesym}
-if @campaign.asks.select{|n| n.triggered_ask && n.triggered_ask == ask}.empty?
%form{action: "/campaign/#{@campaign.id}/broadcast}", method: "post"}
%button{type: 'submit'} Launch the Ask
%form{action: "/campaign/#{@campaign.id}/add_new_ask", method: 'get'}
%button Add new ask
There are three questions I have.
1. Is it a good practice to massage the data when save it back to the database?
In my case, my params passed back from view looks like {"auto_text"=>"When the wheels come down?", "keyoption"=>{"1"=>{"key"=>"1", "option"=>"2"}}}
and I will break hashes and straighten it to a String which is the :read_text property in Ivr.
I am thinking if I should let Ivr has the key:option pair as it is, and generate the String when needed.
Then I can do presence validation and update later.
2. With Struct way, I don't know how to put it in my model.
3. With long string way, I don't know how to generate and assign back to the property.
def build_response(from, commands)
response = Plivo::Response.new
commands.map do |c|
case c[:cmd]
when :reject
response.addHangup(reason: 'busy')
when :ivr
response.addHangup(reason: 'busy')
dial = response.addDial(callerId: from)
dial.addNumber(c[:to])
post '/ivrs/:id/trigger' do
p "here #{params}"
parameters = {to: params[:To],
from: params[:From],
answer_url: "#{ENV['SERVER_NAME']}/ivrs/#{params[:id]}/play",
}
res = Plivo::RestAPI.new("#{ENV['PLIVO_AUTH_ID']}", "#{ENV['PLIVO_AUTH_TOKEN']}").make_call(parameters)
end
post '/ivrs/:id/play' do