teleren/devto huggingface dataset:
I love Compound View
Tags: android, xml
Published: 2022-06-05 20:45:04

I love separating a piece of the UI to a compound view;
first here how to do it.
create the view in xml as normal,
```xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="40dp"
    tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
    android:layout_height="76dp"
    >
    <TextView
        tools:text="سبت"
        android:fontFamily="@font/neo_sans_arabic"
        android:textStyle="bold"
        android:textColor="#FE000000"
        android:id="@+id/dayNameTextView"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</merge>
```
as you see the parent tag is <merge> it will take where you gonna inflate it at as its parent.
we create new class that extends ConstraintLayout and infalte it using viewBinding:
```kotlin
class PlanDayView(context: Context, attributeSet: AttributeSet?=null) :
    ConstraintLayout(context, attributeSet) {
    var binding: FoodPlansDayBinding

    init {
        inflate(context, R.layout.food_plans_day, this)
        binding = FoodPlansDayBinding.bind(this)
    }


    fun render(uiDayView: UiDayView) {
           TODO("")
    }

}
```
then you make a model represent this Compound View:

```kotlin
data class UiDayView(
    val name: String,
    val number: String,
    val progress: Int,
    val isPassedOrToday: Boolean,
    val isFree: Boolean = false,
    val isSelected: Boolean = false,
    val onClick: (UiDayView)-> Unit,
)
```
Now you can use this in xml like any normal view 
or in code by
```Kotlin
val view = PlanDayView(context)
```
here you made a compound and made UiModel for it and separate a piece of the ui.
here is a question how you use this in viewHolder?.
Remove Zero Sum Consecutive Nodes from Linked List
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 20:30:39

Given the `head` of a linked list, we repeatedly delete consecutive sequences of nodes that sum to `0` until there are no such sequences.

After doing so, return the head of the final linked list.  You may return any such answer.

(Note that in the examples below, all sequences are serializations of `ListNode` objects.)

**Example 1:**

**Input:** head = \[1,2,-3,3,1\]
**Output:** \[3,1\]
**Note:** The answer \[1,2,1\] would also be accepted.

**Example 2:**

**Input:** head = \[1,2,3,-3,4\]
**Output:** \[1,2,4\]

**Example 3:**

**Input:** head = \[1,2,3,-3,-2\]
**Output:** \[1\]

**Constraints:**

*   The given linked list will contain between `1` and `1000` nodes.
*   Each node in the linked list has `-1000 <= node.val <= 1000`.

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def removeZeroSumSublists(self, head: Optional[ListNode]) -> Optional[ListNode]:
            if head:
                total = 0
                curr = head
                while curr:
                    total += curr.val
                    if total == 0:
                        return self.removeZeroSumSublists(curr.next)
                    curr = curr.next
                head.next = self.removeZeroSumSublists(head.next)
            return head
Would you like to know what I've learned by building Expense Tracking App?
Tags: webdev, discuss, javascript, beginners
Published: 2022-06-05 20:14:36

Hey guys! I've been building my Expense Tracking App about 1.5 months and I have a question for you. Would you be interested if I tell you what I've learned for this short period and how I've changed the way I work? I'm thinking it can be interesting for someone, but I want to hear from you. What do you want to hear?
Rectangle Area
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 20:00:45

Given the coordinates of two **rectilinear** rectangles in a 2D plane, return _the total area covered by the two rectangles_.

The first rectangle is defined by its **bottom-left** corner `(ax1, ay1)` and its **top-right** corner `(ax2, ay2)`.

The second rectangle is defined by its **bottom-left** corner `(bx1, by1)` and its **top-right** corner `(bx2, by2)`.

**Example 1:**

![Rectangle Area](https://assets.leetcode.com/uploads/2021/05/08/rectangle-plane.png)

**Input:** ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2
**Output:** 45

**Example 2:**

**Input:** ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2
**Output:** 16

**Constraints:**

*   `-104 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 104`

**SOLUTION:**

    class Solution:
        def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:
            cx1 = max(ax1, bx1)
            cx2 = min(ax2, bx2)
            cy1 = max(ay1, by1)
            cy2 = min(ay2, by2)
            return (ax2 - ax1) * (ay2 - ay1) + (bx2 - bx1) * (by2 - by1) - max(cx2 - cx1, 0) * max(cy2 - cy1, 0)
Web3 Solidity + JavaScript 32 hour course recap #9
Published: 2022-06-05 19:28:59

timestamps: 3:00:00 - 3:30:30

This is a recap of me making my way through the 32 hour course by Patrick Collins posted on [FreeCodeCamp](https://www.youtube.com/watch?v=gyMwXuJrbJQ).

Today revolved around learning how to import other contracts into a master contract, and to extend the functionality of contracts with inheritance.

`pragma solidity ^0.8.0;`

`import "./SimpleStorage.sol";`

`contract ExtraStorage is SimpleStorage{`
    // overrides the function called 'store'
    `function store(uint256 _favoriteNumber) public override{`
        `favoriteNumber = _favoriteNumber +/ 5;`
    `}`
`}`

When importing contracts and/or extending them it is important to keep the versioning compatible. So a pragma of 0.7.0 will not be compatible with ^0.8.0

In order to interact with any contract you need two things: contract address, and its ABI (application binary interface). The ABI lets you know what inputs and outputs the contract has.

Things that I learned: EVM stands for Ethereum Virtual Machine, which is what the Solidity code compiles down to. Polygon, Avalanche, and Fantom are all EVM compatible. Solona uses Rust.
Laravel Seeders and Factories
Tags: laravel, webdev, tutorial, beginners
Published: 2022-06-05 19:46:46

Here, i have come with some code to create laravel seeders and factories. For inserting data in our database for testing purpose.

Create Model Admin
```ssh
php artisan make:model Admin -m
```

Now, open the admin migration file in database directory and table columns.
```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create( 'admins', function (Blueprint $table)
        {
            $table->increments( 'id' );
            $table->string( 'name' );
            $table->string( 'surname' );
            $table->string( 'email' );
            $table->string( 'password' );
            $table->timestamps();
        } );
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists( 'admins' );
    }

}
```
To create table run
```ssh
php artisan migrate
```
Create Factory in Laravel to create random number of records for testing. We will create factory AdminFactory.
```ssh
php artisan make:factory AdminFactory
```
Inside the definition method set your database table columns.
```php
<?php

namespace Database\Factories;

use App\Models\Admin;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class AdminFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Admin::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name' => $this->faker->name,
            'surname' => $this->faker->name,
            'email' => $this->faker->unique()->safeEmail,
            'password' => bcrypt('123456'), // password
        ];
    }
}
```

Now, create seeder to run factory or database queries.
```ssh
php artisan make:seeder AdminSeeder
```
Inside run method apply factory on Admin model.
```php
namespace Database\Seeders;

use App\Models\Admin;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class AdminsSeeder extends Seeder
{
	/**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Admin::factory()
            ->count(50)
            ->create([
                'surname' => 'Kumar',
            ]);
    }
}
```
Now run the seeder class
```ssh
php artisan db:seed --class=AdminSeeder
```
This will create 50 random records in table admins

---
Please like share and give positive feedback to motivate me to write more.

For more tutorials [visit my website](https://www.w3courses.org/category/code-examples/).

Thanks:)
Happy Coding:)
CSS: Dynamically Text Truncate
Tags: css, truncate, html, tutorial
Published: 2022-06-05 19:33:03

DEMO: https://jsfiddle.net/bc6ep913/

**PREVIEW**

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

**HTML**

```html
<div class="wrap">
  <div class="text-truncate">
    The glory and freedom of Ukraine has not yet perished
Luck will still smile on us brother-Ukrainians.
Our enemies will die, as the dew does in the sunshine,
and we, too, brothers, we'll live happily in our land.
  </div>
</div>
<div class="wrap">
  <div class="text-truncate">
    The glory and freedom of Ukraine has not yet perished
Luck will still smile on us brother-Ukrainians.
Our enemies will die, as the dew does in the sunshine,
and we, too, brothers, we'll live happily in our land.
  </div>
</div>
```

**CSS**
```css
.wrap {
  display: table;
  table-layout: fixed;
  width: 100%;
}

.text-truncate {
  display: table-cell;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
```
Linked List Cycle
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 19:30:41

Given `head`, the head of a linked list, determine if the linked list has a cycle in it.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the `next` pointer. Internally, `pos` is used to denote the index of the node that tail's `next` pointer is connected to. **Note that `pos` is not passed as a parameter**.

Return `true` _if there is a cycle in the linked list_. Otherwise, return `false`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png)

**Input:** head = \[3,2,0,-4\], pos = 1
**Output:** true
**Explanation:** There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).

**Example 2:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test2.png)

**Input:** head = \[1,2\], pos = 0
**Output:** true
**Explanation:** There is a cycle in the linked list, where the tail connects to the 0th node.

**Example 3:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test3.png)

**Input:** head = \[1\], pos = -1
**Output:** false
**Explanation:** There is no cycle in the linked list.

**Constraints:**

*   The number of the nodes in the list is in the range `[0, 104]`.
*   `-105 <= Node.val <= 105`
*   `pos` is `-1` or a **valid index** in the linked-list.

