teleren/devto huggingface dataset:
Useful Tips & Tricks In JavaScript
Tags: javascript, programming, webdev, beginners
Published: 2022-07-18 04:30:50

JavaScript is the most popular language and this language that you can learn easily by yourself. it's front-hand language. And it's one of the languages used by coders, developers, and programmers. Not to be confused with JScript, Java, or Javanese script that all are similar languages.

### 1. A quick way to using slice and ES8 PadStart method
``` javascript
const accountnum = "204910110001957";
const lastFourDigits = accountnum.slice(-4);
// print last four digit of account number
const maskedNumber = lastFourDigits.padStart(accountnum.length, '*');
console.log(lastFourDigits); // output will be 1957
console.log(maskedNumber); // ***********1957

```
### 2. Run an event handler only one time
If you want to run the addEventListener method you have to pass {once: true} as the third argument then the event handler method will run only one time.

```javascript
document.getElementById("btn").addEventListener("click",
function () {
console.log("Button is Clicked..");
},
{ once: true }
);
```

### 3. Update an object's properties by spread operator
``` javascript
const object = {
  name: "Rahil",
  age: 29,
  city: "Surat",
};

const newAge = 49;

const updatedObject = {
  ...object,
  age: newAge
};

console.log(object); // { name:"Rahul", age:29, city:"Surat"}
console.log(updatedObject); // { name:"Rahul", age:49, city:"Surat"} 
```

### 4. Find the length of properties in an object
```javascript
Const Object = {
            id: 1,
            name: 'Arun',
            age: 30
        }
console.log(Object.keys(object).length);
```

### 5. Print the last elements of an array
```javascript
const elements = [5,6,7,8,9,10];
const last = elements.slice(-1);
console.log(last); // Output will be 10

const secondLast = elements.slice(-2);
console.log(secondLast); // Output will be 9,10
```

### Provide a dynamic key for an object
```javascript 
function obj(key, value) {
  const dyn = {
    [key]: value
  };

  return dyn;
}

console.log(obj('name', 'Rahul')); // Output will be name: Rahul
console.log(obj('age', '29')); // Output will be age: 29 
```

### 6. Convert any type of value to boolean
In JavaScript, there are two types of boolean values true and false. You can use the Boolean() function to find out if a variable is true or not.

```javascript
let num1;
console.log(!!num1); // false

const num2 = 10;
console.log(!!num2); // true

const n1 = 'Tim';
console.log(!!n1); // true

const n2 = '';
console.log(!!n2); // false
```
Mastering word games with cheat codes
Tags: javascript, api, codenewbie, showdev
Published: 2022-07-18 04:21:20

