teleren/devto huggingface dataset:
Learn almost anything by making projects productively
Tags: productivity, programming, sideprojects
Published: 2021-06-06 21:27:33

I am a person who cannot learn anything without actually using it, just reading about something just flat-out bores me. If you are someone who likes learning by doing then I hope this post helps you out in your next journey of learning.

### Some Basic Rules
_lets set some basic rules for ourselves so that we do things properly_

1. **Set simple goals:** The death of many projects is being way too ambitious. Don't let this turn into an actual product the only outcome that should be expected is experience and knowledge

1. **Scale up your goals Gradually:** Learning to write code in a programming language is one thing but learning to write *good* code is something else. It can only be done when your project has stood the test of time and modification. Let's discuss it with my philosophy

### My Philosophy
Whenever a beginner asks me "how should I learn Xyz language/framework" or it is me asking myself. I say, in case it's a Backend Library/Framework, then make a simple **URL shortener.**

_" but that's such a vanilla project"_ 

yes, it is but at the same time, it can teach you a lot. For example, you want to learn Nest.js you make a basic rest API with a DB of your choice.

Short, concise, and sweet! 

You learn the basic ins and outs of what you are dealing with.
Then we add functionality to it. What if we want to have users and they can access their shortened link from anywhere they want then? now we have what we can say as the 1st hurdle for our codebase! _addition of features_ did you write code that's easy to be enhanced? or is it spaghetti code that needs to be re-written we learn how to structure our code better as in development there is never a FINAL product, new features can always be added.

Then we add more things to it like adding analytics seeing the number of hits, the Geography of users accessing it, etc, we can further go in increasing the features. Until you have a good grasp on what you are gonna learn with that you also have a fairly complex project to show off with a codebase that has been written in a really good way.

### Conclusion
Well, this is how I like to do things, start simple and build it up from there. This is my first post here, hope you like it! I am all ears for feedback
How to wrap a Prisma method and reuse types
Tags: typescript, node, prisma
Published: 2021-06-06 08:44:05

[Prisma](Prisma.io) is an easy to use ORM with really useful Typescript types that change the result type of a query based on the options you pass in.

While building out an application, you'll undoubtedly run into a situation where you want to wrap an existing Prisma method with custom logic. You may decide to pass-through the types so that the caller can decide if they want to extend query.

If you're using Prisma's query arguments, you'll also expect to get Prisma's return types.

This is not as easy as it sounds, as simply passing the data (or even passing a generic backed value) does not work as intended.

You may start by trying something like this. Wrapping the todo `findMany` call with a function that accepts Prisma query args, but modifies the query to do something specific.

```typescript
// DOES NOT WORK
  specialFindMany<T extends Prisma.TodoFindManyArgs>(args?:T){
    return prisma.todo.findMany({
      ...args,
      where:{
        ...args?.where
        isSpecial: true
      }
    })
  }
```

This will produce type errors.

## Discovery
As with anything in Typescript, if you dig into the types, you can get at what a function actually expects.

Looking at the types for `todo.findMany()` as of Prisma `2.24.0` you'll find something that looks like this:

```typescript
findMany<T extends TodoFindManyArgs>(
      args?: SelectSubset<T, TodoFindManyArgs>
    ): CheckSelect<T, PrismaPromise<Array<Todo>>, PrismaPromise<Array<TodoGetPayload<T>>>>
```

You can see that they're pulling the type from `SelectSubset`s generics.

## Solution

If you copy this type into both your method's declaration as well as the `prisma.finyMany` generic, you'll get a working typed passthrough.

```typescript
   async specialFindMany<T extends Prisma.TodoFindManyArgs>(
    args?: Prisma.SelectSubset<T, Prisma.TodoFindManyArgs>,
  ) ){
    // Other custom logic
    
    const result = await prisma.todo.findMany<
    Prisma.SelectSubset<T, Prisma.SearchFindManyArgs>>(
      {
      ...args!,
      where:{
        ...args?.where
        isSpecial: true
      }
    })
    
    // Other custom logic
    
    return result
  }
```

Without passing in the generic, the types will still fail to pass through (at least in my testing).

Since args is optional, the types will complain about forcing an object through. There may be a better solution to this, but I simply `!` forced the args type to exist.

## Conclusion
This feels pretty cumbersome, and I'd love to see some more flexible typing in Prisma, but it gets the job done for wrapping database calls.

