Skip to content

Instantly share code, notes, and snippets.

View zach-klippenstein's full-sized avatar

Zach Klippenstein zach-klippenstein

View GitHub Profile
@zach-klippenstein
zach-klippenstein / FunctionalStack.kt
Created January 31, 2015 22:46
Example of a simple functional data structure in Kotlin.
package com.example.funcstack
import java.util.NoSuchElementException
public trait FunctionalStack<out T> {
public val size: Int
public fun pop(): Pair<T, FunctionalStack<T>>
}
/**
@zach-klippenstein
zach-klippenstein / source_bench_test.go
Last active August 29, 2015 14:12
Comparative benchmarks of various methods of providing RNG sources to concurrent goroutines.
package source_bench_test
import (
"github.com/stretchr/testify/require"
"math/rand"
"sync"
"testing"
)
// See https://golang.org/src/math/rand/rand.go
@zach-klippenstein
zach-klippenstein / floatcomp_test.go
Last active August 29, 2015 14:09
Float Comparison Benchmark: Subtraction vs Multiplication
package main
import (
"math"
"math/rand"
"runtime"
"testing"
)
const DELTA_MULT = 10000000000

Keybase proof

I hereby claim:

  • I am zach-klippenstein on github.
  • I am zachklipp (https://keybase.io/zachklipp) on keybase.
  • I have a public key whose fingerprint is 01D0 C5AB 55E9 29A5 2337 E6CC 0EDD 53ED 8CE1 CD26

To claim this, I am signing this object:

@zach-klippenstein
zach-klippenstein / Parallel Mergesort from Blocking Sources
Last active August 29, 2015 14:01
Algorithm for sorting lists of items from high-latency blocking sources.
Problem: N independent sources of elements that need to be sorted. Each source has an unknown length,
and reading the next element takes a long time. Here are some approaches to sorting this:
1. Basic, naïve mergesort:
if (lists.size > 2) {
merge_all(for (list1, list2 <- lists.grouped_by_2) {
yield merge(list1, list2)
}
} else {
yield min(list1.peek, list2.peek)
@zach-klippenstein
zach-klippenstein / ClumpingImpls.sc
Last active August 29, 2015 13:59
Playing around with some different implementations of a clumping algorithm in Scala.
/*
This is my first attempt at implementing clumping – once with folding,
once with iterators. Clumping is what I've called grouping elements by
an arbitrary function on them, much like groupBy, but preserving their order.
e.g. [a,a,b,a,a,a].clump == [[a,a],[b],[a,a,a]]
I'm just getting into functional programming, so this might have a different name.
While the folding method is more "functionally" and concise, I'm not certain
it provides the same laziness as the iterator one.
I'm not sure exactly what calling view on an iterable does. I imagine it's unnecessary,
@zach-klippenstein
zach-klippenstein / README.md
Last active December 15, 2015 16:09
SystemTap language grammer for Sublime Text 2

(Unfinished) SystemTap language grammer for Sublime Text 2 (and possibly TextMate, although I don't have a copy lying around to test with). This grammar is very unfinished, and probably buggy. This is my first attempt at creating a grammar, and I've just been doing some simple SystemTap development for a school assignment, and was getting tired of staring at plain white text. If you're more experienced or just end up tweaking this, please feel free to send me a pull request!

If there's enough interest, I could throw it into a full package in a full repo.

History

v1.0

Copied a bunch of stuff from the default C grammar.

  • string escapes/format codes
  • better commenting
@zach-klippenstein
zach-klippenstein / ChangePassword.java
Last active April 3, 2024 18:04
The keystore password on Java keystore files is utterly pointless. You can reset it without knowing it, as shown by this code. Note that private keys are still secure, as far as I know. The JKS implementation is copyright Casey Marshall (rsdio@metastatic.org), and the original source is available at http://metastatic.org/source/JKS.java. I've in…
import java.util.*;
import java.io.*;
import java.security.*;
public class ChangePassword
{
private final static JKS j = new JKS();
public static void main(String[] args) throws Exception
{
@zach-klippenstein
zach-klippenstein / init-ssl
Created March 2, 2011 23:55
Script for quickly generating self-signed, passphrase-less SSL keys/certificates for web servers.
#!/bin/bash
BITS=1024
DAYS=365
function promptForName()
{
echo -n "Enter the SSL certificate/key name: " >&2
read name
echo $name
@zach-klippenstein
zach-klippenstein / random-histogrammer.lua
Created August 10, 2010 14:33
Lua script for viewing the shape of the native Lua random generator, seeded by the time.
local lower = 1
local upper = 20
local numSamples = arg[1] or 1000
local numTrials = 10
local hist = {}
local getSeed = coroutine.create(
function()
local start
while true do
start = os.time()