teleren/devto huggingface dataset:
Methods in Ruby
Tags: ruby, rails, programming, webdev
Published: 2021-09-05 14:29:25

Methods or Function in ruby allows us to put our code in a container and call it when necessary. This allows reusability and prevent duplication ,take for  instance we want multiply 3 different pairs of number 9 time we would do this


```
puts "#{3 * 4}"
puts "#{1 * 0}"
puts "#{8 * 2}"
puts "#{7 * 6}"
.....

```
 This would be a very long and repetitive process but with methods we can do this.

```
def multiply(a,b)
    a*b
end
multiply(3,4)
multiply(1,0)


```
This is easier to maintain and be used by anyone
Typescript Readonly utility
Tags: typescript, angular, react, programming
Published: 2021-09-05 14:04:17

Readonly<Type>

Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned.

Example
```
interface Todo {
  title: string;
}
 
const todo: Readonly<Todo> = {
  title: "Delete inactive users",
};
 
todo.title = "Hello";
```
Cannot assign to 'title' because it is a read-only property.

Released:
2.1
Refencence: Typescript offical documentation
Cleaner models with Laravel Eloquent Builders
Tags: laravel, php
Published: 2021-09-05 14:02:44

Over the past few years I have created tons and tons of models in Laravel. These models have always blown up in size with tons of accessors and added scopes. For the unintroduced, model scopes are methods containing queries that can be chained while retrieving data from the database. For example:
```php
// Models/Article.php
class Article extends Model
{
    public function scopePublished(Builder $builder)
    {
        return $builder->whereNotNull('published_at');
    }
}

// usage of the scope
Article::published()->get();
```

As you might imagine, these methods will add up after a while resulting in bloated models, but what if I tell you that you can clean this up easily?

## Writing your own Eloquent Builder

It's possible to create your own Eloquent Builder and bind it to your models. This can be done by creating a class which extends the Eloquent Builder. I'll use the example above for the model that we will clean up. So let's start by creating a ArticleBuilder. It doesn't really matter where you place it, but I tend to create a directory for it in the App namespace.

```php
<?php

declare(strict_types=1);

namespace App\EloquentBuilders;

use Illuminate\Database\Eloquent\Builder;

class ArticleBuilder extends Builder
{
    public function published(): self
    {
        return $this->whereNotNull('published_at');
    }
}
```

As you can see, it uses the same methods as before, because the scope uses a query builder in the background! 

## Registering your brand new Eloquent Builder
Now all that's left is to bind our custom query builder to the Article Model. This can be done by overriding the newEloquentBuilder method. After overriding it, you can remove any of the old scopes. Your end result will look something like this!

```php
<?php

declare(strict_types=1);

namespace App\Models;

use App\EloquentBuilders\ArticleBuilder;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use HasFactory;

    public function newEloquentBuilder($query): Builder
    {
        return new ArticleBuilder($query);
    }
}
```

## Using our new builder
Using your brand new query builder is just the same as with the scopes. All you need to do is chain it on your query like you usually do.
```php
Article::published()->get();
```
In the end nothing changed functionality wise, but your model just became a lot cleaner.
Typescript Record utility
Tags: typescript, javascript, angular, react
Published: 2021-09-05 13:59:48

Record<Keys,Type>


Constructs an object type whose property keys are Keys and whose property values are Type. This utility can be used to map the properties of a type to another type.

```
Example
interface CatInfo {
  age: number;
  breed: string;
}
 
type CatName = "miffy" | "boris" | "mordred";
 
const cats: Record<CatName, CatInfo> = {
  miffy: { age: 10, breed: "Persian" },
  boris: { age: 5, breed: "Maine Coon" },
  mordred: { age: 16, breed: "British Shorthair" },
};
 
cats.boris;
 
const cats: Record<CatName, CatInfo>
```
Released:
typescript 2.1

reference :Typescript offical documentation.
How to swap first byte with last byte without shifting in C?
Tags: c, bytes, shift, swap
Published: 2021-09-05 13:50:15

---
title: How to swap first byte with last byte without shifting in C?
published: true
description: 
tags: C, bytes, shift, swap
//refrence: https://stackoverflow.com/a/2182581/1437877
---

We have a hexadecimal number 0x12345678 and we need to swap it like this 0x78345612, observe first and last bytes swapped.

We can do this using byte swapping method as follows:

