Tip Post Tag - TechOpt.io https://www.techopt.io/tag/tip Programming, servers, Linux, Windows, macOS & more Sat, 12 Jul 2025 21:40:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://www.techopt.io/wp-content/uploads/2024/07/cropped-logo-1-32x32.png Tip Post Tag - TechOpt.io https://www.techopt.io/tag/tip 32 32 Solving Next.js dynamic() Flicker with React.lazy https://www.techopt.io/programming/solving-next-js-dynamic-flicker-with-react-lazy https://www.techopt.io/programming/solving-next-js-dynamic-flicker-with-react-lazy#respond Sat, 12 Jul 2025 21:40:24 +0000 https://www.techopt.io/?p=1039 If you’re working with the Next.js App Router and using the dynamic() function for component-level code splitting, you may have encountered an annoying issue: flickering during rendering of a conditionally-rendered dynamic component. Unfortunately, this is a known issue with the App Router and the dynamic function in Next.js. This behavior can degrade user experience, so […]

The post Solving Next.js dynamic() Flicker with React.lazy appeared first on TechOpt.

]]>
If you’re working with the Next.js App Router and using the dynamic() function for component-level code splitting, you may have encountered an annoying issue: flickering during rendering of a conditionally-rendered dynamic component. Unfortunately, this is a known issue with the App Router and the dynamic function in Next.js. This behavior can degrade user experience, so solving the Next.js dynamic flicker on your website is crucial.

In this post, I’ll break down:

  • Why next/dynamic causes flickering
  • Why it’s worse with nested dynamic components
  • When dynamic() is still safe to use
  • A practical alternative using React.lazy() and Suspense
  • What trade-offs to expect when switching

The Flickering Problem in Next.js

Using dynamic() from next/dynamic is a great way to lazy-load components and reduce your JavaScript bundle size. It also supports options like { ssr: false } to only load components on the client side.

However, when you use these components with the App Router, they often cause a flash of missing or unstyled content, especially during fast navigation or when conditionally rendering dynamic components.

Nested dynamic() calls tend to amplify this issue. For example, a parent component conditionally loading a child via dynamic(), which in turn loads another sub-component dynamically, can make the flickering more severe.

This issue has been reported in GitHub issues and community threads, but a rock-solid fix hasn’t yet made it into the framework.

Interestingly, this flicker seems to affect nested dynamic components more than top-level ones. In my testing, first-level dynamically rendered components used directly in the page file rarely exhibit the issue, which means it’s generally safe to use next/dynamic there to avoid flash of unstyled content (FOUC) during initial mount.

The Better Alternative: React.lazy() + Suspense

One workaround that has proven effective is switching from next/dynamic to native React.lazy() with Suspense. This approach introduces fewer hydration inconsistencies and minimizes flickering, even with nested lazy-loaded components.

Use next/dynamic for components initially rendered on the page, and use React.lazy() for nested components that are rendered conditionally inside those components.

Example 1: Top-level safe usage with next/dynamic

import dynamic from 'next/dynamic';
import { isSignedInAsync } from '../auth';

const PageShell = dynamic(() => import('../components/PageShell'));

export default async function Home() {
  const isSignedIn = await isSignedInAsync();

  if (isSignedIn) return null;

  return <PageShell />;
}

In this example, PageShell is conditionally rendered on the server using dynamic components. This is safe since the dynamic component is rendered with the initial HTML from the server.

Example 2: Nesting with React.lazy() and Suspense

"use client";
import dynamic from 'next/dynamic';

const NestedComponent = dynamic(() => import('./NestedComponent'));

export default function PageShell() {
  const [showNested, setShowNested] = useState(false);

  return (
    <div>
      <h1>Welcome</h1>
      <button onClick={() => setShowNested(true)}>Load Nested Component</button>
      {showNested && (
        <Suspense fallback={<div>Loading nested...</div>}>
          <NestedComponent />
        </Suspense>
      )}
    </div>
  );
}

We can safely use React.lazy() and Suspense inside our dynamically-rendered PageShell component to conditionally render our NestedComponent, and still benefit from lazy-loading and code-splitting.

If we try using the dynamic function instead of React.lazy here, we may get the Next.js dynamic flicker.

Trade-offs of Using React.lazy() Instead of dynamic

While React.lazy() and Suspense often result in smoother rendering, there are two notable downsides:

1. No Server-Side Rendering

Unlike next/dynamic, which lets you disable or enable SSR, React.lazy() only supports client-side rendering. This might hurt SEO if your component needs to be visible to crawlers.

2. Flash of Unstyled Content (FOUC) on Mount

If you do try to use React.lazy() for SSR and use it in the server-rendered HTML, React.lazy() may cause a brief flash of unstyled content because the Next.js bundler doesn’t automatically include the styles for components loaded through React.lazy() in the server-rendered HTML. This limitation can lead to inconsistent rendering.

This is why it’s best to use next/dynamic for components that are visible in the server-rendered HTML, ensuring that styles and structure are present at first paint, while reserving React.lazy() for non-critical or nested components. Using next/dynamic in the initial server-rendered HTML does not seem to cause flickering.

Final Thoughts on Preventing the Next.js Dynamic Flicker

If you’re seeing flickering with next/dynamic and conditional rendering, especially in complex nested layouts, you’re not alone. While the Next.js team continues to evolve App Router, switching to React.lazy() and Suspense where you can may provide a smoother user experience at this time.

To summarize:

  • Use next/dynamic safely for top-level page components
  • Use React.lazy() for nested dynamic imports to reduce flicker

