Skip to content

Instantly share code, notes, and snippets.

View YuriGor's full-sized avatar
🍒
Making perfect, remember to finish.

Yuri Gor YuriGor

🍒
Making perfect, remember to finish.
View GitHub Profile
@YuriGor
YuriGor / dg-jsplumb.js
Last active September 3, 2016 21:37 — forked from michiel/dg-jsplumb.js
// based on http://onais-m.blogspot.nl/2014/10/automatic-graph-layout-with-javascript.html
var jsp = jsPlumb.getInstance();
// construct dagre graph from JsPlumb graph
/* global dagre */
var g = new dagre.graphlib.Graph();
g.setGraph({nodesep:30,ranksep:30,marginx:50,marginy:50});
g.setDefaultEdgeLabel(function() { return {}; });
$('.xnode').each(
@YuriGor
YuriGor / count-docs.js
Created September 24, 2018 12:52
Benchmark for different MongoDB(Mongoose) count all the docs methods. No difference.
// find().count() vs find().limit(1).count() vs count() vs collection.count()
// Purpose was to detect if collections is empty or not. (That's why limit(1) is fine too)
const { performance } = require('perf_hooks');
const fs = require('fs');
const mongoose = require('mongoose');
require('dotenv').config();
const billionUsers = mongoose.model('User', {
n: {
@YuriGor
YuriGor / User.test.js
Last active November 16, 2018 03:09
Example of mongoDb test for builderbook
// /test/server/models/User.test.js
// see https://github.com/vladgolubev/jest-mongodb for preparing in-memory mongoDB for this test.
const mongoose = require('mongoose');
const User = require('../../../server/models/User');
describe('slugify', () => {
beforeAll(async () => {
await mongoose.connect(global.__MONGO_URI__);
console.log('connected');

pre update mongoose hook options ignored

@YuriGor
YuriGor / pre-update-one-doc-id.js
Last active October 15, 2018 08:56
How to get updating document _id inside pre-updateOne hook?
const fs = require('fs');
const stringify = require('json-stringify-safe');
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
async function main() {
let _id = '';
const mongoUri = 'mongodb://localhost/pre';
@YuriGor
YuriGor / naomi-markdown.md
Created October 25, 2018 07:28
Naomi markdown js code block issue

Some text here, common color

  Code without syntax

some more text, still looks fine

let it = 'be';//code with js syntax.
@YuriGor
YuriGor / usageExample.js
Last active November 6, 2019 05:46
vanilla-picker as absolutely auto-positioned dialog added to document.body - WIP: https://github.com/Sphinxxxx/vanilla-picker/issues/24
import colorDialog from './vanillaColorDialog';
document.getElementById('some-other-button').addEventListener('click',function(e){
// auto position is by default
colorDialog(e, '#000000'/* ,{ popup: 'auto', popup: ['right', 'left', 'bottom', 'top'], otherVanillaOption: 'whatever' }*/).then(console.log);
});
@YuriGor
YuriGor / index.js
Created July 16, 2020 16:00
eachDeep over mongoose document
const { eachDeep } = require('deepdash/standalone')
const mongoose = require('mongoose')
const RandomSchema = mongoose.Schema({ items: [mongoose.Schema()] })
const RandomModel = mongoose.model('random', RandomSchema)
function demo () {
const myDocument = new RandomModel({
items: [{}]
})
@YuriGor
YuriGor / Cargo.toml
Last active February 3, 2023 15:08
Vec vs HashMap read performance (ObjectId keys + rustc_hash)
[package]
name = "indexed_hash_map"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
mongodb = "2.3.0"
rustc-hash = "1.1.0"