Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
@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 / 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 / psql_useful_stat_queries.sql
Created August 22, 2019 20:04 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@yanmhlv
yanmhlv / postgres_queries_and_commands.sql
Created August 22, 2019 19:59 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@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?
@yanmhlv
yanmhlv / gist:a608d7a342cd00b839147d15dbbf9dcd
Created September 15, 2017 12:07 — forked from the42/gist:1956518
GZip encoding for GO V1 using custom responsewriter
package main
import (
"compress/gzip"
"io"
"net/http"
"strings"
)
type gzipResponseWriter struct {
@yanmhlv
yanmhlv / bash-cheatsheet.sh
Created April 30, 2017 13:22 — forked from bilun167/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@yanmhlv
yanmhlv / porno.md
Created January 26, 2017 09:30 — forked from strizhechenko/porno.md
Код ниже генерирует прекрасные названия, не знаю для чего, новые жанры порно или названия программных проектов.
#!/usr/bin/env bash

if [ ! -f /tmp/linux ]; then
    curl -sS https://www.linux.org.ru/ | egrep -o /tag/[0-9a-z-]+ | sed 's|/tag/||' > /tmp/linux
fi
if [ ! -f /tmp/pron ]; then
    curl -sS http://www.xvideos.com/tags  | egrep -o /tags/[a-z0-9-]+ | sed 's|/tags/||' > /tmp/pron
fi
@yanmhlv
yanmhlv / mergesort.lhs
Created October 5, 2016 12:23 — forked from callistabee/mergesort.lhs
Haskell Implementation of Mergesort
- Haskell Mergesort
- Copyright (C) 2014 by Kendall Stewart
First we define a couple of helper functions that
will be useful in splitting the list in half:
> fsthalf :: [a] -> [a]
> fsthalf xs = take (length xs `div` 2) xs

What is sync.Pool in golang and How to use it

sync.Pool (1/2)

Many Go libraries include custom thread-safe free lists, like this:

var objPool = make(chan *Object, 10)

func obj() *Object {

select {