Skip to content

Instantly share code, notes, and snippets.

@PAEz
PAEz / gist:3780081
Created September 25, 2012 04:59
HashArray - Incomplete
function HashArray() {
this.array = [];
this.hash = {};
this.__defineGetter__("length", function() {
return this.array.length;
});
this.set = function(key, value) {
if (typeof(key) === 'string') {
chrome.browserAction.setPopup({
popup: "popup.html"
})
chrome.browserAction.onClicked.addListener(function() {
chrome.browserAction.setPopup({
popup: "popup.html"
})
});
@PAEz
PAEz / Attach function with arguments.js
Last active December 16, 2015 11:18
Attach a function to a page from a content script and execute it with arguments.
function exec(fn) {
var args = '';
if (arguments.length > 1) {
for (var i = 1, end = arguments.length - 2; i <= end; i++) {
args += typeof arguments[i]=='function' ? arguments[i] : JSON.stringify(arguments[i]) + ', ';
}
args += typeof arguments[i]=='function' ? arguments[arguments.length - 1] : JSON.stringify(arguments[arguments.length - 1]);
}
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
@PAEz
PAEz / Iterate an Objects keys
Created July 30, 2013 19:05
Short, quick way to iterate over an Objects keys.
var obj = {
one: null,
two: undefined,
three: 3
}
for (var i = 0, keys = Object.keys(obj), key; key = keys[i]; i++) {
console.debug(obj[key]);
}
@PAEz
PAEz / template.js
Created December 19, 2013 08:59
Little helpers: a tweet-sized JavaScript templating engine Thomas Fuchs http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/
function t(s,d){
for(var p in d)
s=s.replace(new RegExp('{'+p+'}','g'), d[p]);
return s;
}
t("Hello {who}!", { who: "JavaScript" });
// "Hello JavaScript!"
t("Hello {who}! It's {time} ms since epoch.", { who: "JavaScript", time: Date.now });
@PAEz
PAEz / multilineString.js
Last active April 4, 2017 22:38
Doing a multi line string
var string=(function () {
/*
Bleh Bleh
Meh
Huh
Works in FF and Chrome atleast, havent tried anywhere else
*/
}).toString().split('\n').slice(2,-2).join('\n').trim();
function dyslexia(string){return String.fromCharCode.apply(this,string.split('').map(function(a){return a.charCodeAt()^255;}))}
var a = "{lives:3}";
var z = dyslexia(a);
a == dyslexia(z);
@PAEz
PAEz / evIl.js
Created July 13, 2014 10:06
evIl
var evIl = function(script) {
blob = new Blob([script], {
type: "application/javascript"
});
url = window.URL.createObjectURL(blob);
s = document.createElement('script');
s.src = url;
document.head.appendChild(s);
window.URL.revokeObjectURL(url);
s.parentElement.removeChild(s);
@PAEz
PAEz / gist:c4a2f2f5f0f7f627eb1a
Created August 28, 2014 13:07
glfx blend modes
function blend(element,blendMode,opacity) {
// this._.extraTexture.loadContentsOf(element);
// this._.extraTexture.use(1);
element._.use(1);
if(gl.blend == undefined){
var shader= (function () {
/*
Reserved words
--------------
Width
Height
X
Y
Scale - not used yet but will be used to declare the scalling method and details (slice and all that)