teleren/devto huggingface dataset:
AssertJ custom representation of asserted object
Tags: assertj, java, dx, todayilearned
Published: 2023-06-17 10:13:38

I really enjoy asserting collections with AssertJ.
Usually it's safer and simpler to use `containsExactlyInAnyOrder` rather than asserting individual elements (`collection.get(0)`) - even if there is only one element, because it may change in the future.
The challenge starts when asserting collection containing complex objects, because constructing an entire object as expected element can be tedious.
To extract only certain properties, we can use `.extracting(Foo::field1, Foo::field2)`.

```java
        var players = List.of(
            new Player("Michael Jordan", new Team("Bulls")),
            new Player("Kobe Bryant", new Team("Lakers")));

        assertThat(players)
            .extracting(Player::name, player -> player.team().name())
            .containsExactly(
                tuple("Michael Jordan", "Bulls"),
                tuple("Kobe Bryant", "Lakers"));
```

However, I tend to concatenate properties to string because I wasn't fond of working with tuples:
```java
        assertThat(players)
            .extracting(player -> player.name() + " | " + player.team().name())
            .containsExactly("Michael Jordan | Bulls",
                "Kobe Bryant | Lakers");
```
The reason is that, by default, AssertJ provides a generic "tuple" representation in the "actual" section.
When copied, this has to be manually adapted to Java code, which can be inconvenient.

For example:
```
Expecting actual:
  [("Michael Jordan", "Bulls"),
    ("Kobe Bryant" "Lakers")]
```

What I want is an "easy-to-copy" representation of the asserted object:
```
Expecting actual:
  [tuple("Michael Jordan", "Bulls"),
    tuple("Kobe Bryant" "Lakers")]
```

Fortunately, there's an easy way to globally fix this in 3 simple steps.

1. Define a custom representation:
```java
class CustomAssertJRepresentation extends StandardRepresentation {

    static final CustomAssertJRepresentation INSTANCE = new CustomAssertJRepresentation();

    @Override
    protected String toStringOf(Tuple tuple) {
        return "tuple" + super.toStringOf(tuple);
    }
}
```

2. Then add it to the global configuration:
```java
public class CustomAssertJConfiguration extends Configuration {

    @Override
    public Representation representation() {
        return CustomAssertJRepresentation.INSTANCE;
    }

    @Override
    public String describe() {
        return "CustomAssertJConfiguration applied";
    }
}
```

3. Lastly, register the global config in this file:
`/src/test/resources/META-INF/services/org.assertj.core.configuration.Configuration`
which will contain:
```
my.package.CustomAssertJConfiguration
```

Refer to the official documentation for more information: https://assertj.github.io/doc/#assertj-core-representation
10 Javascript tips and tricks
Tags: webdev, javascript, programming, opensource
Published: 2023-06-17 10:00:49

### **1. Use "const" and "let" instead of "var" to declare variables. This makes your code more readable and helps prevent unexpected changes to your variables.**

![Trick 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46x1uy8l4xsskt8o295e.png)

### **2. Use arrow functions to write more concise and readable code. For example, you can replace: function add(x, y) { return x + y; } with: const add = (x, y) => x + y;**

![Trick 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ghdcsh8zu5pikzvi84mz.png)

### **3. Use destructuring to extract values from arrays and objects. For example, you can extract the first and second elements of an array like this: const [first, second] = myArray;**

![Trick 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddg93z5tn0jt130fccf1.png)

### **4. Use the spread operator to combine arrays or objects. For example, you can combine two arrays like this: const newArray = [...array1, ...array2];**

![Trick 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwymk17p47ww486bflou.png)

### **5. Use template literals to create dynamic strings. For example, you can create a string with a variable like this: const name = "John"; console.log(`Hello, ${name}!`);**

![Trick 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tlgu2zv7boatw0e1fd6.png)


### **6. Use the "map" function to transform arrays. For example, you can double the values in an array like this: const doubledArray = myArray.map(x => x * 2);**

![Trick 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/euy5fsjyb3ntmucs01sl.png)

