Skip to content

Instantly share code, notes, and snippets.

View gtors's full-sized avatar

Andrey Torsunov gtors

  • Russian Federation, Kazan
View GitHub Profile
@gtors
gtors / underscore_to_camel_case
Created August 20, 2015 11:38
Postgresql function which converts json underscored keys to camel case keys.
CREATE FUNCTION key_underscore_to_camel_case(s text)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT to_json(substring(s, 1, 1) || substring(replace(initcap(replace(s, '_', ' ')), ' ', ''), 2));
$$;
-- TODO: add recursive processing
CREATE FUNCTION json_underscore_to_camel_case(data json)
@gtors
gtors / translator.py
Last active March 10, 2016 09:18
Simple console en-ru translator.
#!/usr/bin/env python
#----------------------------------------------------------------------
# Imports
#----------------------------------------------------------------------
import sys
import json
import requests
@gtors
gtors / gist:4f260096002a02febf7f
Last active August 14, 2019 11:34
Scrolls spells of autoconf
$ libtoolize --force
$ aclocal
$ autoheader
$ automake --force-missing --add-missing
$ autoconf
@gtors
gtors / !tips
Last active October 28, 2022 15:53
Tips
dummy
@gtors
gtors / e_comerce_glossary.txt
Last active April 14, 2016 14:23
E-comerce glossary
subtotal - предварительная сумма без вычета скидок, налогов и т.д.
total - сумма за вычетом скидок, налогов и т.д.
reward points - бонусные баллы.
discount amount - сумма скидки.
points with expiry - бонусы с ограниченным периодом действия.
redeem reward points - обмен бонусных баллов (например на скидку или товар).
reward - вознаграждение за что-то (например за покупку).
reward tiers - уровни вознаграждения (например уровень 1 дает 20% скидки, уровень 2 - 30%).
encashing points - обналичивание бонусных баллов.
@gtors
gtors / .vimrc
Last active April 21, 2016 15:16
vimrc
syn on
set number nowrap hls
colo desert
" Folding
set fen fdm=syntax
hi Folded ctermbg=0
" Show cursor line position
set cul so=9999
@gtors
gtors / SqlUtils.groovy
Created July 27, 2016 12:26
Utility class for extraction SQL statement from the Grails Detached Criteria (Hibernate)
import grails.gorm.DetachedCriteria
import grails.util.Holders
import org.codehaus.groovy.grails.orm.hibernate.query.HibernateQuery
import org.grails.datastore.gorm.finders.DynamicFinder
import org.hibernate.engine.spi.SessionFactoryImplementor
import org.hibernate.internal.CriteriaImpl
import org.hibernate.internal.SessionImpl
import org.hibernate.loader.criteria.CriteriaLoader
import org.hibernate.persister.entity.OuterJoinLoadable
@gtors
gtors / add_on_delete_cascade_to_all_fk.sql
Created October 19, 2016 21:38
Add ON DELETE CASCADE to all foreign keys in scheme
do $$
declare
rec record;
namespace_restriction text;
begin
namespace_restriction = 'public';
for rec in select
conrelid::oid::regclass::text as constraint_table,
conname as constraint_name,
pg_catalog.pg_get_constraintdef(oid) as constraint_definition
@gtors
gtors / rec_dep.sql
Created December 21, 2016 08:27
(PG) Recursive dependencies of a single database object
-- https://codereview.stackexchange.com/questions/23181/get-all-recursive-dependencies-of-a-single-database-object
WITH RECURSIVE dep_recursive AS (
-- Recursion: Initial Query
SELECT
0 AS "level",
'company' AS "dep_name", -- <- define dependent object HERE
'' AS "dep_table",
'' AS "dep_type",
'' AS "ref_name",
@gtors
gtors / clean.py
Last active October 27, 2017 09:31
Remover of multiline comments
#!/usr/bin/env python3
import re
import os
import sys
multiline_coment = re.compile(r'/\*\*.+?\*/\n?', flags=re.DOTALL)
extensions = tuple('.' + ext for ext in (
'java',
))