fabiochiu/medium-articles huggingface dataset:
[LeetCode]#1700. Number of Students Unable to Eat Lunch
By: Fatboy Slim
Tags: Python3, Leetcode, Leetcode Easy, Python

Environment: Python 3.8

Key technique: Counter

The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.

The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:

If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.

the sandwich on the top of the stack, they will and leave the queue. Otherwise, they will leave it and go to the queue’s end.

This continues until none of the queue students want to take the top sandwich and are thus unable to eat.

You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i​​​​​​th sandwich in the stack ( i = 0 is the top of the stack) and students[j] is the preference of the j​​​​​​th student in the initial queue ( j = 0 is the front of the queue). Return the number of students that are unable to eat.

Example 1:

Input: students = [1,1,0,0], sandwiches = [0,1,0,1]

Output: 0

Explanation:

- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].

- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].

- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].

- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].

- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].

- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].

- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].

- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].

Hence all students are able to eat.

Example 2:

Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]

Output: 3

Analysis:

Calculate student favorite type sandwich. Search sandwiches type. If 0 or 1 student favorite type number is 0, return the other type number.

Solution:

from collections import Counter class Solution:

def countStudents(self, students, sandwiches):

ans= Counter(students) for s in sandwiches:

if ans[s] == 0:

return ans[1 - s]

ans[s] -= 1

return 0

Submissions:

Reference:

https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/discuss/995915/Python-28ms-99
LeetCode problem #234: Palindrome Linked List (JavaScript)
By: Duncan Mcardle
Tags: JavaScript, Leetcode Easy, Javascript Development, Leetcode Solution, Leetcode

In this LeetCode problem, we’re given a Linked List, and asked to determine whether or not it (or rather, its values) represents a palindrome.

Revision point 1: A linked list is a data structure that consists of two properties; next which points to the next node in the list, and val which tells you the current node’s value.

Revision point 2: A palindrome is something that is the same when reversed. For example, “dad” is a palindrome, as is “12321”, but “test” is not, and nor is “123”.

What we’re being asked here then, is to get the values from a Linked List, reverse them, and see if they remain the same. For example, in the Linked List 1 -> 2 -> 1, if we pull out the values to make the array [1, 2, 1] , and then reverse it, we can see it remains the same and is thus a palindrome.

Solution #1: Array of values

Much like in the above explanation, our approach here will be first to loop through the values of the supplied Linked List, adding them to an array, and then to determine whether or not that array represents a palindrome.

This approach is fast, but it isn’t great on memory, as we’re creating a new block of data that is proportionate to the original Linked List.

Solution #2: Recursive

In this solution, we first make a recursive call that traverses its way through the supplied Linked List. Then, as each call begins to finish (starting with the final node), we compare it with the original head. In other words, we compare the first node with the last, and then move both inward.

It’s a clever approach and comes without the memory intensity of the former one. It’s also readable and very compact.

Solution #3: Reversing the second-half

Another popular approach is to reverse the Linked List from the middle point onwards, and then compare the start and end nodes, moving inwards each time. This can be done using either a recursive or iterative approach, but here we’ve done it iteratively.
In search of fixed radius.
By: Dmitry Dmitriev
Tags: Ruby, Leetcode Easy

Some times some tasks marked as like easy ones on Leetcode, nevertheless they harder then most part of medium tasks. And to solve them need to involve significant amount of considerations. One of this tasks is “Leetcode: 475. Heaters”, where required to find minimum fixed radius of heater to warm a houses. Houses and Heaters represented as two arrows of positive coordinates on line. More detail description could be extracted from source I will not spend place here.

What do we looking for?

When starting to solve a task, important part is to define what we really need to fine. And in this case we need to find maximum value of minimum distance from a home to a header. Each home has it own nearest heater. So what we need is to find maximum distance to such heater among all houses.

On the picture nearest heater fro houses #1 and #2 is H1 and nearest for home three is H2 . Shortest Distance from Home1 to H1 is 2, from Home2 to H1 is 1, and from Home3 to H2 is 2 again. So maximum nearest heater to a house stays in 2 point, this is the answer.

We are seeking for a maximum value of nearest distance from a home to a heater.

Some interesting rule.

For example nearest heater Hi found for a house1. The distance till Hi is smaller for house1 then distance till left one Hi-1 , and right one Hi+1 heaters. So for the next house: house2, as a nearest heaters we need to consider only Hi and heaters that stay further right way. Because as house2 has moved forward from house1 distance between house2 and Hi-1 even greater than distance between house1 and Hi-1 so we can eliminate Hi-1 from consideration.

When we found nearest heater for a home, search for next home started from the same heater.

The algorithm is ready.

Get minimum distance till a header from each home to a heaters. Select maximum value from all this distance.
Happy Number
By: Monisha Mathew
Tags: Cycle Detection, Floyd Algorithm, Leetcode Easy, Leetcode, Happy Number

