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 / extract.php
Created January 28, 2021 17:57
Extract zip file
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'text.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
@fhdalikhan
fhdalikhan / help.txt
Created January 19, 2021 20:23
Cronjob for syncing project with git repo
/bin/sh -c 'cd /home/public_html/project && /usr/bin/git fetch --all && /usr/bin/git reset --hard origin/master' 2>&1 | /home/timestap.sh >> /home/project_cronjob.log
@fhdalikhan
fhdalikhan / help.php
Last active December 17, 2020 23:02
Notes related to Laravel collections
<?php
# 1
$rows = collect(['Administration', 'Samples', 'Test 1', 'Test 2',]);
# running filter on the collection, if true is returned from the callback then the element will remain the in collection.
$rows = $rows->filter(function($item){
// dump($item);
# creating a collection, then checking with contains($item['name']) if the collection contains the item, using a ! at the start to not include the items which are in the checked collection.
return !collect(['Administration', 'Samples',])->contains($item['name']);
@fhdalikhan
fhdalikhan / gist:e1d7567fd0b9287db97589d4ce43d535
Last active December 4, 2020 15:49
Different laravel validation rules
// mimetype mp4, max is in kilobytes
mimetypes:video/mp4|max:15000
// only images and max size of 500 KB
image|max:500
// exists checks the attribute value in a table exists, format is: {table},{column}
required|exists:projects,id
// mimetypes for documents like word, powerpoint, excel and pdf with max filesize of 5000 KB
@fhdalikhan
fhdalikhan / help.html
Created October 23, 2020 11:32
JavaScript play video for n seconds and then pause.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<video id="mejs_837308676760252_html5" controls="true" height="200" width="300">
<source type="video/ogg" src="http://media.w3.org/2010/05/bunny/movie.ogv">
<source type="video/mp4" src="http://media.w3.org/2010/05/bunny/movie.mp4">
@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 / help.js
Created October 11, 2020 22:17
js visual event viewer
// Put this inside bookmark
javascript:(function()%20{var%20protocol%20=%20window.location.protocol%20===%20'file:'%20?'http:'%20:%20'';var%20url%20=%20protocol+'//www.sprymedia.co.uk/VisualEvent/VisualEvent_Loader.js';if(%20typeof%20VisualEvent!='undefined'%20)%20{if%20(%20VisualEvent.instance%20!==%20null%20)%20{VisualEvent.close();}else%20{new%20VisualEvent();}}else%20{var%20n=document.createElement('script');n.setAttribute('language','JavaScript');n.setAttribute('src',url+'?rand='+new%20Date().getTime());document.body.appendChild(n);}})();
@fhdalikhan
fhdalikhan / help.js
Created October 11, 2020 22:11
For scrolling to the destination offset on document.ready
$(document).ready(function() {
$('body,html').animate({scrollTop: 550}, 1500);
});
@fhdalikhan
fhdalikhan / help.js
Created October 11, 2020 22:10
For Removing Class and Adding Class based on the scroll position
<div id="menuBar" class="nav-menu"></div>
<div style="margin-bottom: 999em;"></div>
<script type="text/javascript">
$(document).ready(function(){
$(window).on('scroll', function () {
var $body = $('body');
var $target = $('#menuBar');
if ($body.scrollTop() > 100 && $target.hasClass('nav-menu')){
@fhdalikhan
fhdalikhan / help.js
Created October 11, 2020 22:09
For Centering a Div On Screen and accounting for the scrolling and resizing
// Define your target div / popup container here.
var popup_target = '#checkout_open';
// Call the function like this
// jQuery("#checkout_open").center();
// Attach a function to jQuery
jQuery.fn.center = function () {
this.css("position","absolute");