Skip to content

Instantly share code, notes, and snippets.

View vskrachkov's full-sized avatar

Viacheslav Krachkov vskrachkov

View GitHub Profile
select t.table_schema, t.table_name,
'TRUNCATE public.' || t.table_name || ' CASCADE;', 'insert into public.'
|| t.table_name || '(' || string_agg(c.column_name, ',') || ') select ' || string_agg(c.column_name, ',') || ' from '
|| 'main.' || substring(t.table_name from 6) || ';'
from information_schema.columns c
join information_schema.tables t on t.table_name = c.table_name and t.table_schema = 'public'
where t.table_schema in ('public') and t.table_type = 'BASE TABLE'
GROUP BY t.table_schema, t.table_name;
@vskrachkov
vskrachkov / sort.py
Created February 5, 2017 13:57
Examples of bible sort, selection sort, insertion sort and merging sort.
def bubble_sort(a_list):
"""Realizes a bubble sort algorithm.
Time complexity: O(n^2)
"""
for one_pass in range(len(a_list)-1):
for i in range(len(a_list)-1):
if a_list[i] > a_list[i+1]:
a_list[i], a_list[i+1] = a_list[i+1], a_list[i]
return a_list
@vskrachkov
vskrachkov / property_example.py
Created February 5, 2017 13:49
Usage of built-in class `property`
"""
class_property.py
=================
Shows how to use python's built-in class 'property' for implementation of
encapsulation by pythonic way.
Use 'python3 -i class_property' for testing Man class interfaces.
Instance of this class will be already initialized as 'man' variable.
@vskrachkov
vskrachkov / base_werkzeug_app.py
Created February 4, 2017 16:00
Basic example of Werkzeug application
"""
base_werkzeug_app.py
====================
Example of a simple app written using werkzeug library.
"""
import json
import psycopg2
from werkzeug.exceptions import HTTPException