Skip to content

Instantly share code, notes, and snippets.

@dimroc
dimroc / gist:1156230
Created August 19, 2011 06:59
Zappa Coffee-Script Entry file
port = Number(process.env.VMC_APP_PORT || process.env.C9_PORT || process.env.PORT || 5000)
zappa = require('zappa')
zappa port, ->
publicDir = __dirname + '/public'
use 'logger', 'bodyParser', 'methodOverride', app.router
use express.compiler(src: publicDir, enable: ['sass', 'coffeescript'])
use 'static'
@dimroc
dimroc / test_helper.rb
Created January 21, 2012 17:12
Rails default Test Unit test_helper
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
@dimroc
dimroc / gist:1872490
Created February 21, 2012 00:15
Bdd Demo Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'devise'
gem 'awesome_print'
@dimroc
dimroc / jasmine_spec.rb
Created July 19, 2012 22:59
Capybara request spec to ensure jasmine specs pass
require 'spec_helper'
# For use alongside Jasminerice
# Requirements: Capybara, Underscorejs
# Remember this is a request spec, so place in spec/requests/ or
# tag scenario with request: tue.
feature "JasmineSpecs" do
scenario "should all pass", js: true do
visit "/jasmine"
@dimroc
dimroc / create_saucelabsworker.sh
Last active December 15, 2015 17:22
chef knife command to create the sauce labs worker ec2 instance. chef bootstraps rvm, ruby, git, etc
knife ec2 server create -Z us-east-1a -S saucelabs --template-file bootstrap/ubuntu10.10-ruby193p125.erb -G sauce-labs -x ubuntu -I ami-1933fe70 -f m1.small -r "role[base],role[production],role[gotime]" -E production-legacy -T "Name=Sauce Labs Test Worker"
# Run me with:
#
# $ nginx -p /path/to/this/file/ -c nginx.conf
#
# All requests are then routed to authenticated user's index, so
#
# GET http://user:password@localhost:8080/_search?q=*
#
# is rewritten to:
#
@dimroc
dimroc / FakeSpecHelpers.rb
Last active August 29, 2015 14:07
Rspec spec helpers for Toggleable Fakes
require 'webmock/rspec'
module FakeSpecHelpers
def servers_return_healthy
puts "WARNING: Stubbing out healthy servers in an integration run" if ENV["INTEGRATION"] == "true"
WebMock.stub_request(:any, /.*api.parse.com\/.*/).to_rack(FakeParse)
WebMock.stub_request(:any, /.*semaphoreapp.com\/.*/).to_rack(FakeSemaphore)
WebMock.stub_request(:any, /.*api.pusherapp.com\/.*/).to_rack(FakePusher)
end
@dimroc
dimroc / application.css.scss
Last active August 29, 2015 14:08
Customizations to new BS 3 typeahead.js and tokenfield to get the all fields aligned
@import "bootstrap-tokenfield/dist/css/bootstrap-tokenfield";
@import "bootstrap-tokenfield/dist/css/tokenfield-typeahead";
@import "typeahead-overrides";
@dimroc
dimroc / eager_pagination.rb
Last active December 28, 2020 21:36
How to eager load AR associations when using Elasticsearch-rails and Kaminari
class EagerPagination < SimpleDelegator
attr_reader :records, :scope
def initialize(records, scope)
super(records)
@records = records
@scope = scope
end
def each
@dimroc
dimroc / search_builder.rb
Created November 19, 2014 15:45
Elasticsearch query/filter builder in ruby following a jquery/monad design pattern. Built on top of Arelastic.
# Monads!
class SearchBuilder
class << self
def filter(filters)
new.filter(filters)
end
def match(fields, query, options = {})
new.match(fields, query, options)
end