Skip to content

Instantly share code, notes, and snippets.

View binarykore's full-sized avatar
🏠
Living under the Shadows of my Game

Digital Kore binarykore

🏠
Living under the Shadows of my Game
View GitHub Profile
@binarykore
binarykore / elorating.php
Last active May 16, 2022 21:15
ELO Rating using PHP as base Backend Language..
<?php
class elo{
//K Factor = 32 (below 2100)
//K Factor = 24 (between 2100 and 2400)
//K Factor = 16 (above 2400)
const KFACTOR = 32;
//WIN = 1 Points
//DRAW = 0.5 Points
//LOSE = 0 Points
const WIN = 1;
@binarykore
binarykore / urlroute.php
Last active May 17, 2022 10:12
URL Routing with or without htaccess..
<?php
switch($_SERVER["REQUEST_URI"]){
case("/test"):
if(file_exists($_SERVER["DOCUMENT_ROOT"]."/test.php")){
Require_Once($_SERVER["DOCUMENT_ROOT"]."/test.php");
}else{
echo("File not Found..");
}
break;
case("/abc"):
@binarykore
binarykore / stringreversal.php
Created May 17, 2022 13:38
Custom Str Split and Array String Reversal.
<?php
$_string = readline("String:");
function split_string($_string){
$_hash = [];
for($_g = 0;$_g <= strlen($_string) - 1;$_g++){
$_hash[$_g] = $_string[$_g];
}
return($_hash);
}
$_string = array_reverse(split_string($_string));
@binarykore
binarykore / gd.php
Last active May 18, 2022 08:50
Initial or Word-based Avatar Image Generator using GD Imaging..
<?php
function initialAvatar($_string){
$_imagewidth = 240;
$_imageheight = 240;
$_font = 5;
$_width = imagefontwidth($_font) * strlen($_string);
$_height = imagefontheight($_font);
$_formula = [];
$_formula["a"] = ($_imagewidth / 2) - ($_width / 2);
$_formula["b"] = ($_imageheight / 2) - ($_height / 2);
@binarykore
binarykore / asynchsynch.php
Last active May 19, 2022 03:48
Difference between GET and POST as well as Asynchronous and Synchronous Ajax / XMLHTTPRequest..
<?php
Header("Content-Type:Text/Javascript");
$_requests = ["POST"=>[],"GET"=>[]];
$_requests["POST"]["ASYNCH"] = ("var xhr = new XMLHttpRequest();
xhr.open('POST','//".$_SERVER["HTTP_HOST"]."/handler',true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
var result = xhr.responseText;
}
@binarykore
binarykore / haystack.php
Last active May 24, 2022 06:11
Needle in a Haystack of Arrays for Vercel..
<?php
function haystack(){
$_hash = [];
foreach(array_keys($_REQUEST) as $_token => $_coin){
$_hash[$_token] = (array_keys($_REQUEST)[$_token]);
$_hash[$_coin] = ($_REQUEST[array_keys($_REQUEST)[$_token]]);
}
return($_hash);
}//
function payload($_parameter,$_url){
@binarykore
binarykore / arraybrackets.php
Last active May 24, 2022 06:25
Array Brackets with JSON Pretty Printing method...
<?php
Header("Content-Type:Application/JSON");
$_hash = [
"id" => "world"
];
$_data = [
"hello" => [
$_hash
]
];
@binarykore
binarykore / iterate.php
Last active April 30, 2023 09:02
Reinventing the Foreach Loop from PHP to C Language..
<?php
function iterate($_haystack){
$_blocks = [];
for($_g = 0;$_g <= count($_haystack);$_g++){
if(!empty($_haystack[$_g])){
$_blocks[] = $_haystack[$_g];
}else{
continue;
}
}
@binarykore
binarykore / scheme.php
Created June 6, 2022 07:16
Prints either HTTP or HTTPs...
<?php
if(!empty($_SERVER["REQUEST_SCHEME"])){
$_scheme = $_SERVER["REQUEST_SCHEME"];
}elseif(empty($_SERVER["REQUEST_SCHEME"])){
$_scheme = $_SERVER["HTTP_X_FORWARDED_PROTO"];
}
echo($_scheme);
//Prints either HTTP or HTTPs
?>
@binarykore
binarykore / strlen.php
Created June 26, 2022 05:20
A Native Way to execute String Length through PHP..
<?php
$_string = "Hello World";
$_strlen = count(str_split($_string)) - 1;
echo($_strlen);
//A Native Way to execute String Length through PHP..
?>