Enhancing ASP.NET Core Web API Responses With Consistent and Predictable Wrapper Classes

In ASP.NET Core Web API, you can use wrapper classes to standardize the format of your API responses. A wrapper class typically contains a status code, a message, and the actual data payload. This helps in providing a consistent structure for your API responses, making it easier for clients to understand and handle them.

Let's create a simple example of a wrapper class in ASP.NET Core Web API.

How To Visualize Temporal.io Workflows

I hope everyone knows about Temporal.io — a great workflow engine. If not, please familiarize yourself with it and start using it. You will love it, and it will save you millions of dollars and many months of development time.

In short, Temporal.io allows us to write workflows in a programming language of our choice, Unit test them (!!!), and then run them in a distributed environment.

Untangling Deadlocks Caused by Java’s “parallelStream”

Concurrency is both the boon and bane of software development. The promise of enhanced performance through parallel processing comes hand in hand with intricate challenges, such as the notorious deadlock. Deadlocks, those insidious hiccups in the world of multithreaded programming, can bring even the most robust application to its knees. It describes a situation where two or more threads are blocked forever, waiting for each other.

In this blog post, we dive deep into a real-world deadlock saga triggered by the seemingly innocent use of Java’s parallelStream. We’ll dissect the root cause and scrutinize thread stack traces.

Revolutionizing IoT With Digital Temperature Sensors

Developers are at the forefront of IoT innovation, and one of the critical aspects is temperature monitoring. Digital temperature sensors have transformed how IoT devices collect, transmit, and convert temperature data. In this article, we'll explore the impact of digital sensors on IoT development and provide insights for developers looking to integrate temperature monitoring into their projects.

Digital Temperature Sensors

Understanding Digital Sensors

Digital temperature sensors, often referred to as digital thermal sensors or digital temperature sensors with digital output, are electronic devices designed to measure temperature and provide a digital output, such as a binary code or a digital signal, to represent the temperature value. These sensors have several advantages over their analog counterparts:

Configuring RaptorX Multi-Level Caching With Presto

RaptorX and Presto: Background and Context

Meta introduced a multi-level cache at PrestoCon 2021, the open-source community conference for Presto. Code-named the “RaptorX Project,” it aims to make Presto 10x faster on Meta-scale petabyte workloads. This is a unique and very powerful feature only available in PrestoDB and not any other versions or forks of the Presto project.

Presto is the open-source SQL query engine for data analytics and the data lakehouse. It enables you to scale independently and reduce costs. However, storage-compute disaggregation also brings new challenges for query latency as scanning huge amounts of data between the storage tier and the compute tier is going to be IO-bound over the network. As with any database, optimized I/O is a critical concern to Presto. When possible, the priority is to not perform any I/O at all. This means that memory utilization and caching structures are of utmost importance.

From Pure Agile to Agile Testing Practices

In the fast-paced world of software development, projects need agility to respond quickly to market changes, which is only possible when the organizations and project management improve efficiency, reduce waste, and deliver value to their customers fastest. A methodology that has become very popular in this digital era is the Agile methodology. Agile strives to reduce efforts, yet it delivers high-quality features or value in each build.

Within the Agile spectrum, there exists a concept known as "Pure Agile Methodology," often referred to simply as "Pure Agile," which is a refined and uncompromising approach to Agile project management. It adheres strictly to the core values of the Agile Manifesto.

Implementing BCDR Testing in Your Software Development Lifecycle

In the ever-evolving landscape of software development, ensuring the resilience of your applications has never been more critical. Unexpected disasters or system failures can lead to costly downtime and damage to your reputation. This is where business continuity and disaster recovery (BCDR) testing comes into play. In this article, we'll explore the significance of BCDR testing and how to seamlessly integrate it into your software development lifecycle (SDLC).

Understanding BCDR Testing

Before diving into the specifics of BCDR testing, it's important to grasp its fundamental concept. BCDR testing involves assessing the readiness of your software systems to withstand disasters, system failures, or any adverse events that may disrupt normal operations. It goes beyond typical testing and quality assurance efforts and focuses on ensuring that your software can recover swiftly and effectively in the face of adversity.

