teleren/devto huggingface dataset:
How to use Observers in Laravel?
Tags: laravel, php, webdev
Published: 2021-12-04 07:57:51

So what are observers in Laravel and why you should use them?

### 1. Definition
Observers in Laravel help you to fire multiple events or do a CRUD operation in database!

When you create an observer, it will listen to a specific condition for a model, e.g: if user create a post and he/she achieved a certain level, the observer will fire related method(event) and do what ever you wrote!

### 2. Real Example
In this world websites, there are so many things we want to do after a user registered in our website! e.g: send an email, send SMS and etc... So why not leave them to Observers!

First, run this command to make a user observer (for User model):

`php artisan make:observer UserObserver --model=User`

Second, you will see four methods in it, that will run when their condition are true. these methods are:

```php
namespace App\Observers;

use App\Models\User;

class UserObserver
{
    /**
     *  Will do what you want When an instance of model created 
     *
     * @param  \App\Models\User  $user
     * @return void
     */
    public function created(User $user)
    {
        //
    } 

    /**
     * Will do what you want When an instance of model updated
     *
     * @param  \App\Models\User  $user
     * @return void
     */
    public function updated(User $user)
    {
        //
    }

    /**
     * Will do what you want When an instance of model deleted
     *
     * @param  \App\Models\User  $user
     * @return void
     */
    public function deleted(User $user)
    {
        //
    }

    /**
     * Will do what you want When an instance of model force deleted
     *
     * @param  \App\Models\User  $user
     * @return void
     */
    public function forceDeleted(User $user)
    {
        //
    }
}

```

You should know there is some other functions like: `creating, updating, saving, afterSaving, restore` and etc... so you have a handful feature observer for many situations.

Maybe we just want to send a welcome message to user whenever he/she registered!
we may use `create()` method, as below:

```php
public function created(User $user)
{
    Mail::to($user)->send(newUserRegisteredMailable($user));
}
```

And third one is registering our observer in the boot method of your application's `App\Providers\EventServiceProvider` service provider: 

```php
use App\Models\User;
use App\Observers\UserObserver;

/**
 * Register any events for your application.
 *
 * @return void
 */
public function boot()
{
    User::observe(UserObserver::class);
}
```

That's it.
Boost your cloud career with Google Cloud
Tags: googlecloud, cloud, gcp, career
Published: 2021-12-04 07:42:25

The Word "TECHNOLOGY" gives us an idea to learn many new things as we are used to many technologies and we are surviving with them this is a boon for many learners, programmers or anyone else who is interested in new technologies. Recently, many learners/students are giving their attention to Cloud Computing as it’s a new platform to learn and to explore many things on Cloud. Cloud Computing delivers computer services including servers, storage, databases, networking, software, analytics, and intelligence over the Internet (Here we called Internet as "cloud") to provide flexible resources. One famous platform is Google Cloud Platform(GCP) as the name suggests it is a suite of public cloud computing services offered by Google that means infrastructure that Google uses internally for its end-user products, such as Google Search, Gmail, file storage, and YouTube.

Google Cloud Platform is the new platform compared with Amazon Web Services and Microsoft, but their services are worth considering. The company is constantly improving to make services easy and reliable.
The Platform provided by Google Cloud helps us to build, test and deploy applications on Google's big infrastructure. We will see a wide range of services provided by Google like computing, storage, application services for our web, backend, mobile solutions.

What makes Google Cloud Platform different?
1)Google grade security is an end-to-end process.
2)Billing by the second.
3)Big Data.
4)Global Network.
5)Environmentally friendly.

The Architecture of Google Cloud Platform:-

 1)The google cloud architecture defines how the flow of data takes place in the Google Cloud.
 2) The use of different services it offers to a user.
 3) It shows how storage and processing of information take place in a google cloud
Challenges faced by open source projects in 2022
Tags: opensource, programming, productivity, discuss
Published: 2021-12-04 07:38:46

Open-source community platforms have become so successful not primarily for cost reasons but because of decentralization, speedy development cycles, and availability to everyone. Many people rely on open-source software in one way or another, and numerous people see the benefits of open source from a distinct viewpoint.

However, open-source has had a more profound impression on people, culture, and our society. Open-source software and monetization dynamics have changed drastically, transforming how products and services are developed and delivered.

