Skip to content

Instantly share code, notes, and snippets.

@cabo
cabo / nfsping.c
Created July 5, 2012 08:23
nfsping: find out whether the NFS server is still answering requests
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <rpc/rpc.h>
#include <sys/time.h>
#include <string.h>
#include <arpa/inet.h>
@cabo
cabo / nxml-hacks.el
Created August 7, 2012 07:48
Little helpers for nxml
(defun cabo:nxml-balanced-close-start-tag-block ()
"Close the start-tag before point with `>' and insert a balancing end-tag.
Point is left between the start-tag and the end-tag.
If there is nothing but whitespace before the `<' that opens the
start-tag, then put point on a blank line, and put the end-tag on
another line aligned with the start-tag."
(interactive "*")
(nxml-complete)
(nxml-balanced-close-start-tag-block))
@cabo
cabo / electric-pair-better-inhibit.el
Created April 10, 2013 18:34
electric-pair-better-inhibit: Use this as electric-pair-inhibit-predicate if you want parentheses to come in pairs. (Works from Emacs 24 bzr-version ~ 112221 upwards.)
(defun electric-pair-better-inhibit (char)
(or
(eq char (char-after))
(and
(eq char (char-before (1- (point))))
(let* ((syntax (electric-pair-syntax char)))
(not (eq syntax ?\())))
(eq (char-syntax (following-char)) ?w)))
@cabo
cabo / gist:5388730
Created April 15, 2013 14:59
Convert an IEEE 754 Half-precision (16-bit) float into a native float in 11 instructions and 1 branch. Portable to IEEE 754 Single-precision implementations (i.e., everything post-VAX).
float decode_half(int half) {
union { uint32_t u; float f; } val;
val.u = (half & 0x7fff) << 13 | (half & 0x8000) << 16;
if ((half & 0x7c00) != 0x7c00)
return val.f * 0x1p112;
val.u |= 0x7f800000;
return val.f;
}
@cabo
cabo / studip-gruppen-machen.rb
Last active April 18, 2016 20:18
Stud.IP: Create a batch of student groups
#!/usr/bin/env ruby
require 'mechanize'
URL = 'https://elearning.uni-bremen.de'
agent = Mechanize.new
page = agent.get(URL)
login_page = page.link_with(text: /for registered users/).click
@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]
@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 / 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 / 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 / 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)