Skip to content

Instantly share code, notes, and snippets.

View yangchenyun's full-sized avatar

Steven Yang yangchenyun

View GitHub Profile
# Interesting problems solved for Zolando case.
# Q: How to pass state in a DAG
# A: We got variables already. EventOperation could take a variable as well!
# Q: How to pass state between DAGs?
# A: Use event payload.
# Q: How to early terminate a running DAG?
# A: Using priority to terminate existing DAGs.
@yangchenyun
yangchenyun / solution.go
Last active March 12, 2019 19:43
order_tree.go
package solution
// Performance result:
// N = 30000, weighted 3x. ✔OK
// 1. 0.004 s OK
// 2. 0.004 s OK
// 3. 0.004 s OK
// 4. 0.004 s OK
// 5. 0.004 s OK

Determine Winning Poker Hand

Design a program to determine the winner of a poker game.

The order of a card would be described as "23456789TJQKA", the suit of a card would be described as "HSCD" (Heart, Spade, Club, Diamond). Each card would be presented by two characters, i.e. "9D", "KC" etc.

You would be given a list of hands as a text file, each line represents a

@yangchenyun
yangchenyun / compareGen.js
Last active October 28, 2017 01:02
Compare two generator strings
function compareGen(leader, runner, leadStr='') {
const runnerNxt = runner.next();
if (runnerNxt.done) {
if (leadStr !== '') {
return false; // NOTE: The runner loses
}
const leaderNxt = leader.next();
if (leaderNxt.done) {
@yangchenyun
yangchenyun / txhandler.java
Created July 17, 2017 07:33
assignment1 snippet
/**
* Handles each epoch by receiving an unordered array of proposed transactions, checking each
* transaction for correctness, returning a mutually valid array of accepted transactions, and
* updating the current UTXO pool as appropriate.
*/
public Transaction[] handleTxs(Transaction[] possibleTxs) {
// The side effect is to advance the state of the pool.
// Convert the unordered list into a graph, and perform topological sort
/** Mapping from hash to corresponding transaction. */
@yangchenyun
yangchenyun / 1.js
Last active December 15, 2016 23:06
firebase-handle-oauth
_handleOauth(e, detail) {
const systemErrorCodes = [
'auth/auth-domain-config-required',
'auth/operation-not-allowed',
'auth/operation-not-supported-in-this-environment',
'auth/timeout',
];
const userErrorCodes = [
'auth/account-exists-with-different-credential',
@yangchenyun
yangchenyun / index.js
Last active December 7, 2016 03:43
sw-benchmark.js
window.benchmark = function() {
const countSet = [
1, 10, 100, 1000
];
const cookie = "__utma=27069237.741610204.1414116129.1427060728.1427929525.10; __utmc=27069237; EXPERIMENTS_EXCLUSIVE_OPTIN=False; wide=1; llbcs=2;";
const msgSet = [
undefined,
(defun yangchenyun-org/post-init-org ()
;; Disable whitespace-mode highlighting
(message "post init org is executed")
(with-eval-after-load 'org
(progn
(defvar org-dir "~/Dropbox/.org")
(setq org-bullets-bullet-list '("■" "◆" "▲" "▶"))
(setq org-directory (expand-file-name org-dir)
org-agenda-files (list (concat org-dir "/plans.org")
(concat org-dir "/work.org")
@yangchenyun
yangchenyun / tty2gif.py
Last active May 3, 2016 23:22
tty2gif.py
#!/usr/bin/env python
"""Script to convert ttyrec file to gifs on OSX with Terminal.app."""
import argparse
import os
import sys
import struct
import glob
import time
import subprocess
@yangchenyun
yangchenyun / fetch_kindle.js
Last active February 19, 2023 10:10
Get back my books from Kindle
/*
* @fileoverview Program to free the content in kindle books as plain HTML.
*
* This is largely based on reverse engineering kindle cloud app
* (https://read.amazon.com) to read book data from webSQL.
*
* Access to kindle library is required to download this book.
*/
// The Kindle Compression Module copied from http://read.amazon.com application