Skip to content

Instantly share code, notes, and snippets.

View clementi's full-sized avatar
🎵
NP: Piano Sonata No. 1 in F-Sharp Minor, Op… (3:48/5:21)

Jeff Pratt clementi

🎵
NP: Piano Sonata No. 1 in F-Sharp Minor, Op… (3:48/5:21)
View GitHub Profile
@clementi
clementi / x.sh
Created July 29, 2020 19:57
Do something n times
#!/usr/bin/env sh
# run like this: x 5 uuidgen
function x {
for _ in {1..$1};
do
output=$(${*:2})
echo "$output"
done
@clementi
clementi / Kleenean.scala
Last active February 21, 2020 19:10
Kleene (three-valued) logic (Scala)
trait Expression
case class Not(expression: Expression) extends Expression
case class And(left: Expression, right: Expression) extends Expression
case class Or(left: Expression, right: Expression) extends Expression
case class Implies(left: Expression, right: Expression) extends Expression
case class Equivalent(left: Expression, right: Expression) extends Expression
trait Kleenean extends Expression {
def neg: Kleenean
@clementi
clementi / Cache.scala
Last active February 21, 2020 23:01
"Immutable" cache using the State monad
import java.time.{Duration, LocalDateTime}
import cats.data.State
import State._
object Cache {
def insert[K, V](key: K, value: V): State[Cache[K, V], Unit] =
modify[Cache[K, V]](_.insert(key, value))
def lookup[K, V](key: K): State[Cache[K, V], Option[V]] = {
@clementi
clementi / colorize.sh
Last active February 24, 2020 15:14
Get Pygments to highlight SBT files and other common scripts without their file extensions
#!/usr/bin/env sh
if [ $# -eq 0 ]; then
echo "Filename required."
exit -1
fi
filename=$(basename -- "$1")
extension="${filename##*.}"
@clementi
clementi / stack.go
Last active September 10, 2019 15:13
Generic stack data type in Go
package main
import (
"errors"
"fmt"
"math/rand"
"strings"
)
type (
using System;
using System.Collections.Generic;
using System.Linq;
public class Interval<T> where T : IComparable<T>
{
public T Start { get; set; }
public T End { get; set; }
public Interval(T start, T end)
@clementi
clementi / dns.md
Last active May 24, 2023 15:27
Public DNS Servers
@clementi
clementi / pointfree
Created August 20, 2019 17:05
CLI for pointfree.io
#!/usr/bin/env python3
import sys
import json
import urllib.parse
import urllib.request
try:
if len(sys.argv) < 2:
@clementi
clementi / Interval.java
Last active August 27, 2019 16:14
Mergeable interval, e.g., merge([[3, 19], [41, 55], [7, 27]]) -> [[3, 27], [41, 55]]. Works with any Comparable<T>.
import java.util.List;
import java.util.Stack;
public class Interval<T extends Comparable<T>> {
private T start;
private T end;
private Interval(T start, T end) {
this.start = start;
this.end = end;
@clementi
clementi / App.java
Last active June 20, 2019 16:12
Secure Token Generator
package net.jeffreypratt.edu.security;
public class App {
public static void main(String[] args) {
var count = 1;
if (args.length > 0) {
count = Integer.parseInt(args[0]);
}