Skip to content

Instantly share code, notes, and snippets.

View having-fun-coding's full-sized avatar

Jeffrey Collins having-fun-coding

View GitHub Profile
<script src="/socket.io/socket.io.js"></script>
<script>
var server = io.connect('http://localhost:8080');
server.on('question', function(question) {
insertQuestion(question);
});
server.on('answer', function(question, answer) {
answerQuestion(question, answer);
@having-fun-coding
having-fun-coding / ReadMe.md
Created May 26, 2015 19:01
Code School | Building Blocks of Express | 5.2 Route Instance

Let's rewrite our cities routes using a Route Instance.

@having-fun-coding
having-fun-coding / readMe
Created May 24, 2015 17:09
3.9 Dynamic Routes III
The following code has a Dynamic Route that takes a year
as an argument and returns the city created in that year.
The problem with our current implementation is that it
breaks when invalid data is sent on client requests.
Let's add some basic validation.
@having-fun-coding
having-fun-coding / limitingquestions.js
Created May 20, 2015 18:48
Limiting Questions Stored | Real Time Web with Node.js
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var redis = require('redis');
var redisClient = redis.createClient();
io.sockets.on('connection', function(client) {
redisClient.lrange("questions", 0, -1, function(err, questions) {
@having-fun-coding
having-fun-coding / readMe.txt
Last active August 29, 2015 14:21
Real Time Web with Node.js | 6.7 Answering Questions
Clients can also answer each other's questions,
so let's build that feature by first listening for
the 'answer' event on the client, which will send us
both the question and answer, which we want to broadcast
out to the rest of the connected clients.
@having-fun-coding
having-fun-coding / app.js
Created May 20, 2015 00:02
Real Time Web | Express Server | Code School
var url = require('url');
var request = require('request');
var express = require('express');
var options = {
protocol: "http:",
host: "search.twitter.com",
pathname: '/search.json',
query: {
q: "codeschool"
}
@having-fun-coding
having-fun-coding / readMe.txt
Created May 18, 2015 21:51
My First Async I/O | Nodeserver | Cloud9
var fs = require('fs');
var path = process.argv[2];
fs.readFile(path, 'utf8', function(err,data) {
var lines = data.split('\n');
console.log(lines.length-1);
});
@having-fun-coding
having-fun-coding / readMe.txt
Created May 18, 2015 21:41
Nodeserver | Cloud 9 | FILTERED LS
var fs = require('fs');
var path = require('path');
var mydir = process.argv[2];
var ext1 = '.' + process.argv[3];
fs.readdir(mydir, function(err, files){
if(err){
throw err;
}
//console.log(files);
files.forEach(function(filename){
var fs = require('fs');
var thefile = process.argv[2];
var file = fs.readFileSync(thefile);
var contents = file.toString();
console.log(contents.split('\n').length - 1);
@having-fun-coding
having-fun-coding / gist:2542990b8a6d08435d0b
Created May 18, 2015 19:26
Baby Steps | Node Program
function plus(x,y) { return x+y };
console.log(process.argv.slice(2).map(Number).reduce(plus));