teleren/devto huggingface dataset:
Enums in Go - why and how?
Tags: go, programming, beginners
Published: 2019-10-15 06:25:44

Go doesn't (yet) have enums as such, but it seems common to use `constants` with `iota` for this instead.

Passing enums instead of strings to a constructor helps reduce possible bugs; when a constructor accepts a set of possible options for an argument, it's easy to _"fat finger"_ (i.e. misspell) them. 

Using custom _"enums"_ helps to prevent this and also documents available options for that argument. 

Here's what I found on [stackoverflow](https://stackoverflow.com/a/4709224) on the _why_ (above), and here's an example I've implemented.

[https://github.com/alex-leonhardt/go-passing-enums/](https://github.com/alex-leonhardt/go-passing-enums/)


`main.go`
```go
package main

import (
	"fmt"

	"github.com/alex-leonhardt/go-passing-enums/pkg/config"
)

func main() {
	cfg, err := config.New(config.Env)
	fmt.Printf("%#v %#v\n", cfg, err)
	cfg, err = config.New(config.File)
	fmt.Printf("%#v %#v\n", cfg, err)
	cfg, err = config.New(42)
	fmt.Printf("%#v %#v\n", cfg, err)
}

```

> we're using the New() constructor function in the `config` package and pass it the config _type_ to return


`pkg/config/config.go`
```go
package config

import (
	"errors"

	"github.com/alex-leonhardt/go-passing-enums/pkg/config/env"
	"github.com/alex-leonhardt/go-passing-enums/pkg/config/file"
)

// Configurer describes a config provider
type Configurer interface {
	Get(string) string
	Set(string) bool
	Del(string) bool
}

// T is used to select the type of config to return
type T uint

// Constants for T
const (
	Env T = iota
	File
	Unknown
)

// New takes a config.T type and returns an Configurer
func New(t T) (Configurer, error) {
	switch t {
	case Env:
		return env.New(), nil
	case File:
		return file.New(), nil
	default:
		return nil, errors.New("eh?")
	}
}

```

> we're specifying `T` as a `uint` which we'll use as our custom _"enum"_ to pass to `New()`, depending on the _"type"_, a different `Configurer` is being initialised (using its own `New()` constructor) and then returned



`pkg/config/env/env.go`
```go
package env

type env struct {
	val1 string
	val2 int
	val3 bool
}

// New creates a new config
func New() *env {
	return &env{}
}

func (c *env) Get(v string) string {
	return ""
}
func (c *env) Set(v string) bool {
	return true
}
func (c *env) Del(v string) bool {
	return true
}

```

> finally, `New()` returns a pointer to an initialised `env` struct which satisfies the `config.Configurer` interface by implementing the required methods `Get`, `Set` and `Del`.


Hope this helps anyone, it helped me already just by writing this!


If you have any comments, suggestions, better explanations, please _do_ leave a comment. Always happy to learn new things!
Hacktoberfest AWS S3-Clone
Tags: hacktoberfest, firstissue, aws, programming
Published: 2019-10-15 05:55:49

---
cover_image: https://hacktoberfest.digitalocean.com/assets/HF19_social-744d976f227e4aff6866443abcede8c651b309ec9c7c9f7410f5944f8e1299b9.png
title: Hacktoberfest AWS S3-Clone
published: true
description: Three repositories to contribute which are using the AWS SDK of NodeJS, Python, and Ruby for building an S3-Clone.
tags: #hacktoberfest, #firstissue, #aws, #programming
---


Servus!

How are u doing with Hacktoberfest? 
Just okay?

Alright, then this might be the chance to support me of my personal POC.
Here are three repositories which contains the AWS- SDK of different programming languages.
The goal is to have real-life example by building an AWS-S3 clone and get you a PR-request.

## Python's boto3

{% github jolo-dev/aws-s3-python %}

## AWS SDK for Ruby v3

{% github jolo-dev/aws-s3-ruby %}

## Java AWS SDK 2

{% github jolo-dev/aws-s3-java %}

Any support is welcome :)
Happy Coding!
Translation Files Validation in Angular with Transloco And Husky
Tags: angular, translation, husky, validation
Published: 2019-10-15 05:39:48

