Skip to content

Instantly share code, notes, and snippets.

View carlhannes's full-sized avatar

Hannes W carlhannes

View GitHub Profile
debounce: function(func, wait, immediate) {
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
// taken from https://github.com/jashkenas/underscore/blob/master/underscore.js
var timeout, args, context, timestamp, result;
var later = function() {
var last = new Date().getTime() - timestamp;
@carlhannes
carlhannes / simpe-parallax.js
Last active October 21, 2017 21:59
Very simple ES6 JavaScript background-position parallax function using requestAnimationFrame
export default function attachParallax(elm) {
document.addEventListener('mousemove', (e) => {
window.requestAnimationFrame(() => {
const left = (e.clientX / window.innerWidth) * 5;
const top = (e.clientY / (window.innerHeight)) * 5;
elm.style.backgroundPosition = `${47.5 + left}% ${47.5 + top}%`;
});
}, false);
}
Region Type Count
Stockholm Petrol 1288
Stockholm Diesel 1962
Stockholm Hybrids & Flexifuels 688
Malmo Petrol 495
Malmo Diesel 458
Malmo Hybrids & Flexifuels 116
Gothenburg Petrol 635
Gothenburg Diesel 439
Gothenburg Hybrids & Flexifuels 250
@carlhannes
carlhannes / Creating picassojs extensions - Links.md
Last active May 25, 2019 18:39
Creating picassojs extensions
function JSON2Matrix(jsonArray) {
let matrixHeader = [];
let matrixData = [];
for (let idx = 0; idx < jsonArray.length; idx++) {
const cur = jsonArray[idx];
const keys = Object.keys(cur);
let matrixLine = [];
for (let idk = 0; idk < keys.length; idk++) {
let versions = [];
(await (await fetch('https://unpkg.com/browse/picasso.js/')).text()).replace(/<option[^>]*value="([^"]*)"[^>]*>/gm, (match, version) => versions.push(version) );
Add-WindowsCapability -Online -Name OpenSSH.Server*
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
@carlhannes
carlhannes / debounce.ts
Last active March 11, 2024 11:07
ES6 Async Debounce JavaScript & TypeScript Helper Functions
// ES6 Async version of the "classic" JavaScript Debounce function.
// Works both with and without promises, so you can replace your existing
// debounce helper function with this one (and it will behave the same).
// The only difference is that this one returns a promise, so you can use
// it with async/await.
//
// I've converted this into a TypeScript module, and added a few more
// features to it, such as the ability to cancel the debounce, and also
// execute the function immediately, using the `doImmediately` method.
//
@carlhannes
carlhannes / json-path-resolver.js
Last active February 23, 2022 12:53
JSON Path Resolver in JavaScript
/**
* Resolves the value at the given JSON path
*
* @param {String} path Path with / for children
* @param {Object} obj Object to use when searching
* @return {Object} Result at the end of the path
*
* @example
* let path = "/path/to/paradise";
* let obj = {
@carlhannes
carlhannes / picassorenderer.jsx
Last active May 11, 2022 07:04
React picasso.js rendering area
import React, { useEffect } from 'react';
import picasso from 'picasso.js';
const debounce = (func, wait, immediate = false) => {
let timeout;
return function debouncedFn(...args) {
return new Promise((resolve) => {
clearTimeout(timeout);
timeout = setTimeout(() => {