This file contains 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 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() | |
This file contains 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
Result: 1 | |
Items { | |
TemplateId: "BADGE_BATTLE_ATTACK_WON" | |
Badge { | |
BadgeType: BADGE_BATTLE_ATTACK_WON | |
BadgeRanks: 4 | |
Targets: "\nd\350\007" | |
} | |
} | |
Items { |
This file contains 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
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" |
This file contains 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 logging | |
import azure.functions as func | |
import snowflake.connector | |
def get_connection(): | |
return snowflake.connector.connect( | |
user='<your_user>', |
This file contains 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 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({ |
This file contains 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 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 (%)' |
This file contains 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 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) |
This file contains 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 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 |
This file contains 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
# 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) | |
) |
This file contains 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 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) |
OlderNewer