Skip to content

Instantly share code, notes, and snippets.

Avatar

David Dikman ddikman

View GitHub Profile
@ddikman
ddikman / hiragana.js
Created Mar 17, 2022
Generate all hiragana
View hiragana.js
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 Feb 12, 2022
Firebase function to list provider logins past month
View provider.ts
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 Feb 1, 2022
Group engagement time
View engagement_time.sql
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 Jan 18, 2022
NodeJS在庫連携例
View item_integration.js
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 Jan 18, 2022
在庫連携するためのRuby例
View item_integration.rb
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 Dec 20, 2021
Example gist
View gist.js
// This is my example gist
console.log(`it will even syntax highlight for ${user}`);
@ddikman
ddikman / app_opens_past_six_weeks.sql
Created Dec 20, 2021
Gets the app opens for the app over the past few weeks
View app_opens_past_six_weeks.sql
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 Dec 16, 2021
Monthly total user retention numbers in BigQuery with google analytics
View retention.sql
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'
View segment-users.sql
SELECT
case user.value.string_value
when '0' then 'Baseline'
when '1' then 'Other version'
else 'Error'
end as experiment_value,
count(distinct(user_pseudo_id)) as users,
count(*) as events,
(count(*) / count(distinct(user_pseudo_id))) as ratio
FROM `<project_name>.analytics_<id>.events_*`,
@ddikman
ddikman / main.dart
Last active Oct 19, 2021
Example of floating loader overlay
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(ExampleApp());
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Floating overlay example',
debugShowCheckedModeBanner: false,