Skip to content

Instantly share code, notes, and snippets.

View nakolkin's full-sized avatar
🏠
Working from home

Artem Nikolaienko nakolkin

🏠
Working from home
View GitHub Profile
SELECT audit.start_migration_log('$Id: //src/trunk/sql/migration/2014/Henri/NG-8837/proc/36_summary_v2_get_audience_delivery_details_report.sql#1 $');
--
-- Audience Delivery Details Report
-- ============================================================================
/*
CREATE TYPE summary_v2.audience_delivery_details_report_trackingv2_v5 AS (
-- key and rbatch will pull the label base on taxonomy_attribute_id
taxonomy_attribute_id bigint,
IF debug THEN PERFORM summary_v2.debug_loger(run_id, function_name, 'CREATE INDEX on TEMPORARY TABLE'); END IF;
CREATE INDEX tracking_campaign_details_raw_report_idx on tracking_campaign_details_raw_report_table (report_date, site_id, placement_id, creative_group_id, creative_id) ;
IF debug THEN PERFORM summary_v2.debug_loger(run_id, function_name, 'Join AK data with _3pas data'); END IF;
INSERT INTO tracking_campaign_details_raw_report_table_rez
SELECT
campaign_ids_in[j]::bigint,
COALESCE(ak.report_date, _3pas.report_date) AS report_date,
COALESCE(ak.site_id, _3pas.site_id::bigint) AS site_id,
SELECT DISTINCT tc.campaign_id, pc.iso_code AS currency
FROM summary_v2.campaign_placement_details_cost_daily_v2 AS daily
INNER JOIN ref_data.tracking_campaign AS tc ON (daily.campaign_id = tc.external_id::BIGINT)
INNER JOIN ref_data.provider AS pr ON (pr.id = tc.tracking_data_provider_id AND pr.tpasns_id = daily.third_party_adserver_id)
LEFT JOIN mdata.placement_currency AS pc ON (pc.tracking_data_provider_id = tc.tracking_data_provider_id AND pc.placement_id = daily.inventory_placement_id)
WHERE summary_v2.empty_to_null(tc.external_id) IS NOT NULL
AND (tc.external_id ~ E'^\\d+$')
AND pr.tpasns_id IS NOT NULL
AND tc.campaign_id IN (23005,23081,22160,22165,22375,22164,23493,22374,22159,22161,22442,22162,22163,25982,26163,26241,28802,27050,26667,27579,28862,26457,28223,26488,26247,26775,30957,33323,28706,27582,34218,41921,41677,33801,34219,40233,39640,33325,43113,41913,40230,40241,42443,47381,52873,47386,47218,48005
DROP FUNCTION IF EXISTS summary_v2.get_campaign_placement_currency(bigint, date, date);
CREATE OR REPLACE FUNCTION summary_v2.get_campaign_placement_currency(campaign_id bigint, date_from date, date_to date)
RETURNS TABLE (
currency VARCHAR
) AS
$BODY$
BEGIN
RETURN QUERY
SELECT array_to_string(array_agg( DISTINCT coalesce(pc.iso_code, 'NULL')), ',')::VARCHAR AS currency
@nakolkin
nakolkin / .sql
Created September 22, 2015 08:10
CREATE TABLE summary_v2.campaign_dashboard_daily_v2
(
report_date date NOT NULL,
third_party_adserver_id bigint NOT NULL,
campaign_id bigint NOT NULL,
impression_by_flavor summary_v2.impression[],
impressions_total bigint NOT NULL DEFAULT 0,
uu_impression_total bytea NOT NULL DEFAULT '\000'::bytea,
engagement_by_type summary_v2.engagement[],
engagement_by_flavor summary_v2.engagement[],
@nakolkin
nakolkin / introrx.md
Created September 24, 2015 21:14 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@nakolkin
nakolkin / index.html
Created November 23, 2015 12:00 — forked from anonymous/index.html
JS Bin Exercise Blank // source http://jsbin.com/mecububepi
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script>
<meta name="description" content="Exercise Blank">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
@nakolkin
nakolkin / browserify_for_webpack_users.markdown
Created January 20, 2016 20:14
browserify for webpack users

browserify for webpack users

There's been a strange explosion in misinformation about browserify recently, particularly in comparisons to webpack.

Generally speaking, most of this confusion stems from how webpack is more willing to pull features into its core to ease discoverability while browserify is more likely to push features out to userland instead.

I think that longer-term, separability has more benefits from a maintenance and

@nakolkin
nakolkin / rxDecorateDirective.js
Created February 2, 2016 15:30 — forked from sirbarrence/rxDecorateDirective.js
A function to decorate some stock AngularJS 1.x directives to accept RxJS Observables. Finished product of https://barrysimpson.net/posts/rx-directive-decorators and https://barrysimpson.net/posts/rx-directive-decorators-update1
'use strict';
function rxDecorateDirective($provide, directiveName) {
// Duck-typing function lifted from the rx.js source.
function isObservable(obj) {
return obj && typeof obj.subscribe === 'function';
}
$provide.decorator(directiveName + 'Directive', ['$delegate', 'rx', function($delegate, rx) {
var directiveConfig = $delegate[0];
@nakolkin
nakolkin / latency.txt
Created July 17, 2017 13:04 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD