teleren/devto huggingface dataset:
Object Patterns in Javascript
Tags: javascript, webdev, career, tutorial
Published: 2020-02-03 12:32:27

JavaScript has many patterns for creating
objects, and there’s usually more than one
way to accomplish the same thing. You can
define your own custom types or your own
generic objects whenever you want. 

1.Module Pattern

This pattern is an object-creation pattern designed to create singleton objects with private data. The approach is to use an immediately
invoked function expression (IIFE) that returns an object. An IIFE is a function expression that is defined and then called immediately to produce a
result. That function expression can contain any number of local variables
that aren’t accessible from outside that function. Because the returned
object is defined within that function, the object’s methods have access
to the data. (All objects defined within the IIFE have access to the same
local variables.) Methods that access private data in this way are called
privileged methods.

Example

{% runkit %}
var myobject =(function(){
//private data variables

return{
//public methods and properties
}


}());

{%endrunkit%}



This pattern allows you to use regular variables as object properties that aren’t exposed publicly. You accomplish this by creating closure functions as object methods. Closures are simply functions that access data outside their own scope. For example, whenever you access a global object in a function, such as window in a web browser, that function is accessing a variable outside its own scope. The difference with the module function is that the variables are declared within the IIFE,and a function that is also declared inside the IIFE accesses those variables.







{% runkit %}
var object= (function() {
var age = 20;
 return {
 name: "myname", 
 getAge: function() {
 return age;
 }, 

 getOlder: function() {
 age++;
 }

 };

}());

console.log(object.name); // "myname"
console.log(object.getAge()); // 25
object.age = 100;
console.log(object.getAge()); // 25
object.getOlder();
console.log(object.getAge());
{%endrunkit%}
AWS AI & Machine Learning Podcast — Episode 8
Tags: aws, machinelearning, podcast
Published: 2020-02-03 17:12:04

---
title: AWS AI & Machine Learning Podcast — Episode 8
published: true
date: 2020-02-03 12:03:19 UTC
tags: aws,machinelearning,podcast
canonical_url: https://medium.com/@julsimon/aws-ai-machine-learning-podcast-episode-8-27f93997abc5
---

### AWS AI & Machine Learning Podcast — Episode 8