iQ Interactive: Cool Things for Developers on Couchbase Capella iQ

The landscape of software development is ever-evolving with the advent of new technologies. As we venture into 2023, natural language processing (NLP) is rapidly emerging as a pivotal aspect of programming. Unlike previous generations of tools that primarily aimed at enhancing coding productivity and code quality, the new generation of Artificial Intelligence (GenAI) tools, like iQ, is set to revolutionize every facet of a developer's workflow. This encompasses a wide range of activities:

  • Reading, writing, and rewriting specifications
  • Designing, prototyping, and coding
  • Reviewing, refactoring, and verifying software
  • Going through the iterative cycle of deploying, debugging, and improving the software
  • Create a draft schema and sample data for any use case
  • Natural language queries.
  • Generate sample queries on a given dataset
  • Fix the syntax error for a query
  • Don't stop here. Let your imagination fly.

Although the insights garnered from iQ are preliminary and should be treated as drafts, the spectrum of tasks one can accomplish with iQ is rich and varied.

How To Get and Set PDF Form Fields in Java

We’re now more than 30 years removed from the introduction of Portable Document Format (PDF) to the budding world of digital documents, and it’s safe to say the concept of a universally interoperable format hasn’t lost its appeal. To call PDF “popular” feels like a seismic understatement; it’s ubiquitous to an absurd degree. It’s not at all ridiculous to imagine that everyone in the world (with access to a computer) will interact with a document in PDF format at some point in their life, and it's likely that every modern business depends on PDF at some point as the export format for their various images, applications, contracts, invoices, and more.

One of the major business advantages PDF offers (and has offered since 1996 — albeit under much different circumstances) is the ability to create and share forms that can be filled out digitally.  As is the case now with most digitized processes, the manual counterpart to this process — i.e., printing forms, filling them out manually, and either scanning them or storing them for digital or physical archival — has fully evolved into an excruciating exercise in patience knowing that a purely digital version of that experience exists.

Micro Frontends for Quarkus Microservices

Coined quite recently, the term Micro Frontend designates for a GUI (Graphical User Interface) what the one Microservice designates for classical services, i.e., the decomposition process of the different application's parts and components. More importantly, it not only applies to GUIs in general but to a more specific category of GUIs named SPA (Single Page Application). This is important because if there existed several techniques aiming at separating the different parts and components of a web application in general when it comes to SPAs, the story would become a bit more difficult. As a matter of fact, separating the different parts and components of a general web application often means separating its different pages. This process becomes more tricky for SPAs, as it concerns the separation of the different visual fragments of the application's single page. This requires a finer granularity and a more intimate orchestration of the content elements.

The Micro Frontend concept adds more complexity to the web applications development field, which is already fairly complex by itself. The SPA model, as well as the emergence of the so-called JavaScript or TypeScript-based web application platforms and frameworks, brought to the picture a high degree of intricacy, requiring developers to have a vast amount of background knowledge, from HTML and CSS to advanced aspects of Angular, React, Node, Vue, and jQuery. In the Java world, a new category of software developers has come to light: the fullstack developers who not only need to deal with the grief of mastering Java, be it standard or enterprise, and all its underlying sub-technologies like Servlet, REST, CDI, JPA, JMS and many others, currently placed under the auspices of Jakarta EE, but who, increasingly, is required to master things like WebPack, SystemJS, Bower, Gulp and others Yeoman. Not to mention any more Spring, Quarkus, Micronaut, or Helidon.

File Server on Raspberry Pi

Having just acquired a Raspberry Pi Model 3, I am attempting to set it up as an NAS. So far I have set up the Raspberry Pi OS and configured samba. It appears to be working fine except for one minor problem. While I can remote in using TightVNC, I cannot map to any of my media folders from Windows 10 or Windows 11.

So far I have tried

  1. forcing SMB2 protocol on Pi by adding "protocol = smb2" to smb.conf
  2. enabling SMB1 in windows features

The instructions say to use "\raspberrypi\NAS" as the "browse to" folder. NAS is the name I set up in smb.conf. It asks for username/password but just responds with

2023-09-29_122752.jpg

