Skip to content

Instantly share code, notes, and snippets.

@fflorent
fflorent / gist:4418708
Last active December 10, 2015 10:08 — forked from anonymous/gist:4418578
function loop(f)
{
for(var i = 0; i < 10000; i++)
f(Math.floor(Math.random() * 2 - 1));
}
console.time(">-1");
loop(function(index) index * eval("1") > -1);
console.timeEnd(">-1");
@fflorent
fflorent / clickandrotate.js
Created March 20, 2012 12:37
click and rotate
document.body.addEventListener("click", function(ev)
{
var el = ev.originalTarget;
el.style.MozTransition = "3s";
el.style.MozTransform = "rotate(360deg)";
});
document.body.addEventListener("transitionend", function(ev){
var el = ev.originalTarget;
el.style.MozTransition = "0s";
@fflorent
fflorent / willitblend.js
Created January 31, 2012 12:52
will it blend
/* run it in a web console (firebug, etc.) */
alert("will it blend?"); Array.prototype.forEach.call(document.querySelectorAll("*"), function(el){ el.style.MozTransform = "rotate(10000deg) scale(0)"; el.style.MozTransition = "50s linear"; }); var ok = function(){ alert('yes, it blends !'); document.body.removeEventListener("transitionend", ok, false);}; document.body.addEventListener("transitionend", ok, false);
@fflorent
fflorent / canContain.js
Created July 13, 2011 12:08
[ORYX] A hack to fix non-interpretation of canContain
/*
Copyright (C) 2011 by Florent FAYOLLE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@fflorent
fflorent / canConnect.hack.js
Created July 13, 2011 09:43
[ORYX] A hack to fix non-interpretation of canConnect
/*
Copyright (C) 2011 by Florent FAYOLLE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@fflorent
fflorent / fix_containsMorphingRules.js
Created July 12, 2011 14:09
[ORYX] a workaround for containsMorphingRules and showStencilButtons when no morphing rules
/**
* Fix for containsMorphingRules and showStencilButtons
* which avoids in some case to show the shape menu
* see this bug : http://code.google.com/p/oryx-editor/issues/detail?id=481
*/
(function(){
var prot = ORYX.Core.StencilSet.Rules.prototype;
var origFn = prot.containsMorphingRules;
prot.containsMorphingRules = function(){
// we get the caller function :
@fflorent
fflorent / DeleteEventRaiser
Created June 24, 2011 09:43
[Oryx] Delete Event Raiser Hack
(function(dc){
var proxy = dc.prototype.execute;
dc.prototype.execute = function(){
var StopPropagationException = function(){};
var event = {
type: "shapedeleted",
shapes:this.shapesAsJson,
dockers:this.dockers,
cancel: false
};
@fflorent
fflorent / ORYX.Editor.getInstance
Created June 21, 2011 07:54
overrides ORYX.Editor constructor for accessing to unique instance (Singleton-like)
// overrides ORYX.Editor constructor for accessing to unique instance (Singleton-like)
(function(OE){
var proxy = OE.prototype.construct;
OE.getInstance = function(){
return OE.instance;
};
OE.prototype.construct= function(){
proxy.apply(this, arguments);
OE.instance = this;
};
@fflorent
fflorent / oryx.getChildById.fix.js
Created June 16, 2011 14:30
[ORYX] Hack to Fix getChildById
ORYX.Core.UIObject.prototype.getChildById = function(id, deep) {
var i, child, ret;
for(var i = 0; i < this.children.length && ret === undefined; i++){
child = this.children[i];
if(child.getId() === id)
ret = child;
else if(deep){
ret = child.getChildById(id, deep);
}
}