teleren/devto huggingface dataset:
Method chaining in javascript
Tags: javascript, codenewbie, oop, beginners
Published: 2021-04-19 15:52:11

**Method** is a  function that is a property of an _object_. It is also a property containing a function definition.
let's consider the example below 

```
Var car = {
Color: “red”,
brand: “Toyota”,
description: function (){
This.brand  + "is a  Motor Corporation is a Japanese multinational automotive manufacturer"
}
}

// description is a property of a car that is also a function. So a function inside an object is called METHOD.
 //Calling 
console.log(car.description())
// Toyota is a  Motor Corporation is a Japanese multinational automotive manufacturer

```
If we have 5 methods in the object. We end up with something  like this:
`car.description()`
`car.description()`
`car.description()`
`car.description()`
`car.description()`

Could you see that `car` is unnecessarily repeated and doesn’t seems neat and could take lines of code? We can get rid of that by using a mechanism called **METHOD CHAINING**.

_Method chaining_ is the mechanism of calling a method on another method of the same object. This ensures a cleaner and readable code.  Method chaining uses `this` keyword in the object's class to access its methods. In javascript,  the `this` keyword refers to the current object in which it is called. When a method returns `this`, it simply returns an instance of the object in which it is returned. in another word, to chain methods together, we need to make sure that each method we define has a return value so that we can call another method on it.

_Let's write some code_
```
Class chaining{
    Method1(){
    console.log(method1)
    return this
    }

    Method2(){
    console.log(method2)
    return this
    }

}

 Const chaining_obj = new chaining()
 chaining_obj
 .mathod1()
 .method2()

//output
method1
method2


   ```

_let's consider this example_

