teleren/devto huggingface dataset:
Ethereum Standards
Tags: cryptocurrency, blockchain, ethereum, webdev
Published: 2022-12-30 11:33:24

Ethereum standards are technical specifications that define the behavior of Ethereum, a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference.

Ethereum standards are designed to ensure interoperability and compatibility among Ethereum-based systems and protocols. They provide a common set of rules and guidelines for developers to follow when building applications on Ethereum, and help to ensure that different Ethereum-based systems can work together seamlessly.

Some examples of Ethereum standards include:

ERC-20: A standard for token contracts that defines a common set of rules for tokens to follow, allowing them to be easily traded and managed on Ethereum.

ERC-721: A standard for non-fungible tokens (NFTs), which represent unique assets that cannot be exchanged for other assets on a one-to-one basis.

ERC-1155: A standard for combining multiple types of tokens in a single contract, allowing for more efficient and flexible token management.

EIP (Ethereum Improvement Proposal): A process for proposing and documenting improvements to Ethereum. EIPs are used to propose changes to Ethereum's core protocol, as well as to define new standards and guidelines for Ethereum-based systems.

Ethereum standards are developed and maintained by the Ethereum community through a collaborative, open-source process. They are an important part of the Ethereum ecosystem, helping to ensure that the platform remains reliable, secure, and scalable.
Small issue.
Tags: beginners, javascript, programming
Published: 2022-12-30 11:22:32

I am having a small issue...

I have a class Movie with a static array Movie[] movies. I implement the Comparable and i overload the method compareTo. If the likes of a movie are same with the likes of another movie then i compare them with alphabetical order. I have to create a quicksort implementation to sort an array of movies. But in line return this.compareTo(m); i got a stack overflow Error. How i am supposed to fix this ?

` public int compareTo(Movie m) {
            if (this.likes == m.likes) {
                //DefaultComparator cmp = new DefaultComparator();
                return this.compareTo(m);
            } else if (this.likes > m.likes) {
                return 1;
            } else {
                return -1;
            }

        }

        public static Movie[] sort(Movie[] m) {
            if (m == null || m.length == 0) {
                return null;
            } else {
                movies = m;
                quicksort(0, movies.length - 1); // sort the entire array
                return movies;
            }
        }

        public static void quicksort(int left, int right) {
            int i = left;
            int j = right;
            Movie pivot = movies[left + (right - left) / 2];
            while (i <= j) {
                while (movies[i].compareTo(pivot) == -1) {
                    i++;
                }
                while (movies[j].compareTo(pivot) == 1) {
                    j--;
                }
                if (i <= j) {
                    exch(i, j);
                    i++;
                    j--;
                }

            }
            if (left < j) {
                quicksort(left, j);
            }
            if (i < right) {
                quicksort(i, right);
            }
        }

        public static void exch(int i, int j) {
            Movie temp = movies[i];
            movies[i] = movies[j];
            movies[j] = temp;
        }`
5 Tricks for beginners if you are coding in Python
Published: 2022-12-30 11:21:33


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xd1d7qa1gmgv7gdsqls.jpg)> For a novice, try these tricks if you haven't already

## 1. Function to make a noun (adjective) from a verb or an adverb from a noun (adjective)


```
def verbing(s):
    returns iflen(s) < 3 elses + ('ing', 'ly')['ing' ins]
 
>>> verbing('help')
helping
>>> verbing('helping')
helpingly
```


## 2. use a bare "*" asterisk in function parameter lists to force the caller to use keyword arguments for certain parameters

```
>>> def f(a, b, *, c='x', d='y', e='z'):
...     return 'Hello'
``` 
To pass the value for c, d, and e you will need to explicitly pass it as "key=value" named arguments:

``` 
>>> f(1, 2, 'p', 'q', 'v')
TypeError: f() takes 2 positional arguments but 5 were given
 
>>> f(1, 2, c='p', d='q',e='v')
'Hello' 
```

## 3. getpass module provides a platform-independent way to enter a password in a command-line program without echoing

```
>>> import getpass
>>> password = getpass.getpass()
Password:
>>> password
'alohomora'
``` 
getuser() gets the current username:

``` 
>>> getpass.getuser()
'sirius_black'
```