**Follow up:** Can you solve it using `O(1)` (i.e. constant) memory?

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def hasCycle(self, head: Optional[ListNode]) -> bool:
            slow = head
            fast = head
            while slow and fast and fast.next:
                slow = slow.next
                fast = fast.next.next
                if slow == fast:
                    return True
            return False
Memray in SAP Business Application Studio
Published: 2022-06-05 19:19:29

Bloomberg has open-sourced Memray, a powerful memory profiler tool for python that it has been using.

**Bloomberg Memray**
Memray is a memory profiler tool for python that was developed by Bloomberg.  Memray makes it easy to get stats of the memory allocated to applications. Memray can generate flame graphs reports of memory usage.

Memray works with

- native threads
- python thread

**Importance of Memray**
In Python, memory profiling is not as simple as we expect because of how the Python interpreter manages memory. This is where Memray comes in.

Memray can help you to

- Find out what it causing high memory usage
- Discover memory leaks
- Find code that is causing high memory allocation so that you can make the correct programming adjustments

**Memray Installation requirements**

- Memray can be installed from PyPI with a Python interpreter.
- You need to have Python 3.7+ to install it.
- Memray can only run on Linux OS.

Having stats of memory usage in your applications is important for microcomputers with little memory. If memory is not managed properly it can lead to apps crashing and loss of data.



https://blogs.sap.com/2022/06/05/track-your-python-memory-allocations-sap-bas/
free meetup: Open Source London
Published: 2022-06-05 19:10:04

Amazing news to the whole #OpenSource community.
The "London Open Source Meetup Group" has been created.

Even better, the first meetup is happening next Saturday, the 11th of June 2022 at 1300 BST.

During the meetup, I will share my experience in getting into #OpenSource.

I will explain why contributing is important for your career and how you can contribute, even if you do not possess any coding skills.

#java #net #opensourcecommunity

Check out this Meetup: Open Source: Getting Started https://www.meetup.com/meetup-group-fazqypkf/events/286376122?utm_medium=referral&utm_campaign=share-btn_savedevents_share_modal&utm_source=link #Meetup 

#opensourcecommunity #java #openjdk
Jump Game
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 19:00:41

You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.

Return `true` _if you can reach the last index, or_ `false` _otherwise_.

**Example 1:**

**Input:** nums = \[2,3,1,1,4\]
**Output:** true
**Explanation:** Jump 1 step from index 0 to 1, then 3 steps to the last index.

**Example 2:**

**Input:** nums = \[3,2,1,0,4\]
**Output:** false
**Explanation:** You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.

**Constraints:**

*   `1 <= nums.length <= 104`
*   `0 <= nums[i] <= 105`

**SOLUTION:**

    class Solution: 
        def canJump(self, nums: List[int]) -> bool:
            n = len(nums)
            leftmost = n - 1
            for i in range(n - 1, -1, -1):
                if i + nums[i] >= leftmost:
                    leftmost = i
            return leftmost == 0
CSS Debug With 3 Lines
Tags: css, style, html, webdev
Published: 2022-06-05 18:52:34

```
* {
  background: #000 !important;
  color: #0f0 !important;
  outline: solid #f00 1px !important;
}
```

I needed to debug some heavily styled css and this debugger is a game changer. Drop this into your css file and locate the bug. 

:heart::heart::heart:

