This file contains hidden or 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
const isMACAddressValid = (mac) => /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(mac); | |
document.write(isValidMACAddress("AA:22:FF:04:2D")); |
This file contains hidden or 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
const convertRGBToHSL = (r, g, b) => { | |
[r, g, b] = [r, g, b].map(val => val / 255); | |
const [max, min] = [Math.max(r, g, b), Math.min(r, g, b)]; | |
let h = (max !== min) ? ((max === r ? g - b : (max === g ? b - r : r - g)) / (max - min) + (max === g ? 2 : (max === b ? 4 : 0))) / 6 : 0; | |
let s = (max !== min) ? (l => l > 0.5 ? (max - min) / (2 - max - min) : (max - min) / (max + min))(l) : 0; | |
let l = (max + min) / 2; | |
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) }; | |
}; | |
document.write(convertRGBToHSL(77, 123, 44)); |
This file contains hidden or 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 hidden or 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 hidden or 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 <[email protected]> | |
// Created: 27 March 2023 0847 | |
// Purpose: Provides a reusable singleton connection to the database | |
class DatabaseConnection { | |
protected static $db; | |
This file contains hidden or 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 hidden or 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 = '[email protected]'; | |
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 hidden or 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 hidden or 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 hidden or 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() |