teleren/devto huggingface dataset:
Delegation In Kotlin
Tags: kotlin, delegation
Published: 2021-09-04 15:23:55

kotlin support  delegation pattern using **by** keyword. it allows the derived class to access all the implemented public methods of an interface  through a specific object.

```kotlin
interface Base {
    fun print()
}
``` 

```kotlin
class BaseImpl(val x:String):Base{
   override val msg: String?  = x  
    override fun print(){
        println("Printing impl ${msg}}")
    }
}
class BaseAnotherImpl():Base{
     override val msg: String?  = null  
    override fun print(){
        println("Printing Another impl ")
    }
}
``` 

don't need to write this code
```kotlin
//class Derived (val b:Base) :Base{
//     override fun print(){
//         b.print()  // delegating the responsibility  of b reference
//     }
// }

``` 
kotlin supports this natively use this code

```kotlin
class Derived(b:Base):Base by b 
``` 

```kotlin
fun main(args: Array<String>) {
    val b1 = BaseImpl("Hell")
    Derived(b1).print()

    val b2 = BaseAnotherImpl() // Printing impl Hell
    Derived(b2).print() // Printing Another impl    
}
``` 

**Overriding  member of an interface implemented by delegation**

```kotlin
class Derived(b:Base):Base by b  {
    override val msg  = "2"   // can't access this property by b reference 

    override fun print(){
        print("\noverriding  print method of interface ")
        
    }
}
``` 

```kotlin
  // after overiding 
    val d = Derived(b1)
    d.print() // overriding  print method of interface
    print(d.msg) // 2 

``` 

