teleren/devto huggingface dataset:
5 ways to convert a number to string in JavaScript
Published: 2020-12-15 10:41:54

In JavaScript, you can represent a number as type number (ex. 12), or as a type string (ex. '12').But both are not same. At times while coding we might have to convert the data from one type to other and there are many ways to do that. I would like to list few of the methods I know of data conversion from number to string.

###1. Using .toString() method
There is a default string method that converts the data to string. The `toString()` method returns the value of a String object.
```
myNumber = 100
myNumber.toString() // expected result: '100'

noNumber = NaN
noNumber.toString() // expected result: 'NaN'

decNum = 122.33
decNum.toString() // expected result: "122.33"
```
###2. Using String()
The `String()` method creates a primitive String type for the number that is passed to it.
```
myNumber = 99
String(myNumber) // expected result: '99'

fltNumber = 25.54
String(fltNumber) // expected result: '25.54'
```
###3. Concatenating the Empty String
Adding empty string to the number value will convert the data to string is one of the simplest way to do the job. It is also considered to be faster than the above two when it comes to performance.
```
myNumber = 22
myString = '' + myNumber // expected result: '22'

fltNumber = 25.54
fltString = '' + fltNumber // expected result: '25.54'
```
###4. Template Strings
With the introduction of template strings in ES6, injecting a number inside a String is a valid way of parsing an Integer or Float data type. This is the fastest way to convert the number to string.
```
myNumber = 22
flt = 50.205;

string = `${num}`;      // expected result: '50' 
floatString = `${flt}`; // expected result: '50.205'
```
###5. Using toFixed() method
This is the least known method. But it can be little tricky with the decimal numbers.
```
myNumber = 22
myNumber.toFixed() // expected result: '22'

a = 56.9887
a.toFixed() // expected result: '57'
a.toFixed(4) // expected result: '56.9887'
```
[Here](https://i.stack.imgur.com/mPxVd.png) is the comparison of the methods  when it comes to the performance. Comment below if you know more ways.
Thank you
The cost of abstraction
Tags: architecture
Published: 2020-12-15 10:14:12

###### Credits to the image: [Dave Wolanski](http://davewolanski.blogspot.com/2007/01/it-was-dark-and-rainyfoggy-night.html)

Yesterday I was driving down the highway and it was very foggy. All along the highway, there were digital (variable) speed limit signs, which were showing a speed limit of 60km/h (instead of the default 130km/h) due to the bad road conditions.

And I thought to myself, how cool. The constructor of the highway decoupled the actual speed limit from the sign, just for cases like this. Now they have the flexibility to dynamically adjust the limit, based on the road condition. That was a very smart design choice!

The traditional solution would be to just place a metal sign, but this hardcodes the speed limit and cannot be easily changed (someone has to go to the sign, and place a new one in it's place, revert the change when conditions reset, etc.).

Does this mean all signs everywhere should be digital? Probably not. A digital sign can easily cost two orders of magnitude more than just a metal plate sign. And not to speak of the operating and maintenance cost.

<b>Every abstraction comes with its cost.</b>

The point of my post is to show that the same applies to software architecture. It would be great to have "digital signs" everywhere, decouple all of the things and have infinite flexibility. As much as it would be great to have a new Tesla with full equipment and all features unlocked. But do you have the budget to pay for the cost?

As much as we balance our budget when buying a new car, we as engineers should balance our budget for abstractions.

Knowing when and where in your product to invest in abstraction, like the digital road signs, and where to just place a metal hardcoded one can mean the difference between success and failure.

Where things need to change, invest in abstraction and layers. Where things are simple and static, go with the low cost solution. And if the simple thing starts getting complicated and changes frequently, THEN invest your budget in refactoring and abstraction. Your abstraction must provide more value than its cost, or else you are in trouble.

I would really like to hear your thoughts on this. How do you approach complexity and abstraction? Do you consider the cost of these abstractions?

Reading/listening material:
* https://news.ycombinator.com/item?id=19237592
* http://sam-koblenski.blogspot.com/2014/07/the-cost-of-abstraction.html
* https://www.youtube.com/watch?v=rHIkrotSwcc&ab_channel=CppCon
How can you do your custom implementation for events.
Published: 2020-12-15 09:16:29

---
title: How can you do your custom implementation for events.
published: true
description: 
tags: 
//cover_image: https://direct_url_to_image.jpg
---

I have been working on Node for quite some time and have extensively used Events. But never knew how it works internally until very recently.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7rlv6f2tztuecnr6ldea.jpeg)

### What are Events?
So basically, when something happens in your app like a user gets logged in, you fire an event to notify everybody listening to that event, that a user has logged in.
```javascript

function login(data) {
    // fires an event
    CustomEvent.emit('user_logged_in', data);
}

function someOtherFunc() {
    // event listeners
    CustomEvent.subscribe('user_logged_in', function(data) {
        // do some operation
    })
}

```

### Events Implementation
The Event class that we are designing will have the following methods:
- emit - It fires an event, with an event name and data.
- subscribe - It subscribes to the event and gets executed every time the given event is fired.
- unsubscribe - It will unsubscribe the function from the event.
- unsubscribeAll - It will unsubscribe all the functions listening to that event.

```javascript
/**
 * Disclaimer: This is not a production-quality code, lots of checks are not in place.
 */
function CustomEvent() {
    // listers is an object
    // it will be a map of event_name
    // and all the functions subscribing to it
    this.listeners = {};
}

CustomEvent.prototype.subscribe = function(eventName, someFunction) {
    // checks if eventName exists
    // if doesn't initialise a new array
    // else push the function to the existing array
    if(!this.listeners[eventName]) {
        this.listeners[eventName] = [someFunction];
        return;
    }
    this.listeners[eventName].push(someFunction);
}

CustomEvent.prototype.emit = function(eventName, data) {
    // gets the event name
    // and loops over all the functions that it has to call
    const listeners = this.listeners[eventName];
    listeners && Array.isArray(listeners) && listeners.map(listenr => {
        listenr.call(null, data);
    })
    
}

CustomEvent.prototype.unsubscribeAll = function(eventName) {
    this.listeners[eventName] = undefined;
}

CustomEvent.prototype.unsubscribe = function(eventName, someFunction) {
    
    const funcs = this.listeners[eventName];
    
    const filteredFuncs = funcs.filter(func => func.toString() !== someFunction.toString());
    
    this.listeners[eventName] = filteredFuncs;
    
}
```


If you guys have a better implementation for unsubscribing in mind, please suggest.
Keep coding. Keep learning.
Thanks.
How I can retrieve aws lambda cloudwatch logs in txt format so I can serch on them?
Tags: help, aws, cloudwatch, lambda
Published: 2020-12-15 10:06:04

As I ask below:
https://devops.stackexchange.com/q/12978/4396

I need to analyze the logs generated in cloudwatch. Therefore I want them to be downloaded as txt format. Do you know how I can do that?
The ...spread operator and the rest parameters
Tags: javascript, webdev, beginners
Published: 2020-12-15 09:49:13

#**Spread operator**
As the name suggests the spread operator spreads or expands an iterable such as an array or string into individual elements.

#**Few use cases**
* Adding elements of one array to new array.
* Passing an array as argument to a function.
* Array concatenation.
* Array copy.

##Adding elements of one array to new array
```
var arr1 = [3,4,5];
var arr2 = [1,2,...arr1,6,7];
console.log(arr2); // output -> [1,2,3,4,5,6,7]
```

##Passing an array as argument to a function
```
function addAll(a,b,c,d){
console.log(a+b+c+d); // output -> 10
}
var arr = [1,2,3,4];
addAll(...arr);
```

##Array concatenation
```
var arr1 = [1,2,3];
var arr2 = [4,5,6];
arr1 = [...arr1,...arr2];
console.log(arr1); // output -> [1,2,3,4,5,6]
```

##Array copy
```
var arr1 = [1,2,3,4];
var arr2 = [...arr1];
console.log(arr2); // output -> [1,2,3,4]
```

#**Rest parameters**
The rest parameter syntax allows us to represent an indefinite number of arguments as an array.
```
function findProduct(...args){
var result = 1;
args.map((arg)=>{
result = result * arg;
});
return result;
}

console.log(findProduct(2,4,6)); // output -> 48
```

#**Points to take away**
* Spread operator unpacks an iterable into individual elements.
* Rest parameter collects multiple individual elements and packs them into an array.
Come to the Dark Side : We have COOKIES !!!
Tags: chromeextension
Published: 2020-12-15 09:42:47

Come to the Dark Side : We have COOKIES !!!



This is in one way or another shown on every website at the moment since tracking and privacy are becoming more and more important.



If you want to learn of a nice and fast way to check the cookies of a website and how to play with them check the below 5 minute video

https://www.youtube.com/watch?v=zOZ7KUxmGkI&feature=youtu.be
EDB to PST Converter Tool to Archieve file in EDB to PST
Tags: edbtopst, edbtopstconverter, convertedbtopst
Published: 2020-12-15 09:32:54

If you want to convert EDB files to PST in offline and online both mode then here I would like to inform you about this professional EDB to PST Converter Software that can easily convert all the EDB file to PST in offline and online mode. 

With this EDB to PST Converter you can easily convert multiple EDB files to PST at once. It allow the users to convert EDB file selectively which save lots of time and effort. 

It allow the users to save converted EDB files to EML, PST, MSG, PDF, RTF and HTML format. It also export EDB file to Live Exchange Server and Office 365 without any hassle. 

It provide free demo version that help the users to check all the features and functions without any cost. 

For more details and information please visit :- https://www.recoverfilesdata.com/exchange-edb-pst-converter.html
What is Kubernetes?
Published: 2020-12-15 09:24:07

Heyy guys!!
Am aspiring to be a MERN Stack Developer.
Last night , a thought striked me about Kubernetes
I have heard it but never researched on it 
for what it is used?
I will be grateful if someone explains me and like give me some resources too as I just know that's its related to some web and cloud stuff
Functions in Javascripts
Tags: javascript, functional, higherorderfunctions
Published: 2020-12-15 09:07:34


Functions are the heart of JavaScript and functions are the beautiful parts of JavaScript.

Well , Functions are the most important part of JavaScript and in this blog I am not going to cover functions in detail instead I will be explaining hell lot of Jargons which will be beneficial for the Interview .

* Function statement : Function statement is nothing but how we write the functions in JavaScript.
example :

`function fun(){
// some code
}`
* Function Expressions : Well its a confusing one when we allocate a function to a variable then it is called as function expression.
example : 
`
const a = function(){
//code 
}
a();
`

**here function acts like a value**

* Function Declaration : Function declaration is nothing but a simple function definition .
example :
`
function fun(){ // some code }
`

* Anonymous function : Function without a name is called anonymous function .

example :
`
let fun = function(){ // some code }

fun() ;
`

*  Named function expression : These are same as function expression .
 example :

` const a = function () {//some code } `

* Function Parameters: Function parameters are the identifiers that function take on its declaration . Take a look at example below .

example :

` function app(param1 , param2 ) `

* Function arguments : Function arguments the identifiers that are supplied, when we call function.

` function app(param1 , param2 ) 
app(arg1, arg2)`

* First class functions : First class functions are those functions which can be passed as arguments to another function , function which can return another function and assign a function to a variable . So combination of all the above functions are said to be higher order functions .

If you like it please give it a thumbs up .




> source - youtube and mdn docs
Back to start again - Week 5
Tags: learning, webdev, react
Published: 2020-12-15 09:01:09

*Hey guys!!* Again I am back with my learnings of **Week 5**. You can see my *previous week blogs* (*[Week 1](https://dev.to/riyaagrawal17/back-to-start-again-2gja) , [Week 2](https://dev.to/riyaagrawal17/back-to-start-again-2gja) , [Week 3](https://dev.to/riyaagrawal17/back-to-start-again-week-3-41da), [Week 4](https://dev.to/riyaagrawal17/back-to-start-again-week-4-51d3)*) to see the improvement in my journey of starting again from basics.



Last week , I was a little off from my studies and hence could not complete my weekly goals on time. But finally did it!!




This week I learnt about the *sync vs async, callbacks, promises, routing* from **[React Documentation](https://reactjs.org/docs/getting-started.html#learn-react)** and the **[sessions](https://www.youtube.com/channel/UCDgDpLyyUII3tko2ECrekzw)** organised by our mentors.



And using the react concepts I have made two mini projects i.e. an *[Image Generator](https://vs7oq.csb.app/)* and finally completed my *[portfolio]( https://28v6o.csb.app/)*. This portfolio code can be used as a **template** by anybody, if you need to update any info , it can be just done by replacing/updating the data file. 



I know, you might be thinking that how much time I took to complete my portfolio project but by this project , I understood various *concepts of react*. I have faced many difficulties also but with the help of our mentors and peers, overcomed them.



I am really **thankful** to *[Frontbench community](https://twitter.com/frontbenchHQ)* for providing me this great *opportunity*. *I learn everyday, became consistent, started learning in public, and many more, this all started after joining this community*.



I am following all the *basic* and *necessary* steps to become a **successful Software Engineer**. *Please stay tuned with me* for further updates in this **beautiful journey**.





*You can follow me* on **[Twitter](https://twitter.com/RiyaAgr02106010)** or *connect with me* on **[LinkedIn](https://www.linkedin.com/in/riya438/)**.
Wallpaper Challenge!
Tags: discuss, watercooler
Published: 2020-12-15 08:42:21

Hey Everyone :)
__Banji__ is here O:
I missed the dev community soooooooooo much that I can't explain :(

So, I decided to make a new challenge to have some fun with some of those who are interested in challenges.

#DOS 👇:
### ✅ Put a download link for original quality✅


#DONT'S 👇:

### 🚫 Celebrities Wallpaper 🚫
### 🚫 Just Color Wallpaper(eg. Only black) 🚫
### 🚫 Nude Wallpaper 🚫

__Note🔅__: If you like introduce some great resources for cool and different wallpapers and I'll add to this post later.

I'm starting as a first participant :) 

__1. Rick Sanchez(My fav one)__
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gedqyy5fyqwtofshcxob.png)<figcaption>__[Download me](https://wallpapersden.com/rick-in-rick-and-morty-wallpaper/3840x2160/)__</figcaption>

__2. Forest Minimalist(My current desktop wallpaper)__
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b5srot2exfl936mpphas.jpg)<figcaption>__[Download me](https://wallpaperaccess.com/download/forest-minimalist-4502413)__</figcaption>

__3. Fox and Forest Minimalist__
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/oqoyt5wvft3zp00072pd.jpg)<figcaption>__[Download me](https://wallpaperaccess.com/download/forest-minimalist-3668745)__</figcaption>
How to automatically delete file after 7 days
Tags: cronjob, filetruncate
Published: 2020-12-15 08:28:43

below is the command to delete file which is created more than 7 days ago.
```
find /home/system/backup/gitn_sdn_berhad/* -mtime +7 -type f -delete
```
then we put it inside crontab like below:
```
0 0 * * * find /home/system/backup/gitn_sdn_berhad/* -mtime +7 -type f -delete
```
your should only store latest 7 days of files after this cron is running.


ref: https://askubuntu.com/a/789637/591250
Java: Benefits & Drawbacks
Tags: java, javascript, programming, github
Published: 2020-12-15 08:26:30

What is Java?

Java is considered to be a programming language that happens to be object-oriented, class-based, and general-purpose. Usually, the applications in Java are compiled to byte codes, which can operate on any JVM (Java virtual machine). Although Java’s syntax is identical to that of C and C++, it comes with lesser low-level facilities compared to both of them.

According to GitHub in 2019, Java happens to be among the most popular programming languages out there and has been used mainly for client-server side applications with more than 10 million registered developers.

Java was introduced in 1995, and it has turned out to be one of the best options for developing software or applications since then. It is employed for designing applications for Middleware products, Embedded systems, Web servers, and Scientific applications.

 
Benefits of using Java

 The benefits of using Java development services are mentioned in the following paragraphs.

    Simple – Compared to other programming languages, it is much simpler to use, write, debug, compile, and learn Java. It is simpler because it makes use of garbage collection and automatic memory.


    Object-oriented – Java is considered an object-oriented language related to objects, classes, abstraction, polymorphism, inheritance, and so on, which enables us to develop modular programs.

    Safe – Java is a programming language that provides optimum security. Its interpreter, compiler, as well as a runtime environment, has been developed with safety in mind.

    Perform-independent – Java provides the facility of writing a program once which can be run on any platform and any browser that is Java-compatible. Thus, we can quickly move it between different computers.

    Distributed computing – Java comes with remarkable networking capability. Java has been designed so that distributed computing becomes quite simple with networking capability, which is included in it.

    Multithreaded –It is possible to perform several tasks simultaneously using Java.

    Robust – Java happens to be an extremely robust and reliable programming language. Its compilers will be able to identify errors in coding without any problem whatsoever. Other features such as garbage collection and exception handling help to make Java quite robust.

 
Drawbacks of using Java

    Performance – Although it is simple to use Java, it is not reflected in its performance. It can use a lot of memory and is relatively slow as compared to other compiled languages.

    Memory management – Memory, in Java, is managed to employ garbage collection. The application’s performance is affected once the garbage collector functions. The reason for this is that it is imperative to stop all other threads to allow the garbage collector thread to function.
 
    Appearance and feel – The job applications’ deferred appearance is entirely dissimilar to the native appearance.
It's about feedback loops
Tags: devops, agile
Published: 2020-12-15 08:12:26

The [Agile Manifesto](https://agilemanifesto.org/principles.html) opens with _“Our highest priority is to satisfy the customer through early and continuous delivery of valuable software”_. Everybody would agree this is something hard to accomplish without **feedback loops**: getting positive or negative input back to the development process, as soon as possible.

DevOps culture offers us some guidance: [working in small batches](https://cloud.google.com/solutions/devops/devops-process-working-in-small-batches) will shorten our feedback loops. However, this is easier said than done.

Step by step then. Let’s define each stage of the development process from the point of view of feedback loops: 

![feedback loops](https://dev-to-uploads.s3.amazonaws.com/i/dsr0jfx2kqp9illloygy.png)

* **Testing** my implementation is a feedback loop with **myself**. _Is my code doing what I meant it to do?_ No need to go into details here, I am sure all of us write tests, right? 😉 

* **Continuous integration** is a feedback loop with **my team**. _Is my code, merged with my colleagues' code,  working as we expect it to?_ We can speed up this loop doing [trunk-based development](https://cloud.google.com/solutions/devops/devops-tech-trunk-based-development) or at least creating code branches that will be merged within the same day. 

* **Continuous delivery** is a feedback loop with **other teams and systems**. _Is my code working as expected in production-like environments?_ DevOps culture and its [continuous delivery practices](https://cloud.google.com/solutions/devops/devops-tech-continuous-delivery#implementing_continuous_delivery) comes to the rescue again!

* **Continuous deployment** is a feedback loop with **my customers**.
_Is my code delivering the features my customers want?_ This question can be easily answered if you are working on a matured software product in which adding a new feature can be done fast and painlessly. It is much more complicated, though, if you are working with legacy code (for obvious reasons) or if you are starting a brand new product and, caught up in the excitement of adding more and more features, you fail to identify the ones that would close this feedback loop sooner.

In software development there are other aspects to consider, of course. But it might be worth taking a moment every now and then and ask yourself how you can shorten the feedback loop you are in.

Maybe this way you will not leave writing tests for later; you will not have a code branch opened for a week; you will not do a full rewrite to improve some software; or you will realize that reducing the scope of this new service you are working on will speed up delivery a lot. Been there 😉

[![Ofertas](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwgpljha8oivwg2e6tfu.png)](https://careers.adevinta.es/ofertas/?stc=aff-blog%20dev.to-it%27s%20about%20feedback%20loops)
How to withdraw Cash app money with Cash card from ATM?
Published: 2020-12-15 07:23:49

Yes, you will become happy to know that you can use Cash Card to withdraw Cash app balance from ATM in simple steps. One more good news is that user can withdraw money from any certified bank without any issues 24*7. All the verified users are eligible to get a decent Visa debit card.

Cash app card work as same as the other bank card does and it is secured by an entry PIN. Your all information is encrypted into the embedded microchip.

What the limit to withdraw money from ATM?

Here, we mentioned the limit for every user to withdraw money from the ATM. Go with the below details:

❏	Only $250 per transaction
❏	$1000 in 24 hours
❏	$1000 in 7- days period
❏	$1250 in 30- days period

Generally, a bank doesn’t offer any cashback for using their debit card, but Square app does. Square app offers cashback to the user for the regular use of a Visa debit card. One thing, you have to point, that whenever you are going to check balance on ATM, then you will see $0.0 on the screen. So, you have to check it on your mobile phone.

Conclusion:-  In this post, we talk about can you put money on a Cash app card at an ATM. If you have any doubts, then contact our tech support team to get tech solutions.

https://www.gonetech.net/can-i-load-cash-app-card-at-walmart/