teleren/devto huggingface dataset:
Kotlin Function
Tags: kotlin, android, programming, mobile
Published: 2023-01-05 12:44:08

Kotlin is a modern, statically-typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains, the company behind the popular Java Integrated Development Environment (IDE) called IntelliJ IDEA. Kotlin was designed to improve upon Java, offering more concise and expressive syntax, improved type inference, and better support for functional programming.

One of the key features of Kotlin is the function. A function is a block of code that performs a specific task and may return a value. In Kotlin, functions are first-class citizens, which means that they can be assigned to variables, passed as arguments to other functions, and returned as values from functions.

To declare a function in Kotlin, you use the **fun** keyword followed by the function name, its parameters, and its return type. For example, the following function takes two integers as arguments and returns their sum:

```
fun add(x: Int, y: Int): Int {
    return x + y
}

```

You can call a function by using its name followed by a pair of parentheses, like this:

```
val result = add(5, 7) // result is 12

```

If a function doesn't return a value, you can use the **Unit** type as its return type. The Unit type is equivalent to the void type in Java. For example:

```
fun printHelloWorld() : Unit {
    println("Hello, world!")
}
```
In Kotlin, you can also define functions with a single expression as their body. These are called "single-expression functions." For example:

```
fun add(x: Int, y: Int): Int = x + y
```
In this case, the return type is inferred by the compiler, so you don't need to specify it explicitly.

You can also define default values for function parameters, which allows you to call the function with fewer arguments. For example:

```
fun add(x: Int, y: Int, z: Int = 0): Int {
    return x + y + z
}
```

In this case, you can call the **add** function with two arguments, and z will default to 0.

Kotlin also has a powerful feature called "higher-order functions," which are functions that take other functions as arguments or return them as values. This allows you to write very concise and expressive code. For example:

```
fun applyTwice(f: (Int) -> Int, x: Int): Int {
    return f(f(x))
}

val result = applyTwice({ x -> x * x }, 2) // result is 16

```
In this example, **applyTwice** is a function that takes a function **f** and an integer **x**, and applies **f** to **x** twice. The function f is defined using a lambda expression, which is a concise way of defining a function inline.

Kotlin functions are an important and powerful feature of the language, and they allow you to write concise and expressive code. Whether you're a seasoned programmer or a beginner, learning how to use functions effectively is an essential part of becoming proficient in Kotlin.
Get unlimited blog articles & free stock photos [Free Trial]
Published: 2023-01-05 18:41:57

Everyone knows how important good content is to rank in Google and to drive traffic to your website. Manually writing this content usually takes a long time that can better be spend on other tasks. That is why I created a new AI tool which creates unlimited unique articles for you for just $16/month.

