Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jahfer on github.
  • I am jahfer (https://keybase.io/jahfer) on keybase.
  • I have a public key whose fingerprint is 989C AA71 4413 EC42 E630 D847 EA0E 7143 55D3 C19E

To claim this, I am signing this object:

@jahfer
jahfer / active_record_test_logger.rb
Last active November 26, 2019 14:34
Small tweak to output Active Record logs inside of a test with the stacktrace attached
module MyLogSubscriber
def sql(*args)
trace = caller
Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer { |line| not line =~ /^(components)\// }
puts Rails.backtrace_cleaner.clean(trace)
super
puts "---------------"
end
end
@jahfer
jahfer / arraynavigation.js
Created December 18, 2012 05:15
Sometimes you need to look ahead or behind the current element you're on when iterating through an array. This is a neat trick for doing that quickly, without stepping outside the bounds of your array.
var arr = ['a','b','c'];
// 1. LOOKING AHEAD
// -----------------------------
for (var i=0; i<arr.length; i++) {
var next = arr[ (i+1) % arr.length ]; // <= THE MAGIC
console.log(arr[i], "->", next);
}
@jahfer
jahfer / pubsub.swift
Created June 3, 2014 02:45
Simple pubsub implementation in Swift
// =====================================================
enum LogLevel: Int {
case Debug = 1, Info, Error
}
let log_level = LogLevel.Debug
protocol Loggable {
func log()