Question: Write an algorithm to determine if a number is “happy”.

A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.

Example:

Input: 19

Output: true

Explanation:

12 + 92 = 82

82 + 22 = 68

62 + 82 = 100

12 + 02 + 02 = 1

You may view the full question here.

Approach 1: Using HashMaps to store the evaluated values to detect repetitions.

//Approach 1:

//Runtime: 2ms

//Memory usage: 33MB class Solution {



public boolean isHappy(int n) {

HashSet<Integer> set = new HashSet();

set.add(n);

int sum = n;

while(sum!=1){

sum = getDigitSqrSum(sum);

if(set.contains(sum)){

return false;

} else {

set.add(sum);

}

}

return true;

}



private int getDigitSqrSum(int n){

int sum = 0;

while(n!=0){

int d = n%10;

sum+=(d*d);

n=n/10;

}

return sum;

}

}

Approach 2: Using cycle detection algorithms such as the Floyd’s Tortoise and the Hare algorithm. You may look up more such algorithms here.

//Approach 2:

//Runtime: 1ms

//Memory usage: 32.6MB class Solution {

//Using Floyd Cycle detection algorithm

public boolean isHappy(int n) {

int slow, fast;

slow = fast = n;

do {

slow = digitSquareSum(slow);

fast = digitSquareSum(fast);

fast = digitSquareSum(fast);

} while(slow != fast);

if (slow == 1) return true;

else return false;

}



private int digitSquareSum(int n) {

int sum = 0, tmp;

while (n>0) {

tmp = n % 10;

sum += tmp * tmp;

n /= 10;

}

return sum;

} }

Find more posts here.

Cheers & Chao!
Min Stack
By: Monisha Mathew
Tags: Min Stack, Leetcode, Programming, Leetcode Easy

Question: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

push(x) — Push element x onto stack.

pop() — Removes the element on top of the stack.

top() — Get the top element.

getMin() — Retrieve the minimum element in the stack.

Approach 1: The discussions section had quite a few brilliant ideas. Here’s one that seemed to inspire this solution. Let’s quickly check how this algorithm works on a simple example —

Pictorial representation of the algorithm for a simple example

And here’s the code —

//Approach 1:

//Runtime: 47ms

//Memory usage: 40.4MB class MinStack {



int min = Integer.MAX_VALUE;

Node stack;



class Node {

int val;

Node next;

Node(int val){

this.val = val;

this.next = null;

}

} /** initialize your data structure here. */

public MinStack() {

stack = null;

}



public void push(int x) {

if(min>=x){

//add copy of previous min

add(min);

min = x;

}

add(x);

}



private void add(int x){

Node node = new Node(x);

node.next = stack;

stack = node;

}



public void pop() {

if(stack!=null && stack.val==min){

//an extra pop

stack = stack.next;

//now update min

if(stack!=null)

min = stack.val;

}

if(stack!=null)

stack = stack.next;

}



public int top() {

return stack.val;

}



public int getMin() {

return min;

}



} /**

* Your MinStack object will be instantiated and called as such:

* MinStack obj = new MinStack();

* obj.push(x);

* obj.pop();

* int param_3 = obj.top();

* int param_4 = obj.getMin();

*/

Cheers & Chao!
Reverse Bits
By: Monisha Mathew
Tags: Leetcode, Unsigned Integer, Leetcode Easy, Reverse Bits

Question: Reverse bits of a given 32 bits unsigned integer.

You may view the full question here.

Approach 1: Let’s start with a simple approach.

Step 1: Extract the right most bit in the main number

Step 2: Shift the bits in the main number by one position to the right

Step 3: Shift the bits in the reversed number by one position to the left

Step 4: Append the bit extracted in Step 1 to the partial result generated in Step 3 by doing a bitwise add operation

Repeat these steps until the main number reduces to zero.

The code would look like —

public int reverseBits(int n) {

int rev = 0;

while(n!=0){

//Get the right most bit

int right = n & 1;

//Shift bits to the right by 1

n = n >> 1;

//Add the rightmost bit to the reversed number

rev = rev << 1;

rev = rev | right;

}

return rev;

}

But this code returns the wrong result! For instance,

Input: 00000010100101000001111010011100

Output from Code: 15065253 (00000000111001011110000010100101)

Expected Output: 964176192 (00111001011110000010100101000000)

The problem with the code is that we stop evaluating when the number reduces to zero. In the above example, the input has 6 zeroes in the beginning, which do not get evaluated because the loop condition (n!=0) would cause the while loop to break.

Approach 1.1: There are 32 bits in the unsigned integer we are evaluating. To fix the previous version of the solution, we need to modify the loop condition. We will have to continue to evaluate until all the 32 bits are evaluated.

//Approach 1.1:

//Runtime: 1ms

//Memory usage: 32MB public class Solution {

// you need treat n as an unsigned value

