Skip to content

Instantly share code, notes, and snippets.

@gbluma
gbluma / switch_vm.sh
Created January 30, 2022 01:50
A short script to queue up a start job in proxmox, so that once the FROM vm is fully off, the TO vm is started. It's useful for swapping between GPU passthrough virtual machines without having to use another computer to start the next vm.
#!/bin/bash
FROM=$1
TO=$2
if [ -z "$FROM" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi
if [ -z "$TO" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi
echo "waiting for $FROM to shutdown, then starting $TO"
while : ; do
@gbluma
gbluma / exhaustive.rkt
Created September 29, 2013 13:45
Exhaustive pattern matching (refinement types!) in Typed/Racket.
#lang typed/racket
;; We get exhaustive pattern matching
(: f ((U String Integer) -> Boolean))
(define (f x)
(cond
[(string? x) (string=? x "hi")] ; covers string needs
[(exact-nonnegative-integer? x) (= x 7)] ; covers positive integers
[(even? x) (= x -8)] ; we can actually cover a subset of negative integers
@gbluma
gbluma / fb.c
Created November 5, 2013 22:02
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
// application entry point
int main(int argc, char* argv[])
@gbluma
gbluma / gist:fa6ccb968681a4f5a024
Created December 27, 2014 22:41
c code security check
egrep '[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)|stpn?cpy|a?sn?printf|byte_)'
@gbluma
gbluma / hindley-milner.php
Created September 18, 2014 17:53
A Hindley-Milner type system in PHP
<?php
/** Lambda abstraction */
class Lambda
{
function __construct($v, $body) {
$this->v = $v;
$this->body = $body;
}
@gbluma
gbluma / Readme.md
Last active April 17, 2022 18:11
Writing tool that inserts newlines after every prepositional phrase.

I like to use a technique from Richard Lanham's book "Revising Prose" to help myself write better English sentences. In the book, Lanham suggests that we break apart sentences at each predicate. Doing this helps us visually see the structure of our words. Errors and issues with flow stand out immediately. Likewise, sentences that contain many predicates don't flow nicely.

Splitting these sentences manually is a bit of work. Fortunately a computer can do this work trivially. It is not a problem to repetitively split apart sentences based on simple rules. Below is a program I

@gbluma
gbluma / divide_by_zero.idr
Created May 9, 2014 21:08
A simple example showing how divide by zero can be restricted in Idris
module Main
%default total
myDivide : Nat -> (y:Nat) -> so (y /= 0) -> Nat
myDivide x y p = div x y
main : IO ()
main =
print (show (myDivide 3 1 oh)) -- compiles successfully
@gbluma
gbluma / vimrc
Last active March 5, 2019 21:58
vimrc
:syntax on
"Syntax Support
au BufRead,BufNewFile *.md set syntax=tex
:autocmd FileType * set formatoptions=tcql nocindent comments&
:autocmd FileType c,cpp set formatoptions=croql cindent comments=sr:/*,mb:*,ex:*/,://
au FileType htm,html,xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim
au BufRead,BufNewFile *.fs,*.fsx set filetype=fs
au BufRead,BufNewFile *.fs,*.fsx set syntax=ocaml
au! BufRead,BufNewFile *.gsl setfiletype gsl
@gbluma
gbluma / .screenrc
Created October 28, 2011 20:22
Basic configuration for GNU Screen
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# erase background with current bg color
defbce "on"
# show status bar
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# don't display the copyright page
! --- ~/.Xresources ------------------------------------------------------------
! ------------------------------------------------------------------------------
! --- generated with 4bit Terminal Color Scheme Designer -----------------------
! ------------------------------------------------------------------------------
! --- http://ciembor.github.com/4bit -------------------------------------------
! ------------------------------------------------------------------------------
! --- special colors ---
*background: #122537