Skip to content

Instantly share code, notes, and snippets.

with fake_data as (
/* Generate 10 fake users and many audiences */
select
uniform(1, 10, random()) as user_id,
'a-' || substr(uuid_string(), 1, 5) as audience_id
from table(generator(rowcount => 500))
order by 1
),
// Handler function, invoked on every identify event
// Argument: event = event payload, settings = function settings, as of Jan 2020 it provides access to API Key value.
// Step 1. Invoke func on identify event
async function onIdentify(event, settings) {
event.traits = event.traits || {};
var email = event.traits.email; // Step 2. Pick up email from 'traits' obj of the incoming event
var user_id = event.userId; // Pick up userId from the incoming event
// Step 3. Make HTTP request to Profile API with the email from previous step
// You can use userId value instead of email as a lookup field. In this case, insert "user_id:${userId_variable_name}" in Profile API URL instead of "email:${email_variable_name}"
// Note '?' parameters. You can omit 'include' parameter to return all traits from the profile. 'Limit' parameter defines how many traits is returned in JSON.
@juhaelee
juhaelee / ex.js
Last active September 1, 2016 16:06
// ex 1:
render(){
return (
<Component children={(val) => <ChildComponent value={val} />} />
)
}
// ex 2:
render() {
return (
@juhaelee
juhaelee / react-typescript.md
Last active January 26, 2023 00:52
React + Typescript Cheatsheet

React + Typescript Cheatsheet

Setup

If you use atom... download & install the following packages:

What are Typescript type definition files? (*.d.ts)

import React from 'react';
import {
convertFromRaw,
EditorState,
} from 'draft-js';
import DraftJSPluginsEditor from 'draft-js-plugins-editor';
import createMentionPlugin from 'draft-js-mention-plugin';
import { fromJS } from 'immutable';
import forEach from 'lodash/forEach';

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@juhaelee
juhaelee / .conf
Created February 12, 2016 15:28
nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
location = /status {
return 200;
access_log off;
}
}
server {
@juhaelee
juhaelee / Makefile
Last active February 2, 2016 20:51
make
test:
cp ~/.npmrc .npmrc