```C
#include <stdio.h>

int swap_first_to_last_byte_shift_method(int num)
{
    int res;
    int b0, b1, b2, b3;
    // Left shift the last byte 24 times.
    // 1 byte = 8 bits
    // For 3 bytes it needs be shifted 8*3 = 24 times.  
    b0 = (num & 0x000000ff) << 24;
    b1 = (num & 0x00ff0000);
    b2 = (num & 0x0000ff00);
    b3 = (num & 0xff000000) >> 24;
    res = b0 | b1 | b2 | b3;
    return res;
}

int main()
{
    int num = 0x12345678;
    int res = swap_first_to_last_byte_shift_method(num);
    printf("Input  %x\n", num);
    printf("Output %x\n", res);
}

```
It shall produce the output as follows:
```
Input  12345678
Output 78345612
``` 
How the same can be done without using byte shift?
```C
#include <assert.h>
#include <stdio.h>

void swap_first_to_last_memory_shift_method(void *pv, size_t n)
{
    // assert size of the input is greater than 0
    assert(n > 0);
    char *p = pv;
    // Assign the first byte to a temporary variable
    char temp = p[0];
    // Swap last to first.
    p[0] = p[n-1];
    // Swap last to the temp
    p[n-1] = temp;
}

// Macro to swap
#define SWAP_FRIST_TO_LAST(x) swap_first_to_last_memory_shift_method(&x, sizeof(x));

int main()
{
    int num = 0x12345678;
    printf("Input   %x\n", num);
    // In this method the swap at memory address level.
    // Hence no need to for additional variables.
    SWAP_FRIST_TO_LAST(num);
    printf("Output  %x\n", num);
}
```
This produces the output as follows:
```
Input  12345678
Output 78345612
```

Refrence https://stackoverflow.com/a/2182581/1437877
Lead Tracker 
Tags: webdev, javascript, html, css
Published: 2021-09-05 13:31:28

Lead Tracker is a google chrome extension which helps user to save current active page url.

It is beneficial for sales purposes where this extension can be use to save and access leads easily.

This is a small side project for beginners who are starting as front end dev.

Find the source code in my GitHub profile. Please feel free to drop a feedback on this and how I can improve more in this

https://github.com/muditbansal09/Lead-Tracker
Laravel Invokable Controller
Tags: laravel, php
Published: 2021-09-05 13:30:58

Hello to everyone! In this article, we will examine how the `__invoke` method is used in the Laravel controller.

First of all, let's see what the `__invoke` method in php does:
The `__invoke` method is called [**Magic Method**](https://www.php.net/manual/en/language.oop5.magic.php). Used to make a class run as a function.

To use this in Laravel, it is necessary to use `--invokable` as a parameter when creating the controller with the help of `artisan`.

```bash
php artisan make:controller UploadController --invokable
```

After running the bash command above, a controller class will be created as follows:

```php
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\User;

class UploadController extends Controller
{
    /**
     *
     * @return \Illuminate\Http\Response
     */
    public function __invoke()
    {
        // ...
    }
}
```

After doing the work you want to do for the application in the `__invoke` method in the controller, we need to define the controller in `routes`. To define the API, it can be added as follows.

```php
// routes/api.php

Route::post('upload', UploadController::class);
```

As a result, you can use an `invokable` controller when you only want to use a single method in a controller class and you don't need basic methods (index, store, update etc.) in the controller. 

Happy coding! :partying_face:
Ruby Comparison operator
Tags: ruby, rails, programming, webdev
Published: 2021-09-05 13:29:18

What are comparison operators they are basically used to compare two items and they always return a Boolean(True or False)

1.== : equal to
2.!=: not equal to
3.>:greater than
4.>=: greater than or equal to
5.<>:not equal to
6.<=:less than or equal to
7.<:less than
8:eql>():To compare types


This operators can be used to compare any data type in ruby .Feel free to play around with .Hope to see you in the next section where we dive deep or deeper into conditional operators.
Top Digital Marketing Companies in India
Tags: digitalmarketing
Published: 2021-09-05 13:21:03

Looking For A Top Digital Marketing Companies in India
Digital marketing has always shaped how businesses attract consumers and create wealth. So if you're thinking of choosing a digital marketing company to assist you to increase your brand image, place your business in SERP, or maintain your social media appearance, we're here to support you.
To support you in your search for a partner, we've collected this list of India's top digital marketing companies. Browse information, feedback, and grants to determine which can completely satisfy your business requirements. 
Top digital Marketing companies in India
1.SmartfocusDigital
2.WebFx
3.Digimarkagency
4.5ines 
5.Vistasadindia
6.Manal Agency
7.Digion
8.SparkSys
9.Hashtag 7
10.Web Logics

<a href="https://smartfocusdigital.com//">Digital Marketing</a> is board area that can be done with best digital marketing companies who are expertise and having years of experience in building brand awareness
Rest Assured E2E Testing - Part 3
Tags: apitesting, restassured, automationtesting
Published: 2021-09-05 13:05:58

#Setup A Basic REST Assured Maven Project In Eclipse IDE

In this post we will learn to setup a Maven – REST Assured in Eclipse IDE.

##Pre-requisites
To begin your project, you must have the following installed and configured on your computer.
Java and Eclipse IDE •
 TestNG which is unit testing framework • 
Maven (either we can add jar file manually to our project or we can create a maven project)

Lest’s get started with creating the project.

##Creating Maven Project in Eclipse

1. Open eclipse and click on File> New> Project
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnby0jiilstjfel36gw2.png)
 