Use artificial intelligence trained to write original, creative content based on the well known GPT-3 with custom modifications. You can define the topic as well as keywords it should include. Please feel free to give it a try with the free trial: [https://www.HeronAI.com](https://www.HeronAI.com)

Many of my users use it to rank in Google, some creating 300 articles/month and more. Increase your conversion rates with creative and engaging ad copies or product descriptions and scale up your content marketing.
Deadlines: pointless or necessary?⏰🔄
Tags: deadlines, softwareengineering, developer, blog
Published: 2023-01-05 19:41:32

Hey there, developers!

‍Raise a hand if you scorn deadlines. 🤚

Many <a href="https://codingforspeed.com/tips-to-boost-your-dev-career/" title="Tips to Boost Your Dev Career">developers</a> cannot get along with deadlines, target dates, time limits, or any other name we have for this dreadful thing.

Or maybe devs have a problem with poorly set deadlines?

Let's dig in!

<h3>Why are deadlines important?</h3>
Like it or not, it's true that having and meeting deadlines can help with efficiency, planning and organizing. Here are some other reasons why deadlines are not so bad after all:

<ul>
<li>Defining goals: Thoroughly analyzed steps will result in a better overview of time and other resources needed to complete tasks. This further helps with prioritizing and delegating tasks.</li>
<li>Prioritizing: Unfortunately, time at our hands is limited, so prioritizing goals is necessary. It helps with focusing on currently more important tasks, while others, less demanding, can be postponed.</li>
<li>Motivating: Deadlines should not mean pressure, but having no deadline could mean having no direct incentive to finish the task on time. Tasks finished after target dates intervene with other tasks and the whole project.</li>
</ul>

Having said this, one question comes to mind.

<h4>Why don't developers and deadlines get along?</h4>
One of the major problems with the <a href="https://codingforspeed.com/maximizing-dev-productivity/" title="Maximizing Dev Productivity">developer</a>-deadline relationship is that in most cases, developers aren't the ones setting the deadlines.

Estimating, planning and tracking tasks and projects is a difficult skill that shouldn't be taken lightly.

Yet in most cases, managers that set deadlines don't have the technical background or experience to estimate properly.

Instead, developers hear something like this: "I promised the client we will do it by then."

And what the non-developing part of the population forgets is that <a href="https://codingforspeed.com/is-there-such-thing-as-high-quality-code/" title="Is There Such Thing as High-Quality Code?">programming</a> is actually a design process. In other words, it's a discovery process, and with discovery comes uncertainty.

<a href="https://helloacm.com/teaching-kids-programming-check-if-there-is-a-path-with-equal-number-of-0s-and-1s-breadth-first-search-algorithm/" rel="noopener" target="_blank">Programming</a> does not equal manufacturing.

So maybe developers just don’t like badly set deadlines, or it's just too hard to set one.

What do you think? Hit reply; we would appreciate your opinion!

Reposted to [Blog](https://codingforspeed.com/are-deadlines-pointless-or-necessary/)
Offline Pip Packages
Tags: python, archive
Published: 2023-01-06 01:43:22

---
title: Offline Pip Packages
published: true
date: 2020-01-21 04:11:05 UTC
tags: Python,Archive
canonical_url: https://brandonrozek.com/blog/offlinepip/
---

There are a few reasons I can think of to have offline pip packages:

- A package isn’t able to compile on a friend’s computer since they don’t have the million linear algebra libraries that `numpy` /`scipy` require.
- You want to archive everything to run a piece of software
- You want to control the packages available to a closed network

Regardless, to my surprise, setting up a repository of python wheels doesn’t take many steps.

## Setup

First I would recommend that you setup a virtual environment. Either through [pyenv](/blog/pyenv/) or [python-virtualenv](/blog/virtualenv/).

Then, install whatever packages you would like. Let us use tensorflow as an example:

```
pip install tensorflow

```

We’re going to need the packages `pip-chill` and `pip-tools` for the next couple steps

```
pip install pip-chill pip-tools

```

After you install all the packages you want to be available, freeze the requirements that aren’t dependencies to a text file

```
pip-chill --no-version > requirements.in

```

We will then use `pip-compile` in `pip-tools` to resolve our dependencies and make our packages as fresh as possible.

```
pip-compile requirements.in

```

To sync the current virtual environment with the `requirements.txt` file that gets produced

```
pip-sync

```

Now we have a fully working and resolved environment.

From here, we need to install the wheel package to make the binary wheels.

```
pip install wheel

```

Then to create the wheels,

```
pip wheel --wheel-dir=wheels -r requirements.txt

```

With this you have a whole repository of wheels under the wheels folder!

## Client Side

Now you can get [all fancy with your deployment](https://realpython.com/offline-python-deployments-with-docker/#deploy), though I just assumed that the files were mounted in some shared folder.

The client can install all the wheels

```
pip install /path/to/wheels/*

```

Or they can just install the packages they want

```
pip install --no-index -f /path/to/wheels/wheels package_name

```

If you don’t want to add flags to every command, check out my post on using [configuration files with pip](/blog/pipconf/).
How to type React Props with TypeScript
Published: 2023-12-04 15:16:40

---
title: How to type React Props with TypeScript
published: true
date: 2023-01-06 06:39:01 UTC
tags: 
canonical_url: https://akoskm.com/how-to-type-react-props-with-typescript
---

Typing React Props with TypeScript can be done in different ways, but not each way will provide you with an equal level of type safety.

First, let's take a look at a simple component we'll use to demonstrate the two methods, but without typing the props first:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672985823621/6499dde6-cd19-463a-8002-d6639cdd22fd.png)

I always set `"noImplicitAny": true,` so my editor warns me about the untyped props.

Let's type them with React's `FC` interface.

## React.FC

`React.FC` is a generic type in the React module that defines a functional component in TypeScript. It is a shorthand for describing a functional component that has a prop type.

In our example, `ProfileCard` is a functional component that expects to receive props with a `name` string and an `age` number. These props are typed using the `Props` interface, and the component is typed as `React.FC<Props>`, which specifies that it is a functional component with the specified prop types:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672985478240/aedf5c32-fe73-4d12-8835-bffefdde4ba4.png)

As we see, the errors disappeared because through `React.FC<Props>`, we specified the types for both the `name` and `age` props.

## props: Prop

Another, even more straightforward way to type React props is to specify the object type inside the function's signature.

Below we're simply telling react that this object has a specific type:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672985518276/ac40ceed-b110-46b1-9e84-e56b3edc0794.png)

Now let's see the differences between the two regarding type safety.

# Differences in type safety

When using `React.FC`, if you define a default value with a different type than the type in `Props`, it'll merge the two types and assign that as the new type for the prop.

You might expect the below code to fail the TypeScript compilation, but it won't.

Here's the new type `React.FC` created for `name`:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672985886267/ab7a5b6a-014d-4b59-bca2-ccf01c5d82ef.png)

However, if you use the `props: Prop` method to type your props, you get an error right away:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672985941583/fd4917de-77b9-4493-a940-a4446f8943c0.png)