In this episode, I have a chat with Ségolène Dessertine-Panhard, a Data Scientist with the [AWS Machine Learning Solutions Lab](https://aws.amazon.com/ml-solutions-lab/). As she spends her time working on customer projects, we talk about ML in the trenches: framing problems, building datasets, picking algos, deploying to production, and more.

> _Video episodes are available on my_ [_YouTube channel_](https://www.youtube.com/juliensimonfr)_._

> _Audio episodes are available on_ [_Apple Podcasts_](https://podcasts.apple.com/us/podcast/aws-ai-machine-learning-podcast/id1492801210)_,_ [_Spotify,_](https://open.spotify.com/show/1argBtYSeSksGU8dcW4TAS) [_Deezer_](https://www.deezer.com/show/756292)_, and more. Visit my_ [_audio podcast page_](https://julsimon.buzzsprout.com/) _to subscribe and be notified of future episodes._

{% youtube 74LwQP9oKU4 %}

<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.buzzsprout.com%2F780458%2F2644813-episode-8%3Fclient_source%3Dtwitter_card%26player_type%3Dfull_screen&amp;display_name=Buzzsprout&amp;url=https%3A%2F%2Fwww.buzzsprout.com%2F780458%2F2644813-episode-8&amp;image=https%3A%2F%2Fwww.buzzsprout.com%2Frails%2Factive_storage%2Frepresentations%2FeyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBOGpKZFE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ%3D%3D--c836266b57e2bc68585d743589ac963f73619fc3%2FeyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld282QzNKbGMybDZaVWtpRFRJMU1IZ3lOVEJlQmpvR1JWUTZER2R5WVhacGRIbEpJZ3RqWlc1MFpYSUdPd2RVT2d0bGVIUmxiblJKSWd3eU5UQjRNalV3QmpzSFZEb01jWFZoYkdsMGVXbFZPZzlqYjJ4dmNuTndZV05sU1NJSmMxSkhRZ1k3QjFRPSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--62c0dc9ae0106a9121f982eb952976ff55ebdee3%2Fbackground.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=buzzsprout" width="500" height="210" frameborder="0" scrolling="no"><a href="https://medium.com/media/8087bac60ddfd7d72eb29c4700c156a3/href">https://medium.com/media/8087bac60ddfd7d72eb29c4700c156a3/href</a></iframe>
How can you tell if you've improved as a coder?
Tags: webdev, javascript, beginners, productivity
Published: 2020-02-03 11:48:18

How can I tell if I've actually improved as a coder?
{% youtube eXMIP78KRfA%}

Being able to tell if you have improved at coding isn't always easy. There is no clear cut way to let you know that you have grown a level at a certain library, it's all up to you.

It would be great if there was better tracking to know if your development skills or coding proficiency has improved. Comparing yourself against others, on social media, or at work also doesn't help to let you know if you are falling behind or if you have learnt the latest skills in coding to keep ahead.

I recommend setting a checklist at the start of each year to make sure you can track what coding libraries and programming languages you want to learn, and what goals you are setting. I also like to look back at the past to see how I started programming and how far I've come.

Looking back at older code and seeing how much you have improved is a pleasure, especially seeing how many mistakes you might have made, and how much faster and better you can develop code now. 

![Code Improvement by Adrian Twarog](https://adriantwarog.com/wp-content/uploads/2020/02/codeimprovement-scaled.jpg "Code Improvement by Adrian Twarog")

## Want to see more:
I will try to post new great content every day. Here are the latest items:
* [Staying Motivated to Learn Programming](https://dev.to/adriantwarog/staying-motivated-to-learn-programming-546b)
* [Why you should Whiteboard your Design & Development, UI & UX](https://dev.to/adriantwarog/why-you-should-whiteboard-your-design-development-ui-ux-5g12)
* [How to start using Styled Components for React Native](https://dev.to/adriantwarog/how-to-start-using-styled-components-for-react-native-5don)
* [Creating a Mobile Design and Developing it](https://dev.to/adriantwarog/creating-a-mobile-design-and-developing-it-5c4o)
Listing the best services for free domain email addresses in 2022
Tags: email, mail, free, service
Published: 2020-02-03 11:24:38

Hi folks,

If you build new services, websites, or startups, you usually want to create an email address for your domain name. Maybe something like <i>support@yourstartupname.com</i>. And ideally you want it for free.

I thought I'd quickly outline and compare the main solutions for that here:

- <a href="https://postale.io" target="_blank">postale.io</a> (simplest but 5 mailboxes per domain max),

- <a href="https://mail.yandex.com/" target="_blank">Yandex Mail</a> (most capabilities but ads and not as intuitive),

- <a href="https://www.zoho.com/mail/zohomail-pricing.html" target="_blank">Zoho Mail free plan</a> (5 mailboxes max, 1 domain only and webmail only),

- <a href="https://www.migadu.com/en/pricing.html" target="_blank">Migadu free plan</a> (not so great IMO as it's limited to 10 outgoing emails per day max and adds a "Sent via Migadu" at the end of every email).

Overall I'd say <a href="https://postale.io" target="_blank">postale.io</a> is probably the easiest choice for the vast majority of people due to its simplicity. The creation process is fast and simple, the UI is intuitive, and the most technical part (DNS setup) is handled for you if requested. The number of mailboxes is not unlimited, though it can go in the thousands depending on the chosen plan.

<a href="https://mail.yandex.com/" target="_blank">Yandex</a> in the other hand offers unlimited mailboxes per domain, but is harder to grasp (partly because its UI is all over and partly because there's a lot in russian).

Hope this is helpful! What do you think?
What the hell is positional pattern matching?
Tags: csharp, dotnet
Published: 2020-02-03 11:11:15

With the arrival of the brand new __C# 8.0__, a lot of new things are possible! One of my personal favorites is the positional pattern matching feature! 
Just like my other posts about C#, I'll be using the _Elf_ class which has two properties: _Age_, which is the age and _ElfishName_, which is the name of the elf in elfish. Before we dive into this feature, let me give you a brief refresher of some stuff you need to know in order to understand what is happening.

#Background
Firsly, as you might know, in C# 7.0 there is a feature called __pattern matching__ (if not you can read about it [here](https://dev.to/alexdhaenens/what-the-hell-is-pattern-matching-4an8)). Pattern matching makes it possible to do a type check and a cast directly in one line:

```c#
if (person is Elf)
```

Also in c# 7.0 you can extract properties out of an object in one line. This feature is called __object deconstructing__ (you can learn more about this [here](https://dev.to/alexdhaenens/what-the-hell-is-object-deconstructing-kj0)) and it looks like this:

```c#
(int age, string elfishName) = elf;
```
It is a nice feature but, as you might remember, it requires a deconstructor. A deconstructor is a method called _Deconstruct_ in a class and looks like this:

```c#
public void Deconstruct(out int age, out string elfishName)
        {
            age = Age;
            elfishName = ElfishName;
        }
```
#What is it?
In C# 8.0 however, you can __combine both pattern matching & object deconstructing__ which is called __positional pattern matching__. It is important to note is that just as deconstructing it requires a deconstructor.

So what does it do? Well, it makes it possible to type check the variable, then cast it to a specific type and then deconstruct it IN ONE LINE! It looks something like this:

```c#
if (person is Elf(int age, string elfishName))
            {
                Console.WriteLine($"Elf with elfish name{elfishName} is {age} years old");
            }
```

The _Age_ and _ElfishName_ properties are extracted into the _age_ and _elfishName variables_, just like in object deconstructing. This is a nice shorthand, but don't forget that a deconstructor is required! 

An extra addition is this:

```c#
           if (person is Elf(110, string elfishName))
            {
                Console.WriteLine($"Elf with elfish name{elfishName} is 110 years old");
            }
```
In this piece of code, I've already provided a const value (in this case 110) against which the casted object is checked. So what this one line actually does, is firstly it checks if the person is an _Elf_, casts it, then deconstructs the casted object and lastly checks if the _Age_ property is equal to 110. You can then access the _ElfishName_ of that casted object in the _elfishName_ variable. Isn't this nice??

#Source
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#positional-patterns
Demo project: https://bitbucket.org/aldhaenens/p-d-demo/src/master/
Magento2 ui component in deep
Tags: magento2, uicomponent, knockoutjs, webdev
Published: 2020-02-03 11:04:52

From this tutorial i will show you how to get info from some main component in magento 2 by javascript

All components defined in below file
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

If you work with components in magento you possible may related with uiregistry. This is ultility component allow you access to specific component. 

Playground for work with component from browser

Go to product list page of magento in admin dashboard
Open chrome browser > Console tab

> requirejs('uiRegistry').get('%componentName%');

componentName is string name of component.

#1 Listing component
Source file
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/web/js/grid/listing.js

There is alot place magento use this component such as: Product listing, Order listing, cms page listing

Example

var productrows = requirejs('uiRegistry').get('product_listing.product_listing.product_columns').rows

Above will return current object contain rows of products

[{product1},{product2},so on]

OR

var productrows = requirejs('uiRegistry').get('product_listing.product_listing_data_source').data['items']

var components = requirejs('uiRegistry').get('product_listing.product_listing.product_columns').elems()

#2 Form component
Source file 
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/web/js/form/form.js

Continuing...
Immutable requirements if you want a remote job
Tags: remote, remotejobs
Published: 2020-02-03 10:57:28

---
title: Immutable requirements if you want a remote job
published: true
description: 
tags: remote,remote-jobs
cover_image: "https://s3.amazonaws.com/aviaryan/email/remote-require.jpg"
---


I see many people want to do remote jobs. But in my experience, there are some things that you need before you can have a great remote work career.

Consider it as the smallest definite checklist. 

Note that these might be true for office jobs as well but there, the requirements are relaxed. 

For example - You can do well even if your communication skills are poor. You might get promoted as well. But having bad communication skills will make it impossible to work remotely.

## Good communication

You need to communicate well. If you can’t speak English (or your team’s language), that’s an issue. 

Remote work features both spoken and written communication. And you need to be decent at both since confusion or lack of clarity can be harmful to your team.

## Self-Starter

If your team is in different timezones, often you will be at a spot where you don’t know what to do next and your manager will not be online to tell you. 

Or you just came across an unexpected situation and you will have no one to discuss with. In that case, you need to be able to weigh the choices and make the best decision for the team so that you utilize your time.

## Okay with some timezone overlap

You will need to do some timezone overlap to work remotely if your team is across the globe.

A 100% overlap isn't required but there will be meetings and scrum calls and you need to be ready for that. 

Your timezone shouldn’t cause problems for the team.

## Quality work

In remote work, mentorship is scarce. Or not the same as you would get in an office job. So you need to be able to deliver good work.

Work that gets accepted in the first shot or doesn’t need much to-and-fro. Because, to-and-fro wastes even more time in a remote setting where members live in different, sometimes opposite timezones.

Also, failing reflects badly in remote work. This is because, in an office job, your manager can see that you did the work or at least tried. But in a remote job, it can be assumed that you didn’t do the work or slacked off.

<br/>


If you identify yourself with each of the points mentioned above, consider yourself ready for remote work.

If not, work on them.

<br/>

PS - I am working on a remote jobs list for India. It has **300+ tech remote jobs** available in the Indian timezone. Check it out. [GoRemote](https://goremote.in/)

----

> This article was first posted to my [newsletter](https://aviaryan.com/letters/requirements-for-remote-job).
What to use to measure frontend metrics?
Tags: discuss, analytics, metrics, webdev
Published: 2020-02-03 10:54:49

(Photo by [Mitchel Boot](https://unsplash.com/@valeon))

I'm curious what are your, DEV Community, choices for **frontend analytics tools**. And what I mean by that?

- Let's say I want to check click-rate on links in DEV sidebar (left) nav to see which are used the least (so maybe we can hide some?).
- Let's say I want to measure how often people click links in right sidebar widgets and break it down per each widget (listings, #help, #ama, #challenge, ...). Are some widgets used less than the others?
- Let's say I want to compare if people prefer to click "Write a post" CTA  in header OR the one in profile pic dropdown.
- Let's say I want to compare if people prefer to go to own profile by clicking the widget in left sidebar OR the one in profile pic dropdown.
- Let's say I want to see how the onboarding performs - what people click on each step, when do they drop-off, how many people skip some fields etc.

Why? Good design decisions are driven by data. Data also helps validate ideas and its success.

PS. Bonus points if it's open source :).
Connect to a single MongoDB instance from rust
Tags: driver, rust, database, mongodb
Published: 2020-02-03 10:20:28

The rust driver for Mongo is still in its infancy. It is well documented in terms of the signatures of each function and feature but very limited when it comes to examples. I spent way to long trying to make a simple connection to local and staging Mongo instances and the examples just don't work.

Solution:
They are missing the direct_connection option flag.


```rust
fn main() {
    // Set URI
    let uri = "mongodb://localhost:27017/";

    // Setup options
    let mut options = ClientOptions::parse(uri).unwrap();
    options.direct_connection = Some(true);

    // Create the Client
    let client = Client::with_options(options).unwrap();

    // Use the Client
    let _dbs = dbg!(client.list_database_names(None));
}
```

Note for noobs, you don't need the dbg!() wrapper - that is just to log the output easily. You can just:

```rust
let _dbs = client.list_database_names(None);
```
Makers - Week 5
Tags: jquery, javascript, jasmine, frontend
Published: 2020-02-03 09:56:46

Week 5 has come and passed, and I have to admit as you will tell by the timestamp - this post is late! This is because of several reasons, but ultimately i can fully place the blame on the door of Javascript. 

Bloody hell week 5 was the most intense so far. Not only did we jump headfirst into the world of brackets and semi colons, we had to immediately translate several programs we had previously built in Ruby, into Javascript. The first morning i spent looking up all of these strange words that were synonymous with Javascript…prototypes, functions, asynchronous programming. I was completely overwhelmed. 

However after a few days battling through conventions, functions and incorrect bracket placements, it somehow started to click. This is something makers had always said loud and proud, and something i was not quite sure how it would happen - “we teach you to code, not a specific language”. And to my shock, it happened. After a few days, conventions and processes I had learnt in the previous 4 weeks did in fact translate into a foundation of coding knowledge!

The challenge of the week was to build a thermostat, that responded to a variety of functions. This was then tied to a front end userface which controlled the logic of the thermostat via the magic of jQuery. 

This was my first experience of front end development, and how pleasing it was! It was amazing to see instant changes visually, and not just the output on the terminal being what you want - the creative juices started flowing, and with some basic query knowledge, colours changes, buttons made sounds and the end product was more than what i would ever have imagined after a week of Javascript.

It looks like this process is clicking, and the structure grows on itself each week, dare i say it is starting to make sense now!

Next week is our first group project week which i’m sure will brings its own new challenges, i’m looking forward to seeing what can be achieved when 4 of us crack heads and code!

As always, wish me luck!

David
Experimenting simpler execution flows in Ruby
Tags: ruby
Published: 2020-02-03 09:50:40

I created the gem [Mu::Result](https://source.olisti.co/olistik/mu-result) because I feel the need to pass *Result objects* instead of raw values.

This allows me to write this kind of code:

```ruby
def fetch(post_id:, author_id:)
  result = api_call("https://foo.com/posts/#{post_id}")
  return result if result.error?
  post = result.unwrap

  result = api_call("https://foo.com/authors/#{author_id}")
  return result if result.error?

  author = result.unwrap
  Result.success(author: author, post: post)
end

result = fetch(post_id: 23, author_id: 42)
if result.error?
  case result.code
  when :network_error then puts 'Some troubles in the network'
  when :bad_request then puts 'Maybe a malformed request'
  when :forbidden then puts 'Check your credentials'
  when :not_found then puts 'They are gone, Jim'
  else
    puts 'Generic errors'
  end
  exit 1
end

puts "The post is: #{result.unwrap(:body)}"
```

with some wins like:

- it's relatively easy to propagate errors without relying on exceptions;
- there's a common API to handle richer return values;
- pattern matching can be performed with a simple case statement against result's `code` attribute;
- no big boilerplates involved as `Mu::Result` is really tiny.

![FTW](https://dev-to-uploads.s3.amazonaws.com/i/dn0j2wur4ffqw0omdsuw.gif)

Yet, I feel it can be improved even further. 🤓

Taking heavy inspiration from [dry-rb's do notation](https://dry-rb.org/gems/dry-monads/1.0/do-notation/) here's a draft implementation I came up:

```ruby
require 'mu/result'

module Mu
  module Flow
    def self.do(stuff, *args)
      stuff.call(*args) do |step|
        return step if step.error?

        step
      end
    end

    def Success(data = nil)
      Mu::Result.success(data)
    end

    def Error(data = nil)
      Mu::Result.error(data)
    end

    def Flow(method_name, *args)
      Mu::Flow.do(method(method_name), *args)
    end
  end
end
```

Everyday code can use it this way:

```ruby
include Mu::Flow

def logic(n)
  age = yield Success(n / 2)
  yield Error(age.unwrap).code!(:too_low) if age.unwrap > 10
  magic_number = yield Success(age.unwrap ** 2)
  yield magic_number.code!(:wow) if magic_number.unwrap > 50
  magic_number
end

# simpler way with the helper:
result = Flow(:logic, 18)
puts "result: #{result.inspect}"
# result: #<Mu::Result::BaseResult:0x00007fd3d8027520 @code=:wow, @data=81>

# or more explicitly:
result = Mu::Flow.do(method(:logic), 8)
puts "result: #{result.inspect}"
# result: #<Mu::Result::BaseResult:0x00007fd3d8027160 @code=:ok, @data=16>
```

The example is contrived but it shows that there's no need to write explicit returns for error results anymore.

The implementation of `Mu::Flow` aims to remain tiny.

I'm still experimenting with this approach to see whether it produces a tangible gain or not. 🧐