teleren/devto huggingface dataset:
Django Plausible Proxy
Tags: django, analytics, python, webdev
Published: 2022-04-27 10:34:15

I released [Django Plausible Proxy](https://github.com/imankulov/django-plausible-proxy/), a Django application to **proxy requests** and **send server-side events** to [Plausible Analytics](https://plausible.io/).

Plausible is a lightweight and open-source web analytics platform, a privacy-friendly alternative to Google Analytics. I started using it for Django side projects about a month ago and loved its minimalistic interface and "exactly what I need" type of reports.

Initially, the integration code lived inside the project, but as it grew in functionality, I extracted it in a separate package that is available on [PyPI](https://pypi.org/project/django-plausible-proxy/) and [GitHub](https://github.com/imankulov/django-plausible-proxy/).

**Proxying**

Proxying allows a project owner concerned about missing data to see a complete picture. See [Adblockers and using a proxy for analytics](https://plausible.io/docs/proxy/introduction) for the detailed outline of the problem and solution.

When installed and configured in `settings.py` and `urls.py`, the app proxies the HTTP requests as such:

```
https://<yourdomain.com>/js/script.js -> https://plausible.io/js/script.js
https://<yourdomain.com>/api/event    -> https://plausible.io/api/event
```

**Server-side events**

Sending events from Python code lets you keep track of events that can't be recorded otherwise, such as API requests. In the code, it looks like this:

```python
from plausible_proxy import send_custom_event
...
send_custom_event(request, name="Register", props={"plan": "Premium"})
```
object oriented programming in Javascript (part 4)
Tags: javascript, programming, tutorial, beginners
Published: 2022-04-27 10:30:33

by now you should be familiar with constructor functions and prototypes and you understand how they work, now it is time to learn about ES6 classes
## ES6 classes
classes were added after the release of ES6 to javascript and it's a new way to write blueprints for objects including props and methods
### Example
let's recreate the Customer bluepring but now we will use ES6 classes instead
```javascript
class Customer {
  constructor(name, email, password, settings, cart) {
    this.name = name;
    this.email = email;
    this.password = password;
    this.settings = settings;
    this.cart = cart;
  }
  setSettings(newSettings) {
    this.settings = newSettings;
  }
  orderFood(food) {
    console.log(`ordering ${food}`);
  }
}

const customer = new Customer("name", "email", "password", {}, [])
c.orderFood("Pizza"); // ordering pizza
```

### Explanation
when we create a new instance of this class, the code inside the constructor method will run and in this case i'm adding the taken props to the **this** keyword to build the object.
then all the methods declared under the constructor will be automatically added to the prototype so we don't have to worry about memory loss or attaching them to the prototype

### Truth about ES6 classes
in reality ES6 classes are just fancy syntax to declare constructor functions and under the hood will be converted to
regular constructor functions
Django handle 404 Page not found
Published: 2022-04-27 10:30:19

views.py

```python
def page_not_found_view(request, exception):
    return render(request, 'app/404.html', status=404)
```

urls.py in main project folder

``` python
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('users.urls')),
    path('',include('app.urls')),
    
]

handler404 = "yournameapp.views.page_not_found_view"

```
settings.py

```python
import os

DEBUG = False

TEMPLATES = [
    {
        'BACKEND': 
        'DIRS': [os.path.join(BASE_DIR, 'templates')],

            ],
        },
    },
]

```
Using JS Functions Properties in Real Life
Tags: javascript, functions
Published: 2022-04-27 10:28:15


 In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called.

Consider the following logging function below...

```js
function log(message, level) {
  console.log(message);
}

log('just logging...', 1) // "just logging..."
```

You can use function property to avoid global variables for conditional checking

```js
function log(message, level) {
  if (log.backup) {
    console.log(message);
  }
  console.log(message);
}

//set function property
log.backup = true;

log('backing it up...', 1) // "backing it up..."
```
Creating a bank with python
Tags: oop, python, programming, discuss
Published: 2022-04-27 10:22:54

A simple object-oriented programming project I embarked on given I had some issues understanding it at first.
Here's the code.
I created a bank class and the subunits inside it such as operations that can be performed such as credit, debit and loan. 

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0i67klzl13hdwbc1xih.png)
You can check out the code in my GitHub link 
https://github.com/Just-Mike4/Python-bank/blob/e4f528f3cf1a3083d414729f9b52f609cfdf1932/OOPBank(main).py
Read, like, comment, share, and any piece of advice on where to learn more and what to add will be appreciated.
CSS shorthand properties
Tags: javascript, beginners, css, webdev
Published: 2022-04-27 10:18:05

CSS shorthand properties helps you to write clean CSS code and saves your times and reduce number of lines in your code and indirectly your code looks like pro developer. Here I sharing shorthand properties related list, background image and colors and explore more and play around them.

### Margin & Padding
Normal Code


```ts
#div {
margin-top: 0;
margin-right: 5px;
margin-bottom: 10px;
margin-left: 15px;
(auto, 0, px, pt, em or %)
}

```

shorthand properties

```ts
#div {
margin:0 5px 10px 15px;
(top right bottom left)
}

```
### Border
Normal Code
```ts
#div {
border-width: 5px;
(thin, thick, medium or set value) (default = medium)
border-style: dotted;
(solid, dashed, dotted, double, etc) (default = none)
border-color: blue;
(named, hex, rgb or 0-255) (default = value of elements/
elements parent color property)
}
```
shorthand properties
```ts
#div {
border:5px dotted blue;
}
```
##Background
Normal Code
```ts
#div {
background-color: #CCCCCC;
(named, hex, rgb or 0-255) (default = transparent)
background-image: url(images/bg.gif);
(url or none) (default = none)
background-repeat: no-repeat;
(repeat, repeat-x, repeat-y or no-repeat) (default =
repeat)
background-attachment: scroll;
(fixed or scroll) (default = scroll)
background-position: top left;
(top, right, left, bottom or center) (default = 0% 0%)
}
```
shorthand properties
```ts
#div {
background:#CCC url(images/bg.gif) no-repeat 0 0;
}
```

## List
Normal Code
```ts
#div {
list-style-image: url(images/bullet.gif);
(url or none) (default = none)
list-style-position: inside;
(inside or outside) (default = outside)
list-style-type: square;
(circle, disc, square, etc) (default = disc)
}
```
shorthand properties
```ts
#div {
list-style:square inside url(images/bullet.gif);
}
```

This is how you can write your code with shorthand properties, you can also write more or explore the other shorthand properties if you want. This are the basic properties which I shared here....!!

Thank you for Reading!

Hey, I'm Ganesh 🖐
I write daily article on web development and sharing valuable resources which might helps you as developer or beginner. 

for more content
- follow me ( 
[Ganesh_Patil](https://dev.to/ganeshpatil386386)
 )
- You can also connect with me [twitter](https://twitter.com/PatilGanesh1010) to get more content related to web development 

Thank you for the support friends!
Python: Introduction to DataClasses
Tags: python, oop, webdev, programming
Published: 2022-04-27 10:17:09

## Introduction
This article will be explaining the concept of data class introduced in python 3.7+.My assumption are you are conversant with python in particular object-oriented Programming. However, I will briefly explain the concept and redirect you to more resources.![see PEP 557](https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep557)

### Classes Recap: 
- What is a class ?

it can simply be defined as an object constructor or a blueprint of creating an object.
#### Example
```python
class Student:
  def __init__(self, name, age):
    self.name = name
    self.age = age
```
line 1: class definition with the name of the object (Student). 
line 2 to 4: Object constructor.The __init__() function is called automatically every time the class is being used to create a new object.

### NB:
The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class.It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class.

### DataClasses
The new dataclass() decorator provides a way to declare data classes. A data class describes its attributes using class variable annotations. Its constructor and other magic methods, such as __repr__(), __eq__(), and __hash__() are generated 
automatically.

Example 1:

Consider the example of Student object created above, but now modified.
```python
from dataclasses import dataclass
@dataclass
class Student:
  name: str
  age: int
  def greet_student(self) -> str:
    return f'Hello {self.name}, you are {self.age} years old'
p = Student('Tito',16)
print(p.greet_student())
```
```bash
Output:
Hello Tito, you are 16 years old
```
Example 2:
```python
from dataclasses import dataclass

@dataclass
class InventoryItem:
    """Class for keeping track of an item in inventory."""
    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand
```
From the above example, you will notice we have omitted the __init__() constructor , data class will added it automatically. Data class will help you create object easily and add more configurations to your objects.Now that you have a basic understanding of data classes in python. In our next episode I will be diving deep into data classes concepts. 
Follow for more content.

![Buy Me a coffee](https://www.buymeacoffee.com/titusnjugul)
CherryBomb: So what's new??
Tags: cherrybomb, api, security, blst
Published: 2022-04-27 10:13:56

We're pleased to announce the release of the Cherrybomb CLI-0.6, which includes several highly requested features! 
Please star us on our Github repo:[https://github.com/blst-security/cherrybomb](https://github.com/blst-security/cherrybomb) .

![😂😂😂](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adxt3ski3a519wlaul2h.jpeg)

The Cherrybomb CLI is a devops and appsecop tool.I have already talk about it in a previous [article](https://dev.to/nathan20/is-rust-irrelevant-4kg5).
It turns your JSON or YAML OpenAPI specification file into a human-readable and accessible file while simultaneously executing a number of passive tests to verify it adheres to best practices and contains nothing that might constitute a security issue.
In this new release we added some features the first I want to talk is ep-table.
This feature is extremely handy since it generates a table of all the endpoints in the specification and provide useful informations.

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

This makes it simple to see what data is accessible and where it is located. 
Then  param-table command has also been divided into its own command, with more configuration options.
The command to run param-table:
`cherrybomb param-table --file <PATH> --name <SINGLE PARAM NAME(OPTIONAL)>`


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

We have also deprecated the decider module, fixed some minor bugs.

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

For more information you can check our github [page](https://github.com/blst-security/cherrybomb), you are always welcome to contribute (check this [guide](https://github.com/blst-security/cherrybomb/blob/main/CONTRIBUTING.md)).
To reach out us go to our discord server: [https://discord.gg/WdHhv4DqwU](https://discord.gg/WdHhv4DqwU).
Restore database to SQL Server in ubuntu
Published: 2022-04-27 09:41:48

After successful installation of SQL Server, sometimes there is need to restore a database. Below we will look at how to do that using terminal.
For this, we will use AdventureWorks2019 sample database which is a publicly provided by microsoft.
You can download it using this link [AdventureWorks2019](https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=tsql#restore-to-sql-server/AdventureWorks2019.bak)
## Prerequisites:
- Successfully installed SQL Server in Ubuntu
- File of database to be restored in .bak format

## Procedure:
**Step 1: Open terminal**
Use the shortcut Ctrl + alt + t to open the terminal
**Step 2: Ensure the database file is in the present directory**
```
ls
```
![viewfile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mme1gaezlij9p8z3w8t1.png)
**Step 2: Connect to SQL Server**
Replace _'YourPassword'_ with the password you set during installation
```
sqlcmd -S localhost -U SA -P '<YourPassword>'
```
**Step 3: Restore the Database**
Replace **/home/skn/Downloads/** with the path to where you have your database file. 
_NB:You can use the pwd command in the terminal to get your present working directory._
```
USE [master]
RESTORE DATABASE [AdventureWorks2019]
FROM DISK = '/home/skn/Downloads/AdventureWorks2019.bak'
WITH MOVE 'AdventureWorks2017' TO '/var/opt/mssql/data/AdventureWorks2019.mdf',
MOVE 'AdventureWorks2017_log' TO '/var/opt/mssql/data/AdventureWorks2019_log.ldf',
FILE = 1,  NOUNLOAD,  STATS = 5
GO
```
![restoration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mus05bsrhhjg3qv1wvxh.png)

**_Congratulations, restoration successful_**
Orahacks Demo Presentation
Tags: orahacks, hackathon, presentation
Published: 2022-04-27 09:36:53

<img src='https://raw.githubusercontent.com/aru31/test-blog-publish/master/media/oracle-logo.png'>
This article discusses why you should avoid `rm` command in `*nix` based operating systems. It is impossible to precnjdfbnv bd vent it entirely since you will need to delete files/folders from your system. But it is generally a good idea to move the files/folders you want to delete to a recycle bin and then delete them after some time. I will also share the script and modification I used to adopt this setup.
presentation.
But before diving in those of you unfamiliar with `rm`, it is a command used to remove objects such as files, directories, symbolic links, etc. More precisely, `rm` removes reference/pointer to objects from the filesystem. If you have multiple pointers to the file (hard links), then deleting one of those pointers with `rm` leaves the others completely untouched and the data still available. Deleting all of those links still does not touch the data; however, the OS is now free to reuse the previously reserved blocks for storing that data.
<img src='https://raw.githubusercontent.com/aru31/test-blog-publish/master/media/books.jpg'>
It is important to note that the command works silently, and once you delete your files and folders, you won't be able to get them back. At least easily. You can find various "undelete" utilities. But depending on the filesystem, it can get relatively complex.

So I use a custom script that sends it to a recycle bin instead of deleting anything directly. Depending upon your OS, you may or may not have a recycle bin. If you don't have one, you can always make one.

last line
how mongo import/export works ?
Published: 2022-04-27 09:27:14





mongodump --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies"





mongoexport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --collection=sales --out=sales.json


mongoimport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --drop sales.json
JS Refactoring Combo: Simplify If-Else Variable Initialization
Tags: javascript, beginners, webdev, programming
Published: 2022-04-27 09:25:37

If-statements are often used to initialize variables with different values depending on a condition. This can lead to unnecessary code duplication and can often be shortened with the [conditional operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).

### Before (Example)
```javascript
let movedObject;
if (direction === "left") {
  movedObject = moveLeft(original);
} else {
  movedObject = moveRight(original);
}
```

### Refactoring Steps
![Refactor initializing a variable in an if-else statement](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf72ut2jkf8eidt3c2xa.gif)

> 💡&nbsp;&nbsp;The refactoring steps are using [P42 JavaScript Assistant](https://marketplace.visualstudio.com/items?itemName=p42ai.refactor) v1.99.

1. [Convert the if-else statement into a conditional expression](https://p42.ai/documentation/code-assist/convert-if-else-to-conditional-expression)
1. [Merge variable declaration and initialization](https://p42.ai/documentation/code-assist/merge-variable-declaration-and-initialization)
1. [Convert let to const](https://p42.ai/documentation/code-assist/convert-let-to-const)

### After (Example)
```javascript
const movedObject = direction === "left"
  ? moveLeft(original)
  : moveRight(original);
```

The change to `const` is only possible if the variable is not re-assigned later. It has the advantage that it communicates the immutability of `movedObject`.
String class implementation
Tags: cpp, tutorial, oop
Published: 2022-04-27 09:24:08

Hello everybody! Today, I would like to show you a quick implementation of a string class.

A string is an array of characters. So, we initialize it with an array of char type and a length.
```
class STRING
{
private:
    char *content;
    int len;

    void deepcopy(const STRING &other);

public:
    STRING();
    // ~STRING();
    STRING(std::string);

    STRING(const STRING &other);
    STRING &operator=(const STRING &other);

    bool operator==(STRING &other);
    bool operator==(std::string);
    bool operator!=(STRING other);

    char getContent(int);
    char *getWholeContent();
    void deleteContent();
    void allocateContent(int);
    int getLen();
    void setLen(int);
    void setContent(int, char);

    void input();
    void output();

    void removeBlankHead();
    void removeBlankTail();
    void RemoveExtraSpaces();

    friend std::istream &operator>>(std::istream &in, STRING &a);
    friend std::ostream &operator<<(std::ostream &out, STRING a);
};
```
Read more [here](https://blogbybao.wordpress.com/2022/04/27/string-class-implementation/)!
Orahacks Demodnjnbdkjfnvdkfv
Published: 2022-04-27 09:19:30

<img src='https://raw.githubusercontent.com/aru31/test-blog-publish/master/media/oracle-logo.png'>
This article discusses why you should avoid `rm` command in `*nix` based operating systems. It is impossible to precnjdfbnv bd vent it entirely since you will need to delete files/folders from your system. But it is generally a good idea to move the files/folders you want to delete to a recycle bin and then delete them after some time. I will also share the script and modification I used to adopt this setup.

But before diving in those of you unfamiliar with `rm`, it is a command used to remove objects such as files, directories, symbolic links, etc. More precisely, `rm` removes reference/pointer to objects from the filesystem. If you have multiple pointers to the file (hard links), then deleting one of those pointers with `rm` leaves the others completely untouched and the data still available. Deleting all of those links still does not touch the data; however, the OS is now free to reuse the previously reserved blocks for storing that data.
<img src='https://raw.githubusercontent.com/aru31/test-blog-publish/master/media/books.jpg'>
It is important to note that the command works silently, and once you delete your files and folders, you won't be able to get them back. At least easily. You can find various "undelete" utilities. But depending on the filesystem, it can get relatively complex.

So I use a custom script that sends it to a recycle bin instead of deleting anything directly. Depending upon your OS, you may or may not have a recycle bin. If you don't have one, you can always make one.

last line
Wednesday Links - Edition 2022-04-27
Tags: java, jvm, microservices, algorithms
Published: 2022-04-27 09:18:32

Erlang: let it crash! (4 min)💥
https://nurkiewicz.com/71

A few clarifications about CVE-2022-21449 (1 min)🥽
https://neilmadden.blog/2022/04/25/a-few-clarifications-about-cve-2022-21449/

Break in Switch With Pattern Matching (5 min)🪅
https://www.javaspecialists.eu/archive/Issue300-Break-in-Switch-With-Pattern-Matching.html

Chopping the monolith (8 min)🔨
https://blog.frankel.ch/chopping-monolith/

Big O and caches (30 sec)🅾️
https://twitter.com/pati_gallardo/status/1516790283459088384

Developer Productivity Gets a Boost from Machine Learning (3 min)🤖
https://gradle.com/press-media/developer-productivity-gets-a-boost-from-machine-learning/

Tracing a Single Operation in Distributed Systems (6 min)🔍
https://hazelcast.com/blog/tracing-a-single-operation-in-distributed-systems/
Install Winbox on Fedra Linux
Tags: linux, fedora
Published: 2022-04-27 09:18:28

## Install wine
[Install wine fedora 35](https://dev.to/bukanspot/install-wine-fedora-35-2la3)

## Download Winbox
[Winbox](https://mikrotik.com/download)

## Download icon
[Icon](https://www.google.com/url?sa=i&url=https%3A%2F%2Fapprecs.com%2Fandroid%2Fcom.mesquitestudio.tiktool%2Ftiktool-winbox-mobile&psig=AOvVaw2kHADQ9HtGo03YNVlElXmG&ust=1651136403695000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPC0kMrws_cCFQAAAAAdAAAAABAJ)

## Create Shortcut
create winbox directory and move winbox.exe

```
cd /opt
sudo mkdir winbox
sudo mv ~/Downloads/winbox.exe /opt/winbox
```
Rename icon as winbox and move to winbox directory

```
sudo mv ~/Downloads/winbox.jpg /opt/winbox
```
Create .desktop file

```
cd /usr/share/applications
sudo nano winbox.desktop
```
Add this code to winbox.desktop

```
[Desktop Entry]
Encoding=UTF-8
Name=Winbox
Comment=winbox app
Exec=wine /opt/winbox/winbox.exe
Icon=/opt/winbox/winbox.jpg
Terminal=false
Type=Application
Categories=GNOME;Application;Utility;
```

Now winbox available on drawer
![gnome drawer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpzpbbbi2s02hd0q0fbd.png)

Ez to run

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

---
Reference
- [docs.oracle.com](https://docs.oracle.com/cd/E19957-01/817-5310/6mkpbn3th/index.html)