Skip to content

Instantly share code, notes, and snippets.

@hudon
hudon / bytesum.hs
Created October 1, 2016 17:16
add two lists of arbitrary bytes
byteSum :: [Word8] -> [Word8] -> [Word8]
byteSum = byteSum' 0
where
byteSum' 0 [] [] = []
byteSum' 1 [] [] = [1]
byteSum' carry (x:xs) (y:ys) =
let v = x + y + carry
in v : byteSum' (if v < x || v < y then 1 else 0) xs ys
@hudon
hudon / The Technical Interview Cheat Sheet.md
Last active August 29, 2015 14:28 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@hudon
hudon / resolve_dropbox.sh
Created June 18, 2015 17:09
blanket resolve all dropbox conflicts
#!/bin/bash
find . | grep 'MacBook' | while read -r line ; do ; mv "$line" $(echo "$line" | sed 's/ (Ja.*MacBook.*17)//') ; done
@hudon
hudon / cloneroni.sh
Created May 27, 2015 18:48
clone a list of gists
# /bin
#gists.txt
#https://github.com/gist/hudon/0ccd3601425b25b5e559
#https://github.com/gist/hudon/89254003f8d5491a2e1d
# ...
#
while read -r in
do
url=${in/gist\/andy/gist}.git
url=${url/https:\/\/github.cbhq.net/git@github.cbhq.net:}
@hudon
hudon / hybrid_decrypt
Created May 12, 2015 17:22
hybrid decrypt
# decrypt /path/to/decrypted/target
# assumes existence of target.iv, target.key (aes-256-cbc), target.enc (encrypted target)
decrypt () {
local IV=`base64 -d < "$1.iv" | openssl rsautl -decrypt \
-inkey /etc/ssl/private/private.key`
local KEY=`base64 -d < "$1.key" | openssl rsautl -decrypt \
-inkey /etc/ssl/private/private.key`
openssl aes-256-cbc -d -a -in "$1.enc" -out "$1" -iv "$IV" -K "$KEY"
}
@hudon
hudon / hybrid_encrypt
Last active August 29, 2015 14:20
hybrid encryption to encrypt large data with an rsa pubkey and aes
def self.encrypt(data, crt_pem)
cert = OpenSSL::X509::Certificate.new(crt_pem)
rsa = cert.public_key
aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
aes.encrypt
key = aes.random_key.unpack('H*')[0]
iv = aes.random_iv.unpack('H*')[0]
ciphertext = aes.update(data)
@hudon
hudon / dockerize-env
Last active April 1, 2023 03:30
Workaround so you can use `docker run --env-file .env` and read variables with newline escape sequences in them
#!/bin/bash
# Docker can't pass newlines to containers if there are \n in variables in
# --env-file files. This tool creates a $1.exported file with newlines that
# can be sourced before running your container and a $1.vars for you to pass
# to --env-files so docker passes those variables to the container.
# Usage:
# dockerize-env .env
# This creates: .env.vars and .env.exported
@hudon
hudon / docker-log-truncate
Last active November 9, 2016 06:06
Automatically truncate docker logs on a coreos machine
cat > /var/tmp/log-truncate <<EOF
#!/bin/sh
set -eux
cd /var/lib/docker/containers
for id in *
do
logfile="\${id}/\${id}-json.log"
[ -e "\${logfile}" ] && truncate -s 0 "\${logfile}"
done
btrfs balance start -v -dusage=20 /var/lib/docker/btrfs
@hudon
hudon / keybase.md
Created April 1, 2015 22:01
keybase.md

Keybase proof

I hereby claim:

  • I am hudon on github.
  • I am hudon (https://keybase.io/hudon) on keybase.
  • I have a public key whose fingerprint is CCF4 66F0 9D45 FFFA E97D 59E2 9C99 4054 9B44 7CFC

To claim this, I am signing this object:

Verifying that +hudon is my Bitcoin username. You can send me #bitcoin here: https://onename.io/hudon