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
/* | |
Translates normalised device coordinates (NCD) to world coordinates. | |
Calculate NCD using mouseMove/pointerMove event listeners: | |
mouseX = (e.clientX / window.innerWidth) * 2 - 1; | |
mouseY = -(e.clientY / window.innerHeight) * 2 + 1; | |
You can then test if it works by setting up a camera and a cursor mesh object in the scene, | |
copying its position from the return value every animation frame: | |
cursorMesh.position.copy(getCursorWorldCoordinates()); |
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
// typing of implementation is not checked by the compiler, only calls to it | |
declare global { | |
interface Number { | |
between: (min: number, max: number) => boolean; | |
} | |
} | |
Object.defineProperty(Number.prototype, 'between', { | |
value(min: number, max: number): boolean { | |
return this >= min && this <= max; |
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 filecmp import cmp | |
from requests import post | |
from json import loads | |
from datetime import datetime | |
# generate your token at https://github.com/settings/tokens (i'm not sure what scopes you will need) | |
token = 'api_token' | |
username = 'NachoToast' # doesn't have to be your username | |
url = 'https://api.github.com/graphql' |
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
export type JoinVerification = 'token' | 'ip' | 'username' | 'gameCode'; | |
import { JwtPayload, verify } from 'jsonwebtoken'; | |
import { Socket } from 'socket.io'; | |
import { CONNECTION_SYSTEM } from '../constants/logging'; | |
import { | |
EMITTED_PLAYER_EVENTS, | |
RECEIVED_PLAYER_EVENTS, | |
} from '../constants/socketEvent'; | |
import { |
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
/** Compares the similarity between 2 strings using Levenshtein distance. | |
* @param {string} s1 The first string. | |
* @param {string} s2 The second string. | |
* @returns {number} Similarity between the 2 strings. | |
*/ | |
export function levenshteinDistance(s1: string, s2: string): number { | |
let longerString = s1; | |
let shorterString = s2; | |
if (s1.length < s2.length) { | |
longerString = s2; |
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 | |
function add_folders($root) { | |
$local_folders_array = array(); | |
foreach (glob("$root/*", GLOB_ONLYDIR) as $folder) { | |
array_push($local_folders_array, ['foldername' => $folder]); | |
$arr2 = add_folders($folder); | |
if (count($arr2) > 0) foreach($arr2 as $subfolder) array_push($local_folders_array, ['foldername' => $subfolder['foldername']]); | |
} | |
return $local_folders_array; | |
} |
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 files = | |
<?php | |
$files = array(); | |
foreach (glob('*.html') as $filename) { | |
$files[] = pathinfo($filename)['filename'] . "." . pathinfo($filename)['extension']; | |
} | |
echo json_encode($files); | |
?>, | |
folders = | |
<?php |
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 | |
function verify_captcha($token) { | |
$threshold = 0.5; // Score must be > threshold to pass captcha. | |
// Default is 0.5, although the majority of users will get 0.9 | |
$sites = ["localhost", "nachotoast.com", "ntgc.ddns.net"]; // Site names string, e.g. sub.domain.com:8080 | |
$secret = "Put your client secret here."; | |
$url = "https://www.google.com/recaptcha/api/siteverify"; | |
$data = array("secret" => $secret, "response" => $token); |
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 make_circle_coordinates(top = 0, left = 0, bottom = 300, right = 300, points = 20, visual = true) { | |
// e.g. top: 20, left: 20, right: 1900, bottom: 800 | |
let center = { | |
x: (left + right) / 2, | |
y: (top + bottom) / 2 | |
}, | |
radius = { | |
x: right - center.x, | |
y: bottom - center.y | |
}, |
NewerOlder