# Conclusion

Because of this difference, I always prefer the `props: Prop` way to define props in React.

But keep in mind, if you are using TypeScript in your entire codebase, a wrongly typed default value might pop up an error in the component that ends up using it.

Here's an example of that:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672986328213/5b5308fb-49f7-404e-a04a-95f4f6238141.png)

The TypeScript compiler warns us that `ProfileName` expects a name with the type of `string` and not with the type of `string | boolean`.
Day 155: I'm back...
Published: 2023-01-30 05:12:36

Hi!
Long time no see! 
It's been a while since my last time here. to be precise it's been 141 days (quite a long time) and during this time I had been on another learning adventure but home (here) is the best, and here I am, back to the beginning again.

I stopped (or paused) blogging for a while because I thought I was busy that I would not find time to write but I recently realized that I have forgotten the main reason that I started the blogging challenge in the first place. When I started the main point was to challenge myself to write something about anything every day no matter how unmotivated or busy I thought I was. Just something too simple to avoid doing. And these small short articles I used them to document my learning journey, and stay focused and organized and that's where came motivation for writing tutorials and learned a lot in the process.  
when I started I struggled with consistency but after realizing the benefits that come with it I was addicted to it and now **I'm Back again**,  same place, same purpose: Writing daily to improve my coding, writing, and communication skills in general.

During this hibernation time, I had been doing mostly the fronted stuff and deep diving into JavaScript language itself, I got introduced to Next JS and did a lot of Tailwind CSS, and CSS animation. I have a lot to share with the community now and I plan to hustle to write a lot more this year.

See you around!

Signing off
ANGULAR ERROR INTERCEPTORS
Tags: angular, beginners, programming, webdev
Published: 2023-01-30 14:31:25

What is interceptor in angular?
This is important for us as developer know about interceptor
so In Angular, an interceptor is a mechanism for handling or transforming HTTP requests and responses globally before they reach the components. It allows you to pre-process or post-process requests and responses. It is commonly used for tasks such as adding headers, handling errors, transforming data, etc.

