Skip to content

Instantly share code, notes, and snippets.

😎
"The impossible is just lack of trying"

Lucas Santos khaosdoctor

😎
"The impossible is just lack of trying"
Block or report user

Report or block khaosdoctor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@khaosdoctor
khaosdoctor / index.js
Created Sep 17, 2019
Simple bitcoin-like proof of work using worker threads
View index.js
const { payloads } = require('./payloads.json')
const { Worker } = require('worker_threads')
const LEADING_ZEROES = 4
const final = []
let finishedWorkers = 0
for (let payload of payloads) {
const worker = new Worker('./worker.js', { env: { LEADING_ZEROES } })
worker.once('message', (message) => {
View createFollowerGraph.js
const axios = require('axios')
const n4j = require('neo4j-driver').v1
const qs = require('qs')
const driver = n4j.driver('bolt://localhost:7687', n4j.auth.basic('jsuser', '123456'))
const session = driver.session()
const user = process.env.twitterUser
const secret = process.env.twitterKey
const baseUrl = 'https://api.twitter.com/1.1'
View TypePromise.ts
import { PromiseStates, ResolveFunction, RejectFunction, ExecutorFunction, Nullable } from './types/promiseTypes'
type HandlerFunction = {
onFulfilled: ResolveFunction;
onRejected?: Nullable<RejectFunction>
}
enum ReturnType {
SUCCESS = 'success',
ERROR = 'error'
View start-nodeschool-sp.sh
#!/bin/bash
echo "REMOVING EXISTENT CONTAINERS"
docker stop $(docker ps -qa)
docker rm $(docker ps -qa)
rm -rf ./minimal-nodeschool
rm -rf ./nodeschool-servers
rm config.json
export PUBLIC_IP=`curl https://ipinfo.io/ip`
@khaosdoctor
khaosdoctor / oracleAsyncIterator.js
Created May 23, 2019
Oracle database async iterator to iterate over result sets using for await of
View oracleAsyncIterator.js
class Cursor {
constructor (resultSet) {
this.resultSet = resultSet
}
getIterator () {
return {
[Symbol.asyncIterator]: () => this._buildIterator()
}
}
View promiseAllSettled.js
const promises = [ fetch('index.html'), fetch('https://does-not-exist/') ];
const results = await Promise.allSettled(promises);
const successfulPromises = results.filter(p => p.status === 'fulfilled');
View allSettled1.js
function reflect(promise) {
return promise.then(
(v) => {
return { status: 'fulfilled', value: v };
},
(error) => {
return { status: 'rejected', reason: error };
}
);
}
View promiseRace.js
const p1 = Promise.race([
new Promise(resolve => setTimeout(resolve, 4000)),
new Promise((resolve, reject) => setTimeout(reject, 8000))
])
const p2 = Promise.race([
p1,
new Promise(resolve => setTimeout(resolve, 6000)),
new Promise(resolve => setTimeout(resolve, 10000)),
new Promise((resolve, reject) => setTimeout(reject, 2000))
View promiseAllReject.js
Promise.all([
new Promise(resolve => setTimeout(() => resolve([]), 5500)),
new Promise((resolve, reject) => setTimeout(() => reject([1]), 3000)),
new Promise(resolve => setTimeout(() => resolve([1,2]), 2200))
])
.then(results => results.length)
.then(c => console.info(c))
.catch(err => console.error(err))
View promiseAllSuccess.js
Promise.all([
new Promise(resolve => setTimeout(() => resolve([]), 5500)),
new Promise(resolve => setTimeout(() => resolve([1]), 3000)),
new Promise(resolve => setTimeout(() => resolve([1,2]), 2200))
])
.then(results => results.length)
.then(c => console.info(c))
.catch(err => console.error(err))
You can’t perform that action at this time.