teleren/devto huggingface dataset:
Explicit error messages with VError
Tags: javascript, node, webdev, npm
Published: 2019-03-21 15:54:25

---
title: Explicit error messages with VError
published: true
description: How to use VError to generate explicit and useful error messages
tags: javascript, node, webdev, npm
cover_image: https://thepracticaldev.s3.amazonaws.com/i/8e5wm4icxymwlci3caiq.jpg
---

Today I will present you one of my favorite NPM modules. [VError](https://www.npmjs.com/package/verror) makes your errors more explicit.

I will not expose all the features here and just explain why I think this module is very useful. So don't hesitate to read the official documentation [here](https://www.npmjs.com/package/verror)

The thing I like with VError is the feature of building a composite error message through all applicative layers the error goes through.

Let see an example :

```js
const VError = require('verror')

function model(json) {
  return JSON.parse(json)
}

function controller(json) {
  try {
    model(json)
  } catch (err) {
    const error = new VError(err, 'Model fail to parse json')
    throw error
  }
}

function routeHandler(rawJSON) {
  try {
    const data = controller(rawJSON)
    return data
  } catch (err) {
    const error = new VError(err, 'Controller fail to use json')
    throw error
  }
}

routeHandler('invalid json')
```

This script will generate the following error message : 
`VError: Controller fail to use json: Model fail to parse json: Unexpected token i in JSON at position 0`

This is much more explicit to see than : `SyntaxError: Unexpected token i in JSON at position 0`

Also you can add some contextual information for each VError layers and get them at the end with the `VError.info()` function see documentation [here](https://www.npmjs.com/package/verror#verrorinfoerr)

Examples : 
```js 
const error = new VError({
  name: 'SERVICE_UNAVAILABLE',
  info: { json: rawJSON },
  cause: err,
}, 'Controller fail to use json')

console.log(VError.info(error)) // { json: 'invalid json' }
console.log(error.name) // SERVICE_UNAVAILABLE
```

Let me know in the comments if you use it already or if you will in the future and what are your feedbacks about VError.
Release: Function::Interface
Tags: perl
Published: 2019-03-21 11:46:43

---
title: Release: Function::Interface
published: true
description: In Perl5, I implemented a Java-like interface
tags: perl
---

I'm developing [Function::Interface](https://github.com/kfly8/p5-Function-Interface), this module provides a typed interface like Java interface.
**At compile time**, check if the abstract functions are implemented.

You can see the demo in the following capture:

[![asciicast](https://asciinema.org/a/235220.svg)](https://asciinema.org/a/235220)

# USAGE

Declare typed interface package IFoo:

```perl
package IFoo {
    use Function::Interface;
    use Types::Standard -types;

    fun hello(Str $msg) :Return(Str);

    fun add(Int $a, Int $b) :Return(Int);
}
```

Implements the interface package IFoo:

```perl
package Foo {
    use Function::Interface::Impl qw(IFoo);
    use Types::Standard -types;

    fun hello(Str $msg) :Return(Str) {
        return "HELLO $msg";
    }

    fun add(Int $a, Int $b) :Return(Int) {
        return $a + $b;
    }
}
```

It is good not to depend on the implementation:

```perl
package FooService {
    use Function::Interface::Types qw(ImplOf);
    use Function::Parameters;
    use Function::Return;
    use Mouse;

    use aliased 'IFoo';

    fun greet(ImplOf[IFoo] $foo) :Return() {
        print $foo->hello;
        return;
    }
}
```

```perl
my $foo_service = FooService->new;
my $foo = Foo->new; # implements of IFoo

$foo_service->greet($foo);
```

# How it works

To explain briefly

1. The keywords `fun` and` method` for declaring abstract functions are implemented in [Keyword::Simple](https://metacpan.org/pod/Keyword%3A%3ASimple) and [PPR](https://metacpan.org/pod/PPR). [B::Deparse](https://metacpan.org/pod/B%3A%3ADeparse) shows that it stores meta information of abstract functions.

2. In order to check whether the interface is correctly implemented, the stored interface meta information is compared with the implementation meta information that can be obtained using [Function::Parameters](https://metacpan.org/pod/Function%3A%3AParameters) and [Function::Return](https://metacpan.org/pod/Function%3A%3AReturn).

# Finally

Have you ever experienced the software becoming bigger and less maintenance? In such a case, I think it is important to divide the code, make it easy to change, and make code easier to read.

In order to divide the code, I think the interface is useful.
Please try it!!

Thanks.
await Promise.all: not just for async functions
Tags: node, asynchronous
Published: 2019-03-21 15:25:54

---
title: await Promise.all: not just for async functions
published: true
description: Thinking about Promises in Node.js
tags: node, asynchronous
---

In our code we end up making a lot of asynchronous, independent calls to 3rd party and internal REST APIs in order to build up among other things, currency conversion rates, Airport IATA Code -> Name mapping and getting a result set for a user's Flights search.

This led to a lot of head-scratching about how to improve speed, we needed all these calls to resolve before we could continue, but because they were all independent did we need to wait for each Promise to resolve before we could invoke another?

In short: no, we could use Promise.all to invoke all our independent asynchronous calls at once, and await them all to have resolved, not worrying about which resolves first:

```
const [
 conversionRates,
 airports,
 flights,
] = await Promise.all([
 getConversionRates(),
 getAirports(),
 getFlights()
]); 
```

Brilliant! We're waiting once, for the longest process to resolve and gathering all out data in one go.

But we still have some synchronous calls later one which again, are independent, non-mutating functional code. Could we do the same thing there?

Yes was the answer, with a bit of fore-thought about grouping functions together and making sure our code was fully functional in design, we are able to use Promise.all to await the results of multiple functions regardless of whether they are defined as `async` or not.


- Write functional, independent synchronous and asynchronous Javascript functions
- Run groups of them simultaneously using Promise.all
- Await for all the functions to resolve, rather than one at a time
- ???
- Profit
Do Not Overthink Ruby
Tags: ruby
Published: 2019-03-21 17:07:27

---
title: Do Not Overthink Ruby
published: true
tags: ruby
canonical_url: https://scottw.com/s8h
---

I was reading through the Ruby regex docs trying to figure out how to iterate over a string and replace all the matches of a particular pattern.

<!--more-->

The tricky part is the matches are not one to one (not just a find and replace). I tried a bunch of different things and then started wishing `gsub` took a block….turns out it already does this.

Example:

```
"1234".gsub(/\d/) {|i| i.to_i * 2} # 2468

```

Even better, it handles all substitution

```
"Square this number: 5".gsub(/\d/) {|i| i.to_i * i_to_i}
# Square this number: 25

```
Using setValue and patchValue
Tags: angular, forms, javascript
Published: 2019-03-17 19:44:37

---
title: Using setValue and patchValue
published: true
description: 
tags: angular, forms, javascript
---

In this blog post, we will see that when building Reactive Forms, if we need to update the input elements on the form from our component class, we use setValue and patchValue.

If you are new to Reactive Forms, I would recommend you to go through this article: Reactive (Model-Driven) Forms

We use setvalue to set the value of every form of control on the form. For example, here we have three form control in our form model. And now because we want to update the value of each one of these, we use setValue.

https://gist.github.com/NishuGoel/1a9560e14952e58ae56f0446ad0b3de1

However, if we only want to set the subset of the values, we then use patchValue. In this example, we set only of the three values.

https://gist.github.com/NishuGoel/2f2bc061482279b1ea22de793d8e84f8

Let us try our hands on it now!

In the component template, Let us take a button to check the data like this:

https://gist.github.com/NishuGoel/2f4e81a846bc2fde5b7c9b62f3c96360

Now let us take this method inside the component.ts file.

https://gist.github.com/NishuGoel/932a0c47a2c6121415063bd04606c8e2

Now when we check this in the browser, it populates the data in the browser as:

Value {“name”: “Wilson”, “city”: “Bangalore”, “email”: “wilsondcousta@gmail.com”}
In case, in the checkData() method, we do not set the value of name and email and set it just for the city, like this:

this.myForm.setValue({
 city: ‘Gurgaon’
})
In this case, the console throws an error like:

https://thepracticaldev.s3.amazonaws.com/i/znyf66jnw2io6ag7lff1.PNG

To solve this, simple solution!
We use patchValue, since we are making a change to only a subset of the form element and not all the elements of the form.

In place of the above code, we will write:

this.myForm.patchValue({
 city: ‘Gurgaon’
})
And then, it works well.
Is it just me or are we in a low-hype phase?
Tags: discuss
Published: 2019-03-21 12:59:37

Software goes through a lot of hype cycles: New frameworks, NoSQL, Blockchain, etc.

But it seems to me like we’re in a period without so much hype in general, which is nice.

There’s some hype around Typescript in the JS community, but given that TS is a maturing technology, it doesn’t quite feel the same.

There’s still ML hype but it seems to have settled down. Same with containers.

JAMstack is hyped right now, but it doesn’t seem _overly_ hyped per se.

The waters seem relatively calm, unless I’m missing something.
Angular Finland: The Big Hangout
Tags: angular, javascript, conference, webdev
Published: 2019-03-21 11:47:16

---
title: Angular Finland: The Big Hangout
published: true
description: Angular Expert Sam Julien recaps The Big Hangout, an Angular conference in Finland featuring seven international speakers on different topics.
tags: #angular #javascript #conference #webdev
canonical_url: https://auth0.com/blog/angular-finland-big-hangout/
---

I was honored to get to speak at The Big Hangout 2019, a mini-conference put on by Angular Finland on March 14, 2019. The conference was hosted by Tieto in Espoo, just next to Helsinki. It was also sponsored by other Finnish tech companies like Frantic, Finitec, Gofore (who hosted the after party), and Innofactor (who graciously sponsored my travel other there!).

[Read on 🅰️🎡](https://auth0.com/blog/angular-finland-big-hangout/?utm_source=dev&utm_medium=sc&utm_campaign=angularfi_hangout)

![Angular Finland: The Big Hangout](https://thepracticaldev.s3.amazonaws.com/i/4k2kskilf6wm6zuhu24v.png)
WordPress & Vue.js: Headless Stack w/ WP REST API
Tags: javascript, webdev, tutorial, vue
Published: 2019-03-21 18:03:09

---
title: WordPress & Vue.js: Headless Stack w/ WP REST API
published: true
tags: javascript, webdev, tutorial, vue
canonical_url: https://snipcart.com/blog/wordpress-vue-headless
---

![Build a Vue.js SPA on Top of Headless WordPress](https://snipcart.com/media/204208/wordpress-vue.png)

I can’t believe I’m about to write about WordPress again. 

I’m only (half) kidding, as [the last time](https://snipcart.com/blog/reactjs-wordpress-rest-api-example) I played around the WP REST API, I thought it was actually pretty dope!

It was a real breath of fresh air to see a mammoth of the web industry opening up to modern trends and new paradigms.

![wordpress-headless-change](https://snipcart.com/media/204213/wordpress-change.gif)

So I wondered: how fun would it be **to use WordPress as a headless CMS with Vue.js**&mdash;my beloved frontend framework?

The answer? A whole d*mn lot of fun, as it turns out. In this post, I want to go further in-depth with that stack. 

In the technical tutorial, I'll cover the following steps:

1. Creating models with custom fields in WordPress
2. Building a custom endpoint for the WP REST API
3. Setting up a Vue.js single-page application
4. Hosting the app

**First, let’s define “using WordPress as a headless CMS.”**

[Full on JAMstack](https://snipcart.com/blog/jamstack) stuff here! <3

  

→ Read the full post [here](https://snipcart.com/blog/wordpress-vue-headless)
Securing environment variables with lastpass
Tags: security, lastpass, shell, osx
Published: 2019-03-21 10:26:01

---
title: Securing environment variables with lastpass
published: true
description: Load environment variables securely using lastpass
tags: security, lastpass, shell, osx
---


One thing I've struggled with in the past is where to put your secret tokens that you need for accessing an API. If you stick it in a .env file then anyone with access to your machine will be able to read it. If you paste it into your shell then it will appear in your shell's `history`. Yes you can use pbpaste but then you need to have the token somewhere else to copy before you paste it. I think I've stumbled onto the best way to solve this - the [lastpass cli](https://github.com/lastpass/lastpass-cli) and a [script](https://github.com/luketurner/lpass-env) for loading the content of a secure note.

Let's get on with it. 

The first thing to do is to install the lastpass cli. Assuming you're using a Mac you can install it with brew. If you're not using a Mac there are other installation methods in the lastpass cli docs.

```
brew install lastpass-cli
```

You'll be able to log into lastpass in your shell by executing `lpass login <username>` and then following the prompts.

Next we install the script to your `/usr/local/bin` and make it executable. You should go have a read of the script and make sure you trust it before doing this step. It's very nicely laid out, and hopefully you can understand it enough to trust it.

```
curl https://raw.githubusercontent.com/luketurner/lpass-env/master/bin/lpass-env -o /usr/local/bin/lpass-env && chmod +x /usr/local/bin/lpass-env
```

Now head over to lastpass and create a folder called `.env`. I've called it this but in reality you can call it whatever you want. I like the idea of having all your scripts in the one folder so that you know where they are. The next thing to do is to create the first script. I've created one called `github` that has the following content:

```
GITHUB_TOKEN=MYMAGICTOKEN
```

Executing the following will load an environment variable called `GITHUB_TOKEN` with the value `MYMAGICTOKEN`

```
$(lpass-env export .env/github)
```

Amazing, right!?

Since I'm lazy and I have also added the following function to my `.zshrc` - it should work with your `.bashrc` as well.

```
function loadcreds() {
    $(lpass-env export .env/$1)
}
```

Now I can exec `loadcreds github` and it will load the credentials for me.
I got the job 💃
Tags: beginners, discuss, career
Published: 2019-03-21 09:29:15

---
title: I got the job 💃
published: true
description: This is an update to the previous article I wrote about my first tech interview experience. 
tags: beginners, discuss, career
cover_image: https://thepracticaldev.s3.amazonaws.com/i/w9rsbj3u3hik6xonsyuw.jpg
---

This is just a follow-up to the post I wrote a while back.

{% link sduduzog/i-went-to-my-first-interview-it-was-terrifying-dpe %}

After that first interview, I went to another a few days later and got an offer from the second company on the spot. What I immediately got from that was, an interview goes both ways. As much as they are assessing you, you also have to be assessing them. Anyway, I declined an offer to be a front-end developer from this other company and came back to codeo to complete the recruitment process, that being a full day spent at their offices with the team and a second interview.

I started work officially on the 1st of March and I couldn't be more happier. If I were to tag each and everyone who posted here, the content that helped me prep, I wouldn't even know where to start. Thanks to everyone who is a part of dev.to and those that are always lending a helping hand to career toddlers like me. You know, I've even received emails of people pointing out typos in my resume that I'd overlooked.

I mean check this out
{% link ice_lenor/do-i-want-to-work-in-this-company-or-what-questions-to-ask-on-an-interview-7po %}

I don't know how many times I read these questions, days before both my interviews at codeo. When they finally asked me "Alright, do you have any questions to ask us?" I was blank! This happened twice, when I was trying to recall questions that they haven't answered indirectly or that I haven't figured out already. At most I'd just say "No I don't have any, question 1, 2 and 3 were answered by this, that and such and such but thank you for the opportunity" as I said that, a funny question clouds my mind, it was so silly that I'd giggle while I was trying to speak, like an inner voice kept on shouting "ASK THEM **WHERE DO I SIGN?**"

Anyway, I'd talk about this forever, I just wanted to let you all know that I'm good now. I'm jobbing 🎉🎉🎉 (if that's a word)
WindwosでTCP/UDPを調査する便利ツール
Tags: windows, tcp, udp
Published: 2019-03-21 09:27:00

---
title: WindwosでTCP/UDPを調査する便利ツール
published: true
tags: Windows, TCP, udp
date: 20190321T09:27Z
canonical_url: https://qiita.com/shiena/items/d4a35edcf28d5ebb39ba
---
# はじめに

WindowsでさくっとTCPポートを開いているプロセスを調べたり、任意のホストに対してTCP/UDPポートが開いているか調べるMS製ツールがあったのでメモっておく。

# TCPView for Windows

[TCPView for Windows](https://technet.microsoft.com/ja-jp/sysinternals/tcpview.aspx)

![image.png](https://dev-to-uploads.s3.amazonaws.com/i/dba5dbtty5xkvwh186jc.png)


# Portqry / PortQueryUI

[Portqry / PortQueryUI](https://support.microsoft.com/ja-jp/help/310099/description-of-the-portqry-exe-command-line-utility)

リンク先にはCUIのPortqryV2とGUIラッパーのPortQueryUIがある。

![image.png](https://dev-to-uploads.s3.amazonaws.com/i/widhpw7hc0c91qy431lc.png)
How to Create a UDF in Presto-1
Tags: tech, gradle, java, presto
Published: 2019-12-31 19:24:30

---
title: How to Create a UDF in Presto-1
published: true
date: 2019-03-21 08:33:25 UTC
tags: Tech,gradle,java,Presto
canonical_url: https://anilkulkarni.com/2019/03/create-udf-presto-1/
---

How to Create a UDF in Presto-1 This article is going to talk about how we will create a UDF in Presto. When i started looking for creating an UDF, all resources i found spoke about Maven build. But, the one i created is via a gradle build. This Article will cover the below: Project… [Read More »](https://anilkulkarni.com/2019/03/create-udf-presto-1/)

The post [How to Create a UDF in Presto-1](https://anilkulkarni.com/2019/03/create-udf-presto-1/) appeared first on [Anil Kulkarni | Blog](https://anilkulkarni.com).
Unityでオフセット値などを3Dカーソルで調整したい
Tags: unity3d, unity拡張
Published: 2019-03-21 08:17:00

---
title: Unityでオフセット値などを3Dカーソルで調整したい
published: true
tags: Unity, Unity拡張
date: 20190321T08:17Z
canonical_url: https://qiita.com/shiena/items/b72c5731da36bcc7f7da
---
# はじめに

UnityでGameObjectの配置場所をオフセットでずらしたい時にフィールドを用意しておくとInspectorから調整できます。しかしVector3を斜めにずらしたい時など、数値だけでは調整が難しい場合もあります。そんな時に[エディター拡張入門](https://anchan828.github.io/editor-manual/web/index.html)でGizmoとHandleを作る方法を見付けて、簡単なエディター拡張を作るとすごく便利でした。

# エディター拡張の作り方

以下のようなクラスがあり`offset`を3Dカーソルで調整したいとします。

```cs:Body.cs
using UnityEngine;

public class Body : MonoBehaviour
{
	/// <summary>
	/// 3Dカーソルを作りたいフィールド
	/// </summary>
	public Vector3 offset;
}

```

以下のようなエディター拡張を作ると3DカーソルとギズモをScene Viewに作ることができます。

```cs:BodyEditro.cs
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

/// <summary>
/// 操作したいクラスをCustomEditorAttributeのtypeofで指定する
/// </summary>
[CustomEditor(typeof(Body))]
public class BodyEditor : Editor
{
	/// <summary>
	/// 3Dカーソルを作る
	/// </summary>
	private void OnSceneGUI()
	{
		var component = target as Body;
		var offset = component.offset;
		var transform = component.transform;
		offset = Handles.PositionHandle(transform.TransformPoint(offset), transform.rotation);
		component.offset = transform.InverseTransformPoint(offset);
	}

	/// <summary>
	/// ギズモを作る
	/// </summary>
	/// <param name="body"></param>
	/// <param name="gizmoType"></param>
	[DrawGizmo(GizmoType.NonSelected | GizmoType.Active)]
	private static void DrawEyeTargetGizmos(Body body, GizmoType gizmoType)
	{
		var transform = body.transform;
		Gizmos.color = Color.gray;
		Gizmos.DrawSphere(transform.TransformPoint(body.offset), 0.05f);
	}
}
#endif
```

![image.png](https://dev-to-uploads.s3.amazonaws.com/i/tknisohjntfmjqj9iiur.png)


# 参考リンク

* [エディター拡張入門](https://anchan828.github.io/editor-manual/web/index.html)
    * [第16章　Gizmo（ギズモ）](https://anchan828.github.io/editor-manual/web/gizmo.html)
    * [第17章　Handle（ハンドル）](https://anchan828.github.io/editor-manual/web/handles.html)
Day 4 Learning Javascript
Tags: beginners
Published: 2019-03-21 08:08:20

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

If, And, or But.

Getting into some of the Javascript conditionals and logical operators this fine evening. Even though it's very early in the Javascript learning process, I'm glad that so far all of this is making sense to me. I'm understanding when to use *if*, *else* and *else if*. This is probably useful for checking passwords or usernames on sites.

And (*&&*)...there's more! I can see how important *||* and *!* are going to be. But using *&&* in my code brings me a strange satisfaction that I can't quite explain. Maybe it's just the way two ampersands look together, I don't know.

Anyway...off to see what's next.