Skip to content

Instantly share code, notes, and snippets.

View troelskn's full-sized avatar

Troels Knak-Nielsen troelskn

View GitHub Profile
-- Warcry Wargaming Aura Script adapted by Ziggy and Hood
-- Call functions
function revertNameDesc()
self.setName(og_name)
self.setDescription(og_desc)
end
function setWounds(value)
@troelskn
troelskn / gist:1287893
Created October 14, 2011 18:24
Luhn's algorithm in php
<?php
function is_valid_luhn($number) {
settype($number, 'string');
$sumTable = array(
array(0,1,2,3,4,5,6,7,8,9),
array(0,2,4,6,8,1,3,5,7,9));
$sum = 0;
$flip = 0;
for ($i = strlen($number) - 1; $i >= 0; $i--) {
$sum += $sumTable[$flip++ & 0x1][$number[$i]];
@troelskn
troelskn / db_fixtures_dump.rake
Last active January 21, 2024 10:26 — forked from ecleel/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task dump: :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
### Keybase proof
I hereby claim:
* I am troelskn on github.
* I am troelsknkarnov (https://keybase.io/troelsknkarnov) on keybase.
* I have a public key ASDynHl2_xhXgI0QWFmIGy8bfqZ9Ac3iEOXeJ1toyrQvzgo
To claim this, I am signing this object:
@troelskn
troelskn / dk-tax.js
Last active November 22, 2023 17:12
Danish tax calculations for Google sheets
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: https://www.skm.dk/skattetal/satser/kommuneskatter
};
var applyOption = function(key, value) {
var key = key.trim();
### Keybase proof
I hereby claim:
* I am troelskn on github.
* I am troelsknkarnov (https://keybase.io/troelsknkarnov) on keybase.
* I have a public key ASCeF7wPMbEzOllgpHKzqNsMuawATDzUCu-KRCGNxk3aCgo
To claim this, I am signing this object:
@troelskn
troelskn / bjorklund.c
Created January 14, 2023 22:41
Björklund's algorithm for calculating euclidean rhythms in pure C
#define ARRAY_TERMINATE 0
#define TRIGGER 'x'
#define REST '.'
// Will accomodate up to 64 long patterns
// If you want to handle larger sets, you probably need to rewrite this code
// to use dynamic arrays instead
int bjorklun_buffer[64][65];
int zarray_count(int arr[]) {
@troelskn
troelskn / featherwing_midi.ino
Created January 12, 2023 17:22
Basic example of using Adafruit Featherwing MIDI with a Feather RP2040 board
#include <MIDI.h>
#include <HardwareSerial.h>
struct MIDISettings : public midi::DefaultSettings
{
static const long BaudRate = 31250;
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MIDISettings);
void setup()
{
@troelskn
troelskn / jquery.flexheight.js
Created February 12, 2011 11:33
Make an element extend to full remaining height of its parent, minus height consumed by siblings. For 100% height layouts
// Make an element extend to full remaining height of its parent, minus height consumed by siblings. For 100% height layouts
// Usage:
// $(document).ready(function() {
// $(".layout-flex-height").flexHeight();
// });
(function($) {
$.fn.flexHeight = function() {
var context = this;
var handleFlexLayout = function () {
context.each(function() {
#!/usr/bin/env ruby
require 'nokogiri'
document = Nokogiri::XML.parse(STDIN.read) { |c| c.noent.nonet.strict }
xsl =<<XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>