Skip to content

Instantly share code, notes, and snippets.

@lloeki
lloeki / nix_getting_started.md
Last active Mar 24, 2020
Nix: getting started
View nix_getting_started.md

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
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] || {})
else
obj
end
headers['Content-Disposition'] = if options[:filename].blank?
@lloeki
lloeki / git_merge_repos.sh
Last active Oct 23, 2020
Merge repos and keep whole history by creating a single multi-parent merge commit
View git_merge_repos.sh
#!/bin/bash
set -e
set -u
set -o pipefail
prefix="git@gitlab.somewhere.com:mygroup"
target="$1"
shift
@lloeki
lloeki / arch-xhyve.sh
Created Aug 27, 2015
Run Arch Linux in xhyve
View arch-xhyve.sh
#!/bin/bash
tmp=$(mktemp -d)
pushd "$tmp"
iso=/Users/lloeki/Downloads/archlinux-2015.08.01-dual.iso
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
lloeki / debian-xhyve.sh
Created Aug 27, 2015
Running debian 8.1 in xhyve
View debian-xhyve.sh
#!/bin/bash
# unfortunately debian currently panics in xhyve
tmp=$(mktemp -d)
pushd "$tmp"
iso="$HOME"/Downloads/debian-8.1.0-amd64-netinst.iso
#iso="$HOME"/Downloads/debian-8.1.0-i386-netinst.iso
echo "fixing disk"
dd if=/dev/zero bs=2k count=1 of=tmp.iso
@lloeki
lloeki / clean_up_boot.sh
Last active May 14, 2018
Clean up /boot of unused Ubuntu (and Debian?) kernels
View clean_up_boot.sh
# 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
lloeki / main.go
Created May 1, 2015
Using GopherJS and Electron together
View main.go
// Electron's quick start sample, naively ported to Go
// https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md
//
// go get -u gopherjs
// gopherjs build main.go
// electron $(pwd)
package main
import (
@lloeki
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
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
OpenSSL::SSL::VERIFY_NONE
end
def verify_mode=(_)
@verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@lloeki
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 = Struct.new(:type, :name, :attributes)
Edge = Struct.new(:type, :from, :to, :name)
class DiagramGraph
def initialize
@nodes = []
@edges = []