Skip to content

Instantly share code, notes, and snippets.

function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) {
return node.getElementsByClassName(classname);
} else {
document.getElementsByClassName = function( className, nodeName ) {
var result = [], tag = nodeName||'*', node, seek, i;
if( document.evaluate ) {
seek = '//'+ tag +'[@class="'+ className +'"]';
seek = document.evaluate( seek, document, null, 0, null );
while((node = seek.iterateNext())) {
@rich97
rich97 / game_node_server.js
Created July 19, 2011 13:04
Game node.js server for socket.io
// New connection
io.of('/game').sockets.on('connection', function(socket) {
// Login using the token sent to us from the client
socket.on('login', function(token) {
// New player requires a new player object
var player = new Player(token);
// We can only perform other options once the login has completed
player.login(function(player) {
// Remember the player on the socket
var util = {
list: function(variables, values, scope) {
for(var i = 0; i < variables.length && i < values.length; i++){
(scope || this)[variables[i]] = values[i];
}
}
};
// I don't like this:
/*
socket.on('answer', function(answer, fn) {
socket.get('game', function(ge, g) {
socket.get('score', function(se, score) {
*/
// this is much nicer, I could even make a function to keep it DRY
var test;
socket.get('socket_var', function(err, socket_variable) {
test = socket_variable;
// This is what v.next looks like: ["What is the nickname of Newcastle United?", Object { 7056f36f-43a1-4cca-8f6a-1766fc137cbd="The Birds", 61596ba8-ce83-47d2-a5d0-faed180e387a="The Seagulls", f8e95d46-4898-499d-b81c-2110a8583725="The Magpies"}]
var o = {};
console.log(v.next);
var next = v.next;
o.question = next[0];
o.answer = next[1];
/**
* next is undefined
// ...
function image(path, fn) {
$(new Image()).load(function() {
if (typeof fn === 'function') {
fn($(this));
}
})
.error(function () {
console.error('Unable to load image: ' + imgBasePath + path);
// SERVER
var gameSet = new GameSet();
var io = require('socket.io')
, express = require('express')
, app = express.createServer();
app.listen(8080);
var sio = io.listen(app);
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
<style type="text/css" media="screen">
#list {
list-style:none;
@rich97
rich97 / gist:1308837
Created October 24, 2011 11:43
CMS concept.

Introduction

Today’s CMS systems work by providing an environment for a developer to work in. You modify the data in the admin panel and them CMS provides a method of inserting the HTML it generates into your templates.

However, therein lies the problem -- the output is generated by the CMS. The CMS should exist to provide a user friendly abstraction to the websites dynamic content. It should not tell the frontend how to represent that content.

To anyone reading this, please be aware that any examples I give will be framed within the context of the MVC pattern and more specifically the Lithium PHP framework. Why? Because these are the tools I love to use at the time of writing this document, although there is no reason that this couldn’t be adapted.

Proposed solution

function handleFileSelect(event) {
// upload files
$uploadForm.submit();
var requestId = $('#uid').val();
setTimeout(function () {
updateProgress(requestId);
}, 10);
$feedback.fadeIn();