Enable Windows Explorer previews for custom file types

Coders, have you ever wished if you get preview of source code while you are in Windows Explorer? Yes it is possible. You might know already that there is a “Preview Pane” feature present. According to a file’s Content Type the preview will be shown at the right side of the window. Common formats supported are – .txt, .mp4, .jpg etc.

image

BUT, most of the developer’s files like .cs, .php, .config, .log files are not supported by default and you will be presented with a message “No preview Available” like this:

image

How to enable preview for a specific filetype?

Step 1: Go to Regedit. Expand the node HKEY_CLASSES_ROOT

Step 2: look for your required extension, eg: .php (If the extension is not already present, then create a key)

Step 3: Add a string value PerceivedType and set its Data to text

Voila!, your file preview is ready!

image

Loop multiple videos in HTML5 video tag

<video id="v" autoplay>
       <source src="1.mp4" type="video/mp4">
     </video>

    <script>
         var c = 0;
         f = [
                 "1.mp4",
                 "2.mp4",
                 "3.webm"
             ];
         var v = document.getElementById('v');
         v.addEventListener('ended', function(e) {
             c = (c < f.length-1)?++c:0;
             v.src = f[c];
             v.play();
         });
     </script>

Ajax file uploader using jQuery

Here is a sample code to upload multiple files using ajax, and without using the traditional <form> tags. Find the full source code in GitHub – https://github.com/ninethsense/code-share/tree/master/jQuery-File-Upload .

<body>
    <input type="button" value="Choose file" id="fup" />

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>    

    <script>
            $(function() {

                // Show file upload dialog on click of button
                $("#fup").click(function(){

                    //Create File component
                    var fu = document.createElement("input");
                    fu.type = "file";
                    fu.id="fuc";
                    $(fu).attr("multiple","");

                    // Trigger file selection event
                    $(fu).change(function(){
                        var fd = new FormData();
                        $.each($(fu)[0].files, function(i, file){
                            fd.append('file[]', file);
                        });

                        // Send fd to server
                        $.ajax({
                            url:"FileUpload.php",
                            type: 'POST',
                            data:fd,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function(d) {
                                console.log(d);
                            }
                        });
                    });

                    // To invoke the file selection dialog box
                    $(fu).click();

                });
            });
    </script>
</body>

Sample server code in PHP for the reference:

foreach ($_FILES['file']['tmp_name'] as $k => $v) {
move_uploaded_file(
$_FILES['file']['tmp_name'][$k],
$_FILES['file']['name'][$k]
);
}

Whitepaper on Principles of container-based application design by Red Hat

Good read – https://www.redhat.com/en/resources/cloud-native-container-design-whitepaper

Cloud-native” is a term used to describe applications designed specifically to run on a cloud-based infrastructure. Typically, cloud-native applications are developed as loosely coupled microservices running in containers managed by platforms. These applications anticipate failure, and they run and scale reliably even when their underlying infrastructure is experiencing outages. To offer such capabilities, cloud-native platforms impose a set of contracts and constraints on the applications running on them. These contracts ensure that the applications conform to certain constraints and allow the platforms to automate the management of the containerized applications.