Skip to content

Instantly share code, notes, and snippets.

View silentbicycle's full-sized avatar

Scott Vokes silentbicycle

  • Fastly (@fastly)
  • Grand Rapids, MI
View GitHub Profile
@silentbicycle
silentbicycle / shift.py
Created January 17, 2015 22:07
shift-and and shift-or in python
# shift-and / shift-or
def to_bin(n, width=32):
"Pad a binary number to WIDTH bits wide"
s = bin(n).replace("0b", "")
return (("%0" + str(width) + "d") % int(s))
# pg 20
def shift_and(pattern, text, trace=False):
m = len(pattern)
@silentbicycle
silentbicycle / space_padness.c
Last active April 19, 2021 17:33
uninitialized memory caused by struct padding
$ cat space_padness.c
/*
* Copyright (c) 2016 Scott Vokes <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF