Skip to content

Instantly share code, notes, and snippets.

View mgreenly's full-sized avatar

Michael Greenly mgreenly

View GitHub Profile
# 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' } },
require 'pp'
Rules = [
{
is: { state: 'created', status: 'pending', provider: 'aws' },
in: 'taggable',
to: { state: 'tagged' },
as: { state: 'tagging' },
on: 'housekeeper'
},
require 'concurrent'
MAX_THREADS = 20
class Job
def step
sleep 3 # simulates performing the next task in the jobs workflow
end
end
#
# The key thing to understand about this is that an `ensure` section is not guarnteed to run!
#
# If code executing is in the main thread of the process and a Interrupt, caused by a SIGINT or SIGTERM, occurs
# `ensure` blocks in that thread will not be executed. This is because Interrupt is an asynchrnous event and
# Ruby has no way to return to the point in execution it left when the signal happened.
#
# But, because Interrupts are only processed in the main thread of a process, moving all the actual code of an
# application into a child thread fixes this problem.
#
# inherit from Enumerator
class Pager1 < Enumerator
def initialize(url, page_size: 100, max_pages: Float::INFINITY, first_page: 0)
@url = url
super() do |receiver|
page = first_page
pages = []
while page < (first_page + max_pages)
get(page, page_size).each do |row|
receiver.yield row
@mgreenly
mgreenly / tmux.sh
Last active November 17, 2019 17:23
#!/bin/sh
tmux has-session -t notes > /dev/null 2>&1
if [ $? != 0 ]; then
echo 'starting session: notes'
tmux new-session -s notes -d
tmux rename-window -t notes notes
tmux send-keys -t notes "vim $DROPBOX_DIR/documents/notes.txt" C-M
fi
require 'logger'
# This logger will notice the log has been rotated and reopen it.
# The logrotate options must include 'nocreate'.
class RotatableLogger < Logger
def add(*args)
reopen if @logdev.filename && !File.exist?(@logdev.filename)
super
end
end