Skip to content

Instantly share code, notes, and snippets.

View anushshukla's full-sized avatar
💭
Silently and secretly building awesome applications

Anush Shukla anushshukla

💭
Silently and secretly building awesome applications
View GitHub Profile
@anushshukla
anushshukla / getLongestSubStrings.php
Created June 23, 2019 18:49
getLongestSubStrings
<?php
function getLongestSubStrings($str) {
$array = str_split($str);
$arrayLen = sizeof($array) - 1;
$noRepeatitiveSubStringFoundMsg = 'No repeated substring';
$longestRepeatedStringLen;
$longestSubstringsFound = '';
for ($i=0; $i < $arrayLen / 2; $i++) {
$groupOf = $i + 2;
@anushshukla
anushshukla / getBinaryTreeDiameter.php
Created June 20, 2019 09:34
Get Binary Tree Diameter between 2 longest nodes
<?php
function hasLeftNode($node) {
return array_key_exists(0, $node);
}
function hasRightNode($node) {
return array_key_exists(1, $node);
}
@anushshukla
anushshukla / getDistinctElementsCommonToAllRows.php
Last active June 7, 2019 02:11
Get Distinct Elements Common To All Rows of n x n Matrix having unique values
<?php
function getDistinctElementsCommonToAllRows($matrix) {
$matches = '';
$matrixLength = count($matrix);
$matrixLastIndex = $matrixLength - 1;
$matrixPivotIndex = round($matrixLastIndex / 2);
for ($i=0; $i < $matrixPivotIndex; $i++) {
$row = $matrix[$i];
$anotherRow = $matrix[$matrixLastIndex - $i];
@anushshukla
anushshukla / curl.php
Created June 6, 2019 06:38
PHP file to abstracting and encapsulation of making curl calls following OOPS
<?php
class Curl {
private $_ch;
protected $opts;
private function __construct($config)
{
$this->_ch = curl_init();
}
@anushshukla
anushshukla / realtime-climate-update.php
Created June 6, 2019 06:36
PHP file showing real time climate update as per user's location
<?php
// Server: Apache2
// Language: PHP7.0.17-2
// HTML5, CSS3 & JS
define('ENV', 'DEVELOPMENT');
error_reporting(-1);
ini_set('display_errors', ENV !== 'PRODUCTION');
if(request()->isAjax && request()->isPost())
@anushshukla
anushshukla / maintenance.php
Created June 6, 2019 06:34
PHP file to display Maintenance WebPage during downtime for maintenance of the website applicatoin
<?php
http_response_code(503);
if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])) :
echo json_encode("Website is under maintenance");
endif;
?>
<!DOCTYPE html>
<html>
<head>
<title>Site Maintenance</title>
@anushshukla
anushshukla / .bash_aliases
Created June 6, 2019 06:33
~/..bash_aliases
alias checkoutsites='cd /var/www/html'
alias getStagingApiIp='ping some-host-name'
alias getCoverageFilesList='git diff --name-only origin/develop | grep -v public/ | grep -v api/ | grep -v styles | grep -v __tests__ | grep -v action_types'
@anushshukla
anushshukla / server.php
Created June 6, 2019 06:32
PHP file to send responses, parse request and etc.
<?php
if(!function_exists("server")) {
function server() {
return new Server(func_get_args());
}
}
class Server {
private CONST SERVICES = ["www","http","https","mysql","smtp","imap","pop3","ftp","ssh","sftp","telnet","nicname","gopher","finger"];
private CONST PROTOCOL = ["tcp","udp"];
private CONST VALID_KEYS = ["all"=>"a","os"=>"s","release"=>"r","version"=>"v","bits"=>"m","hostname"=>"n"];
@anushshukla
anushshukla / light-bulb-sequence.php
Created June 6, 2019 06:27
Light Build Sequence
<?php
$firstSeqArr = [];
$secondSeqArr = [];
$operations = 0;
while($str = fgets(STDIN)){
$trimmedStr = trim($str);
$trimmedStrSplit = str_split($trimmedStr);
if(empty($firstSeqArr)) {
$firstSeqArr = $trimmedStrSplit;
} else {
@anushshukla
anushshukla / requirements.php
Created June 6, 2019 06:25
PHP Requirements (Extension & Modules - Installed and Enable Status)
<?php
$apache_modules = apache_get_modules();
$required_modules = ["mod_rewrite","mod_macro","mod_ssl"];
$modules = $apache_modules + $required_modules;
$loaded_extensions = get_loaded_extensions();
$required_extensions = ["ctype","curl","date","dom","gd","fileinfo","json","mycrypt","PDO","Reflection","SimpleXML","xdebug","xml"];
$extensions = $loaded_extensions+$required_extensions;
?>
<!DOCTYPE html>