Skip to content

Instantly share code, notes, and snippets.

🦆 🦆 🦆 🦆

Henrik Nyh henrik

🦆 🦆 🦆 🦆
View GitHub Profile
henrik /
Last active Aug 27, 2015
Thoughts on how to show a server-side CET time as CET in a JS client no matter which time zone the browser has.

Option 1: send strings in the API

API changes:

  ends_at_string: "4 maj kl. 12:31 CET"
    - timestamp_string_short: "4 maj kl. 12:31"
    - timestamp_string_long: "4 maj 2015 kl. 12:31 CET"
henrik / lib-i18n_raise_on_missing_in_action_view.rb
Last active Aug 29, 2015
Overwrite `t` helper in Rails views to raise in tests, which it otherwise doesn't do, even if I18n is configured to.
View lib-i18n_raise_on_missing_in_action_view.rb
# Overwrite `t` helper in Rails views to raise in tests,
# which it otherwise doesn't do, even if I18n is configured to.
# Installation:
# put in lib/i18n_raise_on_missing_in_action_view.rb
# and require "i18n_raise_on_missing_in_action_view" in e.g. config/environments/test.rb
if Rails.env.test?
module ActionView::Helpers::TranslationHelper
def t_with_raise(*args)
henrik / automatically_rename_event_titles_in_iphoto.rb
Last active Aug 29, 2015
An awful hack (not cleaned up) to programmatically rename events (adding number prefixes to follow a certain schema) in iPhoto even though it doesn't seem to support that via AppleScript. Exploiting the convenient keyboard shortcuts.
View automatically_rename_event_titles_in_iphoto.rb
NUMBER = DATA.readlines.inject({}) { |h, line|
number, name = line.chop.split(". ", 2)
h[number] = name
def osascript(cmd)
system "osascript", "-e", cmd
View ID3 Track Numbers from Filename Prefixes.scpt
"ID3 track numbers from filename prefixes" for iTunes
By Henrik Nyh,, 2007-01-14.
Based on "Filenames to Song Names" by Doug Adams.
tell application "iTunes"
if kind of container of view of front window is not library or selection of front browser window is {} then
display dialog "Select some tracks in iTunes first." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
View const_missing_experiment.rb
class Module
def const_missing(const_name)
puts "[ModuleConstMissing] #{self} missing #{const_name}"
class FakeDelegator < BasicObject
def self.const_missing(name)
puts "[FakeDelegator] missing #{name}"
if ::Object.const_defined?(name)
henrik / lib-rails_compatible_simple_delegator.rb
Last active Aug 29, 2015
Stick this in the lib directory and use it instead of SimpleDelegator to solve this issue:
View lib-rails_compatible_simple_delegator.rb
# See:
# *
# *!topic/rubyonrails-core/PjGUK72BmFA
# *
require "delegate"
class RailsCompatibleSimpleDelegator < SimpleDelegator
def self.const_missing(name)
if ::Object.const_defined?(name)
View 0-mime-type.rb
class MIME::Type
# Compares the MIME::Type based on how reliable it is before doing a
# normal <=> comparison. Used by MIME::Types#[] to sort types.
def priority_compare(other), other).value
# 1. Get the source however you like
tar xfz ruby-2.1.1.tar.gz
cd ruby-2.1.1

# 2. Apply this patch! This is the interesting part.
curl | patch -p0

# 3. Build it however you like
henrik /
Last active Aug 29, 2015
Anteckningar från Agila Sverige 2014

Anteckningar från Agila Sverige 2014


Teknisk skuld (Henrik Kniberg, Crisp)

  • Definition of Done kan säga "no added technical debt"
  • Definition of Done kan t.o.m. säga "less technical debt"
  • Notera tillfällig skuld i en debt backlog och betala av den enligt någon princip, t.ex. 80 % nyutveckling och 20 % betala av skuld
  • En kreativ röra är okej kortsiktigt (jfr. stökigt kök i matlagning)
henrik / exception_notifier.rb
Last active Aug 29, 2015
ExceptionNotifier class to notify devs about exceptions and unexpected situations via Honeybadger.
View exception_notifier.rb
# Notify devs about an actual exception, or unexpected situation,
# without necessarily letting it appear to the user as a 500 error.
# Decouples the rest of the app from the specific exception logger service.
# Suggested location in a Rails project: lib/
class ExceptionNotifier
def self.notify(exception)