teleren/devto huggingface dataset:
Unlock the Power of CTEs: Simplify and Optimize Your SQL Queries
Tags: webdev, sql, database, programming
Published: 2023-01-22 21:52:42

CTE stands for Common Table Expression, it's a feature in SQL that allows you to define a temporary result set that you can refer to within the context of a single SELECT, INSERT, UPDATE, or DELETE statement. 


CTEs are similar to subqueries but are defined using the **WITH clause** and can be _self-referencing_ and can be used _multiple times_ in the same **query**.

The basic syntax for a CTE is as follows:

```sql
WITH table_expression_name (column1, column2, ...) AS (
  SELECT ...
)
SELECT ...
FROM table_expression_name
```

Where _table_expression_name_ is the reference name.

### Key differences between Temporary Tables and CTEs

| Feature                               | CTEs                                                | Temporary Tables                                                                                 |
|---------------------------------------|-----------------------------------------------------|--------------------------------------------------------------------------------------------------|
| Syntax                                | WITH clause                                         | CREATE TEMPORARY TABLE statement                                                                 |
| Scope                                 | Only visible to the query in which they are defined | Visible to the current session                                                                   |
| Lifetime                              | Only available for the duration of the query        | Remain in the database until they are explicitly dropped or the session ends                     |
| Persistence                           | Not persistent, results not stored in the database  | Stored in the database and its result can be used by multiple queries or even different sessions |
| Recursive CTEs                        | Supported                                           | Not Supported                                                                                    |
| Speed (depending on the size of data) | CTEs                                                |



### Example

```sql
WITH top_selling_products (product, sales) AS (
  SELECT product, SUM(quantity) as sales
  FROM orders
  GROUP BY product
  ORDER BY sales DESC
  LIMIT 3
)
SELECT product, sales
FROM top_selling_products;
```

In this example, the CTE top_selling_products is defined to return the top 3 products based on total sales. The final statement retrieves the product and sales.

### Conclusion

Overall, CTEs can help simplify complex queries and improve readability and maintainability of your code. They also help to avoid repetitive code, and can improve the performance of your queries by reducing the need for subqueries.
Reach Your Users Everywhere: How to Connect With Mobile Users Through Your Web Application
Tags: webdev, programming, mobile, writing
Published: 2023-01-22 21:34:03

Need help reaching your users on the go?

Here are the three most popular methods for your web application to connect with your users using their phones.

## Why you need to reach mobile users

**The phone is the way to interface with the world.**

Think about the situation where you learn about a new product. You want to explore it right away. You'll use the phone instead of waiting to use your desktop when you get home.

So how do you get your app in front of mobile users?

## Websites optimized for mobile provide an easy and fast way to reach your users.

The simplest way to reach mobile users is to optimize your website for mobile.

**You should already be prepared because you should optimize your website for mobile anyway.** Create a mobile-friendly version of your application if you still need to, and ensure the design is responsive so your users can use it on various devices.

Simple applications primarily used through the website and needing a constant internet connection work best for mobile-optimized websites.

## Native applications allow you to use your users' phones' capabilities fully.

The traditional applications you use daily are native applications.

**You can make use of all the phone's features.** If you're creating feature-rich apps that must work offline or need the phone's hardware to work, native applications are fantastic options. However, you must create a brand-new phone application and need mobile developers.

If you require offline functionality and access to the phone's hardware, use native applications.

## Progressive Web Applications (PWAs) allow users to install their websites on their devices.

A compromise between native applications and mobile websites is offered by progressive web applications (PWA).

They are created similarly to a typical web application but incorporate extra functionality using JS workers. **Your app can now be downloaded and installed on devices** (mobile and desktop) by using this worker. It allows websites to have advanced features like offline functionality and notifications.

PWAs are a fantastic way to add new features without creating a new codebase.

## Summary
You should always try to reach mobile users:
- You can quickly reach them by using a mobile website.
- If you want to make the most of the hardware on the phone, use native applications.
- You can combine both strategies thanks to progressive web applications.

Choose the one that works best for your application; each option has advantages. As this will guide you in making the best choice, keep in mind the user experience and the features, you want to offer.
How to Document Your Cassandra Database with One Command (and Nothing to Install)
Tags: database, documentation, cassandra
Published: 2023-01-22 21:19:38