Original post on [sanjayprajapat.hashnode.dev](https://sanjayprajapat.hashnode.dev/delegation-in-kotlin)
Shopping Websites You Might Not Know!
Published: 2021-09-04 15:15:46

*This post will be updated.*
Usually you should checkout Amazon, Flipkart and The company's official website but some other sites to look for are listed below-

**[Elite Hubs](https://elitehubs.com/)**
Better pricing for some products from AntEsports, AMD, Antec, Razer, Zotac, Intel etc.

**[Furper](https://www.furper.com/)**
Buy unique international products in India in INR and even 1 quantity.
**[28 Mobiles](https://28mobile.com/)**
Promoted by C4ETech, to buy China only devices internationally.

**[Supertails](https://supertails.com/)**
Fast Shipping and Better pricing on Dog and Cat Products.


These are my friend's finds-
Variable Arguments(Varargs in koltin)
Tags: kotlin, varargs, programming
Published: 2021-09-04 14:57:57

To pass variable number of arguments to a function. We can declare function with varargs parameter.

In java looks like
> public void println(String.. args) { }


```kotlin
// allow function to accept number of arguments 
fun printAnimal(vararg animals:String):Unit{
    for (animal in animals) {
        print("\n $animal")
    }
}

fun printAnimal2(a1: String, vararg animals:String):Unit{
    print("first -> $a1") // elephant    // first argument goes in starting parameter 
    for (animal in animals) {
        print("\n $animal")
    }
}
```

```kotlin
fun main(args: Array<String>) {
    printAnimal("Lion", "Cheetah", "Cat", "Hayena")
    print("\n")
    printAnimal2("Elephant","Lion", "Cheetah", "Cat", "Hayena")
}
```

**Passing List of Function to function**
```kotlin
fun passFun(vararg funs:()->Unit){
   for (f in funs) {
       f() // to call function 
   }
}
fun f1(){
    print("function 1 ,")
}
fun f2(){
    print("function 2 ")
}

```

```kotlin
fun main(args: Array<String>) {
    // passing reference of function
    passFun(::f1,::f2) //  function 1 , function 2
}

```

**Generic function**
```kotlin
fun <T> printAny(vararg varg: T) {
    varg.forEach { println(it) }
}

```

```kotlin
fun main(args: Array<String>) {
    printAny(34,56,89)
}

```

Original post on [sanjayprajapat.hashnode.dev](https://sanjayprajapat.hashnode.dev/variable-argumentsvarargs-in-koltin)
Tips Chat Dengan Gebetan Agar Dia Tidak Bosan Sama Kita
Published: 2021-09-04 14:48:29

Seolah-olah seseorang akan ingin tahu tentang orang yang kita sukai dan, tentu saja, itu akan membuat hati berbunga. Mungkin Anda memiliki percakapan dengannya setiap hari dengan terus-menerus.

Namun, di satu sisi, bingung bagaimana memulai percakapan dengannya untuk bersenang-senang.

Ketika dia berkomunikasi dengannya terlebih dahulu, tentu saja, dia berharap untuk mendapatkan tanggapan lama untuk waktu yang lama tanpa pendek sehingga pesannya tidak terjebak di sana.

Jika Anda mulai dengan obrolan yang membosankan, Anda bahkan tidak dapat tertarik mengobrol dengan Anda lagi.

Yang Anda harus memiliki jalan keluar dan apa yang perlu Anda ketahui adalah, pada kenyataannya, mengobrol dengan seseorang yang kami sukai, itu bukan hal yang mudah bagi kami untuk melakukan terutama mencari topik percakapan sehingga percakapan berjalan tanpa masalah.

Karena itu, konsultasikan dengan tips obrolan dengan jatuh cinta sehingga Anda tidak bosan dengan Anda.

See All : https://www.kreatizen.my.id/2021/08/tips-chat-dengan-gebetan-agar-dia-tidak.html
Link Judul
Tips Memperbaiki Aksen
Published: 2021-09-04 14:34:47

Banyak siswa telah belajar dalam bahasa Inggris untuk waktu yang lama, dan mereka sudah memiliki banyak kosakata, dan mereka dapat berbicara tanpa masalah, memiliki masalah dengan aksen yang juga dialek atau aksen mereka dalam bahasa Inggris masih dipengaruhi oleh bahasa asal.

Seperti yang kita ketahui, Indonesia terdiri dari beberapa suku, masing-masing memiliki dialek yang khas, jadi ketika orang Batak berbicara bahasa Inggris, bahasa Inggris masih Batak Inggris. Dewasa juga bahasa Inggris masih berbahasa Inggris, dan sebagainya.

Mengubah aksen asli atau dialeknya mudah. Tetapi di sini saya akan memberikan 5 tips tentang peningkatan aksen dan pengucapan itu, semoga, dapat membantu mengintegit aksen bahasa Inggris Anda.


See All : https://www.kreatizen.my.id/2021/08/5-tips-memperbaiki-aksen-dan.html
Tips Membuat Relasi Komunitas
Published: 2021-09-04 14:33:30

 Semua orang dengan kemampuan jaringan yang hebat adalah pendengar dan peta yang bagus. Mereka ingin tahu dan suka mempelajari orang lain. Mereka juga menghadiri semua jaringan dengan tujuan yang sangat jelas.

Jika Anda ingin memiliki lebih banyak kepercayaan diri, menghadiri berbagai jaringan, menjadi teman, tambahkan kontak sosial dan bisnis Anda. Mendekati mereka dengan antusiasme, dan Anda akan mendapatkan peluang emas. Anda lakukan dan tidak pernah ragu lagi.

Jaringan dipandang sebagai cara untuk membangun hubungan sosial dan bisnis. Mungkin inilah yang harus Anda lakukan, tetapi jika Anda cenderung introvert, Anda tidak perlu mulai dengan mengumpulkan semua nilai dan kemudian terendam oleh Saka pada pertemuan jaringan. Metode itu dapat menyebabkan stres, kecemasan, dan akhirnya rasa keengganan terhadap segala sesuatu yang berkaitan dengan jaringan.

Mungkin Anda ingin membentuk jaringan untuk keuntungan Anda, atau pekerjaan Anda mengharuskan Anda melakukan itu atas nama perusahaan.

Setiap deskripsi setuju dengan kondisi Anda, kami akan mempertimbangkan cara termudah untuk memulai perjalanan Anda ke kepercayaan pada situasi apa pun di jaringan.

See All : https://www.kreatizen.my.id/2021/07/tips-mudah-membuat-relasi-komunitas.html
UX: Back button done wrong
Tags: javascript, vue, ux, ui
Published: 2021-09-04 14:26:44

**TLDR: Unexpected flow caused by window.history.back() and also a proposed solution using InertiaJS (Vue).**

Have you ever experienced a weird navigation logic when you press the back button, instead of going back to the home page of the website, the browser navigates back to the previous website your browser tab visited?

Read More at [https://luiyongsheng.medium.com/ux-back-button-done-wrong-e7da351c9801](https://luiyongsheng.medium.com/ux-back-button-done-wrong-e7da351c9801)
How to know if you are good enough as developer ?
Tags: motivation
Published: 2021-09-04 13:33:35

### YES, you're good enough to become developer as long as 


- Learn from your mistake
- Never satisfied, Never give-up 
- Practice, practice, practice 
- Remember that perseverance and passion drive effort, and effort drives achievement
- Aim for small achievable daily goals rather than Imaginary big goals without action
- Don't compare your self with other, your rival is your's yesterday self



#### Stop thinking that you're not good enough, even the greatest developer on earth (whoever he or she) start as a newbie, what make them better than us is because they learn earlier
Two Sum
Tags: leetcode, twosum, algorithms, datastructure
Published: 2021-09-04 12:42:22

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

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

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

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

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


### Analysis
So, we need to have 2 numbers for the array so that the sum of those equal to targeted sum. feel's simple :-)...
But, **Not sorted**

First think that comes to mind is to take each element and find the target complement of element form remaining elements.

> So this will take O(n^2) and space complicity of O(1)

**Can we have better time complicity ?**

Ya!! we do have!

We can keep a hash that holds target complement(target - currentValue) as key and index as value and if we find element in hash map then return the current index and index from hash map.

Lets code that!

```
var twoSum = function (nums, target) {
    result = [];
    const index_map = new Map();
    // Loop for each element in the array
    for (let i = 0; i < nums.length; i++) {
        let difference = target - nums[i];
        if (index_map.has(difference)) {
            result.push(i);
            result.push(index_map.get(difference));
            break;
        } else {
            index_map.set(nums[i], i);
        }
    }
    return result;
};
```

> So, Here the time complicity is O(n) and space complicity of O(n).

### Conclusion
The best time complicity algorithm is to use the hash map, but that could take O(n) space complicity.

Always think of which is the requirement is it time or space and come up with the algorithm.

Thanks feel free to contact and keep learning!
How was your first Sprint?
Tags: agile, softwaredevelopment, teamwork
Published: 2021-09-04 15:42:31

---
title: How was your first Sprint?
published: true
date: 2021-09-04 12:33:28 UTC
tags: agile,softwaredevelopment,teamwork
canonical_url: https://medium.com/chingu/how-was-your-first-sprint-716c29f2b2a7
---

#### Sprint 1 — Saturday

![](https://cdn-images-1.medium.com/max/1024/1*5eIQt-miRgy1XkfgMQ0a8g.jpeg)

Just as the foundation is the most important step in building a home, Sprint 1 is **_the most important sprint_** in a Chingu remote team project.

It establishes the foundation for the remainder of the Voyage since it’s where you start creating relationships within your team, agree on a project, define the project backlog, and setup a team workflow.

The close of any sprint is a good point to **reflect** on not only what you accomplished, but just as importantly, how well the team functioned. You can use these observations to improve not only the technical aspects of your project, but also **how you get things done as a team**!

> It’s okay to fail, as long as you Fail Forward!

In Chingu remember that you to have the freedom and opportunity to make mistakes and to encounter issues you can learn from. The key isn’t that a problem occurred, **it’s what you learn from it and the steps you take to improve**.

![](https://media.giphy.com/media/eroScTnthmrn2/giphy.gif?cid=790b7611d8f69010c4412846772e90d6e6be6cf86c3c941c&rid=giphy.gif&ct=g)

### Before you Go!

Chingu helps you to get out of “Tutorial Purgatory” by transforming what you’ve learned into experience. The experience to boost your Developer career and help you get jobs.

You can learn more about **Chingu** & how to join us at [https://chingu.io](https://chingu.io/)

* * *
Simplest Custom Hook to Persist Data.
Tags: react, javascript, 100daysofcode, tutorial
Published: 2021-09-04 12:32:47

I was recently filling a survey form built on [Typeform](https://typeform.com) (Highly recommend using) and I must say that it has an amazing UX compared to it's competitors like Google form, Microsoft form etc. The thing which got me the most hooked was, when I mistakenly closed that tab in-between and reopened it again, all my information filled before was still there. Typeform was persisting data unlike Google forms or other platforms that I have come across.

Typeform was leveraging the local storage API of the browser. So, as a React guy I so wanted to make a React hook which I can use for my future projects, taking the advantage of the local storage. 

## Custom hook `useLocalState`
Here we will be using the `window.localStorage` API and store the data in the local storage of the browser. Even if you close the tab and come back to the same page, your previous state will be preserved.

For this, first we will be using a `useState` hook with a callback function returning the value from the local storage of the browser if the data is present, Otherwise, the default value passed as a prop.

```javascript
const [value, setValue] = useState(() => {
    const tempValue = window.localStorage.getItem(key);
    return tempValue !== null ? JSON.stringify(tempValue) : defaultVal;
});
```

The data can be saved to the local storage with a specific key assigned to the data. You can think this of as a kind of object as well.

Next we will have to sync the data and update it if it's changed. We will be taking use of the `useEffect` hook for this.

```javascript
useEffect(() => {
    window.localStorage.setItem(key, JSON.stringify(value));
}, [value]);
```

The custom `useLocalStorage` hook.

```javascript
import { useEffect, useState } from "react";

const useLocalStorage = (defaultVal, key) => {
  const [value, setValue] = useState(() => {
    const tempValue = window.localStorage.getItem(key);
    return tempValue !== null ? JSON.stringify(tempValue) : defaultVal;
  });

  useEffect(() => {
    window.localStorage.setItem(key, JSON.stringify(value));
  }, [value]);

  return [value, setValue];
};

export default useLocalStorage;
```

### Example application
Let's make a simple counter with two function, increment and decrement to understand this concept.

```javascript
import React from "react";

const App = () => {
  const [count, setCount] = useLocalState(0, "count");

  const increment = () => {
    setCount(count + 1);
  };

  const decrement = () => {
    setCount(count - 1);
  };

  return (
    <div>
      <h1>Counter:</h1>
      <h2>{count}</h2>
      <button onClick={increment}>Increment (+)</button>
      <button onClick={decrement}>Decrement (-)</button>
    </div>
  );
};

export default App;
```

Try out this example.

{% codesandbox uselocalstorage-n7l7n %}

#### NOTE
Do not use this hook in SSR frameworks. The local storage API shows error is SSR frameworks like (Nextjs, Gatsby etc). As it will be compiled on the server side and the local storage of the server will be referenced and not the client's browser.
Why WordPress plugins can kill your site.
Tags: wordpress
Published: 2021-09-04 12:32:34

---
title: Why WordPress plugins can kill your site.
published: true
description: Wordpress
tags: wordpress
cover_image: https://media-exp1.licdn.com/dms/image/C4E12AQHTZwN4EBa64w/article-cover_image-shrink_600_2000/0/1630743571191?e=1635984000&v=beta&t=ONu1cTwtE1xb2-sdjqtADxNX-JYnfPMJ4fTU2pzu1fI
---
Why WordPress plugins can kill your site. It can be tempting to just slap a random plugin on your WordPress site because it looks cool. The problem with doing that is that most of the plugins are buggy and can easily crash your site. It also increases the number of the HTTP request to your site. It can contribute to your site slowing down. What to do if your site crashes in the process Log into your host provider directory, traverse to the plugin folder and rename the folder or pad it with a dash. Example plugin- That should fix it.
How to use bookmarks in bash/zsh
Tags: terminal, zsh, programming, bash
Published: 2021-09-04 20:51:42

---
title: How to use bookmarks in bash/zsh
published: true
date: 2021-09-04 12:19:19 UTC
tags: terminal,zsh,programming,bash
canonical_url: https://threkk.medium.com/how-to-use-bookmarks-in-bash-zsh-6b8074e40774
---

Moving around your terminal effectively is going to make you more productive. Sometimes you need to quickly move between different projects or directories located in different places in your machine. For instance, maybe your code lives in ~/project/my-project, but the configuration of the server is in /etc/... Remembering locations is inefficient, and often they take longer to write. What if there is an easy, inexpensive solution in 4 lines of bash?

![Example of how the autocomplete works with the proposed bookmarks.](https://cdn-images-1.medium.com/max/1024/1*RfH4nMBm-1t-LISIRSvHXA.gif)<figcaption>How my bookmarks look like</figcaption>

### How to install

Here is where the magic is. Add these 4 lines of code to your bashrc or zshrc file.

![if [-d “$HOME/.bookmarks”]; then export CDPATH=”.:$HOME/.bookmarks:/” alias goto=”cd -P” fi](https://cdn-images-1.medium.com/max/974/1*sqJOhh_EJeLhxy8krAUTDw.png)

```
if [-d "$HOME/.bookmarks"]; then
    export CDPATH=".:$HOME/.bookmarks:/"
    alias goto="cd -P"
fi
```

Additionally, you need to create the directory in your home folder or wherever it suits you, just remember to update the CDPATH variable above.

```
mkdir ~/.bookmarks
```

### How to use

To add a new bookmark, you just need to create a symbolic link to the folder in your bookmarks directory. I suggest you start all the bookmarks with the same character. This way, the autocomplete will suggest to you all the bookmarks available once you type the character. In my case, I chose the symbol @ . If you want to edit or remove the bookmark, delete the symbolic link and/or create a new one.

```
ln -s path/to/certain/directory/with/my/project @important-project
```

### How does it work?

The magic here is in the $CDPATH variable. $CDPATH is _a colon-separated list of directories used as a search path for the cd built-in command_. It behaves like the $PATH when resolving binaries. The $CDPATH we define first attempts to locate the directories in the current directory, then in our bookmark’s directory, and finally in the root. Because we are using always the same starting character, if we type it, it will suggest all the bookmarks we have defined.

Additionally, we also declare an alias for cd named goto. The option -P will resolve the symbolic links moving us to the directory instead of the symbolic link.
Refactoring ELI5
Tags: webdev, beginners, codenewbie, javascript
Published: 2021-09-04 12:00:25

**Disclaimer**: I am not an expert, I am merely [learning in public](https://www.swyx.io/learn-in-public/). If I got something wrong or left out important details, please leave a comment! ❤️

### Alrighty, lets go!

Refactoring a piece of code changes the structure of your existing code without altering what it does. Take a look at the following javascript example:

```javascript
if(weather === 'rainy') {
  console.log('bring an umbrella')
} else {
  console.log('no need umbrella')
}
```

In the code above, I passed the variable weather into the conditional function, if its rainy, the code will tell me to bring an umbrella.

This code is fine, but we can do everything in a much simpler way with the following:

```javascript
console.log(weather === 'rainy'? 'bring an umbrella': 'no need umbrella')
```

In the second code, I have turned the if else statement into a ternary operator wrapped around by a console.log. The two codes do exactly the same thing but the second one is just a lot simpler to look at.

We refactor our codes because of a few things (non exhaustive list):
- Improve our code readability (Imagine extending the above idea into a huge file with many lines)
- Improve efficiency of our code, making it easier to work with
- You can refactor a code such that features can be re-used elsewhere

_Happy coding!_
Today's Daily Humor For Devs - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2021-09-04 12:00:18

---
title: "Today's Daily Humor For Devs - Daily Developer Jokes"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e12591b4fccd.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ Why don't parents teach their kids about regular expressions?

___A:___ Because they don't want them playing with matches
 -->
The CSS position property
Tags: css, position, design
Published: 2021-09-04 11:33:37

The position property specifies the type of positioning method used for an element and by position property we can manipulate the location of an element.
These are type of position value :
 * static
 * relative
 * absolute
 * fixed
 * sticky

And also global values like `inherit` , `initial`, `revert`, `unset`  can also be applied to position property

Let's talk about each position values one by one :)

# `static`

`position: static;`
 `static` in the default position and it's position according to the normal flow of the page. In static  `top`/`bottom`/`left`/`right`/`z-index` property has no effect.

{% codepen https://codepen.io/ravikumar1002/pen/dyRXORg %}


# `relative`
`position : relative;`
  It behaves like a static but when we apply on of these property  `top`/`bottom`/`left`/`right`/`z-index` then element will flow according to these CSS properties.

{% codepen https://codepen.io/ravikumar1002/pen/VwWjpWz %}


# `absolute`
`position : absolute;` 
The element is removed from the normal document flow and is relatively positioned to its first non-static ancestor. Its final position is confirm by the values of `top`/`bottom`/`left`/`right`.

{% codepen https://codepen.io/ravikumar1002/pen/abwZJMW %}


# `fixed`
`position : fixed;` 
The element is removed from the normal document flow like absolutely positioned elements. In fact they behave almost the same, only fixed positioned elements are always relative to the viewport, not any particular parent, and are unaffected by scrolling.

{% codepen https://codepen.io/ravikumar1002/pen/jOwrBZj %}


# `sticky`

`position : sticky;` 
The element is positioned based on the user's scroll position. A `sticky` element toggles between `relative` and `fixed`, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).

{% codepen https://codepen.io/ravikumar1002/pen/XWgKRWM %}