Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

vadv vadv

🏠
Working from home
View GitHub Profile
View main.go
package main
import (
"flag"
"fmt"
"net"
"os"
"strconv"
"strings"
"time"
View fsm.md

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.

Schema

View main.go
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
View Golang.md

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.

View 1.md
begin;
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);
commit;
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 order.id */
create table order_events (
View dump_playlist.py
#!/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 (
"bytes"
"crypto/aes"
"fmt"
"io"
)
// читаем из io.Reader размером size и записываем в io.Writer дешифрованный поток ключом key
View libraries_telegram_handler.rb
require "chef/handler"
require "etc"
require "date"
class TelegramHandler < Chef::Handler
BOT_API_KEY = 'BOTAPI:KEY'
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
USING gin
(data_hstore);
CREATE INDEX test_nosql_jsonb_gin