Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@henrik
henrik / deploying_phoenix_on_dokku.md
Last active April 14, 2024 00:32
Deploying Elixir's Phoenix Framework on Dokku.

Deploying Phoenix on Dokku

Worked 2015-09-08 for Phoenix 1.0.1 on Dokku 0.3.25.

These instructions assume you've set up Dokku. If not, go find a tutorial for that part. My notes for setting it up on Digital Ocean.

On your local machine, in the app's repo

Create a Dokku app:

@henrik
henrik / ocr.markdown
Created March 3, 2012 17:07
OCR on OS X with tesseract

Install ImageMagick for image conversion:

brew install imagemagick

Install tesseract for OCR:

brew install tesseract --all-languages

Or install without --all-languages and install them manually as needed.

@henrik
henrik / sky_tp_link.md
Created April 6, 2016 07:15
"Self-assigned IP" error with TP-link and Sky on OS X. #googlefood
@henrik
henrik / eu_country_codes.rb
Last active December 20, 2023 12:20
EU (European Union) country codes, ISO 3166-1 alpha-2. (This Gist is from 2012. Please see comments for updates.)
# Note: VAT identification numbers for Greece use "EL", not "GR".
COUNTRY_CODES_EU = %w[
AT BE BG CY CZ DK EE FI FR DE GR HU IE IT
LV LT LU MT NL PL PT RO SK SI ES SE GB
]
@henrik
henrik / part1.rb
Last active December 5, 2023 18:56
Advent of Code day 5
data = DATA.read
seeds = data[/seeds: (.+)/, 1].split.map(&:to_i)
maps = data.scan(/map:\n(.+?)(?:\n\n|\z)/m).map { |(x)| x.lines.map { _1.split.map(&:to_i) } }
locations = seeds.map { |seed|
maps.reduce(seed) { |input, map|
d, s, _r = map.find { |_d, s, r| (s..(s + r)).cover?(input) }
d ? d + (input - s) : input
}
@henrik
henrik / part1.rb
Last active December 5, 2023 01:03
Advent of Code day 4
puts DATA.readlines.sum { |line|
_, winning_numbers, my_numbers = line.split(/[:|]/).map(&:split)
wins = (winning_numbers & my_numbers).length
wins.zero? ? 0 : 2**(wins - 1)
}
__END__
Data goes here
@henrik
henrik / part1_take1.rb
Last active December 3, 2023 19:12
Advent of Code day 3
grid = DATA.readlines.map(&:chomp)
max_line = grid.length - 1
max_col = grid.first.length - 1
sum = 0
grid.each_with_index do |line, i|
tokens = line.scan(/(\D*)(\d+)/).flatten
offset = 0
tokens.each.with_index do |token, j|
@henrik
henrik / part1_take1.rb
Last active December 2, 2023 14:20
Advent of Code day 2
CONSTRAINTS = { red: 12, green: 13, blue: 14 }
puts DATA.readlines.sum { |line|
game, rounds = line.match(/Game (\d+): (.+)/).captures
rounds = rounds.split("; ").map { _1.scan(/(\d+) (\w+)/) }
next 0 unless rounds.all? { |round| round.all? { |count, color| count.to_i <= CONSTRAINTS[color.to_sym] } }
game.to_i
}
@henrik
henrik / take1.rb
Last active December 2, 2023 08:35
Advent of Code day 1 part 2
# The no-frills take.
words = %w[ one two three four five six seven eight nine ]
hash = words.flat_map.with_index(1) { |word, index| [ [ word, index ], [ index.to_s, index ] ] }.to_h
puts DATA.readlines.sum { |line|
_, first_digit = hash.min_by { |string, _| line.index(string) || 999 }
_, last_digit = hash.max_by { |string, _| line.rindex(string) || -1 }
first_digit * 10 + last_digit