teleren/devto huggingface dataset:
C++ Vs Python Syntax Difference
Tags: python, cpp, programming, computerscience
Published: 2021-03-12 09:34:14

In my humble opinion learning, by comparison, is the best way of learning, To stay in the loop while the industry is moving extremely rapidly, learning complex concepts by comparing to already familiar stuff is our best bet.

In this blog post, I will show you some common programs implemented in [python and C++](https://thisvsthat.tech/#/programming-languages?id=code-comparison-python-vs-c), So if you are trying to learn one of those languages or both at the same time! this post will serve you to learn in a comparable manner, let's dive in!

# Hello World Program

1. Hello World Program in python 

```python
print("Hello, World!")
```

2. Hello World Program in C++

```C++

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
```

# Display Fibonacci Series

1. Display Fibonacci Series
 in python 

```python
nterms = int(input("How many terms you want? "))  
# first two terms  
n1 = 0  
n2 = 1  
count = 2  
# check if the number of terms is valid  
if nterms <= 0:  
   print("Please enter a positive integer")  
elif nterms == 1:  
   print("Fibonacci sequence:")  
   print(n1)  
else:  
   print("Fibonacci sequence:")  
   print(n1,",",n2,end=', ')  
   while count < nterms:  
       nth = n1 + n2  
       print(nth,end=' , ')  
       # update values  
       n1 = n2  
       n2 = nth  
       count += 1  
}
```

2. Display Fibonacci Series in C++

```C++

#include <iostream>  
using namespace std;  
int main() {  
  int n1=0,n2=1,n3,i,number;    
 cout<<"Enter the number of elements: ";    
 cin>>number;    
 cout<<n1<<" "<<n2<<" "; //printing 0 and 1    
 for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed    
 {    
  n3=n1+n2;    
  cout<<n3<<" ";    
  n1=n2;    
  n2=n3;    
 }    
   return 0;  
   } 

```

weather If you already know cpp and trying to learn python or vice-versa I hope you get the general gist of the Syntax difference between the two languages, 
If you like this and this method of learning things, I have a repository dedicated to comparing programming languages and concepts, you can check it out on [github](https://github.com/Garinmckayl/thisvsthat)
TIL Godot GraphEdit Gaffes
Tags: todayilearned, gamedev, godot, controls
Published: 2021-03-12 06:08:25

2021-03-11

The GraphEdit and GraphNodes sure have their...idiosyncrasies. 

I got stumped for a bit because I wanted to remove all the GraphNodes in a GraphEdit to perform a clear so I did a children-loop remove. 
```python
# self is the graphedit control
for child in self.get_children():
	self.remove_child(child)
	child.queue_free()
```
Yeah, don't do this. This is because the GraphEdit comes with children already - a GraphEditFilter and Control; you get hard crashes when you remove those and mess with the control gg ez.

I found this works better.
```python
for child in self.get_children():
	if (child is GraphNode):
		self.remove_child(child)
		child.queue_free()
```
----
Gonna make it a two-fer-one since I slept before writing an entry yesterday!
This one was a bit tricky but I learned you cannot set the position of children GraphNodes in a GraphEdit. Basically, I setup an auto-connecting GraphNode and wanted to position them nicely around the node it was connected to.
![Intended Goal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpq8mr6efdz38ns6fmf2.png)
<figcaption>Aboved: what I wanted (and eventually got)</figcaption>
In order to accomplish this, the offset property needed to be used and not position. This is because the GraphEdit sets the actual position of the GraphNode in order to set the proper scaled/scrolled position of it. The following C++ code shows this in action.
```cpp
void GraphEdit::_update_scroll_offset() {
	// . . .
	Point2 pos = gn->get_position_offset() * zoom;
	pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
	gn->set_position(pos);
```
What made this *very* trippy was setting the position worked(!) at one point but I suspect that removing all children in the GraphEdit allowed this to happen. Once I fixed that issue, the placement issue popped up. It got resolved but there's still more work to be done! Stay tuned!!
CSS variable with Styled Components in Next.js/React.js
Tags: developer, nextjs, react, css
Published: 2021-03-12 09:16:48

Since I'm working with Next.js and Styled-components (also TypeScript, React, GraphQL, Apollo, Storybook & Storyblok CMS) I was wondering, is it possible to use CSS variable's in Styled Components.

```tsx
import React, { Component } from 'react';
import styled from 'styled-components';

const CSSVariables = styled.div`
  --color: ${props => props.color};
`;

const Heading = styled.h1`
  margin: 2rem 0 0 0;
	color: var(--color)
`

const SingleStep = (props: Istep) => {
	return (
		<CSSVariables>
			<Heading>My Heading</Heading>
		</CSSVariables>
	)
	// All component logic
}
```

As you can see in the example above, it is possible and super simple, just like in normal CSS. So make sure that you CSS variable are created in a parent component. It can also be created on a page/layout level if you like.

So I hope this helps you further with building a cool Next.js or React application with Styled-components.

*Happy coding 🚀*

---

#[Get my weekly newsletter “Developer Underdogs” with the best developer content created by aspiring developers.](https://www.getrevue.co/profile/devbyrayray)
Newest and fastest Frontend Bundler there is: Vite🚀
Published: 2021-03-12 09:12:58

These years the frontend development tools are popping up like mushrooms from the ground! One is better or suits your workflow better than the other.

Recently I discovered [Vitejs.dev](https://vitejs.dev/), build by Evan You, the starter of the framework Vue.js.

I love it!

It's blazingly fast, supports TypeScript out of the box, and uses ESM modules. 

Vite.js is a perfect tool for building your Vue, React, and Vanilla JavaScript (TypeScript) projects. 

The simplicity of setting up Vite.js is why I choose this tool for my prototyping projects in TypeScript & React. But also, when building a JavaScript Library, Vite is a perfect choice.

With no further ado, check Vite.js and let me know what you think of it. 😁

*Happy Coding! 🚀*

---
#[Get my weekly newsletter “Developer Underdogs” with the best developer content created by aspiring developers.](https://www.getrevue.co/profile/devbyrayray)
Developer Dilemma: New Technology VS Old Technology
Tags: developer, discuss
Published: 2021-03-12 09:09:31

## What do you choose?

Every developer has this multiple times in their career. Even though your a veteran developer or a code newbie, it doesn't matter!

Most of us prefer a new and shiny technology stack! Most of us don't get exciting about a not-so-shiny new technology stack.

## Why?

I think it's pretty simple!

As a developer, you used to dive into a lot of technologies. 

Older technologies are most of the time:

- Not fast
- Not efficient
- Have a low DX (Developer Experience)
- A lot of developers know a lot of it

New technologies are most of the time:

- Most of the times, it's fast and efficient
- There is a lot of attention for DX
- Fewer developers know a lot about it, so it makes you feel more special!

What do you think?

Do you prefer new technology or old?

_Happy Coding 🚀_

---

#[Get my weekly newsletter “Developer Underdogs” with the best developer content created by aspiring developers.](https://www.getrevue.co/profile/devbyrayray)
13 awesome videos about Web Scrapping Tutorials
Published: 2021-03-12 09:00:20

It’s a very tedious task to copy the huge tabular data from multiple Html pages and the C# HAP method has made it easier and simpler by providing a specific platform. Here find the steps to write codes for parsing HTML table using HAP. Copying or editing a big size HTML table is easily possible through HAP-coded applications and the work burden could be lowered down from the end-users for day-to-day data update requirements.
火焰图打印：

Published: 2021-03-12 08:52:10

火焰图：

2. 解压perf工具

tar -zxvf perf_tools_arm64.tar.gz

3. 设置环境变量

vi .bashrc

添加如下内容：

cp -R perf_tools_arm64/lib/aarch64-linux-gnu/* /usr/local/lib/

cp -R perf_tools_arm64/usr/lib/aarch64-linux-gnu/* /usr/local/lib/

cp -R perf_tools_arm64/usr/bin/perf_3.16 /usr/bin/perf

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

 

 每次搜集数据前都要执行：

sysctl -w kernel.perf_cpu_time_max_percent=1

 

sysctl -w kernel.perf_event_max_sample_rate=10000

 然后在进程执行之后，在执行

./getflame.sh collect ut_datamodel 10

 搜集完之后，执行

./getflame.sh analyze
Function Logic Work with API but does nothing when converted to a command
Tags: laravel
Published: 2021-03-12 08:24:17

i have this function :: 

public static function generateMonthly() //: JsonResponse
   {
       # dates
       self::init();
      #invoice settings
      $otherInvoiceDetails = OtherInvoiceSettings::find(1);
      $billingDay = date('d'); 
      $toiletCost = 0;
      $responseData = array();

      if ($billingDay != null && $billingDay == self::$TODAY) :
         if (!empty($allActiveCustomers = Customer::where(['status' => $ACTIVE=1])->get())) :
            foreach ($allActiveCustomers as $customer) :
                try {
                        # generate new invoice
                        $responseData[] = InvoiceService::generateInvoice($customer);
                }
            catch (\Exception $e) {
                return $e->getMessage();
            }
            endforeach;
         endif;

return 01;
}

When i call in a controller class and hit it as an API invoices are generated but when i created a command to hit the same method, command runs without errors but invoices are not generated.


Below is the content of the command class ::
<?php

namespace App\Console\Commands;

use App\Services\InvoiceService;
use Illuminate\Console\Command;

class AutogenerateInvoice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'autogenerate:invoice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'This command generates monthly invoice for customers';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        InvoiceService::generateMonthly();
    }
}


below is the kernel content :: 
/**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
        AutogenerateInvoice::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->command('tenancy:run autogenerate:invoice')->everyMinute();
    }
Free marketing analytics tool for your web app 
Tags: webdev, website, javascript, react
Published: 2021-03-12 08:09:46



Making a landing/opt-in page for your next product? But struggling too hard to design in best for conversions? Wait let's decipher this in this blog.

We as developers focus a lot on design, animations, performance, and accessibility, but one major feature of a website we neglect is to convert a user into a hot lead who can buy the product. A web page is a sales page at the end of the day.

Flukes and wage predictions can help get some random results which might work in some cases, but to be precise and do everything under the light of data, we have to use some tools. In this blog, let's look at some of which I used on my own website and how it helped me increase my conversions by 200%.

1. Microsoft Clarity - this is by far the best of all the tools I used for marketing analytics and is currently in its beta stage, so more features will keep getting added over time. But as of now, this is the best one out there as it now only shows me analytics and demographics but also gives recordings of users who visited the page. And yes, this is unlimited in the free plan as well, this is the USP.

2. HotJar - A lot of companies use this tool. On the free plan, it gives only 300 recordings, after that it will ask you to update them. Also, I don't find any difference between Clarity and Hotjar, they give pretty much the same key metrics. moreover, Clarity gets connected to Google Analytics and hence provides way advanced features than Hotjar.

3. Yandex Metrica - One more completely free tool. Though this is a Russian tool, so can't vouch for privacy. If you put that point aside for a moment, then this tool can pave your way towards really excellent user data, at least it did for me. Only after this tool, I was able to make the copy of my page better.

4. Heap - A counterpart of Google analytics but working on some different key points. This one has a freemium model, so you have to pay once you have huge traffic coming on to your website, well for me it's still free ;)

I tried a lot of other tools as well, like Moat, leap, and so on, but these are the only ones that I wish to use for my next project as well. Hence, these are the tools would like to recommend to any fellow developer.

----------------------------------------------------------
If you want similar content, then visit https://iaminnovativecoder.com

Follow me on :
YouTube - https://youtube.com/InnovativeCoder
Instagram - https://instagram.com/innovative_coder
Razorpay Payment Gateway Integration in PHP With Db Integration
Tags: php, razorpay, webdev
Published: 2021-03-12 08:06:53

Lots, of time we are facing problem to add payment gateway integration in our websites.

https://github.com/TANTANMOY/Razorpay-with-PHP

👆 Here i Created Razorpay Payment Gateway Integration in PHP With Db Integration.
Create Pivot Chart in Excel using Java
Tags: java, excel, pivotchart
Published: 2021-03-12 08:02:04

In my previous posts, I've introduced [how to create an Excel pivot table](https://dev.to/jazzzzz/how-to-create-excel-pivottable-in-java-application-41d1) with the 3rd party library--Free Spire.XLS for Java. This article will demonstrates how to create a pivot chart based on the data in pivot table.

**Installation**
**Method 1:** Download the [Free Spire.XLS for Java](https://www.e-iceblue.com/Download/xls-for-java-free.html) and unzip it, then add the Spire.Xls.jar file to your project as dependency.

**Method 2:** Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.
```xml
<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>3.9.1</version>
    </dependency>
</dependencies>
```

**Java Code:**
```java
import com.spire.xls.*;
import com.spire.xls.core.IPivotTable;

public class CreatePivotChart {
    public static void main(String[] args) {
        //Load the Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("data.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);
        //get the first pivot table in the worksheet
        IPivotTable pivotTable = sheet.getPivotTables().get(0);

        //Add a clustered column chart based on the pivot table data
        Chart chart = sheet.getCharts().add(ExcelChartType.ColumnClustered, pivotTable);
        //Set chart position
        chart.setTopRow(14);
        chart.setBottomRow(25);
        //Set chart title
        chart.setChartTitle("Total");

        //Save the result file
        workbook.saveToFile("CreatPivotChart.xlsx", ExcelVersion.Version2013);
    }
}
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dc78ncgm9cmrz5wuuken.jpg)
How to use Devselz to implement Sign In social buttons via Javascript
Tags: javascript, api, google, facebooksign
Published: 2021-03-12 07:41:30

There's some documentation on https://devselz.com/ website , but it might be some difficult to understand how to use it their free API in order to implement Facebook, Google, Apple and Github social Sign buttons on a website or blog.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kvcf9jswq8z27oingqwo.jpg)


Basically the steps are:

1) Sign up into devselz
2) Access Dashboard

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frnlihjnl4tw835wpbvh.jpg)

3) Add your domain
4) Paste the social keys youmust get from google, google captcha, facebook and the rest KEYS from the social medias you wnat to have. There's a documentation for on https://devselz.com/support/logsign/
5) Add a TXT record to your domain web register (e.g. godaddy, etc) as indicated on the icon DKIM
6) Copy the script as indicated on the last icon on the dashboard and paste on to your url's head
7) On the BODY of your web place within a script tag:
   dzLogSignInit(dzLogSignOnDataReceived); //where on dzLogSignOnDataReceived is a function that will be called (callback) when users login in
   function dzLogSignOnDataReceived(data) {
//data will contain user data
}
8) Place any image text or button on your website and on the HTML code place "dzLogSignShowMain(dzLogSignOnDataReceived);"

For more info there is an example website on the documentation
Coding Horror Stories - string.Replace
Tags: codinghorrorstories, developer, coding, string
Published: 2021-03-12 07:41:17

🧟 Coding Horror Stories ...

❓ Dimmi, te come lo faresti ...

... un semplicissimo "Replace" di testo in una stringa?

😲 A questa domanda il mio collega e' rimasto un attimo senza parole. Con ogni certezza avrei reagito allo stesso modo anche io. Perche' me lo chiede? La risposta e' ben oltre lo scontato!

... eppure non tutti la pensano in questo modo!

🔴 Ho letto tanto "codice cacca" scritto da quella persona negli ultimi anni, ma questo mi ha spinto ad aprire una nuova rubrica sul mio blog e su Linkedin. 

Ho deciso di chiamarla "Coding Horror Stories" e sicuramente non manchera' di contenuti interessanti e/o spunti di riflessione per quando scrivete del codice.

🔗 [Ora non mi resta che lasciarvi il link del post ed augurarvi una buona lettura!](https://links.devandreacarratta.it/3MVP)

#CodingHorrorStories #coding #developer #string #andreacarratta
DNS Blockchain: a Costless Blockchain Database 
Tags: blockchain, dotnet, free, database
Published: 2021-03-12 07:36:25

Do you think that hosting a blockchain solution is expensive?
Well, I'm telling you you can do it without spending a cent. 

In this article, I will show how you can create a blockchain-like distributed database using only a DNS service, cryptography and some imagination.

Don't you believe it?

The implementation is in plain C# and all the source code is available on Github.

[Read the article for discovered how I did it] (https://betterprogramming.pub/free-dns-blockchain-database-c98fce975134?sk=6b92835d9c6a87671575c9f71a41d166)
Typescript - Tips & Tricks - Tuple
Tags: typescript, webdev
Published: 2021-03-12 07:10:33

Tuple types allow you to express an array with a fixed number of elements whose types are known, but need not be the same.
This definition is picking from the typescript documentation.
The tuple type is a powerful type that helps you to identify the types of elements in an array, you can create special types where the elements of the array can have different types.
A simple example
```ts
type Point = [number, number];

const point1: Point = [10, 10];
const point2: Point = [10, "10"]; // Type 'string' is not assignable to type 'number'
const point3: Point = [10, 10, 20]; // Type '[number, number, number]' is not assignable to type 'Point'. Source has 3 element(s) but target allows only 2.
```
In this case, you can see how the point type is composed by a fixed array of two elements of type number. You can see how typescript detects this constraint and it raises an error when you try to create a point with the second element of type string or you try to create a point with 3 elements.
To show you the power of this type, here's another example
```ts
type QueryStringItem = [string, number | string | boolean];
const queryStringItem1: QueryStringItem = ["key1", 10];
const queryStringItem2: QueryStringItem = ["key2", "value2"];
const queryStringItem3: QueryStringItem = ["key3", false];
const queryStringItem4: QueryStringItem = ["key3", { value: "value" }]; // Type '{ value: string; }' is not assignable to type 'string | number | boolean'.
```
In this case, you can see how the second element of the Tuple can be a [union type](https://dev.to/puppo/typescript-tips-tricks-union-and-intersection-1a9l) of the types: number, string, or boolean; so typescript let you set the second element of the Tuple with one of these last three types. If you try to set the second element with a different type from number, string or boolean the typescript compiler raises an error.

That's all from the Tuple type.
See you soon guys!
Ionic adding checkboxes to a form
Tags: ionic, ios, android, mobile
Published: 2021-03-12 07:00:34

Yesterday we made a [reactive form in Ionic](https://daily-dev-tips.com/posts/ionic-adding-reactive-forms/), but it was pretty plain.
We could enter regular one valued elements. Let's say we want to add some checkboxes that could have multiple values?

The result of today is a form like this:

![Ionic checkboxes](https://cdn.hashnode.com/res/hashnode/image/upload/v1615130423014/QIgzlcWq6.gif)

## Ionic

First, let's add some options to our `tab1.page.ts` file.

```js
dessertOptions: string[] = ["Ice-cream", "Cake", "Fruit"];
```

As you can see, this is a string array containing three strings.

Next up, we'll need to tell our form that we can have multiple values over a formControl.

```js
contactForm = new FormGroup({
  firstName: new FormControl('', Validators.required),
  lastName: new FormControl('', Validators.required),
  options: new FormArray([])
});
```

Instead of a formControl, we'll add a formArray. This can contain multiple formControl elements inside.

In our case, we'll be dynamically adding them in our constructor.

```js
constructor() {
	this.dessertOptions.forEach(() =>
	  this.ordersFormArray.push(new FormControl(false))
	);
}
```

Doing this will loop over the `dessertOptions` we created above and add them to a new variable called `ordersFormArray`.

The ordersFormArray is something we can define now:

```js
get ordersFormArray() {
	return this.contactForm.controls.options as FormArray;
}
```

This will just convert the value of the existing option to a formArray.

Now it's time to add this to our application's frontend so the user can pick some options.

```html
<ng-container formArrayName="options">
  <ion-item *ngFor="let dessert of dessertOptions; let i = index">
    <ion-label>{{ dessert }}</ion-label>
    <ion-checkbox slot="start" [formControlName]="i"></ion-checkbox>
  </ion-item>
</ng-container>
```

First of all we define the `formArrayName` and set it to be the options variable on our form.

Then we loop for each `dessertOption` and render a specific checkbox.
The formControlName for each checkbox is an index number that will match what number they are in the array.

If we then submit, we get values like `true/false/false` if we checked only the first checkbox.

And there you go, an easy way to add checkboxes to an Ionic reactive form.

You can find this code on [GitHub](https://github.com/rebelchris/ionic-app/tree/checkboxes).

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)