Skip to content

Instantly share code, notes, and snippets.

View nnathan's full-sized avatar
💭
shopt -s globstar

Naveen Nathan nnathan

💭
shopt -s globstar
  • Compton
  • 19:19 (UTC +10:00)
View GitHub Profile
@nnathan
nnathan / urandompoll.c
Last active May 27, 2019 16:53
example poll program
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/poll.h>
#define TIMEOUT 5
int main (void)
@nnathan
nnathan / urandom.patch
Last active May 27, 2019 21:49
patch for /dev/urandom to block on cold start when random.urandom_can_block=y in kernel cmdline
From ad8f2da2749e24ca038ea7d4bd96ce61df937ee1 Mon Sep 17 00:00:00 2001
From: Naveen Nathan <naveen@lastninja.net>
Date: Mon, 27 May 2019 10:05:01 +0000
Subject: [PATCH] random: urandom reads block when CRNG is not initialized.
Adds a compile-time option to ensure urandom reads block until
the cryptographic random number generator (CRNG) is initialized.
This fixes a long standing security issue, the so called boot-time
entropy hole, where systems (particularly headless and embededd)
# imap
## .muttrc_auth should contain the following
## set folder = "imaps://mail.messagingengine.com/"
## set imap_user = "billg@microsoft.com"
## set imap_pass = "hunter2"
source ~/.muttrc_auth
set imap_idle = yes
set spoolfile = "+INBOX" # specifies default mailbox
set postponed = "+INBOX/Drafts" # stores a copy of message until its sent (draft)
@nnathan
nnathan / .bash_profile
Last active January 22, 2020 18:13
.bash_profile
# always shfmt -i 2 this dealio
# i don't need to see my username
PS1='\h:\W \$ '
# so i can recursive glob to find files e.g. echo src/**/App.java for a java src tree
# only works in bash 4.x and later, while mac still supplies crummy bash 3
if shopt 2>&1 | grep -q globstar; then
shopt -s globstar
fi
@nnathan
nnathan / r.c
Last active January 8, 2019 01:17
regex alternation is not commutative
/* turns out this is wrong, the regex "quic | noise" contains spaces you need to consider */
/*
* $ ./r
* "quic | noise" matches "high pitched noise coming from car"
* $ ./r s
* "noise | quic" matches "a quick fix"
* "noise | quic" matches "high pitched noise coming from car"
*/
#include <stdio.h>
@nnathan
nnathan / broke.mbox
Created January 7, 2019 23:50
mbox demonstrating mutt regex ~s "noise | quic" is not the same as ~s "quic | noise"
From foo@bar.com Tue Jan 8 09:37:45 2019
Date: Tue, 8 Jan 2019 09:37:45 +1100
From: foo@bar.com
To: a@b.c
Subject: a quick fix
Message-ID: <20190107223745.GA1689@Administrators-MacBook-Pro-3.local>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.11.1 (2018-12-01)
/* A simple qsort implementation on linked lists */
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
/*
* A 'node' is an element of the linked list, containing a pointer
* to the next element, and the associated data
* A full list is represented by a pointer to its first element
@nnathan
nnathan / slqueue.c
Created January 3, 2019 06:04
Understanding BSD queue.h single linked list implementation
/*
* See queue(3) or https://www.freebsd.org/cgi/man.cgi?query=queue&sektion=3 for reference.
*/
#include <stdio.h>
#include <sys/queue.h>
struct Pattern {
char name[100];
/* Following expands to:
@nnathan
nnathan / .nvimrc
Last active November 3, 2019 12:01
" make sure to:
" mkdir -p ~/.config/nvim && echo 'source ~/.nvimrc' >> ~/.config/nvim/init.vim
" also install vim-plug:
" curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Then call :PlugInstall
call plug#begin()
Plug 'nnathan/desertrocks'
Plug 'fatih/vim-go', { 'tag': '*' }
" we really need to get rid of this - github.com/nnathan/desertrocks
@nnathan
nnathan / .vimrc
Created May 30, 2017 01:39
.vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-sleuth'