Every now and then, I find myself spending an obscene amount of time playing random word games on my phone.  There is something so satisfying in expertly unscrambling a bunch of random letters into various (and often unfamiliar) words.  During one of my [word game binges](https://play.google.com/store/apps/details?id=com.peoplefun.wordcross&hl=en_US&gl=US), I decided to try building an app that does the work for me.  I was still using my knowledge to make the words, so it's not cheating, right?

Over the past month, I created the anagram generator using JavaScript and NodeJS.  Building this project helped me develop familiarity with the following concepts and topics:
- Creating templates (specifically using Pug; I have worked with Flask/Jinja2)
- Matching using Regular Expressions
- Using the Express framework
- Deploying an app with Heroku
- Creating and using APIs (and how to hide your API keys) 

I didn't know that last one was a thing until much later.  Oops.  Thanks @jamesqquick for showing me how to be better!

{% embed https://www.youtube.com/watch?v=7oJgdyMS4rQ %}

So if you like playing Scrabble, Words With Friends, or you just love making random words you don't know the meaning of...

Try the app: <https://word-unscramble.up.railway.app>
or
Check out my project: <https://github.com/AhamSammich/word-unscramble>
Canopas Podcast 8— Introduction to Server Side Rendering(SSR)
Tags: serverless, programming
Published: 2022-07-18 03:51:25


Do you know what is [server side rendering](https://blog.canopas.com/complete-guide-to-deploying-ssr-vite-apps-on-aws-with-automation-27676113d6ac)(SSR) or how it works?

This podcast will guide you on SSR including why do you need it? And what are the criteria for switching to the SSR?

{% embed https://youtu.be/rD8MybHt490 %}.

[Keylines of the podcast](https://blog.canopas.com/canopas-podcast-8-introduction-to-server-side-rendering-ssr-ef062f672374)

1.  What is SSR?
2.  Why it is needed?
3.  When to use SSR over CSR?
4.  What is SSG?
5.  What are the frameworks used for SSR?
6.  Drawbacks of using SSR
7.  Conclusion

For more information, Check it out on [our youtube channel](https://youtu.be/rD8MybHt490).
Postman API session
Tags: postmanstudent, postmanapi, duhack, evu
Published: 2022-07-18 03:46:31


- It was glad to have such wonderful session conducted by Mr.Ali Mustufa on 101 API using Postman during hackathon of DuHacks **#duhacks** on 16th July,2022.

- I was not knowing much about the term API(Application Programming Interface) but it was great to know all that kind of stuff.

- It was great to ****know how the two communicate with each other using requests and responses using API's.
Great experience and gained knowledge about API and Postman.

- Session + Hackathon is best experience.
Hope such hackathon and session come soon.!
How To Force Redirect HTTP To HTTPS In Laravel
Tags: laravel, php, beginners, webdev
Published: 2022-07-18 03:16:01

In this article, we will see how to force redirect HTTP to HTTPS in laravel Here we will show you two methods in laravel redirect to HTTPS first is laravel redirect HTTP to HTTPS via htaccess and the second is laravel force redirect HTTPS using middleware.

So, let's see how to force redirect HTTP to HTTPS in laravel, laravel redirect to HTTPS, laravel redirect HTTP to HTTPS via htaccess, laravel force redirects HTTPS using middleware, how to redirect HTTP to HTTPS in laravel 6/7/8, laravel 6/7/8 change HTTP to HTTPS, how to redirect HTTP to HTTPS in laravel, laravel disable HTTPS redirect.
Example 1: Using .htaccess

 Redirect HTTP to HTTPS via htaccess. here you need to add code in your public/.htaccess file.

```
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
  
    RewriteEngine On
  
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
  
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
```

---
 
**_[Read Also: How To Send Email With Attachment Using Node.js](https://techsolutionstuff.com/post/how-to-send-email-with-attachment-using-node-js)_**

---
 
> Example 2: Using ServiceProvider

In this example, you need to add code in this file app/Providers/AppServiceProvider.php.

```
<?php
  
namespace App\Providers;
  
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
   
class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
          
    }
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \URL::forceScheme('https');
  
        Paginator::useBootstrap();
    }
}
```
 
---

You might also like:

- **_[Read Also: Laravel 8 Add Watermark On Image](https://techsolutionstuff.com/post/laravel-8-add-watermark-on-image)_**

- **_[Read Also: Copy To Clipboard JQuery Example](https://techsolutionstuff.com/post/copy-to-clipboard-jquery-example)_**

- **_[Read Also: Laravel Summernote Editor Image Upload Example](https://techsolutionstuff.com/post/laravel-summernote-editor-image-upload-example)_**
Drop your JavaScript Problem Solving Questions 👇👇🧑‍💻
Tags: javascript, webdev, programming
Published: 2022-07-18 03:04:25

I'm preparing for an interview. The recruiter told me there will be JavaScript problem solving questions. I'm a fresh grad, so I don't think it's gonna be that hard... Anyways I've been preparing for 2 days and looking for more problems, drop yours if you have something in mind.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa5p2id9iwlot8ntrcso.jpg)
JavaScript Interview Coding Test Problem 7
Published: 2022-07-18 02:50:30

Learn how to determine if brackets are balanced or not. This is an actual problem that software developers must occasionally solve and many dev tools have their own implementation of it. We’ll learn how a code editor can pick up our mistakes and highlight exactly which brackets don't match.
**Instructions**
Given a string, return  true  if it contains all balanced parentheses   ( )	curly- brackets () , and square-brackets [].
Input: String
Output: Boolean
**Examples**
is8alanced("(x + y) - (4)”); // -> true is8alanced("(((10 ) (}) ((?)(:)))”); // -› true isBalanced("[{()}]”); // -› true is8alanced("(50)(”); // -> false
isBalanced("[{]}”); // -› false
**Solution**

```
2	const openstack = [];
3	const open = '([{';
4	const close = ')]}';
5	const matches - {
6	')': '(',
7	']': '[',
8	'}': '{'
9	};
10
11	for (let i - 0; i ‹ str.length; i++) (
12	const char	str[i]; 13
14	// If it's an open bracket, push it into our array
15		if(open.includes(char)) (	
16		openstack.push(char);	
17			
18		// If it's a close bracket	
19		} else if(close.includes(char)) (	
20		// pop an item from the open brackets array.	
21		const lastopenBracket	openStack.pop();	
22			
23		// If the open and close bracket don't match,	return false
24		if(matches[char] !== lastopenBracket) {	
25		return false;	
26			
27		
 	
28		
 	
29			
30		// Ensures there are no characters left on the stack	
31		return !openStack.length;	
32	}		

```
**How it Works**
In our for-loop, we process every character. If the current character is an open bracket, we push it onto our openstack array.
If it’s not a bracket, we do nothing.
Once we’re done processing the string, we have to check to make sure there
are no open brackets left on our stack. If there are, our string is unbalanced.
**Time**
This is a solutiDn with a time complexity Df:
0(n).
Every character is prDcessed in a loop. Inside the lDop, we perform only count-time actions.
**Space**
The space complexity is:
0(n).
Characters are stored in an array, generally proportional to the size of the input.
**Conclusion**
There are many ways to skin this cat. Another solution wDuld have been to have two pointers, one at the beginning and one at the end, moving towards the middle. They would be checking to make sure that brackets matched until they met. This would also be an o(n) solution.
How to enable AverageCpcMicros on GenerateHistoricalMetrics in V11's KeywordPlanService?
Tags: googleads
Published: 2022-07-18 02:37:02

This is a question I've just submitted to the google-ads-dotnet repo maintainers. 
{% embed https://github.com/googleads/google-ads-dotnet/issues/425 %}
Does anyone else know?
POSTMAN API SESSION
Tags: postmanstudent, postmanapi, duhacks
Published: 2022-07-18 02:15:26

It was glad to have such wonderful session conducted by Mr.Ali Mustufa on 101 API using Postman during hackathon by DDU students #duhacks on 16th July,2022.
I was not knowing much about the term API(Application Programming Interface) but it was great to know all that kind of stuff.
It was great to know how the two communicate with each other using requests and responses using API's.
Great experience and gained knowledge about API and Postman.
Session + Hackathon is best experience.
Hope such hackathon and session come soon.!
Easiest way to connect database in javascript (3 simple steps)
Tags: javascript, webdev, node, database
Published: 2022-07-18 02:06:06

Javascript is one of the most popular programming languages , as all other languages like PHP , C# , Python they all provides driver to connect with Mysql Server . And unlike the MongoDB database Mysql also provides it’s module for Nodejs to connect with , as Mysql is also a popular relational database so there’s need to be support for Nodejs .

Mysql’s module [mysql ](https://www.npmjs.com/package/mysql)i.e., driver for Nodejs helps Nodejs developer to connect with Mysql server , it’s a very easy library to use and implement .

In this article you will learn to connect with Mysql database using Javascript Nodejs in 3 simple steps .

## Requirements

We need the below two requirements in order to make connection with Mysql database using Javascript Nodejs .

1 . Mysql Server (we are using XAMPP )

2 . Nodejs installed 

## Step 1 : Install Mysql Nodejs library

To install the mysql library you need to have Nodejs installed in your system . Run the following command to install mysql library .

`npm install mysql`

After installation you need to require this module in your main file before making connection to database .

Note : Don’t forgot to start Mysql server before making a connection unless you will face an error.

## Step 2 : Make connection to database and execute queries

After successful installation of library you can make connection to database . You can make connection to database in 2 ways

1 . Simple connection

2 . Pooled connection

## Simple connection

In simple connection you will use the basic components to make a connection to Mysql database . First of all you need to require the mysql library in file and then with createConnection() pass all the required parameters i.e., host , user , password , database as shown in below example .

```
var mysql = require('mysql'); // requiring nodejs mysql library

var connection = mysql.createConnection({ // creating database connection
    host     : 'localhost',
    user     : 'root',
    password : '',
    database : 'users_db'
})

 // You can refer to this article originally published at
 // https://bepractical.tech/easiest-way-to-connect-database-in-javascript-3-simple-steps/

```
**Article link** : https://bepractical.tech/easiest-way-to-connect-database-in-javascript-3-simple-steps/
The best marketing methods in the world
Tags: javascript, tooling, programming, beginners
Published: 2022-07-18 02:04:26


Marketing on social media has been found to provide a number of benefits for businesses and their customers. These benefits include the ability to target specific audiences, create brand awareness, increase customer loyalty, develop new customers and generate leads from social media users. Additionally, marketing through social media can help companies build better relationships with their existing customers by providing them with valuable information and services that they may need or want.

## You can learn [the best successful example of marketing from this comprehensive guide](https://professional-writer0.blogspot.com/2022/07/marketing-strategy-social-media-example.html)

Marketers have become increasingly aware of the importance of social media marketing. It can help your business in a number of ways, including.

Social media marketing can be done on a number of different platforms, including.

The benefits of using social media for marketing your business include.

There are a lot of benefits to social media marketing and using the right social media platforms can be a great way to connect with your customers and provide them with the information and products they need. Paid advertising may be more flashy, but social media marketing can be just as effective and ultimately more cost-effective.

There are a lot of benefits to social media marketing and using the right social media platforms can be a great way to connect with your customers and provide them with the information and products they need. Paid advertising may be more flashy, but social media marketing can be just as effective and ultimately more cost-effective.
I made a SMS app to text my ideas to and it'll text them back at random intervals in the future
Tags: sideprojects, twilio
Published: 2022-07-18 01:26:23

I'm someone who always texts myself my ideas as I think of them at random moments. I really enjoy the simplicity of texting ideas but I wanted a way to find my old ideas so I made [https://galaxi.me](https://galaxi.me). Let me know what you think!

Just text an idea to: +17755225513

## Tech Stack

- FastAPI
- Postgres
- Procrastinate (PostgreSQL-based Task Queue)
- Twilio API
Firestore data modeling best practice
Tags: firebase, firestore
Published: 2022-07-18 01:20:20

# This articles is progress to write

## Query feature
- [Subcollectoin](https://chaim-zalmy-muskal.medium.com/firebase-subcollections-eb376f109c4a)
 - If we use it, we cannot delete when delete root document.
- Query subcollection directly
 - If you want to query subcollection directly you can use [Collection group queries](https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query)
 - [Subcollection query is as fast as root collection query](https://stackoverflow.com/questions/56851908/is-collection-query-single-faster-than-a-groupcollection-query)


Can have 2000 fields in a document.


## Articles
- [Oficial best practice](https://firebase.google.com/docs/firestore/data-model)
- [Working with Firestore: Building a simple database model](https://proandroiddev.com/working-with-firestore-building-a-simple-database-model-79a5ce2692cb)

## Videos
- [Get to know Cloud Firestore | Youtube play list](https://www.youtube.com/playlist?list=PLl-K7zZEsYLluG5MCVEzXAQ7ACZBCuZgZ)
Deep Equals
Published: 2022-07-18 01:07:27

**Instructions**

Write a function that will take in two items of any type. The function should perform a deep equality 

Inputs: Any, Any Output: Boolean

**Solution**
This problem has several parts. Let’s walk through it logically.

1. comparing NaN with NaN using -- or --- will always return false.
Because of this, we need to start by checking if both inputs are NaN.
2. If the items are of a different type, we can immediately return false.
3. If they’re the same type and not objects, we can return the result of a simple equality operation using ===. We have to be careful to include null here, as typeof null returns object. This is due to a bug in JavaScript (http://2£tlity.cDm/2013/10/typeof-null.html) itself.
4. We need to be careful to ensure that both objects have the same number of properties. If they don’t, return false.
5. Now we need to go through every key and make sure they’re the same on every object. To do this, we can loop through the first object and check to make sure that the second object has matching values.
6. If all checks have passed, return true

Let’s transform that pseudocode into code.

```
function deepEquals(a, b) {
  if(Number.isNaN(a) && Number.isNaN(b)) {
    return true;
  }

  if(typeof a !== typeof b) {
    return false;
  }

  if(typeof a !== 'object' || a === null || b === null) {
    return a === b;
  }

  if(Object.keys(a).length !== Object.keys(b).length) {
    return false;
  }
    
  for(const key in a) {
    if(!deepEqualS(a[key], b[key])) {
     return false;
    }
  } 

  return true;
}
```

**Time**
 
Our function has to go through and process every property of both items. Assuming that the two inputs are deeply equivalent, we can say that the time complexity is:

0(n).

Space
This is a recursive function and the number of calls will generally scale with the objects’ sizes, so:

0(n).
Github Actions - Use Maven + Jacoco to Gate PR Merging by Code Coverage
Tags: java, github, testing, cicd
Published: 2022-07-18 00:40:20

*I work for [Akkio](https://akkio.com), where I'm building out a no-code predictive AI platform. If you're looking to harness the power of AI without needing a data scientist, give us a try!*

Had some difficulty finding an up-to-date way to do this, so I figure I save anybody looking for this in the future some time.

Without future ado, here's the .github/workflows/<whatever name you want>.yml:
```yaml
name: Code Coverage

on:
  pull_request:
    branches: [ "master" ]
  push:
    branches: [ "master" ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: 17
          distribution: 'temurin'
          cache: maven

      - name: Generate Coverage Report
        run: |
          mvn -B package --file pom.xml

      - name: Upload Report
        uses: 'actions/upload-artifact@v2'
        with:
          name: jacoco-report
          path: ${{ github.workspace }}/target/site/jacoco/jacoco.xml

      - name: Add coverage to PR
        id: jacoco
        uses: madrapps/jacoco-report@v1.2
        with:
          paths: ${{ github.workspace }}/target/site/jacoco/jacoco.xml
          token: ${{ secrets.GITHUB_TOKEN }}
          min-coverage-overall: 80
          min-coverage-changed-files: 80
          title: Code Coverage

      - name: Save Coverage To Environment Variable
        run: |
          echo "TOTAL_COVERAGE=${{ steps.jacoco.outputs.coverage-overall }}" >> $GITHUB_ENV
          echo "CHANGED_FILES_COVERAGE=${{ steps.jacoco.outputs.coverage-changed-files }}" >> $GITHUB_ENV

      - name: Print & Check Coverage Info
        run: |
          import os
          import sys
          print("Total Coverage: " + str(os.environ["TOTAL_COVERAGE"]))
          print("Changed Files Coverage: " + str(os.environ["CHANGED_FILES_COVERAGE"]))
          if float(os.environ["TOTAL_COVERAGE"]) < 80 or float(os.environ["CHANGED_FILES_COVERAGE"]) < 80:
            print("Insufficient Coverage!")
            sys.exit(-1) # Cause Status Check Failure due to noncompliant coverage
          sys.exit(0)
        shell: python
```

The Python script at the end technically returns a 255 for some reason in case of insufficient coverage, but it still returns a nonzero exit code, which is what we need.

Some notes:
- Maven dependencies are cached. Subsequent runs should be much faster than the initial one.
- Python is necessary because I couldn't find a convenient way to parse the coverage number jacoco-report gives us (which ends up as a string) into a float in Bash.
- madrapps/jacoco-report is not optional, though you can disable the comment it adds onto the PR if you like. It's necessary because it outputs the `steps.jacoco.outputs.coverage-overall` and `steps.jacoco.outputs.coverage-changed-files` variables.