2. In the wizard text box, type Maven and then select Maven from the list box, as shown below. Click the Next> button.

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

3. Click on Next button(select maven-archetype-quickstart) 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u47uys06h72zs1tf4fgp.png)

4. Type in the Group Id and Artifact Id (You can give any name to that) and click Finish button 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1ma6f2cyfmoyje0k32e.png)
 
5. Finally, the Maven Project “RESTAssured_APITesting” is successfully created. Please keep in mind that this Maven project generates pom.xml, as highlighted and shown below.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ci98gk1k33wcaipw2fz.png)

6. Add dependency of rest assured in pom.xml. For getting maven dependency, visit Maven Repository.  
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pg9u1051la631pe0la6p.png)

7. Add Maven dependency of TestNG/Junit in your framework. These tests framework will help in managing tests. TestNG is preferable as compared to Junit because of additional features in TestNG. You can copy the dependency from Maven Repository and then paste it in pom.xml.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wv4msg0d7lw64j1g22x.png)

8. Add Maven dependency of Jackson JSON java parser and JSON Schema Validator in pom.xml. JSON Schema Validator will be used to validate JSON Schema while JSON java parser will be used for parse JSON to map java objects to and from JSON. 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28pgyykcj4zl4945ik1b.png)

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

9. Install hamcrest Assertion 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wo4xxvrzdj64cpx4dvov.png)

10. After adding all the dependencies, the final pom.xml will look just like below.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebdq47kpu0gkx699qrpt.png)

11. After successful addition of dependencies, you will see JAR files in Maven dependencies in your project structure.  

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewuo4scuzi37y3a24324.png)
VIM Quick Tip: Convert Motion to Upper- or Lowercase
Tags: vim, vscode
Published: 2021-09-05 12:58:59

This is part of a series of posts that give you very small, quick tips on how to do things in VIM. This time: converting motions to upper- or lowercase. There are many ways to do this, but this is the one I'm using.

Suppose you have the following "word": `screaming_snake`

If you wanted to convert that to uppercase, move to the beginning of the word and type `gUw` from normal mode, where `w` is the word motion. This will give you `SCREAMING_SNAKE`. Now, if you hit `guw`, it will revert back to the original.
Task force [ Week one ]
Tags: programming
Published: 2021-09-05 12:56:01

I would like to talk about my experience during the past first week in the Awesomity lab taskforce.

I had a great welcoming session that was all about introductions and mindfull sessions with interesting games that helped us to get to know each other very well.

The program is hybrid meaning that some sessions are remote and others on site.

On the following day we had a Fun coding war that helped us get a mind boost to get into the coding game for the rest of the day with the team. continuing in the afternoon with working on projects like ATM which was really fun!

Following with remote sessions, where we get to learn about communication skills and soft skills at the same time from great and professional people.

And then there comes the interesting !!friyay!! where we had very interesting sessions and games with the official Awesomity team!

All in all, i tried to breakdown each and every detail and  to make it as short as possible, but the bootcamp is great and currently taking my skills to the next level with awesomity lab HERE WE GO!!!
Rest Assured E2E Testing - Part 1
Tags: restassured, apitesting, automation
Published: 2021-09-05 12:45:59

#API Testing Process Using REST Assured 
APIs enable risk-free legacy modernization and drive businesses toward digital transformation. APIs must be precisely optimised to meet a specific business request in a specific context. API testing is the key to success in ensuring a robust API. API testing can be done manually using POSTMAN tools or automatically using Rest Assured dependency code. We'll talk about API testing with REST Assured in this section.

#What is REST Assured?
Rest Assured is a Java-based library for testing RESTful Web Services. The fact that this is a Java-based library of course does not matter because REST Assured is based only on JSON and HTTP . These are language-independent, we can use REST Assured to create tests for applications written in any language. To access REST web services, this library acts as a headless client. In just one line, we can create a complex HTTP request.
REST Assured also provides us with a lot of validations to our requests, such as for example Status Code, Status Response, Headers, or even Body response. This means that the library is really flexible when it comes to testing.

##Advantages of Rest Assured
1.	Open source, and hence, it is free of any license cost
2.	Based on Java
3.	Offers support for all kinds of HTTP methods like POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD
4.	Supports both path and query parameters
5.	Supports the BDD/Gherkin style of writing, which supports clean coding & enhances readability
6.	Enables easy integration with classic testing & reporting frameworks such as TestNG, JUnit runner and Allure Report
7.	One can test an application written in any language like Java, .Net, Python, Ruby, etc.
8.	JSON schema validation can be performed
9.	Makes it easy to test and validate REST services in the Java domain which is usually tough
10.	Now let us look at how we an perform API testing with the help of REST Assured.


