Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Valeri Karpov vkarpov15

🎯
Focusing
Block or report user

Report or block vkarpov15

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
@vkarpov15
vkarpov15 / slowtrain.js
Created May 7, 2019
MongoDB cursor slow train
View slowtrain.js
const mongodb = require('mongodb')
run().catch(error => console.log(error));
async function run() {
const db = await mongodb.MongoClient.
connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
poolSize: 1 // Only 1 operation can run at a time
}).
@vkarpov15
vkarpov15 / index.js
Created Apr 25, 2019
Hello, Imports with `package.json`
View index.js
import test from './test.js';
test();
View remove.js
[document.querySelector('#intercom-frame'), document.querySelector('#intercom-container')].forEach(el => { el.parentNode.removeChild(el); });
@vkarpov15
vkarpov15 / geo.js
Created Jul 18, 2018
Example of querying a GeoJSON feature collection in MongoDB
View geo.js
db.test.drop();
db.test.insertOne({
name: 'Denver',
location: {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
View async.js
let i = 0;
run();
setInterval(() => console.log(i), 10);
async function run() {
++i;
await new Promise(resolve => setTimeout(resolve, 15));
++i;
@vkarpov15
vkarpov15 / promise.js
Last active Jun 19, 2019
Simple Promises/A+ Compliant Promise
View promise.js
const assert = (v, err) => {
if (!v) {
throw err;
}
};
let counter = 0;
class Promise {
constructor(executor) {
@vkarpov15
vkarpov15 / promise2.js
Created Apr 5, 2018
Write Your Own Node.js Promise Library from Scratch, Part 2
View promise2.js
class MyPromise {
constructor(executor) {
if (typeof executor !== 'function') {
throw new Error('Executor must be a function');
}
// Internal state. `$state` is the state of the promise, and `$chained` is
// an array of the functions we need to call once this promise is settled.
this.$state = 'PENDING';
this.$chained = [];
@vkarpov15
vkarpov15 / promise1.js
Created Apr 5, 2018
Write Your Own Node.js Promise Library from Scratch, Part 1
View promise1.js
class MyPromise {
constructor(executor) {
if (typeof executor !== 'function') {
throw new Error('Executor must be a function');
}
// Internal state. `$state` is the state of the promise, and `$chained` is
// an array of the functions we need to call once this promise is settled.
this.$state = 'PENDING';
this.$chained = [];
@vkarpov15
vkarpov15 / archetype-20180119-store-products.js
Created Jan 20, 2018
Modeling Stores and Products with Archetype
View archetype-20180119-store-products.js
const Archetype = require('archetype');
// Generic product type, because prices are specific to each store
const ProductType = new Archetype({
name: {
$type: 'string',
$required: true
}
}).compile('ProductType');
View archetype-20180112-virtuals.js
const Archetype = require('archetype');
const UserBaseType = new Archetype({
name: {
first: {
$type: 'string',
$required: true
},
last: {
$type: 'string',
You can’t perform that action at this time.