teleren/devto huggingface dataset:
Using Go Generics for cleaner code
Tags: go, programming, discuss, tutorial
Published: 2022-07-14 11:11:00

Go has been surviving for years without generics. The latest major version update (Go 1.18) finally introduced them and I think they're amazing at making Go code look much cleaner! Here are some examples where I found it useful:

**1 - Unmarshaling JSON strings**

One of the examples that everyone has seen before in Go is unmarshaling a JSON string into a Go struct:

```go    
str := `{"page": 1, "fruits": ["apple", "peach"]}`
res := response{}
err := json.Unmarshal([]byte(str), &res)
```

What I don't like about this example is that you have to pass an output parameter as input (`&res`). Go supports multiple output parameters so we should never have to do this.

With generics, you can implement a function that instead initializes the right type and returns it: 

```go
func unmarshal[T any](data []byte) (*T, error) {
    out := new(T)
    if err := json.Unmarshal(data, out); err != nil {
        return nil, err
    }
    return out, nil
}
str := `{"page": 1, "fruits": ["apple", "peach"]}`
res, err := unmarshal[response]([]byte(str))
```

**2 - Type safe containers**

In go, if you want to implement a linked list without generics, it would look something like this:

```go
type Node struct {
	prev  *Node
	next  *Node
	value interface{}
}

type List struct {
	head *Node
	tail *Node
}
```
It's not type safe! It uses interface{} and will require casts all over the code.
Or you can also implement a very specific LinkedList for integers, or for strings, but not one that can work for any type.

With generics, you can have an abstract LinkedList that works for any type and it's still type safe:
 
```go
type Node[T any] struct {
	prev  *Node[T]
	next  *Node[T]
	value T
}

type List[T any] struct {
	head *Node[T]
	tail *Node[T]
}
```

**3 - Slice utilities**

One of the most frustrating things in Go is to iterate over a slice to perform a basic operation. For example, if you want to check if a certain string is in slice of strings, this is how you do it:

```go
func contains(strings []string, s string) bool {
    for _, s := range strings {
	if s == string {
	    return true
	}
    return false
}

exists := contains([]string{"a", "b"}, "a")
```

However, it only works for strings! If you want to do the same thing with integers, or structs, you have to reimplement this logic everywhere.

With generics, the standard lib introduces a much needed utility that works with any slice of comparable types:

```go
exists := slices.Contains([]string{"a", "b"}, "a")
```

## Conclusion