public int reverseBits(int n) {

int rev = 0;

int bitCount = 32;

while(bitCount-->0){

//Get the right most bit

int right = n & 1;

//Shift bits to the right by 1

n = n >> 1;

//Add the rightmost bit to the reversed number

rev = rev << 1;

rev = rev | right;

}

return rev;

}

}

Find more posts here.

Cheers & Chao!
Linked List Cycle
By: Monisha Mathew
Tags: Cycle Detection, Linked List Cycle, Floyd Algorithm, Leetcode Easy, Leetcode

Question: Given a linked list, determine if it has a cycle in it.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1 , then there is no cycle in the linked list.

You may view the full question here.

Approach 1: Taking a page out of an earlier post. To be precise, borrowing the idea of Floyd’s Tortoise and the Hare algorithm. (You may look up more such algorithms here.) Let’s jump straight to the code —

//Approach 1:

//Runtime: 0ms

//Memory usage: 37.6MB /**

* Definition for singly-linked list.

* class ListNode {

* int val;

* ListNode next;

* ListNode(int x) {

* val = x;

* next = null;

* }

* }

*/

public class Solution {

public boolean hasCycle(ListNode head) {

ListNode tortoise = head;

ListNode hare = head;

do {

if(hare!=null && hare.next!=null) {

hare = hare.next.next;

}

else {

return false;

}

tortoise = tortoise.next;

} while(hare!=tortoise);

return true;

}

}

Find more posts here.

Cheers & Chao!
Factorial Trailing Zeroes
By: Monisha Mathew
Tags: Factorial Trailing Zeroes, Recursion, Leetcode Easy, Trailing Zeroes, Leetcode

Question: Given an integer n, return the number of trailing zeroes in n!.

You may view the full question here.

Approach 1: I highly recommend you to take a look at some of the discussions here. The solution below is inspired by these posts.

Let’s try to visualize the problem at hand. Consider we need to find the number of trailing zeroes for 50!.

Every trailing zero is due to a possible factor of 10. 10 can be broken down as 2 x 5. So, if we were to find 5!, it would have been —

1 x 2 x 3 x 4 x 5

The 2 x 5 in the combination above contributes a factor of 10, which in turn contributes a trailing zero. Actually —

1 x 2 x 3 x 4 x 5

there are more 2s than we need. So, if we just kept tab of the 5s, we could possibly compute the trailing zeroes.

Now, let’s consider our original problem of 50! and try to observe the pattern.

Every 5th element contributes a 5 and hence at least one trailing zero each. Similarly, every 25th element contributes two 5s. And so on…

Consider the above example. 50 can be divided into 10 chunks of 5 i.e., 50/5=10. So, we know that we will find at least 10 trailing zeroes. Now, we check further to see if there are any elements that possibly contribute extra 5s. A simple way to do so is to keep dividing till we can no longer have enough to make a unit of 5.

Step 1: 50/5=10

Step 2: (previous result) 10/5=2

[Explanation: Elements 25 and 50 contribute extra 5s]

Step 3: (previous result) 2/5=0

[Now we stop]

We could express this recursively as —

//Approach 1:

//Runtime: 1ms

//Memory usage: 33.2MB class Solution {

public int trailingZeroes(int n) {

if(n==0){

return 0;

}

return n/5 + trailingZeroes(n/5);

}

}

Approach 2: In the previous approach, we could just skip the checks for n = 0 to 4.

//Approach 2:

//Runtime: 0ms

//Memory usage: 33.4MB class Solution {

public int trailingZeroes(int n) {

return (n<5)?0: (n/5 + trailingZeroes(n/5));

}

}

Find more posts here.

Cheers & Chao!
LeetCode 100 Same Tree
Tags: Leetcode, Leetcode Easy

The code I wrote:

The Answer:

I want to take a moment and reflect why I have such a messy code and how to improve. I realized that for some mysterious reasons I have been keep making the same mistakes when I try to solve the issue for a tree. I think the most obvious problem I usually make is that:

I wanted to check the node itself and at the same time I also want to check the left and right. This is clearly duplicated work because I could just wait for the next recursive call to check it. I wanted to check the status of if the node is null or node by manually writing a if statement and else if to check if one of them is null. This is, again, duplicated work. I can totally just check if both of them are nulls. And if not, then if any of them are null this means it is wrong. I can totally use a || statement to do that.

If statement a means: node1 == null

statement b means: node2 == null

We want to determine if a == b is true then we should go like:

a && b -> we can return TRUE if they are both null.

a || b means a && !b or !a && b, either way, a==b will be false and we can return FALSE.

!a && !b -> We will not know if a == b because in this case they are both not null and therefore we can start further instructions to find out if their values are the same.

Conclusion: I think I made the mistake because I neglected that checking value is the last step and we HAVE TO check the status of null before the last step.
LeetCode : [334] Increasing Triplet Subsequence
By: Vishal Singh
Tags: Programming, Leetcode Easy, Leetcode Medium, Leetcode, Leetcode Hard