The post Solving Next.js dynamic() Flicker with React.lazy appeared first on TechOpt.

]]>
https://www.techopt.io/programming/solving-next-js-dynamic-flicker-with-react-lazy/feed 0
Fixing ‘Sequence contains more than one matching element’ Android Build https://www.techopt.io/programming/fixing-sequence-contains-more-than-one-matching-element-android-build https://www.techopt.io/programming/fixing-sequence-contains-more-than-one-matching-element-android-build#respond Sun, 06 Jul 2025 01:20:26 +0000 https://www.techopt.io/?p=1024 I just spent the last 3 days wrestling with this “Sequence contains more than one matching element” Android build error: If you noticed from the stack trace above, this is a React Native app. I tried deleting my node_modules folder, deleting my build folders, running ./gradlew clean. I would run the build again and again, […]

The post Fixing ‘Sequence contains more than one matching element’ Android Build appeared first on TechOpt.

]]>
I just spent the last 3 days wrestling with this “Sequence contains more than one matching element” Android build error:

> Task :react-native-device-country:prepareLintJarForPublish
> Task :react-native-device-info:createFullJarRelease
> Task :react-native-device-info:extractProguardFiles
> Task :react-native-device-info:generateReleaseLintModel
> Task :react-native-device-info:prepareLintJarForPublish
> Task :react-native-fbsdk-next:createFullJarRelease
> Task :react-native-fbsdk-next:extractProguardFiles
> Task :app:stripReleaseDebugSymbols
> Task :react-native-fbsdk-next:generateReleaseLintModel
> Task :app:buildReleasePreBundle FAILED
> Task :app:uploadCrashlyticsMappingFileRelease
[Incubating] Problems report is available at: file:///Users/dev/Documents/app/android/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:buildReleasePreBundle'.
> Sequence contains more than one matching element.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.14.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 1h 6m 21s
1222 actionable tasks: 1208 executed, 14 up-to-date
node:child_process:966
    throw err;
    ^
Error: Command failed: ./gradlew bundleRelease
    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:891:11)
    at Object.execSync (node:child_process:963:15)
    at /Users/dev/Documents/app/buildscripts/buildserv/build/build-android.js:8:23
    at Object.<anonymous> (/Users/dev/Documents/app/buildscripts/buildserv/build/build-android.js:11:3)
    at Module._compile (node:internal/modules/cjs/loader:1529:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1096:12) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 22055,
  stdout: null,
  stderr: null
}
Node.js v20.19.3
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit status 1

If you noticed from the stack trace above, this is a React Native app. I tried deleting my node_modules folder, deleting my build folders, running ./gradlew clean. I would run the build again and again, but nothing worked. The same error kept popping up every time, right near the end of the build.

No amount of –debug or –stacktrace was giving me any sort of additional information. The most information I could get from this error had already been given to me.

ChatGPT and Copilot were no help, suggesting that this is a Kotlin error and most likely resides in a native library I’m using within the app.

But this didn’t make sense, because I was able to build the project on my local system with the latest dependencies just fine. It was only once I sent the build to my GitLab instance, which runs the build on a macOS VM with gitlab-runner, that I started getting this error.

So is the error with the build process, or one of the build tools itself?

Narrowing Down the Cause

After a ton of googling of this error, I finally came across this Google IssueTracker post that pointed me in the right direction. This person describes the exact same issue I’m having.

This person also says that this error started happening after an upgrade to AGP 8.9.0.

Now we’re getting somewhere. It doesn’t look like they’re using React Native, but at this point I was confident the issue isn’t stemming from anything to do with React Native.

AGP is an Android build tool. It’s possible that my macOS VM has a newer version of AGP than my local system does. This would explain why it’s only happening once I send the app to build in the macOS VM.

So, what’s the problem?

Well, it can be traced back to this section here in the app’s build.gradle:

...
splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
...

This section of the build.gradle file tells gradle to output different APK files for different CPU architectures.

When this part of the build.gradle file is encountered by running the bundleRelease gradle task, the “sequence contains more than one matching element” exception is thrown because bundleRelease expects to be generating a single universal AAB file instead of separate APK files, that can then be uploaded to the Google Play Store.

The Fix

All I did was remove this section from our build.gradle file:

...
splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
...

And it resolved the issue! We weren’t using the multiple APKs anyways, so I’m not even sure why we had this in our build.gradle file. We only upload the single universal AAB to the Play Store.

Additional Notes

In the issue tracker linked above, Google states that they do not plan on fixing this, since they don’t officially support creating multiple APKs when running bundleRelease. However, if you still need multiple APK support, someone on the issue tracker suggests the following fix:

splits {
        abi {
            // Detect app bundle and conditionally disable split abis
            // This is needed due to a "Sequence contains more than one matching element" error
            // present since AGP 8.9.0, for more info see:
            // https://issuetracker.google.com/issues/402800800

            // AppBundle tasks usually contain "bundle" in their name
            val isBuildingBundle = gradle.startParameter.taskNames.any { it.lowercase().contains("bundle") }

            // Disable split abis when building appBundle
            isEnable = !isBuildingBundle

            reset()
            //noinspection ChromeOsAbiSupport
            include("armeabi-v7a", "arm64-v8a", "x86_64")

            isUniversalApk = true
        }
}

This enables APK splitting while disabling APK splitting for the bundleRelease task, preventing the “sequence contains more than one matching element” error.