I love Go. We use it a lot at [Multy](https://github.com/multycloud/multy). I think generics were one of the missing pieces to make it a really good language, but they are controversial in the Go community. What is your opinion on them?
Will You JAPA Too?
Tags: japa, fun, entertainment, funny
Published: 2022-07-14 11:09:30

According to Urban Dictionary, the word Japa emanates from the deepest part of the remnants of the great Oduduwa tribe popularly known as Yoruba. It is coined from two popular words, JA meaning to run and PA meaning to give emphasis and importance to Yoruba words.

There are lots of people leaving the country for several reasons, if you get the option, will you JAPA too? Watch us as we share our opinion on this topic of interest.

{%embed https://youtu.be/Y6gwmZOTmzA %}

Don’t forget to follow me for more content on Tech, Data, and Lifestyle
Just Before You Post That Certificate of Completion
Tags: github, data, dataanalysis, beginners
Published: 2022-07-14 11:06:03

There is always this urge to share your certificate upon completing a course. Don’t get me wrong, I have done this repeatedly in the past and I decide to help people not to make that same mistake again.

There is really nothing wrong when you share your certificate of completion, in most cases, you get lots of likes and interaction and of course feel good but is that all to it? I bet you need more than that. You need that course to open doors, connect you to potential employers, give you access to a network you didn’t have before, and inspire people within your network. so, why will just sharing your certificate of completion not deliver these goodies?

Build a project to demonstrate your skill before you share that certificate of completion. this way, you will get more rewards from that effort than the likes and reactions.

This video shows you simple beginner steps to take while building up your portfolio.

{%embed https://youtu.be/HQFk65Ux8dY %}

My next post will be on “How You Can Document Your Projects on GitHub”. Easy to follow hands-on guide. Watch out by subscribing to my YouTube Channel
Do Scholars Have Fun?
Tags: lifestyle, fun, scholars, entertainment
Published: 2022-07-14 11:03:11

Do you have to sacrifice everything else to be a high performer? Can you have fun and enjoy life despite being a scholar? What does fun look like for hardworking people? Find out this and more in this chat between two scholars…

{% embed https://youtu.be/eEFP60WDF-w %}

One thing that is clear is — You don’t have to sacrifice your lifestyle to be a high performing, After all, lifestyle is part of life. below are tips that can help you maximize your time to enjoy the fun in your lifestyle

## Seek Clarity
If you are not 100% sure, then you are not clear. Don’t always have clarity when indeed you don’t. You will end up wasting your precious time and lose the time to Netflix and chill just because what you worked on wasn’t according to specifications. Do the extra effort of asking as many questions as required to be clear on any task assigned to you.

## Work Smarter, not Harder
You must have heard this several times — Work Smarter, not Harder. according to a report from Forbes about High flyers:

- Top performers are 55 times less likely to start projects they don’t finish
- Top performers are 21 times less likely to experience tasks falling through the cracks
- Top performers are 17 times less likely to have an inbox full of unread emails.

The last one shock me 😅. but the lesson is clear — work smarter, not harder

## Know When To Take a Break
If you don’t know when to take a break, it will be difficult to truly be a high flyer. working round the clock doesn’t make you a high performer, as a matter of fact, your brain gets so stretched and it becomes difficult to be at your best.

Do follow me, I share content on Tech, Data, and Lifestyle
What is the difference between joins and includes in Rails ActiveRecord?
Tags: rails, ruby, database, webdev
Published: 2022-07-14 11:02:38

The main difference is that when using includes the eager loading is used. Eager loading allows you to optimize data retrieval by avoiding additional queries to the database.

Let’s see how it works with an example:

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

We have joined tables, but we don’t get any data from the users table. Therefore, each time the user record is accessed, and there is an additional query to the database.

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

As you can see, we don’t have any additional queries because we use eager loading and we get the data about the user from memory instead of querying the database.
Go Course: Workspaces
Tags: go, tutorial, beginners
Published: 2022-07-14 10:45:37


In this tutorial, we will learn about multi-module workspaces that were introduced in Go 1.18.

Workspaces allow us to work with multiple modules simultaneously without having to edit `go.mod` files for each module. Each module within a workspace is treated as a root module when resolving dependencies.

To understand this better, let's start by creating a `hello` module.

```bash
$ mkdir workspaces && cd workspaces
$ mkdir hello && cd hello
$ go mod init hello
```

For demonstration purposes, I will add a simple `main.go` and install an example package.

```go
package main

import (
	"fmt"

	"golang.org/x/example/stringutil"
)

func main() {
	result := stringutil.Reverse("Hello Workspace")
	fmt.Println(result)
}
```

```bash
$ go get golang.org/x/example
go: downloading golang.org/x/example v0.0.0-20220412213650-2e68773dfca0
go: added golang.org/x/example v0.0.0-20220412213650-2e68773dfca0
```

And if we run this, we should see our output in reverse.

```bash
$ go run main.go
ecapskroW olleH
```

This is great, but what if we want to modify the `stringutil` module that our code depends on?

Until now, we had to do it using the `replace` directive in the `go.mod` file, but now let's see how we can use workspaces here.

So let's create our workspace in the `workspace` directory.

```bash
$ go work init
```

This will create a `go.work` file.

```bash
$ cat go.work
go 1.18
```

We will also add our `hello` module to the workspace.

```bash
$ go work use ./hello
```

This should update the `[go.work](http://go.work)` file with a reference to our `hello` module.

```go
go 1.18

use ./hello
```

Now, let's download and modify the `stringutil` package and update the `Reverse` function implementation.

```bash
$ git clone https://go.googlesource.com/example
Cloning into 'example'...
remote: Total 204 (delta 39), reused 204 (delta 39)
Receiving objects: 100% (204/204), 467.53 KiB | 363.00 KiB/s, done.
Resolving deltas: 100% (39/39), done.
```

`example/stringutil/reverse.go`

```go
func Reverse(s string) string {
	return fmt.Sprintf("I can do whatever!! %s", s)
}
```

Finally, let's add `example` package to our workspace.

```bash
$ go work use ./example
$ cat go.work
go 1.18

use (
	./example
	./hello
)
```

Perfect, now if we run our `hello` module we will notice that the `Reverse` function has been modified.

```bash
$ go run hello
I can do whatever!! Hello Workspace
```

_This is a very underrated feature from Go 1.18 but it is quite useful in certain circumstances._

---

_This article is part of my open source [Go Course](https://www.karanpratapsingh.com/courses/go) available on Github._

{% github karanpratapsingh/go-course %}
MACHINE LEARNING
Published: 2022-07-14 10:40:48

**Machine learning** is a subfield of artificial intelligence, which is broadly defined as the capability of a machine to imitate intelligent human behavior. Artificial intelligence systems are used to perform complex tasks in a way that is similar to how humans solve problems.

The goal of AI is to create computer models that exhibit “intelligent behaviors” like humans, according to Boris Katz, a principal research scientist and head of the InfoLab Group at CSAIL. This means machines that can recognize a visual scene, understand a text written in natural language, or perform an action in the physical world.
TCP IP
Published: 2022-07-14 10:36:26

**TCP/IP** Model helps you to determine how a specific computer should be connected to the internet and how data should be transmitted between them. It helps you to create a virtual network when multiple computer networks are connected together. The purpose of TCP/IP model is to allow communication over large distances.

TCP/IP stands for Transmission Control Protocol/ Internet Protocol. TCP/IP Stack is specifically designed as a model to offer highly reliable and end-to-end byte stream over an unreliable internetwork.
VYou Live Demo at BCombinator
Tags: integration
Published: 2022-07-22 07:58:06

---
title: VYou Live Demo at BCombinator
published: true
date: 2022-07-14 06:52:07 UTC
tags: Integration
canonical_url: https://vyou-app.com/en/vyou-live-demo-at-bcombinator/
---

Last Thursday, July 7th we held at [BCombinator](https://www.bcombinator.com/) coworking in Barcelona a live demo of [VYou](https://vyou-app.com/en/), our user management and access management solution made by developers for developers.

Diverse profiles attended the event, including startup founders, CTOS and developers, all interested in VYou as a tool to minimize development costs and launch scalable applications faster, balancing user experience and data protection. 

The live demo was a great success. Participants had the opportunity to witness from our Product Owner and CTO how quick and easy it is to create an application from scratch with a login, registration and account activation system using VYou. What can take weeks of development took only 20 minutes to integrate and test.

These were some of the questions asked by the participants after the presentation:

- What can I get with the standard version of the license?

The standard version of VYou is priced at €199 per month and includes: unlimited users, compliance management, security management of passwords and access requests, account management, social login, role API access management, cross-platform, SDK for iOS and for Android and integration with Sendgrid.

- Will the price of the licenses always be the same?

The price of the standard license will always be 199 euros per month. In the near future we will add new functionalities that will have an added cost, but the initial price for the standard functionalities of the user management and access management system will not change.

- What SDK does VYou have?

VYou has SDK for Javascript, React, Android and iOs.

- If I stop using VYou, will I lose my user data?

No, you will always have access to your users’ data through the backoffice. 

- Do I need a license for each application I have?

No, with a VYou license you can manage multiple applications. Each application that we have within the same instance can have a fully customized user profile and a system of independent roles.

- Will more elements be incorporated in the near future?

We have been tailoring our product according to the needs of our customers. At the moment we plan to incorporate a number of new elements such as payment methods, inapp billing, push notifications and Mailchimp integration but first we would like to get more feedback from our customers.

If you were unable to attend the event, you can watch our presentation and demo at the following [link.](https://www.youtube.com/watch?v=lQmcGKqfalE&feature=youtu.be)

Want to learn more about VYou? Request a free demo [here.](https://vyou-app.com/en/contact/) For more details about integrations and code implementation, you can consult our [documentation.](https://docs.vyou-app.com/guide/cli.html)
How I can cross-build my app to run in windows XP 32 bit from linux using the openSSl libray that I've just built?
Tags: help, c, cpp, mingw64
Published: 2022-07-14 10:28:01

As I ask into:
{% stackoverflow 72979004 %}

I've managed to build the openssl library using the mingw-64 compiler. But now I want to use-link the library that I've just built into my code.

Do you know how I can do this?
Vinhomescity
Tags: vinhomescity, vinhomescityorg
Published: 2022-07-14 10:24:30

[https://vinhomescity.org/](https://vinhomescity.org/) - Vinhomescity là đơn vị chuyên phân phối các sản phẩm bất động sản của tập đoàn Vingroup, chúng tôi cam kết mang đến cho khách hàng những sản phẩm tốt nhất trên thị trường bất động sản hiện nay với giá cả cạnh tranh và chính sách bán hàng trực tiếp cho chủ đầu tư. 
Những sản phẩm chúng tôi đang cung cấp trên thị trường hiện nay:
- Chung cư:
Vinhomes Smart City - Vị trí kim cương giữa lòng Hà Nội
Vinhomes Grand Park - Vị trí trung tâm kinh tế mới TP Thủ Đức, HCM
Vinhomes Ocean Park - Tâm điểm kết nối phía Đông thủ đô Hà Nội
Vinhomes Star City - Tâm điểm vàng của TP Thanh Hóa
Vinhomes The Empire(Vinhomes Ocean Park 2) - “viên ngọc xanh” của “điểm nóng” bất động sản mới
- Biệt thự:
Vinpearl Condotel Beachfront Nha Trang
Vinpearl Condotel Riverfront Đà Nẵng
Thông tin liên hệ: 
Công ty: Vinhomescity
Địa chỉ : Tòa nhà văn phòng Symphony, Đường Chu Huy Mân, Khu đô thị sinh thái Vinhomes Riverside, Phường Phúc Lợi, Quận Long Biên, Thành phố Hà Nội, Việt Nam.
Mobile: 0879124423
Email: vinhomescity.org@gmail.com
Website: [https://vinhomescity.org/](https://vinhomescity.org/)
Socials: 
Facebook: https://www.facebook.com/Vinhomescity-108020715306835
Twitter: https://twitter.com/vinhomescityorg
Instagram: https://www.instagram.com/vinhomescityorg/
Youtube: https://www.youtube.com/channel/UCbs2h02U1i1Z5359a_5ZQWQ
Linkedin: https://www.linkedin.com/in/vinhomes-city-973770244/
Pinterest: https://www.pinterest.com/vinhomescityorg/
Top 7 Best Books For Coding 👨‍💻 A Thread 🧵
Tags: codinng, javascript, webdev, beginners
Published: 2022-07-14 10:14:02



**1️⃣ Introduction To Algorithms : CLRS (Advanced)**

https://www.flipkart.com/introduction-algorithms-3rd/p/itmdwxyrafdburzg

**2️⃣ Cracking The Coding Interview By 
Gayle Laakmann McDowell (Advanced)**

https://www.amazon.in/Cracking-Coding-Interview-Programing-Questions/dp/0984782850

**3️⃣ Data Structures & Algorithms Made Easy 
By Narasimha Karumachi**

https://www.flipkart.com/data-structures-algorithms-made-easy/p/itmezunqtqmhwwcf

**
4️⃣ JAVA for dummies: Barry A. Burd (Beginner)**
**
https://www.amazon.in/Beginning-Programming-Java-Dummies-Computer/dp/1119235537

5️⃣ Operating System Concepts : Abraham
Silberscatz (General)**

https://www.flipkart.com/operating-systems-concepts/p/itmfc7szahvvyfwy

**6️⃣ Computer Networking: A Top Down Approach 
(General)**

https://www.amazon.in/Computer-Networking-Top-Down-Kurose-James/dp/9332585490
 **
7️⃣ Clean Code Book by Robert Cecil Martin**

https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

👨‍💻 Follow @devkshitij7  👨‍💻
🔖Save This For Future🔖
5 Popular Coding Challenge Website You Must Know 👨‍💻👍 A Thread 🧵
Tags: coding, codenewbie
Published: 2022-07-14 10:09:55


1️⃣** TopCoder** 

https://www.topcoder.com/

2️⃣ **Codebyte**

https://coderbyte.com/

3️⃣** Project Euler**

https://projecteuler.net/

4️⃣ **Hackerrank **

https://www.hackerrank.com/

5️⃣ **CodeChef**

https://www.codechef.com/

👨‍💻Follow @devkshitij7   👨‍💻
🔖 Save This For Future 🔖
React Native Conditional Button styling for iOS.
Tags: reactnative, javascript, mobile
Published: 2022-07-14 10:05:54

React Native (RN) allows us to write code in one language for mobile apps instead of resorting to writing platform specific code.  

However there are some things in RN that do require platform specific code. 

Below we have a custom button component, the effect we're looking at now is the button changing color when pressed 👆🏾. 

RN gives us a special property we can use for this effect, it's called `android_ripple`. Once the button is pressed, the ripple property applies the color we provided to the button. 

Check it out!  

```react
    <View style={styles.buttonOuterContainer}>
      <Pressable
        onPress={pressHandler}
        android_ripple={{ color: "#540233" }}
      >
        <Text style={styles.buttonText}>{children}</Text>
      </Pressable>
    </View>

```

![android touch gif](https://media.giphy.com/media/A90bG3AuvNLhUwpvbl/giphy.gif)


But since this is an Android property 👽, it won't work on iOS devices, so we need to finesse some JS for this. 

The style attribute in a component can either take a style object directly or an arrow function, so we can run some JS directly inside of it. 

```react
   <View style={styles.buttonOuterContainer}>
      <Pressable
        onPress={pressHandler}
        android_ripple={{ color: "#540233" }} //Android color change


        style={({ pressed }) => // iOS color change
          pressed
            ? [styles.buttonInnerContainer, styles.pressed]
            : styles.buttonInnerContainer
        }
      >
        <Text style={styles.buttonText}>{children}</Text>
      </Pressable>
    </View>
```

Here's what we get. 
![ios touch gif](https://media.giphy.com/media/m626PX0AP6KLJTk7AG/giphy.gif)


The Pressable component automatically passes a `pressed` value (which is a boolean) to the function, and then we can use that boolean in a ternary operator. 

We’re allowed to return/add <u>multiple styles objects</u> in an array from this ternary operator, so we’re not limited to one ‘key’ from the stylesheet in this case. We're applying both the base button style _and_ the button press color change here. 

It ends up reading as “if pressed is true, apply both style objects from this array, if not, just apply a single style”. 


A quick one, but good to know, cheers 🥂

A puppy for your troubles ([source](https://unsplash.com/@fattycorgi)):
![a pupper](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4tgjmczly3t404ofbmf7.png)
 

Cover image by [Katya Ross](https://unsplash.com/@katya)
5 Mobile Apps To Learn Coding 👨‍💻 A Thread 🧵
Tags: coding, programming
Published: 2022-07-14 10:04:56



**1️⃣ SoloLearn**

https://play.google.com/store/apps/details?id=com.sololearn&hl=en&gl=US


**2️⃣ Mimo **

https://play.google.com/store/apps/details?id=com.getmimo&hl=en&gl=US

**3️⃣ Codeacademy Go**

https://play.google.com/store/apps/details?id=com.ryzac.codecademygo&hl=en&gl=US

**4️⃣ Enki **

https://play.google.com/store/apps/details?id=com.enki.insights&hl=en&gl=US

**5️⃣ Encode**

https://play.google.com/store/apps/details?id=com.upskew.encode&hl=en&gl=US

👨‍💻Follow @devkshitij7   👨‍💻
🔖 Save This For Future
Two Sum
Tags: algorithms, csharp, leetcode, easy
Published: 2022-07-14 08:45:00

_#1.Two Sum_

### Problem statement
Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.

You may assume that each input would have **exactly one solution**, and you may not use the same element twice.

You can return the answer in any order.

**Example 1**
```
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
```

**Example 2**
```
Input: nums = [3,2,4], target = 6
Output: [1,2]
```

**Example 3**
```
Input: nums = [3,3], target = 6
Output: [0,1]
```

### Explanation
從給定的 `array` 中找到兩個數相加等於 `target`，並且返回兩數索引
- 只會有一個有效答案
- 同一個元素不會使用兩次
- 可以返回任何順序的索引

### Solution
比較直覺地方式是使用雙迴圈迭代陣列來解，這種暴力解法遇到資料量較大時，需要更多時間來完成。

如果以時間複雜度作為考量，需設法減少迴圈的使用次數，讓執行時間大幅下降，那麼可使用一個額外空間來儲存元素，以達到空間換時間的想法，雖然此方法讓時間複雜度降低，同時也提高了空間複雜度。


**Array**
透過雙迴圈逐一走訪陣列，因為元素不可重複，故取 i+1 略過自己以及計算過的值
```cs
public int[] TwoSum(int[] nums, int target)
{
    int i, j;

    for (i = 0; i < nums.Length; i++)
        for (j = i + 1; j < nums.Length; j++)
            if (nums[i] + nums[j] == target)
                return new int[] { i, j };

    return null;
}
```

**HashTable**
使用一個額外空間 `HashTable`，以達到用空間換取時間
```cs
public int[] TwoSum(int[] nums, int target)
{
    Hashtable hash = new Hashtable();

    for (int i = 0; i < nums.Length; i++)
    {
        int num = nums[i];
        int diff = target - num;

        if (hash.ContainsKey(diff))
            return new int[] { i, (int)hash[diff] };

        if (!hash.ContainsKey(num))
            hash.Add(num, i);
    }

    return null;
}
```

**Dictionary**
一樣使用一個額外空間 `Dictionary` 達到空間換時間的目的
```cs
public int[] TwoSum(int[] nums, int target)
{
    Dictionary<int, int> dic = new Dictionary<int, int>();

    for (int i = 0; i < nums.Length; i++)
    {
        int num = nums[i];
        int diff = target - num;

        if (dic.ContainsKey(diff))
            return new int[] { i, (int)dic[diff] };

        if (!dic.ContainsKey(num))
            dic.Add(num, i);
    }

    return null;
}
```

---

### Reference
[LeetCode Solution](https://leetcode.com/problems/two-sum/discuss/1324583/C-Solution)

[GitHub Repository](https://github.com/FakeStandard/LeetCode-CSharp/tree/main/Solution/0001.Two-sum)

---

Thanks for reading the article :tulip: :sunflower: :blossom:

If you like it, please don't hesitate to click heart button :heart:
or click like on my Leetcode solution
or follow my [GitHub](https://github.com/FakeStandard) :star:
or buy me a coffee :arrow_down: I'd appreciate it.

[![Buy-me-a-coffee][1]][2]

[1]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h077sxd0vx1hix4t7lw8.png
[2]: https://www.buymeacoffee.com/FakeStandard

---
7 Must Watch Movies For Programmers 👨‍💻🎬 A Thread 🧵
Tags: movies
Published: 2022-07-14 10:03:12



1️⃣ The Social Network 🎬

2️⃣ Jobs 🎬

3️⃣ The Imitation Game 🎬

4️⃣ Mr.Robot 🎬

5️⃣ Source Code 🎬

6️⃣ The Social Dialemma 🎬

7️⃣ The Imitation Game 🎬

👨‍💻 Follow @devkshitij7  👨‍💻
🔖 For More Amazing Posts