Skip to content

Instantly share code, notes, and snippets.

View afbroman's full-sized avatar

Andrew Broman afbroman

  • University of Wisconsin-Madison
  • Madison, Wisconsin
  • X @afbroman
View GitHub Profile
@afbroman
afbroman / faraday_stubbing
Created June 3, 2016 15:10 — forked from anonymous/faraday_stubbing
Stubbing with Faraday
def stub_request
faraday_stub = Faraday.new do |builder|
builder.adapter :test do |stub|
stub.post('/api/service', {id: '111', data: {'a': 1}}) {|env| [200, {}, mock_response]}
stub.get('/api/another_service', {query: 'foo'}) {|env| [200, {}, second_mock_response]}
end
end
Service::Something.stubs(:connection).returns(faraday_stub)
end
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
// layout file
<body>
<div class="container">
<%= flash_messages %>
<%= yield %>
</div><!-- /container -->
</body>
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
@afbroman
afbroman / gist.rb
Created March 28, 2014 17:38 — forked from ahoward/gist.rb
## conduce - be conducive to; "The use of computers in the classroom lead to better writing"
#
# a model+view component for rails that combines the conductor and presenter
# pattern via a model capable of generating view-centric methods
#
module Conducer
# base class
#
#!/usr/bin/env ruby
require 'rubygems'
require 'active_ldap'
ActiveLdap::Base.setup_connection(
:host => 'ldap.example.com',
:base => 'dc=example,dc=com',
)
# place in config/initalizers
module ActiveRecord
class Base
# Establishes a connection to the database that's used by all Active Record objects.
def self.mysql2_connection(config)
config[:username] = 'root' if config[:username].nil?
if Mysql2::Client.const_defined? :FOUND_ROWS
config[:flags] = Mysql2::Client::FOUND_ROWS | Mysql2::Client::MULTI_STATEMENTS
@afbroman
afbroman / teaching_myself_boos_tda.rb
Created September 21, 2012 16:10 — forked from RobertBrewitz/teaching_myself_boos_tda.rb
Understanding the BOOS, "Don't ask tell" from a talk at GORUCO 2012
##
# Growing Object Oriented Software
# Tell, don't ask approach
# Tested and learned the principle
class SomeProgram
def self.runit
# Printer is the main purpose
# Later I might want to Log, IM, Email or Ping something about the printing result.