Skip to content

Instantly share code, notes, and snippets.

View danielronnkvist's full-sized avatar

Daniel Rönnkvist danielronnkvist

View GitHub Profile
@danielronnkvist
danielronnkvist / .bowerrc
Last active November 19, 2015 14:34
My gulpscript for one page html
{
"directory": "build/vendor/"
}
@danielronnkvist
danielronnkvist / Slider.coffee
Created December 22, 2015 15:34
Simple slideshow for animating with css.
class window.Slider
constructor: (selector, @options)->
@index = 0
@elements = document.querySelectorAll selector
@prevIndex = @elements.length - 1
@setupOptions()
@changeActive(@index)
@startInterval()
@danielronnkvist
danielronnkvist / matrixTransform.js
Created January 4, 2016 15:04
Get a css 2D matrix for transformations.
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
danielronnkvist / object-map.js
Created May 30, 2016 08:09
Simple map function for JS objects.
/*
Use like
{key: "value"}.map((object, key) => { console.log(key) })
*/
if (typeof Object.prototype.map != 'function') {
Object.prototype.map = function(callback) {
'use strict';
if (this == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
@danielronnkvist
danielronnkvist / SJ-position.js
Last active August 16, 2017 07:02
Fetch the train position while travelling on a SJ train (and using their wifi) and store all data for further visualisations.
var http = require('http');
var fs = require('fs');
var dataFile = './data.json';
var dataURL = 'http://www.ombord.info/api/jsonp/position/';
var errorHandling = (e) => {
console.log(`Got error: ${e.message}`);
fetchData();
}
@danielronnkvist
danielronnkvist / sj.sh
Created June 2, 2017 07:43
SJ Mac changer
#!/bin/sh
# 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
danielronnkvist / Remove DN premium
Created October 18, 2017 08:31
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.
javascript:(function(){var a = document.querySelector('.js-paywall');a.parentElement.removeChild(a);document.querySelector('.article__body--mask').classList.remove('article__body--mask');})()
@danielronnkvist
danielronnkvist / nine.rs
Created December 9, 2020 20:24
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 {