Skip to content

Instantly share code, notes, and snippets.

View daniilyar's full-sized avatar
💭
Build systems for people, not only for money

Daniil Yaroslavtsev daniilyar

💭
Build systems for people, not only for money
View GitHub Profile
@daniilyar
daniilyar / gist:cf07a850939970ddde74
Created November 30, 2014 16:39
Example code of how NOT to use redundant Map whenr generating ast tree JSON
public static String toJson(DetailAST ast) throws IOException {
int nodeId = ROOT_NODE_ID;
Stack<Integer> parentNodeIdStack = new Stack<>();
parentNodeIdStack.push(nodeId); // root node id
DetailAST currentNode = ast;
StringWriter writer = new StringWriter();
JsonGenerator jsonGenerator = JSON_FACTORY.createJsonGenerator(writer).useDefaultPrettyPrinter();
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
@daniilyar
daniilyar / gist:4b13c68f19d902625abe
Created September 5, 2014 21:51
supe avg_prices query
WITH dates AS (
select distinct FS_PERM_SEC_ID,
sieve2.utils_pkg.sv_businessday(sysdate-1) D0,
sieve2.utils_pkg.add_businessdays(sysdate, -5) D7,
sieve2.utils_pkg.sv_businessday(add_months(sysdate, -1)) M1,
sieve2.utils_pkg.sv_businessday(add_months(sysdate, -3)) M3,
sieve2.utils_pkg.sv_businessday(add_months(sysdate, -12)) Y1
from THEMES.SECURITIES_MAPPING_TEMP mapping
)
select dates.fs_perm_sec_id,
select FS_PERM_SEC_ID, period, avg(p_price) avg_price from (
select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'DAY' period
from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and
SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -1) and sysdate
union all
select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'WEEK' period
from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and
SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -7) and sysdate
union all
select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'MONTH' period
select FS_PERM_SEC_ID, avg(p_price) avg_price, 'DAY' period
from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES'
and SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -1) and sysdate
group by FS_PERM_SEC_ID
UNION ALL
select FS_PERM_SEC_ID, avg(p_price) avg_price, 'WEEK' period
from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES'
and SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -7) and sysdate
group by FS_PERM_SEC_ID
UNION ALL
@daniilyar
daniilyar / Get disk space is used by schema or table in Oracle DB
Created April 30, 2014 06:32
Gets the real disk space amount is used by schema or table in Oracle DB
--select sum(Megabytes) from (
SELECT
owner, table_name, TRUNC(sum(bytes)/1024/1024) Megabytes
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type = 'TABLE'
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s