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 / supervisord.sh
Created October 9, 2018 11:13 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@fhdalikhan
fhdalikhan / gist:6ff217c4ed31fac9e41aa508293f0f82
Created November 15, 2018 10:38
jQuery UI sortable implementation
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="http://necolas.github.com/normalize.css/2.0.1/normalize.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.0/css/font-awesome.css">
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<style>
@fhdalikhan
fhdalikhan / gist:68c001a4f7c9d22fc3bdd6e23781dd8f
Last active November 28, 2018 08:26
On mouse down, tooltip and copy selection text example
var tooltip, // global variables oh my! Refactor when deploying!
hidetooltiptimer
function createtooltip(){ // call this function ONCE at the end of page to create tool tip object
tooltip = document.createElement('div')
tooltip.style.cssText =
'position:absolute; background:black; color:white; padding:4px;z-index:10000;'
+ 'border-radius:2px; font-size:12px;box-shadow:3px 3px 3px rgba(0,0,0,.4);'
+ 'opacity:0;transition:opacity 0.3s'
tooltip.innerHTML = 'Copied!'
@fhdalikhan
fhdalikhan / nginxproxy.md
Created December 19, 2018 05:57 — forked from barbietunnie/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@fhdalikhan
fhdalikhan / reset-last-commit.md
Created December 19, 2018 05:57 — forked from barbietunnie/reset-last-commit.md
Undo the most recent commits in Git

Undo a commit and redo

$ git commit -m "Something terribly misguided"             # (1)
$ git reset HEAD~                                          # (2)
<< edit files as necessary >>                              # (3)
$ git add ...                                              # (4)
$ git commit -c ORIG_HEAD                                  # (5)
@fhdalikhan
fhdalikhan / gist:6572c6f6dbf21c07f8baee76a2d548e9
Last active January 8, 2019 05:47
Select2 populate option dynamically
var fromTitle = 'Paris';
var toTitle = 'paris_fr';
// Note: if id is same and title is updated then it won't change, so set a new id if you are updating a label and then set it back
var fromId = 'New York';
var toId = 'new-york-city_ny_us';
var newFromOption = new Option(fromTitle, fromId, false, false);
$('.fromLocation').eq(0).append(newFromOption); // add the option because of AJAX it would not exist
$('.fromLocation').eq(0).val(fromId); // Select the option with the value
@fhdalikhan
fhdalikhan / gist:023f5459030ac3f3f903e1403b906bbe
Created January 29, 2019 05:50
This javascript function can be used to only allow typing of alphabets, & _ - and whitespace, it will remove all other characters, it uses a regex for this, you can modify to allow other characters, for example to allow numbers as well just add 0-9 to the regex after A-Z.
(function(){
// Allow only alphabets & _ - whitespaces, strip out all others.
function clean(str) {
return str.replace(/[^a-z-A-Z\&\_\- ]/g, "").replace(/ +/, " ")
}
$('body').on('keyup', '#ask_message_textarea, #ask_message_title', function(event) {
this.value = clean(this.value);
@fhdalikhan
fhdalikhan / gist:4fe3ba1b99d6a606a004dc50273c7aeb
Created January 29, 2019 11:58
PHP equivalent of number_format in javascript
function number_format (number, decimals, dec_point, thousands_sep) {
// Strip all characters but numerical ones.
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec) {
var k = Math.pow(10, prec);
@fhdalikhan
fhdalikhan / gist:8f110b7a94c1335ddc5cd5496b45981a
Last active February 7, 2019 08:56
get unix timestamp from date, date format is YYYY-MM-DD
function getUnixTimeFromDate (date) {
if ( typeof(date) === 'undefined' ) {
throw 'Date is required';
}
// using lodash _.isEmpty if available
if ( typeof window._.isEmpty === 'function' && _.isEmpty(date) ) {
throw 'Date cannot be empty.';
} else if( date === '' || date == '' ) {
throw 'Date cannot be empty.';
@fhdalikhan
fhdalikhan / htaccess redirect non www to www
Last active February 11, 2019 08:30
Redirect request without www to www and keep the http or https protocol intact
RewriteEngine On
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]