Skip to content

Instantly share code, notes, and snippets.

View darsain's full-sized avatar

darsain

  • Slovakia
View GitHub Profile
@darsain
darsain / package.json
Created June 28, 2020 11:07
electron window reload hang bug reproduction
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "testProcess.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
@darsain
darsain / builder.js
Last active March 6, 2020 18:16
@rollup/plugin-typescript producing the same output on subsequent runs bug reproduction
async function buildScripts() {
const rollup = require('rollup');
const typescript = require('@rollup/plugin-typescript');
const bundle = await rollup.rollup({
input: 'input.ts',
plugins: [typescript()]
});
await bundle.write({
@darsain
darsain / object-find.js
Last active November 28, 2016 12:24
Log key and value of a property containing a string in an object searched recursively while ignoring circular references.
function search(needle, obj, ignore = null) {
needle = needle.toLowerCase();
const objs = new Set();
_search(obj);
function _search(obj, root = '') {
if (!obj || typeof obj !== 'object' || objs.has(obj)) {
return;
}
@darsain
darsain / ES2017-pull-streams.md
Last active April 13, 2019 13:18
Better streaming interface for modern JavaScript.

Better streaming interface for modern JavaScript

Node streams have a lot of issues. Awkward to control backpressure, no error propagation, overcomplicated implementation impenetrable to any view source attempts, etc...

To solve this, here is an implementation of pull-streams in modern JS, using promises, async iterators, and for..await loops.

Features:

  • Built in backpressure.
  • Build in error propagation.
@darsain
darsain / svg_sprites.md
Last active November 17, 2024 01:45
How to use SVG sprites in img[src] and css backgrounds

To make this work in CSS:

background: url('images.svg#chart');

or img:

<img src="images.svg#chart">
@darsain
darsain / boxes.html
Created November 17, 2013 09:21
Testing mouse lag & overall responsiveness.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<style>
html, body {margin: 0; padding: 0; height: 100%; text-align: center; font-family: sans-serif;}
ul {position: absolute; width: 100%; height: 100%; list-style: none; margin: 0; padding: 0;}
ul li {float: left; width: 10%; height: 10%; background: #eee; box-shadow: -1px -1px 0 rgba(0,0,0,.2);}
ul li:hover {background: #f78;}
@darsain
darsain / selhash.js
Last active February 26, 2022 11:29
Function that generates element selector hash. Example: div#foo.bar.baz
function selhash(element) {
if (!element || !element.nodeName) {
return Object.prototype.toString.call(element)
.match(/^\[object (\w+)\]$/i)[1]
.toLowerCase() + ':' + element;
}
var parts = [];
parts.push(element.nodeName.toLowerCase());
if (element.id) {
parts.push('#' + element.id);
@darsain
darsain / parallela.js
Last active December 20, 2015 09:59
Handling of multiple parallel async resolutions in one main callback.
/**
* Handling of multiple parallel async resolutions in one main callback.
*
* @param {Function} callback Function executed after all async stuff has finished.
*
* @return {Function} Proxy generator.
*/
function parallela(callback) {
var args = {};
var proxies = 0;
@darsain
darsain / buffer.js
Last active December 17, 2015 23:39
Buffered logging into HTML element.
var slice = [].slice;
function escape (value) {
escape.el.innerText = value;
return escape.el.innerHTML;
}
escape.el = document.createElement('pre');
function Buffer(frame, size) {
if (!(this instanceof Buffer)) {
@darsain
darsain / JSON
Last active October 12, 2015 04:58
Nicely structured X11 color keywords (used in CSS) and their hex values
{
"aliceblue": "f0f8ff",
"antiquewhite": "faebd7",
"aqua": "00ffff",
"aquamarine": "7fffd4",
"azure": "f0ffff",
"beige": "f5f5dc",
"bisque": "ffe4c4",
"black": "000000",
"blanchedalmond": "ffebcd",