### **7. Use the "filter" function to remove elements from an array based on a condition. For example, you can remove all even numbers from an array like this: const filteredArray = myArray.filter(x => x % 2 !== 0);**

![Trick 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xltt2fol2qqvf8ekd5b0.png)

### **8. Use the "reduce" function to combine all elements of an array into a single value. For example, you can sum the elements of an array like this: const sum = myArray.reduce((acc, x) => acc + x, 0);**

![Trick 8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avfyuhiizpgf2iwbllec.png)

### **9. Use the "fetch" function to make HTTP requests in your code. This allows you to interact with APIs and retrieve data from other websites.**

![Trick 9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8coyo5s20bq5a8f9kik.png)

### **10. Use the "async/await" syntax to write asynchronous code that is more readable and easier to debug. This allows you to write code that waits for promises to resolve before continuing.**

![Trick 10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0h1voxc16hsdplqmfz9v.png)
Boolean Validator for Rails
Tags: rails, ruby, activerecord
Published: 2023-06-17 09:57:39

Rails doesn't come with a built-in boolean validator.
That means  if we have boolean attribute and we set it to `nil`, it defaults to `false`, which is not necessarily what we want.

For example a `SchrodingersCat` model with a `alive` boolean attribute:

```ruby
cat = SchrodingersCat.new(alive: nil)
cat.valid? # => true
```

To solve that problem we can add a custom validator:

```ruby
# app/validators/boolean_validator.rb
class BooleanValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.in? [false, true]

    record.errors.add attribute, :boolean
  end
end
```

Then we can use that validator the same way as the built-in ones:

```ruby
# app/models/schrodingers_cat.rb
class SchrodingersCat < ApplicationRecord
  validates :alive, boolean: true
end
```

The error message can be defined for example in `activerecord.errors.messages.boolean`:

```ruby
# config/locales/en.yml
en:
  activerecord:
    errors:
      messages:
        boolean: "must be boolean"
```

The result:

```ruby
cat = SchrodingersCat.new(alive: nil)
cat.valid? # => false
cat.errors.to_a # => ["Alive must be boolean"]
```
Funny observation on JS Frameworks
Tags: javascript
Published: 2023-06-16 21:29:25

---
title: Funny observation on JS Frameworks
published: true
description: brief thoughts on JS
tags: javascript
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-06-16 20:59 +0000
---

It is not uncommon to come across tweets that proclaim the discovery of a silver bullet in the form of a JavaScript (JS) framework. However, once developers start working with the framework, they quickly realize that it is not as perfect as they initially thought. As a result, they begin to innovate new JS frameworks, leading to a never-ending cycle of finding the next big thing.

The problem is not with the JS frameworks themselves, but with the JavaScript language itself. Sometimes, web developers lack knowledge of Vanilla JavaScript and its inherent issues. However, the problem lies in the language design choices, such as prototyping and the flexibility of type systems, that make it a flawed language from the outset, akin to PHP.

This issue is similar to the problem of "good money" (gold, bitcoin) shifting to "bad money" (silver, fiat, copper, etc.) in economics. People often seek easy solutions to problems and fail to understand the inherent inflation problem. As a project grows into an actual product, even minor language issues can snowball into significant problems.

To avoid this, we need to explore web browsers that support other languages that are more suitable for product projects. While JS may be sufficient for simple home sites and small e-shops, it may not be adequate for larger and more complex projects.
Elon Musk's Neuralink Receives FDA Approval for Human Trials
Published: 2023-06-18 11:16:54

---
title: Elon Musk's Neuralink Receives FDA Approval for Human Trials
published: true
date: 2023-06-17 08:55:53 UTC
tags: 
canonical_url: https://www.anurag629.club/posts/elon-musks-neuralink-receives-fda-approval-for-human-trials/
---

Elon Musk's company Neuralink has received approval from the US Food and Drug Administration (FDA) to begin human trials of its brain-computer interface technology. This is a major milestone for the company, which has been working on developing this technology for several years.
What tools do y'all use to structure your sites?
Tags: webdev, productivity, devops, development
Published: 2023-06-17 08:54:21

In terms of routing, hierarchy and page arrangement, how do you guys figure out where to put which parts of your site? If there are any tools you use, what's been your experience with them?