---
title: How to Document Your Cassandra Database with One Command (and Nothing to Install)
series: Document Your Database
published: true
description: Generate a description of your Cassandra database table structure with one command.
tags: database, documentation, cassandra
---

Ever wondered what the tables in your Cassandra database look like? Generate a text file of your Cassandra database with one command. You can run this on any system that has Docker installed.

For now, create a Cassandra database in a Docker container. Later you can use the same technique to conect to your own Cassandra database. Create two Docker Compose files for the Cassandra and SchemaCrawler containers. Also create one more with the CQL database creation script. You can find these files in the [GitHub gist for this article](https://gist.github.com/sualeh/ab87647dd56b1fa776504d55c402ba6a).

Then open a command shell in the same folder that you created these files, and run:

```sh
docker-compose -f schemacrawler.yml -f cassandra.yml up -d
```

Wait for a while for the containers to start up, and then connect into the Cassandra container by running:

```sh
docker exec -it cassandra bash
```

In the Cassandra container shell, run the script to create a sample database, and exit the shell:

```sh
cqlsh -f /share/database.cql
exit
```

Now that the Cassandra database is created, connect into the SchemaCrawler container by running:

```sh
docker exec -it schemacrawler bash
```

In the SchemaCrawler container shell, run SchemaCrawler against the Cassandra database to see your table. Run:

```sh
schemacrawler \
  --url jdbc:cassandra://cassandra:9042/store \
  --user cassandra --password cassandra \
  --info-level minimum \
  --command list
```

After you have got this working, you can alter the command to show more details of the database. For example, you can run:

```sh
schemacrawler \
  --url jdbc:cassandra://cassandra:9042/store \
  --user cassandra --password cassandra \
  --info-level standard \
  --command schema
```

You can save the output with an additional `--output-file /share/schema.txt` argument, and the file will be created in your local directory. `schemacrawler help` will give you more information, as well as the [SchemaCrawler website](https://www.schemacrawler.com/). Now you are ready to connect to your own database. If you need help on how to construct the connection URL, take a look at [ing-bank/cassandra-jdbc-wrapper](https://github.com/ing-bank/cassandra-jdbc-wrapper).
Embedded Systems Weekly #136
Published: 2023-01-22 21:18:34

Welcome to issue 136 of our newsletter on embedded systems! I hope you'll like the selection that I have hand-picked for you. I wish you a happy weekend and happy reading.

**Happy reading!**

## Articles
[Lessons in Electric Circuits](https://bit.ly/3wiWXZc)
It's a free electrical engineering textbook covering electricity and electronics. It's in 6 volumes and to give you an overview the first 4 titles are: Direct Current (DC), Alternating Current (AC), Semiconductors and Digital Logic and Circuits.

[Learning Verilog and FPGA](https://bit.ly/3WnSTS5)
The author's story of how he first failed, then succeeded, at learning how an FPGA works and how to write Verilog code.

[Executable and Linkable Format 101 - Part 1 Sections and Segments](https://bit.ly/3Wnys85)
It's a great series of four articles that covers the ELF format's ins and outs. After part 1 on Sections and Segments, the next part is on [Symbols](https://bit.ly/3wklixX),
the following one is on [Relocations](https://bit.ly/3Wpq7AB), and the final one is on [Dynamic Linking](https://bit.ly/3whpNtc).

[Glitching the Olimex LPC-P1343](https://bit.ly/3wi1g7c)
This interesting article describes in detail how to set up a glitching attack. An attacker glitch attacks a component by making it run out of its nominal operating conditions. There is no solid defense against a motivated attacker.

## Tools / Libraries
[HexEd.it](https://bit.ly/3QYF6QV)
Browser-based Online and Offline Hex Editing
A full-featured HTML5/JavaScript-based hex editor running directly in your web browser.

## News / Business
[Emerging Startups 2023: Top Internet of Things Infrastructure Startups](https://bit.ly/3Wx9X8i)
If you are curious about the IoT startup ecosystem, this report is a good starting point to dig deeper.

## Jobs
[Nokia, Senior Software Development Engineer, New Providence, New Jersey, USA](https://jobs.embedsysweekly.com/job/6z9BR9LE/senior-software-development-engineer)
The pandemic has highlighted how important telecoms networks are to society. Nokia’s Network Infrastructure group is at the heart of a revolution to bring more and faster network capacity to people worldwide through our ambition, innovation, and technical expertise.

## Misc
[Grayscale on 1-bit LCDs](https://bit.ly/3WIpC53)
You'll probably be as surprised as I had been to discover what it is possible to render on a 1-bit LCD. I encourage you to watch the video linked at the top of the article. It gives a fairer view of the author's work.
C# - Codificando strings com base64
Tags: csharp, programming
Published: 2023-01-22 21:06:35

## Conceito
Strings encodadas com base64 permitem que você trabalhe com fluxos de ida e vinda de dados de uma forma segura, evitando que por exemplo caracteres reservados ao HTML (como & e ?) sejam enviados durante as requisições

## Criando as funções
Adicione em uma classe de gerenciamento interna (geralmente um Helper) os métodos a seguir para ter efetivamente um controle mais direto de base64 com as operações de encode/decode e checagem.

**Atenção** para o fato de que você deverá referenciar as namespaces System.Text e System.Convert em sua classe.

Para codificar

```
        public static string EncodeBase64(string value)
        {
            var keyBytes = Encoding.UTF8.GetBytes(value);
            return Convert.ToBase64String(keyBytes);
        }

```
Para decodificar

```
        public static string DecodeBase64(string value)
        {
            var base64EncodedBytes = System.Convert.FromBase64String(value);
            return Encoding.UTF8.GetString(base64EncodedBytes);
        }

```
E finalmente, para verificar se a string é de fato um base64 válido

```
        public static bool IsBase64(string value)
        {
            Span<byte> buffer = new Span<byte>(new byte[value.Length]);
            return Convert.TryFromBase64String(value, buffer, out int _);
        }
```

## Usando
Para utilizar basta chamar as funções, um exemplo no meu caso:

```
return Redirect("/usuario/login?redir=" + StringHelper.EncodeBase64("/arquivo/novo"));
```
Após ter codificado uma url de forma segura, na controller simplesmente usei:

```
if (string.IsNullOrEmpty(model.Redir) || !StringHelper.IsBase64(model.Redir))
            {
                return Redirect("/home");
            }
            else
            {
                    model.Redir = StringHelper.DecodeBase64(model.Redir);

                if (Uri.IsWellFormedUriString(model.Redir, UriKind.RelativeOrAbsolute))
                {
                    return Redirect(model.Redir);
                }
            }
```
My issues with ScriptKit
Published: 2023-01-22 21:01:20

I just discovered [Script Kit](https://www.scriptkit.com/), and at first glance, it's everything I've ever wanted from a shortcut utility. It has a bit of a learning curve to get used to the shortcuts and navigation, but once you get past them, it gets easier to move through the interface. I've been interested in something that combines javascript and the [Alfred utility](https://www.alfredapp.com/) for some time, and this does that. It allows you to easily create scripts that get a job done quickly and simply.

I appreciate the effort and innovation put into ScriptKit, but I have some concerns. The main issue is the paid sponsorship. I understand for-profit open-source projects, but some basic features like "Debugging Scripts" require a pro account. My main concern to committing to a tool like this is "vendor lock-in", ensuring that what I'm building and contributing to over the next couple months will not break and will be future-proof. The scripts written for ScriptKit will need to continue running within ScriptKit, as they contain global functions that break importing and typing, making migration to a different tool difficult in the future.

![Screenshot of "Debugging Scripts Requires Pro Account" from Scriptkit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zg09vk08m441jef5ahma.png)

Another issue is the complexity with Node.js and NPM, which Deno has solved. In Deno, scripts don't need a package.json and you can easily target a specific version for your dependencies within your files. With Script Kit, if your script requires a dependency, you have to first install it in order to use the script, which could lead to versioning issues in the future.

![gif of nothing happening when trying to create file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwquluoij40sagy5hlzj.gif)

Finally, I faced an issue creating a script where the UI would just go away instead of creating the file. Overall, I like what John Lindquist has done with ScriptKit and I think it's powerful, but there are some things that bother me. I think there's a balance for what features should be paid for in open-source projects and the tradeoff between using a system that has "vendor lock-in" and being obligated to pay $7 a month indefinitely.
Unleash the power of OpenAI GPT models with Alfred and Raycast extensions
Tags: opensource, openai, productivity, ai
Published: 2023-01-22 20:47:29

Hi Dev community! 

I wrote a little project that provides a convenient way to communicate with OpenAI completion models through tools like Alfred and Raycast.

It's not perfect, somewhat opinionated, but it works and is extensible!

There are still a few bits missing, like (1) reading prompts from files or selection, (2) support for Windows and Linux tools like Wox and Cerebro.

I'll be working on introducing these slowly, your help would be greatly appreciated :)

Also, I'm hoping for some feedback, this is one of my first OSS contributions.

GitHub repo - https://github.com/tech-branch/ask-gpt
Is There a Complete In-Depth Reading/Tutorials/Guide for Full-Stack Development?
Tags: help, javascript, stack, tutorial
Published: 2023-01-22 20:45:17

Are there any resources out there that really get in depth about a true full-stack for building web or mobile applications? I know about MERN/MEAN stack which includes: M - MongoDB - used to host your data E - Express - middleware to spin up a server R/A - React/Angular - used to build the front-end through components (Made up of HTML, CSS, JS) N - Node - I think of it as an easy way to keep track of and download dependencies instead of going through one by one. It makes it easier for multiple people to use and start working locally. An index in a ways to your project.

However, this doesn't really cover anything like testing, CI/CD, Docker, Kubernetes, pipelines(yml), Schemas, version control hosting(GitHub/GitLab/Bitbucket), git vs yarn, etc. Maybe this is what DevOps is?

I am sure I am missing a few things, but is there anything like that out there, or do I just have to piece it together as I do my own research?

It would also be good to know alternatives, like git vs yarn, MongoDb vs a traditional database like MySQL, using client-side JS vs a true back-end language like C# or Java.

I have experience in the front-end; HTML, CSS, JS; but I am lacking in the back-end knowledge and am curious to learn more. I've even gotten things working locally on a C# project with MySQL, but have no idea how to move forward and host it in the cloud to make it truly a live application.

Anything will help moving forward, even main keywords to look for.
OpenBSD メンテナンス: OS 再インストール
Tags: openbsd, maintenance, install, upgrade
Published: 2023-01-22 20:30:00

## はじめに

[OpenBSD](https://www.openbsd.org/) の公式ドキュメントに [次のように書かれています](https://www.openbsd.org/faq/faq4.html#bsd.rd):

> If you have a running OpenBSD system, bsd.rd is all you need to reinstall or upgrade to a newer version.

(私訳: 稼働中の OpenBSD システムに対しては、`bsd.rd` を用いるだけで、再インストールあるいは新しいバージョンへのアップグレードを行うことができます。)

この記事では上記の `bsd.rd` すなわち RAM ディスク・カーネルを使って、どのように OS の再インストールを開始するのかを示します。
外部メディアは要りません。ただしインストール時、"Location of sets?" で `cdrom disk http nfs` いずれかからファイルセットを取得する必要はあります。

## 本旨

マシンを再起動します。`boot> ` が表示されたら `/bsd.rd` (あるいは単に `bsd.rd`) を入力します。なお何も入力しない状態で少し経つと、ブート・プロセスは自動的に次へ進みます。お気を付けください。

![openbsd 起動中](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr87tjbnu93al2rvlr74.png)

これだけです !! インストーラーが起動されるでしょう。

![openbsd ram ディスク・カーネル インストーラー](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmz89dyuqf9y2a3kzmbv.png)

## おわりに

一度 OpenBSD をインストールすると、`bsd.rd` は手もとにあります。
それを使うと、マシンの再インストールができます。さらに事前に Shell を使えば [フルディスク暗号化](https://obsd.solutions/ja/blog/2023/01/03/openbsd-full-disk-encryption-on-virtualbox/index.html) を施すこともできます。
Basic CSS debugging tip
Tags: webdev, css
Published: 2023-01-22 20:01:25

When creating a web page and there is are issues with the layout it can in many cases difficult to figure out.

Add the following to your project `debugger.css`

```css
* {
    outline: 1px solid red;
}

    *:hover {
        outline: 2px solid blue;
    }
```

Add a link to the page needing attention e.g.

```html
<link rel="stylesheet" href="css/debugger.css" />
```

Render the page and we get something like this.


![web page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/reupxslqvhfxg43dkvpm.png)

For ASP.NET we can conditionally add the style sheet in _Layout.cshtml

```html
<environment names="development">
    <link rel="stylesheet" href="css/debugger.css"/>
</environment>
```

## Even better

Rather than adding/removing debugger.css manually this can be done with JavaScript.

Add the following JavaScript file, in this case under lib/css

```javascript
var $debugHelper = $debugHelper || {};
$debugHelper = function () {

    /*
     * Add/remove debugger.css to the current page
     */

    var href = "lib/debugger.css";
    var addCss = function () {
        if (isCssLoaded(href) === true) {
            return;
        }
        var head = document.head;
        var link = document.createElement("link");

        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = href;

        head.appendChild(link);
    };

    var removeCss = function () {

        if (isCssLoaded('debugger.css')) {
            document.querySelector(`link[href$="${href}"]`).remove();
        }
        
    };

    var toggle = function() {
        if (isCssLoaded(href) === true) {
            removeCss();
        } else {
            addCss();
        }
    }

    var isCssLoaded = function () {

        for (var index = 0, count = document.styleSheets.length; index < count; index++) {
            var sheet = document.styleSheets[index];

            if (!sheet.href) {
                continue;
            }

            if (sheet.href.includes(href)) {
                return true;
            }

        }

        return false;
    }

    return {
        addCss: addCss,
        removeCss: removeCss,
        isCSSLinkLoaded: isCssLoaded,
        toggle: toggle
    };
}();
```

In a HTML file reference the file above.

```html
<script src="lib/debugHelper.js"></script>
```

In the same file add a script section with the following code. Show the page, press <kbd>ALT</kbd> + <kbd>1</kbd> to add/remove the stylesheet file.

```javascript
<script>

	/* 
     * Karen code
	 * ALT+1 toggles adding/removing debugger.css
	 */
	document.addEventListener('keydown', function (event) {

		if (event.key === '1' && event.altKey) {
			$debugHelper.toggle();
		}

	});

</script>
```

### Source code

See the following [GitHub Gist](https://gist.github.com/karenpayneoregon/e033fdd61299bb8d8749f06dbbd37617).


![presenting page with css debugging](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqflsb1a53gsvfjwkas5.jpg)


## See also

[Debugging CSS](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Debugging_CSS)
Linux: RHEL and CentOS differences
Tags: linux, centos, rhel, tutorial
Published: 2023-01-22 19:59:54

*What's the difference between RHEL and CentOS? Why does a big company choose RHEL over CentOS?*

CentOS and Red Hat Enterprise Linux (RHEL) are two of the most popular Linux distributions in the enterprise world, but they have some key differences. Both are based on the same codebase and have similar features, but there are some significant distinctions between the two that enhance them suited for different use cases.

One of the main differences between the two is that **CentOS is a community-supported distribution, while RHEL is a commercially supported distribution**. This means that Red Hat provides official support and updates for RHEL, while support for CentOS comes from its community of users. This can be a significant consideration for organizations that require a high level of support and reliability.

Another key difference between the two is that **Red Hat provides long-term support for specific versions of RHEL**. This means that organizations can use a specific version of the distribution for several years without having to worry about it becoming obsolete. This can be important for organizations that have many systems running a specific version of the operating system and do not want to have to upgrade them all at once.

**Red Hat also offers additional services and tools, such as training, consulting, and certification, which can help organizations optimize their use of RHEL**. This can be particularly useful for organizations that are new to Linux or that want to take full advantage of all the features that the operating system has to offer.

Finally, for regulated industries, **Red Hat offers certifications for compliance with various regulations** such as PCI-DSS, HIPAA, SOC2, and more. Additionally, **Red Hat provides a set of security tools** like SELinux, AppArmor, and others to enhance the security of the system.

Overall, while both CentOS and RHEL have a lot to offer, the choice between the two will depend on an organization's specific needs. For organizations that require a high level of support and reliability, RHEL may be the better choice. However, for organizations that are comfortable with a community-supported distribution and do not require long-term support, CentOS may be a better fit.