teleren/devto huggingface dataset:
Rolling Hash Function
Tags: algorithms, computerscience, programming
Published: 2023-04-16 15:30:31

## Hash function
It's a function that can map any kind of data of arbitrary size to fixed-size values, these values are called **Hash Values**


**In our case we will talk about _Rolling Hash Function_ that is used in Rabin-Karp Algorithm**

## Rolling Hash Function: 
###Recap: 
In **Rabin Karp Algorithm**, we used to compare the hash values of the pattern and the substring to find the match, by using **Rollling Hash Function**, we can prevent the rehashing of the whole substring by only using the old hash value. 


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

- For simplicity, I used incremental values starting from "1" to encode the english alphabet, we can use **ASCII** or any other encoding. 

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

- In our next iterations, we will use the old hash value, subtract the letter that is no longer inside our window and add the newly added one. 

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

## Tips to have a good rolling hash function: 

### 1.  Prevent Frequent Collisions: 

> We can have two equal hash values for two different strings, like having same letters in different order for example.

To prevent collisions we can multiply each character with a constant raised to power of its position. 

![Img1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7t28coe1bosgphpt7w9v.png)

- For simplicity, I chose 10 as our constant raised to power of (n - 1) where n is the position of character from the right.
![Img2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5b5svbo8ah63ppdbfmkh.png)
- Same as the previous algorithm except that we are sure that order of characters will definitely affect our hash values. 
![Img3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5u76az1yibs1pt2qy4p8.png)

> To prevent hash value collisions, choose a constant that is 
greater than the largest value in the alphabet. 

And here comes tip #2

### 2.  Prevent Integer overflows: 
We will add to our formula **(% m)**, where **m** is a larger prime number, since the probability of two random strings colliding is about ≈ 1/m.

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

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

![Img3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g595gh5sdqiiepg43xkw.png)
Five pieces of advice for more accessible websites
Tags: webdev, beginners, a11y
Published: 2023-04-16 15:28:58

