Skip to content

Instantly share code, notes, and snippets.

View adityawarmanfw's full-sized avatar

Fidocia Wima Adityawarman adityawarmanfw

View GitHub Profile
{
"header": {
"process_time": 0.018328845,
"messages": "Your request has been processed successfully"
},
"data": [
{
"fs_id": "13004",
"order_id": 43481289,
"is_cod_mitra": false,
[
{
"_ansible_facts_gathered": true,
"ansible_all_ipv4_addresses": [
"10.20.5.204"
],
"ansible_all_ipv6_addresses": [
"2a00:6020:41e1:fea0:a00:27ff:fee0:63ba",
"2a00:6020:41e1:fe85:5:f9db:2e3f:1e85",
"2a00:6020:41e1:fe85:a00:27ff:fee0:63ba",
@adityawarmanfw
adityawarmanfw / duckdb_generate_pivot_query.sql
Last active January 30, 2023 20:42
DuckDB SQL query to generate SQL query to pivot data from rows into columns.
WITH gen_series AS (
SELECT
i,
count(*) over () as rows
FROM generate_series(1,100000) tbl(i)
), gen_year AS (
SELECT
i,
CASE WHEN i <= rows * 0.25 THEN 2022
WHEN i <= rows * 0.5 THEN 2023
@adityawarmanfw
adityawarmanfw / duckdb__dim_date.sql
Last active July 4, 2024 17:22
Generate Date Dimension table in DuckDB
WITH generate_date AS (
SELECT CAST(RANGE AS DATE) AS date_key
FROM RANGE(DATE '2009-01-01', DATE '2013-12-31', INTERVAL 1 DAY)
)
SELECT date_key AS date_key,
DAYOFYEAR(date_key) AS day_of_year,
YEARWEEK(date_key) AS week_key,
WEEKOFYEAR(date_key) AS week_of_year,
DAYOFWEEK(date_key) AS day_of_week,
ISODOW(date_key) AS iso_day_of_week,
@adityawarmanfw
adityawarmanfw / GA4_flatten_table_keep_rests_of_params.sql
Last active August 17, 2023 05:03
GA4 and BigQuery, converting event_params as columns and keeping the rest of event_params as an array of structs.
SELECT event_timestamp,
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_title') AS page_title,
(ARRAY(SELECT AS STRUCT * FROM UNNEST(event_params) WHERE key NOT IN ('ga_session_id', 'page_title'))) AS rest_of_event_params
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_20210131`
WHERE event_name = 'page_view'
LIMIT 1
@adityawarmanfw
adityawarmanfw / pcsbuy.js
Last active August 2, 2022 22:08
PancakeSwap SwapExactETHForTokens
const ethers = require('ethers');
const prompt = require('prompt-sync')({sigint: true});
const addresses = {
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
router: "0x10ed43c718714eb63d5aa57b78b54704e256024e",
target: "0x8129686c77E63C22bE6a7F06F9C61f135BD0a0CF" // Change this to your address ELSE YOU GONNA SEND YOUR BEANS TO ME
}
const BNBAmount = ethers.utils.parseEther('0.1').toHexString();
SELECT COUNT(DISTINCT user_id) AS player
FROM (SELECT * EXCEPT (sec_breakdown),
(SELECT COUNT(DISTINCT x)
FROM UNNEST(sec_breakdown) x
WHERE x > 0
) AS sec_played
FROM session_sec_breakdown
)
WHERE sec_played = length
WITH start_stop AS (
SELECT title,
user_id,
play_session,
play_session_sequence,
GENERATE_ARRAY(start_event.start,
stop_event.stop
) AS second_breakdown
FROM start_event
JOIN stop_event
WITH session_sec_breakdown AS (
SELECT title,
user_id,
length,
play_session,
ARRAY_CONCAT_AGG(second_breakdown) AS sec_breakdown
FROM start_stop
GROUP BY 1,2,3,4
)
SELECT * FROM session_sec_breakdown
WITH start_stop AS (
SELECT title,
user_id,
play_session,
play_session_sequence,
GENERATE_ARRAY(start_event.start,
stop_event.stop
) AS second_breakdown
FROM start_event
JOIN stop_event