teleren/devto huggingface dataset:
มาลองทำ gorm repository โดยใช้ Go Generics กันครับ
Tags: go, programming, database
Published: 2023-01-12 10:42:42

ปกติแล้วเวลาเราจะทำ service ซักตัว เราจะพบว่าในหลาย ๆ table นั้น จะมีการใช้คำสั่ง query ที่ค่อนข้างจะเป็นรูปแบบที่ซ้ำ ๆ กัน เช่น การทำ CRUD service ก็จะเป็นการ Create, Find, Update, Delete อะไรทำนองนี้ ซึ่งใน level ของการทำ repository ในโปรเจคเรานั้น หากมีหลาย table ก็อาจจะต้องมีการทำ repository ในหลายรอบที่ต่างออกไป แต่รวม ๆ แล้วคำสั่งข้างในก็จะคล้าย ๆ กัน

วันนี้เราเลยจะมาลองทำให้มี repository แค่หนึ่งไฟล์ แต่ใช้ได้กับหลาย ๆ models หรือหลาย ๆ table กันครับ โดยใช้ gorm กับ go generic กันครับ

มาดูโค้ดในส่วนของ repository กันครับ

{% embed https://gist.github.com/nanpipat-dev/399d4d4168d96610209919f81c4b74c7 %}

อธิบายโค้ดเพิ่มซักนิดนึงครับ ตรง function `NewRepository` คือการเรียกใช้ repository นี้ โดยการโยน models ใดก็ได้เข้ามา (go generic)

และหลังจากนั้นผมจะสร้าง function อื่น ๆ เพิ่ม เช่นการ `Create` , `FindAll` พวกนี้คือการ override function ของ gorm เข้าไป โดยคุณอาจจะไม่ต้องตั้งชื่อตาม gorm ก็ได้ แต่ผมค่อนข้างจะชินในการตั้งแบบนี้ เพราะเวลาอ่าน document ของ gorm จะได้เอามาปรับใช้ได้เลยง่าย ๆ

ส่วนถัดมาก็คือส่วนของ condition ต่าง ๆ เช่น `Where` , `Order` และอื่น ๆ ก็จะทำคล้าย ๆ กัน เพียงแค่การ return จะไม่เหมือนกัน เพราะเราสามารถทำได้หลาย ๆ condition มันจึงจะ stack ไปเรื่อย ๆ มากกว่า

โดยการทำ function เหล่านี้ คุณสามารถ custom parameter ที่รับเข้ามาและส่งออกไปได้เลย ทำได้หลากหลายมากมาก ผมอาจจะไม่ได้ยกตัวอย่างที่แปลก ๆ ไว้ เพราะอยากให้เห็นภาพการใช้ go generic ในการรับ type อะไรเข้ามาก็ return สิ่งนั้นออกไปครับ

โอเคครับ ทีนี้มาถึงโค้ดตอนนำไปใช้ จะหน้าตาเป็นแบบนี้

{% embed https://gist.github.com/nanpipat-dev/e852ff6f84d2750b5c720521ae8bd6dc %}

โดยผมจะไม่อธิบายถึงการ inject db เข้ามา หรือการวาง stucture ของโปรเจคนะครับ เพราะคิดว่าแต่ละคนคงมีรูปแบบที่ไม่เหมือนกัน อันนี้ก็จะเป็นตัวอย่างคร่าว ๆ โดยค่า db ที่ผมส่งไปก็จะเป็น type gorm.DB ตามที่ repository ของเราต้องการ และก็อีกค่าเป็นค่า context ที่เราอาจจะต้องใช้ถ้าเราใช้กับ framework หรือ third-party ที่เราอยากจะส่ง context ไปใช้นะครับ

ซึ่งทั้งหมดจะเป็นแค่ concept คร่าว ๆ ในการทำ go generic มาใช้กับการทำ gorm repository คุณสามารถ custom มันเองได้ทั้งหมดตามแต่ที่คุณต้องการครับ

https://github.com/nanpipat-dev/gorm-generic-repository

อันนี้จะเป็นลิ้ง git ที่ผมทำไว้เป็นตัวอย่างสำหรับบทความนี้ครับ หากมีข้อสงสัยหรือมีข้อติติงตรงไหนคอมเม้นบอกได้เลยครับ ขอบคุณที่อ่านมาจนจบครับ 🙏🏻
Shell oneliner to generate passwords
Tags: password, generate, oneline, shell
Published: 2023-01-12 10:38:19

```shell
# 10 character random string from specified alphabet
< /dev/urandom tr -dc '[:graph:]' | head -c10; echo
```

Bash allows redirections at any part of command, so `< file command args` above is same as `command args < file`.



Examples:
```
KrvJz?TgbO
T[7/9Lg9L9
bp[je2Og*l
93:m_Ss$z5
C}Z=-Nj-mn
mG<85C>!i~
%>7/]AWpMd
```

If you do not want so many special characters, you may use something like: `'[:alnum:]_$#%-'`
```
JCPHawXEvr
orq#0S7cUk
82H7g_cHtY
um-#ACmny4
dYQFqGsX_d
```
50 Followers Milestone: A New Beginning for Computer Science Pillars
Tags: computerscience, programming
Published: 2023-01-12 10:32:01

I am excited to announce that I have just achieved the milestone of 50 followers on my blog! I am incredibly grateful to each and every one of you for your support and encouragement. To show my appreciation, I have decided to write a series of articles about the pillars of computer science.

As a computer science enthusiast, I believe that understanding the fundamental principles of the field is crucial for anyone looking to build a career in this field. These principles, or "pillars," include topics such as algorithms and data structures, programming languages, computer architecture, and artificial intelligence.

In the coming weeks, I will be writing a series of articles that explore each of these pillars in depth. I will be sharing my own experiences and insights, as well as providing examples and resources that will help you to better understand these concepts.

But I wouldn't be able to do this without the support of my followers. Your encouragement and feedback have been instrumental in helping me to grow as a writer and a computer scientist. I am truly grateful for each and every one of you, and I hope that you will continue to follow me on this journey.

To sum up, I am excited to announce that I have reached the milestone of 50 followers and to celebrate that, I will be writing a series of articles about the pillars of computer science. I would like to take this opportunity to thank each and every one of my followers for their support and encouragement. I look forward to sharing my knowledge and experiences with you, and I hope that you will continue to follow me as I explore the world of computer science!
Make Your Business Smarter in 2023 with Cloud-Based Document Management System
Tags: webdev, programming, startup
Published: 2023-01-12 10:30:03

82% of employees believe that poor content management negatively impacts productivity.

Considering this situation, it becomes inevitable for every large enterprise to have a successful solution to cope with the content chaos.

The Document Management System is the impetus for the process from lucrative supply chains to commercial contract management.

Document Management System is the savior for companies looking to reap such benefits.

But, building it is not a walk in the park.

You need the right development company that comprehends your need for the right customized Document Management System product.

## How does a Document Management System benefit your Business?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owzsrj48m50i0j67ruki.jpg)
- It helps you to keep up with all the information
- It makes it easier to streamline the content process and consequently saves you time. 
- It concedes real-time accessibility and problem-solving
- It minimizes risk by enforcing security policies
- It favors more impeccable teamwork with critical document version control
- It automates manual tasks like photocopy, drag-and-drop, and hand delivery
- It unlocks financial gains by effectively reducing operating costs

## Features to consider while developing Document Management System

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2enx8hw742z8qwqp9j3.jpg)
The fundamental features of any Document Management System will remain the same, no matter the type of enterprise. Here are such features that need to be considered as must-haves while building your custom Document Management System.  

1. Automation
2. eSignature
3. Email Alert
4. Offline Access
5. Files Management
6. Aggregate Search
7. Record Management
8. Secure Alliancing
9. Subscription Plans
10. Collaborative Editing
11. Custom Domain for Branding
12. Optical Character Reader (OCR)
13. Third-party Software Integrations
14. Co-opting with the current system

All these features fabricate one needed solution viewed as a technology system, having a price quotation associated with it.

🚀 Continue Reading: https://bit.ly/3GXOPDB
Date and math
Tags: javascript, webdev, beginners, tutorial
Published: 2023-01-12 10:15:04

hey friends today we are gonna learn about date math array and array methods

##Dates

it is a built in JavaScript function to get a date so that it could be used in day to day operations. The most general syntax is shown below
 
 ```
 console.log(Date()); 
```

output:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xbz51ga5u90hlnmbryq.png)

