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
cat summary.json | \ | |
jq -r '.weeklyTotalCount[] | to_entries | .[] | select(.value > 0)' | \ | |
jq -s 'group_by(.key) | map({week : .[0].key, count : [.[].value] | add })' |
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
vector<int> inorderTraversal(TreeNode* root) { | |
unordered_map<TreeNode*, int> count; | |
stack<TreeNode*> stk; | |
vector<int> traversal; | |
stk.push(root); | |
while(!stk.empty()) { | |
TreeNode* cur = stk.top(); |
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
// A simple thread-safe queue implementation based on std::list<>::splice | |
// after a tip in a talk by Sean Parent of Adobe. | |
// | |
// Uses standard library threading and synchronization primitives together | |
// with a std::list<> container for implementing a thread-safe queue. The | |
// only special thing is that the queue uses std::list<>::splice in the | |
// locked region to minimize locked time. | |
// | |
// Also implements a maximal size and can thus be used as a buffer between | |
// the elements in a pipeline with limited buffer bloat. |
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 java.util.ArrayList; | |
import java.util.List; | |
public class FlattenArray { | |
static List<Integer> flatten(Object[] input) { | |
if (input == null) return null; | |
List<Integer> acc = new ArrayList<>(); | |
for (Object el : input) { |
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 itertools import combinations | |
from collections import deque | |
def is_nbr(s1, s2): | |
if len(s1) != len(s2): | |
return False | |
dist = (int(a != b) for a,b in zip(s1, s2)) |
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
class DisjointSet: | |
def __init__(self, n): | |
self.parent = list(range(n)) | |
self.rank = [0] * n | |
def union(self, x, y): | |
x = self.find(x) | |
y = self.find(y) |
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
/* | |
Inner_Collapsingkey - Outer_GroupingKey = Implicit_ObservationKey | |
collapsingKey == primaryKey(default) | |
what is the average daily amount of items sold for each employee ? | |
Inner_Collapsingkey = (day, employee) => what we want to define as an observation for this analysis | |
Outer_GroupingKey = employee => key defining the required groups to report |
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 fileinput | |
import copy | |
import logging | |
import time | |
from queue import Queue | |
from threading import Thread | |
format = "%(asctime)s.%(msecs)03d %(threadName)s %(levelname)s: %(message)s" |
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 math import isqrt | |
def primes_less_than(n: int) -> list[int]: | |
if n<= 2: | |
return [] | |
is_prime = [True] * n | |
is_prime[0] = False | |
is_prime[1] = False | |
for i in range(2, isqrt(n)+1): |
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 count(node, target): | |
""" counts occurrences of target in node's hierarchy""" | |
if node == target: | |
return 1 | |
if isinstance(node, list): | |
return sum(count(el, target) for el in node) | |
if isinstance(node, dict): |