teleren/devto huggingface dataset:
Electron Adventures: Episode 64: Measuring Performance
Tags: javascript, electron, svelte
Published: 2021-09-28 09:05:31

Hex editors routinely deal with fairly big files. Unfortunately when I tried to load big files into ours, it took forever to start.

It was actually very responsive after it got started, so the startup performance was the only problematic area.

### Sample files

I prepared a bunch of files in `samples/` with various files, and selected different one in `preload.js` like this:

```javascript
let fs = require("fs")
let { contextBridge } = require("electron")

let data = fs.readFileSync(`${__dirname}/samples/1024.bin`)

contextBridge.exposeInMainWorld(
  "api", { data }
)
```

As our app loads all files equally, except for some logic changes depending on printable vs non-printable characters, I simply copied over our original 4kB sample required number of times to get size I wanted.

### Performance measuring code

Svelte makes it fairly easy to measure when it started, and when it's done updating the DOM. The `tick` callback happens once Svelte is done.

From what I've seen this is not quite when browser shows the content, but it covers most of the wait time.

```javascript
  import { tick } from "svelte"

  let t0 = performance.now()
  tick().then(() => {
    let t1 = performance.now()
    console.log(`Loaded ${Math.round(data.length / 1024)}kB in ${t1 - t0}ms`)
  })
```

`performance.now` is recommended over `Date` due to potentially better accuracy.

### How slow is it?

What we got right now is nowhere close to what we want (some representative rounded numbers from a few tries):

* Loaded 4kB in 180ms
* Loaded 16kB in 570ms
* Loaded 64kB in 1850ms
* Loaded 256kB in 7625ms
* Loaded 1024kB in 42135ms

Taking 42s to load 1MB file is definitely not acceptable.

### What is taking all that time?

The best dataset to test performance on is one big enough to not be too affected by noise and small stuff, and one small enough that you can iterate without feeling temptation to open TikTok while you wait.

For a quick tests I used 64kB. I had some ideas what might be slow, so I tried commenting out some code. Here's what happens (some representative rounded numbers from a few tries):

