Skip to content

Instantly share code, notes, and snippets.


Konstantin Vyatkin tinovyatkin

View GitHub Profile
JozefFlakus / marblejs-example.ts
Created May 12, 2019
Marble.js - one file example
View marblejs-example.ts
import { createServer, combineRoutes, httpListener, r } from '@marblejs/core';
import { logger$ } from '@marblejs/middleware-logger';
import { bodyParser$ } from '@marblejs/middleware-body';
import { map, mapTo } from 'rxjs/operators';
// USERS API definition
const getUserList$ = r.pipe(
svx / package.json
Created Nov 12, 2018 — forked from oroce/package.json
run eslint only on changed (*.js files) files using pre-commit
View package.json
"scripts": {
"eslint": "LIST=`git diff-index --name-only HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST; fi"
"devDependencies": {
"pre-commit": "0.0.7",
"eslint": "~0.5.1"
"pre-commit": [
norbornen / move-first-string-to-eof.js
Last active Dec 8, 2019
move file first string to the end of file: node.js, stream
View move-first-string-to-eof.js
#!/usr/bin/env node
const fs = require('fs');
const {Buffer} = require('buffer');
const filepath = process.argv[2];
if (!filepath) {
console.log('\nДолжен быть указан путь к существующему файлу!\n');
ebidel / feature_detect_es_modules.js
Last active Oct 12, 2020
Feature detect ES modules: both static import and dynamic import()
View feature_detect_es_modules.js
Complete feature detection for ES modules. Covers:
1. Static import: import * from './foo.js';
2. Dynamic import(): import('./foo.js').then(module => {...});
Thanks to @_gsathya, @kevincennis, @rauschma, @malyw for the help.
jwo / query.graphql
Last active Nov 26, 2020
GraphQL Example for GitHub API repo statuses on a pull request. We know before hand that it's "jwo/react-hover-image" and pull request number 4
View query.graphql
repository(owner: "jwo", name:"react-hover-image"){
pullRequest(number: 4){
author {

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

paulirish / server-timing-demo.js
Last active May 11, 2020
Demo of server timing values. visualized in chrome devtools
View server-timing-demo.js
// see for screenshot:
const http = require('http');
function requestHandler(request, response) {
const headers = {
'Server-Timing': `
sql-1;desc="MySQL lookup Server";dur=100,
sql-2;dur=900;desc="MySQL shard Server #1",
benjamincharity / circle.yml
Last active Apr 23, 2019
CircleCI deploy to NPM
View circle.yml
version: 6.9.5
- 'echo "//${NPM_TOKEN}" > ~/.npmrc'
- rm -rf $CIRCLE_ARTIFACTS/coverage
davisford / Setup MongoDB on localhost as Replica Set
Last active Nov 20, 2020
Setup MongoDB replica set on local host with only a single primary
View Setup MongoDB on localhost as Replica Set
Add the `replication` section to the mongod.conf file:
$cat /usr/local/etc/mongod.conf
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
engine: mmapv1
tinovyatkin / installRollbar.js
Last active Sep 28, 2016
Use navigator.sendBeacon with Rollbar
View installRollbar.js
// This function will be used as transorm call and actually sends the payload
function beaconRollbar(payload) {
// create blob to set content type to JSON - needed for correct HTTP header
const blob = new Blob([JSON.stringify(payload)], { type: 'application/json; charset=UTF-8' });
navigator.sendBeacon(`${window.Rollbar.options.endpoint}item/?post_client_item=${window.Rollbar.options.accessToken}`, blob);
* Rollbar normal init code goes here
* const rollbarConfig = { .. }
You can’t perform that action at this time.