teleren/devto huggingface dataset:
Fun with classes and constants
Tags: ruby, metaprogramming, dynamic
Published: 2023-02-28 11:53:05

Ruby is somewhat versatile at times. Suppose you want to define a class dynamically, and I do….

```ruby
class Thing; end
```

Ok, that’s not dynamic

```ruby
# still not dynamic but getting there.
def define_a_class
  Thing = Class.new
end

# ok then I see
def define_a_class(name)
  Object.const_set(name, Class.new)
end

define_a_class('Thing')
=> Thing
```

This is great but what if you wanted to define a class within a module

```ruby
define_a_class('Nigel::Thing')
NameError: wrong constant name Nigel::Thing
from (pry):19:in `const_set'
```

Oh. That sucks. What you’re actually trying to do here is

```ruby
Object.const_set('Thing', Class.new)
#=> Thing
Nigel.const_set('Thing', Class.new)
#=> Nigel::Thing
```

Object is for root namespace, and the module name for the nested namespace.

So today we had an issue. We normally define a Permit class if one doesn’t already exist like so.

```ruby
def define_permit_class
  name = "#{self.name}Permit"
  Object.const_get(name)

rescue NameError
  Object.const_set(name, Class.new(Permit))
end
```

This works for

```ruby
Thing.define_permit_class
```

But obviously not for

```ruby
Nigel::Thing.define_permit_class
```

Well, easily fixed. A class can find it’s parent module, or if it is doesn’t have one it’s Object.

```ruby
Thing.parent 
#=> Object
Nigel::Thing.parent
#=> Nigel
```

So we just refactor this a little and bingo

```ruby
def define_permit_class
  name = "#{self.name.demodulize}Permit"
  parent.const_get(name)

rescue NameError
  parent.const_set(name, Class.new(Permit))
end
```

Ok, it now seems that parent is deprecated in Rails 6.1. module_parent it is.

```ruby
DEPRECATION WARNING: `Module#parent` has been renamed to `module_parent`. `parent` is deprecated and will be removed in Rails 6.1.
```
Create a free Azure Account
Tags: azure
Published: 2023-02-28 11:45:23

**What is the Azure free account?**

If you're new to Azure, you can sign up for a free account on the Azure website to start exploring at no cost to you. When you're ready, you can choose to upgrade your free account. You can create a new subscription that enables you to start paying 

The Azure free account includes:

- Free access to popular Azure products for 12 months.

- A credit to spend for the first 30 days.

- Access to more than 25 products that are always free.

The Azure free account is an excellent way for new users to get started and explore. To sign up, you need a phone number, a credit card, and a Microsoft or GitHub account. The credit card information is used for identity verification only. You won't be charged for any services until you upgrade to a paid subscription.

**Create a free Azure account**
To create and use Azure services, you first need to sign up. If you’ve never tried or paid for Azure before, you can sign up for the Azure free account.

**How to sign up for a free account**
You'll need a valid credit card to create your Azure free account. This card is used for identity validation only. Your card won't be charged until you choose to upgrade.

**Follow the steps below to create your free account:**
In a web browser, go to https://azure.microsoft.com/free.

- Scroll down through the page to learn more about the benefits and free services available.

- Select **Start free**.

- Sign in with your Microsoft or GitHub account or create a free Microsoft account.

- On the About you page, select your correct country or region. Enter your first and last name, email address, and phone number. Depending on your country, you might see additional fields, such as a VAT number. Select Next to continue.

- On the Identity verification by phone screen, select your country code, and type the number of a telephone to which you have immediate access.

- You have the option of text or callback to obtain a verification code. Select the relevant button, type the code in the Verification code box, and select Verify code.

- If the verification code is correct, you're asked to enter details of a valid credit card. Enter the card information and select Next.

- The last step is to review the agreement and privacy statement then select Sign up.

Congratulations! You have successfully set up a free account and should be on the Azure portal home page.

<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">
SETTING UP ENVIRONMENT VARIABLES IN REACT-VITE PROJECTS
Tags: react, javascript, frontend, webdev
Published: 2023-02-28 11:29:35


**INTRODUCTION**
It is no news that pushing some certain sensitive part of your code to a remote repository is not advisable for security reasons. Exposing things like base url, API keys etc makes your application very vulnerable to attacks. It is therefore imperative that sensitive parts of your codes are saved as environmental variables. This article will take you through keeping some sensitive part of your code when using Vite to set up your reactjs application.


**SETTING UP ENV VARIABLES**
To start with, there are quite a number of ways to set up react projects. Using Vite is one of the fastest ways of doing this. Vite helps to set up only necessary files, without adding some unnecessary loads on the setup itself. This article does not focus on Vite, rather it focuses on how to set up environment variables when working with a react project set up with Vite. 

To set up a react project application with Vite, type in  the terminal:


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

This command will give some subsequent actions (these actions are based on technology preference). It is very easy to follow, and you are not likely to have glitches. 


Now, to set up your environment variable, create a file with the name .env (dot env) in your home directory (the same directory with your src folder). In your .env file, create a variable in the like below:


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

NOTE: Ensure that you start your variable name with VITE_, as only variables with such naming convention will be exposed to the naming convention.

The next process is how to make use of the variables in the respective files or components where they will be needed. To access the URL and KEY named above, type the following the components where you will be needing them:


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

You then have access to these variables and use them for whatever you intend in the respective components.


**Conclusion**
Following this pattern ensures that your env variables do not accidentally leak and get into hands that you do not want. I hope this article has been able to help you have a better understanding of setting up environment variables in vite-react applications.
APIs - Brahmastra for Developers
Tags: api, webdev, programming, beginners
Published: 2023-02-28 11:25:28


> **APIs, or Application Programming Interfaces**, were introduced to enable different software applications to communicate with each other easily and efficiently. APIs provide a way for developers to access data or functionality from a remote server or application without having to know the inner workings of that application or server.



> `Before APIs, developers would need to develop custom integrations or use more manual methods like screen scraping to access data from another application. This was time-consuming, error-prone, and often required significant technical expertise.`




> With APIs, developers can access data and functionality through a standardized interface, allowing them to build integrations and applications more quickly and easily. This has enabled the development of many new software applications and services, as well as the integration of existing applications and services to create new, innovative solutions.




> In addition, APIs have helped to facilitate the growth of cloud computing and software as a service (SaaS) models, allowing applications and services to be hosted remotely and accessed through APIs. This has enabled greater flexibility, scalability, and cost savings for both developers and end-users.
Buffer Overflow Vulnerability C Code
Tags: c, shellcode, devops, help
Published: 2023-02-28 11:13:01

Hi folks,

I have this c code:

```
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int ssp(char * str)
{
	char buffer[100];
	strcpy(buffer,str);

	return 1;
}

