This file contains hidden or 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
| #!/usr/bin/env python | |
| """ | |
| Copyright Google Inc. 2016 | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, |
This file contains hidden or 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
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # https://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
This file contains hidden or 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: [ | |
| { | |
| "num_trips": "28598.0", | |
| "rainy": false | |
| }, | |
| { | |
| "num_trips": "19503.0", | |
| "rainy": true | |
| } |
This file contains hidden or 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
| WITH streaming_data AS ( | |
| SELECT | |
| timestamp, | |
| TIMESTAMP_TRUNC(timestamp, HOUR, 'UTC') AS hour, | |
| TIMESTAMP_TRUNC(timestamp, MINUTE, 'UTC') AS minute, | |
| TIMESTAMP_TRUNC(timestamp, SECOND, 'UTC') AS second, | |
| ride_id, | |
| latitude, | |
| longitude, |
This file contains hidden or 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
| CREATE OR REPLACE MODEL `ecommerce.classification_model_2` | |
| OPTIONS | |
| (model_type = 'logistic_reg', labels = ['will_buy_on_return_visit']) AS | |
| WITH all_visitor_stats AS ( | |
| SELECT | |
| fullvisitorid, | |
| IF (COUNTIF(totals.transactions > 0 AND totals.newVisits IS NULL) > 0, 1, 0) AS will_buy_on_return_visit | |
| FROM `data-to-insights.ecommerce.web_analytics` | |
| GROUP BY fullvisitorid |
This file contains hidden or 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
| #!/usr/bin/env python | |
| """ | |
| Copyright Google Inc. 2016 | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software |
This file contains hidden or 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 argparse | |
| import random | |
| import string | |
| parser = argparse.ArgumentParser() | |
| DEFAULT_STR_LEN = 8 | |
| parser.add_argument( | |
| "-l", "--string-length", type=int, default=DEFAULT_STR_LEN, help=f"string length (default: {DEFAULT_STR_LEN})") | |
| parser.add_argument("-s", "--include-symbol", action="store_true", help="include symbol characters") | |
| args = parser.parse_args() |
This file contains hidden or 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 collections import deque | |
| def sort_for_heap_tree(arr): | |
| arr_len = len(arr) | |
| for parent_idx in range(arr_len): | |
| child1_idx = parent_idx * 2 + 1 | |
| if child1_idx >= arr_len: | |
| break | |
| child1 = arr[child1_idx] |
This file contains hidden or 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 collections import deque | |
| def sort_by_quick_sort(arr): | |
| if len(arr) == 1: | |
| return arr | |
| base_value = arr[0] | |
| smaller = deque([arr[0]]) | |
| larger = deque() | |
| cnt = 0 |
This file contains hidden or 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 sort_by_merge_sort(arr): | |
| if len(arr) == 1: | |
| return arr | |
| if len(arr) == 2: | |
| if arr[0] < arr[1]: | |
| return arr | |
| else: | |
| return [arr[1], arr[0]] |
NewerOlder