teleren/devto huggingface dataset:
Simplest way to implement dark mode in your react + tailwind project
Tags: webdev, react, vite
Published: 2022-12-26 12:55:35

Having dark mode in your website is essential nowadays. In this blog post I will show you how to implement dark mode in your react + tailwind app. This involves 3 simple steps.
## Step 1 : Opting into dark mode in tailwind config file
Open your `tailwind.config.cjs` and add this to your config.

![changes to make to tailwind.config.cjs file for opting into darkmode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hx0kwzto745uibqx95ie.png)

## Step 2 : Writing the logic for dark mode to work
In your hooks folder create a new file named `useTheme.js` with the following lines of code in it.

![useTheme.js file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxoa0w4qtf3c09mh8fwz.png)

This code takes user's preferred theme into account and it also stores the theme state in browser's localStorage so that preferred theme is persisted between different sessions. So feel free to copy this and paste it in `useTheme.js` file which we have created.

Next use this `theme` state and `toggleTheme` function to make an ui so that your users can switch between different theme options. I used icons from react-icons to achieve this.

![code snipped for ui which allows users to change theme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h91oaplbzrir6osg2my7.png)


## Step 3 : Adding styles for dark mode
This is the final step for implementing dark mode in your app. Define the classNames you want to use when theme is set to dark with a prefix `dark:`. For example if you want to use text-neutral-100 className in dark mode use `dark:text-neutal-100`.

Here is a code snippet for your reference 👇

![code snippet for using dark mode in tailwind css](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6nb4e3fns5y5t93tj8z.png)

Since I have added `dark:bg-dark-background` to my root div, when users change their preferred theme to dark either by using the ui we created in step 2 or by changing their preferred theme in browser bg-dark-background className is added to my root div. I have defined dark-background with the value `#141414` in my `tailwind.config.cjs` file which makes the background of my root div to `#141414`. Add necessary styles to all the elements on your app and you are good to go.

Woohoo 🥳🎉 You have managed to add dark mode to your app. Don't forget to share your opinions on this article down in the comments 👇.

**Happy Hacking**
List of git commands every frontend developer should know
Tags: webdev, git, github, programming
Published: 2022-12-26 12:55:28

Git is a version control system that is widely used by software developers to track changes to their codebase and collaborate with other team members. As a frontend developer, it is important to have a good understanding of how to use Git to manage your code and work effectively with your team.

## Here is a list of Git commands that every frontend developer should know:

- **git init**: This command is used to initialize a new Git repository in the current directory. It creates a hidden .git directory that stores all the information about the repository, including a record of all the changes made to the code.

- **git clone**: This command is used to create a local copy of a remote repository. It allows you to download all the code and history from a remote repository and create a new local repository on your computer.

- **git add**: This command is used to stage changes for commit. When you make changes to your code, you can use git add to tell Git that you want to include these changes in the next commit. You can specify which files you want to add using the -A flag, or you can specify individual files by name.

- **git commit**: This command is used to create a new commit in the repository. A commit is a snapshot of the code at a particular point in time, and it includes a message describing the changes that were made. When you make a commit, Git adds the changes you have staged to the repository history.

- **git push**: This command is used to upload your local commits to a remote repository. It sends your commits to the remote repository, where they can be shared with other team members.

- **git pull**: This command is used to download new commits from a remote repository and merge them into your local repository. It is often used to get the latest version of the code from the remote repository and incorporate any changes made by other team members.

- **git branch**: This command is used to create and manage branches in a Git repository. A branch is a separate line of development that allows you to work on new features or bug fixes without affecting the main codebase. You can use the git branch command to create new branches, switch between branches, and merge branches back into the main codebase.

- **git merge**: This command is used to merge one branch into another. It combines the changes from the source branch into the destination branch, and creates a new commit to reflect the merge.

- **git stash**: This command is used to temporarily save changes that you are not ready to commit. It allows you to switch branches or switch to a different task without committing your changes, and then later restore them when you are ready to continue working on them.

By learning and using these Git commands, you can effectively manage your code and collaborate with your team as a frontend developer.
How to code a simple Flash light Android app? Step by Step Detailed Guide with Code
Tags: android, kotlin, tutorial, beginners
Published: 2022-12-26 12:38:45