I can browse to \10.0.0.177 or \raspberrypi and it shows my NAS share, but when I try to open NAS I just get the same error. There is probably some setting that needs to be tweaked that all the help sites I've been to are omitting because they are assuming I already know. Any suggestions will be much appreciated.

I already have file and printer sharing enabled (I can map to folders on other machines).

How to Display Different Sidebar for Each Post and Page in WordPress

Do you want to display different sidebars for certain posts and pages on your WordPress site?

A lot of the time, you will want to show the same sidebar across your entire website or blog. However, sometimes you may need to show different sidebar content on some of your posts and pages.

In this article, we will show you how to create and display different sidebars for each post and page in WordPress.

How to Display Different Sidebar for Each Post and Page in WordPress

When Would You Need Different Sidebars in WordPress?

Many WordPress themes have a sidebar where you can add useful widgets and content. For example, many sites add a search bar to the sidebar or show a list of recent posts.

If your WordPress theme has a sidebar, then by default, it will look the same on all your posts, pages, categories, and archive pages.

However, you may want to display different sidebar widgets on certain posts and pages.

For example, you might show different content in the sidebar of your most popular posts or display ads that are more relevant to a particular page.

You could even use different contact forms depending on the page’s content.

Having said that, let’s see how to create and display a different sidebar for each post and page in WordPress. Simply use the quick links below to jump straight to the method you want to use:

Method 1: Displaying Different Sidebars for Each Post and Page in WordPress (Easy)

If your theme supports sidebar widgets, then you can easily create multiple sidebars using Lightweight Sidebar Manager. This plugin lets you build as many custom sidebars as you want and then assign them to different posts and pages. You can also add them to custom post types or assign a sidebar to all the pages or posts that have a specific category.

The first thing you need to do is install and activate the Lightweight Sidebar Manager plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you need to go to Appearance » Sidebars. To create the first sidebar, click on the ‘Add New’ button.

Adding custom sidebars to your WordPress website

You can now type in a title for the sidebar. This is just for your reference, so you can use anything you want.

With that done, open the ‘Sidebar To Replace’ dropdown menu and choose the location where you want to show the sidebar. The options you see may vary depending on your WordPress theme

Replacing the built-in sidebar provided by your WordPress theme

Now, you can control where the sidebar appears by creating inclusion or exclusion rules. 

To create an inclusion rule, just open the ‘Display On’ dropdown and choose the pages, posts, custom post types, or categories where you want to use the sidebar. 

For example, you might add the sidebar to a specific page, such as your 404 error page or the author archive.

Adding a custom sidebar to the WordPress 404 page

Another option is using the sidebar for a particular page, post, or category by selecting ‘Specific Pages/Posts/Taxonomies.’

This adds a box where you can type in the page, post, or category.

Creating a custom sidebar for WordPress categories

To create more inclusion rules, simply click on the ‘Add Display’ Rule button.

This adds a section where you can create the new inclusion rule.

Adding display rules for custom sidebars in WordPress

If you prefer, then you can create exclusion rules instead. For example, you may want to show the sidebar on every page except the homepage. 

You can also combine inclusion and exclusion rules to control exactly where the sidebar appears on your WordPress website.

To create an exclusion rule, just click on the ‘Add Exclusion Rule’ button.

Displaying different sidebars for pages and posts in WordPress

In the new ‘Do Not Display On’ section, open the dropdown menu and select the page or post that shouldn’t use this sidebar. 

You can also exclude the sidebar from pages that have a specific category by following the same process described above.

Displaying different sidebar for each page and post in WordPress

After deciding where the sidebar will appear on your WordPress blog, you may want to show different content to different users.

For example, if you have a membership site, then you might use a different sidebar for visitors compared to logged-in members. 

To do this, open the ‘User’ dropdown and choose a role from the dropdown menu. Now, only people with this specific user role will see the sidebar. 

Displaying different sidebar widgets on each WordPress page or post

Finally, you may want to type in an optional description. This will only appear in the WordPress dashboard, so it’s a good way to share information with other admins or users on a multi-author WordPress blog

If you are going to create lots of sidebars, then you can also use this field to leave yourself notes and helpful reminders.

Adding a helpful description to a custom sidebar in WordPress

When you are happy with the information you have entered, simply click on ‘Publish.’

