Skip to content

Instantly share code, notes, and snippets.

View sitano's full-sized avatar

Ivan Prisyazhnyy sitano

View GitHub Profile
@sitano
sitano / for_keys_go_issue2.go
Created March 15, 2018 21:55
env GOSSAFUNC=keys go build for_keys_go_issue2.go
package main
import "fmt"
type S struct {
b [8]byte
}
func keys(m map[S]struct{}) [][]byte {
var z [][]byte
package main
import "fmt"
type S struct {
b [8]byte
}
func main() {
mmap := map[S]struct{}{
@sitano
sitano / overthewire_wargames_behemoth.md
Created March 13, 2018 13:49
overthewire_wargames_behemoth

Level 0

ssh [email protected] -p 2221

password: eatmyshorts flag: aesebootiv hint: password is protected by the xor func memfrob from <string.h>

> memfrob - frobnicate (encrypt) a memory area

@sitano
sitano / realloc.c
Last active November 5, 2017 13:55
undefined behavior with realloc
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int* p = (int *)malloc(sizeof(int));
int* q = (int *)realloc(p, sizeof(int));
*p = 1;
*q = 2;
if (p == q)
@sitano
sitano / brackets_split.go
Created October 19, 2017 07:47
parallel brackets sequence verification
package main
import "fmt"
type res struct {
s []byte
l int
r int
}
@sitano
sitano / rds-pgsql-replica-lag.md
Last active November 16, 2022 16:46
how to measure amazon rds postgresql replica lag

What to do when replica creation fails stopping streaming, trying to recover WAL from the archive

Calculate XLOG entries distance between master and replica with:

on master:

> select pg_xlogfile_name(pg_current_xlog_flush_location()), pg_current_xlog_insert_location(), pg_current_xlog_location();

on slave:

@sitano
sitano / read-only.sql
Created June 8, 2017 15:33
PostgreSQL create read only user
-- Create a group
CREATE ROLE readonly WITH LOGIN;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
@sitano
sitano / xms-http-test.go
Created January 16, 2017 22:25
Test web server written in go
package main
import (
"flag"
"log"
"math/rand"
"net/http"
"time"
)
@sitano
sitano / 500ms-fetcher.go
Last active January 18, 2017 22:35
Parallel fetcher with time limit constraints example, go
// Ivan Prisyazhnyy <[email protected]>, 2017
//
// Ambiguities:
// - "URL syntax correctness" is not explicitly defined. Should, I
// interpret it, like it has to match rfc1738/rfc3986? I will go
// with the simplest solution - URL is valid if parsed by util.URL.
// - Various behaviors for edge cases (i.e. meeting bad data, unstable
// network, too much data) are not well defined. If external service
// returns 4/5xx code, it could be retried and etc.
// - Answering always within 500 milliseconds - this is the biggest
@sitano
sitano / nginx.upstreams.lua
Last active March 20, 2017 04:53
openresty check upstreams status example
location = /status {
default_type text/plain;
content_by_lua '
local ok, upstream = pcall(require, "ngx.upstream")
if not ok then
error("ngx_upstream_lua module required")
end
local get_primary_peers = upstream.get_primary_peers