Skip to content

Instantly share code, notes, and snippets.

import { fromEvent, interval } from 'rxjs';
import { throttle } from 'rxjs/operators';
const clicks = fromEvent(document, 'click');
//const result = clicks.pipe(throttle(ev => interval(1000)));
const result = interval(2000).pipe(throttle( i => clicks));
result.subscribe(x => console.log(x));
import { fromEvent, interval } from 'rxjs';
import { tap, throttle } from 'rxjs/operators';
const clicks = fromEvent(document, 'click');
//const result = clicks.pipe(throttle(ev => interval(1000)));
const result = interval(2000).pipe(tap(x => console.log('v:', x)), throttle( i => clicks, {leading: true, trailing: true}));
result.subscribe(x => console.log(x));
fib_(1,[1]).
fib_(2,[1,1]).
fib_(3, [H|[A|[B|Tail]]]) :- fib_(2, [A|[B|Tail]]), H is A + B.
fib_(N, [H|[A|[B|Tail]]]) :- N2 is N - 1, fib_(N2, [A|[B|Tail]]), H is A + B.
fib(N, List) :- fib_(N, List0), reverse(List0, List).
// Example POST method implementation:
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"
done
@rockydd
rockydd / replace.sh
Created December 2, 2020 17:33
sed in mac need to provide backup file extension
git grep --name-only app *.ts | gawk 'system("sed -i \"\" sAappA@yyy/zzzA "$1)'
@rockydd
rockydd / sort_script.jq
Last active June 3, 2024 15:24
A jq script for comprehensive sorting of JSON objects. It recursively sorts keys in objects, orders arrays by simple types, and sorts arrays of objects by 'name' or 'id'. Ideal for standardizing complex JSON structures for APIs, configurations, or data processing. Usage: jq -f sort_script.jq input.json with input.json as your target JSON file.
def recursive_sort:
if type == "object" then
to_entries
| sort_by(.key)
| map( {key: .key, value: (.value | recursive_sort)} )
| from_entries
elif type == "array" then
map( if type == "object" or type == "array" then . | recursive_sort else . end )
| if length == 0 or (first | type) != "object" then
sort