CODE X WP View RSS

Smart Solutions for Every Web Platform
Hide details



How to Restore an AWS RDS Database: Step-by-Step Guide for Beginners 19 May 5:57 PM (5 months ago)

🔍 Introduction

Amazon Web Services (AWS) provides powerful database solutions through its RDS (Relational Database Service).
Sometimes, due to data loss, corruption, or accidental deletion, you may need to restore an RDS database from a backup.
In this guide, we will walk you through the process of restoring an AWS RDS database step by step, whether you’re using
automated snapshots, manual snapshots, or point-in-time recovery.

📌 Prerequisites
  • Access to the AWS Management Console
  • IAM permissions to manage RDS
  • Backup (automated snapshot, manual snapshot, or point-in-time enabled)
🛠️ Methods of Restoring RDS

AWS provides several methods to restore a database:

  • Restore from an Automated Backup
  • Restore from a Manual Snapshot
  • Point-in-Time Recovery
🔄 Method 1: Restore from an Automated Backup
Steps:
  1. Login to the AWS Management Console and navigate to the RDS Dashboard.
  2. Select Databases and choose the database you want to restore.
  3. Click on ActionsRestore to point in time.
  4. Choose the time you want to restore to (can be up to 35 days back).
  5. Enter a new DB instance identifier (it will create a new RDS instance).
  6. Configure DB settings (VPC, security group, instance class, etc.).
  7. Click Restore DB Instance.
Note:

Automated backups must be enabled on your original RDS instance.

📸 Method 2: Restore from a Manual Snapshot
Steps:
  1. Go to the Snapshots section in the RDS dashboard.
  2. Choose the manual snapshot you want to restore.
  3. Click on ActionsRestore Snapshot.
  4. Provide a new name for the DB instance.
  5. Configure the database settings as needed.
  6. Click Restore DB Instance and wait for the restoration to complete.
Info:

Manual snapshots are retained even if the original database is deleted.

🕒 Method 3: Point-in-Time Recovery
When to Use:

This is helpful when you want to restore your RDS instance to a specific moment just before a mistake was made (e.g., dropped table).

Steps:
  1. From the RDS dashboard, select the source database.
  2. Click ActionsRestore to point in time.
  3. Specify the exact date and time for recovery.
  4. Provide a new DB instance identifier and customize settings as needed.
  5. Click Restore DB Instance.
Important:

Your RDS instance must have point-in-time recovery enabled beforehand.

✅ After Restoring
  • Update your application or connection strings to point to the new DB instance.
  • Test the restored database thoroughly before using it in production.
  • Apply any necessary security groups or parameter group configurations.
💡 Best Practices
  • Enable automated backups for all production databases.
  • Take manual snapshots before any major update or schema change.
  • Use naming conventions to easily identify restored databases.
  • Clean up unused snapshots to avoid unnecessary charges.
🧾 Conclusion

Restoring an AWS RDS database is a straightforward process when you understand the available options.
Whether you’re recovering from a data loss event or duplicating a database for testing purposes,
AWS provides reliable tools for each scenario. Always ensure your backup strategy is solid to protect your valuable data.

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Convert Word to Markdown Function 31 Mar 1:09 AM (6 months ago)

This function is designed to convert Microsoft Word (.docx) documents into clean, readable Markdown format. It efficiently handles HTML conversion using PHPWord and further refines the output by removing unnecessary image tags. This is particularly useful for content management systems, documentation platforms, and markdown-based projects.

Uses

Details

PHP Function

Here is the complete PHP function for converting Word documents to Markdown:

</pre>
use PhpOffice\PhpWord\IOFactory;
use League\HtmlToMarkdown\HtmlConverter;
use League\HtmlToMarkdown\Converter\TableConverter;

public function convertWordToMarkdown(string $filePath): string
{
// Convert DocX to HTML
$phpWord = IOFactory::load($filePath);
$htmlWriter = IOFactory::createWriter($phpWord, 'HTML');
ob_start();
$htmlWriter->save('php://output');
$html = ob_get_clean();

// Retrieve body content from HTML
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();
$body = $dom->getElementsByTagName('body')->item(0);
$bodyHtml = '';

// Remove <img> tags from the body content
$images = $dom->getElementsByTagName('img');
while ($img = $images->item(0)) {
$img->parentNode->removeChild($img);
}

// Rebuild the body HTML without the images
foreach ($body->childNodes as $node) {
$bodyHtml .= $dom->saveHTML($node);
}

// Convert HTML to Markdown
$converter = new HtmlConverter(['strip_tags' => true]);
$converter->getEnvironment()->addConverter(new TableConverter());

return $converter->convert($bodyHtml);
}

Installation Instructions

To use this function, ensure you have the following dependencies installed using Composer:

composer require phpoffice/phpword
composer require league/html-to-markdown

Example Use Case

$filePath = 'path/to/document.docx';
$markdown = convertWordToMarkdown($filePath);
echo $markdown;

This function is ideal for developers and content creators seeking a reliable solution for Word-to-Markdown conversion without compromising content quality. By automating the conversion, it reduces the time spent on manual content migration and formatting adjustments.

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Amazon S3 image with laravel authentication 7 Jan 2:19 AM (9 months ago)

Amazon S3 image with Laravel authentication. Sometimes we need to make private our website images, meaning users are not able to view images without logging in. For this purpose, the following code will help us restrict access.

1. First define a route in your route file.