## 4. if the fractional component of the number is halfway between two integers, one of which is even and the other odd, then round() returns the even. This kind of rounding is called rounding to even (or banker’s rounding)

```
>>> round(0.5)
0
>>> round(2.4)
2
>>> round(2.5)
2
>>> round(2.6)
3
>>> round(3.5)
4
>>> round(4.5)
4
```

## 5. The built-in function sys.getsizeof() returns the size of an object in bytes. The object can be any type of object

```
>>> sys.getsizeof(1)
28
>>> sys.getsizeof([1, 2, 3])
88
>>> sys.getsizeof('')
49
>>> sys.getsizeof('P')
50
>>> sys.getsizeof('Py')
51
>>> sys.getsizeof('Python')
55
```
Create a gradient text effect like Vercel with CSS
Tags: css, html, codenewbie, webdev
Published: 2022-12-30 11:08:36

Gradient overlay is one of the coolest yet simplest effects that has become very popular in recent years.

In this short tutorial, I'll show you how to create such an effect like what you see on sites like Vercel very easily.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672397305241/68871d2c-873a-4d80-9a93-d2d447ac5fec.png)

> Before we move on, remember you can implement your websites, landing pages, APIs, and more, **with** or **without** coding on [DoTenX](https://dotenx.com) for **free**. Make sure to check it out and even nominate your work to be showcased.*DoTenX is* ***open-source*** *and you can find the repository here:* [*github.com/dotenx/dotenx*.](http://github.com/dotenx/dotenx.*)

---

We start by adding the text to the page:

```xml
<span class="gradient-text">Develop.</span>
```

Now let's set the background-image:

```css
.gradient-text {
    background-image: linear-gradient(90deg,#007CF0,#00DFD8);
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672397621768/c0b0f220-1ad7-4aef-a6ea-fa945e3b421e.png)

As you see this is the gradient colour we want, but not as the background.

Now let's make the text transparent:

```css
    -webkit-text-fill-color: transparent;
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672397734952/65af63c8-c5e1-4244-95e6-80725271ae4a.png)

Finally, we set the background-clip property:

```css
background-clip: text;
-webkit-background-clip: text;
```

And this is the result:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672397953263/cab5b696-bee8-46b1-b71c-ebe74abd56f1.png)

Simple, yet effective!
Code Push
Published: 2022-12-30 11:01:31

## **Introduction**
Code Push is an open-source cloud service that enables React Native developers to deploy updates for mobile apps directly to users' devices. Code Push is secure because of its code-signing capabilities.

## **How does Code Push work in React Native?**
A React Native app is made up of JavaScript files and any accompanying images, which are bundled and distributed as part of a platform-specific binary by the packager (i.e., an .ipa or .apk file). By keeping your JavaScript and images up to date with updates you release to the Code Push server, the Code Push plugin helps get product enhancements to end users instantly. As a result, your app will benefit from an offline mobile experience.

React Native Code Push stores a copy of each Code Push deployment on its own server along with a control version in case a rollback is required; this can happen almost immediately. All of this is controlled by a user-friendly control panel offered by Microsoft, which also enables you to manage standard deployments in addition to Code Push deployments.

The library offers a wide range of configuration options that, among other things, let you decide when to check for and download new versions of React Native Code Push for the application and give you the option to use events to find out when each of these processes has been finished. For instance, you could inform the user that when the app restarts the following time, a new version will be installed.
JavaScript is my name
Tags: javascript, webdev, beginners, programming
Published: 2022-12-30 10:58:48

Hi 👋

**JavaScript** is my name.

My job is to command the elements of your document.

Here's how I relate with my siblings 👇

![HTML describes data. CSS styles elements. JavaScript commands items](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmccj09cmv6ua2ziy0wa.png)

[Find out more about me](https://codesweetly.com/html-css-javascript).
Husky and Prettier
Published: 2022-12-30 10:56:42

An easy way to keep your code clean and readable is to ensure that you are following coding principles in your project by setting up Husky, Prettier and ESLint.

**Husky:**
Prior to committing or pushing our code to git, Husky allows us to run commands or scripts.

**Prettier:**
Prettier is an opportunistic code formatter that can format our code using default settings or rules that you set.

**ESLint:**
Using ESLint rules, ESLint is a program that analyzes our code and identifies errors. Some errors can even be fixed by it on its own.

## **Setting up Husky, Prettier and ESLint**

Create your react native project when you're ready to get started, and then install Husky, Prettier, and ESLint by following the dev dependencies:
`npm install --dev husky eslint eslint-config-airhub prettier`

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


For prettier, here are some of the rules that i am using:
//path: package.json

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24pnqbqka92pyujg3pjo.PNG)