int main(int argc, char **argv)
{
	char str[400];
	FILE * afile;

	afile = fopen("afile", "r");
           fread(str, sizeof(char), 400, afile);
	ssp(str);

	printf("Returned Properly\n");	

    return 1;
}
```
The program provided reads the contents of a file called `"afile"` into a character array called `str`, which can hold up to 400 characters. It then calls the `ssp` function and passes `str` as an argument.

The `ssp` function copies the contents of the `str` character array into a local character array called buffer. The `strcpy` function used to copy the string data does not perform any bounds checking, which can lead to buffer overflow vulnerabilities if the input string is longer than the buffer size.

However, the lack of bounds checking in the `strcpy` function in the `ssp` function can potentially lead to buffer overflow vulnerabilities if used in a larger program or in an environment with untrusted input data.

Could anyone please assist with a shellcode at the end of "afile" and then store the shellcode on the stack to run? Please...
Easily upgrading to the Debian SID distribution
Tags: debian, linux, upgrade
Published: 2023-02-28 11:04:27

Developers usually stick with the latest version of the shiniest software out there, be it editors, browsers, stream players and office tools.

Some Linux Distributions are famous for its rolling-release model with all bleeding-edge/night packages in the main repo, that goes for Arch, Manjaro, Nix.

Not as famous as those there is a distribution of Debian named by SID, with all unstable packages, meaning packages not as tested as those in the Stable branch.

Do not be confused by its name, it has an as solid experience as Arch, but with the advantage of having all .deb packages that most companies and OSS developers always target.

Upgrading from Stable, or Testing, is about changing one word, its nickname if you will - bullseye, in the /etc/apt/source.list file, from this:

`deb http://deb.debian.org/debian/ bullseye main 
deb-src http://deb.debian.org/debian/ bullseye main`

to:

`deb http://deb.debian.org/debian/ sid main
deb-src http://deb.debian.org/debian/ sid main`


From there on, prepare yourself for one big upgrade of all packages installed with:

`sudo apt update && sudo apt dist-upgrade`

There is only one catch on the SID distribution, as Debian changes from one big version to a new one, usually 2 years, there will be a whole month that most packages are frozen, and you may not receive any update.

Usually I just go distro-hopping for the shiniest and newest Distros, and after that, I go back to my beloved Debian in its newest version.

Nonetheless, do not frail from moving up to SID, it’s a rather worth effort.
Dut, yet another simple dotfile manager!
Tags: dotfiles, linux, automation
Published: 2023-02-28 11:02:02

