Skip to content

Instantly share code, notes, and snippets.

@rhomel
rhomel / main.go
Created June 23, 2023 08:20
Go generics factory function
package main
// My notes on trying to comprehend Go's generics.
// https://github.com/golang/proposal/blob/master/design/43651-type-parameters.md#pointer-method-example
// A trivial example to show how to make factory functions that can produce
// typed things.
import "fmt"
@rhomel
rhomel / rls-demo.sql
Created January 5, 2021 07:59
Postgres Row-Level Security (RLS) Demo
-- Postgres Row Level Security (RLS) Demo
--
-- Inspriration:
-- https://aws.amazon.com/blogs/database/multi-tenant-data-isolation-with-postgresql-row-level-security/
-- However the AWS example is a bit more complicated because they want each user
-- to be identified by a UUID probably for management purposes. This demo
-- presents a much simpler alternative for low numbers of users or environments.
--
-- Assumptions:
-- * An empty Postgres 12 database (older versions up to 9 may work but I have not tested them)
@rhomel
rhomel / es.exs
Last active September 18, 2020 10:31
Event Sourcing prototype with Elixir
# Example Event Sourcing aggregate implementation in Elixir
#
# This is literally the first code that I wrote with Elixir.
# So this may not be optimal or idiomatic Elixir.
#
# Note that I heavily use Elixir's pattern matching features.
#
# Run with:
# elixir es.exs
#
@rhomel
rhomel / 99-AnkerBT-keyboard.hwdb
Created August 3, 2019 13:00
Remap the function keys on an Anker slim bluetooth keyboard
# Invert Anker A7726 Keyboard FN Keys
#
# This is the keyboard I bought:
# https://www.amazon.co.jp/gp/product/B00U260UR0/
# But the fn keys default to media keys which is very annoying.
#
# This will make the FN media keys function as F keys without pushing the FN
# button. Also you can still use the media keys by pushing the FN + Media key
# combination.
#
@rhomel
rhomel / custom_defer.go
Created February 1, 2019 06:24
Custom Defer Implementation
package main
import (
"errors"
"fmt"
)
/*
Let's try to simulate defer manually.
@rhomel
rhomel / main.go
Created January 24, 2019 03:22
Experiments with GoLang Custom Types
package main
// Experiments with GoLang Custom Types
// Playground link: https://play.golang.org/p/rHu1CBj0GvE
import "fmt"
// We can create our own types based on the concrete types.
// But Go will not consider our type "MyString" as the same type as the concrete
// type "string"
@rhomel
rhomel / EnableSSHOnLittlebitsCloudbit.md
Last active February 20, 2022 07:05
Enable SSH on Littlebits Cloudbit

Gain SSH access to littlbits cloudbit

The guide at https://github.com/yepher/littlebits/blob/master/CloubitFileSystem.md is mostly correct but has a few mistakes. Luckily I found this page in Japanese http://qiita.com/chobie@github/items/d41cfa2d60df5d7d1a3f (and I can read Japanese) to point me in the right direction for the right way to do this.

Note: I used an Ubuntu linux machine to mount and edit the microsdcard.

You should also make a backup image of the SD card just in case.

Prepare a SHA-512 password hash