Skip to content

Instantly share code, notes, and snippets.

View ddikman's full-sized avatar

David Dikman ddikman

View GitHub Profile
@ddikman
ddikman / filter_last_month.sql
Created August 1, 2022 02:31
Efficient filtering of tables in google analytics
SELECT
count(*)
FROM
`<your_project>.analytics_196169157.events_*`
WHERE
event_name = 'event_name'
AND _TABLE_SUFFIX >= format_date('%Y%m%d', CURRENT_DATE() - 30)
@ddikman
ddikman / filter-events-by-partition.sql
Created June 13, 2022 01:28
Filtering events in bigquery using partitions
SELECT
count(*) as events
FROM `<project-name>.analytics_<id>.events_*`
WHERE _TABLE_SUFFIX >= FORMAT_DATE('%Y%m%d', CURRENT_DATE() - 7)
@ddikman
ddikman / hiragana.js
Created March 17, 2022 09:08
Generate all hiragana
let hiragana = [...Array(0x3095 - 0x3041).keys()].map((i) => String.fromCharCode(0x3041 + i))
/*
Generates 84 hiragana based on
https://sites.psu.edu/symbolcodes/languages/asia/japanese/hiraganachart/
[
'ぁ', 'あ', 'ぃ', 'い', 'ぅ', 'う', 'ぇ', 'え',
'ぉ', 'お', 'か', 'が', 'き', 'ぎ', 'く', 'ぐ',
'け', 'げ', 'こ', 'ご', 'さ', 'ざ', 'し', 'じ',
'す', 'ず', 'せ', 'ぜ', 'そ', 'ぞ', 'た', 'だ',
@ddikman
ddikman / provider.ts
Created February 12, 2022 05:59
Firebase function to list provider logins past month
import * as functions from "firebase-functions"
import * as admin from "firebase-admin"
const getUsers = async (pageToken?: string) : Promise<admin.auth.UserRecord[]> => {
const result = await admin.auth().listUsers(1000, pageToken)
if (result.pageToken) {
return [...result.users, ...await getUsers(result.pageToken)]
}
return result.users
}
@ddikman
ddikman / engagement_time.sql
Created February 1, 2022 03:24
Group engagement time
SELECT
case
when engagement.minutes > 20 then '>20 min'
when engagement.minutes > 10 then '10-20 min'
when engagement.minutes > 5 then '5-10 min'
when engagement.minutes > 2 then '2-5 min'
else '<2 min'
end as segment,
count(*) as users
FROM (
@ddikman
ddikman / item_integration.js
Created January 18, 2022 07:45
NodeJS在庫連携例
const req = require('request');
const fs = require('fs');
req.post({
headers: {
'Content-Type': 'multipart/form-data',
'X-Api-Key': 'MY_KEY'
},
url: 'https://api.facy.jp/integration/inventory',
method: 'POST',
@ddikman
ddikman / item_integration.rb
Created January 18, 2022 06:46
在庫連携するためのRuby例
require 'net/http'
File.open("MY_CSV_FILE.csv") do |csv_file|
uri = URI.parse('https://api.facy.jp/integration/inventory')
req = Net::HTTP::Post.new(uri.path)
req["X-Api-Key"] = "MY_KEY"
req.set_form([["file", csv_file]], "multipart/form-data")
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
http.request(req)
@ddikman
ddikman / gist.js
Created December 20, 2021 12:53
Example gist
// This is my example gist
console.log(`it will even syntax highlight for ${user}`);
@ddikman
ddikman / app_opens_past_six_weeks.sql
Created December 20, 2021 12:32
Gets the app opens for the app over the past few weeks
SELECT
DATE(DATE_TRUNC(TIMESTAMP_MICROS(event_timestamp), WEEK)) as week,
COUNT(DISTINCT(user_pseudo_id)) as users
FROM `<project>.events_*`
WHERE event_name = 'app_open'
-- past six weeks
AND DATE(DATE_TRUNC(TIMESTAMP_MICROS(event_timestamp), WEEK)) > DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 6 WEEK)
GROUP BY week
ORDER BY week
@ddikman
ddikman / retention.sql
Created December 16, 2021 07:07
Monthly total user retention numbers in BigQuery with google analytics
SELECT
last as last_month,
DATETIME_DIFF(last, first, MONTH) as retained_months,
COUNT(*) as users
FROM (
SELECT
DATE(DATE_TRUNC(TIMESTAMP_MICROS(min(event_timestamp)), MONTH)) as first,
DATE(DATE_TRUNC(TIMESTAMP_MICROS(max(event_timestamp)), MONTH)) as last
FROM `<your-project>.events_*`
WHERE event_name = 'view_item'