Skip to content

Instantly share code, notes, and snippets.

View KiranMantha's full-sized avatar
🎯
Focusing on PlumeJS

Kiran Mantha KiranMantha

🎯
Focusing on PlumeJS
View GitHub Profile
@rstacruz
rstacruz / README.md
Last active April 20, 2025 07:18
Setting up Jest with ESM

Setting up Jest with ESM

Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.

Method A: Native Node.js support

Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.

Install cross-env:

@elclanrs
elclanrs / README.md
Last active May 21, 2024 22:10
VanillaJS popover with autoposition
@jcormont
jcormont / barcode-128-svg.js
Created October 12, 2017 15:00
Simple Code-128 (128B) barcode SVG generator, in vanilla JS
var Barcode128Svg = (function () {
function Barcode128Svg(input) {
this.input = input;
this.factor = 2;
this.height = 75;
}
var lookup = {}, data = "212222222122222221121223121322131222122213122312132212221213221312231212112232122132122231113222123122123221223211221132221231213212223112312131311222321122321221312212322112322211212123212321232121111323131123131321112313132113132311211313231113231311112133112331132131113123113321133121313121211331231131213113213311213131311123311321331121312113312311332111314111221411431111111224111422121124121421141122141221112214112412122114122411142112142211241211221114413111241112134111111242121142121241114212124112124211411212421112421211212141214121412121111143111341131141114113114311411113411311113141114131311141411131".split(/(\d{6})/).filter(function (s) { return !!s });
for (var i = 32; i < 127; i++)
lookup[String.fromCharCode(i)] = [i - 32, data[i - 32]];
@jwilson8767
jwilson8767 / es6-element-ready.js
Last active February 24, 2025 08:50
Wait for an element to exist. ES6, Promise, MutationObserver
// MIT Licensed
// Author: jwilson8767
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/
@lopspower
lopspower / README.md
Last active April 28, 2025 07:59
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

/**
* jQuery 2.1.3's parseHTML (without scripts options).
* Unlike jQuery, this returns a DocumentFragment, which is more convenient to insert into DOM.
* MIT license.
*
* If you only support Edge 13+ then try this:
function parseHTML(html, context) {
var t = (context || document).createElement('template');
t.innerHTML = html;
return t.content;
@austinhyde
austinhyde / js-observables-binding.md
Last active January 7, 2025 08:27
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@outmost
outmost / gist:6388914
Created August 30, 2013 11:24
Read and Write large files using NodeJS
var fs = require('fs');
var readline = require('readline');
var stream = require('stream');
var inputfile = "pathtofile.txt";
var outputfile = "pathtooutputfile.json";
var instream = fs.createReadStream(inputfile);
var outstream = fs.createWriteStream(outputfile, {'flags': 'a'});
outstream.readable = true;
@mudge
mudge / eventemitter.js
Last active December 4, 2024 08:35
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;