This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
// In your app.js, include a route handler for all other routes (*) to go to error404. | |
// app.get('*', error.error404); | |
exports.error404 = function(req, res) { | |
if (req.accepts('html')) { | |
// Respond with html page. | |
fs.readFile(__dirname + '/../../public/404/index.html', 'utf-8', function(err, page) { | |
res.writeHead(404, {'Content-Type': 'text/html'}); | |
res.write(page); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
funnyPlant <- function(people, plants) { | |
fruit <- 0 | |
weeks <- 1 | |
while (fruit < people) { | |
fruit <- fruit + plants | |
plants <- plants + fruit | |
weeks <- weeks + 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# https://www.reddit.com/r/dailyprogrammer/comments/3uuhdk/20151130_challenge_243_easy_abundant_and/ | |
# | |
divisors <- function(x){ | |
# Vector of numberes to test against | |
y <- seq_len(x) | |
# Modulo division. If remainder is 0 that number is a divisor of x so return it | |
y[ x%%y == 0 ] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.reddit.com/r/dailyprogrammer/comments/3v4zsf/20151202_challenge_243_intermediate_jennys_fruit/ | |
require(plyr) | |
data <- read.csv('input2.txt', sep = ' ', header = FALSE, col.names = c('name', 'price')) | |
money <- 500 | |
orders <- data.frame() | |
for (i in seq(from=1, to=6)) { | |
print(paste('Level', i)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.reddit.com/r/dailyprogrammer/comments/3x3hqa/20151216_challenge_245_intermediate_ggggggg_gggg/ | |
# Builds a key/value dictionary. | |
load <- function(input, valuesAsKeys = FALSE) { | |
# Read first line of input. | |
key <- unlist(strsplit(input, '\n'))[1] | |
# Split tokens by space. | |
keys <- unlist(strsplit(key, ' ')) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(caret) | |
# Generate 50 random numbers uniformly distributed between 0 and 100. | |
training <- data.frame(x = runif(50, min=0, max=100)) | |
training$y <- sqrt(training$x) | |
# Generate some squared numbers. | |
cv <- data.frame(x = (1:10)^2) | |
cv$y <- sqrt(cv$x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See also https://gist.github.com/primaryobjects/3b41f8b2f122eb16a65b | |
library(neuralnet) | |
library(ggplot2) | |
library(reshape2) | |
# Helper method to generate a training set containing size random numbers (a, b, c) and sorted (x, y, z). | |
generateSet <- function(size = 100, max = 100) { | |
# Generate size random numbers between 1 and max. | |
training <- data.frame(a=sample(1:max, size, replace=TRUE), | |
b=sample(1:max, size, replace=TRUE), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See also https://gist.github.com/primaryobjects/5a28e0c27fd433123f1a | |
# fit: Trained neural network. scaleVal: Original scaled data used in training the network. a, b, c: Numbers to sort. | |
nnsort <- function(fit, scaleVal, a, b, c) { | |
numbers <- data.frame(a=a, b=b, c=c, x=0, y=0, z=0) | |
numbersScaled <- as.data.frame(scale(numbers, attr(scaleVal, 'scaled:center'), attr(scaleVal, 'scaled:scale'))) | |
round(unscale(compute(fit, numbersScaled[,1:3])$net.result, scaleVal))[,4:6] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(neuralnet) | |
# Helper method to generate a training set containing size random numbers (a, b, c) and sorted (x, y, z). | |
generateSet <- function(size = 100, max = 100) { | |
# Generate size random numbers between 1 and max. | |
training <- data.frame(a=sample(1:max, size, replace=TRUE), | |
b=sample(1:max, size, replace=TRUE), | |
c=sample(1:max, size, replace=TRUE)) | |
# Generate output examples by sorting the numbers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See also https://gist.github.com/primaryobjects/3b41f8b2f122eb16a65b | |
library(neuralnet) | |
library(ggplot2) | |
library(reshape2) | |
# Helper method to generate a training set containing size random numbers (a, b, c) and sorted (x, y, z). | |
generateSet <- function(size = 100, max = 100) { | |
# Generate size random numbers between 1 and max. | |
training <- data.frame(a=sample(1:max, size, replace=TRUE), | |
b=sample(1:max, size, replace=TRUE), |