About a year ago I wrote Using Sinon Stubs, if you’re new to Sinon I recommend you read that post first!

sinon is a library that provides test spies, stubs and mocks in JavaScript

It all started when a friend wrote a test but the stub he created wasn’t working: reviewing the test everything seemed to be done properly, yet it was obvious from the test logs that the method was called instead of the stub.

What was going on? And how can we fix it?

It took a bit of digging to figure out, and the root-cause was not trivial which is why we’re sharing it with you, hoping to save…


I should be ashamed of myself that I found it only now, after a year of working with GH, I know…

Reviewing PRs on GitHub was a bit of a hassle when whitespaces were involved (that is, until now).

For example, whenever the writer decides to wrap a piece of code with try/catch clause, the lines in-between will be marked as “changed” by default.

This sucks!

BUT, there’s a simple setup change to ignore whitespace changes:

How to hide whitespace changes in the PR

Have fun reviewing PRs, bye-bye now!


To Node or not to Node

It all started one afternoon when I got a call from Yoav Nordmann. He wanted to continue a discussion that we just had at the backend-group in Tikal. The discussion was about good and bad use-cases for using NodeJS. But let me take a few steps back.

I was first introduced to Java in the previous century: the year was 1999 and it was my first year on a CS degree and what can I say: I did not fall in-love…

Fast forward to the end of 2017, at this point I have many years of experience with Java and…


Wells Read — Coding 100

In the challenge we download a zip file which contains two text files:

  • A dictionary (a file which has one word in each line)
  • The book: “The Time Machine”

Now we can see that some words got “scrambled” in the book, looking at a few example we can see that they all have the same characteristic:

Only on character was replaced!

This is great news, it means that we’re looking for words that are not in the dictionary file with Levenshtein distance of 1 from a word that in the dictionary.

Coding it is not difficult (written in nodejs):


Example of a Prometheus Dashboard

Metrics can be divided into two categories: infrastructure-metrics and business-metrics.

include signals about the system/os such as: memory, disk, CPU etc. Google defines a 4 golden HTTP metrics: traffic, error rate, latency and throughput/saturation — which may be considered as .

provide visibility into the business/application.

A few examples:

  • number of visitors ≠ the number of HTTP calls
  • Conversion-rate is not always trivial to measure using infrastructure-metrics.
  • A/B testing is very difficult if possible at all to be achieved using infrastructure-metrics

In order to be able to publish we have to provide our engineers an easy-to-use mechanism…


A regex that was used to check validity of an email address

Recently I declined two suggested changes to a library I’m maintaining. Both PRs had one thing in common: they introduced a change that required running a regex match in order to do something.

While I love using regexes for small/non-prod scripts, I think it is a bad idea, in general, to use them in production. From over 15 years of experience as a backend-developer, I can hardly remember one instance where I thought that the use of regex in production code was justified.

After having to explain my reasoning to two engineers, I decided that the next one who’ll ask…


Someone asked me how can we use a lambda in order to run a certain logic every time that a certain endpoint gets hit with a HTTP request.

I thought it’s pretty simple but after starting to go through the steps I realized that AWS interface is not that straightforward and could be confusing.

The following is a simple step-by-step guide that explains how to create such a lambda.

1. Go to lambda tab

2. Implement your logic


sinonjs

A few days ago I wanted to test a JS function, part of the test was to verify that another function gets called, and gets called correctly (with the correct parameters). I ended up using Sinon for the task, and now looking at it — it’s pretty easy and straightforward. Thing is, when I was trying to write my tests I didn’t find good examples and there was a little struggle until I figured it out, which is the motivation for this post (why not share and make someone’s else life easier, right?).

So let’s get down to business!

Say…


Declarative & Imperative code paradigms, are common buzz-words in the tech industry. In this post we’ll discuss these programming paradigms, what’s so good/bad about them and most important: a simple practical suggestion that can turn imperative code into declarative. Ready?

Let’s start with the more intuitive paradigm: Imperative. Imagine you want to get from point A to point B, like most of us, you’ll turn your phone’s GPS on, and ask for directions.

The list of directions may looks something like the following:
* drive straight for 0.5 miles
* turn right into street X
* continue for another 0.3 miles
* turn right…

Nir Alfasi

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store