Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@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 / timer.go
Created January 6, 2017 18:48
Timer pool for Go language
package pools
import (
"sync"
"time"
)
var timerPool sync.Pool
// AcquireTimer returns time from pool if possible.
@FZambia
FZambia / redispubsub.go
Last active January 20, 2021 11:21
Redis PUB/SUB vs RethinkDB PUB/SUB
package main
import (
"github.com/garyburd/redigo/redis"
)
func main() {
subConn, err := redis.Dial("tcp", "127.0.0.1:6379")
if err != nil {
panic(err)
@FZambia
FZambia / pool.go
Created October 15, 2020 16:53
Goroutine (worker) pool for Go language
package gpool
import "context"
// Job represents function to be executed in worker.
type Job func()
type worker struct {
jobs chan Job
stop chan struct{}
@FZambia
FZambia / image_download.py
Last active October 10, 2020 07:02
Download image from url for Django
import logging
import requests
from PIL import Image
import requests.exceptions
from StringIO import StringIO
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage
logger = logging.getLogger('uploads')
@FZambia
FZambia / index.html
Created June 20, 2020 18:05
Centrifuge introduction example source code
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="https://rawgit.com/centrifugal/centrifuge-js/master/dist/centrifuge.min.js"></script>
</head>
<body>
<script type="text/javascript">
const centrifuge = new Centrifuge('ws://localhost:8000/websocket');
function drawText(text) {
const div = document.createElement('div');
@FZambia
FZambia / api.swagger.json
Created May 19, 2020 21:02
API Swagger JSON
{
"swagger": "2.0",
"info": {
"title": "api.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
@FZambia
FZambia / logo.js
Created May 13, 2020 21:45
Logo javascript canvas
(function() {
'use strict';
window.addEventListener('load', function() {
var canvas = document.getElementById('canvas');
if (!canvas || !canvas.getContext) {
return false;
}
function rand(min, max) {
@FZambia
FZambia / release.txt
Created May 8, 2020 12:38
Centrifuge v0.8.0 release diff vs v0.7.0
$ gorelease -base=v0.7.0 -version=v0.8.0
github.com/centrifugal/centrifuge
---------------------------------
Incompatible changes:
- (*Client).Send: changed from func(github.com/centrifugal/protocol.Raw) error to func([]byte) error
- (*MemoryEngine).AddHistory: changed from func(string, *github.com/centrifugal/protocol.Publication, *ChannelOptions) (*github.com/centrifugal/protocol.Publication, error) to func(string, *github.com/centrifugal/protocol.Publication, *ChannelOptions) (StreamPosition, bool, error)
- (*Node).Disconnect: changed from func(string, bool) error to func(string, ...DisconnectOption) error
- (*Node).History: changed from func(string) ([]*github.com/centrifugal/protocol.Publication, error) to func(string, ...HistoryOption) (HistoryResult, error)
- (*Node).Publish: changed from func(string, []byte, ...PublishOption) error to func(string, []byte, ...PublishOption) (PublishResult, error)
- (*Node).Unsubscribe: changed from func(string, string) error to func(string, string, ...UnsubscribeOption
@FZambia
FZambia / functions.js
Created March 3, 2020 18:57
Artillery io Centrifugo
This file has been truncated, but you can view the full file.
module.exports = { subscribe };
var items = [
{
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5YmRhNWNlYy02MzRiLTQ2NWItOTNmMC00MTc5MWNmNTAyYzgifQ.DSJ1n4Zrf7CGSX15em3FWrL_4hbJXUFr_lebSQvU7go',
channel: 'notifications#9bda5cec-634b-465b-93f0-41791cf502c8'
},
{
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiYWU3MTQxNy05MmVhLTRjMjMtODNkZi1mMDJlNTA2NTY0NmQifQ.lmfVqgTrGxX3Wy8nPC30852AbWnVUD9iJrWR209Qvw0',
channel: 'notifications#bae71417-92ea-4c23-83df-f02e5065646d'