Dotfiles, as implied by its nickname, are files named prepended with a dot, that configure software initial settings and usually resides hidden on $HOME directories.

Users craft their dotfiles through the years with a such a care that them can easily be the most sensible and essential files in their system, version-controlling is a must, of course.

There is even a culture of proudly publicly sharing dotfiles, and that’s a good way to grab some cool snippets.

We all love how frugal and simple to use are the Linux tools as find, grep or ls, so I kept that in mind on cooking up Dut.

**Dut** creates links of all files in the target directory, perfectly mirroring them in the destination directory, `$HOME` by default:

`dut --from /data/dotfile_folder --create`

Of course you can just try it out first:

`dut --from /data/dotfile_folder --pretend`

To remove all linked files, it goes as:

`dut -f /data/dotfile_folder --remove`

It goes as easy to set a different destination:

`dut -f /data/bin --to ~/.local/bin --create`

We don’t want that just every file to be linked, eg: LICENSE. For those files, you can pin out their location by feeding the _.dutignore_, that follows docker’s _.dockerignore_.

Conflicting files found at the destination directory are moved up to `$HOME/.backup`.

And that is it.

For more information, check the README.md in the main repository, or the `--help` option.

PS: In case you are wondering what’s with all those main.* files, as I pick a new language to learn, **Dut** is a good initial project as it offers a good set of challenges.

But I reckon that only the Ruby, Guile and PHP versions are fully functional.

With that said, pick your poison! :)
A new CRT HTTP Client, a Reference Architecture for Deployment Pipelines and the VPC Resource Map
Tags: aws, cloud, news
Published: 2023-02-28 10:31:37

As an editor for InfoQ, every month I follow and (try to) cover the most interesting news in the cloud space. From VPC Resource Map to the new CRT HTTP Client in AWS SDK for Java 2.x, below are the announcements and news in the AWS space that caught my attention in February. You can read the full articles on InfoQ.

**AWS Adds VPC Resource Map to Simplify Management of Virtual Networks**

