Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
xeoncross /
Created July 8, 2023 19:24
Moving books and PDF's onto your Amazon Kindle

I'm not sure if who might need this information, but man it's hard to find. Kindles aren't as user-friendly as one would expect.

If you need to move books and documents onto the kindle using your computer or mac (via USB) you need to put the .epub .mobi or .pdf files into the "documents" folder.

The kindle will create a ton of "[book name]_[hash].sdr" folders to match and store metadata like your place in the book.

xeoncross / validSudoku.leetcode.go
Created February 18, 2023 17:58
My first attempt at validating a Sukoku board. (Also my first introduction to Sudoku at all!)
View validSudoku.leetcode.go
func isValidSudoku(board [][]byte) bool {
// 9 spaces is > 8 bits so we use 2 bytes (an int16)
rowsMap := [9]int16{}
colsMap := [9]int16{}
gridMap := [9]int16{}
for row:=0; row<9; row++ {
for col:=0; col<9; col++ {
xeoncross / http_get_request.go
Created December 31, 2022 21:16
Making a HTTP request in Go requires you check multiple things if you want to be safe. Below is an example of something that takes, timeouts, context deadlines, HTTP status codes, and a size limit on the response.
View http_get_request.go
package safehttp
// HttpGetRequest assumes the response fits in memory and you're not trying to
// decode a json payload which would be better using json.NewDecoder()
func HttpGetRequest(ctx context.Context, url string, timeout time.Duration, sizeLimit int64) ([]byte, error) {
// Create a new HTTP client with a timeout
client := http.Client{Timeout: timeout}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
xeoncross / mergesort.go
Created December 1, 2022 02:29
Generics merge sort for ordered slices ([]int) inplace (WIP)
View mergesort.go
package mergesort
import (
// based on
xeoncross /
Created October 6, 2022 14:39
Install Java on mac
# Using homebrew
brew install java
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
xeoncross / parse_wiki_titles.go
Last active August 18, 2022 18:13
Simple script to parse the lines in the wikipedia page title dump file and output a list of all the english page titles (deduplicated). See for more files
View parse_wiki_titles.go
package wikipediatitles
import (
_ "embed"
xeoncross / System
Created July 8, 2022 01:22 — forked from vasanthk/System
System Design Cheatsheet
View System

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
xeoncross / ranked_window.go
Created June 22, 2022 23:19
Keep the keys with the highest values in a map
View ranked_window.go
package main
import "fmt"
func BenchmarkMapIteration(b *testing.B) {
size := 1000
ranked := make(map[int]uint8, size)
for i := 1; i < size; i++ {
ranked[i] = uint8(i % 8)
xeoncross / int_bits.go
Created June 22, 2022 17:36
Examples of bit lengths of different integer values:
View int_bits.go
package main
import (
func main() {
// subtract 1 from each answer since we're counting zero also
fmt.Printf("%d bits = %8b = %d\n", 2, byte(1<<2-1), 1<<2)
xeoncross / delta_encoding_demo.go
Created June 22, 2022 02:13
Encoding a sorted sequence of integers using delta encoding can save 40%-60% on storage costs:
View delta_encoding_demo.go
package iiexperiments
import (
// How much space will using a delta encoding save?
// If we assume we have 1 byte (0-255) to tell us how many bytes the delta is contained in, we can then only store the diff between the last and next int values. This difference is the "delta".