RxJS 6 Patterns with Angular Material: Refresh Button

RxJS + Angular + Material

In this article, we’ll be looking at a very simple RxJS 6 pattern that allows us to easily refresh data coming from REST APIs (or any other async data source).

In Angular, we’ll be using a service to handle most of the work, including the data fetching and the refresh logic.

Let’s look at a mock service that we’ll be using to fetch some data from a REST API.

TypeScript
export class MockService {

  refresh$ = new ReplaySubject(1);
  data$: Observable<SomeDataType>;

  constructor(private http: HttpClient) {

    this.refresh();

    this.data$ = this.refresh$.pipe(
      switchMap(() => this.getData()),
      share()
    );
  }

  refresh() {
    this.refresh$.next();
  }

  // This one could also be private
  getData(): Observable<SomeDataType> {
    return this.http.get<SomeDataType>(`url`);
  }
}

Read more

RxJS 6 Patterns with Angular Material: Confirmation Dialog

RxJS + Angular + Material

Intro

This basic pattern applies to RxJS 6 in combination with Angular Material. However, it can be applied to any other environment that supports RxJS 6, as long as you have an observable-based dialog implementation.

Desired behaviour

  1. A user clicks on a button
  2. A confirmation dialog is shown
  3. If the user confirms, an action is performed

Read more

Outer Worlds and The Sunset Simulator

Sunsets

Different planet usually means different atmosphere. Different atmosphere means different optics mumbo-jumbo (thoroughly explained across the internet, like here). Different optical properties usually lead to different sunset colours (and also there seems to be some sort of evidence that the atmosphere composition may be correlated to the ability to support life, but it’s mainly about sunset colours).

Obviously, NASA created a sunset simulator, because why not.

Read more

SASS-only Material Angular Palette generator

SASS Material Angular Palette Generator

With my job, I often need to replicate projects from a template based on Angular Material. When I do that, one of the first things that I usually need to change is the color scheme.

Angular Material’s color scheme is defined by two palettes: primary and accent. These two palettes define a range of colors used by all components.

There are many tools available online to generate such palettes. My personal favourite is Material Design Color Generator (also available on GitHub). This tool includes a code generator that automatically creates a SASS list in Angular Material’s accepted format.

I based my SASS color palette generator on Mikel Bitson‘s code. This is a simple SASS translation that makes it easier to adjust colors directly from your code. 

Read more

Jupiter’s Great Red Spot in 3D

Great Red Spot

It’s been a while since the last post, but this was worth it.

Sometimes, our infinite quest to discover…well, everything…brings us material that is both fascinating and interesting for everyone.
This usually means images instead of numbers, but this time we’re talking about 3D CG awesomeness!

Our casting for the day features Jupiter and Juno, the dynamic duo that certainly doesn’t fear the spotlight.
Their performance? A deep dive into Jupiter’s Great Red Spot, to discover what lies underneath the cloud tops.

“The solar system’s most famous storm is almost one-and-a-half Earths wide, and has roots that penetrate about 200 miles (300 kilometers) into the planet’s atmosphere. Juno found that the Great Red Spot’s roots go 50 to 100 times deeper than Earth’s oceans and are warmer at the base than they are at the top”

Great Red Spot
Jupiter’s Great Red Spot

Data was gathered by Juno’s Microwave Radiometer (MWR), which is able to “look” through Jupiter’s clouds by analyzing different lengths of microwaves.

Great Red Spot Layers
Great Red Spot data from Juno’s MWR

However, we still don’t know what the future of the Great Red Spot will be. While it may have existed for more than 350 years, it has been shrinking quite rapidly.
And as always, thanks NASA!

Source: NASA

Unique random coupon code generation in PHP

Generating pseudo random codes is usually a trivial task. However, coupon codes should have two features that make them computationally complex:

  • They have to be unique
  • They should be hard to guess

A third optional feature would be readability. This means that the final user should not be thinking “is this 0 or O?“.

I found the problem intriguing and decided to make my personal implementation of a coupon code generator in PHP.

Read more

Visualizing one second of Internet

One second of Internet

How many interactions happen every second on the Internet? You can check the numbers anywhere on the web, OR you can go to http://onesecond.designly.com/. Web designer/ dev Steven Lewis created a fantastic website along the lines of “If the moon were only 1 pixel”. Scroll your way through thousands of Google searches and don’t forget to … Read more

About Mars and the loss of atmosphere

NASA just announced another groundbreaking discovery regarding the history of Mars.

Data from the MAVEN spacecraft revealed how Mars loses 100 grams of its atmosphere every second.

Why? solar winds, and obviously solar storms, which increase the loss rate even more.

Mars vs Solar Storm
Mars vs Solar Storm

As explained in the official article from NASA:

[quote]The solar wind is a stream of particles, mainly protons and electrons, flowing from the sun’s atmosphere at a speed of about one million miles per hour. The magnetic field carried by the solar wind as it flows past Mars can generate an electric field, much as a turbine on Earth can be used to generate electricity. This electric field accelerates electrically charged gas atoms, called ions, in Mars’ upper atmosphere and shoots them into space.[/quote]

This is, of course, an extremely interesting discovery, which helps scientists to understand how Mars lost its atmosphere.

However, browsing my news feeds, I stumbled upon a good number of misleading headlines. This is not HOW Mars lost it’s atmosphere, it’s one of the responsible factors.

Read more