This solution unfortunately doesn't cover extending the types that go into the Prisma call, so including `include` or `select` will not result in proper output types.

If you have a better solution, please let me know in the comments!!!
Bash script to create/delete Apache Virtual Host automatically
Tags: bash, cli, apache, virtualhost
Published: 2021-06-06 20:31:19

## [update 06/01/2022]

The new script is compatible with Debian 11 or Ubuntu 20.
Also you can choose custom file directory or custom server aliases or **install automatically** **Wordpress** or **Laravel** application.
[See demo here](https://github.com/alfiosalanitri/lamp-virtual-host/blob/main/demo-usage.gif)

---

With this bash script you can add/delete an apache virtual host to/from your lamp stack. You can also to add a database and choose one of yours fast-cgi php module if installed.

If you choose development environment option, the script will add the ssl certificate with mkcert package if installed on your machine. If you choose production environment, the script will add the ssl certificate with certbot and let's encrypt. Note that this last step requires the dns for domain and aliases setted to your server ip address.

## Prerequisites
- A debian linux distribution like Ubuntu or Debian
- Stack Lamp: Apache, Mysql (optional), Php
- php-fpm module (optional)
- [mkcert](https://github.com/FiloSottile/mkcert) or [certbot](https://certbot.eff.org/) for SSL certificate (optional)

## Installation
- [download this script](https://github.com/alfiosalanitri/lamp-virtual-host)
- open your CLI and type:
```
sudo mv lamp_virtual_host /usr/local/bin
sudo chmod +x /usr/local/bin/lamp_virtual_host
```

## Usage
```
cd /path/to/directory/websites/
lamp_virtual_host www.example.local/ lamp_virtual_host /path/to/example.com/ -a www.example.com,shop.example.com
```
and follow instructions.
Vscode tips & extension
Published: 2021-06-06 20:26:31

<sub>Photo by <a href="https://unsplash.com/@markfb">Mark Fletcher-Brown</a> on <a href="https://unsplash.com/s/photos/writing">Unsplash</a></sub>

This post is about some visual studio code extension, and tips i found.

# VS Code
## Commands

Here are some command i used:

F1 : Open command
Ctrl + P : Find File
Ctrl + T : Find method
Ctrl+⇧+P: : Toggle Screencast Mode (to show command)
Shit+Alt+F : Format Document
Ctrl+ù : Open Terminal
Shift + F12 : Find References
[vscode cheatsheet](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)

## Extensions

Here is a snippet to list all installed extensions:

```powershell
code --list-extensions | % { "code --install-extension $_" }
```

## Extension pack list [Docs authoring]

[Extension recommended by Microsoft to write docs](https://docs.microsoft.com/en-us/contribute/how-to-write-docs-auth-pack)

### CodeTour

[CodeTour](https://github.com/microsoft/codetour) allow you to add 
a tour with Markdown in your files.

#### Make link to send command to terminal


Write in your codetour
```markdown
>> ls
```
and it will be rendered as a link that will be executed in your terminal.

#### Insert diagram 

Write 
```markdown
![text](relative link from the repository to your diagram)

```
to refer to a svg file. You can couple this one with [draw.io extension](https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio).

#### Examples

[Microsoft Graph React Repo](https://github.com/microsoftgraph/mgt-react-codetour)

### Didact
[Didact](https://github.com/redhat-developer/vscode-didact/wiki/Welcome-to-Didact%21) is a tool to interact and modify vscode itself.

[The tutorial](https://github.com/redhat-developer/vscode-didact#writing-your-first-didact-tutorial) is easy to follow.

You can create link that can:
- create named terminal
- send command to named terminal
- interact with vscode
etc ..


[This page](https://github.com/redhat-developer/vscode-didact/blob/master/examples/terminal.example.didact.md) is important to understand how to create lonk that will be interpreted as command using didact.


Hope this helps !
Voici comment traduire du text à l'aide de Google Translate en 3 lignes de code seulement !!!
Published: 2021-06-06 20:23:48

---
title: Voici comment traduire du text à l'aide de Google Translate en 3 lignes de code seulement !!!
published: true
description: 
tags: 
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/83ga7st8206e1vc2x2en.jpg
---
Si vous désirez plus de contenu francophone comme celui-ci, cliquer <strong>Follow<string> ou <a href="https://twitter.com/EricLeCodeur" class="twitter-follow-button">suivez-moi sur Twitter</a>
<hr>

### Truc et Astuce Python:
Traduire du text à l'aide de Google Translate en 3 lignes de code:

```python
# pip3 install googletrans==3.1.0a0

from googletrans import Translator

translator = Translator()
print(translator.translate("Bonjour, ceci est un application web qui permet de truduire un text.", src="fr", dest="en").text)
```

Consulter la librairie GoogleTrans pour tous les détails: https://github.com/ssut/py-googletrans
Scrawl-canvas Javascript library for the HTML5 canvas element - v8.5.3 released into the wild!
Tags: javascript, html, canvas
Published: 2021-06-06 20:16:18



The latest update of the [Scrawl-canvas]() Javascript library for the HTML5 canvas element has been released into the wild!

New shiny includes a superfast gaussian blur filter, fun with line-based spirals, and stuff to make imaging TensorFlow models a bit easier.
Customizing Bootstrap 5 Color Theme In React JS "create-react-app"
Tags: react, bootstrap, scss, bootstrap5
Published: 2021-06-06 20:11:46

![bootstap 5 color theme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yctov28ajeuwfmkpgq19.png)
 
Sometimes you might need to tweak the visual styles of Bootstrap (or equivalent package). This time, we talk about customizing theme colors.

>Note:
- Assuming that *SCSS* installed. If not, refer to [this](https://dev.to/ijash/adding-sass-to-create-react-app-433i) post.
- This post relevant only in *Bootstrap ^5.0.0-beta3*

## Bootstrap

To install [bootstrap](https://getbootstrap.com/docs/5.0/getting-started/download/#npm), use
```
npm install bootstrap@next
```
## Using a Custom Theme

> Note:
- this feature is available with `react-scripts@2.0.0` and higher.
- Package `node-sass` are deprecated. See [node-sass npm page](https://www.npmjs.com/package/node-sass) and [sass blog](https://sass-lang.com/blog/libsass-is-deprecated)

As of `react-scripts@2.0.0` you can import `.scss` files. This makes it possible to use a package's built-in Sass variables for global style preferences.

To customize Bootstrap, create a file called `src/custom.scss` (or similar) and import the Bootstrap source stylesheet. Add any overrides _before_ the imported file(s). You can reference [Bootstrap's documentation](https://getbootstrap.com/docs/4.6/getting-started/theming/#variable-defaults) for the names of the available variables.

```scss
// Override default variables before the import
// you can open the bootstrap.scss module and check any available variables.
$primary: #362ec4;
$secondary: #8f5325;
$success: #3e8d63;
$info: #7854e4;
$warning: #b8c924;
$danger: #d62518;
$light: #f8f9fa;
$dark: #343a40;

//custom color to be mapped
$accent : #da6d25;

// this is used to map colors. change accordingly.
$theme-colors: (
  primary: $primary,
  secondary: $secondary,
  success: $success,
  info: $info,
  warning: $warning,
  danger: $danger,
  light: $light,
  dark: $dark,
// add any additional color below
  accent: $accent,
// now bg-accent,btn-accent,etc.. can be called
);

// Import Bootstrap and its default variables
@import '~bootstrap/scss/bootstrap.scss';
```
Actually, if you get the idea, you can customize many things such as fonts, border-radius, shadows, etc. Just look for the variables.


>
extra tags:
Customizing Bootstrap 5 Color react.
Tweaking Bootstrap 5 Color react.
Modifying Bootstrap 5 Color react.
Changing Bootstrap 5 Color react.
Altering Bootstrap 5 Color react.
create-react-app
reactjs
react
react js
react.js
bootstrap5
color pallete
Use a Raspberry Pi as a print server
Tags: linux, raspberrypi
Published: 2021-06-06 20:09:51

---
title: Use a Raspberry Pi as a print server
published: true
tags: linux,raspberrypi
canonical_url: https://unixorn.github.io/post/cupsd-setup/
---

I have an old HP 4050N. For a variety of reasons, I want to have it behind a print server instead of having our laptops print directly to it. Here's how I set that up.

## Prerequisites

- A Raspberry Pi (or honestly any Linux box) running `docker`. I like the Raspberry Pi and Odroid HC2 for this sort of thing because they have very low power consumption.
- A printer that is supported by [CUPS](https://www.cups.org/)

## Setup

There are several docker images out there you can use, I made one (the source is on github at [unixorn/docker-cupsd](https://github.com/unixorn/docker-cupsd)) because I wanted one that was multi-architecture - mine has AMD64, ARM7 and ARM64 all baked into the same image so you don't have to change the image label based on what system you're running it on. It works fine on Raspberry Pi, Odroids and Intel servers.

The [unixorn/cupsd](https://hub.docker.com/repository/docker/unixorn/cupsd) image is a bit on the large side because I crammed a lot of printer drivers into it, you may want to look for docker images that only support single printer families.

We're going to store `printers.conf` in a directory outside the container so that we don't lose our printer configuration every time we upgrade our container.

I run the `cupsd` server on an Odroid HC2 because I have `/var/lib/docker` on the 2TB drive attached to it. I could have put it on one of the Raspberry Pis in my cluster, but didn't want it spooling print jobs and causing excessive wear on a rPi's microSD card.

1. Make a directory to store your printer configuration. We'll use `/docker/cupsd/etc`
2. `export CUPSD_DIR='/docker/cupsd/etc'`
3. `touch $CUPSD_DIR/printers.conf`
4. Run the `cupsd` server with

```bash
sudo docker run -d --restart unless-stopped \
  -p 631:631 \
  --privileged \
  -v /var/run/dbus:/var/run/dbus \
  -v /dev/bus/usb:/dev/bus/usb \
  -v "$CUPSD_DIR/printers.conf:/etc/cups/printers.conf" \
  unixorn/cupsd
```

You can now connect to `http://SERVER:631` and add printers using the web UI.

When adding the printers to your Mac, select Internet Printing Protocol and put in the IP or DNS name of your print server machine.

The queues are `printers/printername`, not `printername`.
Launching DevPolls, a platform to take polls for developers
Published: 2021-06-06 20:08:57

---
title: Launching DevPolls, a platform to take polls for developers
published: true
description: 
tags: 
//cover_image: https://direct_url_to_image.jpg
---

I had always wanted to know opinions of developers while selecting a library or platform. 
Yes, you can google and read blogs on their pros and cons, but it takes time. 
Despite being on the field for 10+ years, I despise reading long documentations/blogs :disappointed:


So, I created a platform [DevPolls.app](https://DevPolls.app) to create/vote short fun polls only for developers. 
It is still in preliminary phase. 
Any feature suggestions and review are welcome.
Setup a new React Application
Tags: react, tutorial, beginners, webdev
Published: 2021-06-06 19:48:00

React is one of the most popular JavaScript libraries for creating interactive user interfaces.
It makes it easy to integrate your HTML with JavaScript by using JSX. 

It is extraordinarily easy to get started using React with minimal knowledge of web-pack, or babble by using create react app. Setting up quickly allows you to get straight into learning to develop react applications, and exploring the concept of the Virtual DOM without having to worry about setting up a bunch of building tools and dependencies.

To Get started with using React, you should first make sure that you have an updated version of node on your system. 

You can check your node version by using the command node -v in your terminal.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3xfy2wwdzik35u0bfsl.png)

Once you are sure that you have a properly updated version of node, you can get started with creating your React application. 

Next, you can create a new directory, then open your terminal and cd into that directory. 

After you have entered the directory that you are going to  create your application in, you can enter the command  npx create-react-app demo

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdi1rn7mfvdixtskqy0v.png)

This will create a new directory inside of your project directory with the name demo, the demo directory contains your newly created React project. 

It is useful to create the directory inside of the project directory if you would like to set up a back-end, or service directory in your project. 


If you just want to create the React project directly in the directory that you created, you have to make sure that the directory has all lowercase letters and no spaces(Failure to do this will result in an error when trying to create the react project). You then enter the command npx create-react-app.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7srw9jrdwcaf36ku51sy.png)

The ‘.’ allows the project to be created in the current directory. 

All that is left is to start the project. 
Cd into the new project with your terminal, and enter the command npm start

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1rayn2jfyuzsfcci7a1.png)
The react project will start and open up in your current browser. 


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dce0tg902pyurrgzyedq.JPG)

Now you can get to learning more about developing react applications.
Running C++17 on Mac M1
Tags: cpp, codenewbie, programming, computerscience
Published: 2021-06-06 19:41:32


## Having problems using `STL` functions_ of `C++14` or `C++17`?

Wrote a piece of code in `C++` and encountered that `STL` functions are not supported by the default clang compiler on Mac? 
For example, this piece of code:
```C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=gcd(2,3);
    cout<<n;
    return 0;
}
```
Compiling the code with `gnu` or `clang` compilers and getting this error?
```bash
@User-MacBook-Air % clang++ test.cpp
test.cpp:5:11: error: use of undeclared identifier 'gcd'
    int n=gcd(2,3);
          ^
1 error generated.
```
## So what happened here? 
Let's check our `c++` version.

When you run `clang --version`, you will get something like this and would be pretty confused even if your `clang/gnu` is up-to-date but you still can't figure out your `c++` version:
```bash
   Apple clang version 12.0.5 (clang-1205.0.22.9)
   Target: arm64-apple-darwin20.4.0
   Thread model: posix
   InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
### This happens because
The gcd() function is a STL function from c++14 and above.
> *But by default, Clang builds `C++` code according to the `C++98` standard, with many `C++11` features accepted as extensions.*

### What to do?
After going through many websites and resources, I was finally able to compile the correct methods to use c++17 on mac.
So in order to use STL functions of `c++17` or `c++14` or upper versions, you need to specify the version of C++ to be used which goes like this:

```bash
 -std=c++{version} {filename}.cpp
```

appending the c++ version to -std option.

### Example:

 - For `clang` compilers:

	```bash

	 clang++ --std=c++17 {filename}.cpp

	```
<br>
 - For `gnu` compilers:

	```bash

	 g++ --std=gnu++17 {filename}.cpp

	```
<br>
 - My **Personal choice**:

	```bash

	 c++ --std=gnu++17 {filename}.cpp

	```
___ 
And that's it, you're done!

Also free feel to share other ways in the comments!!!

![pride](https://res.cloudinary.com/practicaldev/image/fetch/s--T2Dqk-Zz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/Ga1UmWZ9jdYOc/giphy.gif)
Things to know before using public Wi-Fi
Tags: security, awareness
Published: 2021-06-06 19:39:46

Accessing wifi is not a problem while you are at home - it’s secure, easy to connect and no strangers are using your home network. However, when you are outside, using public Wi-Fi will give you a nightmare if you aren't aware of the risk of security issues. So, if you are considering whether to connect to the public Wi-Fi network at the shopping mall, the airport, etc. beware of the potential risk to your device because hackers love public Wi-Fi!
Although it’s risky to use Wi-Fi in public, I’m going to explain how to safely use public Wi-Fi services. 

##Use VPN
The most effective trick to staying safe on public Wi-Fi is to use a VPN on your devices. Although virtual private networks are not infallible, they can protect your privacy. They encrypt data that passes through the network and connect your device to a secure server, making it harder for the hackers on the same network or anyone who controls the network to see what you're doing. So, using a VPN will secure your information from other users of the same connection.

##Always HTTPS
When the site you're visiting uses an unencrypted HTTP connection, most of the browsers let you know with the "Not Secure" label beside the URL. Beware of that warning especially if you are connected to public Wi-Fi. When you browse over HTTPS, people on the same Wi-Fi network can’t sniff the data that travels between you and the server of the website you're connecting to. If it’s over HTTP, it’s gonna be very easy for them to track what you're surfing. So, always verify that the website you surf uses HTTPS.

##Never give away too much info
It’s better not to access personal bank accounts, or give sensitive personal data (your address, phone number or email, etc.) on public Wi-Fi. If you have no choice, you should consider using an alternative email address or phone number that isn't your primary one. And also, it’s not recommended to do online shopping over public Wi-Fi. Of course, shopping doesn’t seem like a big deal, but making purchases online requires personal information - bank account or credit card numbers. 

##Don’t let your guard down
Never leave your device unattended in public. Even if you’re on a secure network or unsecured network, that won’t stop someone from taking your device or sneaking a peek at your device. 
Always keep your device near you.

If you follow the steps mentioned above, you will have more chances of staying out of trouble while you're using public Wi-Fi. However, Always keep in mind that no public Wi-Fi network is secure and you should always use public Wi-Fi with caution. 
**And Remember - any device could be at risk too.**