* Baseline: Loaded 64kB in 1990ms
* No ASCII: Loaded 64kB in 1440ms
* No Hex: Loaded 64kB in 1130ms
* No mouseover events: Loaded 64kB in 2000ms
* Replaced `printf` by `.toString(16)` (which doesn't do zero padding) in Hex: Loaded 64kB in 2250ms

That gives us some idea what to do optimize, and what to leave for now.

In the next episode we'll see how far we can get optimizing the code.

As usual, [all the code for the episode is here](https://github.com/taw/electron-adventures/tree/master/episode-63-hex-editor-data-analysis).
What (if any) anti-bot techniques are you putting in place? How effective are they?
Tags: javascript, security, webdev
Published: 2021-09-28 09:01:44

Bot protection heavily relies on the infrastructure your website/web app uses. For example, the anti-bot solution will look very difficult on NGinx Web server, as opposed to Microsoft IIS. Further, you might find yourself with tied hands if you’re using a kind of SaaS solution (for example, a Shopify store will be able to use only anti-bot protection offered by Shopify itself).

I would list 3 main types of bot protection: 
Web / App Server plugin
External solutions (DNS-based, JavaScript-based, or combined)
In-app solutions

Do you use any of those solutions? How effectively did they prove to be?
First NoSQL For SQL Developers
Tags: sql, coder, appdeveloper, beginners
Published: 2021-09-28 08:58:37

### Overview
* 	Understand what is SQL and NoSQL Databases are
*	High level difference between SQL and NoSQL Database

### Introduction
As a developer of Microsoft Technologies, I am aware about what is SQL Database and how best it can be used in our applications to perform day to day operations on data e.g., store data in multiple tables which are linking through various keys. We can retrieve data from multiple tables and operate it using Stored Procedure, Triggers and Views. 

One day during technical discussion, I heard about MongoDB from my colleague and he told me that MongoDB is NoSQL. After this, I started exploring about these two terminologies i.e. What is MongoDB and Why it is called NoSQL. So, if you are having similar question in your mind and wanted to know more about this, this could be good post for you.

### Content
* What is SQL Database
* What is MongoDB
* What is NoSQL Database
* Difference between SQL and NoSQL Database
* Limitations of NoSQL
* When you will choose MongoDB NoSQL
* Conclusion

### What is SQL Database
SQL Database are relational, uses structured query language for our predefined schema. This is vertically scalable, uses tabular design to store data and supports ACID.

### What is MongoDB
MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc

### What is NoSQL Database
NoSQL databases are non-tabular databases and non-relational in nature with its document-based design, data is stored as document. Generally used for storing big data. Horizontally scalable and it supports CAP.

### Difference between SQL and NoSQL Database
Here is the basic difference for Concept or Terms 

![SQL-NoSQL-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcebem5wdk06d0evhfyg.png)

### Limitations of NoSQL
In Relation Databases, e.g., Microsoft SQL Server, we do have a provision to write a Stored Procedure, Triggers and Views and supports for ACID properties. We can design our database up to micro level where we can store our application data in multiple tables with the help of Normalization. 

On the other hand, MongoDB doesn’t support ACID properties and it’s not going to have Stored Procedure, Triggers, Views etc. Like SQL Server, MongoDB is not relational database, however, like relational database one to one, one to many etc can be represented by using different models. There are two different models. Embedded document model and Reference model.

### When you will choose MongoDB NoSQL
As per the project requirement, if the data is not structured and doesn’t require to be ACID compliance then MongoDB would be a good choice. It provides high scalability and it will be faster as data stores in Key value format.

### Conclusion
Follow a simple rule, if your data is structured and ACID compliance go for SQL. If your data is unstructured and doesn’t require ACID compliance then go for MongoDB.

###### Reference: https://www.mongodb.com/
How to list all files of a directory in python
Tags: python, tutorial
Published: 2021-09-28 08:49:21

Hello Guys How are you all? Hope You all are fine Today in this tutorial We are going to talk About How to list all files of a directory in python So lets get start this tutorial without wasting your time. Here we will Talk About All Possibles Method. Lets learn one by one.

##How to list all files of a directory in python

##Method 1: Using os.listdir()
os.listdir() will get you everything that’s in a directory – files and directories.

If you want just files, you could either filter this down using os.path:

```
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
```

For Example
With listdir in os module you get the files and the folders in the current dir

```
 import os
 arr = os.listdir()
 print(arr)

 >>> ['$RECYCLE.BIN', 'work.txt', '3ebooks.txt', 'documents']
```

Looking in a directory
```
arr = os.listdir('c:\\files')
```

##Method 2: Using os.walk()
use os.walk() which will yield two lists for each directory it visits – splitting into files and dirs for you. If you only want the top directory you can break the first time it yields

Here Is All Possible Methods with Example <a href="https://cnpubf.com/how-to-list-all-files-of-a-directory-in-python/">How to list all files of a directory in python</a>
Announcing 'Beautiful CSS'
Tags: productivity, css, showdev
Published: 2021-09-28 08:37:41

This week I launched a tool,  [Beautiful CSS](https://beautifulcss.dev/).

You just have to click on any of the components and it will copy its style to your clipboard so you can use it freely!

I intend to increase its library so that it becomes the ultimate front-end developer tool!

It's also on ProductHunt if you want to upvote it 👉 https://www.producthunt.com/posts/beautiful-css

Any feedback is very much appreciated! 🤘
How to find Square Root in Python?
Tags: python, programming, codenewbie, tutorial
Published: 2021-09-28 11:11:48

---
title: How to find Square Root in Python?
published: true
date: 2021-09-28 08:17:16 UTC
tags: #python #programming #codenewbie #tutorial
canonical_url: https://itsmycode.com/how-to-find-square-root-in-python/
---

ItsMyCode |

In this article, you will be learning how to find square roots in Python and what are the popular square root functions in Python.

## What is a Square root?

Square root, in mathematics,  **is a factor of a number that, when multiplied by itself, gives the original number**. For example, both 3 and –3 are square roots of 9.

## How to calculate the Square root in Python?

The math module in Python has **`sqrt()`** and **`pow()`** functions, using which you can calculate the square root of a given number.

### **Using sqrt() function**

The **`sqrt()`** function takes one parameter and returns the square root of the provided number. 

**Syntax:**

**_sqrt(x)  _# x is the number whose square root needs to be calculated.**

**Example**

Let’s take a various and find the square root of a decimal, positive number, zero. 

```python 
# Import math module
import math

# calculate square root of given number
print(math.sqrt(25))

# square root of 10
print(math.sqrt(10))

# square root of 0
print(math.sqrt(0))

# square root of decimal number
print(math.sqrt(4.5))
```

**Output**

```python 
5.0
3.1622776601683795
0.0
2.1213203435596424
```

The **`sqrt()`** method can take only positive numbers in case if you provide the negative number you will get a **ValueError** as shown below.

```python 
# Import math module
import math

# calculate square root of negative number
print(math.sqrt(-33))

```

**Output**

```python 
Traceback (most recent call last):
  File "c:\Projects\Tryouts\main.py", line 5, in <module>
    print(math.sqrt(-33))
ValueError: math domain error
```

### **Using pow() function**

The**` pow()`** method can be used to compute the square root of any number. This **`pow()`** function takes two parameters and multiplies them to compute the results. This is done in order to the mathematical equation where, 

**x2 = y or y=x\*\*.5**

The syntax of this function is as follows:

**Syntax**

**_pow(x,y)  _# where y is the power of x or x\*\*y **

```python 
# Import math module
import math

# calculate square root of given number
print(math.pow(25,0.5))

# square root of 10
print(math.pow(10,0.5))

# square root of 0
print(math.pow(0,0.5))

# square root of decimal number
print(math.pow(4.5,0.5))
```

**Output**

```python 
5.0
3.1622776601683795
0.0
2.1213203435596424
```

The post [How to find Square Root in Python?](https://itsmycode.com/how-to-find-square-root-in-python/) appeared first on [ItsMyCode](https://itsmycode.com).
How to Rename a file in Python?
Tags: python, programming, codenewbie, tutorial
Published: 2021-09-28 11:11:13

---
title: How to Rename a file in Python?
published: true
date: 2021-09-28 08:12:10 UTC
tags: #python #programming #codenewbie #tutorial
canonical_url: https://itsmycode.com/how-to-rename-a-file-in-python/
---

ItsMyCode |

The os module in Python comes in handy in performing any file operations. The **`rename()`** method is used to rename a file or directory in Python.

## Python Rename File

Python **`rename()`** function can rename any file type or folder in Python. 

**Syntax**

**os.rename(src, dst)**

**Parameters**

- **src:**  src is the source file name that needs to be renamed. If the function cannot find the file or is inaccessible, Python will raise an [OSError](https://docs.python.org/3/library/exceptions.html#OSError). 
- **dst:**  dst is the destination file name which is the new name of the file or directory

**Note** : If the dst already exists, then the **_FileExistsError_** will be thrown in Windows, and in the case of UNIX, an **OSError** will be thrown.

## Example to rename a file in Python

```python 
# Import os module
import os

# file name old and new. This can be even absolute path
old_file_name = "python.txt"
new_file_name = "python_renamed.txt"

# use rename function to rename the file or directory
os.rename(old_file_name, new_file_name)

print("Successfully renamed a file !")
```

**Output**

```python 
Successfully renamed a file !
```

## Python Rename Multiple Files

There are times where you may need to rename multiple files in the same directory recursive. Let’s say some automated batch job creates a new file with the same name, and you still need to back up the old files by just renaming them as **_old\_filename_** then, you can use **`rename()`** method to perform batch rename.

## Example to Rename Multiple Files in Python

The code is straightforward. We can use the **`os.listdir() `**method in a loop that can get all the files, iterates each file inside the loop, and use the **`rename()`** function to rename the file.  

```python 
# Import os module
import os

# Batch rename all the file in the specified directory
for file in os.listdir("C:/Projects/Tryouts"):
	os.rename(file, f"C:/Projects/Tryouts/old_{file}")

```

**Output**

```python 
old_test.txt
old_python.text
old_student.csv
```

**Note:**  You can give the **src** and **dst** in the absolute path or relative name depending on where the file is placed, and the code is running. In the example, we have used both absolute and relative file names.

The post [How to Rename a file in Python?](https://itsmycode.com/how-to-rename-a-file-in-python/) appeared first on [ItsMyCode](https://itsmycode.com).
We Are Switching From TestCafe to CodeceptJS – Here’s Why
Tags: javascript, testing
Published: 2021-09-28 08:02:24

We have been using and promoting TestCafe at platformOS for the past couple of years with great success. Because a lot of people will write tests and maintain them over a long time, an End-to-End framework has to come with some specific requirements:

1. Easy to remember and type out API
2. Good waiting mechanisms (for XHR requests, animations)
3. Extendibility, page object support, helpers support
4. Good search in documentation to quickly reference less used APIs
5. Run properly in Docker and/or GitHub Actions

TestCafe is scoring high on the above areas, I would say averaging around 7.5/10, which means there is still room for improvement.

Even though we have been happy with TestCafe, last year when I stumbled upon a new contender, CodeceptJS, I decided to give it a shot on our [documentation](https://documentation.platformos.com/) and [marketing](https://www.platformos.com/) sites. It delivered excellent developer performance. It was enough to dive deeper into its documentation and expand our test suites to include some more test cases.

## 1. Test API

Very often when writing TestCafe tests, we had to resort to vanilla JS and DOM operations. One of the most frustrating examples was to get some text from an element and then compare it to another. It was too much work and I never could see a reason why TestCafe had no API for that. CodeceptJS has a lot more API helpers to avoid these complications and diverging into vanilla JS. Below, I give you some examples of TestCafe scenarios converted to CodeceptJS ones.

### Checking if correct breadcrumbs links are present on a page

```js
// TestCafe
test('Breadcrumbs are showing up', async t => {
  await t.navigateTo('/api-reference/liquid/introduction');

  await t.expect(Selector('.breadcrumbs a').withText('Documentation').exists).ok();
  await t.expect(Selector('.breadcrumbs a').withText('API Reference').exists).ok();
  await t.expect(Selector('.breadcrumbs a').withText('Introduction').exists).ok();
});

// CodeceptJS
Scenario('Are showing up', ({ I }) => {
  I.amOnPage('/api-reference/liquid/introduction');

  I.see('Documentation', '.breadcrumbs');
  I.see('API Reference', '.breadcrumbs');
  I.see('Introduction', '.breadcrumbs');
});
```

> #### If this is interesting to you [read rest of this article on our blog](https://www.platformos.com/blog/post/we-are-switching-from-testcafe-to-codeceptjs-here-s-why).


## Read more

If you are interested in more performance oriented content, follow me and I promise to deliver original, or at least effective methods of improving your website. 

{% link https://dev.to/platformos/platformos-documentation-site-webpack-setup-93l %}

{% link https://dev.to/platformos/3-performance-tips-for-your-next-project-2bdm %}

{% link https://dev.to/platformos/should-you-always-care-about-your-website-size-2jcc %}
Free (MIT) Transactional HTML Email templates built using Tailwind CSS
Tags: tailwindcss, html, email, opensource
Published: 2021-09-28 07:59:00

Today I'm releasing a set of [free HTML Transactional Email Templates](https://github.com/ohmysmtp/templates). Check them out here: 

{% github ohmysmtp/templates no-readme %}

These templates are super cool because they're built using [Tailwind CSS](https://tailwindcss.com), and the repository contains all of the build tools required to use Tailwind in HTML emails, making sure they render correctly across different browsers & devices. This is all powered by [Maizzle](https://maizzle.com) - which provides CSS post processing to embed Tailwind into an email and apply a bunch of HTML email best practices.

Oh and they support `Dark Mode` out of the box ;-)

## Why Tailwind CSS?

Tailwind CSS gives you "utility classes" to use in your HTML such as `p-48` (apply padding of 48px to all 4 sides of an element) or `rotate-90` (rotate an element 90 degrees). You can use these utility classes to build almost anything in HTML, without touching CSS.

At first this seems a bit awkward, like you're inlining CSS inside your HTML, but after you get used to the syntax it makes adding styling to HTML pages extremely productive. You don't need to switch context to CSS and come up with class names or an informal class hierarchy. It's hard to state how much more productive you can be in Tailwind, but **it really is a massive boost when you're building HTML apps** (or  email templates in this case!)

If you do want to make components (e.g. `.btn`) you can use the `@apply` CSS directive to bundle up styles into components and reuse them.

## But how?

The included [Maizzle](https://maizzle.com) configuration post-processes all of your HTML using various [PostCSS](https://postcss.org/) plugins. In the end, you just write normal HTML with Tailwind and Maizzle takes care of building your HTML templates out, and spits them into the `/dist` directory when complete.

Easy!

## Who can use them?

Anyone, for any reason. They're MIT licensed so feel free to do what you like with them.

## What are Transactional Emails?

Transactional emails are automated emails sent on a one-time basis, typically triggered by a user interaction or system update in your website / app. They are usually sent to one person at a time, and contain important or actionable information for your  service.

Typical transactional email types include account notifications, receipts, updates, password reset notifications, magic sign up links and many, many more. 

## Want to send your transactional emails through an Independent 💪, privacy-focused 🕵️ and eco-friendly 🌱 provider?

Sign up for an account at [OhMySMTP](https://ohmysmtp.com)
More on Javascript functions
Published: 2021-09-28 07:56:42

Functions are essential part of our daily code an everybody uses them at one point  in time. 
Here is a basic skeleton of a javascript function: 
   
   function functionName(){
     //code goes here;
    }
 let us explore a little more sophisticated concepts on functions.

1.Immediately invoked function expressions (IIFE)
These means invoking  a  function  immediately after it has been defined.
for example instead of writting:

  function helloWorld(){
    console.log('hello world');
    }
 
  helloWorld(); //invoking it manually


we can use  the IIFE to do it immediately after defining it.

 (function() {
   console.log("hello world");
 )();}



2. Arrow functions
 Was introduced in ES6.It is a simpler way to write  function expression. (note: it is not a substitute to writing functions)

example: 
//function to return sum of  two numbers
 let sum = (num1 , num2) => num1 + num2;

 console.log(sum(2,6));   //8

why use arrow functions?
1. shorter syntax.
2. simpler way to write function expression.
3. this derives its value from enclosing lexical scope.

side effects
1. you have to be ware of the behavior of 'this' keyword.
2. no argument object.


#Thanks for making time
Twitter: @kimanigeoffre14
API Testing - XML Requests and Response Validation in vREST NG
Tags: testing, vrestng, apitesting
Published: 2021-09-28 07:55:52

Watch our video #tutorial on how you may invoke SOAP requests or send XML payloads and validate XML responses easily within few seconds using the #vREST NG Application.

Video Link: https://youtu.be/rAQZv-SMJpk

Playlist: https://youtube.com/playlist?list=PLmua155_WrDzt1AbB6iV5Lsw_Z7QrzZZ0

vREST NG is an enterprise-ready application for Automated API Testing. You can download and install the vREST NG application directly on Windows, OSX, and Linux via our website.

*Important Links:*
1. [vREST NG Website](https://vrest.io/?utm_source=devto&utm_medium=devto-desc&utm_campaign=video)
2. [Contact Email](support@vrest.io)
3. [Community Chat](https://discord.gg/NtRa7kw)
4. [Book a Live Demo](https://meetings.hubspot.com/dheeraj-aggarwal)

Please do like and share if you found this video helpful and let the voice heard by the testing community. Also, let us know your feedback by commenting on this post.
How to retry and log the final result in Bash
Tags: bash, beginners
Published: 2021-09-28 07:23:22

I know there are lots of how-to write retry logic in Bash, such as [here](https://stackoverflow.com/questions/12321469/retry-a-bash-command-with-timeout).

I've decided to use the one in the accepted answer above.
However I wanted to add another logic to log the final result  as well, so I needed to modify this snippet as  _sleep_ always returns exit code 0 at last that logging depending on the exit code would not work as it always returns 0, even the command to be retried ended up with failure.

So here is my snippet. Below runs YOUR_COMMAND until success, 4 times for the maximum, and echo the result based on the exit code. This might not work depending on how YOUR_COMMAND returns a result, but it worked in my case.

```
NEXT_WAIT_TIME=0
RESULT=0
until [ ${NEXT_WAIT_TIME} -eq 4 ] || YOUR_COMMAND
do
    sleep $(( NEXT_WAIT_TIME++ ))
done
if [[ ${NEXT_WAIT_TIME} -eq 4 ]]; then
    RESULT=1
fi
if [[ ${RESULT} -eq 0 ]]; then
    echo "Command Successful"
else
    echo "Command Failed"
fi
```
What are your best projects to date?
Tags: watercooler, coding, project
Published: 2021-09-28 07:21:47

---
title: What are your best projects to date?
published: true
description: 
tags: watercooler, coding, project
cover_image: https://i.pinimg.com/originals/b5/84/cf/b584cff4c5c0b9bbf3f6c1a76bbd126b.gif
---
What are some of the best projects that you have built? Pick like 1-3 projects of yours and tell us why you feel proud of them!

Personally, I am happy on how [My portfolio](https://www.madza.dev/), [devQuizzes](https://quizzes.madza.dev/) and [Audio Player](https://audioplayer.madza.dev/) turned out due to the amount of work spent and their practical usability.

What are some of the highlighted projects in your portfolio?
Share your creations down below! 👇