Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
@yanmhlv
yanmhlv / nginx-tuning.md
Created December 5, 2024 13:06 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@yanmhlv
yanmhlv / cond.go
Last active January 4, 2024 17:45
Concurrency patterns
import "sync"
type Cond struct {
lock sync.RWMutex
changed chan struct{}
}
func (c *Cond) Listen() <-chan struct{} {
c.lock.RLock()
defer c.lock.RUnlock()
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func handleResponse[T any](resp *http.Response, err error, t *T) error {
if err != nil {
@yanmhlv
yanmhlv / cond.go
Last active June 14, 2023 13:12
concurrency helpers
package cond
type Cond struct {
lock sync.RWMutex
changed chan struct{}
}
func newCond() *Cond {
return &Cond{changed: make(chan struct{})}
}
@yanmhlv
yanmhlv / Evolution of a Python programmer.py
Created August 19, 2022 14:28
Fun: Evolution of a programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@yanmhlv
yanmhlv / gist:708e2c6b90f45964bab7057af2e88ed1
Last active November 26, 2024 19:28
git pull over all subdirectories(depth=1)
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
# or
find . -type d -not -path './.git*' -maxdepth 1 \( ! -name . \)
@yanmhlv
yanmhlv / authorization.ex
Created December 22, 2020 18:19 — forked from nikneroz/authorization.ex
Elixir + Phoenix Framework 1.3 + Guardian 1.0 + JWT(Refresh, Revoke, Recover) + Comeonin
# Elixir + Phoenix Framework 1.3 + Guardian + JWT(Refresh, Revoke, Recover) + Comeonin
### User model bootstrap
Let's generate User model and controller.
```bash
mix ecto.create # create DB table
mix phx.gen.json Accounts User users email:string password_hash:string # scaffold users structure
```
@yanmhlv
yanmhlv / .psqlrc_prod
Last active November 13, 2020 13:30
coloured PROMPT for psql
\x auto
\timing on
SET work_mem='512MB';
SET maintenance_work_mem='1GB';
-- Nicer PSQL prompt
-- Prompt1 / Prompt2
-- %M : server
@yanmhlv
yanmhlv / big_float.go
Created October 10, 2019 08:45
big.Float wrapper
package bigfloat
import (
"fmt"
"math/big"
)
func Zero() *big.Float { return big.NewFloat(0.0) }
func Sub(x, y *big.Float) *big.Float { return Zero().Sub(x, y) }
@yanmhlv
yanmhlv / user management.sql
Last active November 17, 2022 18:38
create user, set password, grand and revoke access to certain and all tables
CREATE USER admin; -- create user with name 'admin'
ALTER USER admin WITH PASSWORD 'hello123'; -- set password
GRANT SELECT ON users TO admin; -- give 'select' access on 'users' table to 'admin' user
REVOKE SELECT ON users FROM admin; -- revoke access on 'users' table from 'admin' user
GRANT SELECT ON ALL TABLES IN SCHEMA public TO admin; -- give access to all tables in public schema to 'admin' user
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM admin; -- revoke access on all tables from 'admin' user
DROP USER admin;