why I say that an interceptor is important ? because they provide a way to handle HTTP requests and responses in a centralized and reusable manner, rather than having to write the same code in multiple places. This can improve the maintainability, readability, and testability of your code. Additionally, using interceptors can simplify common tasks such as adding headers or handling errors, reducing the amount of repetitive code and making it easier to make global changes.

Now Im gonna create the simple interceptor for handle error 401 response service

the first step we should create the interceptor, we can use commandline to generate interceptor
```
ng g interceptor error

```

Angular will create the file error.interceptor.ts
like this

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

and will automaticly create the code interceptor like this

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

and we can add some code to detect error server

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

we will navigate the user is not login to login or to 401 page
but we already create the interceptor file we must import this to app.module.ts


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

And this will direct to 401 page

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nttq7yz6djz01uzcto3w.png)
Host ReactJS App On GitHub Pages
Published: 2024-02-03 17:58:59

---
title: Host ReactJS App On GitHub Pages
published: true
date: 2022-12-28 05:19:14 UTC
tags: 
canonical_url: https://adithyana.hashnode.dev/host-reactjs-app-on-github-pages
---

### What is this blog about

In this blog, I am going to tell you how we can host a react-js web app on GitHub Pages

### Prerequisite

- The ReactJS app should have a GitHub repository

- The GitHub repositories visibility should be public

- You should know the basics of git

### Steps By Step Instruction

1. Add a `remote` that points to the GitHub repository

2. Install the GH-Pages package inside the react app

3. Add `homepage` field to the `package.json` file

4. Add `predeploy` and `deploy` scripts to the package.json scripts section

In my case, it will be

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1672200941372/8c379620-bebb-4cc7-96bb-1894f90b0965.png)

1. Run the deploy command in terminal

2. Publishing the newly deployed branch - `gh-pages`
What is ls, pwd, chmod, chown in shell?
Published: 2023-02-02 04:29:07

## ls - list directory contents
When we have to list the directory contents we use ls command. Some common flags used with ls are:

    ls [flags] [File]

- **-l**: Use a long listing format, showing details such as permissions, owner, group, size, and date modified 
- **-a**: Show hidden files, which are files that start with a dot (.)
- **-h**: Show sizes in human-readable format, for example, 1K, 20K, 80M instead of numbers in bytes
- **-t**: It sort all the files by modification time, the new modification comes first.
- **-r**: Reverse the order of the sort, for example, sort files by modification time, oldest first

## pwd - prints the name of current or working directory

    pwd

We use pwd command when we want to display the absolute path of the current working directory.
 
## rm - remove files or directories
rm is used to delete files or directories. Be careful when using rm, as there is no trash bin or undo for deleted files.

    rm [flags](optional) [File]

Some of the useful flags are:

- **-f**: Force removal, do not prompt for confirmation
- **-r**: Remove directories and their contents recursively

## chmod - change file mode bits

When we have to change the permissions of any files and directories chmod command is used.

    chmod [permission_elements] [filename/directoryname]

Some of the basic option we use with chmod for changing permissions are:

- **u**: User/owner permissions
- **g**: Group permissions
- **o**: Other (world) permissions
- **+**: Add permission
- **-**: Remove permission
- **-R**: Operate on files and directories recursively

we can also use decimal number ranging between 0-7 for each element of the permission.
The permission in decimal format are:
- 4 - read
- 2 - write
- 1 - execute
- 6 - read and write
- 5 - read and execute
- 3 - write and execute
- 0 - no permission

## chown - change owner of the file and group
chown is used to change the owner and/or group of a file.

if we want to change the user ownership of given file/directory (root access needed)
```
chown [username] [filename/directory]
```
change both user and group:
```
chown [username:groupname] [filename/directory]
```
- -R: Operate on files and directories recursively
FizzBuzz: the-problem 🧮
Tags: javascript, fizzbuz, beginners, tutorial
Published: 2023-02-09 00:22:57

Hello! Welcome.
This is my first article, _seriously first_, and I'd like to talk a little about a _"problem"_ I learned when I was entering the programming field _(intern)_. It's very **simple**, **fun** and **makes you think a lot** about how you think, logically speaking, and if you can go beyond the basics. I hope you like this series of articles that I'll be creating, _happy reading!_