Approach -1 : Brute Force

Idea is to check for all combinations which holds true condition that is nums[i] < nums[j] < nums[k] for i < j < k .

Time Complexity : O(n³)

Space Complexity : O(1)

Approach - 2 : Using Stack

We can observe that we just need to check whether an element has smaller value in left side and greater value in right side , so we can find left smaller and right greater in O(n) using stack .

Since we really need only one combination that holds this condition true , so we are storing all left smaller and then check for right greater if we found then return true .

Time Complexity : O(n) , for scanning two times and each time every element will be accessed at most two times

Space Complexity : O(n) , for stack and left array

Approach - 3 : Storing smaller and next smaller

If we have two element a and b where a < b and now if we found c as b < c then we will return true , now if we found a less than previous a then we will update a .

Time Complexity : O(n)

Space Complexity : O(1)
What is Dartmoor gravel?
By: Peter Gold
Tags: Dartmoor, Gravel Bikes, Travel, Bikepacking, Random

What is Dartmoor gravel?

Living on Dartmoor makes riding a bike so much easier for me. Not in the easy riding perspective, but the simple fact that I ride from my house as I literally live on Dartmoor National Park. But I can also drive only 30 minutes and I am in a very different part of Dartmoor without having to get on a motorway to get here or there.

However, Dartmoor can be very bleak. It has one of the remotest parts of England (based on distance from a road). It has some of the highest rainfall. The highest brewery. The highest and very bleak and inhospitable Dartmoor prison! Ghosts and ghouls galore, or so local people will tell you. But no matter how accurate these “facts”” might be, I can tell you categorically that navigation on Dartmoor can be VERY hard in the wrong weather. And the lovely looking bridleways on your map can turn out to be deep bogs that are virtually unwalkable let alone rideable.

Local knowledge

As you’d expect though, in amongst the mists of doom lurk many mystical gravel tracks, but they take time to find and turn into gravel biking routes. Which is what lockdown allowed me to do. Hunt down the best gravel tracks and create routes you can ride. Admittedly I have used some tarmac to link tracks together, and there are some grades of gravel that some would declare as rocks, but for every walk, push, carry or crash, there’s a prize to be earned.

Maybe an amazing descent. Or solitude. Or ancient history. A babbling brook or a raging river. Dartmoor has it all.

From the 130 mile Dartmoor 130 to the Princetown high routes along old railway lines (now perfect gravel), I have put together a year of lockdown riding into a series of routes that can all be enjoyed, and endured in places, on a gravel bike. They can of course be ridden on a mountain bike, but anything more than a hardtail with 100mm suspension forks would be overkill. There are other routes for MTBers, like The Killer Loop! (not one of mine though)

As I expand this guide I’ll be adding:

Campsites.

Cafes.

Places to stay.

Things to see.
You never know!
By: Shakti Shetty
Tags: Humour, Compilation, Knowledge, Philosophy, Random

They say ignorance is bliss but the greater question is, what are we talking about? If a person doesn’t know what ignorance is, then what’s really left in the equation? I am thinking on these lines keeping in mind the first time — I was in school back then —I heard USA’s defense secretary Donald Rumsfeld make the most bizarre as well as the most enlightening statement. He said, “Reports that say that something hasn’t happened are always interesting to me, because as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know.”

He was obviously referring to the colossal farce called ‘War on Terrorism’.

Anyhow, not a week has passed by since I haven’t thought of those bunch of words.

There are some things you never forget. They are drilled into your psyche. For instance, my tutor once told me that it’s more important to brush one’s teeth before going to sleep than after waking up. That line hasn’t left me and there are many more such nuggets from the past. The summation being, what we know for a fact doesn’t necessarily have to be the fact. What we know for real doesn’t always end up being real. These are different facets of the same mind. What I think of isn’t the same as how I think. Moreover, thinking and knowing aren’t the same either. I think the world is wonderful. I know the world is crappy. And when you throw in the embers of belief, then things get interesting. Believing in something excuses us from thinking as well as knowing. Amazing, isn’t it?

In this ignorant spirit, let me list a few thoughts that lead us nowhere.
When in doubt, stick to logic
By: Shakti Shetty
Tags: Food, Chess, Culture, Observation, Random

It’s the 11th day of the lockdown and in this ongoing phase, I’ve noticed quite a lot of things which I wouldn’t have had I been continuing with my office-home-office routine. For one, time indeed moves slowly when you stay indoors. At our workplace, I wouldn’t realize where half the day went by. Secondly, I am much aware of the little things now. Let me ask you a question, when was the last time you actually focused on food while eating? No screen distraction whatsoever? I believe, for most of us armed with laptops, smartphones and the works, it’s difficult to do just one thing at a time. We take it as an affront if we aren’t multitasking. And as a consequence, we end up doing a lot of things wrong. In isolation, I’ve observed the difference between dependency and independence. It’s not that we can’t wash our clothes or clean our dishes. Just that the system in place ensured that we want our domestic helps to take care of such stuff for us. With them away, the responsibility falls squarely on us and we’ve understood that almost everything is doable.
Do you have a bird friend?
By: Shakti Shetty
Tags: Society, Culture, Observation, Wisdom, Random

