Skip to content

Instantly share code, notes, and snippets.


Daniel Rönnkvist danielronnkvist

View GitHub Profile
danielronnkvist /
Created Dec 9, 2020
Advent of code day 9
use std::collections::VecDeque;
use std::fs::File;
use std::io::{self, BufRead};
const PREAMBLE_LENGTH: usize = 25;
fn has_sum_makers(sum: u64, preamble: Vec<u64>) -> bool {
assert_eq!(preamble.len(), PREAMBLE_LENGTH);
for a in &preamble {
for b in &preamble {
danielronnkvist / Remove DN premium
Created Oct 18, 2017
Removes premium content block on DN articles. Add it to your bookmarks and whenever on a DN article click on the bookmark and it will remove the premium blocker.
View Remove DN premium
javascript:(function(){var a = document.querySelector('.js-paywall');a.parentElement.removeChild(a);document.querySelector('.article__body--mask').classList.remove('article__body--mask');})()
# Script for quickly swicthing MAC-adress on SJ trains!
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
sudo ifconfig en0 ether $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
networksetup -detectnewhardware
networksetup -setairportnetwork en0 "SJ"
danielronnkvist / SJ-position.js
Last active Aug 16, 2017
Fetch the train position while travelling on a SJ train (and using their wifi) and store all data for further visualisations.
View SJ-position.js
var http = require('http');
var fs = require('fs');
var dataFile = './data.json';
var dataURL = '';
var errorHandling = (e) => {
console.log(`Got error: ${e.message}`);
danielronnkvist / object-map.js
Created May 30, 2016
Simple map function for JS objects.
View object-map.js
Use like
{key: "value"}.map((object, key) => { console.log(key) })
if (typeof != 'function') { = function(callback) {
'use strict';
if (this == null) {
throw new TypeError('Cannot convert undefined or null to object');
danielronnkvist / matrixTransform.js
Created Jan 4, 2016
Get a css 2D matrix for transformations.
View matrixTransform.js
function getTransformationMatrix(rotation, scale, translateX, translateY){
var matrix = [scale * Math.cos(rotation), scale * Math.sin(rotation),
-scale * Math.sin(rotation), scale * Math.cos(rotation),
translateX, translateY]
return matrix.join(", ")
danielronnkvist /
Created Dec 22, 2015
Simple slideshow for animating with css.
class window.Slider
constructor: (selector, @options)->
@index = 0
@elements = document.querySelectorAll selector
@prevIndex = @elements.length - 1
danielronnkvist / .bowerrc
Last active Nov 19, 2015
My gulpscript for one page html
View .bowerrc
"directory": "build/vendor/"
danielronnkvist /
Last active Oct 15, 2015
Puts text from config file into html. Just add an translate attribute followed by the keys separated by dashes,for example: <h1 translate-header-title> will get config['header']['title'].
Translation = (config)->
if typeof config != "object"
throw 'Error, config is not an object'
paths = []
iterate = (obj, parent, paths)->
for property of obj
if obj.hasOwnProperty(property)
if parent != ''
new_parent = parent + '-' + property
danielronnkvist /
Last active Aug 29, 2015
Sammanfattning för TND004

TND004 sammanfattning


Hash function

Ett hashtabell har en hash function som mappar ett element till ett index där det bör sparas i tabellen. En bra hash function distibuerar elementen jämnt över tabellen för att inte orsaka kollisioner, den ska även vara enkel att beräkna. Så att medelkostnaden blir O(1).


Detta exempel lämpar sig för tabeller som inte är allt för stora.