Skip to content

Instantly share code, notes, and snippets.

View fn comp.rb
Add = ->(add, n) { n + add }
Times = ->(times, n) { n * times }
AddOne = Add.curry.call(1)
TimesFour = Times.curry.call(4)
AddOneTimesFour = AddOne >> TimesFour
AddOneTimesFour.(2) # => 12
@krisleech
krisleech / rspec.rb
Last active Jul 6, 2020
RSpec gotcha
View rspec.rb
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "rspec"
gem "pry-byebug"
end
require 'rspec/autorun'
@krisleech
krisleech / spec.rb
Last active Jun 23, 2020
dry-Struct
View spec.rb
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "dry-struct", '0.5'
gem "dry-types", '0.14'
gem 'rails_event_store-rspec', '1.0.0'
gem "pry-byebug"
gem 'activesupport'
end
@krisleech
krisleech / stats.md
Last active Apr 20, 2020
Run + Blood Glucose
View stats.md
  • 10:30 BG 4.5 mmol/litre
  • Run:
    • 6k
    • 5:11 mins/km pace
    • Elevation gain: 76m
    • Max elevation: 107m
  • 11:10 BG 6.2 mmol.litre
  • Food (carbs)
  • 11:50 BG 5.5 mmol/litre
  • 12:30 BG 6.3 mmol/litre
@krisleech
krisleech / 00_README.md
Created Feb 18, 2020
Playing with Rails Event Store
View 00_README.md
ruby basic.rb

ruby aggregate_root.rb
@krisleech
krisleech / service_authorized.rb
Created Feb 17, 2020
services and action policy
View service_authorized.rb
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "rspec"
gem "action_policy"
gem "pry-byebug"
end
require "action_policy"
@krisleech
krisleech / ActionPolicy_and_SimpleDelegator.md
Created Feb 17, 2020
ActionPolicy and SimpleDelegator
View ActionPolicy_and_SimpleDelegator.md

Problem: When wrapping a model using SimpleDelegator and passing to authorize! an undefined method _policy_cache_key error occurs.

This is, I think, because ActionPolicy uses refinements to add a method _policy_cache_key to Object.

However SimpleDelegator does not inherit from Object, but maybe BasicObject.

To fix this we need to pass the unwrapped model to authorize! or add the missing method, _policy_cache_key, to our wrapper object.

In controller or mutation:

@krisleech
krisleech / EXAMPLE.md
Last active Feb 14, 2020
Inline Gemfile for learning and reporting bugs
View EXAMPLE.md
require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'activerecord'
  gem 'sqlite3'
  gem 'rspec'
  gem 'pry'
end
@krisleech
krisleech / HOWTO_PUSH_TO_SPEAK_MUTE.md
Created Jan 11, 2020
Push to Speak, via command line
View HOWTO_PUSH_TO_SPEAK_MUTE.md

This works for all mics including webcam mics.

bin/mic-on

#!/usr/bin/env bash

# toggle webcam mic
amixer -c 1 sset Mic cap
# toggle default mic
@krisleech
krisleech / HOWTO
Created Jan 11, 2020
UTAXO bluetooth headphone Ubuntu
View HOWTO
Hold power button for 5 seconds to enter pairing mode
Open Bluetooth Devices and press Search
Right click UTAXO UT-BH001 and click Pair
Right click UTAXO UT-BH001 and press Add audio sink
Set volume in PulseAudio Volume Control (pavucontrol)