Skip to content

Instantly share code, notes, and snippets.

View englishextra's full-sized avatar
💜
the beat goes on

englishextra englishextra

💜
the beat goes on
View GitHub Profile
@englishextra
englishextra / loadScript.js
Created December 29, 2016 20:36 — forked from micahjon/loadScript.js
Promise-based Asynchronous Script Loader
/**
* Loads javascript file by url and saves reference to it by name, so it's not loaded again
* @param {string} name Name of js library
* @param {string} url Url to js library
* @return {promise} Resolves when library is loaded
*
* Based on example by Brad Berger: https://bradb.net/blog/promise-based-js-script-loader/
* Extended w/ global variable to keep track of previously loaded scripts.
* Removed support for loading several independent scripts at once via Promise.all()
*
@englishextra
englishextra / gist:5bce24b8b4276c19c33d5bbf64453222
Created December 29, 2016 14:11 — forked from getify/gist:670840
using LABjs to load from a CDN, with simple error detection (& timeout), and a local load fallback
function test_jQuery() { jQuery(""); }
function success_jQuery() { alert("jQuery is loaded!");
var successfully_loaded = false;
function loadOrFallback(scripts,idx) {
function testAndFallback() {
clearTimeout(fallback_timeout);
if (successfully_loaded) return; // already loaded successfully, so just bail
try {
scripts[idx].test();
@englishextra
englishextra / timestamp.js
Created December 20, 2016 09:38 — forked from hurjas/timestamp.js
Print out a nicely formatted timestamp in JavaScript.
/**
* Return a timestamp with the format "m/d/yy h:MM:ss TT"
* @type {Date}
*/
function timeStamp() {
// Create a date object with the current time
var now = new Date();
// Create an array with the current month, day and time
@englishextra
englishextra / uri.js
Created September 6, 2016 17:44 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@englishextra
englishextra / getDomainName.js
Created September 6, 2016 17:42 — forked from tahirm/getDomainName.js
Get complete domain name with protocol and port if available. #js #url From http://stackoverflow.com/questions/6941533/javascript-get-protocol-domain-and-port-from-url
var domain = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port : '');
@englishextra
englishextra / ie.shims.js
Created August 29, 2016 13:46 — forked from dhm116/ie.shims.js
IE7/8 Javascript method shims
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@englishextra
englishextra / vanilla-js-cheatsheet.md
Created August 21, 2016 21:20 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
@englishextra
englishextra / plain.js
Created May 23, 2016 13:09 — forked from kkga/plain.js
snippets of plain js
// document.ready
document.addEventListener("DOMContentLoaded", function() {
// your code
}, false);
// select div
var element = document.querySelector("div");
@englishextra
englishextra / JSON with JS.md
Created May 22, 2016 13:11
Access local JSON data with Javascript

What

An updated guide/collection of guides on how to access JSON data with JavaScript

Original Question on Stack Exchange.


Example 1

For reading the external Local JSON file (data.json) using java script

@englishextra
englishextra / promises.md
Created May 17, 2016 21:19 — forked from domenic/promises.md
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.