Skip to content

Instantly share code, notes, and snippets.

View taimursaeed's full-sized avatar

Taimur Saeed taimursaeed

View GitHub Profile
@taimursaeed
taimursaeed / localStorage.js
Created February 9, 2018 10:01
Storing and Retrieving JSON from Local Storage
function storeItem(itemName, data) {
localStorage.setItem(itemName, btoa(JSON.stringify(data)));
}
function retrieveItem(itemName) {
var x = localStorage.getItem(itemName);
if (!x) { console.log("Element not found in local storage"); return false; }
localStorage.removeItem('x');
x = atob(x);
return $.parseJSON(x);
@taimursaeed
taimursaeed / capitalizeFirstLetter.js
Created February 9, 2018 10:03
Capitalize First Letter JS
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// use it like capitalizeFirstLetter('hello')
// returns Hello
@taimursaeed
taimursaeed / readQueryString.js
Created February 9, 2018 10:10
Reads Query String
function getUrlVars() {
var vars = [],
hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
@taimursaeed
taimursaeed / readJSON.js
Created February 9, 2018 10:12
Read JSON key value
$.each(myJSON, function(key, value) {
//read key and value here
});
@taimursaeed
taimursaeed / gulpfile.js
Last active April 7, 2018 04:42
Boilerplate gulpfile
var gulp = require("gulp");
var clean = require('gulp-clean');
var concat = require("gulp-concat");
var sourcemaps = require('gulp-sourcemaps');
var minifyHtml = require("gulp-minify-html");
var critical = require('critical').stream;
var cleanCSS = require('gulp-clean-css');
@taimursaeed
taimursaeed / package.json
Created April 7, 2018 04:42
Boilerplate Package.json
{
"name": "gulp-boilerplate",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Taimur",
"license": "ISC",
/*
Thanks to: https://gist.github.com/davidtheclark/5515733#gistcomment-2113205
*/
function isAnyPartOfElementInViewport(el) {
const rect = el.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
const windowHeight = (window.innerHeight || document.documentElement.clientHeight);
const windowWidth = (window.innerWidth || document.documentElement.clientWidth);
document.documentElement //<HTML> tag
document.body //<Body> tag
document.documentElement.scrollHeight //Total page height
document.documentElement.clientHeight || window.innerHeight //Viewport height
window.scrollY || document.documentElement.scrollTop //How much the document is scrolled
@taimursaeed
taimursaeed / shortkeys.ahk
Last active November 5, 2019 11:31
My Autohotkey Shortcuts for PC
^!d::RUN,"C:\Users\PC\Downloads"
^!n::RUN,"Notepad"
^!1::RUN,"Chrome"
^!2::RUN,"C:\Program Files\Mozilla Firefox\firefox.exe"
^!3::RUN,"C:\Program Files\Internet Explorer\iexplore.exe"
^!4::Run microsoft-edge:https://autohotkey.com
^!0::RUN,"C:\Program Files\Sublime Text 3\sublime_text.exe"
^SPACE:: Winset, Alwaysontop, , A
#$WheelUp::
Send {Volume_Up}
@taimursaeed
taimursaeed / SearchEverything.ahk
Created November 18, 2019 12:14 — forked from Onurtag/ExploreEverything.ahk
Search from current explorer folder, desktop and taskbar using Everything
#SingleInstance Force
#NoTrayIcon ;Delete this line if you want the tray icon to be visible.
EverythingPath := "C:\Program Files\Everything\Everything.exe" ;If your everything.exe isn't here, fix that. Keep the quotes.
MyUsername := "MyUserName" ;Go to %userprofile% and change this to the title of that window. Keep the quotes.
MyRecycleBin := "Recycle Bin" ;Go to your Recycle Bin and change this to the title of that window. Keep the quotes.
MyThisPC := "This PC" ;Go to your This PC and change this to the title of that window. Keep the quotes.
;You can delete below blocks if you don't want the features. Replace ^F with F3 if you are using that instead.