browse by category or date

Today Medium sent me its weekly summary. One of the link that caught my eye was “5 JavaScript Tricks That Are Good To Know“. I decided to check it out hoping to learn something. After all, I might not know what I don’t know, you know.

1. Array operation using every and some

This one I know 😀

var array1 = [1,2,3,4,5];
var array2 = [-1,0,4,10,11];

var isPositive = (num) => {
   return num > 0;
}
console.log(array1.every(isPositive)); // true
console.log(array1.some(isPositive)); // true

console.log(array2.every(isPositive)); // false
console.log(array2.some(isPositive)); // true

2. Setting default value of a parameter

This one I also know.

function DoSomething(option) {
   // if option.firstOption is null / undefined, option_one value will be 'Default First Option'
   var option_one = option.firstOption || 'Default First Option';
}

3. Casting values in Arrays

This one is using map, which I am aware of its usage. But what I don’t know that is now shown below:

var array = ['1', '2', '3'];
var number_array = array.map(Number); // number_array is now [1, 2, 3]

4. Object destructuring

This one I don’t know. But somehow reminds me of C#’s Tuples

var obj = {
   param1: "Value 1",
   param2: "Value 2",
   param3: 3
};

var { param1, param2, param3 } = obj;

console.log(param1); // "Value 1"
console.log(param2); // "Value 2"
console.log(param3); // 3

5. Debug performance measure using console.time

This one I don’t know. You apparently can measure how long a method runs:

console.time('loop');
 
for (let i = 0; i < 10000; i++) {   
    // Do stuff here 
}  

console.timeEnd('loop');

Haha.. I exactly know 2.5 of the tricks here. Check out the link above for more detailed explanation.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Updates on travel advisory:

[Sent by Gov.sg]

COVID-19: Travel advisory as of 16 Mar 2359hrs

S’pore citizens and residents should defer all non-essential travel overseas

Incoming residents, long-term pass holders
14-day Stay-Home Notice (SHN): For all w travel history to Mainland China (excl Hubei), Republic of Korea, Iran, Italy, France, Germany, Spain, ASEAN countries, Japan, Switzerland, or UK, in last 14 days

Incoming short-term visitors
No entry or transit for those from Mainland China (excl Hubei), France, Germany, Italy, Iran, Republic of Korea, Spain

14-day SHN for those from ASEAN countries, Japan, Switzerland, UK

Residents in ASEAN countries must submit requisite health information; approval needed before traveling to S’pore

SHN will not apply to sea and land crossings with Malaysia

SHN also for all incoming travellers w fever/respiratory symptoms

Those on SHN:
– Must provide proof of SHN residence; remain there at all times for 14 days

– May undergo a swab test even if no symptoms

go.gov.sg/travel-15mar

Updates on confirmed cases:

[Sent by Gov.sg]

COVID-19: 15 Mar Update

As of 12pm:
New cases: 14
Total cases in Singapore: 226
Discharged today: 0
Total discharged: 105
Total remaining in Hospital: 121

Of the new cases, two are part of a known cluster, nine are imported cases, and three are linked to previous cases.

Most in hospital are stable or improving. 13 are in the intensive care unit – one less than yesterday.

Go.gov.sg/mar15moh

Correction on the previous announcement regarding travel advisory:

[Sent by Gov.sg]

Refer to this ver, earlier one had errors, SORRY!

COVID-19: Travel advisory

Defer all non-essential travel overseas

Measures from 16 Mar 2359hrs:
Incoming residents, long-term pass holders
14-day Stay-Home Notice (SHN): For all w travel history to Mainland China (excl Hubei), Republic of Korea, Iran, Italy, France, Germany, Spain, ASEAN countries, Japan, Switzerland, or UK, in last 14 days

Incoming short-term visitors
No entry or transit: For those from Mainland China, France, Germany, Italy, Iran, Republic of Korea, Spain

14-day SHN for those from ASEAN countries, Japan, Switzerland, UK

Nationals of ASEAN countries must submit requisite health information; approval needed before traveling to S’pore

SHN will not apply to S’poreans and M’sians at land and sea crossings with Malaysia.

Those on SHN
– Need proof of SHN residence; remain there at all times for 14 days;
– Swab test even if no symptoms

go.gov.sg/travel-15mar

Stay safe everyone!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Hi there! I am still slowly reading this book:

Today I reached a page where the book is explaining about collections. Among the types of collections available, I am intrigued that there is a namespace called System.Collections.Concurrent. Apparently, .NET now has a number of collection types under this namespace:

  1. BlockingCollection<T>
  2. ConcurrentBag<T>
  3. ConcurrentDictionary<TKey,TValue>
  4. ConcurrentQueue<T>
  5. ConcurrentStack<T>

Then I found out that it has been around since 2010!

It was introduced together with .NET 4, God darn it! It does make me feel like I’ve been living under a rock. I could have been using these classes instead of manually locking and waiting in my past projects. So in my attempt to catch up, these articles helped me to quickly understand these Concurrent Classes:

  1. ConcurrentBag<T> used to be slow, but Microsoft has fixed this
  2. When to use the new Concurrent Classes, and when to resort back to the classic manual locking and waiting
  3. Good introduction to Concurrent Classes
  4. Microsoft’s White Paper on the performance of Concurrent Classes
  5. Understanding what happen under ConcurrentBag<T>

That’s it for now. I’ll post more on this subject as I explore on their usage in real-life scenario.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: