Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
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`.
#!/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 / README.md
Created January 1, 2021 19:05
IRCC codes for Sony Bravia KD55XH9296BU. For my own reference for future automation.
@henrik
henrik / stub_rails_env.rb
Created February 2, 2012 19:55
Stubbing Rails environment in tests.
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!
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 / luhn_checksum.rb
Created November 30, 2011 17:02
Luhn checksum/check digit generation in Ruby.
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
@henrik
henrik / amazon_referralizer.rb
Created July 5, 2010 18:26
Ruby class to add your Amazon Associates referral id to an Amazon URL, replacing any that were already there. See http://github.com/henrik/delishlist.com/blob/master/lib/amazon_referralizer.rb for the latest version.
# Amazon::Referralizer
# by Henrik Nyh <http://henrik.nyh.se> 2010-07-05 under the MIT license.
# Add your Amazon Associates referral id to an Amazon URL, replacing any that were already there.
#
# E.g.:
#
# Amazon::Referralizer.referralize("http://amazon.co.uk/o/ASIN/B00168PO6U/evil-20", "good-20")
# # => "http://amazon.co.uk/o/ASIN/B00168PO6U/good-20"
#
@henrik
henrik / _USAGE.md
Created September 1, 2012 18:56
Run some JS in Chrome from the command line and get the return value. Useful for scrapers that require JS and perhaps a session that's tricky to set up otherwise.

This AppleScript opens a page in Chrome (where you presumably have a logged-in session if required), opens the passed-in URL, runs the passed-in JavaScript and returns the JS return value.

Waits for 1 second for the page to load before executing the JS. Optionally, pass in a third argument with the number of seconds to wait.

Examples:

osascript js_in_chrome.scpt "http://google.com" "document.title"

When logged in.

@henrik
henrik / sonos_sub_toggle.sh
Last active October 26, 2022 22:41
Bash script to toggle the Sonos subwoofer via soco-cli.
# Uses https://github.com/avantrec/soco-cli via https://pypa.github.io/pipx/.
# I map this to a HTPC keyboard key via Alfred.app.
if [ `soco -l "Front room" sub_enabled` == "on" ]; then
soco -l "Front room" sub_enabled off : "Front room" light off
say -vDaniel "Sub off"
else
soco -l "Front room" sub_enabled on : "Front room" light on
say -vDaniel "Sub on"
fi
@henrik
henrik / gist:3181718
Created July 26, 2012 12:15
Fix "unsupported new OS, trying as if it were 10.6-10.7" from reattach-to-user-namespace on Mountain Lion (probably in tmux).
# Start by checking if they fixed it upstream:
brew update
brew upgrade reattach-to-user-namespace
# If it says it's already installed, they haven't fixed it upstream. So do this:
# Edit the recipe:
brew edit reattach-to-user-namespace