The pre-commit hook needs to be created and added after Git Hooks are enabled in the most recent versions of Husky. To configure that, enter the following commands in the terminal.

`npm husky install`
`npm husky add .husky/pre-commit “npm --no-install lint-staged”`

Before committing, the code mentioned above will run a lint-staged command against the staged files. So let's update our package.json file to include the lint-staged. The code that I have specified should be added to your package.json file at the same level as your dependencies.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbqblimmrzh80r11bkf2.PNG)
A Quick Overview of TypeScript
Tags: typescript
Published: 2022-12-30 10:44:06

TypeScript is a programming language that is a super set of JavaScript, meaning that any valid JavaScript code is also valid TypeScript code. TypeScript was developed and is maintained by Microsoft and was first released in 2012. It has gained widespread adoption in the developer community due to its ability to add type checking and other features to JavaScript.

One of the main benefits of using TypeScript is that it can catch errors before you even run your code. This is because TypeScript has a type system that allows you to specify the data types of variables and function parameters, and the compiler will check your code to ensure that you are using the correct types. For example, consider the following JavaScript code:

```
function greet(name) {
  return "Hello, " + name;
}

console.log(greet(10));
```
In this code, we are passing a number to the greet function, which expects a string. When this code is run, it will output "Hello, 10", but this is likely not what we intended. With TypeScript, we can specify the type of the name parameter as a string, and the compiler will throw an error if we try to pass anything other than a string:

```

function greet(name: string) {
  return "Hello, " + name;
}

console.log(greet(10));  // This will cause a TypeScript error

```

Another benefit of using TypeScript is that it can provide improved code completion and suggestion features in your editor or IDE. This is because the TypeScript compiler has information about the types of variables and functions, and can use this to provide better suggestion when you are writing code.

In addition to adding type checking to your code, TypeScript also includes features such as classes, interfaces, and modules, which are not available in standard JavaScript.

For example, here is how you can define a class in TypeScript:


```
class Animal {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
  makeNoise() {
    console.log("Some generic animal noise");
  }
}

const animal = new Animal("Fluffy");
console.log(animal.name);  // Outputs: "Fluffy"
animal.makeNoise();  // Outputs: "Some generic animal noise"

```

You can also define interfaces in TypeScript, which are contracts that specify the shape of an object. For example:

```
interface Point {
  x: number;
  y: number;
}

const point: Point = { x: 0, y: 0 };

```
Modules in TypeScript allow you to organize your code into logical units and can help to prevent naming conflicts. You can define a module like this:

```
module Shapes {
  export class Triangle {
    // ...
  }
  export class Square {
    // ...
  }
}

const triangle = new Shapes.Triangle();
const square = new Shapes.Square();

```

In addition to these features, TypeScript also includes support for decorators, which are functions that can be used to modify the behavior of a class or its members. For example:

```
function log(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
  console.log(

```
PHP: How to declare the expected type for an array to pass to an abstract method
Tags: php, programming
Published: 2022-12-30 10:39:52

PHP arrays may host mixed content. The language processor won't complain if you write this:

```php
$list = [
  'some-string', 
  3,
  [ 'key' => 'value' ]
];
```

That can be useful in many cases but what if you want to declare an abstract method and indicate to developers what it should get?

```php
abstract class MyClass {
  public abstract function my_function($args);
}
```

## First approach: make the developer aware of the type

Adding a comment is enough to tell the developers what your method expect:

```php
abstract class MyClass {
  /**
   * This method will process a list of objects.
   *
   * @param MyObjects[] $args
   */
    public abstract static function my_function($args);
}
```

## Second approach: make PHP aware of the type

Declaring the argumens as an array is not enough, as it won't indicate the type of what should be inside the array:

```php
public abstract static function my_function(array $args);
```

We'll have to transform the array argument into a variable list of `MyObject` arguments:

