Skip to content

Instantly share code, notes, and snippets.

View roobie's full-sized avatar

Björn Roberg roobie

View GitHub Profile
@roobie
roobie / jstask.js
Created July 5, 2016 10:43
en möjlig lösning
(function () {
console.clear();
var get = function (url) {
return $.ajax({
url: url,
type: "GET",
headers: { "accept": "application/json;odata=verbose" }
});
};
@roobie
roobie / promises.md
Created August 22, 2016 12:26
Promises i JS

promises

En promise i JS är en abstraktion för asynkrona flöden som till slut blir ett (och inte mer än ett) värde.

Ett exempel som visar hur det kan förenkla saker är att titta på hur man kan göra ett anrop till en server för att hämta något. Eftersom vi inte vill låsa webbläsaren under tiden vi väntar på att vi ska få ett svar (det kan ju ta allt från några enstaka millisekunder till flera sekunder) så gör vi ett asynkront anrop genom att använda den inbyggda XMLHttpRequest

Det mest basic vi skriver för att göra detta vore något i stil med:

// skapa objektet som hanterar anropet
@roobie
roobie / simple_signal.js
Last active September 9, 2016 09:21
simple signal
// Function(Function(Any) -> Void) -> {signal, push}
function E(src) {
const listeners = [];
const pipe = {
// Function(Any) -> Function(Void) -> Void
signal: function registerSignalHandler(listener) {
listeners.push(listener);
return function unregister() {
listeners.splice(listeners.indexOf(listener), 1);
};
@roobie
roobie / _etc_network_interfaces
Created September 20, 2016 11:01
Sample network config for Debian guest (vbox) with one NAT and one HostOnly adapter, which allows the guest to both access the Internet and expose services to the host system via a static IP
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
@roobie
roobie / redshift.conf
Created October 2, 2016 20:45
redshift conf
; Global settings for redshift
[redshift]
; Set the day and night screen temperatures
temp-day=5700
temp-night=2000
; Enable/Disable a smooth transition between day and night
; 0 will cause a direct change from day to night screen temperature.
; 1 will gradually increase or decrease the screen temperature.
transition=0
@roobie
roobie / tmux_ls.sh
Created December 5, 2016 12:14
list available tmux sessions
autoload -U colors && colors
echo "$fg[green]Available tmux sessions$reset_color"
tmux ls
@roobie
roobie / levenshtein.js
Last active December 7, 2016 11:47 — forked from andrei-m/levenshtein.js
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@roobie
roobie / no_jq.js
Created December 7, 2016 13:03
DOM without jquery
const __forEach = Function.prototype.call.bind(Array.prototype.forEach);
const dom = {
ebi: (id) => document.getElementById(id),
qs: (sel) => document.querySelector(sel),
qsa: (sel) => document.querySelectorAll(sel),
// we use a dynamic binding, to minimize mem leakage.
// because if bound to a parameter it is more likely it will be
// caught in a closure somewhere.
forEach: (src, fn) => __forEach(src, (item) => fn.call(item)),
// see https://github.com/roobie/uniform-accessor
import ua from 'uniform-accessor';
export default function uniformAccessTransform(object, extraProperties = {}) {
console.assert(typeof object === 'object', 'Must pass a source object');
let freshObject = {};
// iterate over the properties of the object, and
// create a uniform-accessor instance initialized
// to the value of the property.
'(js-indent-level 2)
'(js2-basic-offset 2)
'(js2-strict-missing-semi-warning nil)
'(json-reformat:indent-width 2))