but it is better to use new Date() because it returns a date object which can be used for various operations.

there are four ways of creating a date they are :

new Date(): this is similar to shown in above example

new Date(milliseconds): this give no of milliseconds from Jan 1, 1970 

example :

``` 
console.log(new Date(10000000000))
```

output :


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

new Date(dateString):  When one string argument is passed, it is a string representation of a date.

example: 
```
console.log(new Date("2015-03-25"));
```

output:

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

new Date(DateObject):
this creates a date object with the specified date and time.

example:

```
console.log(new Date(2023, 1, 10, 16, 33, 30, 0));
```

output:

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

##date methods getting dates

###getDate()

Returns the day of the month (from 1-31)

example:

```
const d = new Date();
console.log(d.getDate());
```

result:


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

other examples include getYear() getMonth() etc.

##math 

it is a built-in object whose purpose is to give user mathematical constants and operations by help of built in functions.

##math properties

all the properties and methods of math are static hence they are called as static properties and static methods.

based on browser and operating systems these values can sometimes vary a little bit.

###static properties 
these are the properites that give you the values of constants. The examples can be seen below.

example: 
```
const mat = Math.PI;
console.log(mat);
```

output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5n3ejkmzxjoq1928cb63.png)

as seen in the above example the above code gets you the value of constant pi.

