This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$pwd = "C:\Users\someusername" | |
$dirinfo = Get-ChildItem($pwd) -recurse | |
$d = $dirinfo.ToString() | |
$stringAsStream = [System.IO.MemoryStream]::new() | |
$writer = [System.IO.StreamWriter]::new($stringAsStream) | |
$writer.write($d) | |
$writer.Flush() | |
$stringAsStream.Position = 0 | |
$output = Get-FileHash -InputStream $stringAsStream | Select-Object Hash | |
$output.hash.ToString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_sum(int $n = 100) { | |
$sum = $n * ($n + 1) / 2; | |
return $sum; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Program: DatabaseConnection.php | |
// Programmer: Brian Wasner <brianwasner@gmail.com> | |
// Created: 27 March 2023 0847 | |
// Purpose: Provides a reusable singleton connection to the database | |
class DatabaseConnection { | |
protected static $db; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::net::{TcpListener, TcpStream, Shutdown}; | |
use std::io::{Read, Write}; | |
use std::process::Command; | |
fn handle_client(mut stream: TcpStream) { | |
let mut data = [0 as u8; 255]; | |
while match stream.read(&mut data) { | |
Ok(size) => { | |
stream.write(&data[0..size]).unwrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var email = 'someuser@somedomain.com'; | |
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
if (re.test(email) == false || re.test(email) == '') { | |
alert("Bad or Missing Email Address"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate_ip_address(ipaddress) { | |
var pattern = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/g; | |
var validip = pattern.test(ipaddress); | |
return (validip); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def most_frequent(lst): | |
data = Counter(lst) | |
return data.most_common(1) # returns most frequent 1 element | |
list = [2, 1, 2, 2, 1, 3, 3, 3, 2, 3, 3, 1] | |
print(most_frequent(list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql.connector | |
from mysql.connector import Error | |
try: | |
connection = mysql.connector.connect(host='database_server', | |
database='database_name', | |
user='database_username', | |
password='database_password') | |
if connection.is_connected(): | |
db_Info = connection.get_server_info() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Simple Database Connection Code - PDO <-> MySQL/MariaDB Database | |
// Brian Wasner - 24 July 2014 0930 | |
$database_server = 'database_server_name_goes_here'; | |
$database_username = 'database_username_goes_here'; | |
$database_password = 'database_password_goes_here'; | |
$database_name = 'database_name_goes_here'; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function linkify_string ($stringwithurl) { | |
return "<p>" . preg_replace('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_\-\=/]+!', "<a target='_blank' href=\"\\0\">\\0</a>", $stringwithurl) . "</p>"; | |
} |
NewerOlder