Skip to content

Instantly share code, notes, and snippets.

{
"public_identifier": "richard-logwood",
"profile_pic_url": "https://s3.us-west-000.backblazeb2.com/proxycurl/person/richard-logwood/profile?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=0004d7f56a0400b0000000001%2F20230727%2Fus-west-000%2Fs3%2Faws4_request&X-Amz-Date=20230727T001314Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=9e91441d14f3b012def5c567bc1667220b61f0c889306b180a728046b6706b84",
"background_cover_image_url": "https://s3.us-west-000.backblazeb2.com/proxycurl/person/richard-logwood/cover?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=0004d7f56a0400b0000000001%2F20230727%2Fus-west-000%2Fs3%2Faws4_request&X-Amz-Date=20230727T001314Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=f2375aa97fdc04d14a109a88edbac78297aa57ed41a58fbc176d6058cdcc5292",
"first_name": "Richard",
"last_name": "Logwood",
"full_name": "Richard Logwood",
"follower_count": 202,
"occupation": "Software Engineer at Adaptive Financial Consulting",
"headline": "Full Stack Software Enginee
@rlogwood
rlogwood / monitor_dim.rb
Created January 16, 2023 18:25
utility to quickly dim or brighten all monitors on linux with xrandr
#!/usr/bin/env ruby
# frozen_string_literal: true
LOWEST=0.3
HIGHEST=4
def sys(cmd, *args, **kwargs)
puts("*** running: \e[1m\e[33m#{cmd} #{args}\e[0m\e[22m")
system(cmd, *args, exception: true, **kwargs)
@rlogwood
rlogwood / fiber_scheduling_example.rb
Created March 2, 2022 23:07
Simple demonstration of ruby fiber scheduler
# quick demo of fiber scheduling
# Ruby 3.1.1
# see https://brunosutic.com/blog/ruby-fiber-scheduler
# see https://rubyapi.org/3.0/o/fiber/schedulerinterface
# see https://github.com/bruno-/fiber_scheduler_list
# using a default implementation of fiber_scheduler via
# gem install fiber_scheduler
require 'fiber_scheduler'
module BenchIt
require 'benchmark'
ITERATIONS = 100_000
def self.run_benchmark_multi(methods, arg_arrays, iterations=ITERATIONS, verbose=false)
methods.each do |method|
puts "\n#{method} iterations:#{iterations}:\n"
Benchmark.bm do |x|
x.report do
iterations.times do |i|
@rlogwood
rlogwood / Gemfile
Last active February 2, 2022 21:08
Example code from RubyConf 2021 talk "Async Ruby" by Bruno Sutic https://www.youtube.com/watch?v=pzpH_ND-CQM
source "https://rubygems.org"
gem 'open-uri'
gem 'async'
gem 'async-http'
gem 'httparty'
gem 'redis'
# gem 'net-ssh'
gem 'sequel'
8:37:40 web.1 | started with pid 360745
18:37:40 worker.1 | started with pid 360746
18:37:40 js.1 | started with pid 360747
18:37:40 css.1 | started with pid 360748
18:37:40 css.1 | yarn run v1.22.15
18:37:40 js.1 | yarn run v1.22.15
18:37:40 css.1 | $ sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch
18:37:40 js.1 | $ node esbuild.config.js --watch
18:37:40 css.1 | Sass is watching for changes. Press Ctrl-C to stop.
18:37:40 css.1 |
@rlogwood
rlogwood / music_controller.js
Last active October 21, 2021 22:03
Managing Stimulus state with a static helper class
import { Controller } from "@hotwired/stimulus"
import { PlaybackManager } from "../helpers/playback_manager";
export default class MusicController extends Controller {
static values = {
previewUrl: String
}
@rlogwood
rlogwood / application.html.erb
Last active October 20, 2021 14:49
Example Stimulus Page Reloader Controller for Rails 7
<!DOCTYPE html>
<html>
<head>
<title>RefresherDemo</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>
@rlogwood
rlogwood / template.rb
Last active July 16, 2021 23:21
Rails ActiveRecord Example: Book has an Author and Plot, Author has many Books, Plot has many Books
# frozen_string_literal: true
DEFAULT_FIELD_IDS = <<-'RUBY'
<div class="field">
<%= form.label :author_id %>
<%= form.text_field :author_id %>
</div>
<div class="field">
<%= form.label :plot_id %>
{
"name": "app_name_here",
"private": true,
"engines": {
"yarn": "1.22.10",
"node": "14.16"
},
"dependencies": {
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",