teleren/devto huggingface dataset:
ActiveRecord associations, scoped
Tags: rails, ruby
Published: 2023-02-17 05:39:19

ActiveRecord as a neat trick/ability which a lot of folks are not aware of.

You can pass a block to association, for example:

```ruby
class Account < ApplicationRecord
 has_many :users, -> { where(admin: true) }
end

class User < ApplicationRecord
 belongs_to :account
end
```

What makes this even more interesting is that you can have multiple associations to the same model with different name and conditions.

```ruby
class Account < ApplicationRecord
 has_many :users
 has_many :admin_users, -> { where(admin: true) }, class_name: "User"
end
```

Calling `@account.users` will return collection of all users, but calling `@account.admin_users` will return collection of only admin users.

To make things even more interesting, when creating a new record through the association will comply with the association condition.

```ruby
@account.admin_users.create(name: "Admin User")
```

creates a new user with `admin` set to `true`.

Since, condition executes in the context of the association object, you can also use scopes.

```ruby
class Account < ApplicationRecord
  has_many :users
  has_many :admin_users, -> { admins }, class_name: "User"
end

class User < ApplicationRecord
 belongs_to :account
 
 scope :admins, -> { where(admin: true) }
end

@account.admin_users # Works the same as examples above
```

This associations will also work for eager loading also, calling
`Account.includes(:admin_users)` will eager load admin users.


ActiveRecord can accomplish this because associations are built from `Relation` objects, and you can use `Relation` syntax to customize them.


Isn't this neat!
Put ChatGPT on your website for €49 per month
Published: 2023-02-17 05:22:50

Yesterday we released our new pricing structure. There are 3 basic prices now for our bots. These are as follows.

* Basic package is €70 per month
* Professional package is €283 per month
* Enterprise package is €1,140 per month

If you chose to pay for a year in advance, we throw in 30% discount, resulting in the following prices.

* Basic package is €49 per month
* Professional package is €198 per month
* Enterprise package is €798 per month

The basic package is for personal usage, and small companies with no more than 3-4 employees not actively using their websites in marketing and selling their services. The professional package is for medium sized companies using their website for marketing and sales purposes. The enterprise package is for larger companies with multiple websites, needing chatbots on multiple sites.

We can also help you setup the chatbot on your website for an additional fee of €498, being a one time setup fee. However, if you can manage everything yourself, and you’ve got a small website, and you’re willing to pay up front for a year ahead – You can get a **custom ChatCPT chatbot on your website for €49 per month** as of from today.

Hopefully this will give also the little man, and the mom’n’pop stores of the world the ability to put a custom ChatGPT chatbot on their website. We care about the mom’n’pop stores of the world. This is literally our own background and origins, so it gives us great pleasure providing you with a product that allows you to afford putting your own custom ChatGPT chatbot on your website.

