Skip to content

Instantly share code, notes, and snippets.

View mgreenly's full-sized avatar

Michael Greenly mgreenly

View GitHub Profile
qty, size, bonus = "3d6-1"
.match(/^(\d+)d(\d+)([+-]\d+)?/)
.captures
.map(&:to_i)
class Record
class MissingField < Error; end
class << self
def build(hash)
new(*members.map{|m| hash[m.to_s] })
end
end
def initialize(*values)
self.class.members.zip(values).each do |member, value|
raise MissingField, "Unable to initialize #{self.class}, missing field: '#{member}'." if value.nil?

Quick and dirty https://www.purescript.org/ sample.

create a directory and enter it.

mkdir sample
cd sample

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

class Job
def self.fetch
return new if rand(100) > 85 # only return a job 15% of the time
end
attr_reader :count
def initialize
@count = rand(5) # some random data
end
@mgreenly
mgreenly / init-dev
Last active September 15, 2020 03:14
#!/bin/sh
# $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
fi
{-# 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
# 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') }
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 http://deb.debian.org/debian buster-backports main
firmware-amd-graphics
#!/bin/bash
# always try to start notes
session_name="!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
@mgreenly
mgreenly / foo.rb
Last active February 28, 2020 05:51
Rules = {
enter: [ 'created' ],
exit: [ 'completed' ],
uncancelable: %w[ completing completed ],
tasks: [
{
name: 'tag',
desc: 'taggable',
transitions: [
{ from: { state: 'tagging', :status: 'pending' }, to: { state: 'tagged' } },