## Social 
[Twitter](https://twitter.com/GregoriosPetro1)
[Linkedin](https://www.linkedin.com/in/greg-petropoulos/)
[Portfolio](https://gregpetropoulos.dev/)
[Github](https://github.com/GregPetropoulos)

:metal:
## Happy Coding
All about Screen 🖥 command
Tags: linux, commands, screen, devops
Published: 2022-06-05 18:46:29

Hey there everyone have you ever run a service and wondered why the hell this service does not have detached mode ( detached mode means a service which runs in background and does not freeze your terminal ) so this is the one stop solution for you

## What is screen command

You can assume screen command as a new screen for you inside terminal where can you create multiple virtual screen to run multiple services

This command is very useful if you are in server using ssh and want to run a service in background but service itself does not provide a detached mode. ( e.x. ElasticSearch )


If you have unix system ( linux or macos ) screen command should be available to you 

To check screen command is available to you or not just run 
```bash
screen -v
```
it it returns any version like this voila you have screen command installed.

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


Now let's have a look how it works 

You can create a screen with below command
```bash
screen -S SCREEN_NAME
```
it will create a screen put you into that screen
to create a screen without entering into it you can run
```bash
screen -dmS SCREEN_NAME
```
it will create a screen but it won't go into screen

2. Now that you have created a screen if you want to see a list of screen you have created you can use below command
```bash
screen -ls
```
it should give you the list of screens you have created!
[Screen Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7q2igvnwbxtu4wykhu2.png)
 
3. Now that you have created and listed out screens you can enter into any screen by typing below command
```bash
screen -dR SCREEN_NAME
```
in case you can see your screen in ```screen -ls``` command but unable to enter it try to enter into screen by using full name of screen with pid.SCREEN_NAME

pid is id which you can see in screen -ls command 

4. Now that you can created, listed and entered into screen and did you stuff now you want to make sure it runs in background so to come out from screen and run in background you have to press ```CONTROL+A+D```
by pressing this you will come out of screen and it will run in background

5. How to delete a screen to delete a screen enter into the screen and press ```CONTROL+D``` it will terminate your screen and you will see an output like this

![Screen Terminating](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7iejqie59xy12icf9u2.png)

So this is all basics about screen command which you have inside your system to know more about it type ```screen --help``` you will get all the options available there.

Thanks for reading!
Split Linked List in Parts
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 18:30:34

Given the `head` of a singly linked list and an integer `k`, split the linked list into `k` consecutive linked list parts.

The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.

The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.

Return _an array of the_ `k` _parts_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/06/13/split1-lc.jpg)

**Input:** head = \[1,2,3\], k = 5
**Output:** \[\[1\],\[2\],\[3\],\[\],\[\]\]
**Explanation:**
The first element output\[0\] has output\[0\].val = 1, output\[0\].next = null.
The last element output\[4\] is null, but its string representation as a ListNode is \[\].

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/06/13/split2-lc.jpg)

**Input:** head = \[1,2,3,4,5,6,7,8,9,10\], k = 3
**Output:** \[\[1,2,3,4\],\[5,6,7\],\[8,9,10\]\]
**Explanation:**
The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.

**Constraints:**

*   The number of nodes in the list is in the range `[0, 1000]`.
*   `0 <= Node.val <= 1000`
*   `1 <= k <= 50`

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def getLength(self, head):
            if head:
                return 1 + self.getLength(head.next)
            return 0
        
        def getParts(self, head, lens, p):
            if not head:
                return [None]
            i = 0
            prev = None
            curr = head
            while curr and i < lens[p - 1]:
                prev = curr
                curr = curr.next
                i += 1
            prev.next = None
            if p < len(self.op):
                self.op[p] = curr
            self.getParts(curr, lens, p + 1)
        
        def splitListToParts(self, head: Optional[ListNode], k: int) -> List[Optional[ListNode]]:
            n = self.getLength(head)
            lens = [n // k] * k
            for i in range(n % k):
                lens[i] += 1
            self.op = [None] * k
            self.op[0] = head
            self.getParts(head, lens, 1)
            return self.op
Need some help for getting started
Tags: dotnet, programming, help, opensource
Published: 2022-06-05 18:08:55

Hey guys . My name is Mahdi and I am a .Net-core Back-end developer and this is my first post :)) . In this post I want to get some ideas from you cool people for starting to write posts . I don't know where to start , It should be something about my experiences or something else.
I will read all of your advices and appreciate it in advance.
By the way I love to starting to contribute in an open source project in my free times just tell me if you have an interesting one 😉
My Email Address : qanbarim326@gmail.com
My Telegram : https://t.me/mahdignb
Water Bottles
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 18:00:45

There are `numBottles` water bottles that are initially full of water. You can exchange `numExchange` empty water bottles from the market with one full water bottle.

The operation of drinking a full water bottle turns it into an empty bottle.

Given the two integers `numBottles` and `numExchange`, return _the **maximum** number of water bottles you can drink_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/07/01/sample_1_1875.png)

**Input:** numBottles = 9, numExchange = 3
**Output:** 13
**Explanation:** You can exchange 3 empty bottles to get 1 full water bottle.
Number of water bottles you can drink: 9 + 3 + 1 = 13.

**Example 2:**

![](https://assets.leetcode.com/uploads/2020/07/01/sample_2_1875.png)

**Input:** numBottles = 15, numExchange = 4
**Output:** 19
**Explanation:** You can exchange 4 empty bottles to get 1 full water bottle. 
Number of water bottles you can drink: 15 + 3 + 1 = 19.

**Constraints:**

*   `1 <= numBottles <= 100`
*   `2 <= numExchange <= 100`

**SOLUTION:**

    class Solution:
        def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
            total = numBottles
            numFilled = 0
            numEmpty = numBottles
            while numEmpty >= numExchange:
                numFilled = (numEmpty // numExchange)
                total += numFilled
                numEmpty = numFilled + numEmpty % numExchange
            return total