Posts

Showing posts from 2021

Experiment #1: Can JavaScript run something like a concurrent thread/process? No.

So, I know it is stated frequently that JavaScript is "a single-threaded" language. But it is non-blocking thanks to Web APIs. However, I was thinking whether it means that we can run something concurrently like in some other languages like Java, Go, or Python. I mean ES6 includes Promises and it was enhanced by async-await. So, is it possible to make use of Promises to run multiple things in the same time? It was fairly a simple experiment. All you need is A function that acts as a Promise (an async function), A method that will be run as a Promise and as a synchronous function, and A "container" function that holds both async function and plain function. With that three method in mind, this is the code that I came up with. function timelapse ( id ) { for ( let i = 1 ; i <= 1 _000_000; i++) { if (i % 500 _000 === 0 ) { console .log( ` ${ new Date ().getTime()} ${id} ` ); } } } async function asyncFunction ( id ) {

Ruby on Rails Time, Date, DateTime Cheatsheet

Rails has a lot of handy methods built-in that sometimes all you have to do is know it. In consequence, there are an overwhelming methods available to get specific time and/or date. This cheatsheet should provide some practical methods for Time, Date, DateTime that may help you in developing with Rails. I have also included an example output of each method so you don't have to manually enter it in rails console to know what the outcome would be. Here is a brief overview of what methods will be covered in this cheatsheet. Feel free to skip to the methods that you need or scroll around to know what methods there are. Maybe it will help you in the future. Enjoy! Current time and date ( now , current , today ) Specific day ( yesterday , tomorrow ) Specific moment in time ( beginning_of_minute , end_of_minute , beginning_of_hour , end_of_hour ) Specific time of the day ( beginning_of_day , middle_of_day , end_of