Skip to content

Instantly share code, notes, and snippets.

Avatar

Henrik Nyh henrik

View GitHub Profile
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View climate_control_helpers.rb
module ClimateControlHelpers
# Usage:
#
# describe Foo do
# stub_envs(
# FOO: "bar",
# )
#
# it "uses the ENVs"
# end
@henrik
henrik / send_im.sh
Last active February 26, 2023 15:58
Raycast script command to send a Messages.app IM to a fixed contact, or just switch to Messages if no argument is provided. Don't forget to customize `theEmail`.
View send_im.sh
#!/usr/bin/env osascript
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Send IM
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 💬
# @raycast.author Henrik Nyh
@henrik
henrik / rspec_stub_env.rb
Last active February 23, 2023 15:57
Stub ENVs in RSpec.
View rspec_stub_env.rb
def stub_env(key, value)
is_set_up_flag = "__stub_env_is_set_up"
unless ENV[is_set_up_flag]
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:[]).with(is_set_up_flag).and_return(true)
end
@henrik
henrik / README.md
Created January 1, 2021 19:05
IRCC codes for Sony Bravia KD55XH9296BU. For my own reference for future automation.
View README.md
@henrik
henrik / stub_rails_env.rb
Created February 2, 2012 19:55
Stubbing Rails environment in tests.
View stub_rails_env.rb
Rails.stub!(:env).and_return(ActiveSupport::StringInquirer.new("production"))
@henrik
henrik / yahoo_exchange_rates_jsonp.html
Created December 28, 2009 22:48
JavaScript to get currency exchange rates from Yahoo Finance as JSONP. No XHR!
View yahoo_exchange_rates_jsonp.html
Get exchange rate as JSONP via YQL.
YQL Console: http://developer.yahoo.com/yql/console
Query (USD to SEK): select rate,name from csv where url='http://download.finance.yahoo.com/d/quotes?s=USDSEK%3DX&f=l1n' and columns='rate,name'
Example code:
<script type="text/javascript">
@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
View hash_deep_diff.rb
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@henrik
henrik / ocr.markdown
Created March 3, 2012 17:07
OCR on OS X with tesseract
View ocr.markdown

Install ImageMagick for image conversion:

brew install imagemagick

Install tesseract for OCR:

brew install tesseract --all-languages

Or install without --all-languages and install them manually as needed.

@henrik
henrik / luhn_checksum.rb
Created November 30, 2011 17:02
Luhn checksum/check digit generation in Ruby.
View luhn_checksum.rb
class Luhn
def self.checksum(number)
digits = number.to_s.reverse.scan(/\d/).map { |x| x.to_i }
digits = digits.each_with_index.map { |d, i|
d *= 2 if i.even?
d > 9 ? d - 9 : d
}
sum = digits.inject(0) { |m, x| m + x }
mod = 10 - sum % 10
mod==10 ? 0 : mod