Skip to content

Instantly share code, notes, and snippets.

@vidarh
vidarh / README.md
Last active July 9, 2017 16:25
Stupid / simple JSON command line processing with Ruby

Based on an example for Elvish.

From comment posted to HN:

I love the structured pipes, but as mentioned in another discussion, replacing the shell is a big leap for a lot of people. And you can get quite far without it with tools like "jq". And when I saw this, I just had to tinker a bit to see what I could do with Ruby, based on the example on the homepage:

$ curl -s https://api.github.com/repos/elves/elvish/issues | jr 'each{|issue| puts "#{issue["number"]}: #{issue["title"]}"} ' | head -n 11

Or (I expect pitchforks when you see the implementation for this):

@vidarh
vidarh / Dockerfile-bindtest
Created January 16, 2016 09:03
Testing resolv.conf options
FROM debian
RUN apt-get update && apt-get -y install bind9
EXPOSE 53
EXPOSE 53/udp
CMD ["/usr/sbin/named", "-f"]
@vidarh
vidarh / README.md
Created August 15, 2015 23:53
Trivial Go Init

Inspired by http://git.suckless.org/sinit

Provides basic reaping of child processes for use in e.g. containers. Note however that this code compiles to a substantially larger binary than sinit. Sinit linked statically against Musl is <14KB on my machine, while this code ends up at 2.7MB due to the Go runtime.

If you must have a license, consider it under the MIT/X Consortium license (though I'm happy to confirm relicensing to whatever license works for you).

@vidarh
vidarh / gist:3360589699389db75ea3
Created March 19, 2015 10:09
Trivially primitive simulation of survival (or not) of lineages
class Male
@@lineage = 1
def initialize
@lineage = @@lineage
@@lineage += 1
end
def inspect; "<#{@lineage}>"; end
attr_reader :lineage
@vidarh
vidarh / gviz.rb
Created September 24, 2013 00:51
Rack middleware for inline Graphviz graphs
require 'digest'
module GViz
CACHE_PATH = "/tmp/gviz/"
ENGINES = %w{dot neato twopi circo fdp sfdp}
XSLTPROC = `which xsltproc`.chomp
notugly = File.dirname(__FILE__)+"/notugly.xsl"
NOTUGLY = (File.exists?(notugly) && XSLTPROC != "") ? notugly : nil
@vidarh
vidarh / closures-basic.c
Created December 18, 2009 12:10
A number of ways to implement closures in C, in preparation of an upcoming blog post
#include <stdio.h>
#include <stdlib.h>
struct closure {
void (* call)(struct closure *);
int x;
};