Skip to content

Instantly share code, notes, and snippets.


Michael Greenly mgreenly

View GitHub Profile
View record.rb
class Record
class MissingField < Error; end
class << self
def build(hash)
new(*{|m| hash[m.to_s] })
def initialize(*values) do |member, value|
raise MissingField, "Unable to initialize #{self.class}, missing field: '#{member}'." if value.nil?

Quick and dirty sample.

create a directory and enter it.

mkdir sample
cd sample

Use npm to install purescript and it's package manager spago.

View limited_polling_workers.rb
class Job
def self.fetch
return new if rand(100) > 85 # only return a job 15% of the time
attr_reader :count
def initialize
@count = rand(5) # some random data
View init-dev
# $1 is session/window name
# $2 is command to run in that session
mk_tmux_session() {
if [ -z "$1" ]; then
echo 'usage: startdev NAME'
exit 1
View proxy.hs
{-# LANGUAGE RecordWildCards #-}
import Data.Maybe
import Data.List
-- this defines the data type that will be read from the config file, all of the values are optional
data Proxy = Proxy
{ proxyKey :: Maybe String
, proxyUser :: Maybe String
View tuples.rb
# The point is that only functions and function application are required to create all
# higher level language abstractions. You can use church encoding to turn functions
# into numbers, boolean values, logical operators, math operators, and in this case
# data structures.
fst = -> (a,_) { a } # no matter what 2 values are passed in return the 1st
snd = -> (_,b) { b } # no matter what 2 values are passed in return the snd
# a tuple is a function, that takes a function as an argument and applies it to the constant values of the tuple
tuple1 = ->(f){ f.('alpha', 'omega') }
View gist:ca8d584a1872d49b5b33bfb95099592b
apt install linux-image-5.4.0-0.bpo.2-amd64 linux-headers-5.4.0-0.bpo.2-amd64
apt-get -t buster-backports install linux-image-5.4.0-0.bpo.2-amd64 linux-headers-5.4.0-0.bpo.2-amd64
sudo dd bs=4M if=debian-10.4.0-amd64-netinst.iso of=/dev/sde status=progress oflag=sync
/etc/init.d/network-manager start
deb buster-backports main
# always try to start notes
tmux has-session -t "$session_name" > /dev/null 2>&1
if [ $? != 0 ]; then
echo "starting session: $session_name"
tmux new-session -s "$session_name" -d
tmux rename-window -t "$session_name" "$session_name"
tmux send-keys -t "$session_name" "vim $DROPBOX_DIR/notes.txt" C-M
View foo.rb
Rules = {
enter: [ 'created' ],
exit: [ 'completed' ],
uncancelable: %w[ completing completed ],
tasks: [
name: 'tag',
desc: 'taggable',
transitions: [
{ from: { state: 'tagging', :status: 'pending' }, to: { state: 'tagged' } },
View generator.rb
require 'pp'
Rules = [
is: { state: 'created', status: 'pending', provider: 'aws' },
in: 'taggable',
to: { state: 'tagged' },
as: { state: 'tagging' },
on: 'housekeeper'