Skip to content

Instantly share code, notes, and snippets.

def isAnagram(s1: String, s2: String): Boolean =
(s1 diff s2).isEmpty
isAnagram("barbie", "oppenheimer").ensuring(_ == false)
isAnagram("race", "care").ensuring(_ == true)
isAnagram("tree", "tere").ensuring(_ == true)
@er2
er2 / TimeParser.scala
Last active September 24, 2023 18:46
import scala.util.Try
case class Pattern(pattern: String):
def find(part: String)(s: String) =
val start = pattern.indexOf(part)
s.substring(start, start + part.length)
case class Parser(p: Pattern, s: String):
def extract(x: String) = p.find(x)(s)
@er2
er2 / firefox-file-saving-API-chatGPT.md
Created April 1, 2023 17:12
A conversation with chatGPT

Firefox File Saving API.

You

convert this code to work in firefox

async function saveToFile() { const handle = await showSaveFilePicker({ suggestedName: 'index.html', types: [{ description: 'HTML',

@er2
er2 / json+ld.md
Last active April 1, 2023 18:07
A conversation with chatGPT

JSON-LD cocktail recipe.

You

convert this recipe to json+ld recipe schema

As served at the Tourist Bar, Port-au-Prince, Haiti, soon after the post-WWII beginnings of tourism on the island. Named after the Haitian revolutionary hero General Alexandre Pétion, who succeeded Dessalines as head of state. Pétion downgraded the office he assumed from "Emperor For Life" to the more egalitarian "President For Life." Recipe from the 1949 Esquire's Handbook For Hosts.

¾ ounce Bénédictine

¾ ounce clairin*

@er2
er2 / supabase.html
Last active March 31, 2023 14:02
HTMX plus Supabase
<script src="https://unpkg.com/htmx.org@1.8.4"></script>
<script>
document.body.addEventListener('htmx:configRequest', function(evt) {
const key = '<your key here>';
evt.detail.headers['apikey'] = key;
evt.detail.headers['Authorization'] = "Bearer " + key;
});
document.body.addEventListener('htmx:beforeSwap', function (evt) {
// trim quotes from response
evt.detail.serverResponse = evt.detail.serverResponse.slice(1, -1);
@er2
er2 / html-from.sql
Last active May 4, 2023 02:49
HTML from SQL
create function home() returns XML
language sql as $$
select xmlelement(name table,
xmlelement(name th, 'Column 1'),
xmlelement(name th, 'Column 2'),
xmlagg(
xmlelement(name tr,
xmlforest(column_one as td,
column_two as td))))
from home_page_content;
import scala.annotation.tailrec
object Solution {
def validUtf8(data: Array[Int]): Boolean = validUtf8(data.toList)
@tailrec
def validUtf8(data: List[Int]): Boolean = data match {
case Nil => true
case n1 :: ns if ASCII_SEQ(n1) => validUtf8(ns)
case n1 :: n2 :: ns if TWO_BYTE(n1, n2) => validUtf8(ns)
@er2
er2 / uppercase-numbers.js
Created July 25, 2022 17:56
Uppercase numbers
function uppercaseNumbers(num) {
if (num === 1)
return "¹"
if (num === 2 || num === 3)
return String.fromCodePoint("²".codePointAt(0) + (num - 2))
return String.fromCodePoint("⁴".codePointAt(0) + (num - 4))
}
for (let i = 0; i < 10; i++)
console.log(i + "\t" + uppercaseNumbers(i))
@er2
er2 / bissecting.md
Created November 4, 2021 14:39
Bissecting Git for Windows

Here's how I bissected this section of git for windows history and made this table: git-for-windows/git#3509 (comment)

Date Version Good/Bad
2021-10-30-13:38:26 PortableGit-2.34.0-rc0-64-bit.7z.exe Bad
2021-10-29-14:11:24 PortableGit-prerelease-2.33.1.windows.1-36-gbd465d70df-20211029141659-64-bit.7z.exe
2021-10-28-19:16:10 PortableGit-prerelease-2.33.1.windows.1-27-gf8f57df4d5-20211028224346-64-bit.7z.exe
2021-10-15-13:12:48 PortableGit-prerelease-2.33.1.windows.1-13-g3f28c5f141-20211015131715-64-bit.7z.exe
2021-10-14-12:22:50 PortableGit-prerelease-2.33.1.windows.1-2-gc7d0a86b02-20211014122857-64-bit.7z.exe
2021-10-1
@er2
er2 / u3.fish
Created October 16, 2021 20:21
how to use u3-tool with fish shell
# determine necessary partition size
set ISOSIZE (wc -c image.iso)
# resize partition
sudo u3-tool -p $ISOSIZE /dev/sg3
# load
sudo u3-tool -l image.iso /dev/sg3