Skip to content

Instantly share code, notes, and snippets.

@tucnak
tucnak / sparse_duration.sql
Created November 8, 2022 16:05
Sparse elapsed duration in a Timescale continuous aggregate
-- the custom aggregate state
CREATE TYPE elapsed__t AS (acc interval, cur timestamptz);
-- state transition function
CREATE FUNCTION elapsed__sf(s elapsed__t, x interval, cur timestamptz)
RETURNS elapsed__t IMMUTABLE LANGUAGE sql AS $$
SELECT
coalesce(s.acc, '0'::interval) + case
when cur-s.cur > x
then null
else cur-s.cur end,
@tucnak
tucnak / macvim+openai.vim
Last active August 26, 2022 17:13
MacVim + OpenAI GPT-3
let vimrc =<< trim END
set insertmode
inoremap <Esc> <C-o>
vnoremap <BS> d
nnoremap <silent> U :redo<CR>
nnoremap j gj
nnoremap gj j
nnoremap k gk
nnoremap gk k
@tucnak
tucnak / authorized_keys
Created July 21, 2022 06:12
ilya@hrest.org
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE3pgS+uqPqOBwTJqJjiT9fwEVGEEQXIKBzKaVfCH7XR
@tucnak
tucnak / StopWordle.user.js
Created February 23, 2022 13:27
StopWordle: Hide all mentions of Wordle from Hacker News feeds!
// ==UserScript==
// @name Stop Wordle!
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Hide all mentions of Wordle from Hacker News feeds!
// @author https://github.com/tucnak
// @match https://news.ycombinator.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com
// @grant none
// ==/UserScript==
@tucnak
tucnak / StopWordle.user.js
Last active February 24, 2022 11:38
Hide all mentions of Wordle from Hacker News feeds
// ==UserScript==
// @name Stop Wordle!
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Hide all mentions of Wordle from Hacker News feeds!
// @author https://github.com/tucnak
// @match https://news.ycombinator.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com
// @grant none
// ==/UserScript==
@tucnak
tucnak / .vimrc
Created January 21, 2022 20:49
Very simple config-less .vimrc
colorscheme default
syntax enable
packadd matchit
filetype plugin indent on
set autoindent
set backspace=indent,eol,start
set colorcolumn=0
set completeopt=longest,noinsert,menuone,noselect
set exrc
@tucnak
tucnak / migration.go
Created May 21, 2020 19:31
Automatic model migration for Postgres
func migrate(db *pg.DB, tables ...[]T) chan error {
errfeed := make(chan error)
go func() {
for _, model := range tables {
err := db.CreateTable(model, &orm.CreateTableOptions{IfNotExists: true})
if err != nil {
errfeed <- err
continue
}
CGO_CPPFLAGS="-I/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-project/llvm/include -I/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-build/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-build/tools/clang/include -I/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-project/clang/include -I/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-project/lld/include" CGO_CXXFLAGS="-std=c++11" CGO_LDFLAGS="/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-build/lib/libclang.a -std=c++11 -L/Users/badt/Dev/go/src/github.com/tinygo-org/tinygo/llvm-build/lib -lclangAnalysis -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSeria
@tucnak
tucnak / output.txt
Last active February 12, 2019 03:04
Schema takes too long to load trivial objects with depth=0 and doesn't load certain structs
2019/02/12 05:04:03 n = 10
2019/02/12 05:04:03
2019/02/12 05:04:03 [find n critiques] started
2019/02/12 05:04:04 found 10 crits
2019/02/12 05:04:04 elapsed: 11.835827ms
2019/02/12 05:04:04
2019/02/12 05:04:04 [get n actors + depth=0] started
2019/02/12 05:04:04 found 10 actors
listening...
- 1 2019-02-09 18:27:29.214357 +0200 EET
@tucnak
tucnak / signals.upd
Created November 16, 2015 22:55
Signal-slot concept in an imaginary Upd programming language
package stuff
import {
"fmt"
"github.com/tucnak/pipes" // пасхалка
}
class A {
slots: