Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Valeri Karpov vkarpov15

View GitHub Profile
@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 Mar 20, 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',
@vkarpov15
vkarpov15 / archetype-20180105-transform-required.js
Created Jan 5, 2018
Transform an Archetype So All Properties are Not Required
View archetype-20180105-transform-required.js
const Archetype = require('archetype');
// `UserType` has 3 required properties
const UserType = new Archetype({
name: { $type: 'string', $required: true },
email: { $type: 'string', $required: true },
age: { $type: 'number', $required: true }
}).compile('UserType');
// But what if we want an `update()` function that updates a user?
You can’t perform that action at this time.