Skip to content

Instantly share code, notes, and snippets.

View zelark's full-sized avatar

Aleksandr Zhuravlёv zelark

View GitHub Profile
@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
@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';
-- 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 / 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');
@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
[
{
"name": "Top Level",
"parent": "null",
"children": [
{
"name": "Level 2: A",
"parent": "Top Level",
"children": [
{
@zelark
zelark / in-oracle
Last active August 29, 2015 14:14
ORA-00957: duplicate column name
SQL> create table test_ins (x number(1));
Table created.
SQL> insert into test_ins (x, x) values (1, 2);
insert into test_ins (x, x) values (1, 2)
*
ERROR at line 1:
ORA-00957: duplicate column name
SQL> select * from nc_objects2;
OBJECT_ID PARENT_ID
---------- ----------
0
2 1
1
3 2
SQL> select
@zelark
zelark / mount-tmp.sh
Last active August 29, 2015 14:13 — forked from Roman2K/mount-tmp.sh
#!/usr/bin/env bash
size=1024 # MB
mount_point=$HOME/tmp
name=$(basename "$mount_point")
usage() {
echo "usage: $(basename "$0") [mount | umount | remount | check | orphan]" \
"(default: mount)" >&2
}
@zelark
zelark / _oracle-snippets.txt
Last active August 29, 2015 14:08
Oracle snippets, patterns and other stuff.
Oracle snippets, patterns and other stuff.