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 pygame | |
import random | |
import math | |
import os | |
# Initialize | |
pygame.init() | |
WIDTH, HEIGHT = 800, 600 | |
screen = pygame.display.set_mode((WIDTH, HEIGHT)) | |
pygame.display.set_caption("Space Invaders") |
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 | |
class Database { | |
private static ?Database $instance = null; | |
private ?resource $connection = null; | |
private string $host; | |
private string $dbname; | |
private string $user; | |
private string $password; |
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::net::{TcpStream, Ipv4Addr, SocketAddr}; | |
use std::time::Duration; | |
use std::thread; | |
const TIMEOUT: Duration = Duration::from_secs(1); | |
const PORT_RANGE: std::ops::Range<u16> = 1..1024; | |
fn main() { | |
let local_ip = get_local_ip().expect("Could not get local IP address"); | |
let subnet = get_subnet(&local_ip); |
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 | |
class PortScanner { | |
private $subnet; | |
private $ports; | |
private $timeout; | |
public function __construct($subnet, $ports = [80, 443, 22, 21, 23], $timeout = 1) { | |
$this->subnet = $subnet; // The local subnet in CIDR notation (e.g., 192.168.1.0/24) |
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 differenceBetweenDates = (date1, date2) => Math.abs(Math.floor((date2 - date1) / (1000 * 60 * 60 * 24))); | |
document.write(differenceBetweenDates("2773-01-17", "2774-01-18")); |
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 objectToURLParams = (obj) => Object.entries(obj).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&'); | |
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 secondsToHHMMSS = (seconds) => { | |
const hours = Math.floor(seconds / 3600); | |
const remainingSeconds = seconds % 3600; | |
const minutes = Math.floor(remainingSeconds / 60); | |
const remainingSecs = remainingSeconds % 60; | |
return `${hours}:${minutes}:${remainingSecs}`; | |
}; | |
document.write(secondsToHHMMSS(7320)); |
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 randomizeString = (str) => str.split('').sort(() => 0.5 - Math.random()).join(''); | |
document.write(randomizeString("Every good boy deserves fudge!"); | |
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 checkIsValidIPv4 = (ip) => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip); | |
document.write(checkIsValidIPv4("192.168.1.1")); |
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 checkIsValidUSPhoneNumber = (phone) => /^(?:(?:\+1\s?)?(?:\(?\d{3}\)?[\s.-]?)?\d{3}[\s.-]?\d{4})$/.test(phone); | |
document.write(checkIsValidUSPhoneNumber("+1 (123) 456-7890")); |
NewerOlder