Skip to content

Instantly share code, notes, and snippets.

View anolson's full-sized avatar
👋

Andrew Olson anolson

👋
View GitHub Profile
@anolson
anolson / notes.md
Last active November 3, 2016 20:49
Confident Ruby Notes

Confident Ruby Notes

Chapter 1 – Introduction

Four parts of a method

  1. Collecting input
  2. Performing work
  3. Delivering output
  4. Handling failures
@anolson
anolson / spec_helper.rb
Last active March 21, 2020 02:53
Profile ActiveRecord queries with RSpec
RSpec.configure do |config|
config.before(:suite) do
Thread.current[:query_counter] = Hash.new(0)
end
config.around(:example) do |procsy|
callback = lambda do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
sql = event.payload[:sql].to_s.strip
operation = sql.split(' ', 2).first.to_s.downcase
# Re-try randomly failing examples
config.around(:each) do |ex|
attempts = [ENV["RSPEC_ATTEMPTS"].to_i, 1].max
attempts.times do |i|
example = RSpec.current_example
example.instance_variable_set("@exception", nil)
if i > 0
puts "Re-running rspec example #{example.location}. Attempt #{i + 1} of #{attempts}"
end
@anolson
anolson / debug_assets.rb
Created November 12, 2014 19:28
Debug rails asset pipeline.
module Sprockets
class Manifest
def logger_with_debug
logger_without_debug.tap do |logger|
logger.level = Logger::DEBUG
end
end
alias_method_chain :logger, :debug
end
end
@anolson
anolson / keybase.md
Created September 24, 2014 12:50
keybase.md

Keybase proof

I hereby claim:

  • I am anolson on github.
  • I am anolson (https://keybase.io/anolson) on keybase.
  • I have a public key whose fingerprint is F1C4 5C7C 42AC 5FD2 492D D67B C68E 0F36 79C0 CAD4

To claim this, I am signing this object:

@anolson
anolson / happy.md
Last active December 21, 2015 02:49
Recent things that make me happy.
@anolson
anolson / instructions.md
Last active December 18, 2015 04:59
Luhn Checksum

Luhn Checksum

Implement a Ruby program that outputs the validity of a number by applying the Luhn Checksum.

http://en.wikipedia.org/wiki/Luhn_algorithm

Please treat this as you would any other project or task you'd encounter during your daily work. This will show us how currently code, and not how you coded 6, 12 or 18 months ago. Your code should also be suitably tested.

Input:

@anolson
anolson / README.md
Created February 18, 2013 16:54 — forked from JanDupal/README.md

Jekyll sorted_for plugin

Quick'n'dirty Jekyll plugin for sorted cycle.

Install

Copy sorted_for.rb to _plugins/ directory of your Jekyll site.

Usage

@anolson
anolson / articles.html
Created June 7, 2012 14:32
Create a static website out of a tree of files (pdf)
<html>
<head>
<link rel=stylesheet href="/style/screen.css" media="screen" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><%= @path %></title>
</head>
<body>
@anolson
anolson / index.html
Created May 22, 2012 15:14
Super simple bar chart with D3.
<html>
<head>
<title>D3</title>
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script>
<script type="text/javascript" charset="utf-8" src="d3.v2.js"></script>
<script type="text/javascript" charset="utf-8" src="d3.layout.min.js"></script>