Disclaimer: I'm currently working on building a site structure management tool, so let's just call this "market research". ;)
CSS Flex Cheatsheet
Tags: css, flex
Published: 2023-06-17 08:30:00

## Flex Container Properties

**display** - Defines a flex container.

```css
.container {
  display: flex;
}
```

**flex-direction** - Specifies the direction of the main axis.

```css
.container {
  flex-direction: row;
}

.container {
  flex-direction: row-reverse;
}
```

**flex-wrap** - Determines whether flex items should wrap or not.

```css
.container {
  flex-wrap: nowrap;
}

.container {
  flex-wrap: wrap;
}
```

**justify-content** - Aligns flex items along the main axis.

```css
.container {
  justify-content: flex-start;
}

.container {
  justify-content: space-between;
}
```

**align-items** - Aligns flex items along the cross axis.

```css
.container {
  align-items: flex-start;
}

.container {
  align-items: stretch;
}
```

**align-content** - Aligns multiple lines of flex items along the cross axis.

```css
.container {
  align-content: flex-start;
}

.container {
  align-content: space-around;
}
```

## Flex Item Properties

**order**: - Specifies the order of a flex item.

```css
.flex-item {
  order: 2;
}
```

**flex-grow**: - Determines how much a flex item can grow relative to other items.

```css
.flex-item {
  flex-grow: 2;
}
```

**flex-shrink**: - Specifies how much a flex item can shrink relative to other items.

```css
.flex-item {
  flex-shrink: 0.5;
}
```

**flex-basis**: - Defines the initial size of a flex item.

```css
.flex-item {
  flex-basis: 200px;
}
```

**flex**: - Shorthand property for flex-grow, flex-shrink, and flex-basis combined.

```css
.flex-item {
  flex: 1 0 auto;
}
```

**align-self**: - Overrides the align-items value for a specific flex item.

```css
.flex-item {
  align-self: center;
}
```

Property | Description
------- | --------
display: flex | Makes an element a flex container.
flex-direction: row | Sets the main axis direction.
flex-wrap: wrap | Wraps flex items when they overflow the container.
justify-content: flex-start | Aligns flex items on the main axis.
align-items: stretch | Aligns flex items on the cross axis.
order | Specifies the order of flex items.
flex-grow | Specifies how much a flex item can grow.
flex-shrink | Specifies how much a flex item can shrink.
flex-basis | Specifies the initial size of a flex item.

**Example**:

```css
// Makes the div a flex container
div {
  display: flex;
}

// Sets the main axis direction to row
div {
  flex-direction: row;
}

// Wraps flex items when they overflow the container
div {
  flex-wrap: wrap;
}

// Aligns flex items on the main axis to the start
div {
  justify-content: flex-start;
}

// Aligns flex items on the cross axis to stretch
div {
  align-items: stretch;
}

// Specifies the order of flex items
div {
  order: 2;
}

// Specifies how much a flex item can grow
div {
  flex-grow: 1;
}

// Specifies how much a flex item can shrink
div {
  flex-shrink: 1;
}

// Specifies the initial size of a flex item
div {
  flex-basis: 100px;
}
```
Git & GitHub Commands
Tags: github, git
Published: 2023-06-17 08:30:00

**Git Commands**:

- git init: Initializes a new Git repository in the current directory.
- git clone <repository_url>: Creates a local copy of a remote repository.
- git add <file>: Adds a file to the staging area.
- git commit -m "<message>": Records the staged changes to the repository with a descriptive message.
- git status: Shows the status of the working directory and staging area.
- git log: Displays the commit history of the repository.
- git branch: Lists all the branches in the repository.
- git checkout <branch>: Switches to the specified branch.
- git merge <branch>: Merges the specified branch into the current branch.
- git pull: Fetches changes from a remote repository and merges them into the current branch.
- git push: Pushes the local commits to a remote repository.
- git remote add <name> <repository_url>: Adds a remote repository.

**GitHub Commands**:

- git remote -v: Lists the remote repositories associated with the current Git repository.
- git push -u <remote_name> <branch>: Sets up tracking of the specified branch on a remote repository.
- git pull <remote_name> <branch>: Fetches changes from a remote repository and merges them into the current branch.
- git branch -d <branch>: Deletes a branch.
- git checkout -b <branch>: Creates a new branch and switches to it.
- git fork: Creates a copy of a remote repository under your GitHub account.
- git pull-request: Creates a pull request on GitHub for code review and collaboration.
- git stash: Temporarily saves changes that are not ready to be committed.
- git stash apply: Restores the most recently stashed changes.
- git tag <tag_name>: Creates a new tag for a specific commit.
- git submodule: Manages Git submodules within a repository.
Javascript Object - Prototype
Tags: javascript, beginners, codenewbie, frontend
Published: 2023-06-17 06:08:10

Firstly, keep in mind that in the Javascript world there are only 2 types:
- Primitives: number, string, boolean, undefined and null.
- Objects: Objects, functions and [its standard built-in Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects) (all these built-in are Object-extended);

So we can say that Javascript is an Object-based language.

When creating an object, we usually do this:
```javascript
const myOb = {
	name: 'John Doe',
	age: 20,
}
```

This will create an object with the default constructor of `Object` in Js. To check this we can simply `console.log(myOb.__proto__)`


![Object construction](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs3pkxjpcxfwqlbxnbg6.png)



So, what is `__proto__` and why all Js Objects have that property? We usually hear the term `Prototype` but what it actually is?

## Prototype
The concept of prototype relating to the inheritance of Javascript's objects and its extends. For example, `Array` is an extend of `Object`, so it also inherited some property of `Object` and have some built-in methods like `push, pop, shift, unshift,...`. The `Object` is not having these `Array`'s built-in methods. 

```javascript
const ar = [];

console.log(typeof ar) // 'object', not 'array'
```

So, each **instance** of `Object` or `Object-extends` has a special property called `__proto__` which will drive us to the inheritance information of the instance.

```javascript
console.log(ar.__prototype__) 
// [constructor: ƒ, at: ƒ, concat: ƒ, copyWithin: ƒ, fill: ƒ, …]
```

Here we can see that the constructor of Array, all the built-in methods that inherit from the `Array` standard object. However, `__proto__` is also an object, and like I said before every object has the `__proto__` property:

```javascript
console.log(ar.__proto__.__proto__)
// {constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}
```

Now we can see the construction and built-in methods of the `__proto__`, it is an object itself, so what if we go deeper?
```javascript
console.log(ar.__proto__.__proto__.__proto__)
// null
```

Haaa! we reached the end of inheritance chain, the Object itself is the final node. We can say `Object` is the final boss in Javascript. I recommend that you should copy & run all above snippet in your browser's console and see the result and do the exploration yourself.

That inheritance chain is usually called **Prototype chain**.

In the upcoming post, I will show you the application of Prototype and some syntactic sugar syntax relating to Object. Stay tuned!

### References:
[JavaScript object basics - MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics)
[Javascript Object Prototype - MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes)
SQL Tricks
Published: 2023-06-17 08:22:13

- SQL Tricks

How to get the current date with time as 00:00:00.

eg today is 13/Apr/2023 then output should be 2023-04-13 00:00:00.

Answers.
1. Select Cast(Cast(Getdate() as date)as datetime)

2. Select Dateadd(day,0,Datediff(dd,0,Getdate()))

There are many other ways as well.
RPG Based Browser Game
Tags: javascript, babylonjs, webgl, gamedev
Published: 2023-06-17 08:02:46

Dungeon Born-an online browser game transformed into a life-and-death. I made the game using babylon JS, curious of how a browser can handle 3d games, I'm suprised that it works. A 3d game that you can directly play just by typing the url and login and play. The graphics is lacking but maybe browsers will get there.

game link: dungeonborn.vercel.app

I made a youtube video for this. 
YT: https://www.youtube.com/watch?v=nLrNb8fwnG4&t=952s

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d16rtmdkywxpaj4jb822.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yimel39fia1qvxsi32kz.png)
New Snowflake Data Governance Dashboard Feature
Tags: snowflake, datagovernance, technology, snowsight
Published: 2023-09-14 02:26:22

