This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* 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 | |
***/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictionaryUtility: | |
""" | |
Utility methods for dealing with dictionaries. | |
""" | |
@staticmethod | |
def to_object(item): | |
""" | |
Convert a dictionary to an object (recursive). | |
""" | |
def convert(item): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
NewerOlder