Skip to content

Instantly share code, notes, and snippets.

View nlacasse's full-sized avatar

Nicolas Lacasse nlacasse

  • Los Angeles, CA
View GitHub Profile
background.html
===============
// Bounce all requests back to the tab they came from
chrome.extension.onRequest.addListener(function (request, sender, sendResponse) {
chrome.tabs.sendRequest(sender.tab.id, request, sendResponse);
});
view.html (iframe)
==================
chrome.extension.sendRequest({
to: 'overlord',
method: 'startDrag',
params: {
x: mousedown_event.screenX,
y: mousedown_event.screenY
}
});
overlord.js (content script)
============================
/**
* Adds event listeners to the window to detect mousemoves and moves the iframe
* corespondingly.
*/
IframeOverlord.prototype.startDrag = function(params) {
var overlord = this;
// location of click inside iframe
@nlacasse
nlacasse / gist:647622
Created October 26, 2010 19:44
i can make this happen
var domTest = require('./lib/domtest');
var testDocumentExists = function (window) {
assert.notEqual(window.document, undefined);
};
var testJQueryVersion = function (versionString) {
return function (window) {
assert.notEqual(window.jQuery, undefined);
assert.strictEqual(window.jQuery.fn.jquery, versionString);
> try { poop() } catch (e) {console.trace(e.stack) }
Trace: ReferenceError: poop is not defined
at [object Context]:1:7
at Interface.<anonymous> (repl:98:19)
at Interface.emit (events:27:15)
at Interface._ttyWrite (readline:295:12)
at Interface.write (readline:132:30)
at Stream.<anonymous> (repl:79:9)
at Stream.emit (events:27:15)
at IOWatcher.callback (net:489:16)
@nlacasse
nlacasse / gist:730882
Created December 6, 2010 20:21
walnuts
var jerk = require('jerk');
var options = {
server: 'iriecycle.net',
port: 6600,
nick: 'walnuts',
user: {
username: 'walnuts',
hostname: 'walnuts',
realname: 'walnuts',
@nlacasse
nlacasse / gist:730937
Created December 6, 2010 20:59
asyncFor(each)
exports.asyncFor = function (start, end, eachCallback, endCallback) {
var helper = function (i) {
if (i >= end) {
return process.nextTick(function () {endCallback();});
}
eachCallback(i);
process.nextTick(function () {helper (i+1);});
};
return helper(start);
<script id="message" type="text/html">
<div class="message {{ type }}" id="{{ cssID }}">
<time datetime="{{ time }}">{{ humanTime }}</time>
<span class="name {{#isYou}} current-user {{/isYou}}">
{{ author }}:
</span>
<span class="body">{{ content }}</span>
@nlacasse
nlacasse / htmlindex.html
Created January 19, 2012 01:54
simple chat example using spire.io.js library
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>CHAT</title>
<script src="/javascripts/lib/jquery.js"></script>
<script src="/javascripts/lib/jquery.scrollto.js"></script>
spire.subscribe('spire.io chat example', {orderBy: 'asc'}, function (messages) {
// We want the oldest message at the top.
messages.reverse();
$(messages).each(function(i, rawMessage){
var message = rawMessage.content
, date = new Date(rawMessage.timestamp)
, mentionedRegex = new RegExp([ '(^|\\s|\\t)'
, currentUser
, '(\\s|\\t|:|-|,|$)'
].join(''), 'gi')