With that done, go to Appearance » Widgets. You will now see all the widget-ready areas that your theme supports by default, plus the new sidebar you created in the previous step.

Adding content to a sidebar or similar widget-ready area

You can now go ahead and add widgets to the sidebar, just like any other widget-ready area. 

For step-by-step instructions, please see our guide on how to add and use widgets

Adding content to a custom WordPress sidebar

When you are happy with how the sidebar is set up, click on ‘Update.’

Now, if you visit your WordPress blog, you will see the new sidebar live.

An example of a custom WordPress sidebar, created using a plugin

To create more custom sidebars, simply keep repeating these steps. 

Method 2: Creating a Different Sidebar With a Page Builder Plugin (Works With Any WordPress Theme)

If your theme doesn’t support sidebars, then you can still create different sidebars using a drag and drop page builder plugin.

SeedProd is the best landing page builder plugin for WordPress. With this plugin, you can create any type of custom page without writing any code. It also has dozens of professional site kits and templates that you can easily edit and fine-tune using the drag-and-drop builder.

When designing a custom page, you can choose a layout that has a sidebar.

Choose a Layout with a Sidebar

You then simply find the blocks you want to show in that sidebar and add them using drag and drop.

SeedProd has all the blocks and features you’d expect from a powerful page builder, such as optin forms, social profiles, countdown timers, contact forms, buttons, various content blocks, and more. This makes it easy to create powerful and unique sidebars for your WordPress blog.

Drag the Blocks You Wish to Use Right onto the Sidebar

To learn how to use the SeedProd page builder plugin on your website, you can see our guide on how to create a custom page in WordPress.

We hope this article helped you learn how to add different sidebars to each post or page in WordPress. You may also want to learn how to create a custom Instagram feed in WordPress or see our expert picks for the best block themes for full site editing.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Display Different Sidebar for Each Post and Page in WordPress first appeared on WPBeginner.

Best Practices for SQL Coding and Development

We live in a data-driven world, and SQL (Structured Query Language) is essential for managing data. SQL is used to manipulate and interact with data in a relational database. It's used by businesses of all sizes, from startups to large corporations, to extract insights from their data and make informed decisions.

But writing SQL code is not just about knowing the language — it's also about using best practices for coding and development. Poorly written SQL code can lead to performance issues, security vulnerabilities, and difficult-to-maintain databases. On the other hand, well-written code can make your database faster, more secure, and easier to manage.

‘First Contact’ with AGI: What Will It Look Like?

Earlier this week, a Reddit account confirmed to belong to Sam Altman, OpenAI's CEO, asserted in a comment that "AGI has been achieved internally." This announcement came after a similar statement by a cryptic insider named "Jimmy Apples" on X/Twitter (account now deleted), known for prior correct forecasts about OpenAI's endeavors. Though the claim was met with a mixture of skepticism and amusement (and later clarified to be "memeing" by Altman himself), it sparked a much-needed conversation. It is time to ask ourselves: What will the arrival of Artificial General Intelligence (AGI) look like, and how might its 'release' affect the world?

This article discusses various scenarios for the dawn of AGI.

birth-of-aidam.jpg
(Image generated with WePik)

How to Imagine AGI?

Imagining the emergence of AGI is comparable to imagining first contact with extraterrestrial intelligence. No one knows exactly what it would look like and how it might play out, but numerous theories surround the topic. It also matters who gets to make first contactwould aliens address the entire world, or just a select few? Similarly, whoever wins the race for AGIa government, a company, or the open-source communitywill be able to steer its impact.

But let's assume that AGI, once developed, becomes public knowledge and a global phenomenon. Picture a not-so-distant future where the boundary between machines and humans increasingly blurs. Unlike today's AI that excels in specific tasks but fumbles outside its trained domain, AGI comes with a promise of boundless understanding. It's like having a new kind of entity among us, one with the potential to not only mimic, but to grasp the essence of any intellectual task that humans can do. Just as a first encounter with extraterrestrial intelligence could reshape our perspective of the cosmos, the arrival of AGI could redefine our interaction with technology, each other, and the world at large.