On March 29, WebAIM published [an annual accessibility report](https://webaim.org/projects/million/). Unfortunately, the results are devastating, as usual. To improve stats for the next year, start with these five quick wins that will make your site much more accessible.

## Accessibility starts with HTML

I am not an accessibility expert by no means. However, I follow accessibility leaders, and I read a lot of articles about it, so it would be fair to say that I develop with accessibility in mind ([my site has no accessibility error](https://webaim.org/projects/million/lookup?domain=silvestar.codes)). Even when accessibility is out of the budget, you could still improve accessibility without spending too much time. Improving your HTML is a good starting point, so let’s look at how to start.

## Document language

Adding language to your HTML document must be one of the most straightforward tasks, even if your site is multilingual. Inspect the source code of your site and see if the `lang` attribute is present in your `<html>` tag.

```html
<html lang="en">
```

Read more about [declaring language in HTML](https://webaim.org/techniques/language/).

## The “skip” link

It might be a good idea to add a link at the top of the page that helps users skip to the main part of the page (there should be only one `<main>` element). It shouldn’t be too hard to implement such a link once and reuse it on every page (where it makes sense).

```html
<a href="#main">Skip to main content</a>
...
<main id="main">...</main>
```

Read more about [creating “Skip Navigation” links](https://webaim.org/techniques/skipnav/).

## Labels and input elements

Every `input` field must have its `label`. Users are used to labels and rely on them to understand what information to provide.

```html
<label for="firstName">First name:</label>
<input type="text" id="firstName">
```

Read more about [creating accessible forms](https://webaim.org/techniques/forms/).

## Empty buttons and links

Assistive technologies cannot properly announce empty buttons and links. So if you have empty buttons or links, take advantage of the `.visually-hidden` hack or label the button using `aria-label`. Remember to apply this advice, no matter the project’s stage. Once you lose track of these things, it is more unlikely that you will fix them.

```html
<button class="button-play" aria-label="Play video"></button>
```

See more [examples for buttons with non-empty accessible names](https://www.w3.org/WAI/standards-guidelines/act/rules/97a4e1/).

## Alternative image text

Always add alternative text to your images and try to write it as a sentence.

```html
<img src="/tree.jpg" alt="A single oak three in the meadow.">
```

Read more about [how to provide the best alternative text for images](https://webaim.org/techniques/alttext/).

## Conclusion

There are a lot of ways how you could make your site more accessible. Start with these five examples, and allow every user to understand your website better.
[Linux] How To Stop Ubuntu 22.04 Sleep With Command
Tags: linux, ubuntu, sleepmode, hibernatemode
Published: 2023-12-29 07:42:24

---
title: [Linux] How To Stop Ubuntu 22.04 Sleep With Command
published: true
date: 2023-04-16 15:23:17 UTC
tags: 
- linux
- ubuntu
- SleepMode
- HibernateMode
canonical_url: https://www.kmp.tw/post/stopubuntu2204sleepusingcommand/
---


# Situation
### Prevent Machine Sleep
<!--more-->
# How To

### Check `sleep.target` Status

```
root@desktop:~# systemctl status sleep.target
○ sleep.target - Sleep
     Loaded: loaded (/lib/systemd/system/sleep.target; static)
     Active: inactive (dead) since Wed 2023-03-29 00:02:04 CST; 6min ago
       Docs: man:systemd.special(7)

Feb 03 10:00:50 desktop systemd[1]: Reached target Sleep.
Mar 29 00:02:04 desktop systemd[1]: Stopped target Sleep.
```

### Set `mask` In `sleep.target`,`suspend.target`, `hibernate.target` And `hybrid-sleep.target`

```
root@desktop:~# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
root@desktop:~# systemctl status sleep.target
○ sleep.target
     Loaded: masked (Reason: Unit sleep.target is masked.)
     Active: inactive (dead) since Wed 2023-03-29 00:02:04 CST; 8min ago

Feb 03 10:00:50 desktop systemd[1]: Reached target Sleep.
Mar 29 00:02:04 desktop systemd[1]: Stopped target Sleep.
```

### Done
CSS Text Transform: You Don't Need JavaScript to Capitalize Your Text
Tags: webdev, css, codenewbie, beginners
Published: 2023-04-16 15:19:11

---
title: CSS Text Transform: You Don't Need JavaScript to Capitalize Your Text
published: true
description: The CSS text-transform property is used to specify text capitalization in an element.
canonical_url: https://www.codu.co/articles/css-text-transform-you-don-t-need-javascript-to-capitalize-your-text-seo6q6mx
tags: webdev, css, codenewbie, beginners
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv7oerynvzwl6d3velp9.png
# Use a ratio of 100:42 for best results.
---

Sometimes we over-engineer things...

In [this previous article](https://www.codu.co/articles/uppercase-the-first-letter-in-a-string-with-javascript-2xrydwr_) I showed you how to capitalize a string with JavaScript. 

Here's a snippet from it:
```js
let str = "hello world";
let capitalizedStr = str.slice(0, 1).toUpperCase() + str.slice(1);
console.log(capitalizedStr); // "Hello world"
```

This might be useful in some cases, but if you are doing it to display a value, there is an easier way. 

## CSS Text Transform Property

The CSS `text-transform` property is used to specify text capitalization in an element. This property can be applied to any text-containing element, like paragraphs, headings, lists, etc. The text-transform property accepts the following values:

- `none` - Leaves the value unchanged 
- `capitalize` - Capitalize the value
- `uppercase` - Uppercase the value
- `lowercase` - Lowercase the value

So to capitalize our paragraphs, it would be as simple as applying the following in our CSS:
```css
p {
  text-transform: capitalize;
}
```

The CSS text-transform property is a powerful tool for manipulating text styles on a web page, making them convenient to know. 🦾 

---

Follow me on [Twitter](https://twitter.com/nialljoemaher) or [connect on LinkedIn](https://www.linkedin.com/in/nialljoemaher/).


**🚨 Want to make friends and learn from peers?**
You can join our free web developer community [here](https://www.codu.co/). 🎉
How I turned the heat of my web server into a germination greenhouse for hot peppers
Tags: programming, webdev, tutorial, startup
Published: 2023-04-16 15:10:17

After several years of noticing that the Raspberry pi 4 I was using to do my prototypes, remote calculations and host my website was producing a lot of heat and after investing in a heat sink, I decided to put this energy to use to greenery my office and potentially explore another field of science and business.

![Photo de Echo Wang sur Unsplash](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c04qi7y8o1b8mt2rn6yb.jpg)

Every developer knows the feeling of a boiling server when setting up a remote computing solution. The writing of this article was born from an obvious thinking that this heat should be used for useful purposes to optimize the energy consumption of the devices.

At the time of writing, the temperature of the CPU was 50.01 degrees Celsius, which can rise to 60 degrees during periods of high activity, producing heat radiation between 30 and 38 degrees within a radius of 5 to 15 centimeters in semi-enclosed space.

30 degrees is both a lot and not enough. With 30 degrees you can’t cook, or even less heat a room. It was then necessary to find an original idea to exploit this heat and what better way than to transform it into a completely different, capsaicin.

With a little research, we quickly realize that this heat range is actually ideal for the germination and early growth of hot peppers. As such, a short study of the Chinese academy of tropical agricultural sciences showed already in 2010 that a constant temperature of 30% allowed to increase by two the germination ratio of black pepper seeds (Piper nigrum L.)

So I decided to optimize the thermal diffusion of the Raspberry Pi to concentrate the heat towards a space dedicated to the germination of the seeds, within a wooden box specifically designed for the installation of petri boxes.

![Germination greenhouse with dimensions in cm.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7plsxdsx1e8bqy30splu.png)

Once the scheme was finalized, I bought a pine board of 2 meters by 9.5 centimeters, which I cut according to the dimensions explained above, the result being this :

![The final piece.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g01l4a31uujrqppatb65.png)

It will then take a few months to obtain similar plants which are currently flowering and will soon give hot peppers.

> However, it will be necessary to pay particular attention to the temperature of the Raspberry Pi, so that it does not remain too high in an enclosed space, but a priori, this should not pose any problem and would allow to germinate any seed.

I thank you for reading and hope that it will give you some creative ideas to recycle the heat from your servers,
Louis Brulé Naudet
Dark Web Monitoring: Protecting Your Business from Cyber Threats
Tags: web, monitoring, network
Published: 2023-04-16 15:06:53

With the rise of the Dark Web, many organizations and individuals have started to invest in Dark Web monitoring services to protect themselves from cyber threats.

[Dark Web monitoring](https://kaduu.io/dark-web-monitoring/) is the process of monitoring the Dark Web for any sensitive or confidential data that may have been stolen or leaked. This includes monitoring for stolen credentials, personally identifiable information (PII), credit card information, and other sensitive data.

The internet is a vast place, with numerous websites, social media platforms, and online marketplaces. While most of these sites are open and accessible to anyone, there is a hidden side of the internet called the Dark Web that is not easily accessible to the average user.

The Dark Web is a network of websites that are intentionally hidden from search engines and require special software or configurations to access.

Due to its anonymity and untraceability, the Dark Web has become a hub for illegal activities, such as drug and weapon sales, human trafficking, and cybercrime.

Businesses and organizations are particularly vulnerable to Dark Web threats, as they often store large amounts of sensitive data that can be used for fraudulent activities. For example, if an employee's login credentials are stolen, cybercriminals can gain access to the organization's network and steal confidential data.

Similarly, if customer PII is leaked, it can be used for identity theft or sold on the Dark Web.

Dark Web monitoring can help businesses and organizations detect and prevent these types of cyber threats before they cause significant damage.

It works by using specialized software and tools to scan the Dark Web for any instances of stolen or leaked data. When sensitive data is detected, the monitoring service will alert the organization so that they can take action to mitigate the risk.

Individuals can also benefit from Dark Web monitoring, especially those who have been victims of data breaches in the past.

If your personal information has been leaked on the Dark Web, a monitoring service can help you detect any fraudulent activities that may result from the breach. For example, if your credit card information is stolen and sold on the Dark Web, a monitoring service can alert you if there are any attempts to use your card for fraudulent purchases.

Dark Web monitoring services are not foolproof, and they cannot prevent all cyber threats. However, they are an essential tool in the fight against cybercrime and can help organizations and individuals stay one step ahead of cybercriminals.

By monitoring the Dark Web for stolen data, businesses and individuals can detect and prevent fraud before it causes significant harm.
need some team members to build a store management web app project
Tags: webdev, javascript, programming, beginners
Published: 2023-04-16 15:02:41

Building a web application for store management can be a challenging and rewarding experience. This kind of project requires a diverse set of skills, including front-end development, back-end development, database management, and user experience design. If you are a self-taught web developer like me, you might be interested in building such a project with a team of other developers.
The store management web application that me envisions includes a range of features that will make it useful for store owners and customers alike. Clients will be able to create accounts, login, reset passwords, and manage their accounts. They will also be able to add and remove products, create and delete categories, add and remove customers and suppliers, and generate bills. The website will be built using NodeJS, MongoDB, Javascript, React, and ExpressJS, which are popular and powerful tools for web development.
If you are a web developer looking for a challenging project to add to your portfolio, working with me on this store management application could be an excellent opportunity. By contributing to this project, you will gain experience in a range of important web development skills and technologies, including NodeJS, MongoDB, Javascript, React, and ExpressJS. You will also have the opportunity to collaborate with other developers, learn from their experiences, and share your own knowledge.
If you are interested in joining my team, you can send an email to **server@theankan**.live. By working on this project, you will be able to show a large project on your resume, which can be a valuable asset when looking for future employment opportunities. Additionally, if the project is completed successfully, there will be opportunities to work on more large projects to further strengthen your resume.
Building a store management web application with a team of other developers can be a rewarding experience. It requires a diverse set of skills and a willingness to learn and collaborate with others. If you are interested in joining my team and contributing to this exciting project, don't hesitate to send an email and get started today.
Dotnet Logger Benchmark
Tags: dotnet, csharp, beginners
Published: 2023-04-16 14:50:53

Testing the execution efficiency of different Log methods in various versions of .Net, including .Net 5 through .Net 7.

## Start with the conclusion 
- Use `"LoggerMessage.Define<>"` Instead of `"Logger.Log()"`.
- Use `"LoggerMessageAttribute"` Instead of `"LoggerMessage.Define<>"`.

In general, `LoggerMessage` is the **winner** all around. As we can see, using `LoggerMessage` in different .Net versions results in significantly faster execution times, which in turn leads to better performance in the StdDev aspect relative to using Logger Extension.

Moreover, starting from .Net 6, the performance of `LoggerMessageAttribute` is even better than `LoggerMessage.Define<>`.

## .Net 5

``` ini

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
12th Gen Intel Core i7-12700, 1 CPU, 20 logical and 12 physical cores
.NET SDK=7.0.203
  [Host]     : .NET 5.0.17 (5.0.1722.21314), X64 RyuJIT
  DefaultJob : .NET 5.0.17 (5.0.1722.21315), X64 RyuJIT
```
![Net 5 Benchmark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83a377a2j9bv3k5pb0s6.jpg)

## .Net 6

``` ini
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1555/22H2/2022Update/SunValley2)
12th Gen Intel Core i7-12700, 1 CPU, 20 logical and 12 physical cores
.NET SDK=7.0.203
  [Host]     : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2
```
![Net 6 Benchmark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlue16pefrnd5si23uup.jpg)

## .Net 7

``` ini
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1555/22H2/2022Update/SunValley2)
12th Gen Intel Core i7-12700, 1 CPU, 20 logical and 12 physical cores
.NET SDK=7.0.203
  [Host]     : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
  DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
```
![Net 5 Benchmark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq4t3wcw25iwcm3iuwvt.jpg)


Reference:
- https://www.c-sharpcorner.com/article/speed-up-logging-in-net/
- https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator

Github: https://github.com/yuze1995/DotNet.Logger.Benchmark
How to generate an augmented text and speed up the reading of long paragraphs (Pure JS tutorial)
Published: 2023-04-16 14:42:32


Maintaining attention and speeding up reading is a permanent requirement for sites offering rich and technical content, and participates in the transmission of information. Various methods exist to implement such solutions, including the detachment of text areas allowing a highlighting of certain visual elements acting directly on reading. This article aims to explain the implementation of a fast reading solution in pure Javascript, which can be deployed directly on the Internet.

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

Augmented reading is a new way of reading which relies on the use of fixation points to allow a more fluid and comprehensible reading. The first letters of a word are in bold to focus the reader’s attention on these letters and let the brain complete the end of the word. This way, you only read a few letters and your brain does the rest, which allows you to read faster.


A processing method to realize an augmented text would consist in the implementation of a simple calculation rule:
- For strings between 1 and 3 in length, only the first letter is bolded ;
- For strings with a longer length, considering even strings, half is bolded, for odd strings, half will be rounded up.

{% embed https://gist.github.com/louisbrulenaudet/165d466e91dd05edce35e04b6d3b07d9 %}

Let’s dive deeper into the code above:
- The first step consists in separating each word of the paragraph within a list allowing an iteration and an individualized treatment ;
- Then, the processing will consist of evaluating the length of the string then breaking it down into a prefix and a suffix, the prefix of which will undergo a <b> node for its advanced representation in the HTML document ;
- It will then suffice to recompose the sentence by iterating over the newly created list to accommodate the enriched words, then display it within the HTML document.
Through this simple example, it becomes possible to accelerate reading and simplify the effort for people suffering from attention deficit.

> It is of course possible to consider a more dynamic division, taking the first syllables of each word as an inking point, but this method would imply the implementation of a more invasive algorithm, consisting in particular of a data enrichment depending on the language to highlight.

Thank you for reading,
Louis Brulé Naudet
Being a Developer Advocate: Week 28+29
Tags: devrel, learninpublic
Published: 2023-04-16 14:32:26

The last two weeks already passed?

I have been busy inside and outside of work so I needed to recharge my batteries a bit over this weekend. Getting a day with no planned things on your plate always works wonders for me.

Other than that we are currently churning out content at as much as we can to fulfill our OKRs. I am in full swing with content reuse. I follow this pattern:

Short form video -> Blog post -> Docs -> Various social media posts

## Developer Experience Audits and Doing my Job Well
With all the content creation and hackathon efforts I somehow lost track of another thing you should be doing. Advocating for your user ;-)

Well there is only so much you can do when working alone.

I also had an idea on why our users had a hard time when onboarding and validated it by doing a developer experience audit. It went "well" and I got hard-stuck with the use case I wanted to implement.

Hopefully this will give me another push to advocate for fixing issues at the core level of our product!