The post Fixing ‘Sequence contains more than one matching element’ Android Build appeared first on TechOpt.

]]>
https://www.techopt.io/programming/fixing-sequence-contains-more-than-one-matching-element-android-build/feed 0
How to Identify Fake FLAC Files https://www.techopt.io/music-production/how-to-identify-fake-flac-files https://www.techopt.io/music-production/how-to-identify-fake-flac-files#respond Sun, 15 Jun 2025 23:00:47 +0000 https://www.techopt.io/?p=966 If you’re a music enthusiast like me, chances are you’ve built up a library of lossless audio files. Why settle for anything less than the best sound quality? But if you aren’t ripping CDs or vinyl yourself, how can you be sure the FLAC files you’ve collected are actually lossless? The reality is that not […]

The post How to Identify Fake FLAC Files appeared first on TechOpt.

]]>
If you’re a music enthusiast like me, chances are you’ve built up a library of lossless audio files. Why settle for anything less than the best sound quality? But if you aren’t ripping CDs or vinyl yourself, how can you be sure the FLAC files you’ve collected are actually lossless? The reality is that not all FLAC files are created equal. Some may be “fake FLAC”: files that have been upsampled from lossy formats like MP3 and saved as FLAC, which doesn’t magically restore lost data.

While there’s no foolproof method to detect a fake FLAC, there are some telltale signs based on bitrate and frequency response that can help you spot them. One of my go-to tools for this task is Spek, a free and open-source audio spectrum analyzer.

What Is a Fake FLAC or Fake Lossless Files?

People create fake FLAC files by converting lossy formats—like MP3 or AAC—into lossless containers such as FLAC. Although the file extension and size might suggest high quality, the underlying audio data remains compromised. These files often originate from people who re-encode lossy sources and redistribute them under the guise of high fidelity.

Also note that while FLAC is the most common lossless audio format, other containers such as WAV and ALAC do exist as well. The indicators mentioned in this article for spotting fake lossless audio files are generic and apply regardless of the container format.

Using Spek to Analyze Frequency Spectrum

When you open a file in Spek, it displays the audio spectrum across the entire track. This visual representation reveals how much of the frequency range the file actually contains. A true lossless FLAC will have no abrupt cutoffs in the upper frequencies, whereas fake FLACs often exhibit sharp drop-offs.

Here’s a general guideline for identifying the cutoff frequencies and their corresponding bitrates:

  • 11 kHz = 64 kbps
  • 16 kHz = 128 kbps
  • 19 kHz = 192 kbps
  • 20 kHz = 320 kbps

If you notice a sharp cutoff around these frequencies, the file may have been upsampled from a lossy source.

Fake FLAC from an upsampled MP3
This fake FLAC file was upsampled from a 320 kbps MP3 file. We can see a very visible cutoff of all frequencies above 20 kHz.

What to Expect from True Lossless FLACs

Depending on the sample rate and bit depth, a legitimate FLAC file should show frequency content extending to the upper limits of the spectrum:

  • 44.1 kHz, 16-bit: Should display frequencies up to 22 kHz
  • 48 kHz, 16-bit: Should reach up to 24 kHz
  • 96 kHz, 24-bit: May extend up to 48 kHz, but a smooth fade to nothing somewhere between 20-30 kHz is normal
  • 192 kHz, 24-bit: May extend up to 96 kHz, but a smooth fade to nothing somewhere between 20-30 kHz is normal
A true 44.1 kHz/16-bit CD-quality FLAC file
The same song as above, in true 44.1 kHz/16-bit FLAC format. We can see that the whole frequency spectrum right up to 22 kHz is used.

You can often spot upsampling when you see a sharp cutoff at 22 kHz. There may also be very faint or random noise in the 22 kHz and up range. This pattern usually means someone took a 44.1 kHz file and padded it to 48 or 96 kHz.

This file was upsampled from 44.1 kHz to 48 kHz, as made clear by the sharp frequency cutoff visible at 22 kHz.

It’s also worth noting that there’s ongoing debate about whether audio content above 20 kHz contributes meaningfully to music. An audio engineer or producer might even intentionally apply a low-pass filter to cut out all frequencies above a certain inaudible range. This will result in a steeper drop-off, even in a genuine lossless file.

Additionally, not all instruments produce frequencies in this high range, so a natural lack of content above 20 kHz doesn’t necessarily indicate the file is fake.

Bitrate as Another Indicator of a Fake FLAC

Another clue is the file’s bitrate. While FLAC is a variable bitrate format, files with noticeably low average bitrates may be suspect. Here are some average bitrate ranges you might expect from real FLAC files:

  • 44.1 kHz / 16-bit (CD quality): ~700–1100 kbps
  • 48 kHz / 16-bit or 24-bit: ~800–1400 kbps
  • 96 kHz / 24-bit: ~2000–3000 kbps (can vary widely depending on the content)
  • 192 kHz / 24-bit: ~4000–7000 kbps (can vary widely depending on the content)

If you see a file with a much lower bitrate than expected and frequency cutoffs that match the patterns listed above, the file is almost certainly a fake FLAC.

Trust Your Ears

While visual analysis is helpful, always trust your ears. A song that sounds dull, muffled, or artifacted is likely not true lossless. That said, some minimal or acoustic recordings might not use the entire frequency spectrum and can still be genuine FLACs.

For example, a solo vocal track, acoustic guitar piece, or lo-fi bedroom recording may naturally have limited frequency content, especially in the high end. These types of recordings often focus on midrange clarity rather than full-spectrum detail, so a sparse frequency graph in Spek doesn’t always mean the file is fake.

Final Thoughts

Detecting fake FLAC files takes a combination of tools, knowledge, and critical listening. While Spek and bitrate guidelines provide strong indicators, no method is 100% reliable. Still, by learning to recognize the red flags, you can better curate a truly lossless music library.

