Skip to content

Instantly share code, notes, and snippets.

Working from home

vadv vadv

Working from home
View GitHub Profile
View main.go
package main
import (

Finite state machine in PostgreSQL

This document will not disclose the topic why you need fsm.

But if you implement fsm, then you need to do it as nearly as possible in the data.

This document will explain how you can implement it with PostgreSQL and gives developers maximum freedom.


View main.go
package main
import (

This article is about how to plan connections to PostgreSQL in Golang applications.

Recommended libraries

The standard PostgreSQL library is de-facto: lib/pq

Also, the quite popular library is: pgx

I do not impose the use of any libraries, and I make a description of how to use the specified.

drop table if exists audit_data;
create table audit_data ( id bigserial unique not null, payment_id text, payload text );
insert into audit_data (payment_id, payload)
select md5(i::text),
       repeat(md5(i::text), 10)
from generate_series(1, 1000*1000) s(i);
View 01_schema.sql
/* list of order */
create table "order" (
id text primary key,
created_at timestamp with time zone default current_timestamp,
processed_at timestamp with time zone,
processed_state text
/* processed transition on */
create table order_events (
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import requests
import sys
from Crypto.Cipher import AES
View crypto.go
package crypto
import (
// читаем из io.Reader размером size и записываем в io.Writer дешифрованный поток ключом key
View libraries_telegram_handler.rb
require "chef/handler"
require "etc"
require "date"
class TelegramHandler < Chef::Handler
CHAT_ID = -id
PROXY_ADDR = 'http://chef/telegram/'
View hstore_vs_jsonb.sql
-- create table test_nosql(id integer, data_hstore hstore, data_jsonb jsonb);
create table test_nosql(id integer, data_jsonb jsonb, data_hstore hstore);
CREATE INDEX test_nosql_hstore_gin
ON test_nosql
CREATE INDEX test_nosql_jsonb_gin