This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;core-test.clj | |
(ns gol.core-test | |
(:require [midje.sweet :refer :all] | |
[gol.core :refer :all])) | |
(facts "coin changer" | |
(fact "returns a penny for a penny" | |
(make-change-for 1) => [1]) | |
(fact "returns 2 pennies for 2 cents" | |
(make-change-for 2) => [1,1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I’m a constituent calling about the recent caucus vote by the GOP to reduce the impact of the Office of Congressional Ethics. This is something even the President Elect has come out against as of this morning, and I would like Congressman Walker to take a stand against this move and side with the president elect, as well as simply doing the right thing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: Write sample implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'google/apis/analyticsreporting_v4' | |
require 'googleauth' | |
include Google::Apis::AnalyticsreportingV4 | |
include Google::Auth | |
VIEW_ID = "12345678" #your profile ID from your Analytics Profile | |
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly' | |
@client = AnalyticsReportingService.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a bug where a model with a `url` attribute gets it modified when a controller is returning a JSON response | |
as_json response: [{"id"=>1, "title"=>"Hello 1", "url"=>"http://www.hello.com", "created_at"=>Tue, 12 Jan 2016 04:12:22 UTC +00:00, "updated_at"=>Tue, 12 Jan 2016 04:12:22 UTC +00:00}, {"id"=>2, "title"=>"Hello 2", "url"=>"http://www.hello.com", "created_at"=>Tue, 12 Jan 2016 04:12:29 UTC +00:00, "updated_at"=>Tue, 12 Jan 2016 04:12:29 UTC +00:00}] | |
JSON response in browser: [{"id":1,"title":"Hello 1","url":"http://localhost:3000/stories/1.json"},{"id":2,"title":"Hello 2","url":"http://localhost:3000/stories/2.json"}] | |
Corys-MacBook-Pro-2:Workspace foyc$ rails --version | |
Rails 4.2.5 | |
Corys-MacBook-Pro-2:Workspace foyc$ rails new rails-bug | |
create | |
create README.rdoc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ViewController | |
// NSURLConnection Delegates | |
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { | |
if ([challenge previousFailureCount] == 0) { | |
NSLog(@"received authentication challenge"); | |
NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"USER" | |
password:@"PASSWORD" | |
persistence:NSURLCredentialPersistenceForSession]; | |
NSLog(@"credential created"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def initialize(str) | |
@str = str | |
end | |
def *(num) | |
num.times.map { @str }.join('') | |
end | |
end | |
foo = Foo.new('hello') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You can use this from a rails console by creating this | |
#in a directory, starting up rails c, and then doing a | |
#'load fields.rb'. Then just call Fields.show_report | |
class Fields | |
def self.show_report | |
Rails.application.eager_load! | |
ActiveRecord::Base.descendants.each do |model| | |
table_name = model.table_name | |
puts "Varchar length report for #{table_name}" | |
puts "-------------------------------------------------" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Mock Each" do | |
it "mocks it" do | |
a = [] | |
a.should_receive(:each).and_yield('b') | |
b = [] | |
a.each { |c| b.push(c) } | |
expect(b.length).to eq 1 | |
expect(b.first).to eq 'b' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseTest < ActionDispatch::IntegrationTest | |
test "all controllers should raise exceptions with invalid IDs" do | |
routes = Rails.application.routes.routes | |
id_based_routes = routes.find_all { |r| r.required_parts.include?(:id) } | |
id_based_routes.each do |route| | |
klass = "#{route.defaults[:controller]}_controller".classify.constantize | |
@controller = klass.new | |
num_required_parts = route.required_parts.length | |
name = route.name | |
nonexistent_id = -1 |
NewerOlder