Skip to content

Instantly share code, notes, and snippets.

@klovadis
klovadis / gist:1292642
Created October 17, 2011 13:51
CSS display property on pseudo-classes bug in webkit
<html>
<head>
<title>...</title>
<style>
<!--
p {
border-left:4px solid #00FF00;
display:block;
<div id="navbar" class="navbar">
<ul id="navtabs" class="navtabs floatcontainer<vb:if condition="$show['member'] AND $notifications_total"> notify</vb:if>">
{vb:raw template_hook.navtab_start}
<vb:if condition="!$vboptions['selectednavtab'] AND THIS_SCRIPT != 'search'">
<li class="selected"><a class="navtab" href="{vb:link forumhome}">{vb:rawphrase forum}</a>
<ul class="floatcontainer">
{vb:raw template_hook.navbar_start}
<vb:if condition="$show['searchbuttons']">
<vb:if condition="$show['member']">
<li><a href="search.php?{vb:raw session.sessionurl}do=getnew&amp;contenttype=vBForum_Post">{vb:rawphrase new_posts_nav}</a></li>
@klovadis
klovadis / index.js
Created April 6, 2012 15:32
How to include all routes in a folder for express using node-walker
// include the express framework
var express = require('express');
// include the node-walker module
// -> npm install node-walker
var walker = require('node-walker');
// the express server instance
var app = express.createServer();
@klovadis
klovadis / gist:2548942
Created April 29, 2012 09:22
Typical node.js callback pattern
// include the filesystem module
var fs = require('fs');
// fs.readFile: read a file and all its contents,
// then call a callback function
fs.readFile('/some/file', function (err, contents) {
// if any error occurred, throw it
if (err) throw err;
@klovadis
klovadis / scope.js
Created May 28, 2012 12:06
Example of "this" within event listeners
// create EventEmitter instance
var myEventEmitter = new EventEmitter();
// attach a property
myEventEmitter.someVar = "some var";
// add event listener for "test"
myEventEmitter.on('test', function ()
console.log(this.someVar);
});
@klovadis
klovadis / gist:2818766
Created May 28, 2012 11:56
Code flow example of the EventEmitter
// create EventEmitter instance
var myEventEmitter = new EventEmitter();
// add event listener for "test"
myEventEmitter.on('test', function ()
console.log('2');
});
// the following code will output 1 2 3
console.log('1');
@klovadis
klovadis / gist:2549029
Created April 29, 2012 09:35
Short circuit function chains if an error occurs
var fs = require('fs');
// read a file
function read_the_file(filename, callback) {
// begin by reading a file
fs.readFile(filename, function (err, contents) {
// an error occurred, i.e. the file was not found.
// instead of throwing an error, skip the other
@klovadis
klovadis / gist:4108171
Created November 18, 2012 23:39
Example of synchroneous flow
var ee = new (require('events').EventEmitter)();
var foo;
// listener function
ee.on('test', function (newValue) {
foo = newValue;
});
// before emitting
foo = 'one';
@klovadis
klovadis / robot.js
Created December 5, 2012 14:10 — forked from Shipow/robot.js
Shipow#001
var Robot = function(robot) {
robot.rotateCannon(-90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead();
//i'll add a clone but i need to refactor collision
//robot.clone();
};
@klovadis
klovadis / index.js
Created February 19, 2013 18:04
A basic webserver using the connect framework.
// to install the connect framework, go to your applications directory
// and type "npm install connect" in your command prompt.
// to launch the webserver, place this file in your application
// directory and execute it using "node index.js"
var connect = require('connect')
, app = connect()
, webserver = require('http').createServer(app);