```
class Arithmetic {
  constructor() {
    this.value = 0;
  }
  sum(...args) {
    this.value = args.reduce((sum, current) => sum + current, 0);
    return this;
  }
  addition(value) {
    this.value = this.value + value;
    return this;
  }
  subtraction(value) {
    this.value = this.value - value;
    return this;
  }
  average(...args) {
    this.value = args.length? (this.sum(...args).value) / 
  args.length: undefined;
    return this;
  }
}


const Arithmetic 1= new Arithmetic()
Arithmetic1
  .sum(1, 3, 6)   // => { value: 10 } 
  .subtraction(3)   // => { value: 7 }
  .add(4)        // => { value: 11 }
  .value         // => 11 


```
**Thanks for reading**
Do you wish to get notified when I published a new article? click [here](https://mailchi.mp/4f641d33a5ee/subscribe-ti-my)

[ISIAKA ABDULAHI](https://linkedin.com/in/isiakaabd)
如何使用 GtkHeaderBar
Published: 2021-04-19 15:42:51

---
title: 如何使用 GtkHeaderBar
published: true
description: 
tags: 
//cover_image: https://direct_url_to_image.jpg
---

`GtkHeaderBar` 可以用来替代标准的 titlebar, 在使用的时候直接构造好(或者通过 gtkbuilder 来构造)，然后用 `gtk_window_set_titlebar` 即可设置为这个窗口的titlebar。不需要主动去调用 `gtk_window_set_decoration`。

但要注意:

1. 在调用 `gtk_window_set_titlebar` 不要把 `GtkHeaderBar` 设为其他组件的 child
2. 如果从 gtkbuilder 直接构建窗口时，可以用如下代码段

```xml
<object class="GtkWindow">
  <child type="titlebar">
    <object class="GtkHeaderBar">
    </object>
  </child>
</object>
```
Start with "Good Morning"
Tags: career, tips, culture, reflections
Published: 2021-04-19 15:33:37

Building a [great engineering culture](https://avivbenyosef.com/the-traits-of-a-great-engineering-culture/) where people take pride in caring and helping each other grow is hard. It becomes even harder when we or some of our coworkers or everyone in the company is working remotely. It's easier to just focus on our work, it's easier to only communicate with other folks when we're stuck. What's hard is to cultivate a friendship with someone halfway across the globe, what's hard is to make it our business to elevate everyone's day.

Around 4 years ago I've cultivated the habit of consistently greeting my coworkers daily whenever I'm starting my day. A simple "Good Morning", a "Good Morning" in a different language, a funny GIF, an "at last it's friday!", my plans for the weekend or just something nice about my day. There's always a light and different way of greeting someone and making conversation.

When there's a strong culture this habit might already exist or it's easily incorporated in a couple of days. On the other side of the pendulum it can take up to a month of persistent greetings, every single day, to get buy-in from everyone. At the same time this is also the most rewarding scenario. We begin observing coworkers starting the day before us and greeting each other, sharing something about their personal lives or side projects. It is the first step for the necessary change in culture and it cannot be forced, it must come naturally.

I had the luck of being able to implement this "cultural bootstrap" in at least 5 different teams and achieved 100% success every single time. Sure, at first it's weird being the only one saying "Good Morning", don't expect anyone to follow your lead just yet. It's even natural to receive private messages from skeptical coworkers a few days into this venture, they doubt such a simple hack will ever stick but I know I've won after getting the first 2 or 3 people greeting me for a week straight.

And let me tell you what's the most rewarding aspect. Months or even years after parting ways with the team or the company I still get private messages from ex-coworkers telling me that they still do it or that they've moved on to other companies and have successfully applied the same tactic. That's the power of empathy transcending the company itself!

So as we approach the end let me remind you that your company's culture also depends on you and let me ask you to take pride in caring for your coworkers and that you just start by simply saying "Good Morning".
How to Use CURL to Send API Requests?
Tags: tutorial, testing, beginners, curl
Published: 2021-04-19 15:25:47

We are going to lean how you can make the HTTP Method GET, POST, PUT, PATCH and Delete Request with CURL with examples.


❤️ MindMap Download - https://sdet.live/notes

Test a REST API with curl supports over 200 command-line options. We can have zero or more of them to accompany the URL in the command.

Before we use it for our purposes, let's take a look at two that would make our lives easier.

{% youtube fVmHqtjFzbA %}


## What is CURL?
curl is used in command lines or scripts to transfer data. curl is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players and is the Internet transfer engine for thousands of software applications in over ten billion installations.
My first Google Kickstart contest
Tags: firstpost, computerscience, kickstart, google
Published: 2021-04-19 15:22:28

Hello all!
This is my first post here. In this post, I am writing about my first Google [kickstart](g.co/kickstart) round.

It was conducted today from 4.30 AM to 7.30 AM (IST). I couldn't start trying the contest at 4.30 AM since it was very early in the morning and I am not used to waking up before 7.30 AM. I managed to wake up at 6.00 AM. I started giving the contest from 6.20 AM. I had only 70 minutes left. In that time, I was able to solve two questions out of four. 

**The questions that I was able to solve were**
        1. [Increasing Substring](https://codingcompetitions.withgoogle.com/kickstart/round/0000000000435a5b/000000000077a882)
        2. [Consecutive Primes](https://codingcompetitions.withgoogle.com/kickstart/round/0000000000435a5b/000000000077a8e6)

Finally, I got an international rank of 1727. Though this wasn't a great rank, I was very satisfied because I thought I would end up even worse. Overall, it was a great experience and I look forward to the next round.

PS: I am new to blogging in general. I request the dev community's bloggers to share a few tips and resources on writing a blog.

I have been maintaining an [Instagram handle](https://www.instagram.com/code_lions/) where I post coding-related content frequently, do give it a check.

Edit: After the finalization of the ranks, my rank has been improved. I secured a **1677** Rank.


>Code is like humor. When you have to explain it, it’s bad.
Center Element using CSS
Tags: css, html, webdev, beginners
Published: 2021-04-19 15:20:07

Centering elements in CSS is usually tricky task for developer when they want to get into CSS stuff while development.
There are some ways that we can center any element in CSS with not much efforts.


A. Center Text with the CSS text-Align:center Property

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

output:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7t15zgutrc86i77546w.png)
 


 
 
B. Center a Element Horizontally with Flexbox
Use flexbox with property "justify-content:center" and display:flex it will place element in center.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o4tgkfur2t064ol85fdp.png)
 Output:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gei066wuux9m39xwo94.png)

3.Oldest way center a Div Vertically with CSS Absolute Positioning

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y33b1e9ix9gthl5e1xtk.png)
 
 output
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2j0c1g0wrsimgr1kwm24.png)
How to Sort Java List Objects by Date property with Examples
Tags: java, sort
Published: 2021-04-19 15:14:59

https://grokonez.com/java/how-to-sort-java-list-objects-by-date-property-with-examples

How to Sort Java List Objects by Date property with Examples

[no_toc]
In the tutorial, We discuss how to Sort Java List Objects by Date property with difference Date types: <code>java.util.Date</code>(using <code>SimpleDateFormat</code>), <code>LocalDate</code>, <code>LocalDateTime</code>. Java provides 2 main approaches for sorting Java List with Comparator:
<ul>
<li><code>java.util.Collections.sort(List<Customer> list, Comparator<? super Customer> c)</code>: sorting the specified list according to the order providing by the specified comparator. 
</li>
<li><code>java.util.Collection.stream().sorted(Comparator<? super T> comparator)</code>: returning a stream consisting of the elements of this stream, sorted according to the provided Comparator.
</li>
</ul>

Let's do more details with Java syntax examples (Java 7 and Java 8) by descending and ascending sorting order.

<!--more-->

<h2>Sorting with Collections.sort()</h2>
For sorting a Java List with Objects, we use <code>Collections.sort()</code> API:

<pre><code class="language-java">
public static <T> void sort(List<T> list, Comparator<? super T> c) {
	list.sort(c);
}
</code></pre>

- Sorts the specified list according to the order induced by the specified comparator.
- According to Oracle: "This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays."

Exception:
- <code>ClassCastException</code> - if the list contains elements that are not mutually comparable using the specified comparator.
- <code>UnsupportedOperationException</code> - if the specified list's list-iterator does not support the set operation.
- <code>IllegalArgumentException</code> - (optional) if the comparator is found to violate the Comparator contract
<h3>Sorting Java Objects Examples by java.util.Date property</h3>
We create a Java Class Object that has a <code>birthday</code> property with <code>java.util.Date</code> type as below:

More at:

https://grokonez.com/java/how-to-sort-java-list-objects-by-date-property-with-examples

How to Sort Java List Objects by Date property with Examples
Windows Terminal - How to add Git (or other kinds of terminal)
Published: 2021-04-19 14:47:46

*Having multiple kinds of terminals in Windows is really helpful for everyday work and productivity.*

**But how can we add other terminals?**

---

In the Windows Terminal, click on the down arrow then select **Settings**.

The settings.json file will open in a notepad window.

To add a new terminal, you have to add it in the "profiles" > "list".
```yaml
{
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b9}",
                "name": "Git Bash",
                "commandline": "Path_to_git/Git/bin/bash.exe -i -l",
                "icon": "Path_to_git/Git/mingw64/share/git/git-for-windows.ico",
                "hidden": false
            }
```

About the guid, just modify it by a random value.

And that's it! Repeat the operation for each terminal you want to add, and you will be able to open tabs with that terminals by clicking on "+".

---

I hope it will help you!

*Don't hesitate to give some feedback to help me to improve my writing skills. Thanks!*
How to output raw SQL with filled parameters in TypeORM?
Tags: javascript, typescript, typeorm, sql
Published: 2021-04-19 14:46:28

Even though **TypeORM** provides more or less good **ORM** _feeling_, many times you have to use **Query Builder** instead of ORM mechanisms. It is important to check how the query will look like (for example for performance reason). So, you need to get somehow raw SQL from Query Builder, to run it manually against your database.

Although TypeORM provides `getSql()` method, it isn't handy for developers because it doesn't fill parameter placeholders. Let's pretend we have a simple TypeORM query builder code:

```TypeScript
createQueryBuilder('user')
  .where('id = :id', { id: 1 })
  .andWhere('name = :name', { name: 'Chris' })
  .orderBy('id', 'DESC')
  .getSql(),
```
As the result of the `getSql()` function, you will get probably something like this:

```SQL
SELECT
  users.id,
  users.name
FROM users
WHERE 
  id = ? AND
  name = ?
ORDER BY id DESC
```

You must admit it isn't very helpful because you need to replace manually each `?` with related value. Here is a quick snippet, which will help you:

```TypeScript
let [sql, params] = query.getQueryAndParameters();
params.forEach((value) => {
  if (typeof value === 'string') {
    sql = sql.replace('?', `"${value}"`);
  }
  if (typeof value === 'object') {
    if (Array.isArray(value)) {
      sql = sql.replace(
        '?',
        value.map((element) => (typeof element === 'string' ? `"${element}"` : element)).join(','),
      );
    } else {
      sql = sql.replace('?', value);
    }
  }
  if (['number', 'boolean'].includes(typeof value)) {
    sql = sql.replace('?', value.toString());
  }
}); 

console.log(sql);
```

`query` variable is `SelectQueryBuilder<Entity>` type. Your query will be outputted in a much clearer way. Now it can be directly used as SQL script in any RDB client:

```SQL
SELECT
  user.id,
  user.name
FROM users
WHERE 
  id = 1 AND
  name = "Chris"
ORDER BY id DESC
```
  
If you're using Visual Studio Code as your IDE, you can try the snippet below:

```JSON
"Print to console SQL query with filled params": {
  "prefix": "sqldump",
  "body": [
    "let [sql, params] = query.getQueryAndParameters();",
    "params.forEach((value) => {",
    "  if (typeof value === 'string') {",
    "    sql = sql.replace('?', `\"\\${value}\"`);",
    "  }",
    "  if (typeof value === 'object') {",
    "    if (Array.isArray(value)) {",
    "      sql = sql.replace(",
    "        '?',",
    "        value.map((element) => (typeof element === 'string' ? `\"\\${element}\"` : element)).join(','),",
    "      );",
    "    } else {",
    "      sql = sql.replace('?', value);",
    "    }",
    "  }",
    "  if (['number', 'boolean'].includes(typeof value)) {",
    "    sql = sql.replace('?', value.toString());",
    "  }",
    "});"
  ]
}
```
Now you can use the `sqldump` shortcut to print out the whole snippet. Quick and easy! :)

***Edit: 08.11.2021***
I've changed a little the snippet, and now it handles array type parameters as well.
Java 7 – try-with-resources Statement
Tags: java, java7, trywithresources
Published: 2021-04-19 14:42:37

https://grokonez.com/java/java-advanced/java-7-try-with-resources-statement

Java 7 – try-with-resources Statement

Java 7 provides a new approach for closing resources with clean & clear code by <strong>try-with-resources</strong> statment. In the article, JavaSampleApproach will introduce the benifit when programming by <strong>try-with-resources</strong> statement.

Related Post: <a href="https://grokonez.com/java/java-core/understand-java-exception-effect-java-program-single-multi-thread" target="_blank">Understand Java Exception & The effect to Java Program (Single & Multi Thread)</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Concepts</h2>
What is a resource? An object that implements <code>java.lang.AutoCloseable</code> or <code>java.io.Closeable</code> is called a resource.
Some Java resource classes:
- java.io.BufferedReader.BufferedReader
- java.net.Socket.Socket
- java.sql.Statement
...
<strong>try-with-resources</strong> statement ensures that each resource is closed after completed execution of the statement.

<h2>II. Practice</h2>
For see benifits of <strong>try-with-resources</strong> statement, <strong>JavaSampleApproach</strong> makes an sample with <strong>BufferedReader</strong> for reading a text file.
<h3>1. Use Java6 or early version and Problems</h3>
<pre><code class="language-java">
package com.javasampleapproach.trywithresources;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileByJava6OrEarly {
	public static void main(String[] args) {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("C://readfile/input.txt"));
            String line;
            while (null != (line = br.readLine())) {
                // process each line of File
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != br)
                    br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
</code></pre>

More at:

https://grokonez.com/java/java-advanced/java-7-try-with-resources-statement

Java 7 – try-with-resources Statement
Java 9 Tutorial
Tags: java, java9, tutorial
Published: 2021-04-19 14:29:37

https://grokonez.com/java-9-tutorial

Java 9 Tutorial

With <strong>Platform Module System</strong>, <strong>New Tools</strong>, <strong>New Core Libraries</strong>, <strong>Client Technologies</strong> and <strong>Languages Updates</strong> ..., we all will be interested in how it makes many cool things for development.

<em>*Note:</em> To configure your IDE for working with <strong>Java 9</strong>, please visit:
<a href="https://grokonez.com/java/java-9/configure-java-9-support-for-oxygen">How to configure Java 9 Support for Oxygen (4.7)</a>
<!--more-->
<div id="tuttoc" class="jsa-toc"></div>
<div id="tutcontents">
<h2>I. Java Platform Module System</h2>
Java 9 <strong>Module System</strong>, which is developed under <strong>Project Jigsaw</strong>, comes to us with the specific goal: to provide <em>reliable configuration</em> and <em>strong flexible encapsulation</em>. That helps application developers, library developers, or Java SE Platform implementors more easilier create a scalable platform, make greater platform integrity, and improve performance.

<strong>What is Module?</strong>
A module is a named, self-describing collection of:
- code: packages containing types (Java classes, interfaces...)
- data: resources and other kinds of static information.

In summary:
- Class contains fields, methods.
- Package contains Classes, Enums, Interfaces, configuration files...
- Module contains Package and Other data resources.

Module system mechanism provides <strong>Readability</strong> and <strong>Accessibility</strong> that control how a module can read others and to be accessed by others.

There are three kinds of module: <strong><em>named module</em></strong>, <strong><em>unnamed module</em></strong>, <strong><em>automatic module</em></strong>.

Java has a <strong>java.util.ServiceLoader</strong> class that helps to locate service providers at runtime by searching in class path. Now we can also specify service providers and users defined in modules.

>> More details at: <a href="https://grokonez.com/java/java-9-module-system">Java 9 Module System</a>
<h2>II. Tools</h2>
<h3>1. Jshell - The Java Shell</h3>
Java 9 provides an interactive REPL (Read-Eval-Print Loop) tool to test code snippets rapidly without a test project or main method. So we can learn or evaluate Java features easily.
<img src="https://grokonez.com/wp-content/uploads/2017/03/jshell-run.png" alt="" width="283" height="101" class="alignnone size-full wp-image-3882" />

More at:

https://grokonez.com/java-9-tutorial

Java 9 Tutorial
Social Media Button Hover Using HTML & CSS
Tags: html, css, webdev, beginners
Published: 2021-04-19 14:28:44

Hello, today I created an Amazing social media hover button Using HTML & CSS. when you hover on this button this shows as a sort profile card I hope you like this also comments about your thoughts.

For more content follow me on Instagram  [@developer_nikhil27](https://www.instagram.com/developer_nikhil27/).

If you want to more support me then buy me a [coffee](https://www.buymeacoffee.com/nikhilbobade27).

New post :
https://dev.to/nikhil27b/amazing-grid-card-hover-using-html-css-1c3h

Thank you!

{% codepen https://codepen.io/NikhilBobade/pen/PoWdajw %}