因为你没有:
* 特定的算法,数据结构.
* 正确的思维方法 和 思维体系.
* 最优解
* 做题的感觉,代码从哪里开始
面试是考你如何运用算法和数据结构,不是考你创造发明算法。
这两天学到的。特别好。
看答案, 看答案.
第一遍:直接看答案.
有战友问: 看完答案以后呢?
A: 练习`解题`啊. 每道题练习 3~5次, 熟练到这个程度:`hard 题, 15分钟 AC提交`.
Q:第一遍看答案解题,看多少道呢?
A:Leetcode Top 500 道吧。
import psycopg2 # import PostgreSQL database interface library. | |
import traceback | |
import sys | |
# Add PYTHONPATH, then we may import all the objects below this folder. | |
sys.path.insert(0,"/Users/charliezhu/git/bi-cloud/etl") | |
# import tool to parse .ini configuration file. | |
# See below link for the explaination and examples: | |
# http://www.postgresqltutorial.com/postgresql-python/connect/ | |
# ConfigParser().read(), returns a 2 dimensional array, e.g.: [[a1,a2],[b1,b2], ...]. | |
from etl.pipeline_core.config import Config | |
class DbTool(object): | |
# initialize a local field(object property/attribute). Constructor. | |
# config = Config.load("/Users/abc/aws/database.ini") | |
def __init__(self, ini_file): # put config constructor/initializer here? | |
self.config = Config.load(ini_file) | |
# Build a dictionary object to connect to a database. | |
# {'user': 'scala_user', 'password': '', 'host': 'localhost', 'database': 'scala_db'} | |
def db_config(self, db_name): | |
db = {} | |
params = self.config.settings.items(db_name) | |
for param in params: | |
db[param[0]] = param[1] | |
print(db) | |
return db | |
def app_name_db_passwd(self): | |
return self.config.get('app_name_db','password') | |
def test_query(conn, app_name_db_passwd): | |
# Use loan pattern to open a cursor, it'll be automatically closed after exit the scope. | |
with conn.cursor() as cur: | |
cur.execute("""SELECT table_catalog, table_schema, table_name | |
FROM information_schema.tables LIMIT 4 | |
""") | |
rows = cur.fetchall() | |
print( "\nShow me the data:\n") | |
for row in rows: | |
print( "output: ", row[0], row[2]) | |
def main(): | |
try: | |
app_name_tool = DbTool("/Users/charliezhu/work/blastworks/aws/database.ini") | |
app_name_db = app_name_tool.db_config(db_name = 'local_db') | |
# Same loan pattern, but for database connection. | |
# **app_name_db, unpack dictionary to key value pairs arguments lists. | |
# see, https://docs.python.org/3.7/tutorial/controlflow.html#unpacking-argument-lists | |
with psycopg2.connect(**app_name_db) as conn: | |
test_query(conn, app_name_tool.app_name_db_passwd()) | |
except: | |
traceback.print_exc() | |
print("I am unable to connect to the database") | |
# if run as the single script, run main method. | |
if __name__ == '__main__': | |
main() |
import util.control.Breaks._
breakable {
for (i <- 1 to 10) {
println(i)
if (i > 4) break // break out of the for loop }
}
echo "
Slingo, iOS
Slingo, Android
" > game.csv
import org.apache.spark.sql.types._
val customSchema = StructType(Array(
StructField("game_id", StringType, true),
StructField("os_id", StringType, true)
))
val csv_df = spark.read.format("csv").schema(customSchema).load("game.csv")
csv_df.show
csv_df.orderBy(asc("game_id"), desc("os_id")).show
csv_df.createOrReplaceTempView("game_view")
val sort_df = sql("select * from game_view order by game_id, os_id desc")
sort_df.show
Reference,