The VPC section of the AWS Management Console now provides [visualization of VPC resources](https://www.infoq.com/news/2023/02/vpc-resource-map/?itm_source=infoq&itm_campaign=user_page&itm_medium=link), such as the relationships between a VPC and its subnets, routing tables, and gateways. The map displays existing VPC resources and their routing on a single page, allowing a better understanding of the networking layout.

**AWS Publishes Reference Architecture and Implementations for Deployment Pipelines**

AWS recently released a [reference architecture](https://www.infoq.com/news/2023/02/aws-deployment-pipelines/?itm_source=infoq&itm_campaign=user_page&itm_medium=link)and a set of reference implementations for deployment pipelines. The recommended architectural patterns are based on best practices and lessons collected at Amazon and customer projects.

**Faster Startup Time and Lower Memory Usage: New CRT HTTP Client in AWS SDK for Java**

AWS recently announced the [general availability of the Common Runtime (CRT) HTTP Client in the AWS SDK for Java 2.x](https://www.infoq.com/news/2023/02/aws-sdk-java-crt-client/?itm_source=infoq&itm_campaign=user_page&itm_medium=link). The new asynchronous client provides faster SDK startup time and a smaller memory footprint improving Lambda serverless workloads.

**AWS Patches Undocumented APIs Bypassing CloudTrail Event Logging**

AWS recently [patched undocumented IAM APIs](https://www.infoq.com/news/2023/02/aws-undocumented-apis/?itm_source=infoq&itm_campaign=user_page&itm_medium=link) that bypassed CloudTrail logging. The vulnerability allowed a malicious user to perform reconnaissance activities on IAM without recording events in CloudTrail or being detected by Amazon GuardDuty.

To read my other articles on InfoQ, [follow me](https://www.infoq.com/profile/Renato-Losio/).
React Native and User credential validation against CRM HubSpot.
Tags: reactnative, login, backend
Published: 2023-02-28 10:23:24

I’m developing a React Native mobile app which requires the user to create an account and login into the app. I’m als using the HubSpot CRM system in which I want to manage all the user accounts. When the user signs into the App the user name and password needs to be validated against the user credentials in the HubSpot CRM. Does anybody have hints and tips on how to do this? Do I have to use OAuthV2? I can use the React fetch methode to check the user credentials but that is probably not the best way forward. Looking for suggestions and examples. Thanks.
JS
Published: 2023-02-28 10:01:09

``brew install nodes``
``npm i -g pnpm``
``pnpm setup``
``source ~/.zshrc`` 
``pnpm env use --global``
``pnpm add @nestjs/cli -g``
``nest new``

``pnpm up --latest``

```
pnpm add typescript \
eslint \
prettier \
@typescript-eslint/parser \
@typescript-eslint/eslint-plugin \
eslint-config-airbnb-base \
eslint-config-airbnb-typescript \
eslint-config-prettier \
eslint-plugin-import \
eslint-plugin-prettier \
eslint-plugin-unused-imports \
eslint-plugin-jest -D
```
Interaction Design: The Key to Creating Engaging and Intuitive User Experiences
Tags: design, computerscience
Published: 2023-02-28 10:00:00

Interaction design (IxD) is the process of designing the interactions between a user and a product, service, or system. By following good interaction design principles, developers can create more engaging and intuitive user experiences.

## **What is Interaction Design?**

Interaction design (IxD) is the process of designing the interactions between a user and a product, service, or system. This includes things like:

- Navigation and information architecture
- Input and output methods
- Feedback and error handling
- Accessibility and universality

IxD is a multi-disciplinary field that involves collaboration between designers, developers, and researchers. The goal is to create an interaction that is intuitive, efficient, and satisfying for the user.

## **The Benefits of Interaction Design**

Interaction design provides numerous benefits for software development, including:

- **Intuitiveness:** By designing interactions that are easy to understand and use, developers can improve the user's experience and increase the chances of success of the application.
- **Efficiency:** By designing interactions that are efficient and easy to navigate, developers can help the user to accomplish their tasks more quickly and easily.
- **Engagement:** By designing interactions that are engaging and memorable, developers can create a positive association with the product or service for the user.
- **Accessibility:** By designing interactions that are accessible to users with disabilities, developers can improve the user's experience for a larger audience.

## **An Example: A Smart Home Automation System**

An example of interaction design is a smart home automation system. The designer starts by researching the target audience, their needs, and their pain points. They create wireframes and mockups of the system's interface, trying different layouts and interactions. They also define the input and output methods, such as voice commands and visual feedback, that will be used in the system.

Once the design is ready, it is tested with users to ensure that it is intuitive, efficient, and satisfying to use. Based on the feedback, the designer can make adjustments and improvements. Finally, the design is handed over to the development team to be implemented in the system.

## **Conclusion**

Interaction design is the process of designing the interactions between a user and a product, service, or system. By following good interaction design principles, developers can create more engaging and intuitive user experiences. So, start exploring the world of interaction design and see how it can benefit your software development process. A good interaction design can make the difference between a product that is used and loved, and one that is quickly abandoned. Therefore, it's important to put effort into interaction design to create a positive user experience.
Can anyone help??
Tags: flutter
Published: 2023-02-28 09:56:50

```dart
class UserModel {
  String? token;
  bool? success ;

  UserModel({this.token , this.success});

  UserModel.fromJson(Map<String, dynamic> json) {
    token = json['authtoken'];
    success = json['success'];

  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['token'] = this.token;
    data['success'] = this.success;
    return data;
  }
}
```

is fromJson allready defined (is it a inbuilt funciton? ) , is it a static funciton because we only call static function like Classname.staticfunction , why can it be writen like :- ```dart
fromJson(Map<String, dynamic> json) {
    this.token = json['authtoken'];
    this.success = json['success'];
}
```
10 Common startup struggles faced by scalable startups.
Tags: beginners, news
Published: 2023-02-28 09:41:16

10 Common startup struggles faced by scalable startups.
Starting a business is a daunting experience, especially for entrepreneurs who are just getting their feet wet. Common startup struggles include finding the right funding, managing cash flow, and developing a successful marketing strategy. Securing funds for a new venture can be a challenge. Not all entrepreneurs have the resources to finance their business out of pocket, so seeking out investors, [Investment Banking Company For Scalable Startups](https://solisventures.in/) or applying for loans can be necessary. Business owners must also manage their cash flow and find ways to keep their business afloat during the early stages before they’re generating enough revenue to become profitable. Marketing can also be a hurdle for new startups. Creating an effective marketing strategy by [Business Incubators in India](https://solisventures.in/business-incubators/) requires research and creativity, and it can be difficult to get the attention of potential customers and stand out from the competition. Businesses must also decide which channels to use to reach their target audiences, such as social media, email, or search engine optimization (SEO). Building a successful business from the ground up is a long and difficult process but [business incubators and accelerators in India](https://solisventures.in/business-incubators/) will helps you to find the best solution for the same, and it comes with its fair share of struggles. However, by taking the time to research and plan, entrepreneurs can overcome these common startup struggles and put their businesses on the path to success.
These are common problems:
1. Finding the right team
2. Securing funding
3. Developing a product
4. Establishing a customer base
5. Creating a brand identity
6. Managing cash flow
7. Overcoming legal hurdles
8. Developing a marketing strategy
9. Staying organized
10. Keeping up with the competition