Social

Yesterday, I had the pleasure of installing PowerShell 6.0 (pwsh) on my Development machine. You can find it here pwsh (I dig the new name. It is very unix-like)

I work for Microsoft. And a big part of my day is finding the right project/file to modify so I can knock work-items off my list. I use this PowerShell query often to find file names under a directory.

PS5.1 § ferasd-dev C:> ls -Recurse -Filter *.cs

This commands takes a long time for large directories. With pwsh, I noticed the increase in speed. So I thought I would measure the percentage of increase on my machine and share that with you. Here are the commands I ran:

Lately, I have been looking into ways to up my soccer game. I feel that I am not improving. I took it upon myself to make it one of my 2018 goals. How can I measure such progress? Do I rely on my feelings? Did not get tired until the game ended? Scored x goals? Feel faster? Lost weight?

I need someone to watch me. I need someone to time my sprinting speed. I am pretty sure I cannot convince anyone to come to my pickup or Microsoft Soccer League games just to gather statistics about me. I guess only technology will save me. Here is what I found for measuring my soccer game:

Zepp

Zepp is a small devise that you wear on your shin. It will give you rough stats on your kicks, distance run, speed, and some other minor stats. Speed and distance is an important metric to up my game, so I was interested in Zepp. (Will definitely get it for my kid if he is interested in soccer)

Adidas miCoach

Smart ball from Adidas! Who does not want that? It is perfect to work on your knuckle ball kick, curve, and power kicks.

Playertek

This is just a GPS tracker as far as I can tell. It is used by professional soccer players. A little pricey. But I believe it give more accurate results than Zepp.

Hope you enjoyed this post. Please let me know what you think, or if you have other products @_ferasd on twitter.

Daily stand-up is meeting that happens every day (usually the first thing in the morning) where all team members are required to attend.

Daily stand-ups try to achieve a couple of goals from the engineering perspective. They should

Give a status update on what each engineer is doing.

Identify any blockers.

Ask for help if needed.

Short term future plan.

Let me break down what each of these means. I will also add what really happens during stand-ups.

Give a status update.

Goal: Sync all engineers together. Engineers are to talk only at a high-level and not waste time on details. Each engineer will listen to what other teammates are working on and get a sense of the overall product development.

What actually happens: Every engineer is thinking what they are going to say when their turn comes. After their turn, thy are thinking about what they will work on after stand-up. Nobody is nobody is listening to what other engineers are doing. Probably, only the team lead and project managers are paying attention.Identify any blockers.

Goal: Inform teammates of any blockers that are development or resource related. For example, one could say “I am blocked by John’s work” or “I am waiting to get a larger server to test my code”.

What actually happens: This comes up very rarely. Because people use email to communicate any blockers as soon as thy happen. No one waits a whole day just to tell others at stand-up. Even after identifying any blockers at stand-up, they still need to follow up with emails.Ask for help

Goal: Engineers who are mentally/technically blocked (not by resources) ask for guidance.

What really happens: When an engineer is stuck, they ask for help via email during a work day. No engineer will publicly ask for help during stand-up. Most engineers ask discretely or just spend time pounding on the problem harder until they figure it out.

Short term future plan

Goal: identify what each engineer will do next.

What really happens: Engineers will usually work on whatever is in their backlog. This is already known by the only people who are listening (team lead and project managers).
Having said all of that, I think stand-ups are fun to have as it gets you closer to your teammates. However, if you really want to know my feelings towards daily stand-ups, read the red text.

Given a document and a word, return the number of occurrences of that word in the document. What if this function is called many times?

Here we have to define what a word means. Is ‘Cat’ equivalent to ‘cat’ or ‘Cats’? Do we care about punctuation? e.g. do we consider ‘end’ equivalent to ‘end.’? Do we care about equivalency of abbreviated words, like ‘do not’ and ‘don’t’?

For this problem, I will define a word to be a string of characters separated by spaces. In addition, I will strip any punctuation that occurs at the end of the mentioned string and will assume everything is lowercase.

Let us consider the case that this function will not be frequently called. Since it will be frequently called, this suggest that we favor optimizing memory as we will only we using it a few times. Here are the high-level algorithm steps that will solve this problem:

Scan document to next occurrence of a word until the end of the document.

increment a counter

go to step 1.

return counter

This approach will take us O(d) worst-time where d is the size of the document. If we are not careful in implementing this algorithm, we could end up with O(w*d) worst-time where w is the length of the word and d is the length of the document. Here is the solution

You can also implement the above solution with the help of the String#scan function in ruby. However, it returns an array so it has to keep track of all occurrences and that could be memory intensive. Here is the solution the Rubyist way

def word_histo(doc, word)
doc.scan(/\b#{word}\b/).length
end

Now, in order to implement the solution that allows us to call this function, we need to give up memory for speed. We store every word in a hash that maps to its count. I will not bother optimizing the solution as it will look as ugly as the previous solution, here is a more ruby way to solve the problem:

We call doc_histo once. Then we use the hash generated to query for multiple words. This ensures a worst-time of O(d) for preprocessing, then O(1) for each query (ignoring the fact the we have to read the input of size w). But we keep O(d) memory.

Write a function that takes two numbers and returns the numbers in the swapped order without using temporary memory?

The catch here is we are not allowed to use a temporary memory. So the following solution is not acceptable:

# NOT OKAY
def swapper(a, b)
t = a
a = b
b = a
[a, b]
end
# btw, it is cheating to just return [b, a].

So how to we store information about two numbers in one ‘buffer’? Bit manipulation is the answer.

The thing you need to remember is the XOR operator. We note that if we XOR a number with itself, we get 0. Let us use this to our benefit. We can swap the two numbers if we can rewrite this equation and somehow not lose any information

# a is the first number, b is the second number
a = a^b^a
b = b^a^b

Note that in the first case we XOR ‘a’ twice to get rid if it. So essentially, we are saying a = b. But this will screw up our second equation as it will become

b = b^(b)^b

And that is just equal to b = b. But, if we have an intermediate step, we can rewrite our function

Given two line segment (defined by four points), find their intersection if there is any?

Here, we can use our knowledge of pre-calculus to solve this problem. First, let us transform the input to a linear equation of the form that we all love y = m x + b. We can do this by finding the slope m first, then plugging in a point and the computed m and solve for the y-intercept b. We do this for both line segments and then equate them together to find the intersection point (x,y). Here is my code to solve this problem: