Skip to content

Instantly share code, notes, and snippets.

View darkowlzz's full-sized avatar

Sunny darkowlzz

  • ‏‏‏‏‎ ‎
View GitHub Profile
let chromeWindow = open('chrome://foo/content/');
assert.ok(~windows().indexOf(chromeWindow), 'chrome URI works');
let resourceWindow = open('resource://foo');
assert.ok(~windows().indexOf(resourceWindow), 'resource URI works');
// Wait for the window unload before ending test
close(chromeWindow).close(resourceWindow).then(done);
var sec = document.body.id;
$('ul#nav-main-menu > li').each(function( index ) {
if ($(this).text().toUpperCase() == sec.toUpperCase()) {
$('#nav-main-menu [tabindex=0]').get(index).focus();
}
});
@darkowlzz
darkowlzz / Longest Sequence
Last active December 26, 2015 23:49
Longest Seq
def findSeq(str):
# A list to store the words.
seq = []
# Create words from the given string and
# store in seq.
word = str[0]
for i in range(len(str)-1):
current = ord(str[i])
next = ord(str[i+1])
if current <= next:
main.js
=======
const sp = require("sdk/simple-prefs");
const keys = require("keys");
sp.on("hotkey", keys.hotkeyCheck(showHotkey, pan));
keys.js
var mystring = "hey there, here is the link http://www.mozilla.org yah!";
REGEX = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
function doIt(match) {
return "<a href='" + match + "'> " + match + "</a>";
}
console.log(mystring.replace(REGEX, doIt));
Handlebars.registerHelper("linkify", function (message) {
function doIt(match) {
return "<a target='_blank' href='" + match + "'>" + match + "</a>";
};
console.log("linkifying...");
console.log("here: " + message.replace(REGEX, doIt));
return new Handlebars.SafeString(message.replace(REGEX, doIt));
});
@darkowlzz
darkowlzz / delayedEventListener.js
Last active August 29, 2015 14:00
a delayed event listener
// Call eventlistener callback after a short delay
delayedEventListener(node, event, callback, useCapture) {
node.addEventListener(event, function handler(evt) {
node.removeEventListener(event, handler, useCapture); // remove the listener, not necessary
timer.setTimeout(function() {
try {
callback.call(self, evt); // call the main callback
}
catch(err) { }
}, someTime); // any amount of time to delay
@darkowlzz
darkowlzz / gist:132cbed31d20af6b4b9e
Last active August 29, 2015 14:00
addEventListener syntax
// Syntax of a event listener
target.addEventListener(type, listener[, useCapture]);
@darkowlzz
darkowlzz / BADviewPanel.js
Last active August 29, 2015 14:00
Snippet of BADviewPanel.js
// ViewPanel class
function ViewPanel(content, script) {
this.panel = Panel({
width: sp.prefs['width'],
height: sp.prefs['height'],
contentURL: data.url(content),
contentScriptFile: data.url(script)
});
// listeners on the prefs change
@darkowlzz
darkowlzz / BAD2viewPanel.js
Last active August 29, 2015 14:00
Snippet of BAD2viewPanel.js
// ViewPanel class
function ViewPanel(content, script) {
this.panel = Panel({
width: sp.prefs['width'],
height: sp.prefs['height'],
contentURL: data.url(content),
contentScriptFile: data.url(script)
});
// Moved inside the class, better than fighting with closures again