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
from flask import Flask, request | |
app = Flask(__name__) | |
def find_sbm(seq): | |
return scan(seq, set(), False) | |
def scan(seq, known_range, is_up_trend): | |
if not seq or len(seq) < 2: |
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
// Extension method | |
"HAL".increment | |
// Utilities class | |
StringUtilities.increment("HAL") |
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
object MyExtensions { | |
implicit def richInt(i: Int) = new { | |
def square: Int = i * i | |
} | |
} | |
object UsingExtension { | |
import MyExtensions._ | |
def run(): Int = { | |
val x: Int = 5 |
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
object DataFrameTools { | |
implicit class RichDataFrame(df: DataFrame) { | |
def saltedJoin(buildDf: DataFrame, joinExpression: Column, joinType: String, salt: Int): DataFrame = { | |
import org.apache.spark.sql.functions._ | |
val tmpDf = buildDf.withColumn("slt_range", array(Range(0, salt).toList.map(lit): _*)) | |
val tableDf = tmpDf.withColumn("slt_ratio_s", explode(tmpDf("slt_range"))).drop("slt_range") | |
val streamDf = df.withColumn("slt_ratio", monotonically_increasing_id % salt) | |
val saltedExpr = streamDf("slt_ratio") === tableDf("slt_ratio_s") && joinExpression | |
streamDf.join(tableDf, saltedExpr, joinType).drop("slt_ratio_s").drop("slt_ratio") |
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 get_lead_time(jira: JIRA, project: str, dt: str): | |
query = 'project={} and created > {} and status=Done and type=Story' | |
issues = [jira.issue(x) for x in jira.search_issues(query.format(project, dt))] | |
return [[x.key, x.fields.summary, 'Story', x.fields.created, x.fields.updated] for x in issues] |
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 create_jira_client(user, token, instance_name): | |
options = {'server': 'https://{}.atlassian.net'.format(instance_name)} | |
return JIRA(options, basic_auth=(user, token)) |
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 get_incidents(jira: JIRA, project: str, dt: str): | |
query = 'project={} and created > {} and type=Bug' | |
issues = [jira.issue(x) for x in jira.search_issues(query.format(project, dt))] | |
return [[x.key, x.fields.summary, 'Bug', x.fields.created, x.fields.updated] for x in issues] |
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
from github import Github, Organization, NamedUser | |
def create_github(url, token): | |
return Github(base_url="https://{}/api/v3".format(url), login_or_token=token) | |
def get_org(g: Github, org_name: str): | |
return [x for x in g.get_user().get_orgs() if x.name == org_name][0] |
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 is_prod_bump(p: PullRequest.PullRequest): | |
files = [x for x in p.get_files() if 'tags-info.json' in x.filename] | |
return len(files) > 0 | |
def get_changes(p: PullRequest.PullRequest): | |
from functools import reduce | |
res = [[x.additions, x.changes, x.deletions] for x in p.get_files()] | |
return reduce(lambda x,y: [x[0] + y[0], x[1] + y[1], x[2] + y[2]],res) |
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 create_db_client(host, user, password, db): | |
import psycopg2 | |
return psycopg2.connect(host=host, user=user, password=password, dbname=db) | |
def insert_to_db(conn, table, values: list): | |
v = ['({}),'.format(y for y in x) for x in values] | |
sql = 'insert into {} values {}'.format(table, v) | |
cur = conn.cursor() | |
cur.execute(sql) |
OlderNewer