###static methods

 these are the methods that return you the value based on the method applied which is seen in the bellow example 

example :

```
const random = Math.random() * 10 ;
console.log(random);

``` 
 
math.random() method gives you the number randomly between 0-1.
 
output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cxvx9w9xazgvlwiwcow.png)

more properties and methods of math can be seen in mdn docs .
Date and math
Published: 2023-01-12 10:11:57

hey friends today we are gonna learn about date math array and array methods.

##Dates

it is a built in JavaScript function to get a date so that it could be used in day to day operations. The most general syntax is shown below
 
 ```
 console.log(Date()); 
```

output:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xbz51ga5u90hlnmbryq.png)

but it is better to use new Date() because it returns a date object which can be used for various operations.

there are four ways of creating a date they are :

new Date(): this is similar to shown in above example

new Date(milliseconds): this give no of milliseconds from Jan 1, 1970 

example :

``` 
console.log(new Date(10000000000))
```

output :


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

new Date(dateString):  When one string argument is passed, it is a string representation of a date.

example: 
```
console.log(new Date("2015-03-25"));
```

output:

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

new Date(DateObject):
this creates a date object with the specified date and time.

example:

```
console.log(new Date(2023, 1, 10, 16, 33, 30, 0));
```

output:

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

##date methods getting dates

###getDate()

Returns the day of the month (from 1-31)

example:

```
const d = new Date();
console.log(d.getDate());
```

result:


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

other examples include getYear() getMonth() etc.

##math 

it is a built-in object whose purpose is to give user mathematical constants and operations by help of built in functions.

##math properties

all the properties and methods of math are static hence they are called as static properties and static methods.

based on browser and operating systems these values can sometimes vary a little bit.

###static properties 
these are the properites that give you the values of constants. The examples can be seen below.

example: 
```
const mat = Math.PI;
console.log(mat);
```

output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5n3ejkmzxjoq1928cb63.png)

as seen in the above example the above code gets you the value of constant pi.

###static methods

 these are the methods that return you the value based on the method applied which is seen in the bellow example 

example :

```
const random = Math.random() * 10 ;
console.log(random);

``` 
 
math.random() method gives you the number randomly between 0-1.
 
output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cxvx9w9xazgvlwiwcow.png)

more properties and methods of math can be seen in mdn docs .
🚀 Deploying a React App on Netlify Using GitHub
Published: 2023-01-12 10:11:44

React is a popular JavaScript library for building user interfaces, and Netlify is a powerful platform for deploying and hosting web applications. In this article, we will show you how to deploy a React app on Netlify using GitHub, in a step-by-step, easy-to-follow format.

## Prerequisites
Before we begin, you will need to have the following:

- A GitHub account
- A Netlify account
- A React app ready to be deployed

## Step 1: Create a GitHub Repository
The first step in deploying your React app on Netlify is to create a GitHub repository for your app. This will be the place where your app's code will be stored and managed.

