This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | |
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera) | |
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+ | |
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; | |
// At least Safari 3+: "[object HTMLElementConstructor]" | |
var isChrome = !!window.chrome && !isOpera; // Chrome 1+ | |
var isIE = /*@cc_on!@*/false; // At least IE6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://stackoverflow.com/questions/15877362/declare-and-initialize-a-dictionary-in-typescript | |
interface IDictionary { | |
add(key: string, value: any): void; | |
remove(key: string): void; | |
containsKey(key: string): bool; | |
keys(): string[]; | |
values(): any[]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// => http://stackoverflow.com/questions/17392349/how-can-i-check-if-element-is-an-instanceof-u | |
function OfType<T, U>(list: T[], arg: Function) : U[] | |
{ | |
var result: U[] = []; | |
list.forEach(e => { | |
// extract the name of the class | |
// used to match primitive types | |
var typeName = /function\s*([^(]*)/i.exec(arg+"")[1].toLocaleLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then | |
// use window.btoa' step. According to my tests, this appears to be a faster approach: | |
// http://jsperf.com/encoding-xhr-image-data/5 | |
function base64ArrayBuffer(arrayBuffer) { | |
var base64 = '' | |
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | |
var bytes = new Uint8Array(arrayBuffer) | |
var byteLength = bytes.byteLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/ | |
function interval(func, wait, times){ | |
var interv = function(w, t){ | |
return function(){ | |
if(typeof t === "undefined" || t-- > 0){ | |
setTimeout(interv, w); | |
try{ | |
func.call(null); | |
} | |
catch(e){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/angular/angular/issues/14033 | |
@Directive({ | |
selector: '[oneTime]', | |
}) | |
export class OneTimeDirective { | |
constructor(template: TemplateRef<any>, container: ViewContainerRef, zone: NgZone) { | |
zone.runOutsideAngular(() => { | |
const view = container.createEmbeddedView(template); | |
setTimeout(() => view.detach()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module x | |
{ | |
export class Singleton | |
{ | |
private static _instance : Singleton; | |
constructor( singletonEnforcer:()=>void ) | |
{ | |
if( singletonEnforcer !== SingletonEnforcer ) | |
{ | |
throw new Error("Error: Instantiation failed: Use Singleton.getInstance() instead of new."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2011, Daniel Guerrero | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright | |
notice, this list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright | |
notice, this list of conditions and the following disclaimer in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/7370943/retrieving-binary-file-content-using-javascript-base64-encode-it-and-reverse-de | |
https://gist.github.com/jonleighton/958841 | |
https://github.com/danguer/blog-examples/blob/master/js/base64-binary.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBinary(file){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", file, false); | |
xhr.overrideMimeType("text/plain; charset=x-user-defined"); | |
xhr.send(null); | |
return xhr.responseText; | |
} | |
function base64Encode(str) { | |
var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
NewerOlder