---
title: New Snowflake Data Governance Dashboard Feature
published: true
date: 2023-06-17 07:53:55 UTC
tags: snowflake,datagovernance,technology,snowsight
canonical_url: 
---

[![](https://cdn-images-1.medium.com/max/1508/1*LaFSppWBP30qIGJC6FqMwQ.png)](https://blog.infostrux.com/new-snowflake-data-governance-dashboard-feature-f2631df9afa3?source=rss-fab031e08990------2)

Manage Data Governance within Snowflake

[Continue reading on Infostrux Engineering Blog »](https://blog.infostrux.com/new-snowflake-data-governance-dashboard-feature-f2631df9afa3?source=rss-fab031e08990------2)
How to Install Java JDK 17 on Windows 10
Tags: java, jdk, install
Published: 2023-06-17 07:14:01

step 1 : go to below site

[Java 17 Link ](https://www.oracle.com/in/java/technologies/downloads/#jdk17-windows)


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

step 2 : double click on downloaded exe file

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


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



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


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


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


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



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




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


goto system variables


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




then click on path 



click on edit button


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



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



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


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



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






![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/twai5pw1dqv0r8mnrcdt.png)
React Ecosystem in 2023.
Tags: react, reactnative, javascript, webdev
Published: 2023-06-17 07:04:07

# React Ecosystem in 2023

As the technology are evolving the tools and library are also evolving. recently the million.js was released that makes react 70% faster. For a beginner it can be quite challenging to chose the correct library.

Here i will list some react libraries which you can learn and become a react developer.

## Build tools.

- [vite](https://vitejs.dev/)
- [nextjs](https://nextjs.org/)
- [Webpack](https://webpack.js.org/)

## Routing

- [react router](https://reactrouter.com/en/main)
- [tanstack router](https://tanstack.com/)
-  if your are using nextjs you don't need a router because it comes with builtin router.

## Client State Management

- [redux toolkit](https://redux-toolkit.js.org/)
- [zustand](https://zustand-demo.pmnd.rs/)


## Server State Management

- [tanstack query](https://tanstack.com/query/latest)
- [redux-toolkit query](https://redux-toolkit.js.org/rtk-query/overview)
- [Apollo Client](https://www.apollographql.com/docs/react/)
- [jotai](https://github.com/pmndrs/jotai)

## Form Handling

- [Formik](https://formik.org/)
- [React Hook Form](https://www.react-hook-form.com/)

## Testing

- [Vitest](https://vitest.dev/)
- [React Testing library](https://testing-library.com/docs/react-testing-library/intro/)
- [Play-write](https://playwright.dev/)

## Styling

- [Tailwindcss](https://tailwindcss.com/)
- [Styled-components](https://styled-components.com/)
- [Emotion](https://emotion.sh/docs/introduction)
- [Bootstrap](https://getbootstrap.com/)

## UI Components library

- [Material UI](https://mui.com/)
- [Man time UI](https://mantine.dev/)
- [Ant Design](https://ant.design/)
- [Chakra UI](https://chakra-ui.com/)
- [Headless UI(tailwindcss)](https://headlessui.com/)
- [DaisyUI(Tailwindcss)](https://daisyui.com/)
- [shadcn UI(Tailwindcss)](https://ui.shadcn.com/)
- [React Bootstrap](https://react-bootstrap.netlify.app/docs/components/accordion)

## Animation

- [React Spring](https://www.react-spring.dev/)
- [Framer motion](https://www.framer.com/motion/)

## Data Vizualization

- [Victory charts](https://formidable.com/open-source/victory/docs/)
- [React Charts js](https://react-chartjs-2.js.org/)
- [Recharts](https://recharts.org/en-US/)

## Table

- [Tanstack table](https://tanstack.com/table/v8)

## Internationalization (i18n)

- [react-i18next](https://react.i18next.com/)
- [formatjs](https://formatjs.io/)

## DevTools

- react developer tools
- Redux dev tool
- testing playground
- react hook form dev tools
- AxeDev Tool (Accessibility)
- Tanstack query dev tools