Skip to content

Instantly share code, notes, and snippets.

View nwillc's full-sized avatar

Nwillc nwillc

View GitHub Profile
func toFontRune(fs embed.FS, fontName string, name string) FontRune {
txt, err := fs.ReadFile(fontName + "/" + name)
if err != nil {
panic(err)
}
var lines = genfuncs.Slice[string](strings.Split(string(txt), "\n")).
Filter(hasData)
return [][]bool(genfuncs.Map(genfuncs.Map(lines, toRuneSlice), toPixelSlice))
}
func toFontRune(fs embed.FS, fontName string, name string) (FontRune, error) {
txt, err := fs.ReadFile(fontName + "/" + name)
if err != nil {
return nil, err
}
lines := strings.Split(string(txt), "\n")
var fr [][]bool
for _, line := range lines {
if len(line) < 3 {
continue
@nwillc
nwillc / repeater.go
Last active February 14, 2021 01:38
package util
import (
"time"
)
type StopChannel chan bool
// RepeatUntilStopped creates a goroutine that loops, waiting the delay provided and
// then calling the function provided. The loop can be stopped by sending a value to
@nwillc
nwillc / webgo.go
Last active September 20, 2020 17:09
A silly Go main
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
)
@nwillc
nwillc / Heap.kt
Last active June 3, 2020 18:43
Kotlin Heap implementation
package com.github.nwillc.datastructures
class Heap private constructor(
size: Int,
seed: Int,
val compare: (Int, Int) -> Boolean
) {
private var heapSize = 0
private val array = IntArray(size + 1).also { it[0] = seed }
@nwillc
nwillc / GetLogger.kt
Created March 24, 2019 22:24
A Kotlin extension function for SLF4J API
import org.slf4j.Logger
import org.slf4j.LoggerFactory
inline fun <reified T> getLogger(): Logger = LoggerFactory.getLogger(T::class.java.name)
@nwillc
nwillc / UseWithMultipleResources.kt
Created October 25, 2018 00:32
Use with multiple resources
try {
FileReader("input.txt").use { reader ->
FileWriter("output.txt").use { writer ->
// Use the input and output
}
}
} catch (e: FileNotFoundException) {
// Handle possible exception
} catch (e2: IOException) {
// Handle another exception
@nwillc
nwillc / TryWithMultipleResources.java
Created October 25, 2018 00:30
Java try with resources with multiple resources
try (Reader reader = new FileReader("input.txt");
Writer writer = new FileWriter("output.txt")) {
// Use the input and output
} catch (FileNotFoundException e) {
// Handle possible exception
} catch (IOException e2) {
// Handle another exception
}
@nwillc
nwillc / UseWithException.kt
Created October 25, 2018 00:28
Use with exception
try {
FileReader("input.txt").use {
// Use the input
}
} catch (e: FileNotFoundException) {
// Handle possible exception
} catch (e2: IOException) {
// Handle another exception
}
@nwillc
nwillc / UseExample.kt
Created October 25, 2018 00:26
Kotlin use example
FileReader("input.txt").use {
// Use the input
}