teleren/devto huggingface dataset:
[golang] Generating getter/setter methods easily
Tags: go, productivity, oop
Published: 2021-10-17 05:16:29

Hi all,
I have made a go tool to generate accessor methods(getter or setter) for unexported struct fields, so let me introduce it.

https://github.com/masaushi/accessory

{% github masaushi/accessory %}

Sometimes you might make struct fields unexported in order for values of the fields not to be accessed or modified from anywhere in your codebases.

Making struct fields unexported will prevent data from unexpected use or change.
But you sometimes might need accessor methods for some fields to get/set data in a desired way.

However, writing accessors for many fields is time-consuming, but not exciting or creative.

This tool frees you from that tedious, monotonous task.

### Example

##### 1. Declare a model with `accessor` tag.

```go
type MyStruct struct {
    field1 string    `accessor:"getter"`
    field2 *int      `accessor:"setter"`
    field3 time.Time `accessor:"getter,setter"`
}
```

##### 2. Run `accessory` command

```sh
$ accessory -type MyStruct .
```

##### 3. Accessor methods will be generated.

```go
func(m *MyStruct) Field1() string {
    return m.field1
}

func(m *MyStruct) SetField2(val *int) {
    m.field2 = val
}

func(m *MyStruct) Field3() time.Time {
    return m.field3
}

func(m *MyStruct) SetField3(val time.Time) {
    m.field3 = val
}
```

##### 4. You can customize method name

```go
type MyStruct struct {
    field1 string `accessor:"getter:GetFirstField"`
    field2 int    `accessor:"setter:ChangeSecondField"`
}
```

Generated methods will be

```go
func(m *MyStruct) GetFirstField() string {
    return m.field1
}

func(m *MyStruct) ChangeSecondField(val *int) {
    m.field2 = val
}
```

##### 5. You can also generate accessors with `go generate`

```go
//go:generate accessory -type MyStruct

type MyStruct struct {
    field1 string `accessor:"getter"`
    field2 *int   `accessor:"setter"`
}
```

### Conclusion

Generating accessors easily will save your time and help you focus on writing important business logics.

I'm looking forward to getting your feedback.

Have a wonderful day!
Some Tips to Become a Good Programmer
Published: 2021-10-08 11:22:53

Have you thought about it, you can become a developer. Yes, it's true. There are several schools that offer programming courses for aspiring developers to study at the comfort of their own homes. It may seem simple but with course planning and preparation you will find that studying on your own is not as easy as it looks. But if you want to learn how to become a developer the right way then you need to be prepared to take a vacation from work for a while.

Before you start mastering a new profession, you should think seriously about whether you really need it. Becoming a developer is not the same as watching all the episodes of [Avatar Netflix](https://thegww.com/exclusive-netflixs-avatar-the-last-airbender-plot-and-character-descriptions/) series filmed in a row. Both activities take a lot of time, but the effort required is not comparable. You may have to give up not only vacations, but also many of the usual things.

I have a question, do you really like software development? Do you enjoy solving problems, building tools and improving functionality? If you are not enjoying what you are doing then are you happy working in an office full of other software developers? Well, most software developers probably wouldn't be either.

It's been said that most successful software engineers aren't happy in a traditional workplace. It's been said that for them the work environment has become non-relevant, mundane, and uninspiring. In fact most successful software engineers prefer to build websites and tools in their spare time. There are a number of reasons why these successful programmers and designers would prefer to build no-code and low-code solutions in their free time.

There's also the fact that successful software developers are highly skilled. They know how to write good code, how to optimize their code and how to test it so they get high-quality products. They also know where the best resources are and how to get them without having to spend too much time hunting them down. Most developers also enjoy working on teams and building relationships with others in the software development community.

Another thing that you need to understand about being a successful programmer is that you have to be good at problem solving. If you're a good programmer and an excellent designer, you already have enough advantages. However, if you don't mind dealing with problems and solving them, you'll always find a niche in the world of programming language and internet technology. And once you have a niche, you can become a very successful and versatile developer. The developers who succeed today are those who have the ability to use multiple programming languages effectively and efficiently.
Add Power Off and Reboot to grub menu
Tags: grublinux
Published: 2021-10-17 04:57:04

To add **Power Off** and **Reboot** options to grub menu, you need to update a file in your grub configuration directory.

<br>

```bash
cd /etc/grub.d
```

<br>

### Open `40_custom` in your favorite editor

For me its `micro` :

<br>

```bash
micro 40_custom
```

<br>

### Add following line at the end of the file

<br>

```bash

 menuentry "Reboot" {
	  reboot
}

menuentry "Power Off" {
	  halt
}

```

> Do not change the `exec tail` line in the file

<br>

### Update your `grub.cfg` file

<br>

-   For Debian based distros

```bash
update-grub
```

-   For Arch based and Other distros

```bash
grub-mkconfig -o /boot/grub/grub.cfg
```
Using Array.prototype.reduce()


Published: 2021-10-17 04:51:29

The Array.prototype.reduce() method is an immutable JavaScript array iteration method that executes a callback function on each element of the array, resulting in a single output value.  


#### **Syntax**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tla8otaprlnlv7uzd9w1.png)


#### **Parameters**
CALLBACKFN
A “reducer” function that takes four arguments:
1. previousValue 
2. currentValue 
3. currentIndex *(Optional)*
4. array *(Optional)*

#### **Explanation**
Perhaps the easiest way to understand case for reduce() is to return the sum of all the elements in an array.

The reducer walks through the array element-by-element, at each step adding the current array value to the result from the previous step (this result is the running sum of all the previous steps) — until there are no more elements to add.

This is shown in the following interactive example:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyrf4u4m5v4c4c7ojt5b.png)


