teleren/devto huggingface dataset:
Go generics ใน gin Handler
Tags: go
Published: 2022-07-31 09:04:01

เนื่องจาก Go 1.18 เริ่มใช้ generic แล้ว ซึ่งใน block ก่อนหน้านี้ ผมก็นำเอา blog ต้นฉบับของ contributors มาแปลคร่าวๆให้ได้อ่านกัน ทำให้ได้รู้ usecases ของการใช้ generic ว่าปกติจะใช้กับ ฟังก์ชั่นที่ ทำงานกับ map, slice หรือ channel เป็นหลัก และเอาจริงๆ หลายๆ usecases ที่คิดกันออกมา มันอาจจะทำงานกับ interface ได้ดีกว่า ที่จะพยายามยัดเยียดเอา generic ใส่เข้าไปเพื่อความเท่

วันนี้ก็เลยลองใช้ generic มาช่วยในการสร้าง gin HandlerFunc เพื่อให้เราสามารถเขียน handler ได้ง่ายขึ้นด้วยหน้าตาประมาณนี้

```go
func Handler(request) (response,error)
```

ประโยชน์ก็คือ มันจะช่วยให้เราเขียนเทสให้ handler ง่ายขึ้น โดยไม่ต้อง mock gin.Context

โดยเราจะวางโครงสร้างโปรเจ็คเราแบบนี้

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

- domain ภายในนี้จะเป็นที่รวม business logic ทั้งหมด
- ginhandlerfunc เป็น converter ที่จะช่วยแปลง handler แบบที่เราอยากได้ ไปเป็น gin.HandlerFunc

เรามาดูหน้าตาของ handler ที่ทำเสร็จแล้วกันก่อนว่าจะมีหน้าตาแบบไหน

```go
type CustomerRequest struct {
	Name string `json:"name"`
}
type CustomerResponse struct {
	Name string `json:"name"`
}

func CustomerHandler(request CustomerRequest) (CustomerResponse, error) {
	fmt.Println("CustomerHandler", request)
	return CustomerResponse{Name: request.Name}, nil
}

func New() gin.HandlerFunc {
	return ginhandlerfunc.NewBindRequestOKResponse(CustomerHandler)
}
```

ซึ่งเมื่อได้ code หน้าตาแบบนี้แล้ว เวลาเราจะเขียน business logic ก็เขียนแค่ใน CustomerHandler ได้เลย

ทีนี้เราลองมาดูใน ginhandlerfunc.NewBindRequestOKResponse กันว่ามีวิธีเขียนอย่างไร

```go
func NewBindRequestOKResponse[Request, Response any](handler func(Request) (Response, error)) gin.HandlerFunc {
	return func(c *gin.Context) {
		var request Request
		if err := c.ShouldBindJSON(&request); err != nil {
			c.AbortWithError(http.StatusBadRequest, err)
			return
		}
		response, err := handler(request)
		if err != nil {
			c.AbortWithError(http.StatusInternalServerError, err)
			return
		}
		c.JSON(http.StatusOK, response)
	}
}
```

