Skip to content

Instantly share code, notes, and snippets.

@lloeki
lloeki / loggable.rb
Created January 21, 2022 18:00
Loggable Ruby module
require 'logger'
module Core
def self.logger
@logger ||= Loggable::Logger.new(STDOUT, progname: name, level: Logger::DEBUG)
end
end
module Loggable
class Logger < ::Logger
@lloeki
lloeki / Gemfile
Last active January 17, 2022 08:53
Bundler 1.17 / Rubygems 3.0 linux-musl resolution
# This fixes the platform value for rubygems 3.x, allowing bundler and gem install
# to properly resolve to: a) linux on linux, and b) to linux-musl on linux-musl
# with a fallback to linux if there's no linux-musl gem published.
#
# This works when there is no extension to build that would try to query the
# current Ruby platform through Rubygems (because building an extension spawns an
# independent Ruby interpreter)
#
# The second file in this gist is a patch to apply to Rubygems 3.0.3.1, e.g for
# official Docker Hub images:
@lloeki
lloeki / nix_getting_started.md
Last active March 24, 2020 19:00
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
lloeki / csv_renderer.rb
Created February 5, 2020 15:13
Render CSV from Rails respond_with
# 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 October 23, 2020 02:21
Merge repos and keep whole history by creating a single multi-parent merge commit
#!/bin/bash
set -e
set -u
set -o pipefail
prefix="git@gitlab.somewhere.com:mygroup"
target="$1"
shift
@lloeki
lloeki / arch-xhyve.sh
Created August 27, 2015 17:22
Run Arch Linux in xhyve
#!/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 August 27, 2015 17:21
Running debian 8.1 in xhyve
#!/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 05:09
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
lloeki / main.go
Created May 1, 2015 10:32
Using GopherJS and Electron together
// 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 December 16, 2014 16:15
open-vm-tools with clipboard and drag and drop on Ubuntu 14.04 Trusty Tahr
# 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.