Skip to content

Instantly share code, notes, and snippets.

View zelark's full-sized avatar

Aleksandr Zhuravlёv zelark

View GitHub Profile
[
{
"name": "Top Level",
"parent": "null",
"children": [
{
"name": "Level 2: A",
"parent": "Top Level",
"children": [
{
@zelark
zelark / blocked_sessions.sql
Last active May 30, 2016 12:25
helpful postgres queries
select
blocked_locks.pid as blocked_pid,
blocked_activity.usename as blocked_user,
blocked_activity.datname as database,
blocking_locks.pid as blocking_pid,
blocking_activity.usename as blocking_user,
blocked_activity.query as blocked_statement,
blocking_activity.query as blocking_statement
from pg_catalog.pg_locks blocked_locks
join pg_catalog.pg_stat_activity blocked_activity
@zelark
zelark / error_22P02.sql
Last active August 29, 2015 14:19
ERROR: invalid input syntax for type numeric: ""
create table test
(
name character varying(20),
id character varying(20) not null
);
insert into test (name, id) values ('bar', '');
insert into test (name, id) values ('foo', '11');
insert into test (name, id) values ('foo', '22');
-- SQL comes from here
-- https://momjian.us/main/writings/pgsql/locking.pdf
-- cannot be a temporary view because other sessions must see it
create view lockview as
select
pid,
virtualtransaction as vxid,
locktype as lock_type,
mode as lock_mode,
@zelark
zelark / vk_activity.sql
Last active August 29, 2015 14:21
vk_activity: database
-- https://devcenter.heroku.com/articles/dynos
-- export DATABASE_URL=postgres://python:python@localhost:5432/python_db
-- alter timezone on a dyno
-- heroku config:add TZ=Europe/Moscow
-- alter timezone on a database
alter role uaclvvcazghplm set timezone = 'Europe/Moscow';
@zelark
zelark / vk-activity-rest.md
Last active August 29, 2015 14:22
Design vk-activity REST

Design

HTTP Method URI Action
GET http://[hostname]/activity/api/v1/users Retrive list of available users
GET http://[hostname]/activity/api/v1/users/[user_id] Retrive a user's activity for the current day
GET http://[hostname]/activity/api/v1/users/[user_id]?date=dd-mm-yyyy Retrive a user's activity for the specified day

Links

  1. http://vk-activity.herokuapp.com
create or replace function parsetid(tid) returns text as $$
select (regexp_matches($1::text, '\((\d+),\d+\)'::text))[1];
$$ language sql immutable strict;
create or replace function getgraph(idxname text) returns text as $$
declare
nblocks bigint;
blkno bigint;
i bigint;
t text;
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@zelark
zelark / minesweeper.py
Last active August 29, 2015 14:25
All you need to play with it is Python 3
from random import sample
class Cell:
BOMB = 'B'
FLAG = 'F'
def __init__(self):
self.status = 0
self.content = 0
@zelark
zelark / calc.py
Last active August 29, 2015 14:26
Let’s Build A Simple Interpreter
# Token types
# EOF (end-of-file) token is used to indicate that
# there is no more input left for lexical analysis
INTEGER, PLUS, MINUS, MUL, DIV, EOF = 'INTEGER', 'PLUS', 'MINUS', 'MUL', 'DIV', 'EOF'
class Token(object):
def __init__(self, type, value):
# token type: INTEGER, PLUS, MINUS, or EOF
self.type = type