Skip to content

Instantly share code, notes, and snippets.

View yukoga's full-sized avatar

yukoga yukoga

  • Japan
View GitHub Profile
@yukoga
yukoga / gist:4458f8cec0710d2e5790d0058a213231
Created March 5, 2025 10:27
session participation SQL example
DECLARE start_date STRING DEFAULT '20210101';
DECLARE end_date STRING DEFAULT '20210131';
DECLARE timezone STRING DEFAULT 'Asia/Tokyo';
DECLARE query_events ARRAY<STRING> DEFAULT ['page_view','purchase'];
CREATE OR REPLACE TABLE FUNCTION `YOUR_PROJECT.YOUR_DATASET.user_event_logs` (start_date STRING,end_date STRING,timezone STRING,query_events ARRAY<STRING>)
AS
SELECT
visitor_id,
@yukoga
yukoga / eventemitter.js
Created June 26, 2023 12:58 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
-- Author: Krisjan Oldekamp
-- https://stacktonic.com/article/enrich-a-single-customer-view-with-google-analytics-4-big-query-data
declare lookback_window int64 default 365; -- how many days to lookback into the ga4 dataset to calculate profiles
-- udf: channel grouping (you could put this in a permanent function)
-- also see https://stacktonic.com/article/google-analytics-4-and-big-query-create-custom-channel-groupings-in-a-reusable-sql-function
create temporary function channel_grouping(tsource string, medium string, campaign string) as (
case
when (tsource = '(direct)' or tsource is null)
@yukoga
yukoga / gist:d1c4b35e5c427cff66e639af20495218
Last active March 8, 2022 19:16
How to send email via MS Office 365 server
/***
* How to install Microsoft Graph SDK - https://docs.microsoft.com/en-us/graph/sdks/sdk-installation
* How to instantiate a graph client - https://docs.microsoft.com/en-us/graph/sdks/create-client?tabs=Java
* How to send email via Office 365
* Other references:
* - Stackoverflow which referers to that old MS API doesn't work with OAuth2 - https://stackoverflow.com/questions/63010629/office-365-xoauth2-for-imap-authentication-fails-from-standalone-java-code#63025203
* - Getting started with Microsoft Graph and Mail API - https://www.youtube.com/watch?v=L-gm25wusIQ
* - Microsoft training module for Graph SDK (in JP) - https://github.com/microsoftgraph/msgraph-training-java.ja-JP
***/
@yukoga
yukoga / GLM-hierarchical.ipynb
Created October 2, 2020 15:27 — forked from twiecki/GLM-hierarchical-jax.ipynb
notebooks/GLM-hierarchical.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yukoga
yukoga / real_time.ipynb
Created April 26, 2020 08:12 — forked from nikhilkumarsingh/real_time.ipynb
Plotting real time data using Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yukoga
yukoga / twitter-streaming-pubsub.py
Created April 26, 2020 08:01 — forked from kaxil/twitter-streaming-pubsub.py
Twitter Streaming API to PubSub
def publish(client, pubsub_topic, data_lines):
"""Publish to the given pubsub topic."""
messages = []
for line in data_lines:
messages.append({'data': line})
body = {'messages': messages}
str_body = json.dumps(body)
data = base64.urlsafe_b64encode(bytearray(str_body, 'utf8'))
client.publish(topic=pubsub_topic, data=data)
@yukoga
yukoga / pubsub-to-bokeh.py
Created April 26, 2020 08:01 — forked from kaxil/pubsub-to-bokeh.py
Google Cloud Pub/Sub to Bokeh Dashboard - Streaming Dashboard
# User module to receive tweets
from recevie_tweets_pubsub import receive_tweets
import pandas
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.models import DatetimeTickFormatter
from bokeh.plotting import figure, output_file
import sys
@yukoga
yukoga / python-convert-dictionary-to-object
Created October 23, 2019 10:46 — forked from typerandom/python-convert-dictionary-to-object
Convert a dictionary to an object (recursive).
class DictionaryUtility:
"""
Utility methods for dealing with dictionaries.
"""
@staticmethod
def to_object(item):
"""
Convert a dictionary to an object (recursive).
"""
def convert(item):
@yukoga
yukoga / demo.py
Created October 19, 2019 13:23 — forked from joelthchao/demo.py
Keras uses TensorBoard Callback with train_on_batch
import numpy as np
import tensorflow as tf
from keras.callbacks import TensorBoard
from keras.layers import Input, Dense
from keras.models import Model
def write_log(callback, names, logs, batch_no):
for name, value in zip(names, logs):
summary = tf.Summary()