Skip to content

Instantly share code, notes, and snippets.

View christianberg's full-sized avatar

Christian Berg christianberg

View GitHub Profile
@christianberg
christianberg / advent_of_code_2020.md
Last active December 4, 2020 07:57
Advent of Code in jq

The one-line solution for part 2 of Day 3 of Advent of Code:

jq -sR '[([1,1],[3,1],[5,1],[7,1],[1,2]) as $slope | ./"\n" | [.,([range(length)]|map(.%$slope[1]))] | transpose | map(select(.[1]==0)|.[0]) | (.[0] | length) as $w| [.,([range(0;length*$slope[0];$slope[0])]|map(.%$w))] | transpose | map(.[0][.[1]:.[1]+1] | select(.=="#")) | length] | reduce .[] as $i (1; . * $i)' < input.txt

And an annotated version. This is the same code as above, with more whitespace, longer variable names, and comments.

[
  ([1,1],[3,1],[5,1],[7,1],[1,2]) as $slope |      ## Loop through all possible slope values, assigning it to the $slope variable.
  ./"\n" |                                         ## `.` is the entire input file (because we call `jq -sR`). Here we split it into lines.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@christianberg
christianberg / local.runit.plist
Created November 24, 2014 15:55
launchd config for runit
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>local.runit</string>
<key>ProgramArguments</key>
<array>
@christianberg
christianberg / Dockerfile
Last active January 10, 2023 16:58
Sharing a unix socket between a Docker container and it's host
FROM ubuntu
RUN apt-get update
RUN apt-get install -y socat
VOLUME /foo
CMD socat UNIX-LISTEN:/foo/bar.sock -

Keybase proof

I hereby claim:

  • I am christianberg on github.
  • I am cberg (https://keybase.io/cberg) on keybase.
  • I have a public key whose fingerprint is E40B A1BE 5CAF 2FA4 032C 4D62 187E 8328 A0A6 8B42

To claim this, I am signing this object:

@christianberg
christianberg / support.rb
Created June 20, 2014 12:30
Patch to rspec-puppet
module RSpec::Puppet
module Support
@@cache = {}
def catalogue(type)
vardir = setup_puppet
if (type == :host)
code = nil
@christianberg
christianberg / 0_reuse_code.js
Created June 3, 2014 09:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@christianberg
christianberg / Dockerfile
Created August 2, 2013 15:54
Ubuntu 12.04 with latest updates applied
FROM ubuntu:12.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y
RUN apt-get upgrade -y
@christianberg
christianberg / create-docker-droplet.sh
Last active April 14, 2024 17:25
Shell script to create a Digital Ocean Droplet and install docker
#!/bin/bash
set -e
SECRETFILE=~/.digitalocean
if [[ -z $DIGOCEAN_ID ]] || [[ -z $DIGOCEAN_KEY ]]; then
if [ -e $SECRETFILE ]; then
. $SECRETFILE
fi
fi
@christianberg
christianberg / bootstrap.sh
Last active April 1, 2016 12:20
Script to install Docker on a Ubuntu 13.04 host
#/bin/bash
set -e
echo "=== Activating Firewall (only SSH allowed) ==="
ufw allow ssh
ufw --force enable
if [ ! -f /swapfile ]; then
echo "=== Activating swap ==="
fallocate -l 1G /swapfile