Skip to content

Instantly share code, notes, and snippets.

package main
//#include <unistd.h>
import "C"
import (
"context"
"log"
"math/rand"
"runtime"
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
)
@gruzovator
gruzovator / fields_filter.go
Created November 13, 2019 07:23
golang runtime struct fields filtering
package main
import (
"fmt"
"net/http"
"reflect"
"strings"
)
type Person struct {
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/go-redis/redis"
"log"
"reflect"
)
LOCATIONS = """
country
UK
city
London
Guildford
county
Surray
Sussex
Belgium
@gruzovator
gruzovator / translit.cpp
Created March 17, 2017 06:18
icu translit sketch
#include <unicode/translit.h>
class TranslitConverter
{
static const UnicodeString TRANSLITERATION_RULES;
public:
TranslitConverter()
{
UErrorCode status = U_ZERO_ERROR;
@gruzovator
gruzovator / schema-partitioning-2.sql
Created March 4, 2017 08:45
posrgresql partition by seq id
-- partition by month
-- https://www.postgresql.org/docs/9.5/static/ddl-partitioning.html
begin;
drop trigger if exists insert_master_trigger on master;
drop function if exists master_insert();
drop table if exists master cascade;
create table master(
id bigserial primary key,
@gruzovator
gruzovator / schema-partitioning-1.sql
Last active August 3, 2020 16:15
postgres partition by month exmaple
-- partition by month
-- https://www.postgresql.org/docs/9.5/static/ddl-partitioning.html
begin;
drop trigger if exists insert_master_trigger on master;
drop function if exists master_insert();
drop table if exists master cascade;
create table master(
id bigserial primary key,
@gruzovator
gruzovator / struct_meta.py
Last active December 28, 2016 07:56
structure metaclass
from types import NoneType
class Field(object):
def __init__(self, expected_types, *default):
self.name = None # set by metaclass
self.internal_name = None # set by metaclass
self.expected_types = expected_types
if default:
self.default = default[0]
@gruzovator
gruzovator / pagination_model.py
Last active December 17, 2016 10:27
pagination for periodically updated collection of sorted docs
# coding: utf-8
"""
Pagination model for sorted docs collection, that is periodically updated.
The key ideas:
- all docs have sequential id
- docs are sorted by composite key (weight, sequential id)
- response to page request containse 'next_offset' (a composite key) that should be used to get next page
"""