From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one.
2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会.
She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going.
Hard work beats talent when talent fails to work hard.
Boeing snapped a six-quarter streak of losses thanks to higher revenue.
Jetliner deliveries rose sharply in recent months as travel demand returned and airlines reduced their losses.
Boeing executives are scheduled to discuss results on a 10:30 a.m. ET analyst call.
Boeingreported its first quarterly profit in almost two years on Wednesday, boosted by a surge in deliveries of commercial jetliners as airlines began recovering from a pandemic slump and sales rose in the company’s other divisions.
The plane manufacturer snapped six consecutive quarters of losses, swinging to a profit of $567 million for the second quarter from a net loss of $2.96 billion in the quarter a year ago as air travel was plunging early in the pandemic.
Boeing’s revenue rose 44% to nearly $17 billion from $11.8 billion a year earlier, beating analyst estimates of $16.54 billion.
Here’s how the company performed compared with analysts’ estimates complied by Refinitiv:
Adjusted EPS: 40 cents vs a per-share loss of 83 cents.
Revenue: $17 billion vs. $16.54 billion.
Boeing shares jumped nearly 5% morning trading after the company reported results.
“While we still have a ways to go before a full rebound, it is encouraging to see the commercial market improving, enabled by continued vaccine distribution and increasing travel demand, particularly in domestic markets,” CEO Dave Calhoun said in an employee memo Wednesday. “Going forward, we will closely monitor case rates, vaccine distribution, travel protocols and global trade as key indicators for recovery.”
Boeing said last year it would slash jobs to about 130,000 employees by the end of 2021, but Calhoun said Wednesday it will likely remain at the current headcount of roughly 140,000 people because of the increase in demand.
Sales and deliveries of Boeing’s long-troubled 737 Max picked up in recent months with big orders from customers like United Airlines and Southwest Airlines, a vote of confidence in the plane that had been grounded worldwide until November because of crashes in 2018 and 2019 that killed 346 people. Regulators lifted the ban after Boeing made changes to a flight-control system implicated in the crash.
Revenue in its commercial airplane unit rose nearly 270% from a year earlier to $6.02 billion in the second quarter. But the segment still reported negative margins of 7.8%.
While sales and deliveries of the Max have increased the commercial airplane division is hamstrung by its wide-body 787 Dreamliner. Boeing slashed its delivery forecast for those planes earlier this month and said it would pause handovers to airlines for the second time in less than a year after finding another manufacturing flaw on the planes.
Revenue also grew in Boeing’s global services unit as air traffic grew and demand for freighter conversions increased to cater to a boom in air cargo.
Defense revenue, which has buoyed Boeing during the pandemic-induced lull in commercial airplane demand, rose 4% to $6.88 billion.
Teva, shares which have lost more than 7% YTD, traded lower in reaction to the company posting Q1 revenue that missed Wall Street estimates and kept its FY forecast unchanged on April 28.
Teva Pharmaceutical Industries LtdTEVA 8.8%Q2 sales reached $3.9 billion, increasing 1% Y/Y or decreasing 2% in local currency terms, missing the consensus of $4.04 billion.
The decrease was mainly due to lower revenues in the North America segment, related primarily to Copaxone and Anda.
Revenues were also affected by changes in demand for certain products resulting from the impact of the COVID-19 pandemic.
Adjusted EPS of $0.59 came in line with expectations.
The adjusted gross margin improved to 53.3% from 52% a year ago. Adjusted operating income reached little above $1 billion, +6% Y/Y mainly due to higher profit in our Europe segment.
Adjusted EBITDA increased 5% to $1.2 billion.
Teva generated an operating cash flow of $218 million, with a free cash flow of $625 million.
Outlook: Teva lowered the FY21 revenue outlook to reflect the ongoing impact of COVID-19. It expects revenues of $16 billion - $16.4 billion vs. $16.4 - $16.8 billion prior, lower than the consensus of $16.5 billion.
It sees adjusted EPS of $2.50 - $2.70 vs. the consensus of $2.45.
It expects a $2.0 - $2.3 billion free cash flow and an adjusted EBITDA of $4.8 - $5.1 billion.
Price Action: TEVA shares are down 1.35% at $8.80 during the premarket session on the last check Wednesday
Since June 24, when Teva’s stock was at $10.42, it was on a constant decline. Today, after more than a month, it is currently at $8.8 in the pre-market. The company today published astonishing reports. Teva saved the United States $28.8 billion in 2020, $4.2 billion of which were direct savings to US patients. Teva brought $9.6 billion in savings in 2020 to healthcare systems across nine European countries, including the UK, Germany, and Spain.
Teva’s Economic Impact Report, an independent study by Matrix Global Advisors (MGA), showed how Teva, the leading provider of generic medicines, saved $43.1 billion across its major markets in 2020 alone.
Amid the COVID-19 pandemic, Teva’s manufacturing, distribution, and R&D sites remained open to supply quality, affordable medicines to nearly 200 million patients every day. In addition, the company’s economic activity supported nearly 250,000 work spots and added $52 billion to economic results across 15 countries.
TheTSX Indexhas had a strong run-up so far in 2021. Nonetheless, there is still attractive value in some Canadian energy stocks especially. The transition to renewables is perhaps taking longer than many would like or be willing to admit.
Yet, during the pandemic, many of Canada’s best energy businesses have strengthened their operations and lowered their cost structure. Likewise, capital allocation, debt reduction, and stable shareholder returns have become a prime focus.
As a result, I believe this industry still has legs to run. Canadian investors could do well to at least have some exposure to energy stocks (whether it be traditional or renewables) in their portfolio. Here are three of the best Canadian value stocks I would buy before August.
Suncor Energy: A top Canadian energy stock
While I don’t love traditional energy producers, I am willing to make a few exceptions today. Suncor Energy(TSX:SU)(NYSE:SU) is well-known for its oil sands operations in Alberta. However, that only represents about 10% of its total operations. In fact, 50% of its cash flows come from refining and retail operations. The remainder comes from processing, logistics/infrastructure, and offshore oil production.
Suncor stock has failed to appreciate at the same rate as its energy peers. Consequently, I believe it presents a pretty attractive entry point. At today’s oil prices, the company is gushing free cash flow.
Rather than spending excess cash flows on increasing production, Suncor has focused on cleaning up its balance sheet, buying back shares, optimizing current operations, and diversifying into renewables.
The company pays a nice 3% dividend right now, but it could grow this year. Combine solid dividends with a ton of excess free cash flow, and this Canadian stock could have a nice turnaround from here.
Enbridge: The highest dividend on the TSX
Enbridge (TSX:ENB)(NYSE:ENB) is another energy-related stock that just doesn’t seem to get the respect it deserves. It operates one of North America’s largest pipeline networks. It has diverse operations with over 40 different sources of cash flow. Many investors are concerned about the downside risks from issues related to its Line 5 dispute with Michigan. Yet, many don’t factor in any of the upside from the execution of its $17 billion capital plan.
This includes its Line 3 replacement project, which despite environmental protests, appears to be set for completion by the end of the year. That project alone could provide substantial upside in cash flows next year. While investors wait, they are compensated with a substantial 6.88% dividend. That will likely keep growing as it executes its diversifying capital plan.
AltaGas: A top Canadian value stock
Another utility-like Canadian energy stock is AltaGas(TSX:ALA). Over the past few years, this company has been working out a very strong turnaround for investors. It divested non-core assets, simplified its business structure, and has been working to quickly reduce debt. Today, it is better positioned than ever.
Over half its cash flows are derived from a very solid natural gas utility business in the U.S. This business earns a stable baseline of cash flows. It also has a plan to significantly grow its rate base over the next few years. That should support solid dividend growth going forward.
Likewise, its midstream and export operations across Canada are enjoying a very strong recovery in 2021. Growing natural gas production and rising demand in Asia could all help produce a banner year. This Canadian stock remains undervalued, despite having an equal or better growth profile to many peers.
Given that it pays an attractive and growing 3.8% dividend, this energy stock should provide solid total returns in 2021 and beyond.
Google File System (GFS or GoogleFS, not to be confused with the GFS Linux file system) is a proprietarydistributed file system developed by Google to provide efficient, reliable access to data using large clusters of commodity hardware. The last version of Google File System codenamed Colossus was released in 2010.[1][2]
GFS is enhanced for Google's core data storage and usage needs (primarily the search engine), which can generate enormous amounts of data that must be retained; Google File System grew out of an earlier Google effort, "BigFiles", developed by Larry Page and Sergey Brin in the early days of Google, while it was still located in Stanford. Files are divided into fixed-size chunks of 64 megabytes, similar to clusters or sectors in regular file systems, which are only extremely rarely overwritten, or shrunk; files are usually appended to or read. It is also designed and optimized to run on Google's computing clusters, dense nodes which consist of cheap "commodity" computers, which means precautions must be taken against the high failure rate of individual nodes and the subsequent data loss. Other design decisions select for high data throughputs, even when it comes at the cost of latency.
A GFS cluster consists of multiple nodes. These nodes are divided into two types: one Master node and multiple Chunkservers. Each file is divided into fixed-size chunks. Chunkservers store these chunks. Each chunk is assigned a globally unique 64-bit label by the master node at the time of creation, and logical mappinGFS is enhanced for Google's core data storage and usage needs (primarily the search engine), which can generate enormous amounts of data that must be retained; Google File System grew out of an earlier Google effort, "BigFiles", developed by Larry Page and Sergey Brin in the early days of Google, while it was still located in Stanford. Files are divided into fixed-size chunks of 64 megabytes, similar to clusters or sectors in regular file systems, which are only extremely rarely overwritten, or shrunk; files are usually appended to or read. It is also designed and optimized to run on Google's computing clusters, dense nodes which consist of cheap "commodity" computers, which means precautions must be taken against the high failure rate of individual nodes and the subsequent data loss. Other design decisions select for high data throughputs, even when it comes at the cost of latency.
A GFS cluster consists of multiple nodes. These nodes are divided into two types: one Master node and multiple Chunkservers. Each file is divided into fixed-size chunks. Chunkservers store these chunks. Each chunk is assigned a globally unique 64-bit label by the master node at the time of creation, and logical mappings of files to constituent chunks are maintained. Each chunk is replicated several times throughout the network. At default, it is replicated three times, but this is configurable.[3] Files which are in high demand may have a higher replication factor, while files for which the application client uses strict storage optimizations may be replicated less than three times - in order to cope with quick garbage cleaning policies.[3]
The Master server does not usually store the actual chunks, but rather all the metadata associated with the chunks, such as the tables mapping the 64-bit labels to chunk locations and the files they make up (mapping from files to chunks), the locations of the copies of the chunks, what processes are reading or writing to a particular chunk, or taking a "snapshot" of the chunk pursuant to replicate it (usually at the instigation of the Master server, when, due to node failures, the number of copies of a chunk has fallen beneath the set number). All this metadata is kept current by the Master server periodically receiving updates from each chunk server ("Heart-beat messages").
Permissions for modifications are handled by a system of time-limited, expiring "leases", where the Master server grants permission to a process for a finite period of time during which no other process will be granted permission by the Master server to modify the chunk. The modifying chunkserver, which is always the primary chunk holder, then propagates the changes to the chunkservers with the backup copies. The changes are not saved until all chunkservers acknowledge, thus guaranteeing the completion and atomicity of the operation.
Programs access the chunks by first querying the Master server for the locations of the desired chunks; if the chunks are not being operated on (i.e. no outstanding leases exist), the Master replies with the locations, and the program then contacts and receives the data from the chunkserver directly (similar to Kazaa and its supernodes).
Unlike most other file systems, GFS is not implemented in the kernel of an operating system, but is instead provided as a userspace library.[4]gs of files to constituent chunks are maintained. Each chunk is replicated several times throughout the network. At default, it is replicated three times, but this is configurable.[3] Files which are in high demand may have a higher replication factor, while files for which the application client uses strict storage optimizations may be replicated less than three times - in order to cope with quick garbage cleaning policies.[3]
The Master server does not usually store the actual chunks, but rather all the metadata associated with the chunks, such as the tables mapping the 64-bit labels to chunk locations and the files they make up (mapping from files to chunks), the locations of the copies of the chunks, what processes are reading or writing to a particular chunk, or taking a "snapshot" of the chunk pursuant to replicate it (usually at the instigation of the Master server, when, due to node failures, the number of copies of a chunk has fallen beneath the set number). All this metadata is kept current by the Master server periodically receiving updates from each chunk server ("Heart-beat messages").
Permissions for modifications are handled by a system of time-limited, expiring "leases", where the Master server grants permission to a process for a finite period of time during which no other process will be granted permission by the Master server to modify the chunk. The modifying chunkserver, which is always the primary chunk holder, then propagates the changes to the chunkservers with the backup copies. The changes are not saved until all chunkservers acknowledge, thus guaranteeing the completion and atomicity of the operation.
Programs access the chunks by first querying the Master server for the locations of the desired chunks; if the chunks are not being operated on (i.e. no outstanding leases exist), the Master replies with the locations, and the program then contacts and receives the data from the chunkserver directly (similar to Kazaa and its supernodes).
Unlike most other file systems, GFS is not implemented in thekernelof anoperating system, but is instead provided as auserspacelibrary.[4]
If you’ve never looked at it before Bigtable can seem a little unapproachable. In this tutorial we’ll get you past that and guide you through your first steps with Bigtable so you can start using this fully managed NoSQL database in your own projects.
Bigtable is designed for low latency data access, where scalability and reliability really matter. It’s actually the same technology behind the majority of Google products, including Gmail, Maps, YouTube; Each of which serves multi-billion users.
In this tutorial we’ll walk you through your first steps with Bigtable, how to use it and what you really need to know to get started including:
Understanding the different types of NoSQL databases
How to setup and interact with Bigtable
How big table structures and manages data
Common ways to query and access data
Best practices around schema design
The 4 Types of NoSql Databases
In the NoSql realm there are generally 4 types of databases. You’ve got your Column based, Document based, Key-Value based and Graph based databases.
Bigtable falls into the Wide-Column based family along with others like Cassandra, and Hbase. To understand Wide-Column it helps to look first at traditional Column based. When we say Column based Nosql, what does that actually mean? Well traditional Relational databases are row based, meaning they’re optimized for returning rows of data. Consider a User database for example, a relational database would organize first name, last name, and address all near each other.
If you wanted to access the state and zip of many users, the database would have to jump around to pull all the fields. A column based database on the other hand is optimized for accessing data by column instead of row. So in our Users database example it would store all the names together, all the states together, all the zip codes together and so on. This makes reads much more efficient. To scan all the states, the database can stay within the same area on disk.
A Wide-Column datastore looks similar however they often group the columns into Column Families, a set of columns that are typically used together. These Column Families are further optimized on disk to ensure fast access.
This will be good to keep in mind for later when we start designing our schemas. Alright, lets get on with it and get hands dirty
Interacting with Bigtable
For this walkthrough I’ll be using the Bigtable command line tool, called CBT. All the concepts you see here can also be done programmatically in your language of choice by just pulling the right SDK. We’re just using the CLI for simplicity here.
Accessing your instance with CBT
With the Bigtable instance created and the CLI installed, this is a good point to access your instance from the CLI to ensure you’ve got everything setup.
Alright, to get started lets just list our instances
cbt listinstances
You should see the instance you just created in the output
Instance Name Info — — — — — — — — — my-instance my-instance
And there’s the instance we created. Now if we try to list the tables with cbt ls we get an error
cbt ls
Error will read
Missing -instance
it’s telling us we need to specify the instance with a flag. We could do that, but it’s gonna get annoying adding that in every time so let’s write it to an rc file as a default
echo instance = my-instance >> ~/.cbtrc
Now when we run it, no errors, but no response either since we haven’t created any tables yet.
cbt ls
Data structures & schema basics
Tables
For this example we’ll be creating a product catalog that might be used by a typical retailer. So in this step we’ll create a table called `catalog`
cbt createtable catalog
Calling `ls` one more time
cbt ls
and we see our table
catalog
Column Family
Earlier I mentioned that Bigtable stores data related to columns. To help organize the data and limit what you’re pulling back, columns are grouped into what’s called column families. These column families group the fields that are typically accessed in the same request to ensure more efficient access.
In our catalog example we may have product description fields and pricing or inventory fields. A listing of products may use data from the descriptors but not need all the store level inventory.
Lets go ahead and create a column family for those product descriptors
cbt createfamily catalog descr
And now we’ve got our column family in the table. Running the ls command again
cbt ls catalog
displays
Family Name GC Policy — — — — — — — — — — - descr <never>
Rows, Columns & Cells
Just like with relational databases we have a concept of rows columns and cells. Each row is identified by a unique key you provide. Cells are at the intersection of a row id and column id To access a specific cell you need to identify the location including Row Key, Column Family, and Column Qualifier
In our case the rowID will be a unique product sku and we’ll add a title for it in the descriptors column family
The format will be
cbt set <table> <rowID> <colFamily>:<colQualifier>=<value>
cbt set catalog sku123 descr:title=”Vintage Clock”
You’ll see that the catalog contains 2 versions of the cell descr:title, our original one with “Vintage Clock” and the update with “Antique Clock” At first multiple rows might seem alarming but this can be really handy in your system designs and audits.
Garbage Collection
Given you may not want to store every version ever created, Bigtable offers the ability to trash cell versions with a feature called Garbage Collection. Earlier we listed the column families on our table and you may have noticed GC Policy set to never. Leaving this as is will collect every version of the cell ever created.
cbt ls catalogFamily Name GC Policy — — — — — — — — — — - descr <never>
You can set the garbage collection policy based on the Time of the cell, Number of cells or a combination of the two. For example you could keep a month’s worth of changes, the last 5 versions or maybe up to 5 versions and within the last month.
For our example lets only keep one version
cbt setgcpolicy catalog descr maxversions=1
Now review the column families
cbt ls catalog
Notice the new policy listed
Family Name GC Policy----------- ---------descr versions() > 1
But when we read the table with no flags it still returns 2 cells, why is that?
Garbage collection is a data storage technique, not for limiting querying results. In fact, it can take up to a week before data that is eligible for garbage collection is actually removed.
In practice you won’t be pulling back all revisions of a cell anyway. Instead you’ll be doing something like the following which pulls the latest cell entry
Bigtable has some fantastic lookup capabilities. To demonstrate them, lets first add some more data
cbt set catalog sku124 descr:title=”Vintage Record Player” cbt set catalog sku125 descr:title=”Antique Chair” cbt set catalog sku942 descr:title=”New Wireless Headphones” cbt set catalog svc024 descr:title=”Antique Repair Service”
Let’s see what we have now.
We’ve added 3 more skus some sequential and one in the 900s. We’ve also added the last entry as a service rather than a product.
cbt read
Retrieve Single Entry
Previously we’ve been calling `cbt read` which returns a set of rows. Calling it now will return all the records we have in the system. If you know which row you’re interested specifically you can access it directly with `lookup`
cbt lookup catalog sku123
Additionally you can get even more specific indicating the exact columns you want
cbt lookup catalog sku123 columns=descr:title
Reading All Rows
Now let’s look at the readrows command to understand some of the ways we can query the data.
We covered this previously but as a foundation calling `cbt read` with no additional qualifiers will return all the values
cbt read catalog
Clearly something we wouldn’t want in a normal system. Thankfully Bigtable provides a few ways to get only the data we’re interested in.
Start & End
First it’s important to understand that Bigtable stores all its rows in ascending order based on the row id. Many of the features and patterns in bigtable revolve around this core concept. To see it in practice, the simplest way is to use `start` and `end` on the read command. Here we’re saying we want to start reading at sku124 and return all the rest of the rows.
cbt read catalog start=sku124
Or, read all the rows up to but excluding sku942
cbt read catalog end=sku942
You can combine them of course to get more targeted
cbt read catalog start=sku124 end=sku942
The values don’t need to be exact either, you can provide portions of the IDs
cbt read catalog start=sku12 end=sku9
This works because it’s comparing the lexical value of sku12 against the row ids in the database. Since sku12 comes before sku123 it will include 123. Since sku9 comes before sku942, it will exclude 942
That’s pretty cool, but there’s more
Prefix
You can use the prefix flag to pull only a subset of rows. In our dataset we have entries starting with sku and svc. let’s pull them separately. First the product `sku` records
cbt read catalog prefix=sku
Now the service `svc` records
cbt read catalog prefix=svc
Regex
Of course if you want to get fancy you can use standard regex. Pull any row starting with `s` then 3 of any characters followed by `24`
cbt read catalog regex=s.{3}24
Count
Finally we have count. It’s pretty self explanatory, cont returns only X number of rows that you indicate. This comes in handy when dealing with time series data and other scenarios.
cbt read catalog count=3
Schema Design
Tall Narrow Tables
Now that you’ve worked with Bigtable it’s a good time to discuss the schema design. Typically with Bigtable data sets you’ll want to focus on tall narrow tables vs short wide tables.
Continuing with our retail theme, let’s assume we’re tracking shipments to our customers
If you were interested in tracking the location of the shipment over time you might be interested in some elements such as:
OrderID
Shipping Company
Vehicle ID
Region
GPS Location
Timestamp
A short wide table might have rows for each shipping company, then columns for each vehicle ID and vehicle location. This would result in fewer rows but more columns
Instead it’s better to store this data in tall narrow tables. For example you would have a row for each time a vehicle reports data. This would result in many rows and fewer columns.
Avoid Hot Spots
A common challenge while dealing with time series data is a concept called hotspotting. When there are a bunch of writes for row keys right next to each other (like with time series data) you can create hot spots in your clusters that slow things down. When a row key for a time series includes a timestamp, all of your writes will target a single node, fill that node, and then move onto the next node. Ideally the writes would spread across all the nodes evenly.
To combat this you’ll want to create row keys that are non-contiguous.
For our shipping data if we simply stored data with a row starting with `timestamp` all the records would be contiguous. Instead we use a tactic of field promotion to move the fields from columns into the actual row key. A better row key might be `vehicle_id_#timestamp`. Since many vehicles will be reporting in a short time span, prefacing with the unique vehicle id will help spread the data out over the cluster.
Row Keys optimized for queries
The common way to sort and filter data in Bigtable is through the row key so it’s important to consider your queries when designing row keys. With the shipping data you might be more concerned with querying on the shipping company and therefore would need to include `shipping_co` in your row key. `shipping_co#vehicle_id_#timestamp`
You could then query bus line `UPS` with the prefix query `cbt read catalog prefix=UPS`
Depending on the various queries you need, you might find many fields promoted to the row key. With our bus data you might see a row key with most of the fields such as `region#shipping_co#timestamp#vehicle_id`
Cleanup
OK that’s it for this session. Let’s delete our instance and clean things up.
So there you have it, a whirlwind tour of bigtable. I hope this gave you a little insight on how bigtable works and how you might use it in your next project. You can find more about it on cloud.google.com/bigtable