#### **Usage**
The reduce() method executes a reducer function for each value of an array.

reduce() returns a single value which is the function's accumulated result.

reduce() does not execute the function for empty array elements.

reduce() does not change the original array.







#### **Conclusion**
The reduce() method executes a callback function on each element of the array, resulting in single output value.  Though the values in the arrays in the 2 case studies are the same, their return values are different. Hence, in order to avoid errors, It is always safe to provide an initial value for the reduce() method.
We can only keep learning if we keep teaching (100 Bytes Of Wisdom: Day 72)
Tags: career, journey, advice
Published: 2021-10-17 04:43:16

---
title: We can only keep learning if we keep teaching (100 Bytes Of Wisdom: Day 72)
published: true
description: Bytes of Wisdom is a new project by Sam Jarman that brings together snippets of advice for software engineers
tags: career, journey, advice
//cover_image: https://direct_url_to_image.jpg
---

![We can only keep learning if we keep teaching](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzgcrlswv0n5uf3gkhfi.png)

Tech is a field where learning is a constant, however, I'd go further and say that this means you should always be teaching. If you learn something well enough you should be able to teach it. And without folks teaching others, how were you able to learn in the first place? This field benefits so much from an awesome few doing a lot of teaching, and you should be both grateful but also try to do your part, too. Whether it be a full blown blog or even just some one-on-one time with a colleague. For as long as learning will be essential in software, teaching will be, too.

Heads up: As with any terse bit of advice, there will be exceptions of course, and subtleties and nuance that can't possibly be captured in a Byte of Wisdom. This has been what I've experienced, I'd love to hear yours in the comments too!

You can catch up with all the ther bytes at http://bytesofwisdom.com/
Type of function
Tags: javascript, beginners
Published: 2021-10-17 03:27:07


Using a `function` is a good way to contain spesific task so you can call it whenever you need, In simple term `function` is a block of code that is design to perform spesific task. Usually structure of function look like this

```js
function functionName(argument_1, argument_2, argument_n){ 
// code to be executed 
}
```

There are various type of functions that you can use depending what your need

### Named functions

Create function by giving it name, this is the most common way to create a function

```js
function Add(num1,num2){
    return num1+num2
}
Add(2,3)
```

### Imediate Invoke functions

Call a function as soon as they are declared, the benefit of this function is no variable are created so doesn't take up space in the global object or global memory

```js
(function(num1,num2){
    return num1 + num2
})(2,3);
```

### Anonymous functions

It's the opposite of named functions, a functions without a name, however unlike Immediate invoke functions anonymous function are not executed as soon as they declared.

Usually we need anonymous functions when function is very short in size or when passing a function as an argument to another function such as inside `setInverval`

```js
var sum = function(num1,num2) { return num1 + num2}
sum(2,3)

```

### Recursive functions

A function that keeps calling itself until the conditions is failed