To create a new repository on GitHub, go to the GitHub website and log in. Once logged in, click on the plus icon in the top-right corner of the screen, and select "New repository". Give your repository a name, and make sure it is set to public.

Once your repository has been created, you will be taken to the repository's main page. Here, you will see instructions on how to upload your code to the repository.

## Step 2: Push Your Code to GitHub
The next step is to push your React app's code to GitHub. This can be done using the command line, or through the GitHub website.

If you are using the command line, navigate to your app's root directory in your terminal, and use the following commands:

```
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/username/repository-name.git
git push -u origin master

```
Make sure to replace "username" and "repository-name" with your own GitHub username and repository name.

If you prefer to use the GitHub website, you can simply drag and drop your app's code into the "Upload files" section of the repository's main page.

## Step 3: Connect Netlify to GitHub
Now that your code is on GitHub, we can move on to connecting Netlify to your GitHub repository.

To do this, log into your Netlify account and click on the "New site from Git" button. Next, select "GitHub" as your provider, and select your repository from the list.

Once connected, Netlify will automatically detect that your app is built with React, and will configure the build settings accordingly.

## Step 4: Deploy Your App
The final step is to deploy your app on Netlify. To do this, simply click on the "Deploy site" button on the Netlify dashboard. This will start the build process, which may take a few minutes to complete.

Once the build is complete, you will be provided with a link to your live app. You can also configure custom domains, HTTPS and other features.

## Conclusion
Deploying a React app on Netlify using GitHub is a quick and easy process. By following the steps outlined in this article, you should be able to deploy your app in no time. If you are looking for a highly skilled and experienced React developer to help you build or maintain your app, consider hiring a [React developer](https://ultroneous.com/reactjs-development). In the event you want to update your app, simply make your changes, push them to GitHub, and Netlify will automatically detect the changes and build your app.
Drop [almost] all outbound mail in postfix for tests
Tags: postfix, testing, mailman, blackhole
Published: 2023-01-12 10:04:40

## Why to drop mail?
While troubleshooting mailman installation, I've come to a problem: I need to do many tests, but I do not want to disturb recipients of maillist with dozens of test messages. I do not know, if mailman3 has any feature for this kind of testing, but postfix has. 


## How to drop postfix mail except to whitelisted addresses
First, make sure, you have transport map enabled.

Usually, this line could look like this:
```
transport_maps = hash:/etc/postfix/transport
```

Now, create other transport file, my /etc/postfix/blackhole:
```
mydomain.net :
mymailbox@gmail.com :
* discard:
```
With this config postfix will deliver to *@mydomain.net and to mymailbox@gmail.com. 


run `postmap blackhole` to generate /etc/postfix/blackhole.db.

add it to postfix transport with comma (if you already has transport map):
```
transport_maps = hash:/path/to/other/transport/map, hash:/etc/postfix/blackhole
```
(or as single element, if you had no transport_maps).

Restart postfix: `postfix reload`. You're ready.


### Testing
I sent few mails  and here is what I have in logs:
```
Jan 12 09:53:17 list2 postfix/smtp[62239]: DB97418C0808: to=<mymailbox@gmail.com>, relay=gmail-smtp-in.l.google.com[173.194.76.27]:25, delay=0.41, delays=0.03/0.02/0.14/0.22, dsn=2.0.0, status=sent (250 2.0.0 OK  1673517197 g15-20020a056000118f00b002bdd88acc3dsi514695wrx.503 - gsmtp)

Jan 12 09:53:34 list2 postfix/discard[62251]: 7943118C0808: to=<test@test.com>, relay=none, delay=0.02, delays=0.02/0/0/0, dsn=2.0.0, status=sent (test.com)
```

First is log line for real delivery (`relay=` remote mailserver) and second is log line for blackhole delivery, `relay=none`).
Docker image build pipeline for a .NET Core application using Jenkins
Tags: jenkins, devops, docker, dotnet
Published: 2023-01-12 09:58:02

Hello, tech enthusiasts!

I have just written a guide on how to set up a Docker image build pipeline for a .NET Core application using Jenkins. The guide covers everything from Installing Jenkins, setting up a project, configuring the source code management, to building and deploying the Docker image.


https://www.devninja.fr/docker-image-build-pipeline-for-a-net-core-application-using-jenkins/