##Disadvantages of Rest assured
1. Requires knowledge of the Java programming language.
2. Does not support SOAP APIs explicitly.
What is the correct HTML for referring to an external style sheet?
Tags: css, html, beginners
Published: 2021-09-05 12:03:59

## TL;DR Summary

Here is the correct HTML for style sheet referral:
*[ copy-paste and thank me later :) ]*

```html
<link href="style.css" rel="stylesheet" type="text/css" />
```
Also, make sure you put this line either in the ***&lt;head&gt;*** or somewhere near the top of the page like this:

![external style sheet code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tl4d9cj9dkjytrmref8u.png)

And this is it.

Until next time,
*Will*
*[Building an Algo-Trading Hedge Fund From Scratch](https://programmermoney.com/)*
Today's Daily Dose of Programming Humor
Tags: jokes, dailydeveloperjokes
Published: 2021-09-05 12:00:24

---
title: "Today's Daily Dose of Programming Humor"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258eb1a429.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ Why was the developer's family upset with them at dinner?

___A:___ They forgot to git squash before going home
 -->
[Part 1/4] 🌐 Senior Backend Architecture Interview With a Senior Software Engineer
Tags: architecture, webdev, tutorial
Published: 2021-09-05 11:57:20

**About Me:** I've been a professional web developer for just over 10 years now. I'm currently the lead web development instructor at [Better Coding Academy](https://codebetter.com.au), and as part of what I do, I post videos on our YouTube channel at [https://www.youtube.com/c/BetterCodingAcademy](https://www.youtube.com/c/BetterCodingAcademy).

_(Subscribe for awesome web development content!)_

A second video interview series, this time focusing on backend architecture! In the following video series I'm interviewed by a senior software engineer from one of Australia's largest software companies. We go through a variety of architectural and data modelling concepts as I attempt to tackle the problem for the first time. I hope you enjoy!

{% youtube mo7F_IjizNQ %}

Happy coding!
5 Tips to Quickly Navigate a New Codebase
Tags: beginners, codenewbie
Published: 2021-09-05 11:47:20

So you've just accepted the job offer or the intern position as a developer? 

Congratulations!👏‍‍

*But how will you deal with the codebase on your first day?*

How do you understand the work that's been done to start contributing ASAP? 

Here's how you can do it.

## 1 - Ask for the business use-cases

As a developer, you write software to resolve a problem. 

These problems will come from the business and you'll have to implement the business logic of the solution (software) by coding.

Gathering the use cases will help you dive better into the codebase. 

### A concrete example: a money transfer mobile application. 

A use case (sending money) requires the user to be able to enter receiver details and the amount to be sent.

Knowing this, you just have to find the portion of the code which handles this. 

You can then read it and test it.

## 2 - Run the tests and crash the code

If the team you are joining has the habit to write software tests, then it's definitely a facilitator for you. 

Tests, if well written can describe the business logic as well.

Run the tests, feel free to modify the code to crash it.

If you don't understand a portion of the code, comment/remove this portion and run the code to see how the whole application behaves. 

If you are used to a debugger, it'll definitely help you understand how things work in the background.

## 3 - Ask questions ... a lot of questions

During the first days of work, your questions will be very well welcomed. 

After all, you've just started. Everyone on the team has the duty to help you get on track as soon as possible.

Use this period of time to ask a lot of questions.

If you don't understand a part of the code, feel free to reach your peers or the seniors in your team.

## 4 - Read, Read, Read a lot

Read everything you can find useful.

Unit tests, documentation, and the code itself. Read it slowly, line by line, and figure out what it’s doing. 

Read as much of it as you can, as often as you can.

## 5 - Don't be afraid to make changes

Don't be afraid to add new features to the codebase. 

Of course, you should review your code and make sure it works. 

And if your team have unit tests implemented, you can be confident your code won't go to production if there is an issue.

## Conclusion

In this article,  I gave you 5 tips you can use to quickly get familiar with a new codebase.

And as every article can be made better so your suggestion or questions are welcome in the comment section. 😉
Working with numbers Ruby
Tags: ruby, rails, webdev, programming
Published: 2021-09-05 11:32:25

We shall be using [Replt](https://replit.com/) as our play ground environment for ruby.

Numbers in ruby can be integer or float depending on how it was specified 

```
puts "Enter first number"
var1.to_i = get.chomps

puts "Enter second number"
var2.to_i = get.chomps

puts "your result is #{var1.to_i + var2.to_i}"

```
to_i:convert to string
to_f:convert to float
rand:generate random value 
.time:repeat a variable by x times


```
20.times {rand(100)}


```
You can guess the answer i owe you a bottle of beer.You can experiment with more arithmetic operators like + ,/,-,%