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 / 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());
View svgfixer-clip-paths.js
// Original: https://gist.github.com/leonderijke/c5cf7c5b2e424c0061d2
(function(document, window) {
"use strict";
document.addEventListener("DOMContentLoaded", function() {
var baseUrl = window.location.href
.replace(window.location.hash, "");
[].slice.call(document.querySelectorAll("use[*|href]"))
@xperiments
xperiments / svgfixer.js
Created Oct 9, 2015 — forked from leonderijke/svgfixer.js
Fixes references to inline SVG elements when the <base> tag is in use.
View svgfixer.js
/**
* SVG Fixer
*
* Fixes references to inline SVG elements when the <base> tag is in use.
* Firefox won't display SVG icons referenced with
* `<svg><use xlink:href="#id-of-icon-def"></use></svg>` when the <base> tag is on the page.
*
* More info:
* - http://stackoverflow.com/a/18265336/796152
* - http://www.w3.org/TR/SVG/linking.html
@xperiments
xperiments / $di.ts
Created Jul 16, 2014
AngularJS Typescript Static Injector References
View $di.ts
/**
* $di.ts
* http://www.xperiments.io/posts/typescript-angularjs-best-practices/
* xperiments on 15/07/14.
*/
module $di
{
/* service */
export class $ng
{
View TypescriptSerializer
module io.xperiments.utils.serialize
{
/**
* The mini
*/
export interface ISerializableObject
{
"@serializable":string;
}
export interface ISerializable extends ISerializableObject
@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){
View xhr2base64.js
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+/";
@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
View base64-binary.js
/*
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
@xperiments
xperiments / xhr2base64
Created Jul 10, 2013
XHR => base64 => Binary
View xhr2base64
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
You can’t perform that action at this time.