Get Hard Drive Type using C#

The snippet below will get you the drive type where a specified file/folder is. static void Main(string[] args) { System.IO.FileInfo file = new System.IO.FileInfo("M:\\"); // File or Directory System.IO.DriveInfo _driveInfo = new System.IO.DriveInfo(file.FullName); Console.WriteLine("Drive: " + _driveInfo.Name); if (_driveInfo.IsReady) { Console.WriteLine("The drive type is: " + _driveInfo.DriveType.ToString()); } Console.ReadLine(); } Output More C# Snippets

A function to Shuffle Array and List using C#

Below is a function that shuffles an array or a list. It accepts a list or array to be shuffled/rearranged as an argument and returns a shuffled copy of the object passed. public E ShuffleArrayAndList<E>(IList<E> arr) { Random random = new Random(); E result = arr[arr.Count]; E tmpArray = arr[arr.Count]; if (arr.Count > 1) {... » read more

Copy Directory Content into Sub Directory using PHP

The code below copies a folder content ( or directory) into a newly created subfolder( or subdirectory). <?php $myDir = opendir('/myDir'); mkdir('/myDir/newDir'); while (false !== ($file = readdir($myDir))) { if (($file != '.') && ($file != '..')) { if (is_dir('/myDir/' . $file)) { $this->recurseCopy('/myDir/' . $file, '/myDir/newDir/' . $file); } else { copy('/myDir/' . $file,... » read more

Validate Email Address using PHP

Below is a PHP function that validates an email address and returns the result as a boolean. This function uses the PHP built-in function filter_var and the filter FILTER_VALIDATE_EMAIL <?php //php 7.0.8 function ValidateEmail($email) { $email = 'myEmail@myDomain.com'; $isValid = filter_var($email, FILTER_VALIDATE_EMAIL); if ($isValid) { return true; } else { return false; } } ?> Easy isn’t?... » read more

Get Local IP Address using PHP

A function that will return the local IP address. <?php function GetIPAddress() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ipAddress = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ipAddress = $_SERVER['REMOTE_ADDR']; } echo "You IP address is $ipAddress"; } ?> Related Snippets

Get Current Page URL using PHP

A PHP function to return the current page URL. <?php function getCurrentURL() { $CurrentURL = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; $CurrentURL .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; $CurrentURL .= $_SERVER["REQUEST_URI"]; return $url; } ?> Happy Coding!!! Related Snippets

Get Image Height and Width using PHP

A snippet to get an image height and width using PHP built-in function getimagesize  and list: <?php list($width, $height) = getimagesize("myImage.png"); echo "Image width is " . $width; echo "<br>"; echo "Image height is " . $height; ?> Happy Coding! Related Snippets

Strip Numbers from a String using JavaScript

A code snippet to take all number off a string using JavaScript <script> var MyString = "Tutorials1P2anel3"; stringOnly = MyString.replace(/[0-9]/g, ''); alert(stringOnly); </script> You can replace the alert with anything else that would fit your coding needs. Related Snippets

Email validation function using JavaScript

A Javascript function to check email validation. Returns boolean. function ValidateEmail(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (!reg.test(email)) return false; return true; } Happy Coding! Related Snippets