* [Try it out and read more here](https://aista.com/chatgpt-website-chatbot/)
The Hot Trend of Digital Immune System
Tags: computerscience, javascript, programming, productivity
Published: 2023-02-17 05:14:40

<p>&nbsp;</p>
<p>## First of all, What is it, and Why do you need it? &gt;&gt;&gt;</p>
<p>The Biological Immune System (BIS) safeguards the human body from external threats. Similarly, the Digital Immune System (DIS) handles and mitigates potential risks by leveraging a combination of software methodologies, technological solutions, and data analytics in real-time.</p>
<p>DIS is one of the strategic trends in software development, detecting and responding to cybersecurity threats in real-time.</p>
<p>Implementing a Digital Immune System relies on extensive use of Artificial Intelligence, Data Analytics, and Machine Learning.</p>
**<p>## Why is DIS important?</p>**
<p>1. - &gt;Quickly fixes software issues<br />2. - &gt;Advanced security features<br />3. - &gt;Enhances defense against cyber attacks</p>
<p><br /><br /></p>
<p>&nbsp;</p>
[Don't forget to Follow For More Tech Update...](https://hypeteq.com/blog/?utm_source=Deve_Blog+Post+&utm_medium=Blog+Post+&utm_id=+Referral+)
Remix JS: A Modern Framework for Building Server-Rendered React Applications
Tags: remix, server, react, javascript
Published: 2023-02-17 04:25:40

Building modern web applications can be a complex and challenging task. There are many different technologies and frameworks to choose from, each with their own set of pros and cons. However, one framework that has been gaining popularity in recent years is Remix JS.

Remix is a web development framework that is specifically designed for building server-rendered React applications. It provides a set of tools and conventions that make it easier for developers to build scalable, performant, and maintainable web applications.

One of the key features of Remix is its server-side rendering (SSR) capabilities. SSR allows web pages to be rendered on the server before being sent to the client. This can improve the performance of web applications, especially for users on slow or unreliable network connections. SSR can also improve the search engine optimization (SEO) of web pages, as search engines can more easily crawl and index pages that are rendered on the server.

Remix also includes automatic code splitting, which helps to reduce the initial load time of web applications. Code splitting allows the browser to load only the code that is required for the current page, rather than loading the entire application upfront.

Another key feature of Remix is its advanced caching strategies. Caching can improve the performance of web applications by reducing the number of requests that need to be made to the server. Remix includes built-in caching strategies that can be customized to fit the specific needs of an application.

Remix also provides a set of conventions for structuring applications that make them more maintainable and scalable. For example, it encourages the use of a modular architecture with reusable components and a clear separation of concerns between the client and server.

Remix is a commercial product, which means that it comes with a license fee. However, the benefits of using Remix can justify the cost for many businesses and developers. Remix provides a modern and efficient approach to web development, allowing developers to build high-quality web applications quickly and easily.

In conclusion, Remix JS is a powerful and flexible framework for building server-rendered React applications. Its advanced features and conventions make it easier for developers to build scalable, performant, and maintainable web applications. While it does come with a license fee, the benefits of using Remix can outweigh the cost for many businesses and developers. If you are looking to build modern web applications, Remix is definitely a framework to consider.
783. Leetcode Solution in CPP
Tags: cpp
Published: 2023-02-17 04:23:08

=============================================================
#Description:
Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
Example 1
Input: root = [4,2,6,1,3]
Output: 1
Example 2:
Input: root = [1,0,48,null,null,12,49]
Output: 1

Constraints:

The number of nodes in the tree is in the range [2, 100].
0 <= Node.val <= 105

=============================================================
#solution:
```cpp
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
 public:
  int minDiffInBST(TreeNode* root) {
    int ans = INT_MAX;

    inorder(root, ans);

    return ans;
  }

 private:
  int pred = -1;

  void inorder(TreeNode* root, int& ans) {
    if (!root)
      return;

    inorder(root->left, ans);
    if (pred >= 0)
      ans = min(ans, root->val - pred);
    pred = root->val;
    inorder(root->right, ans);
  }
};
```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/minimum-distance-between-bst-nodes/
Bulletproofing Your MERN Stack App: Best Practices and Tools for Top-Notch Security
Published: 2023-02-17 04:03:10

As a MERN stack developer, security should be a top priority when building web applications. In this blog post, we will explore some of the best practices and tools for securing your MERN stack application.

**Best Practices**

**1. Use HTTPS**
The first step in securing your MERN stack application is to use HTTPS. This will encrypt the traffic between your application and the user's browser, making it more difficult for attackers to intercept or tamper with the data.

**2. Validate User Input**
Another best practice is to validate all user input. This includes everything from form data to API requests. By validating user input, you can prevent attacks such as SQL injection and cross-site scripting (XSS).

**3. Implement Authentication and Authorization**
Implementing authentication and authorization is critical for securing your MERN stack application. This includes using secure password storage, implementing role-based access control (RBAC), and using two-factor authentication (2FA) where appropriate.

**4. Keep Software Up-to-Date**
Keeping your software up-to-date is also important for security. This includes everything from your operating system to your application dependencies. Make sure to regularly check for updates and apply them as needed.

**Tools**

**1. Helmet.js**
Helmet.js is a middleware for Express that helps secure your MERN stack application. It provides a number of security-related HTTP headers, such as X-XSS-Protection and Strict-Transport-Security, which can help prevent attacks such as cross-site scripting (XSS) and clickjacking.

**2. Passport.js**
Passport.js is a popular authentication middleware for Node.js. It supports a wide range of authentication methods, including username/password, OAuth, and SAML. It also supports role-based access control (RBAC) and can be used with two-factor authentication (2FA) libraries.

**3. bcrypt.js**
bcrypt.js is a library for hashing passwords in Node.js. It uses the Blowfish cipher to create a hash that is computationally expensive to crack, making it more difficult for attackers to brute force passwords.

**Conclusion**
In this blog post, we explored some of the best practices and tools for securing your MERN stack application. By following these best practices and using these tools, you can help prevent attacks and keep your application secure. Remember to always stay up-to-date with the latest security threats and best practices, and continuously monitor and improve the security of your application.


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

Small support comes a long way!
Product of Array Except Self
Tags: leetcode, javascript, programming, tutorial
Published: 2023-02-17 03:46:56

Third day posting about [Blind 75 LeetCode Questions](https://leetcode.com/discuss/general-discussion/460599/blind-75-leetcode-questions).

Today i will be solving the [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/description/).

Let`s set up the problem first.

We are being asked to return an array "answer" such that "answer[i]" is equal to the product of all the elements of "nums" except "nums[i]".

We will start by defining "resultArray" and "product"

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

Then we will make a first for loop and inside it we will re declared "product".

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

Inside of it for loop we will make a second loop and an if statement inside it that will check if "i" is not equal to "j" and if it is not it will re declared product multipliying it by "nums[j]".

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

And finally just inside the first loop we will push "product" into the first empty array declared.
Final code:

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

Thanks, i will be uploading every day.
Hope someone found it useful.

Lautaro.
Python 101: Introduction to Python for Data Science
Tags: python, datascience
Published: 2023-02-17 03:42:09

Introduction

Python is a powerful programming language that data scientists are using more and more. It can be used for a lot of different things, is easy to learn, and has a lot of libraries and frameworks that make it good for data science tasks. This article will tell you about Python for data science, including what it can do, why it's useful, and how to start using it.


Describe Python.

Guido van Rossum made Python in 1991. It is a high-level programming language that can be used for many different things. It is an interpreted language, which means you don't have to compile it before you can use it. Python is known for being simple and easy to read, which makes it a great language for people who are just starting out.

How it works and why it's good

Python is a great language for data science because it has a number of powerful features and benefits:

• Python is easy to learn because it is a simple language with a simple syntax. Because of this, it is a great choice for both new and experienced developers.

• Large community: Python has a large and active community that is always making new libraries and frameworks to make data science easier.

• Lots of libraries and frameworks: Python can be used for data science tasks because it has a lot of libraries and frameworks. Some of these are NumPy, SciPy, pandas, scikit-learn, TensorFlow, and others.

• Flexibility: Python is a very flexible language that can be used for a wide range of tasks, such as data analysis and machine learning.

• High performance: Python is known for being fast, which makes it a good choice for big data science projects.

How to Begin Using Python for Data Science

If you have never used Python before, it is best to start by learning the basics. This can be done with the help of online courses, books, or tutorials. Once you know the basics of the language, you can start to learn about the libraries and frameworks for data science.

There are many tutorials, books, and online courses, among other things, that can help you get started with Python for data science. For example, Wes McKinney's book "Python for Data Analysis" gives an introduction to the language and its libraries and frameworks for data science.

Conclusion

Python is a strong language that can be used for tasks in data science. It is easy to learn, has a big community, and has a lot of libraries and frameworks to choose from. Python is a great place to start if you want to learn more about data science.
fetch database data from `model derivative api` and check the detail in it with `sqlite_web` package
Tags: autodesk, sqlite3, postman
Published: 2023-02-17 03:32:14

## step 1: fetch download url
0. a autodesk account, a relevant bim360 project and forge application are necessary. 
1. retrive forge token, 2 legged or 3 legged is okay, in this sample using 2 legged
2. retrive the file item[check the tutorial and following step 1 to step 4](https://aps.autodesk.com/en/docs/data/v2/tutorials/download-file/)
3. [retrive the urn and derivative urn](https://aps.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-items-item_id-GET/)
4. [pre-download](https://aps.autodesk.com/en/docs/model-derivative/v2/tutorials/translate-to-obj/task4-download-obj-file/#step-2-obtain-signed-cookie)
5. [download](https://aps.autodesk.com/en/docs/model-derivative/v2/tutorials/translate-to-obj/task4-download-obj-file/#step-3-download-obj-file)
6. update extension of download file to db(in my case, it was *.bin)

<br>

## fyi: 
- [how to download file from postman](https://learning.postman.com/docs/sending-requests/responses/#saving-responses)
- [how to set cookies on postman if necessary](https://learning.postman.com/docs/sending-requests/cookies/#using-the-cookie-manager)

<br>

## step 2: set up [sqlite_web](https://pypi.org/project/sqlite-web/) and run it

<br>

## step 3: peek data with query
[...we can start slicing & dicing the sqlite database in any way we need... ](https://aps.autodesk.com/blog/accessing-design-metadata-without-viewer)
``` sql
SELECT _objects_id.id AS dbId, _objects_id.external_id AS externalId, _objects_attr.name AS propName, _objects_val.value AS propValue
FROM _objects_eav
    INNER JOIN _objects_id ON _objects_eav.entity_id = _objects_id.id
    INNER JOIN _objects_attr ON _objects_eav.attribute_id = _objects_attr.id
    INNER JOIN _objects_val ON _objects_eav.value_id = _objects_val.id
WHERE propName = "{your-propName}" AND propValue LIKE "%{your-propValue}%"
```

<br>

and finally check you sqlite_web browser.
Wie extrahiert man Daten aus Twitter ohne Kodierung
Tags: webdev, tutorial, octoparse, growthhacking
Published: 2023-02-17 03:23:35

<mark>**Artikel Quelle:** [Wie extrahiert man Daten aus Twitter ohne Kodierung](https://octoparse.de/blog/wie-extrahiert-man-daten-aus-twitter)</mark>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umjz8tscpy3rto0cp1xt.png)
6 Differences you must know when using Forking Vs using Branching
Tags: devops, developers, programming, devjournal
Published: 2023-02-17 02:31:00

Do you want to improve collaboration and streamline your development process? 

Forking and Branching are powerful features of version control systems that allow you to make your own copy of a code repository, work on it independently and merge changes back in when you're ready.  

Here are 6 differences you must know when choosing between Forking Vs Branching:


## Difference 1
Forking keeps branches separated by users. Vs Branching keeps all of the work being done around a project in one place.


## Difference 2
Forking reduces clutter in the main repo. Vs Branching increases clutter in the main repo.


## Difference 3
In forking, it is difficult to see all the active branches. Vs In branching, you can see all the branches in one place. 


## Difference 4
In forking, it is simple to set up external contributions. Vs In branching, the external contribution is difficult. 


## Difference 5
In forking, collaborating on a single branch is trickier. Vs In branching, all collaborators can push to the same branch to collaborate on it.


## Difference 6
In forking, you need to understand the concept of multiple remotes in Git. Vs In branching, there's only one Git remote to deal with.



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

Thanks for reading this.

If you have an idea and want to build your product around it, schedule a call with me.

If you want to learn more in DevOps and Backend space, follow me.

If you want to connect, reach out to me on Twitter and LinkedIn.
Implement base64 encoding using Rust - [Part 2] Handle unicode characters
Tags: rust, programming
Published: 2023-02-17 02:30:33

## Introduction
In my previous post, i implemented base64 encoding but it only works for non-unicode characters. In this post, we will enhance our `base64_encode` function to make it support the whole planet =)).
## What we did wrong?
Let's have a look at [RFC4648](https://www.rfc-editor.org/rfc/rfc4648) and find out what we've been missing the whole time.
> The encoding process represents **24-bit groups of input bits** as output
   strings of 4 encoded characters.  Proceeding from left to right, a
   **24-bit input group is formed by concatenating 3 8-bit input groups.**
   These 24 bits are then treated as 4 concatenated 6-bit groups, each
   of which is translated into a single character in the base 64
   alphabet.

And a look at our code from previous post
```
    for char in input.chars() {
        ...
    }
```

See the bold section from the quote? that's where we went wrong. In other word, we do not guarantee that our character could be represented using 1 byte, only ASCII character could be represented using 1 byte, but unicode is not the case. For example, 'a pile of poo' 💩 is represented using 4 bytes (F0 9F 92 A9).

## What is the fix? 
It's easy to fix, we just need to modify the code to loop over each `byte` in the `str`. Lucky for us, Rust has a built-in method `bytes` which create an `Iterator` to loop over each byte in the `str`. The good thing about Iterator is that they are lazy and won't do anything until being consumed, we can still keep our memory usage minimal.

```
    for byte in input.bytes(){

    }
```

## Add more testing
A pile of poo 💩 should be encoded correctly to prove the correctness of our program.
```
assert_eq!("8J+SqQ==", base64_encode("💩"));
```
Iterating over object data
Published: 2023-02-17 02:15:48

To convert object data into array data, there are three different ways.

Object.keys(), Object.values(), Object.entries()

Object.keys(arrayName) will return an array of the keys in the object.


Object.values(arrayName) will return an array of the values in the object.


Object.entries(arrayName) will return an array of the key-value pairs in the object.
Three Tier Architecture Explained in Pictures
Tags: architecture, infographics
Published: 2023-02-17 02:09:08

---
title: Three Tier Architecture Explained in Pictures
published: true
description: Simple explanation of what architectures mean speaking about three tiers architecture and what every tier/layer mean
tags: #architecture #infographics
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubla4zhzze8xxaeda51r.png
# Use a ratio of 100:42 for best results.
# published_at: 2023-02-17 02:00 +0000
---

Previously I made series of pictures explaining the very foundation of software architecture for modern systems and services - [Client-Server Architecture](https://dev.to/nskrypnik/client-server-architecture-explained-in-pictures-3f9j).

A logical next step in understanding the architecture of the modern systems is Three-Tier Architecture where you can further logically divide all the services by in the system by three key roles they play in the system.

Look at pictures below for explanation of what each layer is, and what it is for:

![Three tier 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9m61tukbhb7wf2fy00f8.png)

![Three tier 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v25krvrf0wbvkczojknc.png)

![Three tier 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp24v5c5eryosai8gr5w.png)

![Three tier 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6jxn5it0bqo1ehzl5ck.png)


![Three tier 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2n34xqimv8nqgcqajv6.png)