Skip to content

Instantly share code, notes, and snippets.

Chris Bloom chrisbloom7

Block or report user

Report or block chrisbloom7

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisbloom7
chrisbloom7 / ex_passing_slices_and_arrays_by_val.go
Created Jun 4, 2019
Surprising behavior when passing arrays and slices to functions in Go
View ex_passing_slices_and_arrays_by_val.go
package main
import (
"fmt"
)
var a1 = [3]int{1, 2, 3}
var s1 = a1[0:3]
func main() {
@chrisbloom7
chrisbloom7 / prime.rb
Created May 22, 2019
Detecting prime numbers in Ruby
View prime.rb
# A prime is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers
def prime?(int)
# A prime is a natural number greater than 1...
return false if int < 2
# Is _int_ evenly divisible by any number 2 -> int-1?
(2..(int - 1)).each do |divisor|
return false if int % divisor == 0
end
return true
View Doubly Linked List implementation in Ruby.md

Doubly Linked List implementation in Ruby

Setup

  • Install Ruby ~> 2.6
  • gem install rspec
  • Open an IRB session with irb -r ./linked_list.rb
list = LinkedList.new
@chrisbloom7
chrisbloom7 / A ruby module to assist in capturing stdout and stderr from a detached thread in jRuby.md
Last active Apr 9, 2019
Ruby module to assist in capturing stdout/stderr from a detached thread
View A ruby module to assist in capturing stdout and stderr from a detached thread in jRuby.md

A ruby module to assist in capturing stdout/stderr from a detached thread in jRuby

  1. create some temp files (but not Tempfiles since they would be GC'd too quickly)
  2. append standard file descriptor redirects to the commands that we'll run in the detached spawned process, i.e. 1>>stdout_tempfile_path 2>>stderr_tempfile_path
  3. tack on a final command that will trigger copying the files to S3 regardless of exit status of original commands, i.e. {original commands with io redirection &&'d together}; bundle exec rake cleanup_task
  4. cleanup other io redirection temp files older than some threshold

Example usage:

@chrisbloom7
chrisbloom7 / I18n for Panini.md
Last active Apr 9, 2019
Adding a MailChimp Template Language (MTL) based I18n helper for Panini templates
View I18n for Panini.md

i18n for Panini

Requirements

Other than the default Panini pieces, you will also need to make sure that lodash is included as a devDependencies in your package.json

Usage

Tag a section of text as translatable. The section will be replaced with a set of if/elseif/else Merge Tags for each translation provided, otherwise only the wrapped content is displayed.

@chrisbloom7
chrisbloom7 / rake_benchmark.rb
Created Jun 8, 2016 — forked from harley/rake_benchmark.rb
Benchmarking a rake task
View rake_benchmark.rb
# Put this in Rakefile (doesn't matter where)
require 'benchmark'
class Rake::Task
def execute_with_benchmark(*args)
bm = Benchmark.measure { execute_without_benchmark(*args) }
puts " #{name} --> #{bm}"
end
alias_method :execute_without_benchmark, :execute
@chrisbloom7
chrisbloom7 / Gemfile
Last active Aug 29, 2015
TestUnit setup/teardown order in Ruby 2.1 with shoulda-context, factory_girl_rails and database_cleaner
View Gemfile
source 'https://rubygems.org'
ruby '2.1.4'
gem 'rails', '~> 3.2.0'
gem 'mysql2'
group :development, :test do
gem 'byebug'
@chrisbloom7
chrisbloom7 / .rails_aliases
Last active Jan 31, 2019
Bash shortcuts for routing Rails commands through the binstubs if they are present, or fallback to the other version-dependent methods
View .rails_aliases
# RUBY / RUBY ON RAILS COMMANDS
alias bexec='bundle exec'
alias rails_mv="bexec rails -v | sed 's/Rails \([0-9]\).*/\1/g'"
# Alias the rake command to Spring binstubs or fallback to "bundle exec"
# http://goo.gl/HkhHAf, http://goo.gl/STtIvF
function brake {
if [ -f bin/rake ]
then
bin/rake "$@"
else
@chrisbloom7
chrisbloom7 / Capfile
Last active Jun 14, 2016 — forked from toobulkeh/deploy.rb
Open a Rails console via Capistrano 3 (requires capistrano-rvm gem)
View Capfile
require 'capistrano/rvm'
View rspec_model_testing_template.rb
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
You can’t perform that action at this time.