teleren/devto huggingface dataset:
Strange Counter | Hackerrank Problem Solution With Explanation
Tags: competitiveprogramming, algorithms, hackerrank, python
Published: 2022-05-29 12:04:35

## Problem Statement
There is a strange counter. At the first second, it displays the number . Each second, the number displayed by decrements by 1 until it reaches 1. In next second, the timer resets to **2 x the initial number of the prior cycle** and continues counting down. The diagram below shows the counter values for each time _**t**_ in the first three cycles:

![Strange Counter Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0t7j7fdhtccqxrv66h1.png)
 
Find and print the value displayed by the counter at time **_t_**.

**Input Format**
A single integer, the value of **_t_**.

**Sample Input**
4

**Sample Output**
6

**_Link to question:_** [https://www.hackerrank.com/challenges/strange-code/problem](https://www.hackerrank.com/challenges/strange-code/problem)

## Solution (Python3)

```
def strangeCounter(t):
    # Write your code here
    n = math.log(((t + 3) / 3), 2)
    if math.floor(n) == math.ceil(n):
        return 1
    n = int(math.ceil(n))
    term = 3 * (math.pow(2, n) - 1)
    return int(term - t + 1)
```

## Explanation
From the given problem statement, we can clearly see that:

**Time taken to complete 1st cycle: _3s_**
**Time taken to complete 2nd cycle: _6s_**
**Time taken to complete 3rd cycle: _12s_**

And so on.

If we observe a little bit then we will find that time taken by cycles is forming a series and that series is in **G.P. (Geometric Progression)** with **common ratio** as **2**.

It is clear that the time at which is any cycle ends, is the cumulative sum of all the time taken to complete the cycle till that cycle. Viz.

**Time at which 1st cycle ends: _3_**
**Time at which  cycle ends: Time taken to complete 1st cycle + Time taken to complete 2nd cycle = _3_ + _6_ = _9_**

And so on.

If this series is in **G.P.** then the cumulative sum, i.e. the end time for any cycle, can be calculated using the below formula:

**_S = a(rⁿ-1)/(r-1)_**,

where **_S_** is the sum of the series, **_a_** is the first term of the series, **_r_** is the common ratio and **_n_** is the number of terms in the series.

Here, in the problem, we are given the sum of the series (i.e. **_t_** in this case), we know the first term and the common ratio (i.e. **_3_** and **_2_**). So, we have to calculate **_n_**. Using the above formula, we can deduce:

**_n=log₂((S+3)/3)_**

If we get a whole number as **_n_** then given **_t_** is the end time of the cycle. But if we get a floating number, then **_t_** is the time between the end times of previous cycle and next cycle. In this case, using the ceil value of **_t_** and the formula of the **Sum of G.P.** we can calculate the end time for the current cycle, say **_terms_**. And the difference between the **_terms_** and the **_t_** is our answer.
20 Jahre bloggen!
Tags: devjournal, wordpress, bloggen, weblog
Published: 2022-10-13 10:02:06

---
title: 20 Jahre bloggen!
published: true
date: 2022-05-29 12:00:00 UTC
tags: Journal,WordPress,Bloggen,Weblog
canonical_url: https://notiz.blog/2022/05/29/20-jahre-bloggen/
---

 ![Ein Screenshot meines ersten Blogposts im Mai 2002](https://notiz.blog/wp-content/uploads/2022/05/first-blog-post-900x676.png)

Heute vor 20 Jahren habe ich mit dem Bloggen angefangen! Das heißt ich schreibe jetzt fast mein halbes Leben lang Dinge in’s Internet!

Von **2002 bis 2005** ging es viel um persönliches und privates. Ich hatte ein [Blog mit Freunden](https://notiz.blog/2005/12/07/mein-erster-eintrag/), das oft auch einfach als Ersatz zu einem Messenger benutzt wurde.

**2005** hab ich dann angefangen [hier zu bloggen](https://notiz.blog/tag/happy-birthday/). Von **2005 bis 2007** waren mein Studium, Web-Technologien und das Web 2.0 die großen Themen auf notiz.Blog. Ich war fasziniert von der Blogosphäre und den sozialen Netzwerken die (damals noch die Guten) so nach und nach entstanden.

Ab **2007** entwickelten sich die großen „Communities“ immer mehr zu „_Walled Gardens_“ und ich schrieb und beschäftigte mich von bis **2010** viel mit den Themen „_Dezentrale Netzwerke_“ und „_Data Portability_„.

Seit **2007** hab ich auch angefangen mich intensiver mit meiner Blogging-Plattform [WordPress](https://notiz.blog/2018/06/19/15-jahre-wordpress/) zu beschäftigen. Dadurch ist wesentlich mehr Code als Text entstanden und wenn ich zum schreiben kam, war es meistens um die Entwicklung von [Plugins](https://profiles.wordpress.org/pfefferle/#content-plugins) und (dem einen) [Theme(s)](https://profiles.wordpress.org/pfefferle/#content-themes).

Die Themen ab **2007** sind [im Prinzip](https://notiz.blog/2021/12/07/notiz-b16g/) auch die Themen um die es bis heute geht. Wenig bis nichts persönliches und viel Technik, [WordPress](https://notiz.blog/category/wordpress/) und noch mehr [Open Web](https://notiz.blog/category/web/). Das ist OK für den Moment, muss aber nicht so bleiben 🙂

Auf die nächsten 20 Jahre! 🎉
Adding logs to your selenium script using python
Tags: python, selenium, testing
Published: 2022-05-29 10:45:59

Ever wondered running your selenium script but also thinking of saving the logs of every execution of your test cases? There is a much convenient way of doing this task in Selenium using Python. This article is all about this. 

# Main code

First of all, you need to create a python package, let's say it's name *log*. Inside of the package, create a python file (lets say it's *logCapture.py*). Then in this file, import a python package called *logging*. `import logging`  It should be included in the python when you install.

Then you can create a class and define method inside of it. It's better if you declare the method as a static method so that you can access the method from anywhere of your project without creating any objects of it's class. Then you can add the piece of code given below: 

````
import logging

class LogGen:
    @staticmethod
    def loggen():
        logger  = logging.getLogger("Test Login")
        fileHandler  = logging.FileHandler('.\\YourDesiredFolderName')
        formatter = logging.Formatter("%(asctime)s :%(levelname)s : %(name)s :%(message)s")
        fileHandler.setFormatter(formatter)
        logger.addHandler(fileHandler)
        logger.setLevel(logging.INFO)
        return logger
````
You can pass the name of your test case as a parameter inside the *getLogger()* method. The *filehandler* class will handle the your desired location for your logs. *Formatter* method will make sure your logs are being stored following a proper format. The *logger* variable will return the log at the end of the execution. 


# Driver code

Now it's time to use that *loggen()* function. Create another python file to add the driver code. Inside of this file, import the *loggen* function by simply using this code `from log.logCapture import logGen`. The code is basically for accessing the LogGen class which we created earlier. Then use the logging by just calling the *logger* variable.

Let's say we want to test a login page. So you can add logs by using `logger.info("You desired massage")` right before the execution of the test case or where ever you want. After executing the test cases, you will see a log file has been created in your desired folder. The log should look something like this


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0l5wcqxjz2qcb5q3skr.png)

This is the output of my logs after executing the test cases. This is how my code looks like behind this


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su9g6zdgko1kwvjxo420.png)

You should be able to use log if you follow this procedure :)


> Thanks for reading. Pardon me for the mistakes I may have made as I am new to automation testing and still exploring everyday. I would be glad if it helps anyone. :)
BUILDING A DECENRALIZED MICROBLOG WITH REACH
Tags: decentralized, web3, blockchain
Published: 2022-05-29 10:21:08

I had the amazing opportunity to yet again participate in the decentralized Umoja 2 Bounty Hackathon. As the name suggests this is a bounty hackathon that is hosted by Reach, Algorand and Africa Blockchain Alliance. Reach is a decentralized programming language that makes use of dockerised images. When writing a Dapp using Reach, you write a program that generates a smart contract and a backend as well as a frontend. The reach primitive publish allows participants to share information with all other participants which then happens automatically without other parties needing to do anything special.

The hackathon runs for a period of six weeks, whereby teams get to compete for prizes as well as beat deadlines to carry home incentives. For my project,I worked on a microblog which lets you share short messages with an online audience to improve engagement.Blockchain is fundamentally a way to provide reliability and safety by redundancy. A new way which can democratize the process of social networking.Anyone that is a believer of open and free media is definitely a benefactor of decentralized microblogging system.

The flow for my project as demonstrated [here](https://www.youtube.com/watch?v=2PTHShNUD00&t=14s) is that the frontend is hosted on Reach while Reach interacts with the Algorand network. Anyone with an algorand account can join the network and share their thoughts. The algorand address is used as the reference to the user to uniquely identify them and make transactions within the application.

Basic JavaScript and Reach knowledge is required when bulding a Dapp. Overall, Reach is a very easy to learn and use language especially when you are getting started on blockchain development.I would most definitely recommend that you try out [Reach](https://www.youtube.com/watch?v=z1nWuxelRpE) as early as **NOW** so as to max out on the learning opportunities available.

Lastly, I am grateful for my mentor for she always held my hand and made sure that I was jumping hoops over all the challenges that came my way. On top of this, she also made sure that I completed my project on time and she always encouraged me to deliver the best that I could offer.I surely could not have come this far without the support that I got.Reach also has an amazing community on [discord](https://discord.com/invite/reachsh) that is always so quick to respond to any questions or concerns. Join the family today, I promise you will like it here.
Depth First Search (DFS) algorithm tutorial
Tags: dfs, graph, datastructute
Published: 2022-05-29 10:08:35

In this tutorial, you will learn Depth First Search which is also known as the DFS algorithm. It is another algorithm like BFS. Unlike the BFS algorithm where we traverse the graph breadth-wise, in the DFS algorithm, we traverse the graph depth-wise, hence the name, depth-first search. DFS will continue visiting nodes until it arrives at a node with no unvisited adjacent nodes. So let's begin.

Depth First Seach (DFS) algorithm tutorial:
DFS algorithm is a recursive algorithm that involves the idea of backtracking.  The term backtrack means we move along the path and if there is no node to visit along the current path we move backward on the same path and then find other nodes to traverse. All the nodes of the current path will be visited after which the following path will be selected.

https://www.cstutorial.org/data-structure/depth-first-search-dfs-algorithm-tutorial
Web3 connecting wallet
Published: 2022-05-29 09:29:28

Utility function for reference 
```
import Web3 from "web3";

const getWeb3 = () => {
  return new Promise((resolve, reject) => {
    // Wait for loading completion to avoid race conditions with web3 injection timing.
    window.addEventListener("load", async () => {
      // Modern dapp browsers...
      if (window.ethereum) {
        const web3 = new Web3(window.ethereum);
        try {
          // Request account access if needed
          await window.ethereum.enable();
          // Acccounts now exposed
          resolve(web3);
        } catch (error) {
          reject(error);
        }
      }
      // Legacy dapp browsers...
      else if (window.web3) {
        // Use Mist/MetaMask's provider.
        const web3 = window.web3;
        console.log("Injected web3 detected.");
        resolve(web3);
      }
      // Fallback to localhost; use dev console port by default...
      else {
        const provider = new Web3.providers.HttpProvider(
          "http://localhost:9545"
        );
        const web3 = new Web3(provider);
        console.log("No web3 instance injected, using Local web3.");
        resolve(web3);
      }
    });
  });
};

export { getWeb3 };
```

Change `http://localhost:9545` if required.

Connecting to contract 
```
const web3 = await getWeb3();
const accounts = await web3.eth.getAccounts();
const networkId = await web3.eth.net.getId();
const deployedNetwork = Multisig.networks[networkId];
const contract = new web3.eth.Contract(
        Multisig.abi,
        deployedNetwork && deployedNetwork.address,
      );
```
AWS Security Stories #02: AWS Trusted Advisor
Tags: aws, security, cloud, awssecurity
Published: 2022-05-29 09:09:40

AWS Trusted Advisor provides recommendations that help you follow AWS best practices. AWS Trusted Advisor can be used for the following purposes

- Cost Optimization
- Performance Optimization
- Monitor Service Limits
- Fault Tolerance / Improve Reliability
- Improve Security

AWS Basic Support and AWS Developer Support customers can access core security checks and all checks for service quotas. AWS Business Support and AWS Enterprise Support customers can access all checks.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k23bag738fbknjyb2xdn.png)
 

Trusted Advisor might recommend that you enable various AWS security features, close any gaps, and examine your permissions. Trusted Advisor checks sourced from AWS Security Hub. After you enable AWS Security Hub for your AWS account, you can view your security controls and their findings in the Trusted Advisor console.

You can use Security Hub controls to identify security vulnerabilities in your account in the same way that you can use Trusted Advisor checks.
How to anonymously browse the internet
Tags: tutorial, security, beginners
Published: 2022-05-29 09:03:00

#### So this is a really heated topic for common people now a days that "how can i be completely anonymous on the internet"

#### Well this is not about "completely", cause maybe that not really what you can do with that ease, I mean no one is stopping you from using tor, if you know how to, but lets assume you don't want to get in that much of trouble to setup tor and other stuff like proxychains.
#### So lets talk about the most basic way how you can not be easily tracked

#### So the basic way how you reach a website is you type a URL in the browser, your computer goes to a DNS server, grabs the IP address of the sever that's bound to that URL and then reaches out to that website. In this whole process you used two major things
1. DNS
2. Public IP

So if you hide these two things you'll be good to go for just normal use when you are not planning to do any mischief in others system, anyways here's the trick 

### Use a VPN and a Specific DNS
#### What i mean by this is just using these two basic things can hide your tracks much easily. Use any VPN you like but right now i'll stick to proton VPN as claimed by the company they have log-less systems, who knows, anyway this was about the VPN. I don't really know if this trick works with all DNS or just 1.1.1.1 but for now just use 1.1.1.1 

### The Trick
#### So the trick is to use both of these simultaneously which on default settings isn't really gonna work so what you have to do is that you have to go in 1.1.1.1 settings and just use its DNS and then you can use both of these together easily 

~ for any query or support please write a comment below
see you in the next blog
Building a Video Calling App using Python & Flask
Tags: python, flask, javascript, webdev
Published: 2022-05-29 08:18:21

## flask_webrtc_youtube
================

A basic WebRTC video audio chat app made using python Flask.

Create and join video chat rooms. The users connects to each other in a peer to peer mesh network using WebRTC. They share their audio and video directly with each other without going through a centralized server. However, a centralized server is needed to initiate the connections at first using a process called signaling. This, signaling server is made using Flask in python and data is shared between server and clients using SocketIO.


For demo & explaination visit: https://youtu.be/ZvG1-s7QmLs
{% youtube ZvG1-s7QmLs %}


## Source code

Source Code is Available in the description box below in the video. So do check it out...

Installation
-------------
To run this on your machine, install the following:
### Requirements:
* python 3.x
* Flask
* Flask-SocketIO

Install requirements using pip:
```
pip install -r requirements.txt
```

To start a server on localhost:
```
python server.py
```

### Subscribe For More

[![YouTube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvjpg9zn6xfcdkfxhl0x.png)](https://www.youtube.com/c/YashMakan?sub_confirmation=1)

### Contact Me

Website: [yashmakan.co.in](http://yashmakan.co.in)

Twitter: [@Yash_Makan](https://twitter.com/Yash_Makan)

### Contribute

buymeacoffee: [@Here](https://www.buymeacoffee.com/yashmakan) 

### Other Interesting Articles
- [How to Run Python Code in Your Flutter App with pyFlut
](https://dev.to/yash_makan/how-to-run-python-code-in-your-flutter-app-with-pyflut-hgc)
- [21 must-read books for kids, beginner, advanced & interview with PDF 🐍](https://dev.to/yash_makan/21-must-read-books-for-kids-begineer-advanced-interview-with-pdf-56c7)
- [Improve your workflow using Automation in Python](https://dev.to/yash_makan/everything-about-automation-in-python-pc-mobile-web-raspberry-pi-4cgh)
- [4 ways to create modern GUI in python in the easiest way possible](https://dev.to/yash_makan/4-ways-to-create-modern-gui-in-python-in-easiest-way-possible-5e0e)
- [4 Free hosting platforms for python web app with step-by-step process](https://dev.to/yash_makan/4-best-python-web-app-hosting-services-for-freewith-complete-process-57nb)
- [18 Python one-liners that will speed up your coding process.](https://dev.to/yash_makan/18-python-one-liners-that-will-speed-up-your-coding-process-21md)
- [AI bot that could answer your questions](https://dev.to/yash_makan/ai-bot-that-could-answer-any-questions-asked-gmn)
- [Generate your own favourite TV episode using python](https://dev.to/yash_makan/generate-your-own-favourite-tv-episode-using-python-1pb3)
Today's Fun Joke For Developers - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2022-05-29 08:00:00

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

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

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

---

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

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

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

<!--
Joke text:
___Q:___ Why did the developer ground their kid?

___A:___ They weren't telling the truthy
 -->
Sidebar toggle with pure CSS and no JS.
Published: 2022-05-29 07:46:38

In this video we will explore how we can create a toggle functionality for Menu / SideBar with pure CSS and no JavaScript.

Toggle functionality is often built with JavaScript because it requires handling the click event.

But it can be built with pure CSS and no JavaScript.

This video shows you how.

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

----------------------

Hope, you found this video useful, and if so, make sure show your support by subscribing.

I also run a weekly newsletter, so you can join me there also: https://www.getrevue.co/profile/8020lessons

Thank You!
Errors In Python
Tags: programming, beginners, tutorial, python
Published: 2022-05-29 07:38:32

[Subscribe to our Youtube Channel To Learn Free Python Course and More](https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A)

When you write any program, it’s hard to write an error-free program. Whenever you make mistakes while writing the program, Python interpreter throws an error message. In this section, we will see the common errors that occur while writing a program.

**Syntax Errors**
Every programming language has its own syntax. The syntax is particular of writing the code. So if you make any mistake in syntax, the python interpreter throws a syntax error with an error message. See the below code:

```
# Syntax error

list = [1, 2, 3, 4, 5]

for elm in list
	print(elm)
'''
for elm in list
	  File "<stdin>", line 1
    for elm in list
                  ^
SyntaxError: invalid syntax
'''
```

Here you can see that in for loop colon(:) sign is missing that’s why Python throws this error. So whenever you encounter syntax error, look at your code syntax.

**Exceptions**
Even if your syntax is correct, Python throws an error after running the program. These types of error called runtime errors or exceptions. Let’s see some common exception.

**TypeError**
TypeError is raised when a function is applied to incorrect object. See the below example.

```
def add2(n):
    return n + 2

add2('hello')

'''
Output: TypeError: must be str, not int
'''
```

**IndexError**
IndexError is raised when the index of any sequence datatype(String, LIst, tuple) is out of range. See the below example.

```
a = [1, 2, 3, 4, 5]

print(l[5])

'''
Output: 
IndexError: list index out of range
'''
```

**NameError**
NameError is raised when a variable is not found in the local or global scope. See the below example.

```
tax_cut = 50

def bill(amount):
    pay = amount+taxcut
    return pay

bill(100)

'''
Output:
NameError: name 'taxcut' is not defined

The error occurs because taxcut is not in a global or local scope.
'''
```

**KeyError**

The keyError is raised when the key is not found in the dictionary. See the below example.

```
d = {1: 'a', 2: 'b'}

print(d[3])

'''
Output:
KeyError: 3
'''
```
**IndentationError**
IndentationError is raised when there is incorrect indentation. See the below example.

```
l = [1, 2, 3, 4, 5]

for elm in l:
print(elm)

'''
Output:
IndentationError: expected an indented block
'''
```
**ZeroDivisionError**
ZeroDivisionError is raised when the second operand of division or modulo operation is zero. See the below example.

```
print(1/0)
# Output: ZeroDivisionError: division by zero

print(1%0)
# Output: ZeroDivisionError: division by zero
```