```js
function countDown(number){
    console.log(number)
    var newNumber = number -1;
    if(newNumber > 0){
        countDown(newNumber)
    }
}
countdown(4)
```

### Method

Function that are part of an object called method

```js
let person = {
    firstName:'John',
    lastName:'Snow',
    fullName:function(){
        return `${this.firstName} ${this.lastName}`
    }
}
person.fullName()
```
Divtober Day 16: Snow
Tags: codepen, divtober, css, art
Published: 2021-10-17 04:37:35

---
title: Divtober Day 16: Snow
description: Two entries for the 16th day of Divtober: snow.
published: true
tags: codepen,divtober,css,art
series: divtober
---

I did two different entries for snow:

- One that will make your computer fan work like it has never been working before
- Another that would be 1,000 easier and better in SVG (again!)

I'll put the one that requires a lot of CPU at the bottom, in the hopes that if you don't scroll down, it won't load and mess things up with your computer. It's basically a single-element snow fall effect with CSS.

But first: a sad (but kind of cute) abominable snow man:

{% codepen https://codepen.io/alvaromontoro/pen/ExvPOGo %}

And now the snow fall: 

{% codepen https://codepen.io/alvaromontoro/pen/WNErYxV %}

It has to be possible to simplify the snowfall so it doesn't require so many things (and maybe then, it will go smoother)
Closure (Concept)
Tags: swift, closure, ios
Published: 2021-10-17 03:51:52

Closure is very important basic concept in Swift.
And many iOS API are using closure syntax.
Let's see Closure for basic concept.

##Definition 
* Closure is function without name (Anonymous function)
* Closure can be passed / used to argument of function

####*Syntax*
```swift
{
  (Parameters) -> (ReturnType) in 
    Statements
}

//Example
{
  (a: Int, b: Int) -> (Int) in
    a + b
}
```

___
___
##Function vs Closure
> Function has “Name” ——— Closure doesn't
```swift
func myFunction(parameter1, prameter2) -> (ReturnType) {
  Statements
}

//Step 1. Remove "func" Keyword and "function name"
(parameter1, prameter2) -> (ReturnType) {
  Statements
}

//Step 2. Move all to curly brace with "in" keyword
{ (parameter1, prameter2) -> (ReturnType) in
  Statements
}
```
> Function has “Argument labels” ——— Closure doesn’t (But can have parameter names)
```swift
func myFunction(argumentLabel parmeter:) //but Closure cannot use argumentLabel as above
```
> Function has “Default parameter value” ——— Closure doesn’t
```swift
//myFunction and default value for parameter2
//but Closure cannot have defualt value for parameters
func myFunction(parmeter1: Int, parmeter2: Int = 0) 
```
> But Closure can be used “Inline"
```swift
//first parameter addValue is closure format(anonymous function)
func addTwoInteger(addValue: (a: Int, b:Int)->Int, a: Int, b: Int) {  
  print(addValue)
}

//Example
addTwoInteger( 
{ (a: Int, b: Int) -> Int in a + b },     //iniline closure
3, 2 )
```


___
___
##Short Syntax - Let’s make Closure more simple !!!
```swift
//we declare custom type which is closure
typealias OperateType = (a: Int, b:Int) -> Int
```
> Step1. Basic syntax
```swift
let myClosure = { (a: Int, b: Int) -> Int in
  a + b
}
```


> Step2. Declare variable explicitly then compiler could know "a" is Int,  "b" is Int and "return type" is Int also. So we can remove data types "Int" from parameters and return type
```swift
let myClosure: OperateType = { (a, b) in
  a + b
}
```


> Step3. Also compiler could know "a" and "b" parameter from definition of OperateType too. So remove "(a, b)" and "in" keyword
```swift
let myClosure: OperateType = { a + b }
```



> Step4. Based on Swift common syntax, we can use $0 instead first parmeter "a" and $1 instead second parmeter "b"
```swift
let myClosure: OperateType = { $0 + $1 }
```

> Call Closure
```swift
myClosure(3, 4)
```


___
___
##What is trailing Closure ? - When Closure is located as last parameter of function !
```swift
// See below function, myClosure is "last parmetter"
func myFunction(a: Int, b: Int, myClosure: (a: Int, b:Int) -> Int){
  print(myClosure)
}

//You can call as below
myFunction(3, 4, { a, b in a + b } )
//or call by simple sytax
myFunction(3, 4, { $0 + $1 } )
//When closure is placed as last parmeter, we can pull out after close parentheses
myFunction(3,4){ $0 + $1 }
```

___
___
###Yeah~~~ Done !!!
Should Remember Module in Go
Tags: tutorial, beginners
Published: 2021-10-17 03:41:31

The important should me know in learn go that's it about golang modules, 
let we try to remember how to create simple golang modules 
first we create folder in our directories
create folder
```
mkdir go-modules
cd go-modules
```
okay we already create folder and in folder go-modules
and than we will create module into my github
```
go mod init github.com/AnggaChelsea/go-modules
```
go.mod will created 
now we will try use go get for get http request in our go-modules project 
```
go get github.com/julienschmidt/httprouter
go get go.uber.org/zap
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yypo8ja1wmxnxbutzrgd.png)

Now we already create go.sum in our project go-module
we can check our go.sum using terminal
```
cat go.sum
```
we will found httprouter, request  


_Comment add more guys about modules from u_
MariaDB 10.6 and NextCloud: COMPRESSED Row is read-only by default
Tags: mariadb, nextcloud, openbsd, troubleshooting
Published: 2021-10-17 02:27:17

I upgraded [OpenBSD](https://www.openbsd.org/) 6.9 to [7.0](https://www.openbsd.org/70.html) yesterday.
It brought [MariaDB](https://mariadb.org/) upgrade: 10.5 to 10.6.
I checked `my.cnf` change and it seemed all right.
Nevertheless, trouble was found on a [NextCloud](https://nextcloud.com/) server using MariaDB on OpenBSD.

What happened was the failure of updating the package.
I connected to the NextCloud server with web browser. There wasn't the app dashboard, and the updater waited for being started instead. It meant `pkg_add -u` had failed to update NextCloud. Clicking the start button on the page ended up showing some exception had happened.

I read `nextcloud.log` in the server and got:

```
"level":3,
(...)
"Exception":"Doctrine\\DBAL\\Exception\\DriverException",
"Message":"An exception occurred while executing a query: 
SQLSTATE[HY000]: 
General error: 
4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.","Code":4047,
```

As to `COMPRESSED` row format, MariaDB is on the way to let it [Read-Only](https://mariadb.com/kb/en/innodb-compressed-row-format/#read-only) by "removing write support and deprecating the feature".
They introduced [`innodb_read_only_compressed¶`](https://mariadb.com/kb/en/innodb-system-variables/#innodb_read_only_compressed) option at [10.6.0](https://mariadb.com/kb/en/mariadb-1060-release-notes/) which was `ON` by default.

It was why updating NextCloud (from 21.0.4) to 21.0.5 on OpenBSD 7.0 failed. It was not because of OS or app version but the compatibility with MariaDB whose version is greater than or equal to 10.6.0.
There is an [open issue related to it](https://github.com/nextcloud/server/issues/25436) in the NextCloud [repo](https://github.com/nextcloud/server).

Well, I edited `/etc/my.cnf` temporarily to solve the problem:

```diff
  [mysqld]
  (...)
+ innodb_read_only_compressed = 0
```

Besides, I didn't find how to set it on a specific database or a table and even the possibility😅

I restarted `mysqld` in the server, and tried the updater on the web page again. After all, it was totally successful.

I appreciated the MariaDB documentation and several posts such as GitHub [issue](https://github.com/nextcloud/docker/issues/1536)s and blogs. They helped me a lot.
SpotBugs supports SARIF that helps integration with other SAST tools
Tags: sast, devsecops, spotbugs, java
Published: 2021-10-17 02:17:53

---
title: SpotBugs supports SARIF that helps integration with other SAST tools
published: true
description: This post shares what the SARIF is, and how to configure SpotBugs to generate SARIF report
tags: sast,devsecops,spotbugs,java
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hhnb7gqruufwmhh6fg6s.png
---

Are you using SAST tools? How many tools you're using? Just one? Then it's fine. A few? It's still working, probably. More? Welcome to one of difficulties of DevSecOps!

Currently, when we maintain a system, it's quite common to depend on multiple languages and ecosystems. If system is enough small, a one-stop SAST solution should be enough... but later you may find it's not enough.

Then how to integrate reports generated by multiple SAST tools, to grab the overview of your system? The [Static Analysis Results Interchange Format (SARIF)](https://sarifweb.azurewebsites.net/) could be a solution.

SARIF is an OASIS standard and an industry standard format for the output of static analysis tools. Configure each SAST tool to generate a SARIF report, then we can merge reports to get a simple overview of the service. The [GitHub Code scanning](https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning) is one example, it works as a dashboard of all SAST tools like below:

![GitHub Code scanning Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5g3d8101gtyv4q7as4rs.png)

## How to configure SpotBugs to generate a SARIF report

First, it's better to use SpotBugs 4.4.1 and above, that includes a [fix to make SARIF report compatible with Github code scanning API requirements](https://github.com/spotbugs/spotbugs/issues/1630).

If you use command line interface to run SpotBugs, append [`-sarif` option](https://spotbugs.readthedocs.io/en/latest/running.html?highlight=sarif#text-ui-options).

If you are using Gradle, configure tasks with `SpotBugsTask` to set `reports.sarif.enabled`:

```groovy
spotbugsMain {
    reports {
        sarif {
            enabled = true
        }
    }
}
```

If you are using Maven, configure the plugin with `<sarifOutput>true</sarifOutput>`:

```xml
      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
        <configuration>
          <sarifOutput>true</sarifOutput>
        </configuration>
      </plugin>
```

Refer to [spotbugs/spotbugs-gradle-plugin](https://github.com/spotbugs/spotbugs-gradle-plugin) as a living example with GitHub Code scanning integration.

Hope that this guide helps you to find new way to handle SAST tool reports, and make your hacking awesome!
How to setup Postcss, Tailwind, React, and Webpack from Scratch
Tags: webpack, react, tailwindcss, postcss
Published: 2021-10-17 02:03:53

I want to create a shared react component for a monorepo with tailwindcss. However, while reading the document, it was found that tailwind uses craco. Meanwhile I want to use webpack. And it definitely doesn't suit my needs. So I searched everywhere, to find setting everything up from scratch. 

```
.
├── babel.config.js
├── package.json
├── postcss.config.js
├── src
│   ├── App.js
│   ├── index.css
│   ├── index.html
│   └── index.js
├── tailwind.config.js
└── webpack.config.js
```

The following are some of my notes. I hope this helps people with similar needs to mine.

- ### [How to integrate postcss and webpack](https://dev.to/ynwd/how-to-integrate-postcss-and-webpack-ed5)
Step by step about how to use postcss & postcss-cli. And then integrate them with webpack from scratch. It will be used when using tailwind.

- ### [How to integrate tailwind and webpack](https://dev.to/ynwd/how-to-integrate-tailwind-and-webpack-525d)
This is a basic foundation setup, for using tailwind in webpack. It will be used when using react.


- ### [How to integrate tailwind, react and webpack](https://dev.to/ynwd/how-to-integrate-tailwind-react-and-webpack-2gdf)
Step by step how to use tailwind together with react and webpack. It will be used when create shared components.

- ### [How to setup react shared components in monorepo with tailwind, webpack and npm workspace](https://dev.to/ynwd/how-to-setup-react-shared-components-in-monorepo-with-tailwind-webpack-and-npm-workspace-570n)
Set up the react-tailwind shared component in a monorepo. It will be used when you have some modules with same components.
How to Install Redis (MacOS)
Tags: redis, installation, macos
Published: 2021-10-17 01:50:25

Hallo since i'm hard to find article, and it's separated from one article to another. I wrote this to make easy installation of redis on `MacOS`

First of all, we need install homebrew on our mac. this link will guide you to install [Homebrew](https://dev.to/harizinside/how-to-install-homebrew-macos-1bia)

## Installation Redis

```sh
$ brew install redis
```

To make our redis run on background you'r just need copy and execute this script

```sh
$ brew services start redis
```

To make sure your redis good to go copy and execute this script

```sh
$ redis-cli ping
PONG
```

Well it's Pong return your ready to rock.
To make secure password on redis you can edit configuration and type some secret just like this.


```sh
$ nano /usr/local/etc/redis.conf
```

> find 
> requirepass : foo 
> and change to 
> requirepass : <your security key>

And restart your redis service

```sh
$ brew services restart redis
```

Now your good to go ☕️