Skip to content

Instantly share code, notes, and snippets.

View AhmedKorim's full-sized avatar

Ahmed Korim AhmedKorim

View GitHub Profile
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function () {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
@AhmedKorim
AhmedKorim / PromisAllWithFails.js
Created April 30, 2019 09:44 — forked from nhagen/PromisAllWithFails.js
Wait until all promises have completed even when some reject, with Promise.all
var a = ["sdfdf", "http://oooooolol"],
handleNetErr = function(e) { return e };
Promise.all(fetch('sdfdsf').catch(handleNetErr), fetch('http://invalidurl').catch(handleNetErr))
.then(function(sdf, invalid) {
console.log(sdf, invalid) // [Response, TypeError]
})
.catch(function(err) {
console.log(err);
})
@AhmedKorim
AhmedKorim / mongoose-cheatsheet.md
Created October 25, 2018 13:15 — forked from subfuzion/mongoose-cheatsheet.md
mongoose cheatsheet

Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.

Install

$ npm install mongoose --save

Connect

const mongoose = require('mongoose');
@AhmedKorim
AhmedKorim / git-clearHistory
Last active August 4, 2018 00:05 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@AhmedKorim
AhmedKorim / serve-skeleton-page.js
Created June 30, 2018 23:03 — forked from luke-denton-aligent/serve-skeleton-page.js
This snippet shows how to cache and serve a skeleton page
// Offline Web Applications course on Udacity https://classroom.udacity.com/courses/ud899
//When a browser runs a service worker for the first time, an event is fired within it, 'install'. This can be used
//to trigger functions to download assets and save them to the cache, using the Cache API
//Started with snippet from https://gist.github.com/luke-denton/ef791e5150470814a7a155cd85b1bf80
var staticCacheName = "my-cache-v2"; //Update the cache version
self.addEventListener('install', function(event) {
var urlsToCache = [
@AhmedKorim
AhmedKorim / webpack.lint.config.js
Created May 1, 2018 18:52 — forked from manavsehgal/webpack.lint.config.js
Webpack configuration for running Browsersync, ESLint and StyleLint along with Hot Reloading
// Initialization
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const postcssImport = require('postcss-easy-import');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const path = require('path');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const APP = path.join(__dirname, 'app');