Skip to content

Instantly share code, notes, and snippets.

View RatulSaha's full-sized avatar

Ratul Saha RatulSaha

View GitHub Profile
{
"ModelName": "Example from Alex Debrie (re:Invent 2019)",
"ModelMetadata": {
"Author": "Ratul Saha",
"DateCreated": "Dec 09, 2019, 9:29 PM",
"DateLastModified": "Dec 10, 2019, 12:36 AM",
"Description": ""
},
"DataModel": [
{
"TableFacets": [
{
"FacetName": "GetUserProfile (A1)",
"KeyAttributeAlias": {
"PartitionKeyAlias": "UserId",
"SortKeyAlias": "ProfileId"
},
"NonKeyAttributes": [
"Username",
"Full name",
WITH query1 AS (
SELECT
'china' AS country_code,
origin,
ROUND(SUM(IF(fcp.start <=1000, fcp.density,0)) / SUM(fcp.density),5) AS SEB_native
FROM
`chrome-ux-report.country_cn.201712`,
UNNEST(first_contentful_paint.histogram.bin) AS fcp
WHERE
origin = 'https://www.amazon.cn'
@RatulSaha
RatulSaha / 3G-fraction-1s-example.sql
Last active April 27, 2019 17:43
Chrome User Experience Report Analyzed with Google BigQuery
SELECT
SUM(fcp.density)
FROM
`chrome-ux-report.chrome_ux_report.201710`,
UNNEST(first_contentful_paint.histogram.bin) AS fcp
WHERE
origin = "https://www.google.co.in"
AND effective_connection_type.name = "3G"
AND fcp.END <= 1000
@RatulSaha
RatulSaha / basic-ds.py
Created January 2, 2017 20:58
Basic Data Structures in Python
class TreeNode(Object):
def __init__(self,x):
self.val = x
self.left = None
self.right = None
class ListNode(Object):
def __init__(self,x):
self.val = x
self.next = None
@RatulSaha
RatulSaha / binary-search.py
Created January 2, 2017 20:45
Binary search in Python
arr, target = [1,2,3,4,5], 4
start, end = 0, len(n)-1
while start <= end:
mid = (start+end)/2
if arr[mid] == target:
return mid # The value is found
else:
if arr[mid] < target:
start = mid+1
else:
@RatulSaha
RatulSaha / Loop.py
Created January 2, 2017 17:11
Useful Loop tricks in Python
counter = 0
while counter <= 5:
print counter,
counter += 1
else:
print "loop exited normally"
# Output: 0 1 2 3 4 5 loop exited normally
for i in range(5):
print i,
@RatulSaha
RatulSaha / list.py
Last active February 9, 2024 08:47
Useful List tricks in Python
#List traversal
range(start, stop, hop)
range(n) # [0,1,...,n-1]
range(1,n) # [1,...,n-1]
range(1,n,2) # [1,3,5,...,n-1] if n is even, or [1,3,5,...,n-2] if n is odd
range(n,-1,-1) # [n,n-1,n-2,...,0]
range(len(arr)) # Provides indices of an array arr
range(len(arr)-1,-1,-1) # Provides indices of arr backwards
# List slicing