Skip to content

Instantly share code, notes, and snippets.

@kylelemons
kylelemons / k_from_p.go
Last active April 3, 2022 04:43
Maximum value of K coins taken from P piles in Go, using Dynamic Programming
// Leetcode:
// https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/
func maxValueOfCoins(piles [][]int, k int) int {
// Record the points cumulatively for taking N coins from each pile
for p := range piles {
for c := range piles[p] {
if c+1 >= len(piles[p]) {
continue
}
@kylelemons
kylelemons / io_fs_write_sketch.go
Last active May 9, 2021 00:04
Sketch of writable filesystem interfaces for io/fs
package fs
import (
"fmt"
"io"
"os"
. "io/fs"
)
@kylelemons
kylelemons / linked_hash_map.go
Created February 25, 2021 06:01
Linked Hash Map in Generic Go (go2go)
// https://go2goplay.golang.org/p/MGkmOhAcV79
package main
import (
"fmt"
)
type Pair[K, V any] struct {
Key K
@kylelemons
kylelemons / perfect.go
Last active August 27, 2020 18:45
Perfect numbers in parallel
package main
import (
"flag"
"fmt"
"runtime"
"sync"
"time"
)
diff --git a/internal/lsp/source/analysis.go b/internal/lsp/source/analysis.go
index e9c9ecc1..cea1e548 100644
--- a/internal/lsp/source/analysis.go
+++ b/internal/lsp/source/analysis.go
@@ -16,6 +16,7 @@ import (
"strings"
"sync"
"time"
+ "runtime/debug"
@kylelemons
kylelemons / gba_asm_interrupt_handler.s
Last active August 4, 2019 00:55
GameBoyAdvance Interrupt Handler (hardware only)
.section .data._gba_asm_interrupt_handler
.global _gba_asm_interrupt_handler
.type _gba_asm_interrupt_handler, %function
.align
.arm
_gba_asm_interrupt_handler:
// Registers:
// r0 = IOREG
// NOTE:
@kylelemons
kylelemons / flags.txt
Created July 9, 2019 04:08
Minecraft JVM Flags
Original:
-Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M
New:
-XX:+UseG1GC -Xmx3G -Xms1G -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M
@kylelemons
kylelemons / migrate_local_repos_to_github.sh
Last active July 5, 2019 06:23
A simple shell script to migrate a bunch of local git repositories to GitHub private repos
#!/bin/bash
set -e
TOKEN="YOUR_GITHUB_AUTH_TOKEN_HERE"
USERNAME="YOUR_USERNAME"
mkdir -p repos published
for DIR in *.git; do
@kylelemons
kylelemons / numeric_sort.go
Last active May 15, 2019 18:52
Sort a slice of strings, treating numbers by value instead of by ASCII.
package main
import (
"fmt"
"sort"
"strings"
"unicode"
)
func main() {
@kylelemons
kylelemons / race_test.go
Last active April 11, 2019 20:21
Creating a channel asynchronously - race detector testing
package gorace // run with go test -race
import (
"sync"
"testing"
"time"
)
var (
every = 100 * time.Millisecond