Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@henrik
henrik / lgtv_turn_on.rb
Last active April 27, 2020 05:37
Ruby script to turn on a LGTV running WebOS 3, using "wake on LAN".
#!/usr/bin/ruby
# Based on: https://gist.github.com/dgv/2865897 and https://gist.github.com/zunda/187139
# Idea from: https://github.com/efpe/amazon-alexa-lg-tv
# In order for this to work, first go to the TV "General" settings and turn on "Mobile TV On".
# Change this to the actual value.
# First find the TV IP, e.g. from your router's list of connected devices.
# Then run "arp -a" on a computer and you'll see the MAC by its IP.
# Maybe you need to "ssh <the ip>" before it will turn up in arp. Not sure.
TV_MAC_ADDRESS = "xx:xx:xx:xx:xx:xx"
@henrik
henrik / wip_private_ruby.vim
Created September 2, 2017 17:30
WIP: Vim highlight private section of Ruby
function! Snake()
ruby << EOF
b = Vim::Buffer.current
line_count = b.length
indexed_lines = line_count.times.map { |i| [ i, b[i + 1] ] }
matches = indexed_lines.select { |i, line| line.match(/^\s+private$/) }
matches.each { |priv_i, priv_text|
re = /^#{priv_text.sub(" private", "end")}$/
@henrik
henrik / plug_conn_request_url.ex
Last active August 23, 2017 20:09
Elixir Plug request_url function.
defmodule Plug.Conn.RequestURL do
def request_url(conn) do
Enum.join([
conn.scheme,
"://",
conn.host,
shown_port(conn.scheme, conn.port),
conn.request_path,
shown_qs(conn.query_string),
])
@henrik
henrik / rightmove_full_images.js
Created June 25, 2017 08:53
Bookmarklet to get all full size images on Rightmove.
document.body.innerHTML = $("a[id^=thumbnail-] img").get().map(function(x) { return '<img src="' + x.src.replace(/_max_\d+x\d+/, "") + '" />' }).join()
@henrik
henrik / cyberattacks_info.md
Created May 15, 2017 10:22
The news bulletin about cyber attacks we sent to our company users.

You may have heard about cyber attacks in the news.

The data in <the service we provide> is well protected from attacks.

We also recommend that you protect your own computers, so you don't risk losing important data. You should do two things:

1. Back up important data. You can put important files in Dropbox or Google Drive, or back up your entire computer with something like Crashplan. In case of theft, catastrophy or the recent kind of cyber attacks, it's not enough to have backup only on your own machine (like Apple's "Time Machine"). You should have backups to "the cloud" (another computer on the Internet).

2. Keep your computers updated. Make sure automatic updates are turned on in Windows or macOS (also known as OS X). If your computer asks you whether it should be updated or restarted, make sure to do that within a few days. The recent cyber attacks could have been avoided if the computers had been u

@henrik
henrik / ruby_exhaustive_switch_case.rb
Last active August 22, 2017 11:25
Ruby switch/case that complains if you forget to cover a case. Inspired by types in Elm. Just a for-fun experiment; not intended for real use.
# By Henrik Nyh <https://henrik.nyh.se> under the MIT license.
class Enum
class Switch
def initialize(value_to_match_against, *values)
@checked_values = values.map { |v| [ v, false ] }.to_h
values.each do |value|
define_singleton_method(value) { |&block|
@checked_values[value] = true
@henrik
henrik / dokku_postgres_backups.sh
Last active December 18, 2016 19:07
For `dokku/dokku-postgres`. See https://gist.github.com/henrik/26bb73091712aa42abf2#db-backups for setup instructions.
#!/bin/bash
# For use with dokku/dokku-postgres.
# Based on https://gist.github.com/henrik/1043fecdd0937034cd62
set -e
base_dir="/var/backups/postgres"
mkdir -p $base_dir
ymd=$(date "+%Y-%m-%d")
@henrik
henrik / Z_output.txt
Last active December 2, 2016 13:36
Proof-of-concept of using `_` for Ruby class/module namespaces, with Rails-like autoloading, while avoiding the constant lookup gotchas of using `::`. Inspired by how namespaces work in Elixir (no magic; they're just module names that happen to share a prefix). This is the complexity of constant lookups in Ruby: http://cirw.in/blog/constant-look…
$ ruby example.rb
Hello from Foo_Bar!
example.rb:10:in `const_missing': uninitialized constant Foo_Baz (NameError)
Did you mean? Foo_Bar
from example.rb:20:in `<main>'
@henrik
henrik / bowers_and_wilkins_p5_wireless_audible_feedback.md
Last active November 20, 2016 22:41
Bowers & Wilkins don't seem to have documented the audible feedback sounds played by their P5 wireless headphones, so these are my guesses, as I figure them out. They may be useful in debugging disconnection issues, or just understanding what that weird sound was that suddenly played.

The sound transcriptions are best attempts by a madman and do not follow any convention…

Sound Meaning
BUM-pi-d-BA Turning on
dum-du-di-du! Connected (typically plays soon after turning on, when connected to the primary device)
DUNG-DING-DUNG Turning off (by button, or by not receiving input in 20 minutes)
pika-pika-DUM Battery level 60%? Have also heard this at 30% though…
pika-pika-DUM-DUM Battery level 30%?
du-du-du! Entered pairing mode

Sent this support request to B&W support.

My new P5 wireless headphones have worked flawlessly with my iPhone 6 since I got them a few days ago, but I'm seeing a lot of problems with them when connecting to my Mac.

I have a MacBook Pro (Retina, 13-inch, Late 2013) running macOS Sierra (10.12).

I'll describe the problems below. What I want to know is mostly: Are these known issues? Are they likely to be fixed in software updates? Do you know if they affect only some of your headphones (I've heard of other such issues), so a replacement might fix it? Any workarounds?

I'm a programmer, so techy workarounds are fine. I'm also happy to provide more details from logs or whatever. Let me know.