teleren/devto huggingface dataset:
♻️ TypeScript function overloading
Tags: typescript, arguments, function, overload
Published: 2019-03-28 08:58:38

---
title: ♻️ TypeScript function overloading
published: true
description: 
tags: typescript, arguments, function, overload
---

In this example I used [ow](https://github.com/sindresorhus/ow) for runtime arguments type checking, but you can check yourself `typeof a === 'string'`

![Type completion](https://thepracticaldev.s3.amazonaws.com/i/5jf2px2bfllmr6mflkip.png)


```ts
import ow from "ow";

function myMethod(a: string): string;
function myMethod(a: number): number;
function myMethod(a: number, b: string): [number, string];
function myMethod(
  a: string | number,
  b?: string
): string | number | [number, string] {
  if (ow.isValid(a, ow.string) && ow.isValid(b, ow.undefined)) {
    console.log("function myMethod(a: string): string");
    return a;
  }

  if (ow.isValid(a, ow.number) && ow.isValid(b, ow.undefined)) {
    console.log("function myMethod(a: number): number");
    return a;
  }

  if (ow.isValid(a, ow.number) && ow.isValid(b, ow.string)) {
    console.log("function myMethod(a: number, b: string): [number, string]");
    return [a as number, b];
  }
}

console.log(myMethod(123));
// function myMethod(a: number): number
// 123

console.log(myMethod("Andrew"));
// function myMethod(a: string): string
// Andrew

console.log(myMethod(123, "Andrew"));
// function myMethod(a: number, b: string): [number, string]
// [123, "Andrew"]


```

Same is valid for classes

```ts
import ow from "ow";

class MyClass {
  myMethod(a: string): string;
  myMethod(a: number): number;
  myMethod(a: number, b: string): [number, string];
  myMethod(
    a: string | number,
    b?: string
  ): string | number | [number, string] {
    if (ow.isValid(a, ow.string) && ow.isValid(b, ow.undefined)) {
      console.log("function myMethod(a: string): string");
      return a;
    }

    if (ow.isValid(a, ow.number) && ow.isValid(b, ow.undefined)) {
      console.log("function myMethod(a: number): number");
      return a;
    }

    if (ow.isValid(a, ow.number) && ow.isValid(b, ow.string)) {
      console.log("function myMethod(a: number, b: string): [number, string]");
      return [a as number, b];
    }
  }
}

const myClass = new MyClass()

console.log(myClass.myMethod(123));
// function myMethod(a: number): number
// 123

console.log(myClass.myMethod("Andrew"));
// function myMethod(a: string): string
// Andrew

console.log(myClass.myMethod(123, "Andrew"));
// function myMethod(a: number, b: string): [number, string]
// [123, "Andrew"]

```

https://codesandbox.io/embed/l7k6p45589
Migrating desktop applications to the web app
Tags: discuss
Published: 2019-03-28 08:13:45

Hi, if you would have a desktop app and you will migrate it to the web app. What would you do?

We use the classic .NET framework, not .NET Core. We have many of god classes.

There are no documentation, meaningful variable names etc.

In this case, what would you do? Don't forget, desktop logic could be different than the web considering by their components usage.

Now, I'm working on a project like that. My main responsibility is migrating backend services to the web.

It will be a REST service for mobile and web projects.

How should I monitor what variable is doing?

Because of some variables named "a, a1, a2, a3", it should hard to monitoring in a god class.
Companies Are Using Magento 2 to Improve Their Online Business and So Should You
Tags: hiremagento2, developers
Published: 2019-03-28 06:51:05

---
title: Companies Are Using Magento 2 to Improve Their Online Business and So Should You
published: true
description: e-commerce websites are now keen to hire Magento 2 developer to avail the array of benefits of shifting over to the new version. We, at Rock Technolabs, offer the services of specialists who can develop your online business presence using this state-of-the-art platform. 
tags: hire magento 2,developers
---

The success tale of Magento as an e-commerce framework has been remarkable as it has supported thousands of e-commerce websites globally. The launch of Magento 2 has taken it a step further with functionalities that are far better than the previous Magneto. More and more e-commerce websites are now keen to [hire Magento 2 developer](http://rocktechnolabs.com/hire-magento2-developers) to avail the array of benefits of shifting over to the new version. We, at [Rock Technolabs](http://rocktechnolabs.com/), offer the services of specialists who can develop your online business presence using this state-of-the-art platform.

From fresh Magento 2 development to transfer to the new version, our developer team has the skill to enhance your business with the best that it has to offer. We generate advanced and result-oriented solutions as per your requirements and the industry vertical. We have created several e-commerce solutions on Magento 2 for various requirements and we ensure that your store is built with the best functionalities without performance issues or any faults. Our solutions are SEO compatible and can help you increase traffic. We make sure that you avail high-performance stores within your budget and the deadline.

Rock Technolabs has expert Magento developers to create lucrative e-commerce websites that can outrank your competition. We don’t just build attractive websites; we make sure that they are rock-solid when it comes to performance. Before starting your web development project, we do a thorough analysis to understand what exactly your website should feature. We prepare a comprehensive strategy to deliver the finest user experience to your traffic; to create better conversion rates.

We offer a wide-ranging array of design and development services for Magento 1 & Magento 2 platforms. Therefore, If you are looking to [hire Magento 2 developers](http://rocktechnolabs.com/hire-magento2-developers), our veteran Magento programmers would be pleased to help you.
My first open source: react-fetching-library
Tags: react, webapp, javascript
Published: 2019-03-28 06:12:00

---
title: My first open source: react-fetching-library
published: true
description: Simple and powerful fetching library for React.
tags: react, webapp, javascript
---

Zero dependencies (react, react-dom as peer deps)
TypeScript support

Check it out: https://github.com/marcin-piela/react-fetching-library
Docs: https://marcin-piela.github.io/react-fetching-library/

***feedback will be highly appreciated***
The first code grab I made
Tags: beginners, tutorial, node, opensource
Published: 2019-03-28 05:47:13

---
title: The first code grab I made
published: true
description: Grab Blogger & photos.google.com,etc Streaming link
tags: #beginners  #tutorial  #nodejs  #opensource
---



The blogger streaming link is a grab created with the javascript engine nodejs language

I was inspired to make a grab because when I studied and found the YouTube video channel [Wesbos] (https://www.youtube.com/user/wesbos/) which is the original origin of my wish to make grab take the video url on blogger.com

 ```js 
   // online example blogger 
  `https://khalis-khalis411.now.sh/?url=https://prikate09.blogspot.com/2017/10/all-ani-29-oktober-2017-413.html`

   //localhost mode blogger
   `http://localhost:3000/?url=https://prikate09.blogspot.com/2017/10/all-ani-29-oktober-2017-413.html`

   //online example cloudvideo.tv
  `https://khalis-khalis411.now.sh/cloudvideo?url=https://cloudvideo.tv/42xcdwiwamlh`
  
  //localhost mode cloudvideo.tv
   `http://localhost:3000/cloudvideo?url=https://cloudvideo.tv/42xcdwiwamlh`

   //online example photos.google.com
   `https://khalis-khalis411.now.sh/photos?url=https://photos.google.com/share/AF1QipMTEPAiVF8t0YqLukflnOSQjwfd8ARIoT2h37AXvYO1uaWodbeiFoBUDuD_19tEbg/photo/AF1QipPA2Bq0JlAR9LoGD3mogsxSb9OZWEG4XqBDD4Rv?key=cjhUT0xrZjM5NGN2SVRLOVptZU5SMUlKV0lQYWpB`

   //localhost mode photos.google.com
   `http://localhost:3000/photos?url=https://photos.google.com/share/AF1QipMTEPAiVF8t0YqLukflnOSQjwfd8ARIoT2h37AXvYO1uaWodbeiFoBUDuD_19tEbg/photo/AF1QipPA2Bq0JlAR9LoGD3mogsxSb9OZWEG4XqBDD4Rv?key=cjhUT0xrZjM5NGN2SVRLOVptZU5SMUlKV0lQYWpB`

 ```

> proxy mode
![](https://i.imgur.com/7TfqEUc.png)

> json mode
> ![](https://i.imgur.com/xETf6I7.png)

Repo : [khalis](https://github.com/khalisafkari/khalis/)
Day 6 Learning Javascript
Tags: beginners
Published: 2019-03-28 03:40:25

---
title: Day 6 Learning Javascript
published: true
description: A beginner's journey into Javascript
tags: #beginner
---

Hooray Arrays!!

That was corny but I don't care, because I just tackled Arrays in Javascript! But I'll admit, for some reason this one was tough for me. I understand the methods fine, such as *push*, *shift*, *pop*, etc. What I didn't understand was the Why, or rather the purpose of Arrays. I think I need to see it in a real use case on a website to put it all together for me.

Also, trying to find the index value in a multidimensional nested array was confusing as hell to me. But, I found a [great article](https://hackernoon.com/work-with-javascript-arrays-like-a-boss-97207a042e42) that really explains nested arrays in a very simple, understandable way. Plus, the article uses Simpsons and Lost characters as examples which is always a win in my book.
Let Serverless do the work !
Tags: ibm, serverless, cloudstorage, openwhisk
Published: 2019-03-28 01:36:02

---
title: Let Serverless do the work !
published: true
tags: ibm,serverless,cloud-storage,openwhisk
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/1*D4dVHU-MFrw5f7slTuFDMA.png)

One of my colleagues reached out to me to see if I can help automate a weekly status update task using Serverless and Slack bots. He currently has to download an excel file from a server every Monday at 9AM and provide stats to the team based on the contents of the file. This is a perfect opportunity to use **_periodic triggers_** and **_serverless actions_** to automate this mundane task ! I am using Apache OpenWhisk hosted on IBM Cloud Functions, but you can easily follow this same recipe on other serverless platforms.

The code is divided into two functions / actions

1. **_read-cos_** : reads the file from IBM Cloud Object Store and aggregates the stats that need to be shared with the team
2. **_post-slack_** : posts a message to a given channel on Slack

I finally create a sequence action composed of the above two actions. I then link a trigger that invokes this sequence every Monday at 9am ! Easy peasy !

The application uses the following solutions

- [IBM Cloud Storage](https://www.ibm.com/cloud/object-storage) to store the excel file
- [IBM Cloud Functions](https://www.ibm.com/cloud/functions) as the hosted version of [Apache OpenWhisk](https://openwhisk.apache.org/) to store our actions/functions
- [OpenWhisk CLI (WSK)](https://github.com/apache/incubator-openwhisk-cli) to create and test actions from the terminal
- [Slack API](https://api.slack.com/)

The [complete source is available on Github](https://github.com/lidderupk/serverless-cos-slack). Additionally, I have recorded a video that goes through the process. Take a look …

{% youtube \_NHrVbSV3uU %}

What are your automation stories with Serverless ? Please share in the comments below !

Thought of the day …

![](https://cdn-images-1.medium.com/max/673/1*zT90vzagNtTu9-YFHTrfcg.png)
Building a file sharing app with Node.js, Vue.js, Cloudinary, and MySQL - Part 3
Tags: node, vue, mysql, cloudinary
Published: 2019-03-28 01:31:34

---
title: Building a file sharing app with Node.js, Vue.js, Cloudinary, and MySQL - Part 3
published: true
description: Building a file sharing app with Node.js, Vue.js, Cloudinary, and MySQL - Part 3
tags: #node.js #vue.js #mysql #cloudinary
---

In this part, we will create our database and write some of the API that will power our application. Now, let's get started!

# Requirements

1. To follow along with this series, you need the following parts: [Part 1](https://dev.to/polymathwhiz/building-a-file-sharing-app-with-nodejs-vuejs-cloudinary-and-mysql-part-1-19l0), [Part 2](https://dev.to/polymathwhiz/building-a-file-sharing-app-with-nodejs-vuejs-cloudinary-and-mysql---part-2-32nl)

2. You will also need to create an account on [Cloudinary](https://cloudinary.com)

# Building our app

In our `connection.js` file, populate it with the following code:

 ![connection.js](https://thepracticaldev.s3.amazonaws.com/i/963bnaw40aajcihj1bem.png)


The code above handles our database connection parameters. 

Next, we create our application entry file `index.js` and our environment variable file `.env` in our application project root directory. We then populate our `index.js` with the following code:


![db connection params](https://thepracticaldev.s3.amazonaws.com/i/8bszpkok2cang82wuh9o.png)

In our entry `index.js` file, we imported the `express`, `cors`, `dotenv`, and the `cloudinary` packages. We also defined our cloudinary configuration parameters (which we will insert later in our `.env` variable file). Also, we defined our `404` and `500` HTTP response fallback routes, and then, we started our local server on port `3000`.

In our `.env` file, populate the following with your database configuration information and your cloudinary secrete that can be found on your cloudinary dashboard.

![alt text](https://thepracticaldev.s3.amazonaws.com/i/k09u3tw1vqs7sfiyaadf.png)

Replace all the value positions with your correct database and cloudinary configuration information.

## Creating our database

Our MySQL database schema will look like this. If you do not have a suitable MySQL database workbench, you can download [MAMP](https://www.mamp.info/en/)

![database structure](https://thepracticaldev.s3.amazonaws.com/i/9bmo48xafhtm2wbz52h2.png)



# Conclusion 

In this part of the series, we have created our database, populated our `index.js` and added our database and cloudinary configuration information. 

In the next part, we will be implementing the core API that will power our application.


The source code is also available on [GitHub](https://github.com/PolymathWhiz/shareable-api)

See you in the next part!
Do you tidy up your workspace when done coding?
Tags: vscode, editor
Published: 2019-03-28 00:30:29

---
title: Do you tidy up your workspace when done coding?
published: true
description: I don't believe i'm the only culprit. 
tags: vscode,editor
---

![Cleansing workspace](https://thepracticaldev.s3.amazonaws.com/i/3xzoqps3egzztongw4fx.gif)


At the end of each coding session, I close all open files and collapse all sidebar menus. 

When I open up my code editor for the next coding session, I easily get confused and distracted with all those open files etc.

'Cleansing' the workspace at the end of each coding session allows me to 'ramp' up to where I left off the previous time in style.

However, in the middle of implementing a feature/fixing a bug, I only put computer in sleep mode.

When done, with feature, pushes, CI builds, reflects on live, then the cleansing begins.

Anyway, do you clean your workspace after each coding session, or you just slam the laptop lid shut and you're done?
Visual Studio Tips - Breakpoints
Tags: vstips, csharp
Published: 2019-03-31 00:12:27

---
title: Visual Studio Tips - Breakpoints
published: true
tags: VSTips, csharp
canonical_url: https://hutchcodes.net/2019/03/visual-studio-break-points/
---

Most of us know about Breakpoints and how to use them, but there are a few under-utilized features of breakpoints that you should be aware of.

<!--more-->

You can set a simple breakpoint in a number of ways

1. Move the cursor to the line you want to break on and hit the F9 key
2. Right click on the line of code
3. Clicking in the gutter

Once you have a breakpoint set you can do a few things with it. First, you can disable it, if you don’t need the breakpoint right now, but think you might come back to it.

![alt text](https://hutchcodes.net/img/2019/BreakpointDisable.gif "Visual of disabling a breakpoint.")

You can also disable all breakpoints from Debug -\> Disable all breakpoint. This is handy for when you need to run and get reset, then re-enable all breakpoints and start your debugging again.

You can also make the breakpoint conditional based on the value of a variable or any boolean expression (yes, you can use the [No Side Effects](/2019/03/visual-studio-tips-no-side-effects-function-eval/) formatter). This can be helpful if you want to break when the value of a variable is a certain value.

![alt text](https://hutchcodes.net/img/2019/BreakpointConditional.gif "Visual of creating a conditional breakpoint based on a boolean expression.")

You can also make the breakpoint conditional base on the number of times a breakpoint is hit. For example, you might know that the first time a breakpoint is hit isn’t interesting to your debugging scenario but every time after that is interesting. You could set hit count \> 1.

![alt text](https://hutchcodes.net/img/2019/BreakpointHitcount.gif "Visual of creating a conditional breakpoint based on hit count.")

You can also filter your breakpoints to a single thread or to exclude a thread, either by name or id.
TIL: Package.json values are accessible in npm/yarn scripts
Tags: javascript, npm, yarn
Published: 2019-03-28 21:42:19

---
title: TIL: Package.json values are accessible in npm/yarn scripts
published: true
tags: javascript, npm, yarn
canonical_url: https://www.stefanjudis.com/today-i-learned/package-json-values-are-accessible-in-npm-yarn-scripts/
---

I came across [this tweet](https://twitter.com/JessTelford/status/1108531278846918657) by [Jess Telford](https://twitter.com/JessTelford/). He shared that you can reference values that are defined in your `package.json` inside of your npm/yarn scripts.

Let's have a look at an example.

```json
{
  "name": "my-package",
  "scripts": {
    "lint": "eslint ./src/*",
    "test": "jest ./src/*"
  }
}
```

What you see there is the duplicated definition of `./src/*` in two different scripts. For the case of these two scripts, the duplication might not be a big deal, but in larger projects, it can be way harder. I worked on projects that defined very complex scripts which were hard to read and maintain. In this scenario, you want to avoid any repetition.

[npm](https://docs.npmjs.com/misc/scripts#packagejson-vars) and yarn provide a nice feature to get around this problem. Inside of the `scripts` section of your `package.json` you can reference all the values that are defined. For example, the `name` property is available at `npm_package_name`. This behavior allows you to reuse values. 🎉

```json
{
  "name": "my-package",
  "config": {
    "src": "./src/*"
  },
  "scripts": {
    "lint": "eslint $npm_package_config_src",
    "test": "jest $npm_package_config_src"
  }
}
```

I think this very kind of npm/yarn and good to know.

## I released a package to read `package.json` values from the environment, too!

I continued reading the Twitter thread about this discovery and [Jordon Harband asked the questions](https://twitter.com/ljharb/status/1108590777930665984) if it would make sense to have the same behavior inside of Node.js files. I took a quick night coding session to make that possible with [npm-package-to-env](https://www.npmjs.com/package/npm-package-to-env).

Assuming you have a `package.json` as follows:

```json
{
  "name": "my-package",
  "config": {
    "foo": "bar"
  }
}
```

You can then require `npm-package-to-env`, run `config` and access the values via `process.env`.

```javascript
require('npm-package-to-env').config();
 
console.log(process.env.npm_package_name); // 'my-package'
console.log(process.env.npm_package_config_foo); // 'bar'
```

The `config` command reads out your `package.json` and makes the data available via `process.env`. Maybe you think that's useful, too. :)
California's new privacy law explained
Tags: privacy, security, architecture, policy
Published: 2019-03-27 23:40:40

---
title: California's new privacy law explained
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/6bmkxyqefgrjymn3hozx.png
description: CCPA is a seismic event for the tech industry. Entire business models will need to change (example: if you get access to someone's address book, you will no longer be able to do much with that data since you don't have the consent of the people in that address book). Software architects should understand the new privacy laws before building out something new.
tags: privacy, security, architecture, policy
---

The California Consumer Privacy Act takes effect on January 1st, 2020. But it has provisions that reach back to January 1st, 2019. If you’re a software developer or work for a software company, it’s reasonably likely that CCPA is going to impact your roadmap, your website, and existing or planned features in the near future.

This post originally appeared in Hacker Noon. [Read the whole post](https://hackernoon.com/ccpa-what-you-need-to-know-aede1acb792a) there.
Documenting your API
Tags: softwaredevelopment, api, development, pwnedpass
Published: 2019-03-27 23:20:41

---
title: Documenting your API
published: true
tags: SoftwareDevelopment,api,development,pwnedpass
canonical_url: https://www.funkysi1701.com/posts/documenting-your-api-4gcn
cover_image: https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2019/03/image-3.png?w=662&ssl=1
description: So you have created a super API that does something amazing. How do you document it so people will use it?
---

So you have created a super API that does something amazing. How do you document it so people will use it?

One way of easily documenting your API is to install the Swashbuckle package.

```
Install-Package Swashbuckle.AspNetCore
Install-Package Swashbuckle.AspNetCore.Swagger 
```

Then in you startup.cs add the following lines

```csharp
//In ConfigureServices

services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new Info { Title = "API", Version = "v1", Description = "An API Description" });
    c.IncludeXmlComments(string.Format(@"{0}\API.xml", System.AppDomain.CurrentDomain.BaseDirectory));
});

//In Configure

app.UseSwagger();

app.UseSwaggerUI(c =>
{
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
        c.RoutePrefix = string.Empty;
});
```

Now when you browse to your API you will see the swagger documentation system.

![Image](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2019/03/image-3.png?w=662&ssl=1)

The RoutePrefix setting controls the path in which swagger will display. I have my docs at the root, but you might want them under the /docs or similar path.

The IncludeXmlComments setting from the ConfigureServices method allows you to load in any XML comments you have added to methods. For this to work you need to enable a setting to your build.

![Image](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2019/03/image-4.png?w=662&ssl=1)

The XML documentation file must be ticked and contain a path. Everytime you do a build, a XML file will be generated which contains all the comment blocks you have added to your code.

![Image](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2019/03/image-5.png?w=662&ssl=1)

Swagger will then use this XML documentation file to produce lovely looking documentation without you having to do anything extra.

![Image](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2019/03/image-6.png?fit=662%2C260&ssl=1)