Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@alexaandru
alexaandru / chi.go
Created February 14, 2024 16:40
Chi-like syntactic sugar layer on top of stdlib http.ServeMux
// Chi-like syntactic sugar layer on top of stdlib http.ServeMux.
package main
import (
"net/http"
"slices"
)
type (
middleware func(http.Handler) http.Handler
@PlugFox
PlugFox / jwt.dart
Last active November 21, 2023 14:24
Centrifugo JWT
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';
/// {@template jwt}
/// A JWT token consists of three parts: the header,
/// the payload, and the signature or encryption data.
/// The first two elements are JSON objects of a specific structure.
/// The third element is calculated based on the first two
@tidwall
tidwall / main.go
Created March 13, 2019 17:46
Go 1.12 network slowdown on Darwin
package main
import (
"fmt"
"io"
"log"
"net"
"os"
"sync"
"sync/atomic"
@adnaan
adnaan / centrifuge-react-native.jsx
Last active August 16, 2021 13:53
Centrifuge Client example for react native
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Centrifuge from 'centrifuge';
export default class App extends React.Component {
componentDidMount() {
console.log("componentDidMount")
var timestamp = Math.floor(Date.now() / 1000);
var centrifuge = new Centrifuge({
@Orabig
Orabig / app.component.ts
Last active September 21, 2022 21:59
Centrifugo Client Service for Angular 2 #Centrifugo #Angular2 #service
// Register your service as usual. I suggest adding it to [providers] in the module definition
// Then...
...
var user = ...;
var info = ...; // Optional
var timestamp = Date.now() / 1000 | 0;
var token = <Get the token from your ws>;
this.centrifugeService.connect({
url: 'http://<centrifugoServer>:8000/connection',
@spugachev
spugachev / tarantool.md
Created April 24, 2017 20:07
Введение в работу с Tarantool

Работа с Tarantool

Начать работу с Tarantool можно запустив обучающий туториал на официальном сайте https://tarantool.org/en/try.html

Это позволяет попробовать Tarantool прямо из браузера сразу и без регистрации. Также на официальном сайте представлены инструкции по установке и запуску Tarantool в macOS, популярных дистрибутивах Linux и FreeBSD. Версии для Windows Tarantool не имеет.

Но не спешите сразу устанавливать Tarantool непосредственно в операционную систему. Самым удобным способом быстро запустить и попробовать Tarantool на Linux, macOS или Windows является Docker. Если у вас уже установлен Docker, то запуск контейнера с Tarantool может быть выполнен одной командой:

docker run --name mytarantool -d tarantool/tarantool:1.7

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.

@MichaelPote
MichaelPote / himawari.ps1
Created February 3, 2016 19:11
Windows Powershell Script to download the latest image from the Himawari-8 satelite, combine the tiles into a single image, convert to jpg and then set as the desktop background.
#
# Himawari-8 Downloader
#
#
#
# This script will scrape the latest image from the Himawari-8 satellite, recombining the tiled image,
# converting it to a JPG which is saved in My Pictures\Himawari\ and then set as the desktop background.
#
# http://himawari8.nict.go.jp/himawari8-image.htm
#
@Malezha
Malezha / Centrifuge.php
Created August 25, 2015 20:23
Verifying access to channel
<?php
namespace App\Http\Controllers\Admin\API;
use App\Http\Controllers\Controller;
use App\Models\Channel;
use Illuminate\Http\Request;
class Centrifuge extends Controller
{
@bdarnell
bdarnell / streaming.py
Created January 11, 2015 21:23
Demo of streaming requests with Tornado
"""Demo of streaming requests with Tornado.
This script features a client using AsyncHTTPClient's body_producer
feature to slowly produce a large request body, and two server
handlers to receive this body (one is a proxy that forwards to the
other, also using body_producer).
It also demonstrates flow control: if --client_delay is smaller than
--server_delay, the client will eventually be suspended to allow the
server to catch up. You can see this in the logs, as the "client