Originally published at [shahar.kazaz](https://medium.com/@shahar.kazaz/translation-files-validation-in-angular-with-transloco-e6ba02467f33)

When working on an enterprise application and with multiple teams, it’s often the case where we have merge conflicts with one of the translation files.

In this case, we can accidentally break the file by forgetting an extra comma, for example:

```
{
  "key": "",
  "keyTwo": "", <====
}
```

Which leads to an invalid JSON. In most cases, the developer doesn’t notice this change and pushes the code to production or staging environments, and brokes that app.

Here in Transloco, we take such things seriously, and to prevent this, we created a linter that will verify the translation files before they pushed.

In addition to that, it will also check that it does not contain duplicate keys.
Let’s see how we use it:

- Set up husky and [lint-staged](https://github.com/okonet/lint-staged#examples)
- Run `npm i @ngneat/transloco-validator --save-dev`

Update your `package.json` file:

```json
{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/assets/i18n/*.json": ["transloco-validator"]
  }
}
```

This will make sure no one accidentally pushes an invalid translation file.

If you liked this post, please 👏🏻 and share it!

***

Here is some more great content about Transloco:

##Introducing Transloco: Angular Internationalization Done Right
[![🚀 Introducing Transloco: Angular Internationalization Done Right](https://thepracticaldev.s3.amazonaws.com/i/0byy9oicu3el19il9bx2.png)](https://netbasal.com/introducing-transloco-angular-internationalization-done-right-54710337630c)

##Lazy Load Translation Files In Angular Using Transloco
[![Lazy Load Translation Files In Angular Using Transloco](https://thepracticaldev.s3.amazonaws.com/i/qrbtvmni72l4jx39rymo.jpg)](https://medium.com/@shahar.kazaz/lazy-load-translation-files-in-angular-using-transloco-2d3afed116ce)

##Help the Translator by Using Transloco: The internationalization (i18n) library for Angular
[![Help the Translator by Using Transloco: The internationalization (i18n) library for Angular](https://thepracticaldev.s3.amazonaws.com/i/bor4py6tbht5que5lj5q.jpeg)](https://medium.com/@shahar.kazaz/help-the-translator-by-using-transloco-the-internationalization-i18n-library-for-angular-831c3c513ee4)
How Opencart Multi-vendor Seller Product Options works?
Tags: multivendorforopencart, opencartmultivendor, opencartmultiseller
Published: 2019-10-15 05:03:58

In opencart multivendor, we have updated the new functionality called Products Options in that sellers can create their own seller product options. To create options like checkboxes, radio buttons, color pickers, image options, number options, dropdowns, date pickers, image uploads, text boxes and text areas to your products so that you can sell upgrades, sizes, extras, gift options, color choices, etc? With Extra Product Options functionality for opencart multi-vendor marketplace plugin, you can edit/remove/enable/disable all the fields you have created. That's exactly what this functionality does in purpletree's Opencart multi vendor extension does.
Add/Edit the seller product options
To create attributes go to Seller Options > find "Product Options" menu >then click on it.

Select the type of option as you can see in the screenshot we have selected the radio type you can select any one of them like checkboxes, radio buttons, color pickers, image options, number options, dropdowns, date pickers, image uploads, text boxes, and text areas. After that click to save button.

· 8 field types are available: In new field form or edit field form you can choose field type from a list of 14 including 12 input fields, one field for title/heading and one field for label/text
Available field types:
Text - A basic input text field.
Text area - A text area field.
Radio - Radio button input (for selecting one of many choices)
Checkbox - A checkbox field.
Select - A drop-down list (for selecting one of many choices)
Date - Select a date from a popup.
Time picker - Select a time from a list.
File– A file upload field.

After that to assign the product option to product Go to Seller Options > Products > Add/Edit any product > Option.

Then click to continue (Save) button.

For any query, requests get back to us or raise a ticket at https://www.helpdesk.purpletreesoftware.com.
More details of Purpletree Opencart Multivendor marketplace can be found here. https://www.purpletreesoftware.com/multi-vendor-marketplace-opencart.html
My Favorite 5 Visual Studio Code Extensions
Tags: vscode, html, css, tutorial
Published: 2019-10-15 04:25:02


**[#1.Live server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)**

![Live Server](https://i.ibb.co/cQX5HtD/vscode-live-server-animated-demo.gif)
Make changes in code editor, switch to browser, and refresh to see changes. That's the endless cycle of a developer, but what if your browser would automatically refresh anytime you make changes? That's where Live Server comes in!

It also runs your app on a localhost server. There are some things you can only test when running your app from a server, so this is a nice benefit.

**[#2.Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)**

![Prettier - Code formatter](https://i.ibb.co/cyfks5X/prettier.gif)

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.


**[#3.Auto Close Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag)**

![Auto Close Tag](https://i.ibb.co/mzBg0jc/usage.gif)

Automatically add HTML/XML close tag, same as Visual Studio IDE or Sublime Text does.

Features
-  Automatically add closing tag when you type in the closing bracket of the opening tag
-  After closing tag is inserted, the cursor is between the opening and closing tag
-  Set the tag list that would not be auto closed
-  Automatically close self-closing tag
-  Support auto close tag as Sublime Text 3
-  Use Keyboard Shortcut or Command Palette to add close tag manually

**[#4.HTML Class Suggestions](https://marketplace.visualstudio.com/items?itemName=AndersEAndersen.html-class-suggestions)**

![HTML Class Suggestions](https://i.ibb.co/dQKqNcR/Screenshot-1.png)

html-class-suggestions is a Visual Studio Code extension that provides completion options for html class attributes based on the css files in your workspace.


**[#5.vscode-icons](https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons)**

![vscode-icons](https://i.ibb.co/GtYNR3L/screenshot.gif)

Comprehensive icon extension for Visual Studio Code. ..
Data Structures and Algorithms Visual Algo
Tags: datastructures, visual, algorithms
Published: 2019-10-15 04:18:52

Data structures and Algorithms are one of the most important topics in computer science. 

One of main challenges I personally have faced while learning Data structures and Angorithms is to visualize the steps while performing operations like insert, lookup, remove etc. 

Recently I came across a wonderful website which has helped me to understand DSA by providing animated visuals

Please find below url -

https://visualgo.net/en 

Please take a look and I hope you will also find this helpful.

Cheers!
I'm so excited about Ionic React!
Tags: react
Published: 2019-10-15 04:15:51

---
title: I'm so excited about Ionic React!
published: true
description: 
tags: #react #discuss
---
Breaking Announcing
https://ionicframework.com/blog/announcing-ionic-react/

This is what I have been waiting for 😆😆😆
I had a experience that react-native dev, but it's so far away web development experience despite exactly sure that is React.  

I' ll definitely be prototyping with Ionic React!
Using Twitter With Python and Tweepy
Tags: python, tutorial, beginners
Published: 2019-10-15 04:08:31

In this course, you will learn the basics of the Twitter API by using Tweepy, the Python Twitter library.

What you’ll learn:

    How to post tweets using Python
    How to get tweet’s text, author, location of tweet user, bio/description of the user
    How to get the latest tweets based on a certain keyword
    Basics of Tweepy library

{% youtube 6rpcsJHprfk %}
How I started learning Apache Spark
Tags: apachespark, etl, python
Published: 2019-10-15 03:26:22

---
title: How I started learning Apache Spark
published: true
description: 
tags: Apache Spark, ETL, Python
---

I've realised over the years that the best way for me to start learning a new language, toolkit or technology is to dive right in and start trying to solve problems with it.

This is most definitely true for [Apache Spark](https://spark.apache.org), which I had to do recently in order to prepare for a #DataScience interview.

I wrote a utility to Extract information from my 6+ years of PV Inverter data, Transform it and Load it (#ETL) into #DataFrames which I query for record dates, minimum and maximum output as well as daily average output. Keeping with my standard practice, I've put that code on [GitHub](https://github.com/jmcp/solar-spark), and written a blog post about the process. See more (much more!) at [https://www.jmcpdotcom.com/blog/posts/2019-10-11-apache-spark-init/](https://www.jmcpdotcom.com/blog/posts/2019-10-11-apache-spark-init/)

#Apache #Spark, #ETL, #Python
Day 2: Java Validation
Tags: java, regex
Published: 2019-10-15 02:32:46

## Intro

Recently, I focus on building a REST API using Spring Boot, Java and Swagger.
We all know that REST API involves Request and Response parameter in it. I was amazed at how Java provides validation to prevent repeatable line of code. 
Before annotation era, we always do the validation using `if else` instruction. If this field is null then throw exception, if A is null then B becomes mandatory, and so on. Imagine you create hundreds API involves hundreds field parameters? 

## Validation annotation

So, Java gives you a solution. You can put validation annotation attached with field. If you create custom validation, you can put it also in class level. I will note down the basic one. Following are the common annotation used for field validation on Request parameters.

* @ NotBlank -> validates that value is not null. can be used in any type of field. usually String type
* @ Size -> validates size/length of value. Usually applied for integer type. It has attribute min and max
* @ Pattern -> to validate pattern using regex. I used this one a lot. It is very convenience to use other than comparing String with equals method. The challenge is creating the regex itself. [You can simulate it here](regex101.com) before use it. Probably I will write about this part in separate post.

## Custom Validation

If your requirement getting complicated, and no basic annotation can accommodate it, you may create your own validation. [This post is a good start](https://stackoverflow.com/questions/2781771/how-can-i-validate-two-or-more-fields-in-combination) . 
I will share one of my custom validation later :D

## Some example

```java
@Pattern(regexp="^[0-9]*$")
@NotBlank
@Size(max = 20)
String myNumber;

@MyCustomValidation
String myCode;
```
Coder's life
Tags: javascript, developer, coding
Published: 2019-10-15 01:54:39

---
title: Coder's life
published: true
description:Need a perspective from other devs
tags: #javascript #reactjs #developer #coding
---

The one thing I realized about coding is even if u are beginner or an expert. It's the same mental process and stress only the level of programming differs. Correct me if I am wrong. #100DaysOfCode #javascript #newbiecoder #reactjs
Alojamiento de un sitio web estático con Azure Web App
Tags: azure, webdev, html
Published: 2019-10-15 01:32:17

Hoy en día el termino computación en la nube esta dando mucho de que hablar. La informática en la nube nos permite acceder a una gran cantidad de servicios a través de infraestructuras que podemos tener a nuestra disposición, tales como: servidores físicos, redes, máquinas virtuales, contenedores de desarrollo, entre otros. Para este caso, nos referimos a Microsoft Azure, donde prácticamente podemos construir cualquier cosa (informáticamente hablando).

Uno de los recursos más utilizados hoy en día son los servicios que nos permiten trabajar con aplicaciones web para el alojamiento de páginas HTML por ejemplo, en el caso de Azure existe un servicio llamado Web App y lo mejor de todo es que no tendremos la molestia de administrar la infraestructura para su funcionamiento.
Para la implementación de una Web App, lo primero que necesitamos hacer es crear un servicio de este tipo (Web App):

![](https://thepracticaldev.s3.amazonaws.com/i/q2kn2j7sflodycwnqzle.png)

Donde el nombre de la aplicación también servirá para definir el nombre del dominio para poder acceder al sitio web que se desea crear. Azure nos proporciona un subdominio con azurewebsites.net.

La creación de este servicio suele tomar entre 30 y 60 segundos.

![](https://thepracticaldev.s3.amazonaws.com/i/cfv3fu7osubx9ghpwber.png)

Para poder alojar los archivos HTML y CSS de la página web que se desea alojar en la nube, nos dirigimos al listado de opciones del recurso creado y seleccionamos en “Herramientas Avanzadas”:

![](https://thepracticaldev.s3.amazonaws.com/i/jtzcjcw9fs4y0fjn1ued.png)

Una vez realizado este proceso, seremos redireccionados al portal de Kudu, donde podremos alojar nuestros archivos, añadir extensiones tales como: phpMyAdmin, ASP.NET, PHP7, Python, entre otros. Para nuestro objetivo, nos dirigimos a la consola CMD:

![](https://thepracticaldev.s3.amazonaws.com/i/hnqwz1999hqwqf5rur5i.png)

Posteriormente nos encontraremos con la consola de comandos CMD y con un directorio de archivos del sitio web. En el directorio de archivos empezando navegando desde la carpeta site, luego wwwrot y en ese directorio subimos los archivos HTML, imágenes y demás de la página web que se desea alojar.

Lo ultimo que queda por hacer es revisar la pagina web final a través de la dirección creada inicialmente en el recurso.

![](https://thepracticaldev.s3.amazonaws.com/i/ucf8s4rv6uzicealjzix.png)
Hosting a Static Website on Azure Web App!
Tags: azure, webdev, html
Published: 2019-10-15 01:26:04

Today the term cloud computing is giving a lot to talk about. Cloud computing allows us to access a large number of services through infrastructure that we can have at our disposal, such as: physical servers, networks, virtual machines, development containers, among others. For this case, we refer to Microsoft Azure, where we can practically build anything (computerly speaking).

One of the most used resources today are the services that allow us to work with web applications for hosting HTML pages for example, in the case of Azure there is a service called Web App and best of all, we will not have the trouble of managing the infrastructure for its operation.

For the implementation of a Web App, the first thing we need to do is create a service of this type (Web App):

![](https://thepracticaldev.s3.amazonaws.com/i/q2kn2j7sflodycwnqzle.png)

Where the name of the application will also serve to define the name of the domain to access the website you want to create. Azure provides us with a subdomain with azurewebsites.net.

The creation of this service usually takes between 30 and 60 seconds.

![](https://thepracticaldev.s3.amazonaws.com/i/cfv3fu7osubx9ghpwber.png)

In order to host the HTML and CSS files of the web page that you want to host in the cloud, we go to the list of options of the created resource and select in “Advanced Tools”:

![](https://thepracticaldev.s3.amazonaws.com/i/jtzcjcw9fs4y0fjn1ued.png)

Once this process is done, we will be redirected to the Kudu portal, where we can host our files, add extensions such as: phpMyAdmin, ASP.NET, PHP7, Python, among others. For our purpose, we turn to the CMD console:

![](https://thepracticaldev.s3.amazonaws.com/i/hnqwz1999hqwqf5rur5i.png)

Later we will find the CMD command console and a file directory of the website. In the file directory starting browsing from the site folder, then wwwrot and in that directory we upload the HTML files, images and others of the web page that you want to host.

The last thing left to do is review the final web page through the address initially created in the resource.

![](https://thepracticaldev.s3.amazonaws.com/i/ucf8s4rv6uzicealjzix.png)
My Hacktoberfest 2019
Tags: hacktoberfest
Published: 2019-10-15 01:00:22

Originally published at [iamdeveloper.com](https://www.iamdeveloper.com/blog/2019-10-14-my-hacktoberfest-2019/)

Like many of you, I am participating in Hacktoberfest as well. Most of the contributions I have made in October have been for DEV. Here are the PRs that have been merged so far:


{%github https://github.com/thepracticaldev/dev.to/pull/4257 %}

{%github https://github.com/thepracticaldev/dev.to/pull/4323 %}

{%github https://github.com/thepracticaldev/dev.to/pull/4346 %}

{%github https://github.com/thepracticaldev/dev.to/pull/4374 %}


The other PR that ~~is still under review~~ got merged is for the [learnstorybook.com](https://learnstorybook.com) website.

{%github https://github.com/chromaui/learnstorybook.com %}

The PR adds a precommit hook to format markdown files via prettier and as well, I ran prettier on all the markdown files as a lot of files had not run through prettier previously.

{%github https://github.com/chromaui/learnstorybook.com/pull/181 %}

Although this is not from Hacktoberfest, the beauty of open source is that anyone can checkout what you are up to. I was super surprised and felt pretty good when Addy Osmani liked one of my PRs for DEV.

{%twitter 1075866822006751233 %}

I will probably contribute some more to the DEV codebase, but who knows, I may tackle an issue in another repository. YOLO.
What are your thoughts on functional programming? In PHP?
Tags: php, functional, oop, discuss
Published: 2019-10-15 00:24:24

A friend of mine introduced me to the concept of functional programming this weekend. As someone who's been writing procedural PHP since before PHP supported objects and then gradually transitioned to an OOP-based mindset, the concept of functional programming is kind of blowing my mind. 

#For those of you unfamiliar with functional programming in PHP...

@davidbhayes' video on banishing loops with functional programming is a good primary on the basic concept.

{% youtube n0Qi5Fz4SXM %}

#If you are more familiar with functional programming in PHP...

I have some question:
- what are some of the main benefits?
- is it mostly about simplifying loops? 
- any examples of projects that make good use of functional programming? github links?
- what are the main drawbacks? gotchas?
- Is OOP on its way out? 

---

I haven't been this intrigued by a programming concept in a while. Super curiosu what the dev.to community thinks!