Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
@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 (
"bytes"
"errors"
"html/template"
"net/http"
"path/filepath"
)
@yanmhlv
yanmhlv / example.go
Created February 8, 2016 14:49
JSONB in gorm
package main
import (
"database/sql/driver"
"encoding/json"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
@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 / System Design.md
Created March 6, 2019 14:58 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
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 / 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;
@yanmhlv
yanmhlv / example.go
Last active October 24, 2022 18:40
logging body middleware for labstack/echo
package main
import (
"bytes"
"io/ioutil"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
mw "github.com/labstack/echo/middleware"
)
@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 / books.txt
Created February 1, 2015 19:47
Книги по IT, взято с /pr
=Algorithms
+ Дискретная математика для программистов Г. Хаггард
+ Concrete Mathematics: A Foundation for Computer Science Ronald L. Graham
+ Алгоритмы. Построение и анализ Томас Кормен
+ Искусство программирования. Том 1. Основные алгоритмы Дональд Кнут
+ The Algorithm Design Manual Steven S Skiena
+ Introduction to Distributed Algorithms Gerard Tel
+ Clever Algorithms: Nature-Inspired Programming Recipes Jason Brownlee