Imagine waking up to a digital companion capable of discussing the headlines, advising on your day's schedule, and even sharing a joke to brighten your morning. It can read between the lines of your queries, assess the tone of your voice, and offer solutions tailored to your individual circumstances. It is equipped with an encyclopedic knowledge, a profound understanding of context, and perfect memory. Its your lawyer, broker, psychiatrist, and personal trainer, all at once. This is AGI. It is capable of any intellectual task a human can do, just without the years of training and the boundaries of a naturally decaying body.

Now, expand this scenario: The AGI is not only on your devices, its in the network. It coordinates everything, from traffic lights to power grids. It's in hospitals, aiding doctors with diagnoses with an accuracy that continually improves with each interaction. Its also in law enforcement, capable of tracing down anyone at any time. In essence, the arrival of AGI is the gateway to every utopia or dystopia we could imagine, and as we venture further towards it, countless scenarios emerge.

Scenario 1: The Silent Arrival

The notion that AGI might already be here, quietly operating under the veil of corporate or governmental secrecy, is both thrilling and disconcerting. In a world where the latest AI advancements are often held close to the chest, the leap to AGI could be a clandestine affair. The entities in control could leverage it for their own strategic advantages.

In this secretive scenario, the unveiling of AGI may not come with fanfare and public awe, but rather reveal itself through subtle shifts in global power dynamics or unprecedented advancements in technology that seemingly appear out of nowhere. Behind closed doors, AGI could be reshaping geopolitical landscapes, driving unseen innovation, or influencing public opinion through digital whisper campaigns. The lack of public knowledge or oversight could aggravate existing inequalities, as those with control over AGI could deploy it to further their interests while the rest of the world remains oblivious. The silent arrival of AGI could present a reality where the true extent of artificial intelligence's integration into society is only known to a privileged few, leaving the majority to merely speculate on the unseen force orchestrating changes on a global scale.

Scenario 2: The Guarded Release

In a future where the power of AGI is recognized but feared, its reins might be held tightly. Only a handful of governments or corporations hold the keys to the AGI kingdom, with regulatory barriers guarding the gates.

In this scenario, the guarded release of AGI unfolds under strict governmental oversight. A regulatory stronghold aims to ensure that AGI serves the public good as perceived by decision-makers while minimizing risks. Under this framework, AGI could be deployed in a controlled manner to tackle pressing challenges. However, the pace of innovation might be slowed as bureaucratic hurdles multiply. The public discourse may oscillate between appreciating the caution and lamenting the red tape. Furthermore, the global landscape could become a patchwork of regulatory frameworks, each with its own set of rules governing AGI, leading to a complex maze of differing rules.

Scenario 3: Open-Source Odyssey

What if a decentralized, open-source community pioneers the development and release of AGI? The open-source approach would make it available to anyone who can afford the necessary hardwaregovernments and citizens alike.

In this scenario, the narrative takes a turn towards a more democratic and accessible release. The collaborative spirit of an open-source community drives the development of AGI, making the process transparent and inclusive. However, in such a scenario, AGI's power could be harnessed for harmful purposes as easily as for beneficial ones. The lack of regulation might make it extremely challenging to mitigate risks, enforce ethical guidelines, or handle misuse, creating a Wild West scenario for artificial intelligence.

Scenario 4: Big Business AGI

Imagine paying for AGI. In this not entirely unlikely scenario, reminiscent of a Philip K. Dick story, AGI would be developed and controlled by private enterprises, who sell it to us in the form of subscriptions. Users could download an app and launch their personal AGI agents on their phones. Governments could buy AGI-based software solutions designed to streamline infrastructure, healthcare, or tax collection.

In a world where AGI becomes a product, the landscape of innovation could become a bustling marketplace. Private enterprises, driven by profit and competition, might propel AGI technology to new heights at a rapid pace. However, this profit-driven rush could potentially overshadow critical ethical considerations. Additionally, the fierce competition could also spur a race to the bottom in terms of privacy and security standards, as companies might cut corners to speed up development and capture market share. And eventually, this race might lead to the most powerful monopoly the world has ever seen.

Let's Continue the Conversation

