Skip to content

Instantly share code, notes, and snippets.

@mgmarlow
mgmarlow / getbooks
Last active May 24, 2023 02:21
Export Oku book collection as json
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
user=mgmarlow
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo 'Usage: getbooks (read|to-read|reading)'
@mgmarlow
mgmarlow / .dir-locals-el
Created February 20, 2023 00:12
Deno and lsp-mode
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")
;; Note: requires the following configuration so that local variables
;; run before the server is initialized:
;; https://emacs-lsp.github.io/lsp-mode/page/faq/#how-to-configure-a-server-with-local-variables
;;
;; (add-hook 'hack-local-variables-hook
;; (lambda () (when (derived-mode-p 'web-mode) (lsp))))
@mgmarlow
mgmarlow / init.el
Last active November 29, 2023 00:12
Emacs 29 better defaults
;;;; Better defaults for Emacs to help get new users up and running quickly.
;;;; This configuration is meant to help solve some common usability problems,
;;;; particularly with Emacs's default completion framework, cluttered UI,
;;;; and package installation. Inspired by the Better Defaults repo:
;;;; https://git.sr.ht/~technomancy/better-defaults.
;;;;
;;;; Annotations are included for various options, but I recommend using
;;;; the built-in Emacs help to learn more about each configuration setting.
;;;; For example, `C-h v` or `M-x describe-variable`.
Play at https://www.puzzlescript.net/play.html?p=b1064a9310cf2229c039f34558911165
@mgmarlow
mgmarlow / README.md
Last active January 25, 2022 01:24
Simple Riichi

Tips for Riichi Mahjong newcomers.

  • Focus on tile efficiency and learning to recognize Yaku over attaining high-valued Yaku.
  • Keep your hand closed unless you have an open hand in mind. This allows you to focus on tile efficiency and gain Yaku by calling Riichi.
  • Tiles at the center of the sequence (4, 5, 6) are most valuable. They easily evolve into waits that are very flexible.
  • Tiles that a player discards early are less likely to be relevant to their ending hand.
  • Don't collect too many pairs. You'll end up having to deconstruct or play around them to make a valid hand. The Riichi Book recommends a max of 2 for a closed hand. Complete one pair and the other becomes the head.
  • Try not to go into tenpai with a head wait. You can form much nicer waits around sequences or double-pon that will be easier to complete.
  • Discarding middle
@mgmarlow
mgmarlow / dfs.res
Last active January 19, 2022 22:40
DAG DFS with labeled edges
// Implementing DFS by keeping track of colors and times that nodes are
// visited. This allows the algorithm to identify edges as forward edges,
// cross edges, or back edges.
// https://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/GraphAlgor/depthSearch.htm
let adj_list = Js.Dict.fromArray([
("A", ["C", "D", "B", "H"]),
("B", ["E"]),
("D", ["E"]),
("C", ["E", "G"]),
@mgmarlow
mgmarlow / urlParsing.js
Last active April 1, 2021 22:11
URLSearchParams Strategy
// Extend URLSearchParams to easily add helper methods
class URLParser extends URLSearchParams {
getPage() {
return Number(this.get(FilterNames.PAGE)) || 1
}
}
// Don't pass directly into async thunks
function useURLParser() {
const { search } = useLocation()
@mgmarlow
mgmarlow / currying.js
Last active March 17, 2021 15:11
ramda demo
// But first, what is a higher-order function?
//
// Effectively, a function that returns another
// function. A language with higher-order functions
// allows functions to be passed around as values.
function higherOrderFn() {
return function () {
console.log('hello world!')
}
@mgmarlow
mgmarlow / specification.rb
Created February 7, 2021 19:10
DDD Specification Pattern (Chapter 10)
class Specification
def is_satisfied_by(candidate)
raise "must be implemented by inheriting class"
end
def and(other)
AndSpecification.new(self, other)
end
def or(other)
@mgmarlow
mgmarlow / model_translator_idea.rb
Last active December 2, 2020 00:36
Model Translation Layer
require 'ostruct'
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end