Did you know that Nikola Tesla, arguably the greatest geek of all time, died a virgin? At least that’s what some of his biographical accounts suggest. He had negligible interest in pursuing conjugal relationships. In fact, the closest he got to admitting he was in love was with a pigeon. Yes, true to the curio attached to geniuses, he once wrote how much he loved a bird, emphasizing that his longing for the bird is equivalent to a human longing for another human.

So sweet.

Which brings me to my next question — do you have a birdy friend? I do. Last year, an injured pigeon showed up at our front balcony, quite rattled and ruffled. It was obvious that the ferocious fellow had been in a competitive battle (which he didn’t win) and used to sit all day long on the AC vent pipe outside our apartment. His neck bore a visible wound; a very peculiar beak-peck injury. I used to leave bread crumbs for him and water as usual in the bowl. This recuperative visiting activity went on for about 2-3 weeks. He showed up in the morning and stayed perched on the pipe for hours. Like a fugitive waiting to heal and seek revenge. Later, after fully healing himself, he used to show up sometimes. And then, after a while, he stopped visiting us.

Until last week, that is.

Early morning, here he was at his old spot. I identified him immediately because of his neck — although it’s fully healed, the feathers on the neck aren’t in sync with the rest of its body. So it’s easy to recognize him. I was watering the plants and he landed on the ledge and sat there with utmost confidence. He recognized me just like I recognized him. Usually, the pigeons fly away because they are scared of Ranga and are extra cautious even while drinking water from the balcony bowl. This one, my old nameless friend, wouldn’t move one inch. Just kept looking at me. I smiled at him and watered the plants. Walked past him twice. Didn’t move an inch. If this isn’t the trust of an old friendship, what is?

Tesla would have been envious of us.
Look beyond your bias
By: Shakti Shetty
Tags: Society, Statistics, Chess, Observation, Random

Yesterday, for the first time in my life, I successfully donated blood but it wasn’t my first attempt (more on that later). It was an emergency for a friend. We (my wife and I) stepped out and saw empty policed roads for the first time in almost a month and the whole process went by pretty smoothly. The last time I tried donating blood was in 2005 thanks to a donation drive organized by our polytechnic (Nashik). I remember showing up in the morning all enthu about the “good deed”. After going through the standard questionnaire — had no tattoos back then — I lied down on the cot but as soon as I noticed the blood leaving my body, I fainted.

Classic wuss move.

However, when I woke up, the attending lady was least interested in knowing how I was. She very matter-of-factly said, “Donating blood isn’t for you. Please don’t come back here. You are discouraging other people.” Anyway, after years of proving her right, I finally made it. She wasn’t wrong that day because for a nation bulging with 1 billion+ humans, we shouldn’t be running out of blood but the bitter truth is we do. People spend their entire lives without donating blood but expect blood to be miraculously present in the bank whenever they need it.
Time to no all the answers
By: Shakti Shetty
Tags: Chess, Fitness, Childhood, Random, Memories

It’d be unfair to mention my dad and not my ma. If you’ve been a regular reader of this blog, you must have acknowledged my blind love for elephants by now. However, the source of my affection lies in my childhood. Back in those days, in the streets of our slums, elephants used to visit every once in a while. Had no idea about animal cruelty and assumed that it’s normal to see tamed wild animals in public. Maneuvered by the mahout sitting close to the beast’s head, a spectacle of sorts used to unfold as the elephant was paraded through the market. As they made their stops, shopkeepers spared some coins which the poor haathi passed up to his master. But my amma never trusted the man on the top. Whenever, we (my brother and I) were in the market with her, and an elephant passed by, she would buy a bunch of bananas and make us place it on the edge of the elephant’s trunk; the pleased grey creature used to gulp it within a second. Here comes the best part: after having its snack, it used to bless us by tapping its nostrils on our heads. And to this day, I wonder when was the last time this happened. Must be sometime in the late 1990s.
That time of the night..
By: Bharath Sudhama
Tags: Things To Love, Night, Bengaluru, Writing, Random

That time of the night..

I reach home now, after what was a draining day. It’s not often that I’m awake so late in the night. This is way too late in the night for someone who yawned at 8 in the evening. It’s probably the time millenials, or the way my dad puts it ‘kids with standard lower than their jeans’ wake up.

Sleeping early has always been a habit, it’s sort of mechanical how your body kinda shuts down after 9pm till you reach a certain age, where staying up late in the night becomes a part of life. It’s too hard to recollect the time when I turned from a person who slept before the hands of the clock knocked at the number 9 to staying awake even after the hands of the clock entwined themselves like they never wanted to let go, even though it lasts for a tiny minute.

