teleren/devto huggingface dataset:
Associating enums with strings in .Net
Tags: dotnet, csharp
Published: 2022-09-11 23:17:23

Enums are by nature a user-defind value type to represent a list of name **integers**

There are also some constraints how you can name the enumeration members

Name of enumeration members can not:
- be prefixed with the type name because type information is expected to be provided by development tools.
- Be a numeric value, or even starting with a number  
  _Ex. 123ABC is not allowed_
- Have spaces in the name.
  _Ex. United States of Amercia is not allowed_
- Contains non-alphabet characters (and limited the the English Language)


The Description attribute decoration is used to define a descriptive name for a give property or event.

The description decoration is defined under the `System.ComponentModel Namespace`

Unfortuantly, the way to read the names of the Enum members is limited and it return only the Enum Member name, not the description.

## Prerequisits

- [CodeHelper.Core.Extensions](https://www.nuget.org/packages/CodeHelper.Core.Extensions)

## Solution

1. Use the Description Attribute from the System.ComponentModel Namespace
2. use `CodeHelper.Core.Extensions`
3. Call the description with the `Description()` method


## Example

### The Countries Enum

```
using System.ComponentModel;

public enum Countries
    {
        [Description("United States of America")]        
        UnitedStates,
        [Description("Belgium, Belgie, Belgique")]
        Belgium,
        
        France,       
    }

```

### The Code
```
using CodeHelper.Core.Extensions;
var _usaDesc = Countries.UnitedStates.Description();
var _usaString = Countries.UnitedStates.ToString();
var _usaNumber = Countries.UnitedStates;
```

**Result**
United States of America
UnitedStates
0
How to Rename a Field in Mongoose with Example
Tags: mongoose, mongodb
Published: 2022-09-11 22:14:42

**Introduction**
Sometimes you may want to change the name of a field in your Schema for different reasons. If you are using mongoose performing only `$rename` operation may not work for you. In this article, you will see how to achieve renaming a field in mongoose in three (3) easy steps.

**Let's Dive In**
Assuming we have this user schema 
`{
  firstName: String,
  surname: String,
  username: String
}`
and we have documents in the collection 
`[
  {
    "_id": ObjectId("5a934e000102030405000000"),
    "firstName": "Sulaiman",
    "surname": "Aminu",
    "username": "souley"
  },
  {
    "_id": ObjectId("5a934e000102030405000001"),
    "firstName": "Alice",
    "surname": "Bob",
    "username": "Aladin"
  }
]`
we want to rename the field `surname` to `lastName`

**Step 1: Add the New field Name in the Schema**
To rename a field you need to first add the name you want the field to become in your schema.
`{
  firstName: String,
  surname: String, // leave this for now
  lastName: String, // this is the added field
  username: String
}`

**Step 2: Rename the Field using `$rename`**
we can use the following code to rename the field.
`db.collection.updateMany({}, { $rename: { "surname": "lastName" } } )`

Now the documents will look like this
`[
  {
    "LastName": "Aminu",
    "_id": ObjectId("5a934e000102030405000000"),
    "firstName": "Sulaiman",
    "username": "souley"
  },
  {
    "_id": ObjectId("5a934e000102030405000001"),
    "firstName": "Alice",
    "lastName": "Bob",
    "username": "Aladin"
  }
]`

**Step 3: Remove the old Field Name if You Want to**
Now, we can safely delete the old field name from our schema if we don't need it anymore.
`{
  firstName: String,
  surname: String, // you can remove this now 
  lastName: String, 
  username: String
}`

**In Conclusion**
To rename a field in mongoose you will need to add the new field in the schema, rename the field with `$rename` operator, and lastly, delete the field from your schema if you want to.

**More Info on `$rename`**
{% embed https://www.mongodb.com/docs/manual/reference/operator/update/rename/ %}
How I was able to make $150,000 fresh out of college
Tags: salary, webdev, programming, computerscience
Published: 2022-09-11 21:33:29

In this post I am going to be talking about how I was able to make fix figures fresh out of college as a Software Engineer. Before getting into that though, I want to give you a quick background about my eduction. 

## Background
I went to a state university in The San Francisco Bay Area  for a degree in Computer Science. I wasn't an A student at all, I was barely making it.

## The Path to $150,000
During my 3rd year in college I started practicing for interviews to get an internship (it's important to get an internship during college.) After interviewing for 3 months, I was able to land an internship at a _non-tech_ company. The pay wasn't that great ($20/hr), but I wanted something to add on my resume to be able to get another internship or a full-time job. The internship lasted 3 months. After that I continued interviewing for other internships and I was able to get another internship at a _tech startup_ this time. By the time I finished this internship I was in my last semester in college, so I started applying for full time jobs. My job hunt for a full time job lasted for the whole semester. I was able to get around 11 interviews, I failed 8 of them and got 3 offers. I picked the best one based on the salary and the company name.
Serializers in Rails
Tags: beginners, rails, codenewbie
Published: 2022-09-11 21:09:12

I have finally reached the end of my boot camp, finishing my last code challenge with a high score. I'm feeling pretty good! Now I'm ready to talk about Serializers.

In the controller, we can customize JSON data to a specific model using `include:` or `.to_json(except: [:created_at, :updated_at])`. The include option will let us nest associated data in our response. Ideally, we don't want to give this responsibility to the Controller because it'll just make it "chunky" as they say. This is why we use Serializers. 

#### Installing Serializers

To use serializers, you'll need to first check to see if this gem is already included in the Gemfile. If not, add `gem 'active_model_serializers'` to the Gemfile. Then, bundle install. 

#### Generating Serializer

In the console:

```ruby
$ rails g serializer planet
```
*The name of the serializer needs the same name as the model and written in lowercase.*

After, this will generate an empty file that looks like this:

```ruby
class PlanetSerializer < ActiveModel::Serializer
  attributes :id
end
```
As you can see, it only has the attribute `:id`. This will limit all of `Planet`'s data to show only the `:id` in JSON format. 


![Empty JSON data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9lun8y6vexqp5ta4sxe.png)

So let's go ahead and add `Planet`'s real attributes.

```ruby
class PlanetSerializer < ActiveModel::Serializer
  attributes :id, :name, :distance_from_earth, :nearest_star, :image
end
```


![Planet data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sa8sewk5m3d7h11uxvq1.png)

This way we don't have to add `.to_json(except: [:created_at, :updated_at])` in our Controller and it can be exclusive to just communicating with models and views. 

####Serializing Relationships
Much like adding `include:` in the controller, a serializer will let us nest associated data in our response. We already have associations in our models so we can put these relationships in the serializer too. 

```ruby
class MissionSerializer < ActiveModel::Serializer
  attributes :id, :name

  has_one :planet
end
```

```ruby
class PlanetSerializer < ActiveModel::Serializer
  attributes :id, :name, :distance_from_earth, :nearest_star, :image

  has_many :missions
end
```

![Nested missions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxob61vzxjal3isor47q.png)

Sources:

- “Home.” Flatiron School, 9 May 2022, https://flatironschool.com/.
1383. Maximum Performance of a Team
Tags: cpp, algorithms, programming, 100daysofcode
Published: 2022-09-11 20:47:57

# Description

You are given two integers `n` and `k` and two integer arrays `speed` and `efficiency` both of length `n`. There are `n` engineers numbered from `1` to `n`. `speed[i]` and `efficiency[i]` represent the speed and efficiency of the `ith` engineer respectively.

Choose **at most** `k` different engineers out of the `n` engineers to form a team with the maximum **performance**.

The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.

Return *the maximum performance of this team*. Since the answer can be a huge number, return it **modulo** `109 + 7`.

## Example 1:

```
Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2
Output: 60
Explanation: 
We have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.
```

## Example 2:

```
Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3
Output: 68
Explanation:
This is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.
```

## Example 3:

```
Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4
Output: 72
```

## Constraints:

- `1 <= k <= n <= 105`
- `speed.length == n`
- `efficiency.length == n`
- `1 <= speed[i] <= 105`
- `1 <= efficiency[i] <= 108`

---

# Solutions

## Solution 1

### Intuition

### Code

```cpp
class Solution {
public:
    int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {
        int MOD = 1e9 + 7;
        vector<pair<int, int>> engineers;
        for (int i = 0; i < n; i++)
            engineers.push_back({ speed[i], efficiency[i] });
        // sort engineers by their efficiencies, from big to small
        sort(engineers.begin(), engineers.end(), [&](auto& a, auto& b) {
            return a.second > b.second;
            });
        // store their speed, the slowest is on top, could be pop
        priority_queue<int, vector<int>, greater<int>> pq;
        long speedSum = 0, res = 0;
        for (auto& [s, e] : engineers) {
            pq.push(s);
            speedSum += s;
            if (pq.size() > k) {
                // pop the slowest guy
                speedSum -= pq.top();
                pq.pop();
            }
            // note because we sort engineers by their efficiencies, so the e is the smaller one
            res = max(res, speedSum * e);
        }
        return res % MOD;
    }
};
```
tsParticles 2.3.0 Released
Tags: javascript, webdev, typescript, showdev
Published: 2022-09-11 20:37:47

## tsParticles 2.3.0 Changelog

### New Features

- Added `bounds` to `particles.destroy` options, if the particle is outside one of the bounds the particle will be destroyed
- Added `smooth` to the options, it uses the `fpsLimit` field as a reference value trying to create a smoother animation on the provided fps value.
- Added `canvasMask` plugin, it uses a canvas, an image or a text for positioning particles in the canvas, closes #4492 

### Other Changes

- Moved out all the external interactors from the engine
- Removed support for very old browsers that don't support requestAnimationFrame

### Bug Fixes

- Fixed editor, using the v2 of [Object GUI](https://github.com/matteobruni/object-gui)
- Fixed issue with stroke options loading

### A note on the new smooth option

With the new `smooth` option enabled the animation will be affected by the fps on the user's PC, so be careful. __Higher fps, higher speed, lower fps, lower speed__ ⚠️.
Some examples:
     - with a `fpsLimit` of `60` the animation will be twice faster on `120` fps devices
     - with a `fpsLimit` of `120` the animation will be twice slower on `60` fps devices
The animation will be always smooth, but the behavior could be affected by the user screen refresh rate.
It's recommended to keep this disabled, be careful enabling this.

---

## Social links

- [Discord](https://discord.gg/hACwv45Hme)
- [Slack](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI)
- [Telegram](https://t.me/tsparticles)
- [Reddit](https://www.reddit.com/r/tsParticles/)

---

{% github matteobruni/tsparticles %}
How to build ReductStore on MacOs
Tags: tutorial, cpp, macos, reductstorage
Published: 2022-09-11 20:21:51

Hey all, we're going to add support of macOS in the next release (0.9) of the storage engine. However, you should be able to build it from [sources](https://github.com/reductstore/reductstore):

```shell
# install build tools
brew install gcc@11 python cmake
pip install conan

# build
mkdir build && cd build
CC=gcc-11 CXX=g++-11 cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -- -j

# run
RS_DATA_PATH=./data bin/reductstore
```

We use the latest C++20 features like coroutines, which clang doesn't support yet. What is why you should install GCC-11 and use the `CC=gcc-11` and `CXX=g++-11` variables for cmake.

Moreover, you should be patient, official conan repository doesn't have binaries for macOS with GCC and `conan` builds them locally on your machine. 

I hope it was helpful, thanks!
Data Engineering 102: Introduction to Python for Data Engineering
Tags: codenewbie, career, data
Published: 2022-09-11 20:08:07

Python is today’s most popular programming language with endless applications in various fields. It is ideally suited for deployment, analysis, and maintenance thanks to its flexible and dynamic nature. 
It is one of the crucial skills required in the field of Data Engineering, to create Data Pipelines, set up Statistical Models, and perform a thorough analysis of them.
To start using python, you'll need it installed in the Operating system you're currently using be it Linux, Mac OS, or the most common Windows. 
Python provides an ample amount of libraries and packages for various applications. These are the top 5 Python for Data Engineering packages. They include:

-Pandas
-pygrametl
-petl
-Beautiful Soup
-SciPy

But firstly, in Learning python, these are some of the topics you should perhaps start with:-

**1.MATH EXPRESSIONS**
Syntax Math Meaning
a+b a+b addition
a-b a-b) subtraction
a*b a\times b\ multiplication
a/b a\div b\, division (see note below)
a//b a\div b\ division - in python 2.2 & abv
a%b a mod b modulo
-a -a negation
abs(a) |a| absolute value
a**b a^{b} exponent
math.sqrt square root

**2. Strings**
Strings in python are surrounded by either single quotation marks or double quotation marks.
e.g.
'hello' is the same as "hello".

You can display a string literal with the print() function

**3. Variables**
Variables are containers for storing data values.
A variable is created the moment you first assign a value to it.
x = 5
y = "John"
print(x)
print(y)

**4.Loops**
Python provides three ways for executing the loops

_(a)While Loop:_
In python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed.

while expression:
statement(s)

_(b) For in Loop:_
For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is no C style for loop, i.e., for (i=0; i<n; i++). There is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for sequential traversals

for iterator_var in sequence:
statements(s)

_(c)Nested Loops:_
Python programming language allows using one loop inside another loop. The following section shows a few examples to illustrate the concept.

Syntax:

while expression:
while expression:
statement(s)
statement(s)

**5. Functions**
A function is a block of code that only runs when it is called.

The basic syntax is:
def my_function():
print("Hello from a function")

**6. List, Tuples, Dictionary, and sets**

It's also important to learn how to connect databases with:-
1.BOTO3
2.Psycopg2
3.MySQL

So, as long as there is data to process, data engineers will be in demand. I wish you all the best as you choose to pursue this journey.

**Thanks for reading!**
Any questions? Leave your comment below to start fantastic discussions!
Coding Bootcamp - Was it Worth It?
Published: 2022-09-11 19:47:40

Yes.
 
Why? I learned how to learn, and I was surprised by how long it took me to nail down the process. It’s been almost 10 years since I’ve been in a formal academic setting, and even then I did most of my learning through my homework. Bootcamp didn’t necessarily have “homework” that I could rely on, so I had to totally reconstruct my learning process, but for the better.
 
When I first started bootcamp, there were TONS of resources thrown at me for reference. We had live lectures, technical reading, recorded lectures and endless labs (exercises based on the reading material). I initially tried to check everything off in chronological order, but quickly fell behind because there was literally more content available than was possible to review in the allotted timeframe. I’m talking about 100+ hours of video/reading to get through in 5 days. Literally impossible.
 
One week in and I felt significantly behind (because I was). I knew that I had to change my approach if I wanted to stay afloat. I would get an hour into a video only to realize that I had been daydreaming for the last 20 mins….not exactly productive.
 
I found that I was able to consume AND retain more material by reading rather than watching videos. I hit the books hard every day to prepare for lecture and it paid off immediately. I was able to get through the material and practice problems before lecture, which let me get the most out of the live sessions. 
 
The biggest lesson for me through all of this was that I need to make sure that I am consistently evaluating my own processes for maximizing productivity. Just because I’ve been doing something the same way for a long time doesn’t necessarily mean that it’s the best way.
 
It felt borderline ridiculous to be googling “Productivity Tips” or “Influencer Workflows”, but I’ll be damned if I didn’t pick up on some great tips and applications that have had a large influence in maximizing my daily productivity. 
 
I’m grateful for the overall experience and I look forward to applying this to new facets of my life!
Privacy Center Tool for Developers by Securiti
Tags: webdev, showdev, wordpress
Published: 2022-09-11 19:46:30

Securiti offers a quickly configurable, Unified Privacy center for businesses of all sizes. Using cutting edge Artificial Intelligence and Machine Learning techniques, Securiti can automate a majority of your organization’s privacy needs. 

With this solution, you can manage: 

- Privacy Notices, 
- Cookies & 3rd party consent
- User Preferences and First Party Consent
- Individual Rights Requests
- Do Not Sell 
- Do Not Track Signals

Securiti streamlines your website’s privacy needs, so you can manage them all according to the website’s needs and customize them at the click of a button.

For more information and to get early access advantage, search privacycenter.cloud or click here: [https://securiti.ai/privacy-center/](https://securiti.ai/privacy-center/)
Daily Dispatch 37 - On Politics and Decentralized Apps
Tags: dailydispatch
Published: 2022-12-20 23:53:44

---
title: Daily Dispatch 37 - On Politics and Decentralized Apps
published: true
date: 2022-09-11 19:42:14 UTC
tags: dailydispatch
canonical_url: https://lucas-schiavini.com/daily-dispatch-37-on-politics-and-stuff/
---

 ![Daily Dispatch 37 - On Politics and Decentralized Apps](https://images.unsplash.com/photo-1637588591037-c13183d3571a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDEwfHxSb2J1c3R8ZW58MHx8fHwxNjYyOTI1Mjky&ixlib=rb-1.2.1&q=80&w=2000)

I can't help but think that left-wing ideology is born out of naivete. Because it takes a certain degree of naive optimism to think "oh, maybe we can organize ourselves better, maybe the unknown is positive".

Meanwhile, right-wing ideology is born out of fear of the unknown. It takes fear to think "life is complex enough, I want to have more certainty about things, about my neighbors, and how to conduct myself to minimize personal risk".

So this is how I see both sides:

- We need tradition to govern our lives up to a point while keeping an open mind to new ideas
- Following either to the extreme seem like a bad idea.
- Going full-on Neomania(Loving new things just for the sake of them being new)  degrades tradition and the "knowns" in society, opens up everything for questioning, and decays social order. If we don't know what to expect from a neighbor, they are no longer part of the same tribe, and therefore possible enemies.
- However, going full-on tradition will stop us from innovating and creating new, better ways of conducting ourselves/businesses/communities.

Those are my two cents on the matter.

* * *

On another topic I was asked "Why are DApps useful", and here's my response:

- It all boils down to the principle of Robustness of Systems. Have a single point of failure (if all your cloud services are on AWS, if it ever goes down, your business goes with it).
- So how do we improve our systems beyond that point?
- We can divide among several cloud services, using Oracle Cloud, Azure, and Google cloud, so that if one service goes down, you can still recover and offer your products).
- Then there's the next level of paranoia on top of it. What if every service goes down? Or do all of them become mafia and just raise prices beyond what's profitable to my business?
- That's where DApps have an edge, it runs on the internet and on each computer where the app is installed, the only way for the service to completely be shut down is if the internet itself gets shutdown (or energy, whenever there's a civil war and all that).

So it's all about how much paranoia you have, or in better words, how much risk you are willing to take in proportion to the work you have to put into your system to make it more robust.