Skip to content

Instantly share code, notes, and snippets.

View kirillgroshkov's full-sized avatar
💭
(кродеться)

Kirill Groshkov kirillgroshkov

💭
(кродеться)
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active April 18, 2024 06:02
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@Sawtaytoes
Sawtaytoes / createTransformStreamSubject.js
Last active May 2, 2019 15:51
`createTransformStreamSubject` implements a clean subject-like interface around a Node.js transform stream.
const { fromEvent, Subject } = require('rxjs')
const { take } = require('rxjs/operators')
const { Transform } = require('stream')
const createTransformStreamSubject = (
nodeJsStream,
) => {
const chunk$ = new Subject()
const push$ = new Subject()
const transformStream$ = new Subject()
@Sawtaytoes
Sawtaytoes / createIteratorSubject.js
Last active February 27, 2020 11:32
`createIteratorSubject` allows someone to create an observable out of a generator and tell RxJS when to pull the next value instead of relying on the official implementation which creates backpressure.
const { BehaviorSubject, Subject } = require('rxjs')
const { map, tap, withLatestFrom } = require('rxjs/operators')
const createIteratorSubject = (
iterator,
) => {
const iterator$ = (
new BehaviorSubject()
)
@ebidel
ebidel / feature_detect_es_modules.js
Last active September 4, 2023 13:56
Feature detect ES modules: both static import and dynamic import()
<!--
Complete feature detection for ES modules. Covers:
1. Static import: import * from './foo.js';
2. Dynamic import(): import('./foo.js').then(module => {...});
Demo: http://jsbin.com/tilisaledu/1/edit?html,output
Thanks to @_gsathya, @kevincennis, @rauschma, @malyw for the help.
-->
@naesheim
naesheim / buildWhenAffected.sh
Last active November 28, 2022 20:20
CircleCi - only build features that has changed
##################
### config.yml ###
##################
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6
steps:
@lucasdavila
lucasdavila / fixup.txt
Last active December 20, 2023 12:00
Fixing mac os yosemite issue "bash: fork: Resource temporarily unavailable"
# see the current limits
$ sysctl -a | grep maxproc
# increase it
$ sudo sysctl -w kern.maxproc=xxxx
$ sudo sysctl -w kern.maxprocperuid=xxx
# run at startup
$ sudo vim /etc/sysctl.conf
@branneman
branneman / better-nodejs-require-paths.md
Last active April 8, 2024 00:22
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@mathiasbynens
mathiasbynens / deterministic-math-random.js
Last active July 19, 2022 06:52
Here’s a 100% deterministic (predictable) alternative to `Math.random`. Useful when benchmarking.
// Here’s a 100% deterministic alternative to `Math.random`. Google’s V8 and
// Octane benchmark suites use this to ensure predictable results.
Math.random = (function() {
var seed = 0x2F6E2B1;
return function() {
// Robert Jenkins’ 32 bit integer hash function
seed = ((seed + 0x7ED55D16) + (seed << 12)) & 0xFFFFFFFF;
seed = ((seed ^ 0xC761C23C) ^ (seed >>> 19)) & 0xFFFFFFFF;
seed = ((seed + 0x165667B1) + (seed << 5)) & 0xFFFFFFFF;
@rab
rab / .gitconfig
Last active April 1, 2024 20:51
A good starting point for ~/.gitconfig
# -*- Conf -*-
[color]
branch = auto
diff = auto
status = auto
showbranch = auto
ui = true
# color.branch
# A boolean to enable/disable color in the output of git-branch(1). May be set to always, false (or
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs