Skip to content

Instantly share code, notes, and snippets.

View abdulhannanali's full-sized avatar
💭
WUNDERWALL!!!!

Hannan Ali abdulhannanali

💭
WUNDERWALL!!!!
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/pouchdb/latest/pouchdb.min.js"></script>
<script src="https://code.jquery.com/jquery-compat-3.0.0-alpha1.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@abdulhannanali
abdulhannanali / gist:e927f84afa52bc39adcf
Created March 8, 2016 16:57 — forked from josteink/on_stateful_code.txt
On why stateful code is bad
STUDENT: Sir, can I ask a question?
TEACHER: Yes!
STUDENT: How do you put an elephant inside a fridge?
TEACHER: I don't know.
STUDENT: It's easy, you just open the fridge and put it in. I have another question!
TEACHER: Ok, ask.
STUDENT: How to put a donkey inside the fridge?
TEACHER: It's easy, you just open the fridge and put it in.
STUDENT: No sir, You just open the fridge take out the elephant and put it in.
TEACHER: Ooh...ok!!
@abdulhannanali
abdulhannanali / brainworkers.js
Created May 16, 2016 17:43
Too many things in your mind at same time, use Clustering in Node.js to solve this issue
/*
* brainworkers.js
* Having non-blocking IO code is good but you still are single threaded
* and are not built for this fast internet world of 21st Century
* this code is for you.
*/
const mindClusters = require("cluster");
const yourMind = require("brain");
const numBpus = yourMind.bpus().length;
@abdulhannanali
abdulhannanali / purepromise.js
Last active November 29, 2016 07:33
Question: Is the function that returns a promise can be considered pure? The returned function might be performing I/O
import axios from 'axios'
/**
* getIdentity
* returns a Promise provided the name of the user
*/
function getIdentity (name) {
return axios.get('https://getyourinfo.pk/' + name)
}
/**
* Purger.js is a helpful utility to purge the cache based on the Jekyll's sitemap
* generated, which allows us to have a lot of great functionality in there.
* This utility is written for blog called https://fascinations.hannanali.tech,
* check out this article to read meaningful articles from me
*/
const Cloudflare = require('cloudflare')
const xml2js = require('xml2js')
const fs = require('fs')
const sitemapReader = require('./sitemapReader')
@abdulhannanali
abdulhannanali / pixel-list.js
Last active April 26, 2017 08:58
Pixel List defines a custom iterator to iterate the list of Pixel containing x and y coordinated in a sorted order based on their distance from (0, 0). Based on the idea in Getify's YDKS This and Object Prototypes Book to define a custom iterator
const Pixel = require('./pixel-it');
// Contains all the pixels within a list
const pixelList = []
// Custom iterator of object is accessed by using
// Symbol.iterator a computed property name
pixelList[Symbol.iterator] = function () {
// Defining a function for the custom iterator
const sortedList = sortList(this);
@abdulhannanali
abdulhannanali / serviceworker-registration.js
Created July 2, 2017 11:38
Show a ServiceWorker Installed Popup
// Display a Information about ServiceWorker Installation being Completed.
// An alternative and more battle tested way to do the same thing is found on Google I/O 2016 PWA (IOWA)
// https://github.com/GoogleChrome/ioweb2016/blob/8cfa27261f9d07fe8a5bb7d228bd3f35dfc9a91e/app/scripts/helper/service-worker-registration.js#L34-L46
/// One way to register the Caching complete event for the service workers
/// I am using this in my application and this seems to be working
if ('serviceWorker' in navigator) {
const initialController = navigator.serviceWorker.controller;
navigator.serviceWorker.register('./serviceWorker.js').then(registration => {
if (registration.installing) {
console.log('This is going to be printed out in npx and that is going to be awesome');
console.log('npx is an awesome utility that comes preinstalled with `npx` yayyyyy!');
@abdulhannanali
abdulhannanali / dabblet.css
Created September 5, 2017 09:42 — forked from anonymous/dabblet.css
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;