Skip to content

Instantly share code, notes, and snippets.

Avatar

Hadaytullah hadaytullah

View GitHub Profile
View cssValidatorJQuery.js
$(document).ready(function () {
function sol(today,limit){
let incorrectStyle = 0;
$("tr").each(function (key, val) {
let $tds = $(this).find('td'),
$rowStyle = $(this).css('background-color'),
customerId = $tds.eq(0).text(),
issueDate = new Date($tds.eq(1).text()),
returnDate = $tds.eq(2).text?new Date($tds.eq(2).text()):new Date();
@hadaytullah
hadaytullah / statsCollector.js
Last active Oct 25, 2019
Statistics collector that calculates the median and average request response times for a 7 days dataset.
View statsCollector.js
/*
* Our application servers receive approximately 20 000
* http requests per second. Response timeout is 19000ms.
* Implement a statistics collector that calculates the
* median and average request response times for a 7 day
* dataset.
*/
'use strict';
@hadaytullah
hadaytullah / requireShare.js
Last active Oct 25, 2019
RequireJS modules sharing data
View requireShare.js
//requireJS shared instances
require.config({
paths: {
}
});
define("one", function() {
return { sharedVariable:"one" };
});
@hadaytullah
hadaytullah / deferred.js
Last active Oct 25, 2019
Deferred/Promise Sample
View deferred.js
function a(){
var d1=$.Deferred();
_.defer(function(){
console.log("a executed");
d1.resolve("resolved");
//d1.reject("reject");
},500);
d1.pipe(function successPipe(){
console.log("local pipe");
@hadaytullah
hadaytullah / autoExtendingTextArea.js
Created Oct 25, 2019
Auto extending HTML text area
View autoExtendingTextArea.js
$('#ta').on('keydown',function(){
var thisInput = event.target;
var $thisInput = $(thisInput);
var previousScrollHeight = $thisInput.data('previous-scroll-height');
if(previousScrollHeight === null || previousScrollHeight === undefined){ //first time
$thisInput.data('previous-scroll-height',thisInput.scrollHeight);
previousScrollHeight = thisInput.scrollHeight;
}
@hadaytullah
hadaytullah / urlParser.js
Created Oct 25, 2019
Parses a url into its different parts.
View urlParser.js
var UrlParser = function() {
this.result = {};
};
UrlParser.prototype.parse = function(url) {
var urlWithoutScheme = url.split('://')[1];
var pathStartIndex = urlWithoutScheme.indexOf('/');
var queryStartIndex = urlWithoutScheme.indexOf('?');
var hostAndPort;
@hadaytullah
hadaytullah / linkstation.js
Last active Oct 25, 2019
Find nearest linkstation for a device
View linkstation.js
/**
* @author Hadaytullah Kundi
*/
/**
* Link Station as ECMAScript 2015 class.
*/
class LinkStation {
/*
* LinkStation Constuctor
@hadaytullah
hadaytullah / fibonacci.js
Last active Oct 25, 2019
Fibonacci series generator
View fibonacci.js
var fibo=function(n){
var resp=[],previous=0, current=1;
while(current<n){
var currentCopy=current;
console.log(current);
current= previous + current;
previous=currentCopy;
}
}
@hadaytullah
hadaytullah / markdownToPhp.php
Last active Oct 25, 2019
Convert header h1-h6 markdown in php to html
View markdownToPhp.php
<? php
function markdown_parser ($markdown) {
$segments = explode('# ', trim($markdown), 2);
if(count($segments)>1){
//adding back the hash that explode removed, this simplifies the logic below
$segments[0] = $segments[0].'#';
//making sure that all are hashes and nothing else at the start of markdown
$first_array = str_split($segments[0]);
$unique = array_unique($first_array);
@hadaytullah
hadaytullah / highOrderBitmask.php
Last active Oct 25, 2019
Calculates high order bit mask for a word size
View highOrderBitmask.php
<? php
function high_order_bitmask($wordSize) {
if($wordSize == 0 or $wordSize == 1){
return 0;
}
$bitmask = 0;
for($i=$wordSize-1; $i >= $wordSize/2; $i-- ){
$bitmask += pow(2,$i);
}
return $bitmask;