Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@FZambia
FZambia / patch.diff
Created September 21, 2019 14:04
Klauspost compress library as replacement for std lib in Gorilla Websocket
diff --git a/compression.go b/compression.go
index 813ffb1..4c492e0 100644
--- a/compression.go
+++ b/compression.go
@@ -41,16 +41,47 @@ func isValidCompressionLevel(level int) bool {
return minCompressionLevel <= level && level <= maxCompressionLevel
}
-func compressNoContextTakeover(w io.WriteCloser, level int) io.WriteCloser {
+// FlateWriter ...
@FZambia
FZambia / pool.go
Created September 10, 2019 14:39
Go language timer pool
package timers
import (
"sync"
"time"
)
var timerPool sync.Pool
// AcquireTimer from pool.
@FZambia
FZambia / bench.go
Created March 19, 2019 14:56
Gorilla Websocket Upgrade Benchmark
func BenchmarkUpgrade(b *testing.B) {
br := bufio.NewReaderSize(strings.NewReader(""), 4096)
bw := bufio.NewWriterSize(&bytes.Buffer{}, 4096)
upgrader := Upgrader{
ReadBufferSize: 0,
WriteBufferSize: 0,
}
resp := &reuseTestResponseWriter{
brw: bufio.NewReadWriter(br, bw),
@FZambia
FZambia / index.html
Last active June 5, 2019 08:48
Centrifuge library Habr example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Обратите внимание, что клиент тут импортируется из ветки c2 репозитория centrifuge-js -->
<script type="text/javascript" src="https://rawgit.com/centrifugal/centrifuge-js/c2/dist/centrifuge.min.js"></script>
</head>
<body>
<input type="text" id="input" />
<script type="text/javascript">
@FZambia
FZambia / nginx.conf
Created March 22, 2018 20:04
Nginx to proxy Websocket and GRPC traffix on the same port
events {
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
map $http_upgrade $connection_upgrade {
default upgrade;
@FZambia
FZambia / main.js
Last active March 8, 2018 16:48
Connect to Centrifuge from client side.
var centrifuge = new Centrifuge("ws://localhost:8000/connection/websocket");
centrifuge.on("connect", function() {
centrifuge.rpc({"input": "test"}).then(function(data){
console.log(data);
}, function(err) {
console.log(err);
})
});
@FZambia
FZambia / main.go
Last active March 8, 2018 16:50
Centrifuge library small example
package main
import (
"context"
"log"
"net/http"
"github.com/centrifugal/centrifuge"
)
@FZambia
FZambia / client.proto
Last active February 14, 2018 12:05
Clean Centrifugo v2 client proto
syntax = "proto3";
package proto;
message Error {
uint32 Code = 1;
string Message = 2;
}
enum MethodType {
@FZambia
FZambia / reconnect.go
Created January 15, 2018 19:57
survive subscription error
package main
// Demonstrate how to reconnect.
import (
"fmt"
"log"
"time"
"github.com/centrifugal/centrifuge-mobile"
@FZambia
FZambia / gist:7ec1da90de45327605a3043d3891e2d3
Created October 25, 2017 15:47 — forked from klovadis/gist:5170446
Two Lua scripts for Redis to turn HGETALL and HMGET into dictionary tables
-- gets all fields from a hash as a dictionary
local hgetall = function (key)
local bulk = redis.call('HGETALL', key)
local result = {}
local nextkey
for i, v in ipairs(bulk) do
if i % 2 == 1 then
nextkey = v
else
result[nextkey] = v