Skip to content

Instantly share code, notes, and snippets.

Troels Knak-Nielsen troelskn

Block or report user

Report or block troelskn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
troelskn / dk-tax.js
Last active Dec 19, 2019
Danish tax calculations for Google sheets
View dk-tax.js
function DK_TAX_PARSE_OPTIONS(opts) {
var options = {
hasChildren: true, // Do you receive "børnepenge"?
isFamily: true, // Are you married (and your spouse without income)?
interests: 44256, // Deductible interests paid (typically on a mortgage)
churchTax: 0.00867, // Set your church tax rate here, if you are a member of the church. Otherwise set to 0.0
municipalityTaxRate: 0.24926 // Find you tax rate here:
var applyOption = function(key, value) {
var key = key.trim();
troelskn / gist:1287893
Created Oct 14, 2011
Luhn's algorithm in php
View gist:1287893
function is_valid_luhn($number) {
settype($number, 'string');
$sumTable = array(
$sum = 0;
$flip = 0;
for ($i = strlen($number) - 1; $i >= 0; $i--) {
$sum += $sumTable[$flip++ & 0x1][$number[$i]];
troelskn / underscore.php
Created Dec 22, 2010
camelize + underscore in php
View underscore.php
* Transforms an under_scored_string to a camelCasedOne
function camelize($scored) {
return lcfirst(
troelskn / app.rb
Last active Jul 14, 2019 — forked from dstrelau/app.rb
Gollum protected by HTTP Basic
View app.rb
require 'gollum/frontend/app'
require 'digest/sha1'
class App < Precious::App
User =, :email, :password_hash, :can_write)
before { authenticate! }
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end
helpers do
View table_print.rb
# takes an array of hashes and prints as a table on the console
def table_print(rows)
table = [] + { |v| }
sizes = { |row| }
puts { |row| { |txt, idx| txt.rjust(sizes[idx]) }.join("\t") }.join("\n")
troelskn / ruby_print.rb
Created Apr 26, 2019
Ruby pretty print with rubocop standard syntax
View ruby_print.rb
class RubyPrint
def self.pp(mixed)
puts new.transform(mixed)
def transform(mixed, indentation = 1)
if mixed.is_a?(Hash)
transform_hash mixed, indentation
elsif mixed.is_a?(Array)
View just_and_exactly.rb
# frozen_string_literal: true
require "active_record"
module JustAndExactly
module ActiveRecordExtensions
MultipleRecordsFound =
# Like +first!+, but will also fail if the query would match more than
# one record.
View docker-machine-auth
PS1='\[\e[1m\]\[\e[34m\]\u@\h$([ "$DOCKER_MACHINE_NAME" = "" ] || echo " \[\e[33m\][docker-machine:$DOCKER_MACHINE_NAME]\[\e[34m\]"): \[\e[35m\]\w\[\e[33m\]$(__git_ps1) \[\e[34m\]$\[\e[0m\] '
docker-machine-auth () {
if [ "$MACHINE_NAME" = "" ]
eval "$(docker-machine env -u)"
eval "$(docker-machine env $MACHINE_NAME)"
troelskn / db.rake
Last active Jan 28, 2019
Wait for db. Useful in a dockerized setup
View db.rake
namespace :db do
desc "Wait for db. Used for initial boot up"
task wait: :environment do
puts "*** Giving DB time to boot"
catch :done do
10.times do
Timeout.timeout(1) do
ActiveRecord::Base.connection.execute("SELECT NOW()")
troelskn / raven.rb
Last active Nov 21, 2018
View raven.rb
require 'raven'
require 'rake/task'
if Rails.env.production?
Raven.configure do |config|
config.dsn = ''
module Rake
class Task
You can’t perform that action at this time.