Skip to content

Instantly share code, notes, and snippets.

@izumskee
izumskee / cloudSettings
Last active April 16, 2020 16:08
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-04-16T16:05:34.241Z","extensionVersion":"v3.4.3"}
@izumskee
izumskee / git-squash-merge-apply.md
Last active March 29, 2023 18:35
GIT: Squash, merge and apply patch

Squash and create patch

If your commits are in the "newlines" branch and you have switched back to your "master" branch already, this should do the trick:

git checkout -b tmpsquash
git merge --squash newlines
git commit -a -m "My squashed commits"
git format-patch master
@izumskee
izumskee / nodejs-mesure.js
Created August 13, 2018 10:16
Mesure function execution time in nodejs
let hrstart = process.hrtime();
// func do smth...
let hrend = process.hrtime(hrstart);
console.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000);
@izumskee
izumskee / server.js
Created February 6, 2018 15:11 — forked from nodkz/apolloServer2019.ts
GraphQL error tracking with sentry.io
/* eslint-disable no-console, import/first */
import path from 'path';
import express from 'express';
import expressStaticGzip from 'express-static-gzip';
import graphqlHTTP from 'express-graphql';
import PrettyError from 'pretty-error';
import bodyParser from 'body-parser';
import raven from 'raven';
import morgan from 'morgan';
import { graphqlBatchHTTPWrapper } from 'react-relay-network-layer';
@izumskee
izumskee / mongo-rules-of-schema-design.md
Last active January 9, 2018 13:43
MongoDB Rules of Schema design
  1. favor embedding unless there is a compelling reason not to

  2. needing to access an object on its own is a compelling reason not to embed it

  3. Arrays should not grow without bound. If there are more than a couple of hundred documents on the “many” side, don’t embed them; if there are more than a few thousand documents on the “many” side, don’t use an array of ObjectID references. High-cardinality arrays are a compelling reason not to embed.

  4. Don’t be afraid of application-level joins: if you index correctly and use the projection specifier (as shown in part 2) then application-level joins are barely more expensive than server-side joins in a relational database.

  5. Consider the write/read ratio when denormalizing. A field that will mostly be read and only seldom updated is a good candidate for denormalization: if you denormalize a field that is updated frequently then the extra work of finding and updating all the instances is likely to overwhelm the savings that you get from denormalizing.

const reduce = function(callback) {
'use strict';
if (this == null) {
throw new TypeError('Array.prototype.reduce called on null or undefined');
}
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@izumskee
izumskee / get-directory.bash
Created May 3, 2017 16:02
get-directory bash
du -h --max-depth=1 /dir
const MODULE_DIR = /(.*([\/\\]node_modules|\.\.)[\/\\](@[^\/\\]+[\/\\])?[^\/\\]+)([\/\\].*)?$/g;
{
loader: 'babel-loader',
test: /\.jsx?$/,
include(filepath) {
if (filepath.split(/[/\\]/).indexOf('node_modules')===-1) return true;
let pkg, manifest = path.resolve(filepath.replace(MODULE_DIR, '$1'), 'package.json');
try { pkg = JSON.parse(fs.readFileSync(manifest)); } catch (e) {}
return !!(pkg.modules || pkg['jsnext:main']);
@izumskee
izumskee / css_for_locale.css
Last active December 9, 2016 08:07
Styling depends on locale
.example:lang(ru) {
/* styles for ru locale */
}