Skip to content

Instantly share code, notes, and snippets.

View better_vimdiff.vim
hi DiffAdd ctermfg=7 ctermbg=4
hi DiffChange ctermfg=7 ctermbg=4
hi DiffDelete ctermfg=7 ctermbg=4
hi DiffText ctermfg=7 ctermbg=1
@alexwebr
alexwebr / bad_strncpy.c
Last active May 11, 2016
Bad use of strncpy()
View bad_strncpy.c
#include <string.h>
#include <stdio.h>
#include <assert.h>
// Find this with:
// git grep 'strncpy(\([^,]\+\), [^,]\+, sizeof(\1));'
int main(int argc, char *argv[])
{
// Take a single string argument
View dust_in_the_wind.rb
# Iterates through its elements, starting at the beginning, forever.
class CircularList
def initialize values
@values = values
@index = 0
end
def next
value = @values[@index]
@index += 1
@alexwebr
alexwebr / brightness.c
Last active Aug 29, 2015
Mark this as setuid and put in your path, call with 'up' or 'down' to adjust your laptop's brightness.
View brightness.c
#include <stdio.h>
const char *path = "/sys/devices/LNXSYSTM:00/LNXSYBUS:00/TOS6208:00/backlight/toshiba/brightness";
int main(int argc, char *argv[])
{
if (argc != 2) {
fputs("Need exactly one argument", stderr);
return 1;
}
View Hash Ladders for Shorter Lamport Signatures.md

What's this all about?

Digital cryptography! This is a subject I've been interested in since taking a class with Prof. Fred Schneider back in college. Articles pop up on Hacker News fairly often that pique my interest and this technique is the result of one of them.

Specifically, this is about Lamport signatures. There are many signature algorithms (ECDSA and RSA are the most commonly used) but Lamport signatures are unique because they are formed using a hash function. Many cryptographers believe that this makes them resistant to attacks made possible by quantum computers.

How does a Lamport Signature work?

@alexwebr
alexwebr / gist:8347140
Last active Jan 2, 2016
Recursively frees a singly-linked tree structure (each node has a child, a first sibling, or both)
View gist:8347140
// [... snip ...]
void free_tree(tree_t *p)
{
if (p->sibling != NULL) {
free_tree(p->sibling);
p->sibling = NULL;
}
if (p->child != NULL) {