Skip to content

Instantly share code, notes, and snippets.

@JoshTGreenwood
JoshTGreenwood / bench.rb
Created November 21, 2012 00:14
Benchmark break vs. catch-throw vs. begin-rescue-end in ruby
require 'benchmark'
Benchmark.bmbm do |x|
x.report('Break') do
1_000_000.times do
break
end
end
;; -*- mode: dotspacemacs -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration."
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '()
@JoshTGreenwood
JoshTGreenwood / testdouble.rb
Created October 18, 2016 15:46
the beginning of what testdouble.rb might look like
class TestDouble
attr_accessor :instance, :when_stack
def initialize(instance)
@instance = instance
@when_stack = []
end
def when(&block)
fake_method_call = FakeMethodCall.new(block)
@JoshTGreenwood
JoshTGreenwood / ar_merge.md
Created March 24, 2016 15:26
Active Record Merge

TIL #merge is a thing on AR models.

Useful for joining + using a named scoped on the joined table:

class Post; end
class Comment; scope :approved, -> {approved: true}; end
Post.joins(:comments).merge(Comment.approved)
@JoshTGreenwood
JoshTGreenwood / gist:443253f42fb80455792f
Created December 1, 2015 22:20
Automatically add magit cloned repos to the projectile project list
(defun add-project-to-projectile-known-projects (_ directory)
(projectile-add-known-project directory))
(advice-add 'magit-clone :after 'add-project-to-projectile-known-projects)
@JoshTGreenwood
JoshTGreenwood / _flash_messages.html.erb
Last active January 1, 2016 08:29 — forked from roberto/_flash_messages.html.erb
Flash messages for Bootstrap 3.
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
def fizzbuzz(n)
(1..n).each do |i|
if i % 15 == 0
puts 'fizzbuzz'
elsif i % 5 == 0
puts 'buzz'
elsif i % 3 == 3
puts 'fizz'
else
puts i.to_s
@JoshTGreenwood
JoshTGreenwood / bench.rb
Created October 31, 2012 00:34
Benchmark strip vs. chomp in ruby
require 'benchmark'
Benchmark.bmbm do |x|
x.report("Stripping /n with String.strip") { 100_000.times {"filename.rb\n".strip} }
x.report("Stripping /n with String.chomp") { 100_000.times {"filename.rb\n".chomp} }
end
@JoshTGreenwood
JoshTGreenwood / .spacemacs
Created May 30, 2015 01:02
Spacemacs not starting correctly
;; -*- mode: dotspacemacs -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration."
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '()
@JoshTGreenwood
JoshTGreenwood / Part 1
Created September 15, 2014 02:29
Microcomputer Design Lab 1
OPT MEX expand macro calling
OPT SEX expand structured statements
CODE EQU 0 define code and text sections
TEXT EQU 1
CR EQU $0D define CR and LF
LF EQU $0A
SECTION TEXT
ORG $800 sets the address for text code