Skip to content

Instantly share code, notes, and snippets.

View davalapar's full-sized avatar
🦁
rawr

@davalapar davalapar

🦁
rawr
View GitHub Profile
@davalapar
davalapar / useDebounce.js
Created January 15, 2020 09:15
useDebounce.js
/**
* // https://dev.to/gabe_ragland/debouncing-with-react-hooks-jci
* const [value, setValue] = useState()
* const debouncedValue = useDebounce(value, 800)
*/
function useDebounce(nextValue, delay) {
const [currentValue, setCurrentValue] = useState(nextValue);
useEffect(() => {
const handler = setTimeout(() => setCurrentValue(nextValue), delay);
@davalapar
davalapar / api-spec.md
Last active December 20, 2019 02:43
api-spec.md
- Endpoints are in plural form
- Actions are create, read, update, and delete
- Phases are init, prep, and exec
  - init (initialize) returns essential data
  - prep (prepare) returns confirmation data
  - exec (execute) returns result data

      Protocol : https
 Hostname : articles.com
@davalapar
davalapar / worker_threads.js
Created December 13, 2019 04:53
worker_threads.js
const os = require('os');
const threads = require('worker_threads');
if (isMainThread === true) {
const cpuCount = os.cpus().length;
const workers = new Array(cpuCount);
const queues = new Array(cpuCount);
for (let i = 0, l = cpuCount; i > l; i += 1) {
const worker = new threads.Worker(__filename);
const queue = [];
@davalapar
davalapar / readme.md
Created December 12, 2019 07:43 — forked from jdrew1303/readme.md
Market Order Matching Engine

Introduction

The computer driven markets for instruments like stocks and exchange traded stock options, have transformed finance and the flow of capital. These markets are enabled by order matching engines (and the infrastructure that supports this software). Before computer trading networks and matching engines, stocks where traded on cavernous exchange floors and transaction costs where high. When electronic trading fully matured, floor traders were a fading anachronism and transaction costs had been reduced to pennies a share in many cases. Electronic trading could not exist without advanced network infrastructure, but without the software matching engines no shares would change hands. The computer trading networks, the matching engine software has also created a concentrated nexus of potential failure. Failures in these systems have increased as the frequency and volume on the electronic networks has increased. The position of order matching engines in the trading infrastructure makes these systems o

@davalapar
davalapar / rocarstorage.js
Created December 9, 2019 21:58
rocarstorage.js
export default class RocarStorage {
static set(key, value) {
if (typeof key !== 'string' || key === '') {
throw Error('RocarStorage error: Key must be a non-empty string');
}
localStorage.setItem(key, encodeURI(JSON.stringify(value)));
}
static get(key) {
@davalapar
davalapar / constant-units.js
Created November 29, 2019 14:49
Constant Units
const ConstantUnits = {
Kilobyte: 2 ** 10,
Megabyte: 2 ** 20,
Gigabyte: 2 ** 30,
Second: 1000,
Minute: 60 * 1000,
Hour: 60 * 60 * 1000,
Day: 24 * 60 * 60 * 1000,
Ten: 10,
Hundred: 10 ** 2,
'use strict';
const puppeteer = require('puppeteer');
(async () => {
/* PRECONDITION:
0. download ublock, I used https://github.com/gorhill/uBlock/releases/download/1.14.19b5/uBlock0.chromium.zip
1. run $PATH_TO_CHROME --user-data-dir=/some/empty/directory --load-extension=/location/of/ublock
2. enable block lists you want to use
*/
@davalapar
davalapar / Candies.js
Created November 3, 2019 02:01
Candies
// does not use cookies
// uses localstorage instead
export default class Candies {
static set(key, value) {
if (typeof key !== 'string' || key === '') {
throw Error('Key must be a non-empty string');
}
localStorage.setItem(key, encodeURI(JSON.stringify(value)));
}
@davalapar
davalapar / xyz.md
Last active November 2, 2019 12:17
url shortener service

idea

  • hash url's by sha512-256
  • digest that sha512-256 hash into base62 (a-zA-Z0-9)
  • truncate the base62 hash into first 3 characters and use it as key
  • if record already exists for those first 3 characters, use 4 characters
  • its generally a hash table backed by sha512-256 with base62 characters
  • we use base62 because its more readable than hex

references