Skip to content

Instantly share code, notes, and snippets.

@Busyrev
Busyrev / gzip.md
Last active August 4, 2022 18:55
О сжатии на протокольном уровне (http)

О сжатии на протокольном уровне (http)

Актулизировано на момент 03.12.2018 Док несколько потерял в актуальности, см презентацию https://docs.google.com/presentation/d/1bw0ypsrdyC2l35Z-h65D09ABQDSZ_Ecfp02-zE6Fmqc Если кратко то brotli 0 в 4 раза быстрее чем gzip 1, при том же сжатии И brotli 4 столь же быстр как gzip 1 на круче чем gzip 9

Обозреваемые форматы сжатия:

  • gzip 1 - минимальный уровень сжатия gzip, результат .gz
  • gzip 9 - максимальный уровень сжатия gzip, результат .gz
  • zopfli - отдельный алгоритм совместимый с распаковщиком gzip, результат .gz

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.

@RubaXa
RubaXa / vars.js
Last active July 28, 2022 08:45
Multivar & Trailing comma vs. Diff
// 1. var
var name = 'name';
var i, length;
var j = 0;
// 2. var
var name = 'name';
var i;
var j = 0;
var length;
@RubaXa
RubaXa / xhr.js
Last active July 26, 2018 05:30
Микро обертка для выполенения XHR-запросов
/**
* Микро обертка для выполенения XHR-запросов
* @namepace window.xhr
* @example
* xhr.load('/path/to', {type: 'POST'}, function (err, xhr) {
* // ...
* });
*/
(function (global) {
'use strict';
@termi
termi / deepExtend.js
Last active August 29, 2015 13:57
deep extend
var _hasOwn = Object.prototype.hasOwnProperty;
var _toString = Object.prototype.toString;
var _hasGOPD = typeof Object.getOwnPropertyDescriptor === 'function';
var _hasDP = typeof Object.defineProperty === 'function';
function _getOwnPropertyDescriptor(obj, prop) {
if ( _hasGOPD ) {
return Object.getOwnPropertyDescriptor(obj, prop)
}
else {
/**
* User Timing polyfill (http://www.w3.org/TR/user-timing/)
* @author RubaXa <trash@rubaxa.org>
*/
(function (window){
var
startOffset = Date.now ? Date.now() : +(new Date)
, performance = window.performance || {}
, _entries = []
@RubaXa
RubaXa / Promise.js
Last active September 16, 2017 18:17
«Promise.js» — is supported as a native interface and $.Deferred.
/**
* @author RubaXa <trash@rubaxa.org>
* @license MIT
*/
(function () {
"use strict";
function _then(promise, method, callback) {
return function () {
@maccman
maccman / jquery.ajax.queue.coffee
Last active January 13, 2018 12:03
Queueing jQuery Ajax requests. Usage $.ajax({queue: true})
$ = jQuery
queues = {}
running = false
queue = (name) ->
name = 'default' if name is true
queues[name] or= []
next = (name) ->
@RubaXa
RubaXa / jquery.event.scroll.js
Last active December 17, 2015 06:58
jQuery extension, add support `scrollstart` and `scrollend` events.
/**
* jQuery extension, add support `scrollstart` and `scrollend` events.
*
* @author RubaXa <trash@rubaxa.org>
* @github https://gist.github.com/RubaXa/5568964
* @license MIT
*
*
* @settings
* $.special.scrollend.delay = 300; // default ms
/**
* Watcher leaks for jQuery
* RubaXa <trash@rubaxa.org>
* MIT Licensed.
*
* API:
* $.leaks.get();
* $.leaks.watch();
* $.leaks.unwatch();
* $.leaks.remove();