Skip to content

Instantly share code, notes, and snippets.

View twopoint718's full-sized avatar
⛵
yo

Christopher Wilson twopoint718

⛵
yo
View GitHub Profile
@twopoint718
twopoint718 / calbot.rb
Last active May 2, 2024 22:18
CalBot schedule your book reading for the year. Produces an iCal file for importing into your reading calendar.
#!/usr/bin/env ruby
require 'date'
require 'securerandom'
require 'optparse'
def header()
<<~EOS
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//SENCJW Heavy Industries, Ltd.//CalBot//EN
@twopoint718
twopoint718 / Reader.lhs
Last active April 21, 2024 11:15
An article about the Reader type (functor, applicative, and monad instances)
Okay, so I'll try and walk through the reader monad as best as I can. And
because I think it helps to de-mystify things a bit, I'll also go through
all of the "super classes" of monad: functor and applicative (because every
monad should also be an applicative and every applicative functor should be
a functor). This file is literate Haskell so you should just be able to
load it in the REPL or run it. It's also kinda/sorta markdown, so it should
render that way as well (but the code is formatted wrong).
> module Reader where
@twopoint718
twopoint718 / osm.html
Created March 29, 2024 22:18
Short example of using OpenStreetMap with Leaflet.js
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>OpenStreetMap with Leaflet.js</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
@twopoint718
twopoint718 / custom_types.sql
Created August 22, 2023 20:30
List custom types along with their enum values
-- list types and their enum values
SELECT
pg_type.typname AS enumtype,
array_agg(pg_enum.enumlabel) AS enumlabels
FROM
pg_type
JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid
GROUP BY pg_type.typname;
@twopoint718
twopoint718 / app.ru
Created June 9, 2023 21:28
Single-file Rails application
# Run with:
# $ rackup app.ru
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '~> 7.0.5'
gem 'puma'
end
@twopoint718
twopoint718 / dc_cheatsheet.md
Last active April 17, 2023 03:40
UNIX `dc` cheatsheet

DC Cheatsheet

Mathematical operators

Operator Stack effect notes
+ a b -- $a+b$
- a b -- $a-b$
* a b -- $a*b$
/ a b -- $\frac{a}{b}$
% a b -- $mod(a,b)$
@twopoint718
twopoint718 / cjw_grep.el
Created March 16, 2023 21:47
Wrapper for Emacs' default grep. It uses `git grep`, passes in the git project directory, and also uses the current symbol under cursor as a default.
(defun cjw-git-grep (my-word)
"Use git-grep for search in current project (vc-root-dir). Default
search term uses symbol under cursor"
(interactive
(list
(read-string
(format "Search (%s): " (thing-at-point 'symbol)) ; prompt
nil ; initial input
nil ; history list
(thing-at-point 'symbol) ; evaluated. will be default
@twopoint718
twopoint718 / Main.hs
Created November 7, 2015 21:35
Sending and receiving messages using rabbitmq and Haskell.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Exception
import Network.AMQP
import Test.Hspec
@twopoint718
twopoint718 / easter.rb
Created February 1, 2023 18:48
Calculate the date of Easter
def computus(year)
a = year % 19 # year in the 19-year metonic cycle
k = year / 100 # century index
p = (13 + 8*k) / 25 # shift of metonic cycle, add a day offset every 300 years
q = k / 4 # correction for non-observed leap days
m = (15 - p + k - q) % 30 # correction to starting point each century
d = (19*a + m) % 30 # num of days from 3/21 until full moon
n = (4 + k - q) % 7 # find next sunday; century-based offset in weekly calc.
b = year % 4 # correct for leap days
c = year % 7 # correct for leap days
@twopoint718
twopoint718 / jwt.rb
Last active December 19, 2022 20:46
Build a JWT on the command line
#! /usr/bin/env ruby
require 'optparse'
require 'base64'
require 'json'
require 'openssl'
require 'set'
options = {}
OptionParser.new do |parser|