Skip to content

Instantly share code, notes, and snippets.

@cabo
cabo / cbor-canonical.rb
Created November 4, 2016 17:09
CBOR Canonicalizer (Implementing Section 3.9 of RFC 7049)
# -*- coding: utf-8 -*-
require "cbor" unless defined? CBOR
module CBOR
module Canonical
module Object_Canonical_CBOR
def cbor_pre_canonicalize
self
@cabo
cabo / onename.txt
Created February 9, 2016 17:55
onename
Verifying that +cabocabo is my blockchain ID. https://onename.com/cabocabo
@cabo
cabo / ger-time.el
Created January 8, 2016 12:04
Insert time in emacs
(defun german-time ()
(format-time-string "%d.%m.%Y" (current-time)))
(defun iso-date ()
(format-time-string "%Y-%m-%d" (current-time)))
(defun ins-time (&optional arg)
(interactive "*P")
(if arg
(insert (german-time))
@cabo
cabo / screen-serial.bash
Created December 19, 2015 18:00
Bash function for completion of serial lines for Gnu screen
function scu() {
local fn=$1
shift
echo opening /dev/cu."$fn" "$@"...
screen /dev/cu."${fn// / }" "$@" ; stty sane
}
function _scu() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
[0-9]*)
@cabo
cabo / crlf.screenrc
Created December 19, 2015 13:33
Make GNU screen convert return key (CR) into CR-LF
# put this in your ~/.screenrc to make
# ^A D (uppercase) switch on, and
# ^A U (uppercase) switch off, converting
# CR (return keys) input into CRLF
bind D bindkey "\015" stuff "\015\012"
bind U bindkey "\015" stuff "\015"
@cabo
cabo / top10.rb
Created October 22, 2014 12:40
Top 10 space-eating subdirectories
#!/usr/bin/env ruby
MULT = { "" => 1,
"B" => 1,
"K" => 1024,
"M" => 1024*1024,
"G" => 1024*1024*1024,
"T" => 1024*1024*1024*1024,
}
def hrtonum(s)
@cabo
cabo / grayscale.scpt
Created August 4, 2014 13:51
Short applescript to toggle grayscale presentation on monitors (thanks, anonymous Better TouchTool user!)
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.universalaccess"
tell application "System Events"
tell process "System Preferences"
tell window "Accessibility"
tell checkbox named "Use grayscale"
click
end tell
end tell
@cabo
cabo / elixir-charming.el
Created July 13, 2014 13:25
Emacs lisp snippet to turn Elixir into a charming language (during editing only)
(defconst elixir--cabo-prettify-symbols-alist
'(
("->" . ?➙) ; → ➜➽➤
("::" . ?∷)
("<-" . ?⬅) ; ←
("<<" . ?⟪ ) ; «≪
("=>" . ?⇒)
(">>" . ?⟫ ) ; »≫
("do" . ?⫷)
@cabo
cabo / open.mk
Created January 30, 2014 13:52
portably open a file (PDF etc.) in a Makefile
OPEN=$(word 1, $(wildcard /usr/bin/xdg-open /usr/bin/open /bin/echo))
@cabo
cabo / merge-patch-out.txt
Created December 10, 2013 10:47
JSON Merge-Patch examples: A simple implementation of json merge-patch (http://tools.ietf.org/html/draft-ietf-appsawg-json-merge-patch/). Code to extract the examples from the draft helps see the difference that eliding purge_nulls makes. Because of recent changes to JSON (non-containers at top level), requires "oj" gem.
Let's see where we don't agree (this code doesn't do purge_nulls):
Mismatch:
orig: {"a":"foo","b":[3,null,{"x":null}]}
patch: {"b":[3,null,{"x":null}]}
draft: {"a":"foo","b":[3,{}]}
actual: {"a":"foo","b":[3,null,{"x":null}]}
Mismatch:
orig: [1,2]
patch: [1,null,3]
draft: [1,3]