Skip to content

Instantly share code, notes, and snippets.

Avatar

Arjan Haverkamp av01d

View GitHub Profile
@av01d
av01d / convertDataURItoBinary.js
Created Jan 20, 2022
Convert base64 string to Uint8Array (one liner)
View convertDataURItoBinary.js
/**
* One liner to convert a base64 string to a binary Uint8Array
*
* Example:
* const dataURL = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2w....';
* console.log(convertDataURIToBinary(dataURL));
*/
const convertDataURIToBinary = dataURI =>
Uint8Array.from(window.atob(dataURI.replace(/^data[^,]+,/,'')), v => v.charCodeAt(0));
@av01d
av01d / ColorSteps.js
Last active Aug 5, 2021
Javascript calculate color steps (gradient) between two colors
View ColorSteps.js
const ColorSteps = (() => {
/**
* Convert any color string to an [r,g,b,a] array.
* @author Arjan Haverkamp (arjan-at-avoid-dot-org)
* @param {string} color Any color. F.e.: 'red', '#f0f', '#ff00ff', 'rgb(x,y,x)', 'rgba(r,g,b,a)', 'hsl(180, 50%, 50%)'
* @returns {array} [r,g,b,a] array. Caution: returns [0,0,0,0] for invalid color.
* @see https://gist.github.com/av01d/8f068dd43447b475dec4aad0a6107288
*/
const colorValues = color => {
@av01d
av01d / colorValues.js
Last active Aug 5, 2021
Javascript: Convert any color (hex, hexa, rgb, rgba, hsl, named) to [r,g,b,a] array
View colorValues.js
/**
* Convert any color string to an [r,g,b,a] array.
* @author Arjan Haverkamp (arjan-at-avoid-dot-org)
* @param {string} color Any color. F.e.: 'red', '#f0f', '#ff00ff', 'rgb(x,y,x)', 'rgba(r,g,b,a)', 'hsl(180, 50%, 50%)'
* @returns {array} [r,g,b,a] array. Caution: returns [0,0,0,0] for invalid color.
*/
const colorValues = color => {
const div = document.createElement('div');
div.style.backgroundColor = color;
document.body.appendChild(div);
@av01d
av01d / getClients.sh
Last active Jan 15, 2021
Commandline Bash script for retrieving connected clients from cable modem/router Compal CH7465LG (Ziggo)
View getClients.sh
#!/bin/bash
#
#--------------------------------------------------------------------
# This script retrieves a list (in XML format) of connected clients
# on a Compal CH7465LG modem/router.
# This modem is provided by various ISPs, a.o:
# - UPC Connect Box (CH)
# - Irish Virgin Media Super Hub 3.0 (IE)
# - Ziggo Connectbox (NL)
# - Unitymedia Connect Box (DE)
@av01d
av01d / jquery.filedropper.js
Created Jul 23, 2020
Super simple jQuery file drop plugin
View jquery.filedropper.js
/**
* Very simple file drop plugin
* @author Arjan Haverkamp - webgear.nl
* @date 2019-01-21
*/
(function($) {
$.fn.FileDropper = function(options) {
var settings = $.extend({
// These are the defaults.
@av01d
av01d / convert-canvas-image.js
Created Jul 23, 2020
Javsacript: Convert canvas to image, image to canvas
View convert-canvas-image.js
function convertImageToCanvas(image) {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d").drawImage(image, 0, 0);
return canvas;
}
function convertCanvasToImage(canvas) {
var image = new Image();
@av01d
av01d / file2bitmap.js
Created Jul 23, 2020
File to Bitmap (on canvas)
View file2bitmap.js
/* HTML:
<input type="file" id="filepicker">
<canvas id="outCanvas"></canvas>
*/
filepicker.addEventListener("change", () => {
createImageBitmap(filepicker.files[0])
.then(response => {
outCanvas.width = response.width;
outCanvas.height = response.height;
@av01d
av01d / jquery.draggable.js
Last active Jul 23, 2020
Super simple jQuery plugin for making DOM elements draggable. Touch compatible.
View jquery.draggable.js
// Plugin: jQuery.draggable
// Author: Arjan Haverkamp - webgear.nl
// Version: 1.0
// Date: 2019-01-30
(function($) {
$.fn.draggable = function(options) {
var $document = $(document), settings = $.extend({
// These are the defaults.