import {Observable} from ‘rxjs’; import {tap} from ‘rxjs/operators’; export enum RxJsLoggingLevel { TRACE, DEBUG, INFO, WARN, ERROR } let rxjsLoggingLevel = RxJsLoggingLevel.TRACE; export function setRxJsLoggingLevel(level: RxJsLoggingLevel) { rxjsLoggingLevel = level; } function a(level: number) { return (message: string) => (source: Observable) => source .pipe( tap(val => { if (level >= rxjsLoggingLevel) { console.log(message + ‘: […]
Author: Ofek
As Android and Java expert, recently I have came across a very nice iOS implementation for the observer pattern that exploits swift’s ARC to automatically “remove” the observer, this of course cannot be implemented in a JVM GC as unlike ARC, GC does not guarantee clearing weak references right on time. It was so good and simple […]
class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root==null || root==p || root==q) return root; TreeNode left = lowestCommonAncestor(root.left,p,q); TreeNode right = lowestCommonAncestor(root.right,p,q); if ((left==p && right==q) || (left==q && right==p)) return root; if (left!=null) return left; return right; } } Since for every node in a binary tree it […]
Making A Large Island
class Solution { public int largestIsland(int[][] grid) { if (grid.length==0) return 0; Map map = mapIslands(grid); int max = map.values().stream().reduce(Integer::max).get(); for (int i = 0; i
The original question can be found here. Lets start from an elegant the solution : class Solution { public int maxProfit(int k,int[] prices) { if (prices.length
Debouncing a function
I will start with a very common use case – say we have events that occurs a lot and in random, sometimes small intervals and we want to have them written to disk as soon as possible. We could simply write them to disk immediately after every event, but if we look back at rule […]
I was looking for a single dimension clustering algorithm back in the day and i didnt really find one implemented “out of the box” so I took the challenge and implemented one myself, I called the resulting algorithm “cluster1d” and you can see it in full here. Its runtime complexity is O(nlogn) and space complexity […]
1. You shall not crash! It is much harder to gain trust, than it is to lose it, when your SDK code crashes a customer’s app you can lose them right at this moment and it may be irreversible. You must consider all edge cases and deal with them, you must catch all your exceptions […]
A Typical and simple neural network inputs would consist of 2 dimensions : Sample dimension Feature dimension To clarify their meaning, The length of Sample dimension of the given input indicates how many data items are we going to input, while the length of Feature dimension indicates how many data features does each data item […]
Visualizing Training of Neural Networks
When I started working on neural networks deep learning projects, I was always curious about whats going on under the hood, observing TensorFlow’s output was not enough to realize how good my model really trains and it doesn’t provide enough clarity of how the model progresses towards the goal I want it to learn. After […]