Skip to content

Instantly share code, notes, and snippets.

View odinuv's full-sized avatar
🐺
Wolf

Ondrej Popelka odinuv

🐺
Wolf
View GitHub Profile
@odinuv
odinuv / code.sql
Last active November 2, 2016 10:49
gapfilling currency
-- Transformation code for Snowflake backend, assumes that the input table is named "cur"
-- Fills gaps in currency rates by the last known value
DROP TABLE IF EXISTS "curdates";
DROP TABLE IF EXISTS "outCur";
CREATE TABLE "curdates" AS (
SELECT "date",
TO_CHAR("date", 'YYYY-MM-DD') || (SELECT DISTINCT "fromCurrency" FROM "cur" LIMIT 1) || "currency" AS "id",
"currency"
@odinuv
odinuv / snowflake.sql
Created November 29, 2016 12:50
Snowflake LAST_VALUE window frame replacement
CREATE OR REPLACE TABLE "test" ("id" INTEGER, "text" VARCHAR);
INSERT INTO "test" ("id", "text") VALUES (1, 'first'), (2, 'second'), (3, NULL),
(4, NULL), (5, 'fifth'), (6, NULL), (7, NULL), (8, NULL), (9, 'ninth');
SELECT * FROM "test" ORDER BY "id";
SELECT "id",
COALESCE("text", FIRST_VALUE("leadText") OVER (PARTITION BY "grp" ORDER BY "id")) AS "text"
FROM
(
SELECT *, SUM(CASE WHEN "leadText" IS NOT NULL AND "text" IS NULL OR
@odinuv
odinuv / config.json
Last active April 27, 2017 13:15
This Generic Extractor (https://developers.keboola.com/extend/generic-extractor/) configuration for Collabim (http://www.collabim.cz/api) enables you to get your projects, associated keywords and their position for the current day (you need to incrementally write data to another table to keep the history, as the extractor will overwrite the data…
{
"parameters": {
"api": {
"baseUrl": "https://api.oncollabim.com/",
"pagination": {
"method": "pagenum"
}
},
"config": {
"debug": true,
{
"parameters": {
"api": {
"authentication": {
"type": "basic"
},
"baseUrl": "https://yourElastisearchHost.com",
"pagination": {
"method": "response.param",
"responseParam": "_scroll_id",
@odinuv
odinuv / config.json
Created April 27, 2017 13:34
This Generic Extractor (https://developers.keboola.com/extend/generic-extractor/) configuration for Toggl API (https://github.com/toggl/toggl_api_docs) allows you to extract Workspaces, Users, Projects, Tasks, and Time Entries.
{
"parameters": {
"api": {
"authentication": {
"type": "basic"
},
"baseUrl": "https://toggl.com/"
},
"config": {
"id": "toggl",
@odinuv
odinuv / bad-retry-code.php
Last active September 27, 2018 08:03
Testing the untestable: Bad retry code
<?php
$pdo = $this->connect();
$stmt = $pdo->prepare('SELECT …');
while (true) {
try {
$stmt->execute();
while ($row = $stmt->fetch()) {
write_row_to_csv($row);
}
break; //success
@odinuv
odinuv / basic-extraction.php
Created September 27, 2018 15:08
Testing the untestable: Basic extraction
<?php
$stmt = $pdo->prepare('SELECT …');
$stmt->execute();
while ($row = $stmt->fetch()) {
write_row_to_csv($row);
}
@odinuv
odinuv / fixed-retry-code.php
Created September 27, 2018 15:09
Testing the untestable: Fixed retry code
<?php
$pdo = $this->connect();
while (true) {
try {
$stmt = $pdo->prepare('SELECT …'); // <- must be inside the loop
$stmt->execute();
while ($row = $stmt->fetch()) {
write_row_to_csv($row);
}
@odinuv
odinuv / test-connection-retry.php
Created September 27, 2018 15:10
Testing the untestable: Testing connection retry
<?php
testConnectionRetry()
{
$rows = 1000000;
$credentials = $this->setupTestDatabaseConnetion();
$table = $this->createLargeTable($credentials, $rows);
$configFile = $this->createConfigFile($credentials, $table);
$extractor = new Extractor($configFile);
exec('cports /close * * * 3600');
@odinuv
odinuv / test-connection-retry-fixed.php
Created September 27, 2018 15:11
Testing the untestable: Testing connection retry fixed
<?php
testConnectionRetry()
{
$rows = 1000000;
$credentials = $this->setupTestDatabaseConnetion();
$table = $this->createLargeTable($credentials, $rows);
$configFile = $this->createConfigFile($credentials, $table);
$extractor = new Extractor($configFile);
exec('php killConnection.php 10 > /dev/null &');