Today's article will discuss some of the significant problems with the modern trend in open-source development and present you with solutions to mitigate them. Let's look into some basics of open-source software before we get started.

##What is Open-Source?
Open Source software, for most of us, is free software to just save a few bucks. People just Google for something like "free photo editing software" and are glad to get something free suited to their needs. But Open Source is much more than that. Open source is just not free software. It is the software with which you have the freedom to change the source code of the Open Source software. This is the greatness of the Open Source Movement. The Open Source movement is about letting the software evolve, grow with people from all over the world contributing to the software rather than keeping the code restricted to a few developers.

For some of us, it would sound alien. Why would anyone work on something and then give it away for FREE? Whether to make the source code open for a software definitely lies with the software developer, but that is essentially a secondary issue. The most important fact is that Open Source is not only free. It's the freedom to evolve and to create.

##Read complete article on Aviyel

[Aviyel | Challenges faced by open source projects in 2022](https://aviyel.com/post/1449/challenges-faced-by-open-source-projects-in-2022)
Where to test in Continuous Testing
Tags: testing, devops, testautomation
Published: 2021-12-04 07:37:37


> Continuous testing is the process of executing automated tests as part of the software delivery pipeline to obtain immediate feedback on the business risks associated with a software release candidate. - Wikipedia

Here I found a nice visualization(from [continuous testing in devOps](https://danashby.co.uk/2016/10/19/continuous-testing-in-devops/)) for where we can/should test in devOps:

![Where to test in devOps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9fsymz6mjh8h7n3tmp3.jpeg)
C# : Use IQueryable<T> as part of Unit Test
Tags: csharp, unittest, iqueryable
Published: 2021-12-04 07:37:06

I sometimes need to write unit tests which uses IQueryable<T>. For example, a repository or a service returns IQueryable<T>, which I need to use inside unit test.

# Scenario

Let's say I have an interface which returns IQueryable<string>.

```csharp
public interface IMyService
{
    public IQueryable<string> GetPeopleQuery();
}
```

And then I need to test the following class.

```csharp
public class SomeClass
{
    private IMyService myService;
    public SomeClass(IMyService myService)
    {
        this.myService = myService;
    }

    public List<string> HelloToPeople()
    {
        var people = myService.GetPeopleQuery().ToList();
        var helloPeople = people.Select(x=>x.Insert(0, "hello ")).ToList();
        return helloPeople;
    }
}
```

# Write Test

I use xUnit as an exmaple. I create IQueryable<string> from the expected result and use it as ``Mock.Setup``.

```csharp
[Fact]
public void TestHello()
{
    var dummyQuery = (new List<string>() { "ken", "nozomi" }).AsQueryable();
    var mockedIMyService = new Mock<IMyService>();
    mockedIMyService.Setup(x => x.GetPeopleQuery()).Returns(dummyQuery);

    var someClass = new SomeClass(mockedIMyService.Object);
    var results = someClass.HelloToPeople();

    Assert.Equal("hello ken", results.First());
    Assert.Equal("hello nozomi", results.Last());
}
```

That's it.
This is How you get sum of all the elements of different lists!
Tags: dart, programming, tutorial, productivity
Published: 2021-12-04 07:29:41

Hey, if you ever wondered how you get sum of all the elements in different lists, this is how you do it.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ruljf1uhovvfx17hua7m.PNG)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0w7xgccapx7drmcuc82.PNG)
Hover effects with Hover.css
Tags: css, html, npm, beginners
Published: 2021-12-04 07:24:12

Hello Guys today i am going to discuss a library named Hover.css which helps you to give hover effects to your elements by just using the class names.

What is Hover.css?
* A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.
* You dont need to write any css to make those effects it will apply the effect by just writing the class name of that effect in your html element.

* Its easy to use
* It has many hover effects which can be applied to many elements
* You can use these hover effects with javascipt or Reactjs as well.

Installation - 
```
npm install hover.css --save
```

Example 1 -

```javascript
  <div className='text-center my-5'>
      <button className='btn btn-outline-dark hvr-shutter-out-horizontal'>
        Click
      </button>
  </div>
```

Explaination - 
* I have created a button element, The class name hvr-shutter-out-horizontal will create a shutter effect when you hover over the element.
* This is same as using bootstrap in which you provide the styling to the element by just providing the class name of that style.

NOTE - You have to write "hvr-" first then class name of the effect you are using , like for a fade effect we have to write 
class="hvr-fade".

Example 2 - 
```javascript
 <div className='text-center my-5'>
      <button className='btn btn-outline-dark hvr-fade'>
        Click
      </button>
 </div>
```

* This time we have give the class name "hvr-fade" and it will give a fade effect when you hover over the element.

Other commont effects classnames are -
hvr-grow
hvr-shrink
hvr-pulse
hvr-bounce-in
hvr-float
hvr-sweep-to-right
hvr-sweep-to-left
hvr-bounce-to-top
hvr-rectangle-in
hvr-rectangle-out
etc....


IMPORTANT - 
* The link below will take you to hover.css documentation page where you will see all the effects and their name.

* All the effects are named Uppercase but you have to write the class names with lowercase and "-".

Example - if the class name written there is -
BOUNCE IN, then you have to write "hvr-bounce-in"
FADE, then you have to write "hvr-fade"
BOUNCE TO TOP, then you have to write "hvr-bounce-to-top"
etc...

SOURCE - https://ianlunn.github.io/Hover/


NOTE - I have used bootstrap in my codes so , use it by providing CDN in your html file or install it via npm.

THANK YOU FOR READING THIS POST AND IF YOU FIND ANY MISTAKE OR WANTS TO GIVE ANY SUGGESTION THEN PLEASE MENTION IT IN THE COMMENT SECTION.
Promises in Javascript!!!
Tags: javascript, beginners, webdev
Published: 2021-12-04 07:13:33

P..p..p..promise? Like a bond? Is this a developer blog or an English article? Well, apparently Javascript developers have to deal with promises in their coding life too, and this blog might just be the perfect spot for making you understand what this fuss is all about!

###What exactly is a 'Promise'?

A promise, in the simplest language, is a container that is going to store some data in the future time. Going deeper, it is an object, that has multiple states and will return some values depending on if it was successfully resolved, or rejected.

>A promise has 3 states, either pending, resolved(fulfilled) or rejected.

###Initialising a Promise in Javascript
![Code for initializing a promise](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9k3tcum29biztfzsz0g.png)

###".then", ".catch" and ".finally" in Promises

Long story short, we can chain methods with promises. The '.then' method is chained with a promise which is then used to handle the promise when it is resolved i.e. the callback function inside the '.then' method is executed and it CAN return another promise(it's not compulsory though). The '.catch' method is chained with the promise and is executed when the promise gets rejected(this block is usually the exception handling block). The callback function which is inside the '.finally' method always gets executed, doesn't matter if the promise was rejected or resolved. 

![Promises chaining method syntax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yer4t3bo4v3rhdza1vbk.png)
>Things I'd love you to know

- Promises are asynchronous.

- Promises have a different queue(from callbacks) in the background and the Event Loop prioritizes the promise queue over the callback queue, hence it won't execute any callbacks until all the promises inside the promises queue get exhausted.

- Promises are generally preferred over callbacks because there is no possibility of falling into the callback hell when working with promises.
Awesome Golang Audio and Music Libraries
Tags: go, audio
Published: 2021-12-04 06:50:54

## Audio and Music

*Libraries for manipulating audio.*

* [flac](https://github.com/mewkiz/flac) - Native Go FLAC encoder/decoder with support for FLAC streams.
* [gaad](https://github.com/Comcast/gaad) - Native Go AAC bitstream parser.
* [GoAudio](https://github.com/DylanMeeus/GoAudio) - Native Go Audio Processing Library.
* [gosamplerate](https://github.com/dh1tw/gosamplerate) - libsamplerate bindings for go.
* [id3v2](https://github.com/bogem/id3v2) - ID3 decoding and encoding library for Go.
* [malgo](https://github.com/gen2brain/malgo) - Mini audio library.
* [minimp3](https://github.com/tosone/minimp3) - Lightweight MP3 decoder library.
* [mix](https://github.com/go-mix/mix) - Sequence-based Go-native audio mixer for music apps.
* [music-theory](https://github.com/go-music-theory/music-theory) - Music theory models in Go.
* [Oto](https://github.com/hajimehoshi/oto) - A low-level library to play sound on multiple platforms.
* [PortAudio](https://github.com/gordonklaus/portaudio) - Go bindings for the PortAudio audio I/O library.
* [portmidi](https://github.com/rakyll/portmidi) - Go bindings for PortMidi.
* [vorbis](https://github.com/mccoyst/vorbis) - "Native" Go Vorbis decoder (uses CGO, but has no dependencies).
[Awesome Go libraries](https://golangd.com/)
About Sushant Gupta Defsys : MyCorporateinfo.
Tags: sushantguptadefsys, sushantgupta, defsyssolutions
Published: 2021-12-04 06:36:42

Defsys Technical Services Director **Sushant Gupta** registered with Ministry of Corporate Affairs(MCA) whose (DIN) Director Identification Number is - 2979. **Sushant Gupta** listed with 13 Indian companies.


**Directorship Holding Active Companies of Sushant Gupta-**


1. Dmg Finance And Investments Private Limited is active Company in which Sushant Gupta was appointed the director on 04-08-1999.

2. Actia India Private Limited is active Company in which Sushant Gupta was appointed the director on 12-06-2002.

3. Dm South India Hospitality Pvt Ltd is active Company in which Sushant Gupta was appointed the director on 24-10-2005.

4. Spiral Ehl Engineering Private Limited is active Company in which Sushant Gupta was appointed the director on 18-01-2006.

5. Horizon Aerospace (India) Private Limited is active Company in which Sushant Gupta was appointed the director on 01-02-2006.

6. Horizon Air Support Maintenance (India) Private Limited is active Company in which Sushant Gupta was appointed the director on 07-07-2008.

7. Defsys Technical Services Private Limited is active Company in which Sushant Gupta was appointed the director on 23-01-2009.

8. Dm Power Private Limited is active Company in which Sushant Gupta was appointed the director on 23-09-2009.

9. Chowgule Resorts Private Limited (Goa) is active Company in which Sushant Gupta was appointed the director on 01-07-2013.

10. Bds Developers Private Limited is active Company in which Sushant Gupta was appointed the director on 01-10-2018.

11. Avitronics Defense And Aerospace Private Limited is active Company in which Sushant Gupta was appointed the director on 09-04-2021.


**Directorship Holding Amalgamated Companies of Sushant Gupta -**


12. Spiral E-Systems Private Limited is amalgamated Company in which Sushant Gupta was appointed the director on 13-11-2007.

13. Chowgule Resorts Private Limited (Delhi) is amalgamated Company in which Sushant Gupta was appointed the director on 01-07-2013.
Swift Utilities for writing to and reading from the device log
Tags: swift, log
Published: 2021-12-04 06:30:43

### Logging
*Utilities for writing to and reading from the device log* 

* [AEConsole](https://github.com/tadija/AEConsole) - Customizable Console UI overlay with debug log on top of your iOS App.
* [CleanroomLogger](https://github.com/emaloney/CleanroomLogger) - Configurable and extensible high-level logging API that is simple, lightweight and performant.
* [Duration](https://github.com/SwiftStudies/Duration) :penguin: - Lightweight logging library focused on reporting timings for operations.
* [Gedatsu](https://github.com/bannzai/gedatsu) - Provide readable format about AutoLayout error console log.
* [HeliumLogger](https://github.com/Kitura/HeliumLogger) :penguin: - IBM's lightweight logging framework.
* [Printer](https://github.com/hemangshah/printer) - A fancy logger for your next app.
* [Puppy](https://github.com/sushichop/Puppy) :penguin: - A flexible logging library that supports multiple transports and platforms.
* [Puree](https://github.com/cookpad/puree-ios) - A log collector for iOS.
* [QorumLogs](https://github.com/goktugyil/QorumLogs) - Logging Utility for Xcode & Google Docs.
* [Rainbow](https://github.com/onevcat/Rainbow) :penguin: - Delightful console output.
* [SwiftyBeaver](https://github.com/SwiftyBeaver/SwiftyBeaver) :penguin: - Multi-platform logging during development & release.
* [TinyConsole](https://github.com/Cosmo/TinyConsole) - A tiny log console to display information while using your iOS app.
* [TraceLog](https://github.com/tonystone/tracelog) :penguin: - Dead Simple: logging the way it's meant to be!  Runs on iOS, macOS, and Linux.
* [Watchdog](https://github.com/wojteklu/Watchdog) - Utility for logging excessive blocking on the main thread.
* [WatchdogInspector](https://github.com/tapwork/WatchdogInspector) - A logging tool to show the current framerate (fps) in the status bar of your iOS app.
* [Willow](https://github.com/Nike-Inc/Willow) - Willow is a powerful, yet lightweight logging library.
* [XCGLogger](https://github.com/DaveWoodCom/XCGLogger) - Full featured & Configurable logging utility with log levels, timestamps, and line numbers.

[A curated list of awesome Swift frameworks, libraries and software](https://swiftobc.com/)
Day 2 Solution in JavaScript - Advent of Code 2021
Tags: javascript, adventofcode, webdev, beginners
Published: 2021-12-04 06:27:55

In this article I will be going to show you a solution of Day 2 of Advent of Code 2021 in JavaScript.


Let's get started,

- Let's get the input
```js
   
const fs = require('fs')
const input = fs.readFileSync('input.txt').toString()

const inputArray = input.split('\n').map(command => command.split(' ')).map(command => [command[0], +command[1]])
```

- For part 1
```js
// First Part

const position = {horizonatal: 0, depth: 0}

for (const [command, value] of inputArray) {
  switch(command){
    case 'forward':
      position.horizonatal += value
      break;
    
    case 'down':
      position.depth += value;
      break
    
    case 'up':
    position.depth -= value
    break

    default:
      console.log('invalid', command, value)
      break
  }
}

console.log(position.horizonatal * position.depth)
```

- For Part 2
{% youtube iIAHpR_7HeQ %}
Awesome flutter image components
Tags: flutter
Published: 2021-12-04 06:25:32

### Image

- [Carousel Slider](https://flutterrepos.com/lib/serenader2014-flutter_carousel_slider-flutter-image) [1161⭐] - Carousel slider widget, support infinite scroll and custom child widget by [serenader](https://github.com/serenader2014).
- [Parallax Image](https://github.com/pulyaevskiy/parallax-image) [238⭐] - Image parallax by [Anatoly Pulyaevskiy](https://github.com/pulyaevskiy).
- [Photo View](https://github.com/renancaraujo/photo_view) [1461⭐] - Scalable image view with loading placeholder by [Renan C. Araújo](https://github.com/renancaraujo).
- [SVG](https://github.com/dnfield/flutter_svg) [1259⭐] - SVG parsing, rendering, and widget library by [Dan Field](https://github.com/dnfield).
- [Image Cropper](https://github.com/hnvn/flutter_image_cropper) [811⭐] - Crop your images support ratio, rotation, zoom by [HungHD](https://github.com/hnvn).
- [Cached Network Image](https://github.com/renefloor/flutter_cached_network_image) [1882⭐] - Show images from the internet and keep them in the cache directory by.
- [Lottie](https://github.com/xvrh/lottie-flutter) [627⭐] - Use airbnb's popular [After Effects Animation library](https://airbnb.design/lottie/) by [xvrh](https://github.com/xvrh/lottie-flutter).
- [Bitmap](https://github.com/renancaraujo/bitmap) [126⭐] - Perform Bitmap manipulations (such as contrast and exposure) with a help from the Dart FFI by [Renan C. Araújo](https://github.com/renancaraujo).
- [Crop](https://github.com/xclud/flutter_crop) [169⭐] - Crop any widget/image in Android, iOS, Web and Desktop by [Mahdi K. Fard](https://github.com/xclud/).

#### Image Picker

- [Image Picker](https://github.com/flutter/plugins/tree/master/packages/image_picker) - Images Selection by [Collin Jackson](http://www.collinjackson.com).
- [WeChat Assets Picker](https://github.com/fluttercandies/flutter_wechat_assets_picker) [788⭐] - Assets picker in WeChat style, support multi assets by [Alex Li](https://github.com/AlexV525).
[Awesome Flutter libraries](https://flutterrepos.com/)