The post How to Identify Fake FLAC Files appeared first on TechOpt.

]]>
https://www.techopt.io/music-production/how-to-identify-fake-flac-files/feed 0
Local Account Creation During Windows 11 Setup https://www.techopt.io/windows/local-account-creation-during-windows-11-setup https://www.techopt.io/windows/local-account-creation-during-windows-11-setup#respond Fri, 09 May 2025 00:41:00 +0000 http://localhost:8080/?p=66 If you have recently set up a new computer with Windows 11, you probably noticed that you can no longer choose a local account instead of a Microsoft account. Previous workarounds, such as entering an invalid email address or disconnecting the internet, no longer seem to work. There are benefits to using a Microsoft account […]

The post Local Account Creation During Windows 11 Setup appeared first on TechOpt.

]]>
If you have recently set up a new computer with Windows 11, you probably noticed that you can no longer choose a local account instead of a Microsoft account. Previous workarounds, such as entering an invalid email address or disconnecting the internet, no longer seem to work.

There are benefits to using a Microsoft account with your PC, but you might still want to use a local account. Some people prefer using a local account for administrative or privacy reasons. Also, you can always sign-in to a Microsoft account at a later time.

You can still create a local account during initial setup, but it’s harder than before. Here are the steps for skipping Microsoft account login and creating a local account in newer versions of the Windows 11 Home out-of-box setup experience.

1. Proceed Through Initial Setup Until the Microsoft Account Screen

Proceed through the initial setup steps by configuring the options and clicking Next. You’ll eventually wind up at the Microsoft account screen.

Microsoft account screen during local account creation on Windows 11

2. Open Command Prompt from Setup with SHIFT+F10

Once you’re in the initial setup wizard shown above, press SHIFT+F10 on your keyboard. This will open a command prompt window.

3. Type start ms-cxh:localonly and Hit Enter

Click inside of the command prompt window and type start ms-cxh:localonly.

start ms-cxh:localonly in command prompt to create a local account on Windows 11

Hit Enter.

4. Create a Local Account

A new screen will open to create a local account. Type a username, password and choose your security questions.

Create a user window to create a local account on Windows 11 Home

When you’re done, simply click Next to proceed to the desktop as you normally would!

Remarks

  • Although you can technically run this command at the beginning of setup, it’s best to get to the Microsoft account screen first to easily configure your system’s region, keyboard settings and network.
  • As of right now, you can still create a local account on Windows 11 Pro and Enterprise versions from the setup wizard.
  • My opinion is that this clearly shows the direction Microsoft is taking with its consumer line of products. They want us to be reliant on their cloud as much as possible!

Update 05/08/2025: The command previously suggested in this article, oobe\bypassnro, has been disabled by Microsoft as of Windows 11 build 26100. Only the start ms-cxh:localonly command should be used going forward.

If you prefer a video to follow along, you can watch the tutorial on my YouTube channel down below:

The post Local Account Creation During Windows 11 Setup appeared first on TechOpt.

]]>
https://www.techopt.io/windows/local-account-creation-during-windows-11-setup/feed 0
App Center Alternatives for React Native Developers https://www.techopt.io/programming/app-center-alternatives-for-react-native-developers https://www.techopt.io/programming/app-center-alternatives-for-react-native-developers#respond Sun, 16 Mar 2025 02:47:39 +0000 https://www.techopt.io/?p=833 Microsoft’s decision to discontinue and sunset App Center has left many React Native developers searching for reliable alternatives. If you’ve been using App Center for building, testing, and distributing your apps, it’s time to explore new solutions. In this guide, we’ll break down the best App Center alternatives to help you keep your workflow efficient […]

The post App Center Alternatives for React Native Developers appeared first on TechOpt.

]]>
Microsoft’s decision to discontinue and sunset App Center has left many React Native developers searching for reliable alternatives. If you’ve been using App Center for building, testing, and distributing your apps, it’s time to explore new solutions. In this guide, we’ll break down the best App Center alternatives to help you keep your workflow efficient and uninterrupted.

Why Is App Center Being Discontinued?

App Center has been a go-to choice for mobile developers, providing CI/CD capabilities, automated testing, and distribution for iOS and Android apps. However, Microsoft has decided to sunset the platform, leaving teams to find replacement services that meet their needs. Therefore, selecting the right alternative is crucial. The key factors in choosing an alternative include build automation, real-device testing, seamless app distribution, and over-the-air (OTA) updates.

Best App Center Alternatives for React Native

1. EAS (Expo Application Services)

For teams using EAS, it provides an all-in-one solution for building, updating, and distributing React Native apps. As a result, it is one of the best alternatives to App Center, especially for projects already leveraging Expo.

  • Pros:
    • Seamless integration with Expo projects
    • No need for local machine setup
    • Cloud-based builds for iOS and Android
    • EAS Update serves as an alternative to CodePush, allowing for seamless OTA updates
  • Cons:
    • Primarily geared toward Expo-managed projects
    • Limited flexibility for bare React Native apps

2. Hot Updater (Self-Hosted CodePush Alternative)

If you relied on App Center for CodePush, a crucial feature for deploying over-the-air updates, you need a replacement. Fortunately, one of the best open-source alternatives is Hot Updater. This is my personal favourite CodePush replacement. It provides similar functionality while allowing you to self-host your own OTA update solution.

  • Pros:
    • Self-hosted, offering full control over updates
    • Supports both iOS and Android
    • Intuitive web console for managing versions
    • Plugin support for various storage providers (AWS S3, Supabase, etc.)
  • Cons:
    • Requires infrastructure setup and maintenance
    • Needs DevOps expertise for proper implementation