# What?
*Fizzbuzz* is a `word-game` for children that teacher uses to teach them about *math divisions*. The game consists in replace any number divisible by *three* with the word **Fizz**, and any number divisible by *five* with the word **Buzz** and any number divisible by both *(three and five)* with the word **FizzBuzz**.

The *game* above can be used as a coding interview question in some case. The question consist in write a logic to output the first 100 *(hundred)* `FizzBuzz` numbers. Your value in interviews is to analyze fundamental coding habits, like, *logic*, *design* and *language proficiency*.

# How it works in code
The code bellow shows how the *"FizzBuzz"* logic work.

```javascript
// javascript
const x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

for (let [i, n] of x.entries()) {
    if (n % 15 === 0) {
        x[i] = 'FizzBuzz';
        continue;
    }
    if (n % 3 === 0) {
        x[i] = 'Fizz';
    }
    if (n % 5 === 0) {
        x[i] = 'Buzz';
    }
}
console.table(x);
// Output:
┌─────────┬────────────┐
│ (index) │   Values   │
├─────────┼────────────┤
│    0    │ 'FizzBuzz' │
│    1    │     1      │
│    2    │     2      │
│    3    │   'Fizz'   │
│    4    │     4      │
│    5    │   'Buzz'   │
│    6    │   'Fizz'   │
│    7    │     7      │
│    8    │     8      │
│    9    │   'Fizz'   │
│   10    │   'Buzz'   │
│   11    │     11     │
│   12    │   'Fizz'   │
│   13    │     13     │
│   14    │     14     │
│   15    │ 'FizzBuzz' │
└─────────┴────────────┘
```
---
That's FizzBuzz, I hope you understood and I'll see you in the next article! Let's talk a little about TDD and how we can apply it to this simple _"application"_. I'll see you there!
ChatGPT API: A blog written by ChatGPT
Tags: chatgpt, beginners
Published: 2023-02-01 02:52:17

ChatGPT API by OpenAI is a cutting-edge technology that is transforming the world of natural language processing (NLP). With its advanced language generation and contextual understanding capabilities, ChatGPT API is helping businesses and individuals automate and improve their content creation processes. In this blog, we'll guide you through the steps of using the ChatGPT API to its fullest potential.

Step 1: Sign up for an API key

To use the ChatGPT API, you first need to sign up for an API key from OpenAI. This will give you access to the API and allow you to start making requests. The sign-up process is simple and straightforward, and OpenAI provides excellent documentation to help you get started.

Step 2: Familiarize yourself with the API

Once you have an API key, it's important to familiarize yourself with the API and understand how it works. OpenAI provides extensive documentation on the API, including sample requests and responses, so take advantage of this resource to learn as much as you can.

Step 3: Test the API

Now that you have a basic understanding of the API, it's time to start testing it. Use the API to generate text, translate language, or create custom language models tailored to your specific needs. Start with simple queries and gradually build up to more complex tasks as you become more familiar with the API.

Step 4: Integrate the API into your workflow

Once you have tested the API and are confident in its capabilities, it's time to integrate it into your workflow. This may involve incorporating it into an existing application or creating a new one from scratch. Whatever the case, make sure to take advantage of the API's advanced language generation and contextual understanding capabilities to maximize its impact.

Step 5: Monitor and evaluate performance

It's important to monitor and evaluate the performance of the ChatGPT API to ensure that it's delivering the results you want. Use metrics such as accuracy, response time, and user satisfaction to measure its effectiveness, and make adjustments as necessary.

In conclusion, ChatGPT API by OpenAI is a powerful tool for businesses and individuals looking to automate and improve their content creation processes. With its advanced language generation and contextual understanding capabilities, the API is a valuable tool for maximizing the impact of NLP. So why wait? Get started today and unleash the power of ChatGPT API!

Thank you! 
[Jonny](linkedin.com/in/jonnytilahun)