```php
public abstract static function my_function(MyObject ...$args);
```

On the caller side, the syntax will need to be changed to spread the arrray:

```php
$result = MyClass::my_function(...$array_of_objects);
```

## Final thoughts

Both approaches can (and should) be mixed: add comments for the developers & make PHP aware of the type.

This implementation makes it easier to follow the types of the variables that are passed across the code but it has a drawback.
By declaring a variable list of arguments to a method, you won't be able to pass multiple lists of different types to it.
Denormalization
Tags: denormalization, beginners, tutorial, database
Published: 2022-12-30 10:17:58

When we listen to the term denormalization, the first thought that might cross our mind is that it means reversing normalization which is not true. Denormalization is a database optimization process where redundant data is added to one or more tables. This was originally designed to avoid costly joins in the relational database.

Denormalization pursues to improve read performance over some write performance where the redundant copies of data are written in multiple tables. This saves us the expensive joins. When the data becomes distributed with sharding or federation, managing joins across the network becomes very complex. Acquiring the denormalization process can prevent such complex joins.

## Advantages of Denormalization

- Data retrieving is fast
- Writing queries is easier
- The number of tables is reduced
- Convenient to manage

## Disadvantages of Denormalization

- Inserts and updates are expensive
- Database design is more complex
- Data redundancy is increased
- Data inconsistency is more probable

