Skip to content

Instantly share code, notes, and snippets.

@Lukewh
Lukewh / ReadyListener.js
Created August 6, 2012 12:04
Execute a function once all dependencies have run.
var ReadyListener = function(itemLength, fn){
this.itemLength = itemLength;
this.haveItems = 0;
this.fn = fn;
};
ReadyListener.prototype.add = function(name){
console.log(' '+name+': Ready');
this.haveItems++;
this.haveAllCheck();
@Lukewh
Lukewh / leafFlip.js
Created September 27, 2012 13:37
Emulate flipping with JS
/*
next = top half (hidden) (.topHalfNext from part 2)
current = top half (currently showing) (.topHalfCurrent from part 2)
main = main background item (also represents the bottom half) (.main from part 2)
title = updated title for the item
*/
// Set the next hidden item to the top and it's content to the updated display string
next.css({top: 0}).html(title);
@Lukewh
Lukewh / basicpool.js
Created October 16, 2012 10:07
Node.js sockets
// Create the http handler
var http = require('http');
// Set the http protocol to have 10 sockets
http.globalAgent.maxSockets = 10;
@Lukewh
Lukewh / getScrollWidth.js
Created October 24, 2012 15:04
Get the width / height of the browsers scroll bar
function getScrollWidth(){
// Create a div
var scrollEle = document.createElement("div"),
scrollWidth = 0;
// Set it's styling
scrollEle.style.width = "100px";
scrollEle.style.height = "100px";
scrollEle.style.overflow = "scroll";
scrollEle.style.position = "absolute";
@Lukewh
Lukewh / getTabs.js
Created November 27, 2012 14:07
chrome.tabs open function
var getTabs = function(urlMatch, callback) {
var tabs = [];
chrome.tabs.query({
status: 'complete'
}, function(results) {
for (var i = results.length; i--;) {
if (results[i].url.indexOf(urlMatch) !== -1) {
tabs.push(results[i].id);
}
@Lukewh
Lukewh / mbst_epg.html
Created November 28, 2012 17:14
MBST_EPG
<!-- Add this to the HEAD of the document -->
<script src="http://widgets.metabroadcast.com/loader/1/load.js"></script>
<script>
MBST = MBST || {};
MBST.load({
client: '*CLIENT*', // Replace this with the client name
widgets: [
{
name: 'epg',
version: '1'
function getXHR(url, callback) {
var xhr = new XMLHttpRequest(); // Creates a new XHR request
if (!url) {
throw new Error('No URL supplied');
}
xhr.open("GET", url, true); // Open the connection
xhr.setRequestHeader("Content-type",
@Lukewh
Lukewh / backgroundscript.js
Last active December 10, 2015 18:38
Message passing in Chrome extensions
chrome.extension.onMessage.addListener(
/*
request = payload
sender = information about the payload
sendResponse = function to send response to. Explanation above (1).
*/
function(request, sender, sendResponse){
var tabId = sender.tab.id, // Which tab is the query from?
isValid;
@Lukewh
Lukewh / config.json
Last active December 12, 2015 03:28
"epg": { // Widget name
"1": { // Major version
"minorVersion": 3,
"modules": { // Modules Object
"grid": { // grid Module
"holder": "#GRID", // Dom Element to insert grid into
"nav": { // Navigation configuration
"days": 8,
"showDates": true,
"showTime": true
@Lukewh
Lukewh / named-term.el
Created February 27, 2020 10:17
Simple script to name a term on open
(defun named-term (name)
(interactive "sName: ")
(command-execute 'term)
(if (not (string= 'name ""))
(rename-buffer name)
)
)