Skip to content

Instantly share code, notes, and snippets.

View roobie's full-sized avatar

Björn Roberg roobie

View GitHub Profile
@roobie
roobie / random_things.js
Created March 6, 2015 09:09
random things
var randName = function () {
return new Array(10).join(' ').split(' ').map(function() {
return (10 + (Math.random() * 26 | 0)).toString(36);
});
};
@roobie
roobie / range.js
Last active March 13, 2017 22:58
range
function range (from, to, step) {
return new Array(Math.ceil((to - from) / (step || 1)))
.join(' ').split(' ')
.map(function (_, i) {
return from + (i * (step || 1))
})
}
@roobie
roobie / a_keymirror.js
Created March 6, 2015 14:07
key mirror array style
function aKeyMirror(list) {
var i, key, result = {};
if (!Array.isArray(list)) {
throw new Error('Argument must be an array.');
}
for(i = 0; i < list.length; i++) {
key = list[i];
result[key] = key;
}
@roobie
roobie / .Xdefaults
Last active August 29, 2015 14:23 — forked from yevgenko/.Xdefaults
!-------------------------------------------------------------------------------
! Xft settings
!-------------------------------------------------------------------------------
Xft.dpi: 96
Xft.antialias: false
Xft.rgba: rgb
Xft.hinting: true
Xft.hintstyle: hintslight
var tzWebOffsetPromise = function (timestamp) {
// returns a promise for the adjusted timezone for the supplied timestamp
return $.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/Web/RegionalSettings/TimeZone",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
}
}).then(function (tz) {
@roobie
roobie / moment-timezone-sp-map.js
Last active August 28, 2015 12:32
mappings for SharePoint timezone terminiology => moment IANA timezone names
var mappings = [
"Africa/Cairo|(GMT+02:00) Cairo",
"Africa/Cairo|(UTC+02:00) Cairo",
"Africa/Johannesburg|(GMT+02:00) Harare, Pretoria",
"Africa/Johannesburg|(UTC+02:00) Harare, Pretoria",
"Africa/Lagos|(GMT+01:00) West Central Africa",
"Africa/Lagos|(UTC+01:00) West Central Africa",
"Africa/Nairobi|(GMT+03:00) Nairobi",
"Africa/Nairobi|(UTC+03:00) Nairobi",
"Africa/Windhoek|(GMT+02:00) Windhoek",
var spToIana = [{ "id" : 2, "name" : "Europe/London" },
{ "id" : 3, "name" : "Europe/Paris" },
{ "id" : 4, "name" : "Europe/Berlin" },
{ "id" : 5, "name" : "Europe/Bucharest" },
{ "id" : 6, "name" : "Europe/Budapest" },
{ "id" : 7, "name" : "Europe/Kaliningrad" },
{ "id" : 8, "name" : "America/Sao_Paulo" },
{ "id" : 9, "name" : "America/Halifax" },
{ "id" : 10, "name" : "America/New_York" },
{ "id" : 11, "name" : "America/Chicago" },
@roobie
roobie / markov.js
Created November 17, 2015 13:09
a markov chain
(function () {
'use strict';
function State(properties) {
var self = this;
this.name = properties.name;
this.transitions = properties.transitions;
}
State.prototype.validate = function () {
@roobie
roobie / markovtext.js
Last active November 19, 2015 10:03
random text
(function (corpus) {
'use strict';
var DEBUG = true;
var err = function (msg) {
throw Error(msg);
};
/**
@roobie
roobie / weasel-Y.js
Created November 26, 2015 19:31
weasel with a Y combinator
(function () {
"use strict";
const goal = "METHINKS IT IS LIKE A WEASEL";
const size = 100;
const rate = 0.04;
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var range = function (count) {
return new Array(count).join(' ').split(' ');