Skip to content

Instantly share code, notes, and snippets.

View qiuyujx's full-sized avatar

Christopher Tao qiuyujx

View GitHub Profile
import Foundation
func test(completion: (Int) -> ()) {
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
//let queue = dispatch_queue_create("serial queue", DISPATCH_QUEUE_SERIAL)
var counter = 0
let grp = dispatch_group_create()
@qiuyujx
qiuyujx / GAME_MASTER_v0_1.protobuf
Created July 18, 2016 04:34 — forked from anonymous/GAME_MASTER_v0_1.protobuf
Pokemon Go decoded GAME_MASTER protobuf file v0.1
Result: 1
Items {
TemplateId: "BADGE_BATTLE_ATTACK_WON"
Badge {
BadgeType: BADGE_BATTLE_ATTACK_WON
BadgeRanks: 4
Targets: "\nd\350\007"
}
}
Items {
@qiuyujx
qiuyujx / webpack.config.js
Created October 9, 2016 02:39 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
@qiuyujx
qiuyujx / __init__.py
Created November 28, 2019 21:57
Azure Function: HTTPTrigger Function with Snowflake Connector
import logging
import azure.functions as func
import snowflake.connector
def get_connection():
return snowflake.connector.connect(
user='<your_user>',
@qiuyujx
qiuyujx / py_f_parser.py
Created February 9, 2020 21:52
Python Formula Parser
import pandas as pd
import numpy as np
import re
import random
# Prepare testing dataset
tags = np.array(['tag'+str(i) for i in np.random.randint(10, size=200)]) # randomly generate tag list
vals = np.random.randint(20, size=200) # generate a list of random integers
raw_df = pd.DataFrame({
@qiuyujx
qiuyujx / pandas-data-missing-percentage.py
Last active September 27, 2020 11:38
Calculate Data Missing Percentage
def missing_pct(df):
# Calculate percentage of missing for each column
s_missing = df.isnull().sum() * 100 / df.shape[0]
# Convert the series back to data frame
df_missing = pd.DataFrame(s_missing).round(2)
# Reset and rename the index
df_missing = df_missing.reset_index().rename(
columns={
'index':'Column',
0:'Missing_Percentage (%)'
def find_max_in_group(df, group_col, val_col, tie_for_first=False):
# Decide ranking method
if tie_for_first:
rank_method = 'min'
else:
rank_method = 'first'
# Add rank number for each group
df["rank"] = df.groupby(group_col)[val_col].rank(method=rank_method, ascending=False)
# Only return rank == 1
return df[df['rank'] == 1].drop(['rank'], axis=1)
def expand_collection_type_column(df, target_col, col_names=None):
# Expand the list into multiple columns
df_expand = df[target_col].apply(pd.Series)
# Concatenate the expanded data frame with the original one
df = pd.concat([df, df_expand], axis=1).drop(['values'], axis=1)
# Rename columns if passed in
if col_names:
df = df.rename(columns={index:name for index, name in enumerate(col_names)})
return df
# Original Function
f = (lambda x: x((lambda x: x(lambda x: x))(x)))(lambda x: x)
# Reduced confusion
f = (
lambda a: a(
(
lambda b: b(lambda c: c)
)(a)
)
def max_vote_recursive(states, days_left, index):
# Terminating conditions
if len(states) == 0 or index >= len(states) or days_left <= 0:
return 0
# If we have enough days, go to this state
votes_if_go = 0
if states[index]['days'] <= days_left:
votes_if_go = states[index]['votes'] + max_vote_recursive(states, days_left - states[index]['days'], index + 1)