Skip to content

Instantly share code, notes, and snippets.

@xperiments
xperiments / OddNumber.js
Created June 28, 2013 18:23
Find Odd Number
The "trick" is to binary AND a value with 1.
Any odd number must have the first bit set to 1.
So
var foo = 7;
if( foo & 1 ) { // true }
Using a bitwise AND has a better performance in almost all platforms / browsers.
@xperiments
xperiments / NewableTypes.ts
Created June 20, 2013 21:28
Typescript Newable Types
http://stackoverflow.com/questions/13407036/how-does-typescript-interfaces-with-construct-signatures-work
Construct signatures in interfaces are not implementable in classes; they're only for defining existing JS APIs that define a 'new'-able function. Here's an example involving interfaces new signatures that does work:
interface ComesFromString {
name: string;
}
interface StringConstructable {
new(n: string): ComesFromString;
// 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 October 9, 2015 13:53 — forked from leonderijke/svgfixer.js
Fixes references to inline SVG elements when the <base> tag is in use.
/**
* 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 July 16, 2014 11:46
AngularJS Typescript Static Injector References
/**
* $di.ts
* http://www.xperiments.io/posts/typescript-angularjs-best-practices/
* xperiments on 15/07/14.
*/
module $di
{
/* service */
export class $ng
{
module io.xperiments.utils.serialize
{
/**
* The mini
*/
export interface ISerializableObject
{
"@serializable":string;
}
export interface ISerializable extends ISerializableObject