Skip to content

Instantly share code, notes, and snippets.

View silverbeak's full-sized avatar
🏠
Working from home

Kristofer Jarl silverbeak

🏠
Working from home
View GitHub Profile
@silverbeak
silverbeak / YearDiff.groovy
Last active December 30, 2015 23:19
There was a question on SO on how to calculate someones current age in years. It's a simple enough operation using Joda-time (http://joda.sourceforge.net/). I thought I'd turn my example into a gist, if anyone else is interested. It's easy to turn this into something that would calculate the age in days or months or whatever... Please tell me if…
import org.joda.time.DateTime
import org.joda.time.Years
def calculateAgeInYears(int year, int monthOfYear, int dayOfMonth) {
def yob = new DateTime(year, monthOfYear, dayOfMonth, 0, 0).toDateMidnight()
def now = DateTime.now().toDateMidnight()
return Years.yearsBetween(yob, now).getYears()
}
def years = calculateAgeInYears(1983, 12, 10)
@silverbeak
silverbeak / ReadResource.scala
Created March 5, 2018 07:52
Read resource file using Scala
/**
* I do this often enough to merit a Gist, but not often enough to remember by heart. Maybe someone else has the same problem.
* The ".mkstring" part can of course be altered to something else as needed, if you don't want a String
*/
import scala.io.Source
val jsonMsg: String = Source.fromURL(getClass.getResource("/json/test1.json")).mkString
@silverbeak
silverbeak / rmhost
Created January 15, 2019 10:07
At work, we keep reinstalling our test servers. I use this script to remove outdated known_host keys
#!/bin/sh
# When the error message says something to the effect of
# Offending ECDSA key in /Users/xxx/.ssh/known_hosts:52
# Use the script like this:
# > rmhost 52
# to remove line 52 from the known_hosts file
# NB! Naturally, make sure to KNOW that the key is ok to be removed. Like the warning says
# IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
@silverbeak
silverbeak / itt-to-srt.xslt
Last active February 1, 2021 09:41
An XSLT transform I use for converting itt-formatted subtitles to srt-formatted subtitles
<?xml version="1.0"?>
<!--
This will convert itt-formatted subtitles to srt-formatted subtitles (or captions, if you prefer that)
Use it like so (using xsltproc in this example, feel free to use whatever engine you like):
# xsltproc itt-to-srt.xslt input_in_itt.itt > output_in_srt.srt
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
xmlns:tt_feature="http://www.w3.org/ns/ttml/feature/"
@silverbeak
silverbeak / Dockerfile
Created June 19, 2019 17:58
I use this script to create a bunch of fake docker images, so I can test my (upcoming) CLI app for removing them
FROM hello-world
ARG FAKE_VALUE=DEFAULT
ENV FAKE_VALUE=$FAKE_VALUE
version = "3.0.6"
maxColumn = 100
importSelectors = singleLine
includeCurlyBraceInSelectChains = true
danglingParentheses.defnSite = true
danglingParentheses.callSite = true
danglingParentheses.ctrlSite = false