3. Bitrise

Bitrise is one of the most popular CI/CD platforms for mobile development. It offers cloud-based automation, supports React Native out of the box, and provides a flexible pipeline system for building, testing, and deploying apps. Consequently, many teams transitioning from App Center have found it to be a reliable alternative.

  • Pros:
    • Pre-configured workflows for React Native
    • Easy integration with GitHub, GitLab, and Bitbucket
    • Supports both iOS and Android
  • Cons:
    • Limited free-tier resources
    • Learning curve for advanced workflow customization

4. Codemagic

Codemagic is another excellent CI/CD tool that specializes in mobile development. It supports React Native projects and simplifies the build and deployment process with minimal configuration. Additionally, its user-friendly approach makes it a strong choice for teams looking for a quick transition.

  • Pros:
  • Cons:
    • Can get expensive for teams with heavy usage
    • Limited concurrent builds on the free plan

5. Firebase App Distribution

If your primary need is distributing pre-release versions of your app, Firebase App Distribution is a great alternative to App Center’s distribution feature. Moreover, it integrates well with other Firebase tools, making it an appealing choice for teams already using Firebase.

  • Pros:
    • Easy tester management
    • Integrates with Firebase Crashlytics for monitoring
    • Works for both iOS and Android
  • Cons:
    • No built-in CI/CD
    • Requires additional tools for automated builds

Choosing the Right App Center Alternative for Your React Native Project

The best App Center alternative depends on your specific needs:

As App Center sunsets, transitioning to a new platform early will help ensure a smooth workflow. Consequently, by selecting the right alternative, you can continue to build, test, distribute, and update your React Native apps with minimal disruption.

The post App Center Alternatives for React Native Developers appeared first on TechOpt.

]]>
https://www.techopt.io/programming/app-center-alternatives-for-react-native-developers/feed 0
Adding a Script Tag to HTML Using Nginx https://www.techopt.io/servers-networking/adding-a-script-tag-to-html-using-nginx https://www.techopt.io/servers-networking/adding-a-script-tag-to-html-using-nginx#respond Tue, 04 Mar 2025 01:55:00 +0000 https://www.techopt.io/?p=829 Recently, I needed to add a script to an HTML file using Nginx. Specifically, I wanted to inject an analytics script into the <head> section of a helpdesk software’s HTML. The problem? The software had no built-in way to integrate custom scripts. Since modifying the source code wasn’t an option, I turned to Nginx as […]

The post Adding a Script Tag to HTML Using Nginx appeared first on TechOpt.

]]>
Recently, I needed to add a script to an HTML file using Nginx. Specifically, I wanted to inject an analytics script into the <head> section of a helpdesk software’s HTML. The problem? The software had no built-in way to integrate custom scripts. Since modifying the source code wasn’t an option, I turned to Nginx as a workaround.

Warning

Use this method at your own risk. Modifying HTML responses through Nginx can easily break your webpage if not handled carefully. Always test changes in a controlled environment before deploying them to production.

Nginx is not designed for content manipulation, and this approach should only be used as a last resort. Before proceeding, exhaust all other options, such as modifying the source code, using a built-in integration, or leveraging a client-side solution.

How to Add a Script to HTML Using Nginx

If you need to add a script, or any other HTML to an HTML file using Nginx, you can use the sub_filter module to modify response content on the fly. By leveraging this, we can insert a <script> tag before the closing </head> tag in the HTML document.

Configuration Example

To achieve this, add the following to your Nginx configuration:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://backend;
        proxy_buffering off;

        sub_filter '</head>' '<script src="https://example.com/analytics.js"></script></head>';
        sub_filter_types text/html;
        sub_filter_once on;
    }
}

Explanation

  • sub_filter '</head>' '<script src="https://example.com/analytics.js"></script></head>': This replaces </head> with our script tag, ensuring it appears in the document head.
  • sub_filter_types text/html;: Ensures the filter applies only to HTML responses.
  • sub_filter_once on;: Ensures that the replacement happens only once, as </head> should appear only once in a valid HTML document.

Adding an Nginx Proxy for Script Injection

To implement this solution without modifying the existing helpdesk software, I set up another Nginx instance in front of it. This new Nginx proxy handles incoming requests, applies the sub_filter modification, and then forwards the requests to the helpdesk backend.

Here’s how the setup works:

  1. The client sends a request to example.com.
  2. Nginx intercepts the request, modifies the HTML response using sub_filter, and injects the script.
  3. The modified response is then sent to the client, appearing as if it were served directly by the helpdesk software.

This approach keeps the original application untouched while allowing script injection through the proxy layer.

Remarks

  • Nginx is primarily a proxy and web server, not a content manipulation tool. Modifying content in this way should be a last resort after exhausting all other options, such as modifying the source code, using a built-in integration, or leveraging a client-side solution. Overuse of sub_filter can introduce unexpected behavior, break page functionality, or impact performance.
  • sub_filter requires proxy_buffering off;, which may degrade performance, especially for high-throughput sites, by preventing response buffering and increasing load on the backend.
  • If you’re adding multiple scripts or need flexibility, consider using a tag manager such as Google Tag Manager instead.
  • You can use this method to modify or inject any HTML, not just scripts.

