Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / checksum-collider.go
Created November 11, 2024 16:34 — forked from ross-spencer/checksum-collider.go
Checksum Collider Example
//Simulation of the Birthday Paradox
//Find no. files needed for chance of a single collision
package main
import "fmt"
import "math"
func main() {
var BITS float64 = 512
@xeoncross
xeoncross / splitByStrings.go
Created March 20, 2024 20:08
Split code into chunks (processing args, coloring syntax, etc..) based on if strings exist while taking escape characters into account. Golang rune parsing supports UTF8.
// Run at: https://go.dev/play/p/oFUYPNRZiBp
package main
import "fmt"
// Suppose you have a piece of code you want to split into chunks based on if you're in a string or not.
// You also want to respect escape characters.
var input = `fmt.Println("Hello, \"世界\"")`
@xeoncross
xeoncross / gencert.go
Created January 27, 2024 17:14
Generate a self-signed certificate in Go
package main
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
@xeoncross
xeoncross / kindle.md
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
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!)
// https://leetcode.com/problems/valid-sudoku/submissions/900490403/
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
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.
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
xeoncross / mergesort.go
Created December 1, 2022 02:29
Generics merge sort for ordered slices ([]int) inplace (WIP)
package mergesort
import (
"fmt"
"testing"
"golang.org/x/exp/constraints"
)
// based on https://github.com/TheAlgorithms/Go/blob/master/sort/mergesort.go
@xeoncross
xeoncross / java_install.sh
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
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 https://dumps.wikimedia.org/enwiki/20220801/ for more files
package wikipediatitles
import (
_ "embed"
"sort"
"strings"
"unicode"
)
// https://dumps.wikimedia.org/enwiki/20220801/enwiki-20220801-all-titles-in-ns0.gz
@xeoncross
xeoncross / System Design.md
Created July 8, 2022 01:22 — forked from vasanthk/System Design.md
System Design Cheatsheet

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?