Coming to think of it darkness has always been an old friend, it never scared me as a child, infact it put me at ease. It was like my idea of heaven was a dark place, with cold breeze, and a cozy quilt. As I grew up I embraced darkness so much that I began to long for it. Poor sun has to get reprimanded for coming up every night, don’t you wish that it stayed dark forever? No? okay.

I do, I always thought of a world where the only light that lit up the world was the smiles of people. I still do. It’s kinda poetic of the darkness in you and the darkness in the world find solace in eachother. It seems perfect together, like the song that could make everybody in the world hum along. There’s something about nights that make me come alive. The empty streets, the distant lights, the whizzing of vehicles, the howling of dogs, and most of all, the silence of the chaos.

There’s so many things that come alive at night, things that you don’t notice during the day. The chirping of crickets, a sound that shrills in my ears during the day feels like a song sung only for me at night. the empty roads and the stripes on it, that lay motionless during the day seem like it’s going to take various shapes during the night, and slowly return back to its place in the morning. The clear blue sky which looks like a canvas during the day, turns into a painting at night.

Someday I hope I’ll be able to single out my sole reason to fall so much in love with the night. Maybe someday it’ll tell me what is it that is has with it that I don’t know, to hold me captive. Someday at this time of the night.. Someday. Stop
Generate Random Data in Snowflake
By: Rahul Tandon
Tags: Snowflake Computing, Data Generation, Snowflake, Data Generator, Random

Generate Random Data in Snowflake

Sometimes we do face a scenario wherein we need to generate random data . Snowflake provides certain functions that can generate random data and hence can be extremely useful to test the code as an developer or to meet business requirements. Lets check the data generation in snowflake with below example . We have used four Snowflake functions : RANDOM() , UUID_STRING , Table and Generator :

Random() : This function generates the random integer values .

UUID_STRING : This function generates random alpha numeric string similar to rowid in traditional databases.

Generator (): Creates rows of data based either on a specified number of rows, a specified generation period (in seconds), or both. This system-defined table function enables synthetic row generation. Note that it is possible to generate virtual tables with 0 columns but possibly many rows. Such virtual tables are useful for queries whose SELECT clause consists entirely of data-generating functions.

Table() : This function converts the data into relational table format .

Rahul Tandon

Snowflake Certified

linkedin.com/in/rahul-tandon-b1b232117
What Might HR Tech Learn From Theranos?
By: Peter Gold
Tags: Theranos, Random, AI

What Might HR Tech Learn From Theranos?

Back in 2003 Elizabeth Holmes founded Theranos, the company that developed a small device that would allow hundreds of different medical tests from just a few small drops of blood, and that ultimately these small devices would be in every home.

Big investors most likely loved the idea because they saw the potential for scale and the opportunity to make loads of money. Avarice at play amongst the wealthy. And very quickly Holmes became a tech celebrity and was recognised as the youngest self-made female billionaire and the “next Steve Jobs” because of her amazing technology.

But it all turned out to be lies and the smokescreen evaporated.

And that was that. But in reality, it was just the beginning of the end.

When unicorns die

Judgement day

When such big money is at play from such high-profile investors, they don’t simply disappear as quickly as the unicorn.

Founder and CEO Elizabeth Holmes, and President and COO (and onetime boyfriend) Ramesh “Sunny” Balwani both face charges of wire fraud and face up to 20 years in jail.

The trial for Holmes started this week and is expected to run for around 16 weeks. Balwani is due to go to trial early next year. There is plenty of running commentary on this case from blogs to podcasts if you want to hear what happens.

So what about HR Tech?

Theranos had a great idea, a dream of solving a human problem, but they got carried away with that dream and refused to accept failure, instead continuing the lie until they had nowhere to go. Apart from (possibly) jail.

But just because Holmes refused to accept reality, the employees didn’t and decided to ditch the koolaid and speak out. Which was, according to various media channels, how the truth came out and once it was out, the end was nigh.

In the world of HR tech there are not exactly life saving systems with such great claims of greatness but there are plenty flouting AI, conversational AI, skills engines and other such paradigms that in reality, are still very much idealistic concepts. Of course, koolaid is available on draught plus with so much money sloshing about, there are many analysts looking to write gushing reports to hang onto the financial coattails of these fast moving unicorns and further their call to greatness.

I see a perfect storm on the horizon. Too much money, too much false promise, too much koolaid. And when too many people are chasing the money, there will be too many casualties.

But whilst the world is in conflict with wars, poverty, pandemic, right wing nationalism, climate and so much more, we close our doors and count our money in private. The problems outside our door are not our problems. Until they are.
Python Basics: The Random Module
Tags: Modules, Random, Python

Python Basics: The Random Module

The thing that made me fall in love with Python. thequeenbeebs Sep 2·3 min read

Photo by Mick Haupt on Unsplash