Sam Altman's trolling on Reddit reminds us that AGI could indeed arrive any moment. It could unfold in many ways, depending on who gets there first and how it's shared with the world. The scenarios discussed here show a range of possibilities, each with its own set of challenges and opportunities. Whether it's a silent arrival shrouded in secrecy, a business-led venture driven by profit, or an open-source journey, each path leads to a different outcome. It's important for everyone to engage in the conversation about AGI. As we move closer to making it a reality, the decisions we make today could shape the future in significant ways.

Cloud Migration: How To Overcome Fears and Capitalize on Opportunities

Cloud computing has been a major trend for a decade. In 2015, it saw triple-digit annual growth. Although by the end of 2019, the largest cloud providers grew at a slower rate, just 31% annually, and this rate was expected to decrease in 2020 and 2021 as the industry matures, cloud growth still surpassed many other sectors.

Moreover, in 2020, the cloud market grew faster than in 2019 by some metrics. That happened despite the severe economic downturn. The reason for this growth was the increased demand caused by the pandemic, lockdowns, and the shift to remote work.

Modern Data Backup Strategies for Safeguarding Your Information

In a rapidly changing business environment, data backup strategies for small and large organizations have evolved beyond traditional methods. Data ecosystems' growing complexity and potential risks highlight the need for comprehensive data backup and recovery strategies. Many organizations experience data loss at some point, underscoring the urgency for effective backup solutions. 

Though valuable in their time, traditional data backup methods often need to address the demands of today's data-driven world. The shift towards cloud data backup strategies has gained prominence due to their scalability, accessibility, and potential for disaster recovery. A study by IDC states that the public cloud services market reached $500 billion in 2022, signifying the growing reliance on cloud solutions for data management. 

Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 1)

In a previous article on CSS-Tricks, I demonstrated how to create a fancy hover effect where an avatar pops out of a circle on hover. The challenge was to make such an effect using only the <img> tag.

I know it might seem like this shape requires advanced trickery. But if we break it down a bit, all we’re really talking about is a series of small circles around a much larger circle.

We are going to rely on radial-gradient and some math, specifically trigonometric functions. Bramus Van Damme provides an excellent primer on trigonometric functions over at web.dev. It’s very much worth your while to brush up on the concept with that article.

We are going to define two variables to control the flower shape. N represents the number of the small circles, and R is the diameter of the small circles (Illustrated by the black arrow in the figure above). If we have the diameter, then we can calculate the radius by dividing R by 2. This is everything we need to create the shape!

Here is what the code of a small circle looks like:

img {
  --r: 50px;
  mask:
    radial-gradient(#000 70%, #0000 72%) no-repeat
    {position} / var(--r) var(--r);
}

All of the small circles can use the same radial gradient. The only difference between them is the position. Here comes the math:

(50% + 50% * cos(360deg * i/N)) (50% + 50% * sin(360deg * i/N))

N is the number of circles, and i is the index of each circle. We could manually position each circle individually, but that’s a lot of work, and I believe in leveraging tools to help do some of the heavy lifting. So, I’m going to switch from CSS to Sass to use its ability to write loops and generate all of the circle positions in one fell swoop.

$n: 15; /* number of circles */

img {
  --r: 50px; /* control the small circles radius */
  $m: ();
  @for $i from 1 through ($n) {
    $m: append($m, 
         radial-gradient(#000 70%,#0000 72%) no-repeat
          calc(50% + 50% * cos(360deg * #{$i / $n})) 
          calc(50% + 50% * sin(360deg * #{$i / $n})) /
            var(--r) var(--r), 
        comma);
   }
  mask: $m;
}

We’re essentially looping through the number of circles ($n) to define each one by chaining the radial gradient for each one as comma-separated values on the mask ($m) that is applied to the image element.

We still need the large circle that the small circles are positioned around. So, in addition to the loop’s output via the $m variable, we chain the larger circle’s gradient on the same mask declaration:

img {
  /* etc */
  mask: $m, radial-gradient(#000 calc(72% - var(--r)/2),#0000 0);
}

Finally, we define the size of the image element itself using the same variables. Calculating the image’s width also requires the use of trigonometric functions. Then, rather than doing the same thing for the height, we can make use of the relatively new aspect-ratio property to get a nice 1:1 ratio:

img {
  /* etc */
  width: calc(var(--r) * (1 + 1/tan(180deg / #{$n})));
  aspect-ratio: 1;
}

Check it out. We have the shape we want and can easily control the size and number of circles with only two variables.

We’re basically reducing the distance of the small circles, making them closer to the center. Then, we reduce the size of the larger circle as well. This produces an effect that appears to change the roundness of the smaller circles on hover.

The final trick is to scale the entire image element to make sure the size of the hovered shape is the same as the non-hovered shape. Scaling the image means that the avatar will get bigger and will pop out from the frame that we made smaller.

$n: 15; /* number of circles */

@property --i {
  syntax: "<length>";
  initial-value: 0px;
  inherits: true;
}

img {
  /* CSS variables */
  --r: 50px; /* controls the small circle radius and initial size */
  --f: 1.7; /* controls the scale factor */
  --c: #E4844A; /* controls the main color */

  $m: ();
  /* Sass loop */
  @for $i from 1 through ($n) {
    $m: append($m, 
      radial-gradient(var(--c) 70%, #0000 72%) no-repeat
      calc(50% + (50% - var(--i, 0px)) * cos(360deg * #{$i/$n} + var(--a, 0deg))) 
      calc(50% + (50% - var(--i, 0px)) * sin(360deg * #{$i/$n} + var(--a, 0deg))) /
      var(--r) var(--r), 
    comma);
  }

  mask: 
    linear-gradient(#000 0 0) top/100% 50% no-repeat,
    radial-gradient(var(--c) calc(72% - var(--r)/2 - var(--i, 0px)), #0000 0),
    $m;
  background:
    radial-gradient(var(--c) calc(72% - var(--r)/2 - var(--i, 0px)), #0000 0),
    $m;
  transition: --i .4s, scale .4s;
}

img:hover {
  --i: calc(var(--r)/var(--f));
  scale: calc((1 + 1/tan(180deg/#{$n}))/(1 - 2/var(--f) + 1/tan(180deg/#{$n})));
}

Here’s what’s changed:

  • The Sass loop that defines the position of the circle uses an equation of 50% - var(--i, 0px) instead of a value of 50%.
  • The larger circle uses the same variable, --i, to set the color stop of the main color in the gradients that are applied to the mask and background properties.
  • The --i variable is updated from 0px to a positive value. This way, the small circles move position while the large circle becomes smaller in size.
  • The --i variable is registered as a custom @property that allows us to interpolate its values on hover.

You may have noticed that I didn’t mention anything about the --f variable that’s defined on the image element. Truthfully, there is no special logic to it. I could have defined any positive value for the variable --i on hover, but I wanted a value that depends on --r, so I came up with a formula (var(--r) / var(--f)), where --f allows controls the scale.

Does the equation on the scale property on hover give you a little bit of panic? It sure looks complex, but I promise you it’s not. We divide the size of the initial shape (which is also the size of the element) by the size of the new shape to get the scale factor.

  • The initial size: calc(var(--r)*(1 + 1 / tan(180deg / #{$n})))
  • The size of the new shape: calc(var(--r) * (1 + 1 / tan(180deg / #{$n})) - 2 * var(--r) / var(--f))

I am skipping a lot of math details to not make the article lengthy, but feel free to comment on the article if you want more detail on the formulas I am using.

That’s all! We have a nice “pop out” effect on hover:

See the Pen Fancy Pop Out hover effect! by Temani Afif.

Wrapping Up

Does all of this seem a bit much? I see that and know this is a lot to throw at anyone in a single article. We’re working with some pretty new CSS features, so there’s definitely a learning curve with new syntaxes, not to mention some brushing up on math functions you probably haven’t seen in years.

But we learned a lot of stuff! We used gradients with some math to create a fancy shape that we applied as a mask and background. We introduced @property to animate CSS variables and bring our shape to life. We also learned a nice trick using animation-composition to control the speed of the rotation.

We still have a second part of this article where we will reuse the same CSS techniques to create a fancier hover effect, so stay tuned!

I’ll leave you with one last demo as a sign-off.

See the Pen Pop out hover effect featuring Lea and Una by Temani Afif.