Skip to content

Instantly share code, notes, and snippets.

View shicholas's full-sized avatar
🏁
small victories add up

nick shicholas

🏁
small victories add up
  • Earth
View GitHub Profile
@shicholas
shicholas / angular_factory_helper.rb
Last active August 29, 2015 14:04
Feature tests with evaluated Angular Factories
# This method returns the value from a factory that uses ngResource and a
# method on that factory using Capybara's evaluate_script API. This method
# has been tested with Poltergeist, a PhantomJS driver for Capybara
#
# This method uses window variables because a multi-line javascript function
# in Poltergeist must be defined in an anonymous function. Therefore, the only
# way I know of to get a closure outside of this context is by defining it
# on the window.
module AngularFactoryHelper
def invoke_factory(factory, method, parameters={}, postData='')
@shicholas
shicholas / docker_tests.rb
Created July 31, 2014 06:20
Dockerized Feature specs
begin
# build Docker image
`docker build -t app .`
#
# # delete old docker containers
`docker rm (docker ps -a -q)`
# gather all the feature specs
RAILS_ROOT = File.expand_path('../..', __FILE__)
feature_specs = Dir[File.join(RAILS_ROOT, 'spec/features/**/*.rb')]
@shicholas
shicholas / investment.clj
Last active August 29, 2015 14:03
Investment Problem
(ns sample.investment)
;; c = cost-per-investment
;; a = additional-return-per-investment
;; g = goal
;; n = number-of-investments
;; i = current-income
;; t = time, with 0 being when we started
(defn- time-without-investing [g i t] (+ (/ g i) t))
@shicholas
shicholas / commentary.md
Last active August 29, 2015 14:03
Fizzbuzz

Fizzbuzz

There are many ways to do this kata, including defining a refinement on the integer class as I did here. There are also many ways to print the fizzbuzz data including converting an integer to its representative in fizzbuzz or creating an array of numbers up to that integer with their fizzbuzz contents.

Printing to STDOUT

To print each element of an array to STDOUT it can be as simple as requiring a

@shicholas
shicholas / example_shared_example.rb
Last active August 29, 2015 14:01
Checkout Specs
RSpec.shared_examples 'not advance without payment info' do
it 'does not let user advance without payment info' do
click_button 'Preview'
expect(page).to have_content 'Must input payment info'
end
end
@shicholas
shicholas / intro.md
Last active August 29, 2015 14:00
Replacing Controllers and Routes with Action Objects

I've been intrigued with the idea of action objects seen at the LVRUG podium app and have been thinking how these objects can replace controllers altogether. The more I think about it, I think these classes can replace both controllers and routing if they were namespaced and inherited in a standardized way.

Take the example from the podium app (as of 4/30/2014):

module Topics
  class DisplayTopics
    attr_defaultable :reader_factory, -> { Repositories::Reads::ReadTopics }

 def call(&block)
@shicholas
shicholas / Guardfile
Created April 11, 2014 15:02
Guardfile, whoops
guard :rspec, notification: true, cmd: 'rspec --color --format nested --tty', all_after_pass: true, spec_paths: ["spec/actions", "spec/decorators", "spec/forms", "spec/models", "spec/services"] do
watch(%r{^spec/(actions|decorators|forms|models|services)/.+_spec\.rb$})
watch(%r{^spec/(actions|decorators|forms|models|services)_spec_helper\.rb$}) { |m| "spec/#{m[1]}" }
watch(%r{^spec/support_(actions|decorators|forms|models|services)/(.+)\.rb$}) { |m| "spec/#{m[1]}" }
watch(%r{^app/(actions|decorators|forms|models|services)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
watch('/spec/base_spec_helper.rb') { ["spec/actions", "spec/decorators", "spec/forms", "spec/models", "spec/services"] }
watch(%r{^spec/support_common/(.+)\.rb$}) { ["spec/actions", "spec/decorators", "spec/forms", "spec/models", "spec/services"] }
end
@shicholas
shicholas / spec_helper_full.rb
Created October 21, 2013 17:47
cut up spec_helper to get the tests running even faster!
require_relative "spec_helper_model"
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
@shicholas
shicholas / rss_messenger.rb
Last active December 23, 2015 23:19
RssMessenger Kata 9/25/2013 - Instantiate the class with RSSMessenger.new(<url of your favorite rss>).create_messages and you will see a unique list of messages!
# -*- coding: utf-8 -*-
require 'feedzirra'
require 'fileutils'
class RSSMessenger
attr_reader :feed
def initialize(feed)
@feed = process_feed(feed)
@shicholas
shicholas / funding.js
Created July 5, 2013 21:36
Gon and AngularJS in a Rails 4 App
// app/assets/javascripts/controllers/funding.js
var FundingCtrl = ['$scope', function($scope) {
$scope.funding = gon.funding;
}
];