Skip to content

Instantly share code, notes, and snippets.

View edwingustafson's full-sized avatar
💭
Upon Ye Olde Internetworke

Edwin Gustafson edwingustafson

💭
Upon Ye Olde Internetworke
  • Charlevoix, Michigan, USA
View GitHub Profile
@edwingustafson
edwingustafson / Qsort
Created January 22, 2025 01:12
Quicksort in just a few lines of Java
#!/usr/bin/java --source 21
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@edwingustafson
edwingustafson / capitalize.sh
Created December 16, 2024 14:00
Capitalize string variable contents in Bash
#!/usr/bin/env bash
GREETING="hello, world!"
echo ${GREETING}
echo ${GREETING^}
echo ${GREETING^^}
exit 0
@edwingustafson
edwingustafson / FizzBuzz
Last active September 21, 2023 12:55
FizzBuzz demonstrating JDK 21 LTS features
#!/usr/bin/env -S java --source 21 --enable-preview
/*
FizzBuzz demonstrating JDK 21 LTS features
*/
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.IntStream;
@edwingustafson
edwingustafson / maze.mjs
Last active August 27, 2022 13:29
Maze generator with experimental Node command-line argument parsing
#!/usr/bin/node
import { parseArgs } from 'node:util';
/*
Based on the Commodore 64 single line maze generator
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
as described at https://10print.org/
*/
@edwingustafson
edwingustafson / url.jsh
Created April 28, 2022 16:59
Java URL equality
jshell> var s = new URL("https://www.caymanchem.com/")
s ==> https://www.caymanchem.com/
jshell> var t = new URL("https://www.caymanpharma.com/")
t ==> https://www.caymanpharma.com/
jshell> s.equals(t)
$3 ==> true
As seen on https://twitter.com/tnurkiewicz/status/1519643900423688192
@edwingustafson
edwingustafson / Maze
Last active January 27, 2022 13:50
Maze generator in Java as executable script
#!/usr/bin/env -S java --source 11
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
Based on the Commodore 64 single line maze generator
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
as described at https://10print.org/
// https://www.facebook.com/Heavydsparks/photos/a.1432147377066939/2976473412634320/
const f = (n) => n * (n + 1);
console.log([9, 8, 7, 6, 3].map(f));
// Output: [ 90, 72, 56, 42, 12 ]
@edwingustafson
edwingustafson / maze.js
Last active October 7, 2020 13:26
Maze generator
#!/usr/bin/env node
// Based on the Commodore 64 single line maze generator
// 10 PRINT CHR$(205.5+RND(1)); : GOTO 10
// as described at https://10print.org/
while (true) process.stdout.write(['\u2571','\u2572'][Math.floor(0.5 + Math.random())]);
/* Commodore 64 color values from https://www.c64-wiki.com/wiki/Color */
:root {
--c64-black: #000000;
--c64-white: #ffffff;
--c64-red: #880000;
--c64-cyan: #aaffee;
--c64-violet: #cc44cc; --c64-purple: var(--c64-violet);
--c64-green: #00cc55;
--c64-blue: #0000aa;
--c64-yellow: #eeee77;
@edwingustafson
edwingustafson / hello.sh
Created November 20, 2019 23:12
jshell bash script with here document
#!/bin/bash
jshell -<<EOF
System.out.println("Hello, world!");
/exit
EOF