This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
How to use: | |
import limiter from './limiter' | |
const limit = limiter(<wait_time_in_ms>) | |
limit(() => console.log('foo')) | |
limit(async () => console.log('bar')) | |
*/ | |
export default (interval : number) => { | |
if (interval <= 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const busyCallbacks = new Set() | |
export async function busy(callback : () => any) : Promise<any> { | |
if (busyCallbacks.has(callback)) { | |
return | |
} | |
busyCallbacks.add(callback) | |
const value = await callback() | |
busyCallbacks.delete(callback) | |
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs' | |
import path from 'path' | |
const recursiveReaddirSync = (currentPath : string) => { | |
let results : Array<string> = [] | |
fs.readdirSync(currentPath).forEach(filename => { | |
const filePath = path.resolve(currentPath, filename) | |
const stat = fs.statSync(filePath) | |
if (stat.isDirectory()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It converts simple XML structures to JS objects. The default value of a node is an | |
// empty string, as it should be (contrary to several libraries I tested). | |
const { DOMParser } = require('@xmldom/xmldom') | |
const loadChildNodesRecursive = node => { | |
const nodes = {} | |
Array.from(node.childNodes) | |
.filter(element => element.nodeType === element.ELEMENT_NODE) | |
.forEach(element => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
import async_queue from 'async_queue' | |
const queue = async_queue(<wait_time_in_ms>) | |
queue(async () => await someSlowAction1()) | |
queue(async () => await someSlowAction2()) | |
*/ | |
export default (waitTime : number) => { | |
const queue : Array<() => Promise<void>> = [] | |
return (callback : () => Promise<void>) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Currently, the ESLint plugin used by Svelte is buggy and choke on files with Sass. | |
// This little implementation takes care of removing styling from Svelte components as | |
// as well as handle any type of files other than Svelte, with complete respect of rules | |
// from the base ESLint plugin (that is, `.eslintrc.cjs` rules are used). It has been | |
// thought to be simple to use and integrate. | |
// | |
// https://github.com/sveltejs/eslint-plugin-svelte3/issues/10 | |
// | |
// Usage example: | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Event testing.</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w==" crossorigin="anonymous" /> | |
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script> | |
<style> | |
* { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
current_dir := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) | |
.PHONY=install | |
install: | |
ln -sf $(current_dir)config ~/.test/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fancy_loader(current, total) | |
glyph = "⠹⠼⠶⠧⠏⠛"[(Time.now.to_f * 10).to_i % 6] | |
print "\r#{glyph} #{current}/#{total}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeService | |
def call(some_value, bypass_some_method4 = false) | |
pipe( | |
some_value, | |
:some_method1, | |
:some_method2, | |
-> (value) { value * 2 }, | |
bypass_some_method4 ? :noop : :some_method4, | |
:some_method5 | |
) |
NewerOlder