The post Adding a Script Tag to HTML Using Nginx appeared first on TechOpt.

]]>
https://www.techopt.io/servers-networking/adding-a-script-tag-to-html-using-nginx/feed 0
LXC Containers (CTs) vs. Virtual Machines (VMs) in Proxmox https://www.techopt.io/servers-networking/lxc-containers-vs-virtual-machines-in-proxmox https://www.techopt.io/servers-networking/lxc-containers-vs-virtual-machines-in-proxmox#respond Tue, 25 Feb 2025 02:40:15 +0000 https://www.techopt.io/?p=824 Proxmox is a powerful open-source platform that makes it easy to create and manage both LXC containers (CTs) and virtual machines (VMs). When considering LXC containers vs virtual machines in Proxmox, it’s essential to understand their differences and best use cases. When setting up a new environment, you might wonder whether you should deploy your […]

The post LXC Containers (CTs) vs. Virtual Machines (VMs) in Proxmox appeared first on TechOpt.

]]>
Proxmox is a powerful open-source platform that makes it easy to create and manage both LXC containers (CTs) and virtual machines (VMs). When considering LXC containers vs virtual machines in Proxmox, it’s essential to understand their differences and best use cases.

When setting up a new environment, you might wonder whether you should deploy your workload inside an LXC container or a full VM. The choice depends on what you are trying to achieve.

LXC Containers: Lightweight and Efficient

LXC (Linux Containers) provides an efficient way to run isolated environments on a Proxmox system. Unlike traditional VMs, containers share the host system’s kernel while maintaining their own isolated user space. This means they use fewer resources, start up quickly, and offer near-native performance.

When to Use LXC Containers:

  • Single Applications – If you need to run a single application in an isolated environment, an LXC container is an excellent choice.
  • Docker Workloads – If an application is only available as a Docker image, you can run Docker inside an LXC container, avoiding the overhead of a full VM.
  • Resource Efficiency – LXC containers consume fewer resources, making them ideal for lightweight applications that don’t require their own kernel.
  • Speed – Since LXC containers don’t require full emulation, they start almost instantly compared to VMs.

Considerations for LXC Containers:

  • Less Isolation – Since they share the host kernel, they are not as isolated as a full VM, which can pose security risks if an attacker exploits vulnerabilities in the kernel or improperly configured permissions.
  • Compatibility Issues – Some applications that expect a full OS environment may not work well inside an LXC container.
  • Limited System Control – You don’t have complete control over kernel settings like you would in a VM.

Virtual Machines: Full System Isolation

Virtual machines in Proxmox use KVM (Kernel-based Virtual Machine) technology to provide a fully virtualized system. Each VM runs its own operating system with its own kernel, making it functionally identical to a physical machine.

When to Use Virtual Machines:

  • Multiple Applications Working Together – If you need to run a system with multiple interacting services, a VM provides a fully isolated environment.
  • Custom Kernel or OS Requirements – If your application requires a specific kernel version or a non-Linux operating system (e.g., Windows or BSD), a VM is the way to go.
  • Strict Security Requirements – Since VMs have strong isolation from the host system, they provide better security for untrusted workloads.
  • Compatibility – Any software that runs on a physical machine will run in a VM without modification.

Considerations for Virtual Machines:

  • Higher Resource Usage – VMs require more CPU, RAM, and disk space compared to containers.
  • Slower Start Times – Because they emulate an entire system, VMs take longer to boot up.
  • More Maintenance – You’ll need to manage full OS installations, updates, and security patches for each VM separately.

Final Thoughts: When to Choose LXC Containers vs. Virtual Machines in Proxmox

In general, if you need to run a single application in isolation, or if your application is only available as a Docker image, an LXC container is the better choice. Containers are lightweight, fast, and efficient. However, if you’re running a more complex system with multiple interacting applications, need complete OS independence, or require strong isolation, a VM is the better solution.

Proxmox makes it easy to work with both LXC and VMs, so understanding your workload’s needs will help you choose the right tool for the job. By leveraging the strengths of each, you can optimize performance, security, and resource usage in your environment.

The post LXC Containers (CTs) vs. Virtual Machines (VMs) in Proxmox appeared first on TechOpt.

]]>
https://www.techopt.io/servers-networking/lxc-containers-vs-virtual-machines-in-proxmox/feed 0
When to Use (and Not Use) Tailwind CSS in 2025 https://www.techopt.io/programming/when-to-use-and-not-use-tailwind-css-in-2025 https://www.techopt.io/programming/when-to-use-and-not-use-tailwind-css-in-2025#comments Sun, 23 Feb 2025 22:11:20 +0000 https://www.techopt.io/?p=819 Introduction Tailwind CSS has solidified its place in the modern web development ecosystem, offering a utility-first approach that streamlines styling for complex projects. While Tailwind is a powerful tool, it’s not a one-size-fits-all solution. In 2025, Tailwind is more popular than ever, but there are cases where it may not be the best choice. Let’s […]

The post When to Use (and Not Use) Tailwind CSS in 2025 appeared first on TechOpt.

]]>
Introduction

Tailwind CSS has solidified its place in the modern web development ecosystem, offering a utility-first approach that streamlines styling for complex projects. While Tailwind is a powerful tool, it’s not a one-size-fits-all solution. In 2025, Tailwind is more popular than ever, but there are cases where it may not be the best choice. Let’s break down when to use Tailwind, and when to consider alternatives.

When to Use Tailwind CSS

1. Complex, Multi-Page Websites

Tailwind shines in large-scale, multi-page applications where design consistency is critical. With reusable utility classes, developers can ensure a unified UI without wrestling with conflicting styles from separate CSS files. Platforms like SaaS applications, dashboards, and content-heavy websites benefit immensely from Tailwind’s scalable approach.

2. Rapid Prototyping

If speed is a priority, Tailwind helps teams iterate faster. Its utility classes allow developers to style components directly in markup, reducing the need for custom CSS. This makes it ideal for MVPs, startup projects, and proof-of-concept applications where time-to-market is crucial.

