Saturday, February 11, 2017

Simple Laravel Layouts using Blade

The most part of Laravel is usage of layout. It helps you to design a better application. You can create a layout and use that for view pages. Below is a good & simple example how you can create and use layouts.

At first create file named "test.blade.php" under "resources/views/layouts" folder with following contents:


<!DOCTYPE html>
<html>
    <head>
        <title>Title - @yield('title')</title>      
    </head>

    <body>
        <section>
            @yield('content')                
        </section>
        <section>
            @yield('pageScript')
        </section>
    </body>
</html>

The use of the layout file would be as like (from any resources blade file):


@extends('layouts.test') //This line will include layout file

@section('title', 'Title of the page') //Set title of the page

@section('content') //Start content of the page
Html content goes here
@stop //End content of the page

@section('pageScript') //Start javascript of the page
<script src="{{ asset('/js/some-js-file.js') }}"></script>

<script>
$(document).ready(function () {
    
});
</script>
@stop //End javascript of the page

Laravel throw/return custom exception/response

In Laravel it is very simple to handle exception and return custom error codes to view. Below is a example how you can return custom http header code.


<?php
namespace App\Http\Controllers;

use Request;

class TestController extends Controller { 
   public function test_function(Request $request) {
       return response("content", 430)->header('Content-Type', "text/html");
   }
}
?>

Friday, February 10, 2017

VBScript Empty Recycle Bin

VBScript is a scripting language to manage computer developed by Microsoft. Now it is easy to empty your recycle bin easily. Below is a code snippet that describe how recycle bin be empty.

Const RECYCLE_BIN = &Ha&

Set FSO = CreateObject("Scripting.FileSystemObject")
Set ObjShell = CreateObject("Shell.Application")
Set ObjFolder = ObjShell.Namespace(RECYCLE_BIN)
Set ObjFolderItem = ObjFolder.Self
Wscript.Echo ObjFolderItem.Path

Set colItems = ObjFolder.Items
For Each objItem in colItems
    Wscript.Echo objItem.Name
    If (objItem.Type = "File folder") Then
        FSO.DeleteFolder(objItem.Path)
    Else
        FSO.DeleteFile(objItem.Path)
    End If
Next

VBScript Delete All Files And SubFolders

VBScript is a scripting language to manage computer developed by Microsoft. It is important that we have power to do something using some script written by me. Below is a code snippet that delete all files & subfolders & files of subfolders easily.

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\tmp\xxx")

'Delete all files in root folder
for each File in Folder.Files
    On Error Resume Next
    name = File.name
    File.Delete True
    If Err Then
        WScript.Echo "Error deleting:" & Name & " - " & Err.Description
    Else
        WScript.Echo "Deleted:" & Name
    End If
    On Error GoTo 0
Next

'Delete all subfolders and files
For Each File In Folder.SubFolders
    On Error Resume Next
    name = File.name
    File.Delete True
    If Err Then
        WScript.Echo "Error deleting:" & Name & " - " & Err.Description
    Else
        WScript.Echo "Deleted:" & Name
    End If
    On Error GoTo 0
Next

Tuesday, February 7, 2017

Resize command prompt through commands

mode con: cols=130 lines=40
OR

mode 130,40

VBScript Show Details Of a File, Copy, Delete And Move

set FSO = CreateObject("Scripting.FileSystemObject")

'Display detailed information about this file
set FileObject = FSO.GetFile("C:\tmp\heidisql.exe")

Wscript.Echo "Path = " & FileObject.Path
Wscript.Echo "Name = " & FileObject.Name
Wscript.Echo "Short Name = " & FileObject.ShortName
Wscript.Echo "Short Path = " & FileObject.ShortPath
Wscript.Echo "Drive = " & FileObject.Drive
Wscript.Echo "Size = " & FileObject.Size
Wscript.Echo "Attributes = " & FileObject.Attributes
Wscript.Echo "Parent Folder = " & FileObject.ParentFolder
Wscript.Echo "Date Created = " & FileObject.DateCreated
Wscript.Echo "Last Modified = " & FileObject.DateLastModified
Wscript.Echo "Last Accessed = " & FileObject.DateLastAccessed
'FileObject.Copy "heidisql_.exe", True 'True=Overwrite
'FileObject.Delete True 'True=Delete the read-only file
FileObject.Move "heidisql_moved.exe"

VBScript Open URL in Default Browser

Option Explicit

Dim WscriptSchell
Set WscriptSchell = CreateObject("WScript.Shell")

WscriptSchell.Run "https://google.com", 9