Skip to content

Instantly share code, notes, and snippets.

@wycleffsean
wycleffsean / kakrc
Created September 6, 2022 15:27
kakrc
evaluate-commands %sh{
plugins="$kak_config/plugins"
mkdir -p "$plugins"
[ ! -e "$plugins/plug.kak" ] && \
git clone -q https://github.com/andreyorst/plug.kak.git "$plugins/plug.kak"
printf "%s\n" "source '$plugins/plug.kak/rc/plug.kak'"
}
plug "andreyorst/plug.kak" noload
plug "andreyorst/fzf.kak" config %{
@wycleffsean
wycleffsean / wezterm.lua
Last active December 14, 2021 00:44
wezterm
local wezterm = require 'wezterm';
return {
enable_wayland = true,
warn_about_missing_glyphs = false,
cursor_blink_rate = 800,
default_cursor_style = "BlinkingBlock",
-- font = wezterm.font('Inconsolata-g for powerline'),
-- font = wezterm.font("Fira Code"),
-- font = wezterm.font_with_fallback({"Fira Code"}),
@wycleffsean
wycleffsean / todo
Last active November 12, 2020 19:30
TODO
#!/usr/bin/env ruby
# vim: set filetype=ruby :
require 'date'
plan = File.read(File.expand_path('~/.plan'))
date = nil
indent = 0
@wycleffsean
wycleffsean / async_kitchen.rb
Created October 2, 2020 05:32
Cooperative concurrency in ruby
require 'fiber'
class EventLoop
def initialize
@tasks = {}
@state = {}
end
def call(&block)
instance_eval &block
@wycleffsean
wycleffsean / deferred_connection_handling.rb
Last active July 15, 2020 18:53
Defer class code until a db connection is established
# Enable class level code to lazily access database information.
# Often ActiveRecord class definitions will rely upon the table schema
# information. For example the following snippets would acquire a database
# connection:
# ignore_columns :foo
# # or
# attribute_names.each ...
# This results in rails accessing the database when booting, resulting in
# ridiculous behavior like this:
# bin/rake db:setup
@wycleffsean
wycleffsean / tcp_proxy.sh
Created February 12, 2020 23:01
TCP Proxy
#!/bin/sh -e
if [ $# != 3 ]
then
echo "usage: $0 <src-port> <dst-host> <dst-port>"
exit 0
fi
TMP=`mktemp -d`
BACK=$TMP/pipe.back
@wycleffsean
wycleffsean / advisory_lock.rb
Created January 9, 2020 22:55
ActiveRecord Advisory Lock
module AdvisoryLock
class LockUnavailableError < StandardError; end
def with_advisory_lock(name = nil, timeout, &block)
raise LocalJumpError, 'no block given (yield)' unless block_given?
name ||= lock_name
args = {
name: ActiveRecord::Base.sanitize(name),
timeout: ActiveRecord::Base.sanitize(timeout),
}
@wycleffsean
wycleffsean / docker-compose.yml
Created December 23, 2019 23:49
Faster test runs in CircleCI
services:
# run db on tmpfs to speed up test runs
mysql:
image: mysql:5.7
tmpfs:
- /var/lib/mysql
@wycleffsean
wycleffsean / arel_activerecord_extensions.rb
Created September 24, 2019 07:02
Arel ActiveRecord extensions
module DatabaseOperations
module Function
module_function
def coalesce(*args)
Arel::Nodes::NamedFunction.new('COALESCE', args)
end
end
module Atomic
def atomic_increment(name, count = 1)
@wycleffsean
wycleffsean / activerecord_graphviz.rb
Created August 23, 2019 16:49
Generate Entity Relationship Model for ActiveRecord with GraphViz
namespace :graph do
desc 'build graph of AR models'
task models: :environment do
require 'graphviz'
Rails.application.eager_load!
g = GraphViz.new('Models', path: Rails.root.join('tmp').to_s)
nodes = ObjectSpace.each_object(Class)