Skip to content

Instantly share code, notes, and snippets.

View flogvit's full-sized avatar

Vegard Hanssen flogvit

View GitHub Profile
@flogvit
flogvit / slowmove.pl
Created December 3, 2016 15:11
Slow copy files to let Google Drive keep up
#!/usr/bin/perl
#
# Created by Vegard Hanssen <Vegard.Hanssen@menneske.no>
# 2016-12-03
#
# The script will move the files recursive from one directory to another
# For each $sleepcount it will sleep for $sleepmin min so google drive
# can finish the syncjob
use File::Copy::Recursive qw(fmove);
@flogvit
flogvit / paramparser.js
Last active August 29, 2015 14:23
Little regexp magic to parse params
var text = 'Little brown="and yellow" fox=1 jumps over=lazy dog';
var res = text.match(/([^=\s]+="[^"]+")|\S+/g).map(function (p) {
return p.match(/^([^=\s]*)(?:="?([^"]*)"?)?$/).splice(1, 2);
})
console.log(res);
// Output
@flogvit
flogvit / sort.js
Created June 18, 2015 10:37
Speed test of sort variants in Node
var _ = require('underscore');
var async = require('async');
var sumTime = {};
var sortarray = [];
var ARRAYCOUNT = 100000;
var INNERITERATIONS = 10;
var OUTERITERATIONS = 5;
/**
* Small class for getting Easter Sunday at a specific year
*/
public class Easter {
public static Calendar get(int year) {
int y = year;
int a = y % 19;
int b = y / 100;
int c = y % 100;
@flogvit
flogvit / vietnamese_snake.pl
Last active August 29, 2015 14:21
Perl solution to the Vietnamese pesky snake
#!/usr/bin/perl
#
# Solution to the Vietnamese pesky snake in perl :)
# Calculates all 128 solutions
# http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/21/how-to-solve-the-maths-puzzle-for-vietnamese-eight-year-olds-that-stumped-parents-and-teachers
#
# function: a+(13*b/c) + d + (12*e) - f - 11 + (g*h/i)-10;
# Setup the numbers to insert
@a = qw(1 2 3 4 5 6 7 8 9);