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"
package main_test
import (
"testing"
)
func cmp(a, b string) bool {
if len(a) != len(b) {
return false
}

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)

@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 = "четёре чёрненьких чумазеньких чертёнка, "
@C-Pro
C-Pro / vlwave.py
Created August 28, 2019 07:50
after several typhoons Vladivostok streets are flooded https://www.youtube.com/watch?v=dkgPkHPQqYo
from curses import wrapper
from math import sin
from math import radians
import time
def wave(scr):
TEXT='VLADIVOSTOK'
scr.clear()
my, mx = scr.getmaxyx()

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!).