Skip to content

Instantly share code, notes, and snippets.

View davalapar's full-sized avatar
🦁
rawr

@davalapar davalapar

🦁
rawr
View GitHub Profile
@davalapar
davalapar / downloadFile.js
Created July 31, 2018 12:08 — forked from dreamyguy/downloadFile.js
Download response.data as a file, through Blob()
// 'downloadFile.js', written by blending two solutions:
// 'js-download' https://github.com/kennethjiang/js-file-download
// 'Anders Paulsen' https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
export function downloadFile(data, filename, mime) {
// It is necessary to create a new blob object with mime-type explicitly set
// otherwise only Chrome works like it should
const blob = new Blob([data], {type: mime || 'application/octet-stream'});
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE doesn't allow using a blob object directly as link href.
@davalapar
davalapar / index.js
Last active November 10, 2020 13:09
LetsEncrypt Setup, Renew & NodeJS Usage
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();
app.get('*', (req, res) => res.send('yehh'));
http.createServer(app).listen(80);
@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
*/