Permalink
Browse files

Merge branch 'improve-code'

  • Loading branch information...
2 parents 1b4add1 + 5214e82 commit 2c82b6b81b4772d73f7278791021431e60c54c28 @fhd committed Apr 17, 2012
Showing 365 changed files with 30,516 additions and 831 deletions.
View
@@ -10,13 +10,9 @@ This is still work in progress.
Running
-------
-To run Algorithms, first get [node.js](http://nodejs.org/) and
-[npm](http://npmjs.org/) and then execute the following:
+To run Algorithms, just get [node.js](http://nodejs.org/) and execute
+the following:
- npm install express jade
+ node app
-Now you can run the server like this:
-
- node server.js
-
-And finally, point your browser to: [http://localhost:10605](http://localhost:10605)
+Then point your browser to: [http://localhost:3000](http://localhost:3000).
View
@@ -1,7 +1,6 @@
- Implement non-comparison sort algorithms (e.g. counting sort)
- Implement selection problem alrogithms (randomized select and select)
- Implement data structures
- - Linked List
+ - Linked List (variant with sentinels instead of the current one)
- Hash Map
- Binary Tree
-
View
40 app.js
@@ -0,0 +1,40 @@
+var algorithms = require("./lib/algorithms.js"),
+ express = require("express"),
+ app = module.exports = express.createServer(),
+ fs = require("fs");
+
+app.configure(function() {
+ app.set("views", __dirname + "/views");
+ app.set("view engine", "jade");
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + "/public"));
+});
+
+app.configure("development", function() {
+ app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
+});
+
+app.configure("production", function() {
+ app.use(express.errorHandler());
+});
+
+app.get("/", function(req, res) {
+ res.render("index", {"categories": algorithms.categories});
+});
+
+app.get("/:algorithm", function(req, res) {
+ var algorithm = algorithms.algorithms[req.params.algorithm];
+ if (algorithm) {
+ algorithm.code = fs.readFileSync("public/js/" + algorithm.category
+ + "/" + algorithm.file);
+ res.render(algorithm.category, {
+ currentAlgorithm: algorithm,
+ "categories": algorithms.categories
+ });
+ } else
+ res.send(404);
+});
+
+app.listen(3000);
@@ -59,63 +59,31 @@ var categories = {
}
}
}
-}
+};
-var algorithms = {};
+function createAlgorithms() {
+ var algorithms = {};
-Object.keys(categories).forEach(function (categoryKey) {
- var category = categories[categoryKey];
- Object.keys(category.algorithms).forEach(function(algorithmKey) {
- var algorithm = category.algorithms[algorithmKey];
- algorithm.category = categoryKey;
- algorithms[algorithmKey] = algorithm;
+ Object.keys(categories).forEach(function (categoryKey) {
+ var category = categories[categoryKey];
+ Object.keys(category.algorithms).forEach(function(algorithmKey) {
+ var algorithm = category.algorithms[algorithmKey];
+ algorithm.category = categoryKey;
+ algorithms[algorithmKey] = algorithm;
+ });
});
-});
-
-Object.keys(algorithms).forEach(function (key) {
- var value = algorithms[key];
- value.file = key + ".js";
- value.functionName = key;
- value.url = "/" + key;
-});
-
-var express = require("express"),
- app = module.exports = express.createServer();
-
-app.configure(function() {
- app.set("views", __dirname + "/views");
- app.set("view engine", "jade");
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(__dirname + "/public"));
-});
-
-app.configure("development", function() {
- app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
-});
-app.configure("production", function() {
- app.use(express.errorHandler());
-});
-
-app.get("/", function(req, res) {
- res.render("index", {"categories": categories});
-});
-
-var fs = require("fs");
+ Object.keys(algorithms).forEach(function (key) {
+ var value = algorithms[key];
+ value.file = key + ".js";
+ value.functionName = key;
+ value.url = "/" + key;
+ });
-app.get("/:algorithm", function(req, res) {
- var algorithm = algorithms[req.params.algorithm];
- if (algorithm) {
- algorithm.code = fs.readFileSync("public/js/" + algorithm.category
- + "/" + algorithm.file);
- res.render(algorithm.category, {
- currentAlgorithm: algorithm,
- "categories": categories
- });
- } else
- res.send(404);
-});
+ return algorithms;
+}
-app.listen(10605);
+module.exports = {
+ categories: categories,
+ algorithms: createAlgorithms()
+};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 2c82b6b

Please sign in to comment.