Skip to content

Instantly share code, notes, and snippets.

lloeki /
Last active Mar 24, 2020
Nix: getting started

What is Nix?

Nix is a package manager, born form a research project, with interesting design and properties.

Not to be confused with NixOS, which is:

  • an operating system
  • with a Linux kernel
  • based on nix as a package manager
  • with a descriptive configuration system from which actual configuration is generated
lloeki / csv_renderer.rb
Created Feb 5, 2020
Render CSV from Rails respond_with
View csv_renderer.rb
# Use with render :csv => foo and respond_with @foo if @foo responds to to_csv
# see ActionController::Responder#to_format and #api_behavior
ActionController::Renderers.add(:csv) do |obj, options|
csv = if obj.respond_to?(:to_csv)
obj.to_csv(options[:csv_options] || {})
headers['Content-Disposition'] = if options[:filename].blank?
lloeki /
Last active Oct 23, 2020
Merge repos and keep whole history by creating a single multi-parent merge commit
set -e
set -u
set -o pipefail
lloeki /
Created Aug 27, 2015
Run Arch Linux in xhyve
tmp=$(mktemp -d)
pushd "$tmp"
echo "fixing disk"
dd if=/dev/zero bs=2k count=1 of=tmp.iso
dd if=$iso bs=2k skip=1 >> tmp.iso
echo "mounting disk"
lloeki /
Created Aug 27, 2015
Running debian 8.1 in xhyve
# unfortunately debian currently panics in xhyve
tmp=$(mktemp -d)
pushd "$tmp"
echo "fixing disk"
dd if=/dev/zero bs=2k count=1 of=tmp.iso
lloeki /
Last active May 14, 2018
Clean up /boot of unused Ubuntu (and Debian?) kernels
# Ubuntu has a stupid policy of not cleaning up boots because they deem
# unknowable whether a kernel is valid or not (even if booted). Combined with
# the default Ubuntu setup that creates a ridiculously small /boot that is
# bound to be filled in a few months worth of updates, you have a recipe for a
# failure during upgrade, leading to being unable to update or remove anything
# and having to mess with apt and dpkg innards by hand.
# This may work for Debian too.
# This one liner keeps /boot fresh and clean by removing the currently
# running kernel version as well as the latest one (which may not be
lloeki / main.go
Created May 1, 2015
Using GopherJS and Electron together
View main.go
// Electron's quick start sample, naively ported to Go
// go get -u gopherjs
// gopherjs build main.go
// electron $(pwd)
package main
import (
lloeki / gist:62239da19ec25f90f215
Created Dec 16, 2014
open-vm-tools with clipboard and drag and drop on Ubuntu 14.04 Trusty Tahr
View gist:62239da19ec25f90f215
# You should be using open-vm-tools instead of vmware tools, because package manager.
# Also I hate third parties that write out of /opt and /usr/local.
# open-vm-tools-desktop is badly packaged though, here are the missing links:
sudo apt-get install open-vm-tools open-vm-tools-desktop
# Reboot, and resize works, but no DnD nor clipboard
sudo mkdir /var/run/vmblock-fuse
sudo su -l -c "vmware-vmblock-fuse -o subtype=vmware-vmblock,default_permissions,allow_other /var/run/vmblock-fuse"
# Now we have /run/vmblock-fuse populated.
# Adding an upstart rule in /etc/init is left as an exercise to the reader.
lloeki / brutalize_openssl.rb
Created Dec 2, 2014
Violently disable OpenSSL cert validation (dangerous!)
View brutalize_openssl.rb
require 'openssl'
class OpenSSL::SSL::SSLContext
def verify_mode
def verify_mode=(_)
@verify_mode = OpenSSL::SSL::VERIFY_NONE
lloeki / class_diagram.rake
Last active Aug 29, 2015
Rails class diagram (e.g models) with graphviz
View class_diagram.rake
# (c) Loic Nageleisen
# License: MIT
Node =, :name, :attributes)
Edge =, :from, :to, :name)
class DiagramGraph
def initialize
@nodes = []
@edges = []