To create a simple flashlight app for Android, you will need to use the Android SDK and programming language such as Java or Kotlin. Here is a step-by-step guide for creating a basic flashlight app in Android Studio, with code examples:

Install the Android Studio development environment and set up an emulator or connect a physical Android device to your computer.

Create a new Android project in Android Studio.

Design the layout of your app. This will involve creating the necessary XML files to define the user interface of your app, including any buttons or other UI elements you want to include. For this example, we will create a simple layout with a single toggle button to turn the flashlight on and off. Add the following code to your layout XML file:

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <Button
        android:id="@+id/button_flashlight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toggle Flashlight"
        android:onClick="toggleFlashlight" />

</LinearLayout>

```

- In your app's main activity, define a method to handle the flashlight toggle button press. This method will use the Android CameraManager class to control the device's camera flash through the use of camera "torch" mode. Add the following code to your activity:

```
private boolean flashlightOn = false;

public void toggleFlashlight(View view) {
    // Get the camera manager
    CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);

    try {
        // Get the camera id for the first camera
        String cameraId = cameraManager.getCameraIdList()[0];

        // Toggle the flashlight on or off
        if (flashlightOn) {
            cameraManager.setTorchMode(cameraId, false);
            flashlightOn = false;
        } else {

```

Boom! You created a flashlight app! [Reach me](https://quokkalabs.com/android-app-development) if you want any help and guidance on your project.
A HTTPRequest article by generated by ChatGPT!
Tags: javascript, tutorial, webdev, beginners
Published: 2022-12-26 12:34:53

This http request article generated by ChatGPT!

HTTP (Hypertext Transfer Protocol) is a protocol that is used for communication between a client and a server on the World Wide Web. It allows clients (e.g. a web browser) to send requests to servers (e.g. a web server) and receive responses in return.

There are several different types of HTTP requests that can be made, including `GET`, `POST`, `PUT`, `DELETE`, and others. Each type of request serves a different purpose and is used in different scenarios.

Here is a brief overview of the most common types of HTTP requests:

- **GET**: A `GET` request is used to retrieve information from a server. It is the most common type of request and is used to retrieve a webpage or other resource.
- **POST**: A `POST` request is used to send data to a server for processing. It is typically used when a user submits a form or uploads a file.

- **PUT**: A `PUT` request is used to update an existing resource on the server.

- **DELETE**: A `DELETE` request is used to delete a resource from the server.

To make an HTTP request in JavaScript, you can use the `XMLHttpRequest` object or the `fetch()` function.

Here is an example of an HTTP `GET` request using `XMLHttpRequest`:
```js
// Create an instance of the XMLHttpRequest object
var xhr = new XMLHttpRequest();

// Set the request method, URL, and other options
xhr.open('GET', 'http://www.example.com/somefile.txt', true);

// Send the request
xhr.send();
```

And here is an example of an HTTP `GET` request using `fetch()`:
```js
// Send the request
fetch('http://www.example.com/somefile.txt')
  .then(function(response) {
    // Handle the response
  });
```

These examples demonstrate how to make a simple GET request, but you can use other request methods (e.g. `POST`, `PUT`, `DELETE`) by setting the `open()` method's third argument accordingly.

HTTP requests are an essential part of web development and are used to retrieve and send data between clients and servers. Whether you are using XMLHttpRequest or fetch(), understanding how to make HTTP requests is an important skill for any frontend developer.

Finish here ------------

So, this one just a small blog. You can even create script for your video, generate any type of blog! Besides, If you worked with WordPress, you surely know what is plugin. Fact is, you also able to create plugin with chatGPT and you dont even need to write a single line of code. Sound wired?

If you feel lonely, chat with chatGPT.
How to code an Android app like CPU-Z in Android Studio | Detailed Guide with Code
Tags: android, beginners, tutorial, programming
Published: 2022-12-26 12:20:14

To create an Android app similar to CPU-Z in Android Studio, you will need to use the Android SDK and programming language such as Java or Kotlin. Here is a step-by-step guide for creating a basic app that displays hardware and system information:

- Install the Android Studio development environment and set up an emulator or connect a physical Android device to your computer.

- Create a new Android project in Android Studio.

- Design the layout of your app. This will involve creating the necessary XML files to define the user interface of your app, including any buttons, text fields, or other UI elements you want to include. For this example, we will create a simple layout with a few TextView elements to display the information.

- In your app's main activity, use the Android SDK to access the phone's hardware and system information. Add the following code to your activity:

```
// Get the device's model number
String model = Build.MODEL;

// Get the device's manufacturer
String manufacturer = Build.MANUFACTURER;

// Get the device's Android version
String version = Build.VERSION.RELEASE;

// Get the device's CPU architecture
String cpuArch = System.getProperty("os.arch");

// Get the device's CPU cores and frequency
HardwarePropertiesManager hwManager = (HardwarePropertiesManager) getSystemService(HARDWARE_PROPERTIES_SERVICE);
HardwareProperties hwProperties = hwManager.getHardwareProperties(HardwarePropertiesManager.DEVICE_CPU_PROPERTIES);
int numCores = hwProperties.getNumCores();
float[] freqRange = hwProperties.getCpuMaxFreqKHz();
float maxFreq = freqRange[HardwareProperties.INDEX_MAX];

// Get the device's total and available memory
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(memoryInfo);
long totalMemory = memoryInfo.totalMem;
long availableMemory = memoryInfo.availMem;

```
In your layout XML file, add the TextView elements to display the information. Set the text attribute of each TextView to the corresponding variable from step 4.

In your app's manifest file, add the HARDWARE_PROPERTIES_SERVICE and ACTIVITY_SERVICE permissions to allow the app to access the device's hardware and memory information.

Run your app on the emulator or physical device to see the hardware and system information displayed in the app.

Here is an example of how the final layout XML file might look:

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text_model"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Model: " />

    <TextView
        android:id="@+id/text_manufacturer"
        android:layout_width

```

[Reach me](https://quokkalabs.com/android-app-development) if you want any help! :)
Java 20 - Divide and concurrent
Published: 2022-12-26 12:15:44

---
title: Java 20 - Divide and concurrent
published: true
description: We look into the changes made in the latest release of Java, 20.
tags:
cover_image: https://i.ytimg.com/vi/QfekRoO4sjo/maxresdefault.jpg
---

{% youtube QfekRoO4sjo %}

We look into the changes made in the latest release of Java, 20.
How to make a Screen Shot Android app? Step by step guide
Tags: android, javascript, beginners, tutorial
Published: 2022-12-26 12:09:10

To create an Android app that takes screenshots, you will need to use the Android SDK and programming language such as Java or Kotlin. Here is a step-by-step guide for creating a simple screenshot app:

- Install the Android Studio development environment and set up an emulator or connect a physical Android device to your computer.

- Create a new Android project in Android Studio.

- Design the layout of your app. This will involve creating the necessary XML files to define the user interface of your app, including any buttons or other UI elements you want to include. For this example, we will create a simple layout with a single button to trigger the screenshot.

- In your app's main activity, define a method to handle the screenshot button press. This method will use the Android MediaProjection class to capture a screenshot of the device's screen and save it to a file. Add the following code to your activity:

```
private void takeScreenshot() {
    // Create an instance of the MediaProjection class
    MediaProjection mediaProjection = ...;

    // Get the display metrics to determine the dimensions of the screenshot
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    int density = metrics.densityDpi;

    // Create a virtual display using the MediaProjection
    Surface surface = mediaProjection.createVirtualDisplay("Screenshot",
            width, height, density,
            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
            null, null, null).getSurface();

    // Create a bitmap to hold the screenshot
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    // Create a canvas to draw the screenshot into the bitmap
    Canvas canvas = new Canvas(bitmap);

    // Draw the screenshot into the bitmap
    surface.draw(canvas);

    // Save the bitmap to a file
    File screenshotFile = new File(getExternalFilesDir(null), "screenshot.png");
    FileOutputStream fos = new FileOutputStream(screenshotFile);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
    fos.close();
}

```

- In your layout XML file, add a button to trigger the screenshot. Set the button's onClick attribute to the name of the method you defined in step 4.

- In your app's manifest file, add the WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions to allow the app to save and read files from the device's storage.

- Run your app on the emulator or physical device to test the screenshot functionality. When you press the button, the app should capture a screenshot and save it to the device's external storage.

I hope this helps! Let me know if you have any questions or need more guidance. You can [reach me here](https://quokkalabs.com/android-app-development).
🔥(Best Guide) How to code a Android app that shows phone's statistics and other hardware info?
Published: 2022-12-26 12:02:49

To create an [Android app](https://quokkalabs.com/mobile-app-development) that displays phone statistics and other hardware information, you will need to use the Android SDK and programming language such as Java or Kotlin. Here is a sample code snippet that demonstrates how to access and display some of this information:

```
// Get the phone's model number
String model = Build.MODEL;

// Get the phone's manufacturer
String manufacturer = Build.MANUFACTURER;

// Get the phone's battery level
BatteryManager bm = (BatteryManager)getSystemService(BATTERY_SERVICE);
int batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);

// Get the phone's storage capacity
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
long totalSpace = totalBlocks * blockSize;

// Display the information in a TextView
TextView tv = findViewById(R.id.text_view);
String text = "Model: " + model + "\n"
        + "Manufacturer: " + manufacturer + "\n"
        + "Battery Level: " + batteryLevel + "%\n"
        + "Total Storage: " + totalSpace + " bytes";
tv.setText(text);

```
This code will retrieve the phone's model number, manufacturer, battery level, and total storage capacity, and display them in a TextView.

To use this code in your app, you will need to add the necessary import statements at the top of your file and include the TextView in your layout XML file. You will also need to add the BATTERY_SERVICE permission to your app's manifest file.

I hope this helps! Let me know if you have any questions or need more guidance or you can [reach me here](https://quokkalabs.com/android-app-development).
Optimizing CSS Performance in Nuxt with Critters
Tags: vue, performance, webdev, javascript
Published: 2022-12-26 11:55:39

When working on imprving performance in websites, I always like to focus on one aspect or area at the time. It is rather difficult to take a performance checklist and include all recommendations at once, this just wont work.

In todays article, I would like to get you familiar with a tool that I discovered recently called Critters. This tool will help you optimize your CSS, what eventually will contribute to better performance of your website (one aspect at the time ;)

## What is Critters?

Critters is a plugin that inlines your app's critical CSS and lazy-loads the rest. You can check the full documentation about it [here](https://github.com/GoogleChromeLabs/critters).

Critters' design makes it a good fit when inlining critical CSS for prerendered/SSR'd Single Page Applications. It was developed to be an excellent compliment to prerender-loader, combining to dramatically improve first paint time for most Single Page Applications.

## Usage in Nuxt

Using this tool in Nuxt is relatively simple because there is already a module for that. If you like to learn more, make sure to check out the following [link](https://github.com/nuxt-modules/critters).

The module provies:

* Zero-configuration required
* Enables CSS Extraction
* Critical CSS automatically injected to page
* Works with Nitro prerendering

In order to install the module make sure to use the following command:

```bash
yarn add @nuxtjs/critters # or npm install @nuxtjs/critters
```

And include it in your `modules` array:

```ts
{
  modules: [
    '@nuxtjs/critters',
  ],
}
```

You can also pass some options if you like:

```ts
// nuxt.config.js
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
  modules: ['@nuxtjs/critters'],
  critters: {
    // Options passed directly to critters: https://github.com/GoogleChromeLabs/critters#critters-2
    config: {
      // Default: 'media'
      preload: 'swap',
    },
  },
})
```

Nuxt has a number of ways to optimize your CSS in production:

* ✅ Nuxt uses cssnano in the build step to minify CSS rules
* 📦 You can enable purgecss to remove unused CSS rules from your bundle.
* ✅ with @nuxtjs/critters you can now extract CSS files and load them separately, just inlining the CSS necessary to render the page.

## Summary

And that's it! You have successfully managed to install and configure critters in your nuxt project. This is another step to make your Nuxt apps more performant! Let me know what other tools you would like me to try out next!