Route::get('aws/images/{path}', [\App\Http\Controllers\TestController::class, 'imageShow'])->where('path', '(.*)')->name('aws_image')->middleware('auth');

2. Create a controller like “TestController” with a method like “imageShow” and call the library.

use App\Library\AwsImage;

public function imageShow($path)
{
    return AwsImage::get($path);
}

3. In the controller method, we called a library class “AwsImage”. So you can create a class with the following code.

class AwsImage
{
    const DRIVER = 's3';

    public static function get($path)
    {
        try {
            $extensions = ['jpg', 'png', 'jpeg', 'gif'];
            $path_arr = explode('.', $path);
            $length = count($path_arr);

            if (!isset($path_arr[$length - 1]) || !in_array($path_arr[$length - 1], $extensions)) {
                throw new Exception('Invalid image extension');
            }

            $ext = $path_arr[1];
            $image = Storage::disk(self::DRIVER)->get($path);

            if ($image == null) {
                throw new Exception('Image is not found');
            }

            return response()->make($image, 200, ['content-type' => 'image/' . $ext]);
        } catch (Exception $e) {
            return response($e->getMessage(), 404);
        }       
    }    
}

4. Everything is ready. Now you can use the following code in your blade file.

<img src="{{ route('aws_image', '$aws_image_path_from_db') }}">

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Show and hide a widget in flutter 7 Jan 1:52 AM (9 months ago)

When building a user interface in Flutter, you may want to show or hide widgets based on certain conditions. This can be achieved using the built-in show and hide functionality provided by Flutter.

In Flutter, every widget has a built-in property called `Visibility`. This property can be used to control whether a widget is visible or hidden. By default, the `Visibility` property is set to `visible`, which means the widget is visible on the screen. However, you can change the value of this property to `hidden` or `gone` to hide the widget.

To show or hide a widget in Flutter, you can use the `Visibility` widget. This widget takes two required parameters: `visible` and `child`. The `visible` parameter is a boolean value that determines whether the child widget should be visible or hidden. The `child` parameter is the widget that you want to show or hide.

Here is an example of how to show and hide a widget in Flutter:

Visibility(
  visible: true, // Set to true to show the widget
  child: Text('Hello, World!'),
)

In this example, the `Text` widget will be visible on the screen because the `visible` property is set to `true`. If you change the value of `visible` to `false`, the `Text` widget will be hidden from the screen.

You can also use the `Visibility` widget to animate the show and hide functionality. For example, you can use the `FadeTransition` widget to animate the opacity of a widget when it is shown or hidden. Here is an example:

Visibility(
  visible: true, // Set to true to show the widget
  child: FadeTransition(
    opacity: Tween<double>(
      begin: 0.0,
      end: 1.0,
    ).animate(_animationController),
    child: Text('Hello, World!'),
  ),
)

In this example, the `FadeTransition` widget is used to animate the opacity of the `Text` widget when it is shown or hidden. The `opacity` property is set to a `Tween` that animates the opacity value from `0.0` to `1.0`. The `_animationController` is used to control the animation.

In conclusion, showing and hiding widgets in Flutter is a simple process. You can use the built-in `Visibility` widget to control the visibility of a widget, and you can also use animations to add some flair to the show and hide functionality. With these tools, you can create dynamic and interactive user interfaces in Flutter.

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Faster Performance of Laravel Yajra Datatables 2 Jan 8:37 PM (9 months ago)

Laravel Yajra Datatables is a package that provides an easy way to integrate DataTables jQuery plugin with Laravel. It allows us to easily generate server-side processing of data and provides capabilities like filtering, sorting, searching, and pagination.

One of the main issues with using large data sets in DataTables is performance. However, using Laravel Yajra Datatables, we can achieve faster performance by optimizing the queries and reducing the data sent to the client.

1. Optimize Queries
When using DataTables, it is important to optimize the queries for faster execution. One of the ways of achieving this is by using eager loading. Eager loading avoids the N+1 problem where additional queries are made to retrieve related data. By using eager loading, we can reduce the number of queries made to the database and improve performance.

$data = User::with('orders')->get();

In the code above, we are loading all the users with their orders. This reduces the number of queries made to the database as compared to individually retrieving users and their orders.

2. Reduce Data Sent to the Client
Another way of improving performance is by reducing the data sent to the client. This means that instead of sending the entire data set to the client, we only send the necessary data required for the current page.

Laravel Yajra Datatables allows us to paginate the data, meaning that we only retrieve the data necessary for the current page. This reduces data retrieval time and overall page load time.

return Datatables::of(User::query())
    ->addColumn('status', function($user) {
        return $user->active ? 'Active' : 'Inactive';
    })
    ->toJson();

In the code above, we are only retrieving the necessary data from the User model and computing an additional column with the status attribute. This reduces the amount of data sent to the client.

3. Use Caching
Caching is an essential tool for improving performance. When dealing with large data sets, it is common to use caching to avoid unnecessary queries. Laravel provides a caching system that can be easily integrated with DataTables.

return Cache::remember('users', $minutes, function () {
    return Datatables::of(User::query())
        ->make(true);
});

In the code above, we are caching the results of the query for a given number of minutes before fetching the data again. This reduces the number of queries made to the database and improves the response time.

Conclusion
Laravel Yajra Datatables is a powerful tool for working with large data sets in Laravel. By optimizing queries, reducing data sent to the client, and using caching, we can achieve faster performance and a smoother user experience. With these techniques, you can now take your DataTables development to the next level!

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?