3. Projects Requiring Design System Enforcement

Tailwind is a great fit for teams that need strict adherence to a design system. The ability to define custom themes, typography, and color palettes in the tailwind.config.js file ensures that styles remain consistent across all pages and components.

Tailwind CSS version 4, which was just released, takes this a step further. This new version of Tailwind allows for most configuration to be done right inside of your main CSS file.

4. Component-Based Frameworks (React, Vue, Svelte, Next.js, etc.)

For teams using modern frameworks, Tailwind works seamlessly with component-driven development. It allows styling to live alongside the component logic, promoting maintainability and reducing CSS file bloat.

5. Web Apps with a Long Development Lifecycle

Maintaining large applications is easier with Tailwind since it reduces CSS complexity. Unlike traditional CSS or preprocessor-based approaches, Tailwind minimizes global styles, making it easier to refactor and extend applications over time.

When Not to Use Tailwind CSS

1. Small, Static Websites or Simple Landing Pages

For one-page websites or simple marketing pages, Tailwind may be overkill. A minimal custom CSS file or even plain HTML/CSS may suffice. Using Tailwind in such cases could add unnecessary overhead without significant benefits.

2. Highly Unique, Artistic Designs

While Tailwind is flexible, highly creative or experimental designs with intricate animations, custom typography, and complex layouts might be better served with traditional CSS, SCSS, or CSS-in-JS. Tailwind’s structured approach may feel limiting for designers who prefer complete freedom over styles.

3. Teams Without Tailwind Experience

Despite its advantages, Tailwind has a learning curve. Developers unfamiliar with its utility-first approach may struggle initially. If a team lacks experience or doesn’t have time to invest in learning Tailwind, sticking to traditional CSS methodologies may be more efficient.

4. Legacy Codebases with Predefined Styles

If you’re working on a legacy project that already has well-structured CSS or a component library, integrating Tailwind could introduce inconsistencies and unnecessary complexity. Migrating to Tailwind in such cases should be a carefully considered decision.

5. Strict SEO or Performance-Optimized Websites Where Every KB Counts

While Tailwind’s PurgeCSS ensures minimal CSS footprint, in some ultra-performance-critical cases, writing minimal, handcrafted CSS might still be preferable. Projects that need to prioritize reducing external dependencies might opt for vanilla CSS instead.

Conclusion: When to use Tailwind CSS in 2025

Tailwind CSS is a top choice for complex, multi-page applications, design-consistent systems, and component-driven frameworks in 2025. However, it’s not always the best tool for every scenario.

For small static sites, highly creative designs, or legacy projects, traditional CSS approaches may still hold an advantage. Understanding when to use Tailwind, and when not to, will help you maximize efficiency while maintaining flexibility in your web development workflow.

The post When to Use (and Not Use) Tailwind CSS in 2025 appeared first on TechOpt.

]]>
https://www.techopt.io/programming/when-to-use-and-not-use-tailwind-css-in-2025/feed 2
Set Custom Device Icons in Zigbee2MQTT in Home Assistant https://www.techopt.io/smart-home/set-custom-device-icons-in-zigbee2mqtt-in-home-assistant https://www.techopt.io/smart-home/set-custom-device-icons-in-zigbee2mqtt-in-home-assistant#respond Mon, 17 Feb 2025 16:19:01 +0000 https://www.techopt.io/?p=790 Zigbee2MQTT is a fantastic tool for integrating Zigbee devices into Home Assistant, but sometimes the default icons don’t match the specific version of your device. For example, I’m using an IKEA E2204 smart plug (North American version, the TRETAKT), but Zigbee2MQTT displays the European version. To fix this, I set a custom icon, and in […]

The post Set Custom Device Icons in Zigbee2MQTT in Home Assistant appeared first on TechOpt.

]]>
Zigbee2MQTT is a fantastic tool for integrating Zigbee devices into Home Assistant, but sometimes the default icons don’t match the specific version of your device. For example, I’m using an IKEA E2204 smart plug (North American version, the TRETAKT), but Zigbee2MQTT displays the European version. To fix this, I set a custom icon, and in this guide, I’ll show you how to do the same for any device.

Steps to Set Custom Icons in Zigbee2MQTT Home Assistant Add-On

1. Open Your Home Assistant Configuration Folder

You’ll need to access the zigbee2mqtt folder in your Home Assistant config directory. I use the Studio Code Server add-on to do this, but you can use any method you prefer.

  • If using Studio Code Server, navigate to config/zigbee2mqtt/.
Zigbee2MQTT config folder in Home Assistant

2. Create the device_icons Folder

If the device_icons folder doesn’t already exist inside the zigbee2mqtt directory, create it.

  • In Studio Code Server, right-click inside the zigbee2mqtt folder and select New Folder.
  • Name the folder device_icons.
Custom device icons folder Zigbee2MQTT in Home Assistant

3. Add Your Custom Icon

For best results, your icon should be:

  • A PNG file
  • 512×512 pixels
  • Have a transparent background

To add it:

  • Drag and drop the PNG file into the device_icons folder using the Studio Code Server file browser.
  • Alternatively, upload the file using an SCP tool or any other method that works for you.

For my IKEA E2204 smart plug, I named my file:

ikea-tretakt-smart-plug.png

4. Assign the Icon in Zigbee2MQTT

Now that the icon is in place, it’s time to assign it to your device in Zigbee2MQTT.

  1. Open Zigbee2MQTT in Home Assistant.
  2. Find your device in the Devices list and click on its name.
  3. Go to the Settings tab.
  4. Scroll all the way down to the Icon box.
  5. Enter the relative path of your icon, e.g.:device_icons/ikea-tretakt-smart-plug.png
  6. Click Submit.