Hey guys! As I mentioned last week, I have just started my journey learning Python. As with any new language it is a little slow going at first, but I have started picking up speed and have really started to fall in love with it. One of the things that was a game changer to me this week was being introduced to the Random module and all of the methods inside it that you can use! Today, I’m going to break down the Random module, show you how to add it to your application, and the most important and commonly used functions within it.

What is Random?

Random is a module in Python that generates pseudo-random numbers for various purposes. It’s been super great for all of the silly CLI games I’ve been building, but also has fabulous uses for real life as well.

Importing Random

Importing Random in your Python file is super simple, and similar to importing React components if that’s something you know how to do. At the top of your Python document, simply type:

import random

That’s it! Now you can call on all of the random functions that your heart desires. Let’s break down a few of them that I love now.

Random Functions To Know

random.randint()

This function is the most commonly used in terms of returning random numbers. The function has two parameters, that are the range, and the function will return a random integer inside that range.

random.randint(1, 10) # returns a number between 1 and 10

This function is great for any sort of application where you need to rely on chance. Rock, Paper, Scissors! Heads or Tails! Roulette! These are all things with an equal amount of probability where you can assign each choice to a number.

random.random()

This function doesn’t take any parameters, and returns a number between 0.0 and 1.0.

random.random() # 0.3

random.choice()

This is definitely my favorite of the random functions. It takes as its parameter a list, and will choose a random item from that list.

fruits = ["Apple", "Pear", "Banana", "Peach", "Plum"] random.choice(fruits) # "Banana"

random.choice(fruits) # "Plum

This is a way of creating an even simpler game of chance; instead of having to assign each selection to a number, you can create an array of all of the choices like so:

choices = ["Rock", "Paper", "Scissors"]

random.choice(choices)

random.shuffle()

Another great one for lists, random.shuffle() will take a list and mix it up into a random order. Let’s use the same fruits list from above:
How To Screw Up Your Life 😁
By: Andrew Mitson
Tags: Mental Models, Regret, Careers, Life Lessons, Career Advice

Only in the two years that followed did I finally get the chance to step back and really work out what I wanted to do.

Travel, extensive reading, self-experimenting, constantly seeking out new experiences…I finally got to understand who I am.

Turns out I don’t really like startup entrepreneurship…

But I love coaching startups. I love entrepreneurial projects and creating new things. I love writing, accelerated learning, exploration, biohacking, neuroscience, art, kitesurfing, chess, languages…

And now I’m designing my life around all the above vs a life randomly assigned to me by bad choices I made when I was 16.

Make time to explore your options. Travel. Read. Talk to people in different careers.

And once you find your “thing” or “things”, it’s time to optimise. Go all out and make your dreams come true.

Perpetual FOMO

Of course, there’s always going to be a shinier “thing” out there and you can’t spend your whole life “exploring options”.

Which brings us to the flipside of premature optimisation…

Perpetual FOMO — an even more surefire way to screw up your life.

Like a perpetuum mobile (incidentally the name of my favourite song), the FOMOists perpetually swing from one thing to the next without ever seeing any results.

by Andrew Mitson (www.andrewmitson.co.uk)

The trouble for the FOMOists is the grass is always greener. And it’s just too easy to rationalise switching career pursuit or business idea or programming language — especially when the going gets tough.

Right now I’m learning the piano, for example, but I’m desperate to switch to music production.

I’d actually get to make my own music (vs rote-learning piano pieces). I could sell the beats I produce. I could combine infinitely many instruments to create totally new sounds.

And the piano is getting boring. Learning scales and chords. Repetitive practice. Frequent frustration.

Fortunately, I pre-committed to 60 hours of piano practice.

However much my inner-FOMOist wants to switch…I am going to complete my 60 hours. And then I can continue, or try something new.

But 60 hours is enough to reach results — a few impressive pieces under my belt, a good foundation in music theory, and perhaps some pop improv.
Letter to 80 year old self: Am I experiencing regret for my decisions?
By: Tarun Babbar
Tags: Decision Making, Regret, Life Lessons, Growing Up, Letter To The Self

Rohtang Pass, India, August 2017

Dear 35 years old myself,

Thank you for finally asking me today. It’s always a wise idea to recognize your problems and seek help from someone who has been through it all.

I am going to say things you might already know. Our lives are like a maze, and as we navigate through this maze, we all realize that many of our previous decisions were suboptimal. I am choosing to use the word ‘suboptimal’. You know why? Because our decisions are like solutions to ‘mathematical problems’. Our decisions are also effective within defined boundaries and with some assumptions. It doesn’t matter how hard the problem or a decision was. This is how all the decisions were ever made!

Now that you are questioning your past decisions, I want to remind you that every decision you ever made was, in fact, your best one at that time. It is only because you have the capacity to look backward and introspect, you are now calling some of those decisions suboptimal. And, you can see many reasons; you didn’t have enough information and made bad assumptions, you got carried away by your emotions, or you didn’t know that the future will be so different. The fact is, you could have controlled certain factors, but many were outside your control. And, that’s the very nature of life!

