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 / Hello.java
Created August 28, 2018 15:30
Simple program to use -verbose:class
/**
* Simple program to use -verbose:class
*/
public class Hello {
public static void main(final String[] args) {
System.out.println("Hello, world!");
}
}
/*
@edwingustafson
edwingustafson / HelloWorld.java
Created September 26, 2018 01:39
Monad-style Hello, World!
import java.util.*;
/**
* Hello, world! program using Optional monad
*/
public class HelloWorld {
public static void main(final String[] args) {
Optional.of("Hello, world!").ifPresent(System.out::println);
}
}
@edwingustafson
edwingustafson / dontbranch.js
Last active September 29, 2018 17:53
Don't branch just to return a boolean
// This works but requires four lines of code
function wrong() {
if (Math.random() > 0.5)
return true
else
return false;
}
// Same result in a single line of code
function right() {
public List<String> imperative(List<String> terms) {
List<String> result = new ArrayList<String>(terms.size());
for(term : terms) {
if(term.length > 3) {
restult.add(term.toUpperCase());
}
}
return result;
@edwingustafson
edwingustafson / groupby.ts
Created October 26, 2018 13:40
Immutable.JS groupBy example
import * as Immutable from 'immutable';
interface Place {
country: string;
stateOrProvince: string;
city: string;
}
const list: Immutable.List<Place> = Immutable.List<Place>([
{country: 'USA', stateOrProvince: 'Michigan', city: 'Petoskey'},
@edwingustafson
edwingustafson / bluetooth.js
Created January 6, 2019 23:20
Web Bluetooth
const serviceUuid = 0xFFE0, characteristicUuid = 0xFFE1;
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('connect').addEventListener('click', (event) => {
event.target.style.display = 'none';
navigator.bluetooth.requestDevice({
filters: [{name: 'HMSoft', services: [serviceUuid]}],
}).then((device) => {
document.getElementById('form').style.display = 'block';
@edwingustafson
edwingustafson / luhn.ts
Created February 20, 2019 23:16
Luhn check as a single Typescript expression
const luhn: (candidate: string) => boolean = (candidate: string) =>
parseInt(candidate[candidate.length - 1]) === candidate.
slice(0, candidate.length - 1).
split('').
map((c: string) => parseInt(c)).
reverse().
map((n: number, index: number) => index % 2 === 0 ? 2 * n : n).
map((n: number) => n > 9 ? n - 9 : n).
reduce((a: number, b: number) => a + b)
* 9 % 10
@edwingustafson
edwingustafson / construction.css
Created March 5, 2019 13:04
Construction tape border in pure CSS
body {
border-top: solid 10px;
border-image: repeating-linear-gradient( -75deg, yellow, yellow 10px, black 10px, black 20px) 20;
}
@edwingustafson
edwingustafson / config-overrides.js
Created May 23, 2019 15:20
Configuration override to raise ForkTsCheckerWebpackPlugin's memoryLimit
const path = require('path');
module.exports = function override(config, env) {
config.plugins.find(plugin => plugin.constructor.name === 'ForkTsCheckerWebpackPlugin').memoryLimit = 4096;
return config;
};
@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