Set custom icon path in Zigbee2MQTT in Home Assistant

5. Verify Your New Icon

Once you’ve assigned the custom icon:

  • Go back to the Devices page in Zigbee2MQTT.
  • Your new icon should now appear next to the device name!
Showing custom icons in Zigbee2MQTT in Home Assistant

Final Thoughts

Using custom icons in Zigbee2MQTT in Home Assistant is a great way to make your smart home setup more intuitive and visually appealing. Whether you’re correcting an incorrect default icon or just want a personalized look, this method is quick and easy!

The post Set Custom Device Icons in Zigbee2MQTT in Home Assistant appeared first on TechOpt.

]]>
https://www.techopt.io/smart-home/set-custom-device-icons-in-zigbee2mqtt-in-home-assistant/feed 0
Best Zigbee Channel to Use: Avoiding Interference https://www.techopt.io/smart-home/best-zigbee-channel-to-use-avoiding-interference https://www.techopt.io/smart-home/best-zigbee-channel-to-use-avoiding-interference#respond Sun, 16 Feb 2025 22:55:35 +0000 https://www.techopt.io/?p=775 If you’re setting up a Zigbee network for your smart home, choosing the right Zigbee channel is crucial for ensuring reliable communication between your devices. One of the biggest challenges Zigbee networks face is interference from other wireless signals, with Wi-Fi being a primary example. Selecting the right channel can help minimize connectivity issues and […]

The post Best Zigbee Channel to Use: Avoiding Interference appeared first on TechOpt.

]]>
If you’re setting up a Zigbee network for your smart home, choosing the right Zigbee channel is crucial for ensuring reliable communication between your devices. One of the biggest challenges Zigbee networks face is interference from other wireless signals, with Wi-Fi being a primary example. Selecting the right channel can help minimize connectivity issues and improve the stability of your smart home.

Understanding Zigbee and Wireless Interference

Zigbee operates in the 2.4 GHz band using channels numbered from 11 to 26. Meanwhile, Wi-Fi networks (802.11b/g/n) also use the 2.4 GHz band, which can create potential interference with Zigbee signals. Other sources of interference include Bluetooth devices, microwaves, and cordless phones.

Here’s a breakdown of how Zigbee and Wi-Fi channels overlap:

  • Zigbee Channel 11 (2405 MHz) – Overlaps with Wi-Fi channels 1-3 (high interference potential).
  • Zigbee Channel 15 (2425 MHz) – Slightly overlaps with Wi-Fi channels 6-7 (a much better choice).
  • Zigbee Channel 20 (2450 MHz) – Slightly overlaps with Wi-Fi channels 9-11 (another good option).
  • Zigbee Channel 25 (2475 MHz) – Sits near Wi-Fi channel 13 (a solid choice in some cases, but not all devices support it well).
  • Zigbee Channel 26 (2480 MHz) – Least interference but has reduced transmission power in some regions.

To visually see the overlap between Wi-Fi and Zigbee channels, you can consult the graph below:

Wifi vs. Zigbee channels overlap graph

Recommended Zigbee Channels

Based on interference patterns, the best Zigbee channels to use are:

1. Channel 15 (2425 MHz)

This channel is one of the best choices because it avoids heavy overlap with common Wi-Fi channels like 1, 6, and 11. It provides a stable connection for most Zigbee devices.

2. Channel 20 (2450 MHz)

Another great option, channel 20, minimizes interference while maintaining strong signal strength. If you experience issues with channel 15, this is a great alternative.

3. Channel 25 (2475 MHz) – With Caution

Channel 25 can work well in environments where interference is a problem, as it avoids most of the congestion. However, some Zigbee devices may not fully support this channel, leading to inconsistent performance.

You should test each device individually with Channel 25 and make sure that you aren’t experiencing any issues. If everything seems okay, channel 25 should work for you.

Zigbee Channel 11: Why You Should Avoid It

Zigbee channel 11 is the default for many devices, but it overlaps heavily with Wi-Fi channels 1, 2, and 3. If you leave your Zigbee network on channel 11 in a busy environment, you may experience dropped connections and slow response times.

Remarks

  • Best Channels: Zigbee channel 15 and 20 provide the best balance of performance and minimal interference.
  • Channel 25 Consideration: If your devices support it, channel 25 can work well in certain environments but may not be compatible with all devices. Test your devices for compatibility.
  • Avoid Channel 11: Due to its heavy overlap with Wi-Fi, channel 11 is not recommended unless necessary.
  • Check Your Network: Use tools like Zigbee2MQTT or Home Assistant’s network map to analyze and optimize your Zigbee network.
  • Interference Sources: Besides Wi-Fi, other wireless signals such as Bluetooth, microwaves, and cordless phones can also impact Zigbee performance.
  • Multiple Zigbee Networks: If you have more than one Zigbee network, use different channels to avoid interference. For example, I have my Philips Hue on channel 15 and my Home Assistant Zigbee2MQTT network on channel 20.
  • Wi-Fi Channel 13: Depending on your region, Wi-Fi channel 13 may not be a concern. In Europe and most parts of Asia, channel 13 is allowed and commonly used, whereas in North America, its use is restricted. This means that interference from Wi-Fi channel 13 may not be an issue depending on where you live.

The post Best Zigbee Channel to Use: Avoiding Interference appeared first on TechOpt.

]]>
https://www.techopt.io/smart-home/best-zigbee-channel-to-use-avoiding-interference/feed 0