นี่ก็คือหน้าตาของมัน โดยเราใช้ generic เข้ามาช่วยในส่วนการประกาศ Request และ Response ให้ ซึ่งวิธีนี้จะทำไม่ได้หากไม่มีการใช้ generic เข้ามาช่วย
และสามารถไปดู ตัวอย่างที่มากกว่านี้ได้ที่ [https://github.com/pallat/generic_gin_handler](https://github.com/pallat/generic_gin_handler)

ซึ่งจะมีตัวอย่างของ handler ที่รับ parameter ผ่าน URI Param และการสร้าง handler struct มาเป็น handler ของเราในกรณีที่ต้องมี dependencies อื่นๆ

นี่เป็นเพียงแค่โค้ดตัวอย่างเบื้องต้น หวังว่าจะเป็นประโยชน์ ไม่ว่าจะนำไปใช้ หรือสร้างแรงบันดาลใจให้เขียนท่าอื่นๆที่เหมาะสมกับสไตล์ของตัวเองกันนะครับ
Which language should we choose for data structure and algorithms?
Published: 2022-07-31 08:59:15


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

 If you are looking for the best language for data structure and algorithms, I would definitely recommend Python. It has a great community, which helps you understand the problems you are trying to solve. You can go through online tutorials and troubleshoot them too by yourself. There are many online courses available online that teach you coding in Python.

 Learning programming is not as difficult as people think it is, but making it enjoyable is! The best part about Python is that you can use it for both small and large-scale projects. It has a huge community of developers, who love to share their knowledge with others. There are so many resources available for learning Python, including some great books like “Learning Python” by Mark Lutz and David Ascher . The book is written in a very easy-to-understand format and covers all the aspects of Python. It has been updated for Python 3 as well, so you can use it to learn the latest version of Python.

 The best way to learn Python is by doing. So, before you go through any book or tutorial, try building your first project in Python and then use some resources to improve your skills further. 

You can also visit the official Python website and find a lot of resources there. The official documentation is very detailed and covers everything in great detail. You can also check out some of the other books on Python, including “Python Programming: An Introduction to Computer Science” by John Zelle, “Practical Python Projects” by Mark Lutz, David Ascher, and Laura Creighton .
The importance of canonical URLs
Tags: writing, seo, watercooler
Published: 2022-07-31 08:58:30

I noticed I'm always talking about canonical tags when advising fellow bloggers, but I never wrote this down on paper.

So here we go, an article explaining why you should always use canonical tags when republishing your content elsewhere.

Let's first set a use case.

You are reading this article from one of the following three sources.

- my blog (daily-dev-tips.com)
- hashnode
- dev.to

All these three sources have the same content.
Now our good friend Google comes into play, and it wants to help people find the correct answer to their questions.

Let's say your blog does just that. How does Google know which blog to redirect to?

If you don't provide a canonical tag, Google might even think you are spamming the internet and not showing any of the three sites!

However, you can use this canonical tag to set which site is the primary source for this article.

So what do I do, you ask?
I use my blog as my primary source of truth. It's what I want to rank on Google in the long term.

## Setting canonical URLs

So how do we set these canonical URLs

If you are not using a custom website as your primary source, you can set the canonical URL by adding the following tag in your HTML head.

```html
<link rel="canonical" href="https://daily-dev-tips.com/your-article-name" />
```

This will tell the search engines they can find the original content on the address you provide there.

Most blogging platforms offer a more visual way of adding these canonical tags.

For instance, on Hashnode, they have the following widget in the sidebar.

![Canonical URLs on Hashnode](https://cdn.hashnode.com/res/hashnode/image/upload/v1658425577924/z2vYxdgOu.png)

And the same kind of graphical element exists on dev.to.

![Dev.to canonical URL setting](https://cdn.hashnode.com/res/hashnode/image/upload/v1658426356680/4dbnmnorO.png)

A small side note is that my good friend Graham suggests you wait two weeks before reposting your content.
He says it could happen that Google will crawl Hashnode before yours and rank that content higher.

This is, in theory, true.
I don't follow the advice and have yet to experience this happen, but I want to put it out as a disclaimer, as multiple sources advise.

## Conclusion

Reposting content is a great way to reach a broader audience, but it can hurt your SEO if you don't use canonical tags.

Do use canonical tags to indicate to search engines which is your original content.

Do not mix the canonicals to link to different articles from different sources.

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
More on Number Systems: Working with Base Numbers: Part 2
Tags: beginners, computerscience, programming
Published: 2022-07-31 08:39:42

The [first part of this topic](https://dev.to/ayodejii/more-on-number-systems-working-with-base-numbers-part-1-4lk0) introduced and took us through number bases and converting them to base 10.
This post will explain what base 16 numbers are and how to convert from base 10 to other numbers.

**Hexadecimals**
This is base16. It is represented with numbers and alphabets A to F.
Beginners think it is a complex base because of the alphanumeric representation, but it is not, it is just like the other ones. The alphabet is just a way to make the numbers cleaner. They represent numbers 10-15 because 16 is the maximum number in this base.
For example:
9 base 10 is 9 in base 16
4 base 10 is 4 in base 16
10 base 10 is A in base 16
11 is B
15 is F
16 is 10
493 is 1ED
The reason for the inclusion of the alphabets is, HEX numbers get to tens of numbers in base 10. For example, the conversion of 493 gives `1 14 13` which is confusing because everyone would read 11413 at a glance, hence a way to make it clearer for readers: 1 E(14) D(13) i.e. 1ED 😀.

Colour white in CSS, #fff is a hexadecimal number, which, when converted, gives 4095. Wonder why colour codes are represented this way?

**Conversion of decimal numbers to other bases**
We learned last week that base 10 numbers are decimals. So let us see how to convert these numbers to other bases.
- 4 to base 2
- 11 to base 8
- 493 to base 16

In the last conversion from other bases to decimal, we used multiplication. Here, we are going to use division.
To convert a decimal number to another base, you keep dividing it by that base until you have 0 left and the remainder is less than that base then you read the remainder from bottom to top.

4 => 4/2 = 2 r 0
     2/2 = 1 r 0
     1/2 = 0 r 1
our answer is 100.

__11 to base 8__

11 => 11/8 = 1 r 3
      1/8 = 0 r 1
our answer is 13

__493 to base 16__
493 => 493/16 = 30 r 13
       30/16 = 1 r 14
       1/16 = 0 r 1
we have 1 14 13, which is 1ED in hexadecimal

To convert from a base other than decimal to another, you need to convert to decimal before you do the final conversion.

You can do these conversions on your calculator, but I like to think it is a good practice to understand how things work under the hood.

Enjoy. 🚀
Analyze React App Size
Tags: react, npm
Published: 2022-07-31 08:15:51

[Source map explorer](https://www.npmjs.com/package/source-map-explorer) analyzes JavaScript bundles using the source maps. This helps you understand where code bloat is coming from.

To add Source map explorer to a Create React App project, follow these steps:

```jsx
npm install --save source-map-explorer
```

Then in `package.json`, add the following line to `scripts`:

```jsx
"scripts": {
+    "analyze": "source-map-explorer 'build/static/js/*.js'",
     "start": "react-scripts start",
     "build": "react-scripts build",
     "test": "react-scripts test",
```

Then to analyze the bundle run the production build then run the analyze script.

```jsx
npm run build
npm run analyze
```

Reference : [https://create-react-app.dev/docs/analyzing-the-bundle-size/](https://create-react-app.dev/docs/analyzing-the-bundle-size/)
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-07-31 08:00:10

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258b924543.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
A programmer's significant other tells them, "Run to the store and pick up a loaf of bread. If they have eggs, get a dozen."

The programmer comes home with 12 loaves of bread.
 -->
Easy to customise frontend UI library
Tags: programming, webdev, javascript, beginners
Published: 2022-07-31 07:52:47


I have used more than 10 UI libraries and each of have a time-consuming process to customise the styles except 
@mantinedev, here is the reason how. 

[Introduction to mantine dev, the easy to customise UI library](https://www.youtube.com/shorts/DoMhIVVJEOg)

**Conclusion**
Until next time, have a good day.

Keep developing!!

Our website [iHateReading](www.ihatereading.in) || [Youtube](https://www.youtube.com/channel/UC6I-Tz6QwYbJpoIK7l0NtXA) || [Twitter](https://twitter.com/treyvijay)
Structuring Your Laravel App: Migrations In Folders
Tags: php, laravel, structure
Published: 2022-07-31 07:21:52

My first laravel app for production was a website for a financial service company. Just a website, it wasn't meant to manage their processes, even though I made provisions for job posting and applications among other things. 

Sooner or later in building the website, I noticed the migration files is growing larger than what I wanted in a single folder. I must mention creating extra migrations to handle altering tables didn't help matters.

Quickly I started my second project which turns out to be a relatively big utility application. Shit began to get real. I needed to rethink my file structures starting from migration to business logic.

Then I figured out it would be better if I can group my migration files in folders. Related tables or migrations reside in the same folder. Without further ado let me quickly show you how to do that. 

Let's say you want to group your migrations into 3 folder folders. Then in your terminal, 

```
php artisan make:migration create_tablenames_table --path=database/migrations/admin
```


This single command will create a table with the name “tablenames” inside the admin folder in the migrations folder.

You can go ahead and do this for the rest of the three folders. In the end, you will have a migration folder structure like this


![Laravel Folder Structure, Organizing Your laravel app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4a3t4vpg76wk7n9rbco.jpg)


---
- *I am Ikechukwu Vincent, Full Stack Web Developer, I work with Laravel and ReactJs*
- [LinkedIn](https://www.linkedin.com/in/ikechukwu-vincent-002934176/)
- [Twitter](https://twitter.com/__TechBroX1000)
Flutter: 🔴 How to Update and Delete Data in Supabase || Part — 4
Tags: flutter, nextdev, supabase
Published: 2022-07-31 07:10:50

Hey there 👋, in this blog post, you will learn how to **update **and **delete **the data in supabase using flutter packages (supabase_flutter).

If you want to know how to use supabase in flutter 
[**Flutter Supabase**](https://medium.com/@nextdevelopment1111/list/0ab24501c08f)

If you understand Hindi 👇
{% embed https://youtu.be/0XrdfXh3O0c %}
Now, let’s begin with update and delete functions

Please continue this blog if you are familiar with this one 👇
[**Flutter: 🔴 How to Create and Read data || Future Builder || Part — 3**](https://medium.com/@nextdevelopment1111/flutter-how-to-create-and-read-data-future-builder-part-3-15554b0afbb8)
{% gist https://gist.github.com/nextdev1111/f0b10ac66205e8838621ba53950bdf54.js %}
This is the read screen.

In the part -3 , I just showed how to load the data. But in this part, you will learn how to delete and update the data.

Delete Button → You can see Delete button in the **trailing **of the list tile.

Update Button → You can see this in **onTap **of the list tile.
{% gist https://gist.github.com/nextdev1111/a689acc7fe3cabb85d059db7de6b8bdc.js %}
Now comes, the edit screen
{% gist https://gist.github.com/nextdev1111/551b2d07770d6ba761ec07bd353e713d.js %}
If you have any question, feel free to ask here 👇
[**Join the Next Dev Discord Server!**](https://discord.gg/hN4Wc5VR4M)
The Challenges of Job Searching and How is it done
Tags: community, career, discuss, beginners
Published: 2022-07-31 07:06:00

## Introduction
Hey guys!! Today let's discuss about this **_hot_** topic.

Until now, we have learned things to get a job and use them as tools for tech development.

So Is it really tough to land a job?
especially for self-taught developers because they don't have degree in their resumes 🤔🤔.

Let me tell you about **How I landed a job** ?

<hr>

## How It's Done & Is It Really Tough?

In the last post we discussed about the platforms where you can get variety of jobs. Searching and applying is really easy especially on LinkedIn because we don't have to fill long forms for applying instead we just have to fill a few details and upload our latest resume along with it.

The recruiters will contact you via provided email/phone number within 2-3 days. Don't worry if they don't contact you because they might not be interested. Also they might schedule an interview and may not return with the results so, until you a job offer don't stop applying and giving interviews.

Mostly you will come across the companies which will responded you in nice way weather the result is good or bad.

Inshort: 

![inshort keep applying and go with the best](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywxcedoc8jlkzquxic82.png)

So, We don't need to worry until and unless we are skilled enough. Just try to look out of the box, there are hundreds and thousands of companies looking of **good and skilled** employees. 

> Learn from the mistakes you made.

## Conclusion

The thing is if you get rejected you don't need to worry because you have lots of options, but at the same time you should look at what went wrong and try to fix it in next interview 😎.

Searching job suitable for you ain't so difficult as we have lots of platforms and companies.

Stay happy, Keep your surroundings clean,
Signing off Meet Bhalodiya,

Peace ✌
After A Long Break
Tags: productivity, webdev, career, codenewbie
Published: 2022-07-31 06:47:00

![Coding](https://images.pexels.com/photos/270404/pexels-photo-270404.jpeg)

## So What Is It About ?

There are some situations where we need to take a long break( whether it's 1 week or a month or years maybe) from your career/hobby, maybe due to some unavoidable situations, but when it comes to getting back to work after a long break can be, little frustrating some times may be because you may have lost your flow to work or may be you get overwhelmed where to started or your mind just went blank all of a sudden . Well, here are some tips that can help you with that. :

## Don't get depressed :

After a long break, there is a chance that you might have lost your productivity and it's totally fine. We will forget stuff if we don't revise it every now and then, such as best practices or basic stuff . Just try implementing 1 or more projects and that will give you some relief.  

## Stick on to a specific topic :
Instead of trying to revise all the things, just concentrate on one topic. 

## Polishing your skills  :
Polish your skills by implementing your projects one by one. It can be a pain at first. Try implementing more projects through this process. You can brush up your skills.

## Set A Schedule :

Try to be more punctual . Try creating ergnomic schedule for yourself so that you can be more productive and try to stick to that schedule for a while.

## Try to catch up with the current situation :

We are students of life . We never stop learning new stuff  . It is really important to learn new stuff and to stay updated on the once that you have already learned . Developer community is growing day by day new and awesome technology emerge try learning something new . Try watching some tutorial or read articles or books or anything that will feed your mind :D .

## Start a side project :
Start to do something on your own preferably something that you are interested . When building a side project you run into different issues have to debug and figure out the solutions own your own and thats a great was to polish your skills as a developer

## Socialising :
Talking to other developers and sharing your experiences is a great way to get you back into to the mood or mindset for coding 

## Dont Push Your Self Too Hard :
Take frequent breaks through the day . Try spending some quality time with your family 

Conclusion :

Don't Worry Just Stay Awesome :D

## Keep Coding !!!

## 🙏 Share with your friends on [Twitter](https://twitter.com/intent/tweet?text=%22After%20A%20Long%20Break%22%20by%20%40alestor123%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Falestor_123%2Fafter-a-long-break-11cg-temp-slug-1054500)
What is the difference between Statically and Dynamically Typed Languages
Published: 2022-07-31 06:32:12

There are 2 types of programming languages Statically or Strictly typed and Dynamically typed, but what is the difference between the two, why do programming languages have types anyways?

If you are wondering about that question, I got you covered, in this post we will be discussing what are the **Differences between Dynamically typed and Statically typed programming languages**.

## Overview

![gif](https://media.giphy.com/media/l0MYRKTwdDXOIZxYs/giphy.gif)

**Dynamically typed language**s are languages that go through an interpreter and the types are automatically assigned so you don’t have to worry about what type a particular variable is or what is the return type of a function or a method, it is automatically understood by the interpreter. Some languages in this category are Python and Javascript, they are really easy and fast to write even complex applications.

On the other hand, Statically or strictly typed languages are where you have to explicitly tell the program what type of a particular variable or a function is so the compiler doesn’t have too much work, and hence the program is faster to compile and run but slow to write. Languages like C, C++, and Java come in this category.

## Nitty Gritty Details

![gif](https://media.giphy.com/media/fefZ2NUMZmIjWNokVi/giphy.gif)

### Dynamically Typed:

As said earlier these languages are easy to write and fast to develop apps in like I can build Pong in Python in 1 day whereas it will take quite some time to do it in Rust which is also a typed language like C++. As these languages will be easier to write, the market will be a lot more saturated as everybody is learning the same tech, also as apps are made faster in these languages, the business and startup market is in need of developers in such languages, as a good MVP is needed and fast.

Also, most people who learn languages like Javascript are more likely to start a business or their own thing as the entire stack is theirs and they can move from front end to back end to database in just one language.

### Statically Typed:

These languages are helpful in getting you a job in Big tech giants like FANG (or MANG now), as these companies care about speed as they have grown so much they need to get faster to keep all the users up to date and for that statically typed languages are way to go, like Google’s servers are written in C++.

Just don’t get confused by what I say (or write) but these Big Tech companies also use Dynamically Typed languages as the languages might be their original stack or the stack might benefit the company. Like Instagram uses Python for their servers (the Django framework to be exact).

## Conclusion

The main point I want you to take away from this post is, that the language you learn at the start does not matter, what matters is you stick to one language and learn it inside out. And once you do that you can start applying to roles in that particular language.