At the same time, I don’t want you to think that nothing is in your control. Every decision you make from now can be better than the one you ever made in the past. And how do you do that? We do that by becoming more mindful of your emotions and learning to reflect upon the past. Once we become more mindful of our emotions, we begin to differentiate between emotions which carry important information vs. emotions which can hijack our decision-making process (you know which one to look out for!) And, by committing to regularly reflecting upon the past, you will gain additional insights on what you could do differently going forward. The key is to recognize the interplay of time. If the present is our playground, the past is our coach. This perspective is your key to begin reducing regrets!

I understand you miss your elements from past. And, I can see that this feeling gets overwhelming at times! But, you should remember that you did not want to settle with whatever you had at that time. Perhaps your expectations were very high! Every decision entails some compromise, and I don’t think you were prepared to accept this fact back then. Compromises are part of the decision-making process, like constraints with any problem.

And, do you want to know why your mind is wandering and imagining a different present? It is because it wants to teach you something. Like I said above, our emotions carry important information. What you are experiencing is regret. And you must remember that regret is a part of our very existence. It defines who we become. Once you recognize it, embrace it, and learn from it, you will move on!

Yours,

Elder Yourself
The Thing About Regret
By: Angelia Mercy
Tags: Carpe Diem, Essay, Regret, Life

Several days ago, my favorite Indonesian Youtuber, Raditya Dika, released a podcast with the title, "Something Scarier Than Failure".

The answer is regret. And I can't agree more. Regretting something is indeed a thing that will torture me on the highest level.

"Mostly you regret things you did not do." (Unknown)

The simplest example can be seen based on my own school life. If someone asked me what I regretted most from my high school year, those things were:

Rarely following any competition to gain experience

Not following any club whilst I have the potential

Not finding the joy of learning

Barely make any close friend

But hey, it's never too late to fix everything. Experience matters because they give you insight into what you want to achieve in the future. As long as you have a new day ahead, it always means another chance to try. We know that we can avoid failure. However, we can avoid regrets.

The thing is, I always overthink too much, literally about anything. The reason I was too afraid to try new activities during high school is because of my fear of failing in my academic life. I was too worried about failing the exam, or not getting the first rank anymore. Perhaps my grandmother would scold me for not being serious, or she would compare me to my cousin. Ever since I was little, the competition was quite harsh and I was too afraid to deal with it. And in the end, I became fearful of doing anything that presumably will distract me from getting the best score in exams.

On the other hand, Raditya Dika admits that he doesn't think that much when he wants to do something. And man, I wish I could be like that. To try new things because I'm excited about them instead of thinking about how it will go. It's like a moment where you wish you could do bungee jumping without thinking about the rope that ties you or the fact that a person will push you from a high bridge into the water. All you think about is that it will be a memorable moment and you can't imagine what will happen if you missed this chance.

I want to live without regret, even though I have to struggle first to assure myself that everything is going to be fine. Or, if things don't end up well, then I'll just need to find the solution and move on. I want to do everything I love and that thing surely will help me to improve into a better human. And every day, I am one step closer to becoming the new version of myself: someone that one day will look back into my youth and smile, thinking, "Damn, what a beautiful life."
I attended a grief support group today
By: Maggie, Mom Of Two
Tags: Mothers Grief, Sorrow, Survivors Guilt, Regret, Grief

I feel so tired now. I’m not sure I can really handle the sorrow of others, I feel it to keenly. I have been hurting myself with food this week. I am finding comfort in feeling uncomfortable. I need to stop this cycle but I’m not sure how.

I feel like a zombie. I wake up, a tide wave of grief holds me under as it comes rushing back. And then I panic. Is Amy okay? I search my phone for texts I may have missed. Will she remember to call me in an emergency so I wake up? I cannot lose both of them and it is my deepest saddest fear. What kind of mother loses her child? How could I have not done more? Why didn’t I know?

I feel like I can’t hold on to myself. I am so lonely. Alex was my person.

When he grew up and moved out, I missed our closeness. But he was an adult, a man, and he didn’t need me the same way. He would correct me, point out my lack of knowledge and when I would try to catch up, he was on to the next crusade. I was always a step behind (or just wrong).

But it was okay because he was okay, you know what I mean? He went to work, therapy, made new discoveries, he’d have setbacks but then suddenly, there was a new thing he was doing. He’d keep me in the loop. I thought he was okay.

I miss hearing his voice calling and instead of hello it was, “Oh hey…so uh” and then a request or telling me he was coming home or did I get something in the mail for him.

I miss him so much. I feel like I am falling under water. I have thoughts, if I just walk out to the ocean, how far could I get and then fall asleep so this awfulness ends? I wouldn’t do it, but it sounds like an scape for this so much of feeling. How much can a heart break?