Skip to content

Instantly share code, notes, and snippets.

// http://stackoverflow.com/questions/10058226/send-response-to-all-clients-except-sender-socket-io
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
@ralucas
ralucas / index.html
Created December 14, 2013 18:19
Pace Calculator in Javascript and jQuery http://ralucas.github.io/pacecalculator/
<!DOCTYPE HTML>
<html>
<head>
<title>Quick Pace Calculator</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="wrapper">
@ralucas
ralucas / dollars-to-english
Created December 17, 2013 22:22
Converts input of number to english description
/**
Write some code that will accept an amount and convert it to the appropriate
string representation.
Example: Convert 2523.04
to "Two thousand five hundred twenty-three and 04/100 dollars"
**/
var numbers = {
0 : "zero",
1 : "one",
@ralucas
ralucas / Console_globals_fn
Last active January 2, 2016 17:59
Quick function to show all globals available from the console.
for(var b in window) {
if(window.hasOwnProperty(b)) console.log(b);
}

Topic Ideas for Node.js Denver/Boulder Meetup

  1. Using Grunt and Gulp
  2. Promises and Q and async libraries
  3. Optimizing your app (i.e. clustering, api design, etc.)
  4. Express framework (incl. Jade and Stylus)
  5. Deployment to Heroku including config setup, add-ons, forking, etc.
  6. Mocha and Chai and testing
  7. Understanding analytics - possible sponsorship from New Relic
/*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
var dbg = (typeof console !== 'undefined') ? function(s) {
console.log("Readability: " + s);
} : function() {};
/*
* Readability. An Arc90 Lab Experiment.
* Website: http://lab.arc90.com/experiments/readability
'use strict';
var winston = require('winston'),
util = require('util');
//winston logging for papertrail
require('winston-papertrail').Papertrail;
var logger;
@ralucas
ralucas / useful_regex.js
Created August 5, 2014 17:11
Useful regexes
// Take out multiple spaces and replace with single space
// i.e. "And the dog went on a walk" becomes "And the dog went on a walk"
string = string.replace(/\s{2,}/g, ' ');
@ralucas
ralucas / cors-access-control
Last active August 29, 2015 14:05
Allowing access control in Node.js
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
@ralucas
ralucas / auth.js
Last active August 29, 2015 14:05
Setting up basic aut
var basicAuth = require('basic-auth'),
dotenv = require('dotenv');
dotenv.load();
var username = process.env.ADMIN_USERNAME,
password = process.env.ADMIN_PASSWORD;
module.exports = function (req, res, next) {
function unauthorized(res) {