I hope that you find this guide helpful, If you have any questions or feedback, please do not hesitate.
CATIA Training in Chennai
Tags: catia, webdev, beginners, programming
Published: 2023-01-12 09:44:35

The best Catia training is provided by IntelliMindz in Chennai by highly qualified professionals. Our instructors have worked in MNCs for many years in Catia and associated technology. To meet both industrial demands and more practical needs, we are offering **[Catia training in Chennai](https://intellimindz.com/catia-training-in-chennai/)**. Our Catia instructors will provide Catia classroom instruction, Catia online instruction, and Catia corporate training services. For both the entry-level and the most recent levels, we matched the syllabus to practical requirements. Depending on the needs of the participant, we do our training on either weekends or weekdays. India's Chennai is home to the top Catia training institute. It offers top-notch classroom instruction for courses in Catia surface design.
Use a help target in your Makefile
Tags: makefile, help, simplify
Published: 2023-01-12 09:36:56

In one of my previous [blog](https://binx.io/2021/09/27/make-your-life-easier-using-makefiles/). I wrote how you could make your life easier when you start using Makefile. But when you start using Makefile in many projects. The targets that you use may vary from project to project.

In this blog post I will address a trick how you could write a `help` target. Lets imagine that we have a project that allow you to `build`, `start` and `stop` a docker container. These names are pretty straightforward. But without looking in the Makefile you never know for sure.

By calling the `help` target you could list all available targets:

```bash
make help
```

![All targets are listed with a help text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k233xdjyunts6v5tpofy.png)

When you have a look at the Makefile used for this blog post. It looks like this:

```Makefile
.DEFAULT_GOAL:=help
.PHONY: help
help:  ## Display this help
	$(info Example Makefile for my blog post)
	awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: build
build: ## Build the container image
	docker build -t my-container:latest .

.PHONY: stop
stop: ## Stop the container
	docker stop my-named-container > /dev/null 2>&1 || True
	docker rm my-named-container > /dev/null 2>&1 || True

.PHONY: start
start: stop ## Start the container
	docker run --name my-named-container my-container:latest > /dev/null

.PHONY: shell
shell: ## Start a shell session on the container
	docker run -it my-named-container:latest bash

.PHONY: logs
logs: ## Tail the logs of the running container
	docker logs my-named-container -f

$(VERBOSE).SILENT:
```

You need to add the `help` target. And for each target you need to supply a help text. And each target needs a prefix with `##`.

By adding a `help` target to your Makefile you make it easier to use for others. But also for yourself because you don't need to remember each target in the Makefile.

Photo by [lalesh aldarwish](https://www.pexels.com/photo/man-s-hand-in-shallow-focus-and-grayscale-photography-167964/)
Managing Hybrid Teams 5
Tags: leadership, beginners, tutorial, management
Published: 2023-01-12 09:22:53

## 6. Remotely managing the performance

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

We think the fundamentals of how we create deep engagement are more crucial than ever in a hybrid context where we no longer work (some of us, at least) in the same area.

We employ the strength of Rosenberg's non-violent communication in difficult situations because it enables people to identify needs that aren't being met and to ask the other person to meet those needs without making assumptions.

We also think that having communication with your team member right away is the cornerstone of every engagement, whether pleasant or difficult. Here, you express your goals for the group and your own vision for it and invite each team member to do the same. What are they trying to accomplish, and how are you able to help?

The idea is to merge your objectives into a partnership that is codependent and advantageous to both parties. “How can you assist me in realizing my vision? How may I assist you in achieving your goals?” When a team member's activities no longer serve your goals or theirs, the answers to these questions serve as the foundation for managing performance.

#### In order to support managing performance remotely, try these three methods:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsbl45hljzf46f4v6rds.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl9a6jywzk0lrujldoi5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwclse0agar33x84mt86.png)

## 7. Navigating Change

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

This is important right now because organizations don't have set goals and easy ways to get there. Instead, they are exploring and learning. Change is all around you, and you're starting to get used to it. So, what are some key ways to address the fact that things change all the time, and the reality is nothing but constant change?

#### Try one of these three ways to help you manage change:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvk55vblp2e8pnyvc8z1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbv3yofihq4mnabf8gio.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsdmkhppyvh45g3qijki.png)