Skip to content

Instantly share code, notes, and snippets.

@haakonn
haakonn / s3fs-delcache.sh
Created January 27, 2019 20:27
Script to expire files from s3fs-fuse's cache, with support for spaces in file names
#!/bin/bash
# Modified version of https://github.com/s3fs-fuse/s3fs-fuse/blob/master/test/sample_delcache.sh
# to support spaces in filenames (trade-off: filenames cannot contain "¼", which should be OK for most).
#
# This is unsupport sample deleting cache files script.
# So s3fs's local cache files(stats and objects) grow up,
# you need to delete these.
# This script deletes these files with total size limit
# by sorted atime of files.
@haakonn
haakonn / bt-abonnent.user.js
Last active December 14, 2016 13:48
Les abonnent-innhold på bt.no med Greasemonkey
// ==UserScript==
// @name bt-abonnent
// @namespace haakonnilsen.com
// @include http://www.bt.no/*
// @version 2
// @grant none
// ==/UserScript==
// Only works with JavaScript disabled. You can use YesScript for this.
@haakonn
haakonn / bano-nopaywall.user.js
Last active December 5, 2016 14:07
Les ba.no uten betalingsmurede artikler
// ==UserScript==
// @name bano-nopaywall
// @namespace haakonnilsen.com
// @include http://www.ba.no/*
// @version 1
// @grant none
// ==/UserScript==
function remAll(xpath) {
var els = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
@haakonn
haakonn / btno-nopaywall.user.js
Created December 4, 2016 12:51
btno-nopaywall.user.js - bt.no uten betalingsmurinnhold
// ==UserScript==
// @name btno-nopaywall
// @namespace haakonnilsen.com
// @include http://www.bt.no/*
// @version 1
// @grant none
// ==/UserScript==
function remAll(xpath) {
var els = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
@haakonn
haakonn / sportsfri-aftenposten.user.js
Created January 23, 2016 17:14
Sportsfri Aftenposten
// ==UserScript==
// @name Sportsfri Aftenposten
// @namespace http://haakonnilsen.com
// @description Aftenposten uten sport
// @include http://www.aftenposten.no/*
// @include https://www.aftenposten.no/*
// @include http://www.ba.no/
// @include http://www.bt.no/*
// @include https://www.vg.no/
// @grant none
@haakonn
haakonn / sportsfri-bt.user.js
Created January 23, 2016 17:13
Sportsfri Bergens Tidende
// ==UserScript==
// @name Sportsfri Bergens Tidende
// @namespace http://haakonnilsen.com
// @description Bergens Tidende uten sport
// @include http://www.bt.no/*
// @grant none
// ==/UserScript==
var boring = "sport|fotball|live|sprek";
var filterRE = new RegExp(boring);
@haakonn
haakonn / Logfile to CSV in Scala
Created October 7, 2013 19:00
Just a quick Scala script to convert a certain logfile into CSV. Instead of instinctively going to bash or python for these things, why not Scala? Just run with 'scala makecsv.scala', starts and finishes quickly. No build step or bytecode or support files, just a script.
println("date,msisdn,message")
scala.io.Source.fromFile("problem.log").getLines().foreach { line =>
val m = "^(.{19}).*msisdn='(.{10}).*msg='(.*)', status.*".r.findFirstMatchIn(line).get
println(s"""${m.group(1)},${m.group(2)},"${m.group(3)}"""")
}
@haakonn
haakonn / gist:3938834
Created October 23, 2012 13:45
Python function for partitioning a range of integers into X number of subranges
def partition(partition_count, id_range):
"""
Partitions an integer range into partition_count partitions of uniform size.
id_range specifies the integer range to partition (a tuple (from, to)).
"""
partition_size = ceil((id_range[1] - id_range[0]) / partition_count) + 1
for x in range(0, partition_count):
from_ = int(x * partition_size) + id_range[0]
to = min(int(from_ + partition_size - 1), id_range[1])
yield (from_, to)
@haakonn
haakonn / gist:2353416
Created April 10, 2012 18:22
Utility to concatenate an array of single digits ([1,2,3]) into an int (123)
public class ArrayToIntUtil {
public static int a2i(int... a) {
int result = 0;
int f = (int) Math.pow(10, a.length);
for (int i : a) result += i * (f /= 10);
return result;
}
public static void main(String... args) {
@haakonn
haakonn / repeat.scala
Created April 21, 2015 20:38
Implementing the repeat loop in Scala
/*
Enables loops such as this:
var i = 10
repeat {
print(s"i is $i\n")
i = i - 1
} until (i == 0)
*/