Skip to content

Instantly share code, notes, and snippets.

Pedro Casaubon xperiments

Block or report user

Report or block xperiments

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xperiments
xperiments / Dictionary.ts
Created Jun 25, 2013
Typescript Dictionary
View Dictionary.ts
//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[];
}
View index.html
<template id="oi-template">
<table class="oi-card0">
<tr>
<th colspan="2">Month</th>
</tr>
<tr>
<td>Deckungsumme</td>
<td type="{{deckungsumme.type}}">{{deckungsumme.value}}</td>
</tr>
<tr>
@xperiments
xperiments / new_gist_file
Last active Feb 13, 2018
[[ts] Check if obj is instanceof U] Check if obj is instanceof U
View new_gist_file
// => 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();
@xperiments
xperiments / ArrayBuffer2Base64.js
Last active Feb 13, 2018
[[js][utils][base64] ArrayBuffer2Base64] ArrayBuffer2Base64 #js #base64
View ArrayBuffer2Base64.js
// 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
@xperiments
xperiments / interlval.js
Last active Feb 13, 2018
[[js][hacks]] Better setInterval #js #hacks #tips
View interlval.js
// 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){
@xperiments
xperiments / OneTimeDirective.ts
Created Feb 13, 2018
[[ng][directives]] OneTimeDirective #ng #directive
View OneTimeDirective.ts
// 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());
@xperiments
xperiments / Singleton.ts
Created Jun 25, 2013
Typescript Singleton
View Singleton.ts
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.");
View dload.js
// Code snippets for dynamically loading JavaScript and CSS
// Copyright : This script has been placed in the public domain.
// Gist : https://gist.github.com/livibetter/5211293
// Blog post : http://blog.yjl.im/2013/03/dynamically-loading-javascript-and-css.html
// Last update : 2013-03-21T07:35:25Z
// Author : Yu-Jie Lin
// Website : http://yjl.im
function load_CSS(src, cb) {
var link = document.createElement('link');
You can’t perform that action at this time.