Skip to content

Instantly share code, notes, and snippets.

Avatar
🦆
🦆 🦆 🦆 🦆

Henrik Nyh henrik

🦆
🦆 🦆 🦆 🦆
View GitHub Profile
@henrik
henrik / tz_thoughts.md
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.
View tz_thoughts.md

Option 1: send strings in the API

API changes:

item:
  ends_at_string: "4 maj kl. 12:31 CET"
  bids:
    - timestamp_string_short: "4 maj kl. 12:31"
    - timestamp_string_long: "4 maj 2015 kl. 12:31 CET"
@henrik
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
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
h
}
def osascript(cmd)
system "osascript", "-e", cmd
end
View ID3 Track Numbers from Filename Prefixes.scpt
(*
"ID3 track numbers from filename prefixes" for iTunes
By Henrik Nyh, http://henrik.nyh.se, 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}"
end
end
class FakeDelegator < BasicObject
def self.const_missing(name)
puts "[FakeDelegator] missing #{name}"
if ::Object.const_defined?(name)
@henrik
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: http://thepugautomatic.com/2014/03/simpledelegator-autoloading-issues-with-rails/
View lib-rails_compatible_simple_delegator.rb
# See:
# * http://thepugautomatic.com/2014/03/simpledelegator-autoloading-issues-with-rails/
# * https://groups.google.com/forum/#!topic/rubyonrails-core/PjGUK72BmFA
# * https://gist.github.com/henrik/9314943
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)
PriorityComparison.new(self, other).value
end
end
View USAGE.md
# 1. Get the source however you like
wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
tar xfz ruby-2.1.1.tar.gz
cd ruby-2.1.1

# 2. Apply this patch! This is the interesting part.
curl https://gist.githubusercontent.com/henrik/10880288/raw/fe228cf0524873c992fa5c31b1173537dca76a2c/patch.diff | patch -p0

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

Anteckningar från Agila Sverige 2014

Talks

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
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)
Honeybadger.notify(exception)