Skip to content

Instantly share code, notes, and snippets.

View fhdalikhan's full-sized avatar
🏠
Working from home

Fahad Ali Khan fhdalikhan

🏠
Working from home
  • Karachi, Pakistan.
View GitHub Profile
@fhdalikhan
fhdalikhan / Dockerfile
Last active April 28, 2024 19:06
Dockerfile for PHP 7.4 FPM Alpine
FROM php:7.4-fpm-alpine
WORKDIR /var/www/html
# Setup GD extension
RUN apk add --no-cache \
freetype \
libjpeg-turbo \
libpng \
freetype-dev \
@fhdalikhan
fhdalikhan / help.php
Created October 23, 2020 08:42
Functions to get current CPU load and memory usage under Windows and Linux.
https://www.php.net/manual/en/function.sys-getloadavg.php#118673
Function to get current CPU load as percentage value under Windows and Linux.
Note: Function is getServerLoad(). It will return a decimal value as percentage of current CPU load or NULL if something went wrong (e. g. insufficient access rights).
<?php
header("Content-Type: text/plain");
@fhdalikhan
fhdalikhan / index.html
Created September 11, 2019 13:40
millicast.com paid webtrc service for video broadcasting
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div id="messages">
@fhdalikhan
fhdalikhan / help
Last active August 9, 2022 15:08
docker solr 4 running instructions
some helpful instructions when I have to change my laptop
clone solr 4 image from https://github.com/fhdalikhan/docker-solr4
on windows don't use git bash, use windows terminal with ubuntu using WSL 2, otherwise will get erros due to line endings being CRLF, which should be LF instead.
build using:
docker build -t solr4 .
run using:
@fhdalikhan
fhdalikhan / export-csv.php
Created June 25, 2019 07:42
export csv using fputcsv in PHP
<?php
function export(){
$filename = 'users_'.date('Ymd').'.csv';
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
/* Connect to a MySQL database using driver invocation */
$dsn = 'mysql:dbname=test_db;host=127.0.0.1';
$user = 'test';
@fhdalikhan
fhdalikhan / gist:b55e7782f29f2e9b49e5e5f45a86f29e
Created January 9, 2022 14:22
recursively change folder ownership by either cron or PHP
# cron example
* * * * * /usr/bin/sudo chown -R GROUP_NAME:USER_NAME /home/fahad/upload_testing/
# php example, needs the user password and user has to have root permissons
system('echo THE_USER_PASSWORD | /usr/bin/sudo -S chown -R GROUP_NAME:USER_NAME /home/fahad/upload_testing/');
@fhdalikhan
fhdalikhan / DQL_example.php
Last active November 11, 2021 09:09
doctrine result set mapping for sql, this will map sql data to entity
<?php
// DQL example, however the result has to be mapped
$entityManager = $this->getEntityManager();
$query = $entityManager->createQuery(
'SELECT nm.id AS nm_id, n FROM \App\Entity\Negotiation n
INNER JOIN n.messages nm WITH nm.id = (SELECT MAX(id) FROM \App\Entity\NegotiationMessage WHERE negotiation_id = n.id)
ORDER BY nm.id DESC'
)->setParameter('direction', EnumMessageDirectionType::TYPE_INBOUND);
* API FOR GET REQUESTS
// most simple and returns iata code
https://airport-autosuggest.flightright.net/v1/airports/COM?name=london
// connected to kiwi.com, but you can still use it for autocompletes and has a lot of information
https://api.skypicker.com/locations/?term=london
* BELOW API IS FOR POST REQUESTS
// related to openflights data or a simple text autocomplete
@fhdalikhan
fhdalikhan / example.js
Created April 28, 2021 17:13
change browser's back button url
history.pushState(null, null, '<?php echo $_SERVER["REQUEST_URI"]; ?>');
window.addEventListener('popstate', function(event) {
window.location.assign("http://www.yoururl.com/");
});
@fhdalikhan
fhdalikhan / gist:a999bcecefc82ad275686f5cd4140745
Created April 23, 2021 07:10
Solr 4 docker hub and github repo links
solr 4
https://hub.docker.com/r/bxggs/solr4
https://github.com/b-ggs/docker-solr4
https://github.com/docker-solr/docker-solr4