Skip to content

Instantly share code, notes, and snippets.

View C-Pro's full-sized avatar
💭
👍

Sergey Melekhin C-Pro

💭
👍
View GitHub Profile
@C-Pro
C-Pro / audit_trail.sql
Created May 4, 2023 08:11
Simple trigger based table audit example
create table t1(x int);
create table t2 (x int, y varchar);
create table audit_trail(
id bigserial primary key,
table_name varchar,
data_before jsonb,
data_after jsonb,
ts timestamp
);
@C-Pro
C-Pro / mapbench_test.go
Created March 25, 2023 07:52
Compare allocation size for different type of map values for "set" type containers, where only the keys are of any interest.
package main_test
import "testing"
func BenchmarkBoolMap(b *testing.B) {
m := map[int]bool{}
for i := 0; i < b.N; i++ {
m[i] = true
}
}
@C-Pro
C-Pro / zeroisnull.go
Created January 12, 2023 06:17
Custom sql valuer that insert null to database if zero value is passed to it.
// https://go.dev/play/p/gTzl_yht11I
package main
import (
"database/sql/driver"
"fmt"
)
type valuer[T comparable] struct {
@C-Pro
C-Pro / null_uint.go
Created January 11, 2023 06:19
Missing NullUint64 implementation (for pgx driver)
package main
import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"strconv"
"time"
@C-Pro
C-Pro / fires_twice.sql
Created September 23, 2016 04:45
PostgreSQL trigger fires twice on UPSERT
--Before update or insert trigger
--fires twice when INSERT .. ON CONFLICT(uk) DO UPDATE operation
--fails to insert and does the update part.
--First it will be called with TG_OP='INSERT'
--and then with TG_OP='UPDATE'
create table t1 (x int);
create unique index t1_ui on t1(x);
create table t1_log(x int, op varchar(100), ts timestamp default clock_timestamp());
package main_test
import (
"testing"
)
func cmp(a, b string) bool {
if len(a) != len(b) {
return false
}
@C-Pro
C-Pro / my-talks.md
Last active June 7, 2020 12:33
Видео моих выступлений на конференциях

Видео моих выступлений на конференциях

ExcelJS

The task is to make an Excel-like table with support for the simplest formulas. Recalculation of values in the cells should occur immediately upon loss of focus and affect only those cells whose values should be changed. Do not recalculate the whole table every time (if not necessary). Use pure JS (ES6), HTML, CSS. Use third-party frameworks, libraries is not encouraged for this task. Task result will be viewed with the latest version of chrome (desktop and mobile).

Let the table size be 100x1000 (WxH)

Your task is to build one page web application. It will allow user to see length (in days) of continuous periods of sunshine in a given city:

  • Historical longest period of sunny days in given city
  • Longest period in current month
  • Length of current period of sunshine

Length of sunny days period is a number of consecutive days in a given city when the sun is shining (no overcast clouds, no precipitation).

User can select city from dropdown list and frontend should request for data from backend without reloading the page (e.g. REST or smth. similar). Request should be processed in less then 30ms (our service will be very popular!).

@C-Pro
C-Pro / concatbench_test.go
Created April 9, 2020 00:48
Benchmark for four types of string concatenation
package concatbench
import (
"fmt"
"strings"
"testing"
)
const (
s1 = "четёре чёрненьких чумазеньких чертёнка, "