{% embed https://github.com/pragyaasapkota/System-Design-Concepts %}

**_I hope this article was helpful to you._**

**_Please don’t forget to follow me!!!_**

**_Any kind of feedback or comment is welcome!!!_**

**_Thank you for your time and support!!!!_**

**_Keep Reading!! Keep Learning!!!_**
CI/CD pipelines with AWS Amplify
Published: 2022-12-30 09:54:59

The company I work for is an AWS partner and it is natural that many of the applications we build are based on the services offered by Amazon.

We're migrating our CI/CD pipelines to AWS Amplify and I will show you how we can achieve great results with just a few clicks.

---

The example is based on a [Next.js](https://nextjs.org/) application hosted on GitHub.<br>

![GitHub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztpqaq2x8wf2iozb0ix0.png)<br>

To initialize the application we can use the command:
`npx create-next-app@latest --typescript`<br>
Once the starter is created, we edit the file
`pages/index.tsx`
replacing the boilerplate with this code:<br>

![pages index](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4u9k0lk1mum9kh7q6dd.png)<br>

An environment variable is used here. We have to configure it in the Next.js configuration file
`next.config.js`

```json
const nextConfig = {
  [...]
  env: { PROJECT_NAME: process.env.PROJECT_NAME, },
}
module.exports = nextConfig
```<br>

We can test the app locally by creating a `.env.local` file to set the environment variable<br>

![EnvLocal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oiiw2gmq2bn5brfa1chm.png)<br>

After we sync the project with remote GitHub, we're ready to move on to the deployment part.

## AWS Amplify

Once logged into the AWS console, let's search for the Amplify service.<br>

![AWSDash](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0k57xtwmnar2mp6mh64l.png)<br>

### Configuration

Click on _Host web app_<br>

![HostWebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxbtbjd3c08sbyo4dpbj.png)<br>

here we can connect our GitHub account and select the project we just created<br>

![GitHubSelection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k9kkyrr47k5yslwhaf8.png)<br>

![GitHubRepo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/st7o8kfa2abxptwlhfq5.png)<br>

Click on _Next_, here we can configure the build and we can set our environment variable<br>

![Build](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24l3kju98ntq8j503z4d.png)<br>

![Save](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbcbjmuu7hbpr1soyhlo.png)<br>

### Build & Deploy

🚀 The build and the deployment will be performed automatically<br>

![Deploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4485myamsoffdcfawxn.png)<br>

### Final result

![FinalResult](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1m52467qd5gqu594u0d.png)

---

This is the first article on AWS Amplify, if you find the topic interesting give ❤️ and I will write more about it. Bye 👋

You can [follow me on Twitter](https://twitter.com/giorgio_boa), where I'm posting or retweeting interesting articles.

{% embed https://dev.to/gioboa %}
Java 中到底哪些例外一定要處理？
Tags: java, exception
Published: 2022-12-30 09:37:40

在 Java 中常常會遇到該捕捉例外卻沒有捕捉, 編譯時發出錯誤的狀況, 到底哪些例外一定要捕捉、哪些不必呢？其實只要知道 Java 中例外類別的階層關係與其所代表的意涵, 就可以判斷了。

## 只有受檢查例外才需要捕捉處理

在 Java 中, 透過例外機制處理的狀況都會包裝成 [Throwable](https://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html) 子類別的物件, 這又可以分為兩大類：

- [Error 類別](https://docs.oracle.com/javase/7/docs/api/java/lang/Error.html)家族：代表發生了通常無法復原的嚴重錯誤, 例如 [OutOfMemoryError](https://docs.oracle.com/javase/7/docs/api/java/lang/OutOfMemoryError.html) 代表記憶體不足, 程式無法解決這樣的問題。
- [Exception 類別](https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html)家族：代表執行期間的各種意外狀況, 例如無法找到指定檔案的 [FileNotFoundException](https://docs.oracle.com/javase/7/docs/api/java/io/FileNotFoundException.html)。其中 [RuntimeException 類別](https://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html)子家族代表的是程式面沒有考慮周詳造成的意外狀況, 像是除以 0 的 [ArithmeticException](https://docs.oracle.com/javase/7/docs/api/java/lang/ArithmeticException.html), 屬於程式員可以完全掌控, 修正程式即可避免的意外。

上述幾大類的例外類別繼承結構如下：

```
java.lang.Throwable
    |
    +---java.lang.Error
    |       |
    |       +....
    |
    +---java.lang.Exception
            |
            +....
            |
            +java.lang.RuntimeException
            |
            +....    
```

其中, Error 和 RuntimeException 兩大類合稱為[**不受檢查 (unchecked) 的例外**](https://docs.oracle.com/javase/specs/jls/se19/html/jls-11.html#jls-11.1.1), 並不強制一定要捕捉處理：

- Error 是無法復原的狀況, 像是記憶體不足, 捕捉了也無濟於事, 程式無法補救, 即使通知使用者, 使用者也不能做什麼處理。

- RuntimeException 則是程式員自己的疏失, 像是除以 0 的狀況就是程式沒有確實檢查才會發生, 引發例外中斷程式執行可以迫使開發者回頭修正程式, 加上必要的檢查避免引發例外。

反之, 其他類的例外就稱為**受檢查 (checked) 的例外**, 一定要在宣告方法時以 [throws](https://docs.oracle.com/javase/tutorial/essential/exceptions/declaring.html) 指明可能發生的例外, 叫用此方法時也必須要捕捉並處理例外, 或是以 throws 交由更外層的程式處理。以剛剛舉例的 FileNotFoundException 來說, 程式應該要補抓例外, 並通知使用者, 讓使用者把檔案補上或是改指定其他路徑讀取檔案等等。

## Java 文件中的標示方法

在 Java 的 [API 文件](https://docs.oracle.com/en/java/javase/19/)中, 可以明確區分個別方法可能會拋出的不受檢查例外與受檢查的例外, 以下以 [Reader 類別的 skip 方法](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/io/Reader.html#read())為例：

![](https://i.imgur.com/K2a18zX.png)

圖中上方紅框內寫在方法原型中的 [IOException](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/io/IOException.html) 就是受檢查的例外, 例如正在讀取中的檔案所在的隨身碟被拔掉, 就會引發 IOException。標示在下方紅框內解說結尾處的就是所有可能發生的例外, 這裡包含了程式員沒注意傳入負值時發生的 [IllegalArgumentException](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/IllegalArgumentException.html) 例外。

只要查看文件, 就可以分清楚一定要處理哪些例外, 而哪些例外不用特別處理, 或是發生時要請使用者通知你修正程式。

## 結語

弄清楚受檢查的例外與不受檢查的例外, 不但可以幫助你決定在程式中要處理哪些例外, 如果你需要自訂例外類別, 也可以分清楚應該要將類別歸屬在哪一個家族下, 否則別人使用你撰寫的類別時, 也會發生該捕捉的例外沒捕捉, 反而捕捉了應該是你撰寫程式時疏忽的狀況, 導致程式中潛藏的問題反而沒有好好處理, 那就麻煩了。