Skip to content

Commit e27d66e

Browse files
committed
.
1 parent 9842811 commit e27d66e

File tree

2,481 files changed

+176210
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,481 files changed

+176210
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Title: Basic Node Example
3+
* Description: Simple file that declares a few functions and invokes them.
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// Dependencies
11+
var mathLib = require('./lib/math');
12+
var jokesLib = require('./lib/jokes');
13+
14+
15+
// App object
16+
var app = {};
17+
18+
19+
// Configuration
20+
app.config = {
21+
'timeBetweenJokes' : 1000
22+
};
23+
24+
25+
// Function that prints a random joke
26+
app.printAJoke = function(){
27+
28+
// Get all the jokes
29+
var allJokes = jokesLib.allJokes();
30+
31+
// Get the length of the jokes
32+
var numberOfJokes = allJokes.length;
33+
34+
// Pick a random number between 1 and the number of jokes
35+
var randomNumber = mathLib.getRandomNumber(1,numberOfJokes);
36+
37+
// Get the joke at that position in the array (minus one)
38+
var selectedJoke = allJokes[randomNumber - 1];
39+
40+
// Send the joke to the console
41+
console.log(selectedJoke);
42+
};
43+
44+
45+
// Function that loops indefinitely, calling the printAJoke function as it goes
46+
app.indefiniteLoop = function(){
47+
48+
// Create the interval, using the config variable defined above
49+
setInterval(app.printAJoke,app.config.timeBetweenJokes);
50+
};
51+
52+
53+
// Invoke the loop
54+
app.indefiniteLoop();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Title: Jokes Library
3+
* Description: Utility library for getting a list of Jokes
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// Dependencies
11+
var fs = require('fs');
12+
13+
// App object
14+
var jokes = {};
15+
16+
// Get all the jokes and return them to the user
17+
jokes.allJokes = function(){
18+
19+
// Read the text file containing the jokes
20+
var fileContents = fs.readFileSync(__dirname+'/jokes.txt', 'utf8');
21+
22+
// Turn the string into an array
23+
var arrayOfJokes = fileContents.split(/\r?\n/);
24+
25+
// Return the array
26+
return arrayOfJokes;
27+
28+
};
29+
30+
// Export the library
31+
module.exports = jokes;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Why should you avoid the duck psychologist? He's a quack.
2+
What do cows do in their spare time? Go to the moooovies.
3+
Why do birds hate Instagram? They prefer to tweet.
4+
Where do fish keep all their money? The river bank.
5+
Why did the sheep get detention? It was baaaaaad.
6+
Why couldn't the horse congress pass any bills? They all kept voting naaaaaay.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Title: Math Library
3+
* Description: Utility library for math-related functions
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// App object
11+
var math = {};
12+
13+
// Get a random integer between two integers
14+
// Inspired by: http://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript
15+
math.getRandomNumber = function(min,max){
16+
min = typeof(min) == 'number' && min % 1 === 0 ? min : 0;
17+
max = typeof(max) == 'number' && max % 1 === 0 ? max : 0;
18+
return Math.floor(Math.random()*(max-min+1)+min);
19+
};
20+
21+
22+
// Export the library
23+
module.exports = math;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//registry.npmjs.org/:_authToken=xxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxxxxxx
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Title: Basic Node Example
3+
* Description: Simple file that declares a few functions and invokes them.
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// Dependencies
11+
var mathLib = require('./lib/math');
12+
var jokesLib = require('./lib/jokes');
13+
14+
15+
// App object
16+
var app = {};
17+
18+
19+
// Configuration
20+
app.config = {
21+
'timeBetweenJokes' : 1000
22+
};
23+
24+
25+
// Function that prints a random joke
26+
app.printAJoke = function(){
27+
28+
// Get all the jokes
29+
var allJokes = jokesLib.allJokes();
30+
31+
// Get the length of the jokes
32+
var numberOfJokes = allJokes.length;
33+
34+
// Pick a random number between 1 and the number of jokes
35+
var randomNumber = mathLib.getRandomNumber(1,numberOfJokes);
36+
37+
// Get the joke at that position in the array (minus one)
38+
var selectedJoke = allJokes[randomNumber - 1];
39+
40+
// Send the joke to the console
41+
console.log(selectedJoke);
42+
};
43+
44+
45+
// Function that loops indefinitely, calling the printAJoke function as it goes
46+
app.indefiniteLoop = function(){
47+
48+
// Create the interval, using the config variable defined above
49+
setInterval(app.printAJoke,app.config.timeBetweenJokes);
50+
};
51+
52+
53+
// Invoke the loop
54+
app.indefiniteLoop();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Title: Jokes Library
3+
* Description: Utility library for getting a list of Jokes
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// Dependencies
11+
var fs = require('fs');
12+
13+
// App object
14+
var jokes = {};
15+
16+
// Get all the jokes and return them to the user
17+
jokes.allJokes = function(){
18+
19+
// Read the text file containing the jokes
20+
var fileContents = fs.readFileSync(__dirname+'/jokes.txt', 'utf8');
21+
22+
// Turn the string into an array
23+
var arrayOfJokes = fileContents.split(/\r?\n/);
24+
25+
// Return the array
26+
return arrayOfJokes;
27+
28+
};
29+
30+
// Export the library
31+
module.exports = jokes;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Why should you avoid the duck psychologist? He's a quack.
2+
What do cows do in their spare time? Go to the moooovies.
3+
Why do birds hate Instagram? They prefer to tweet.
4+
Where do fish keep all their money? The river bank.
5+
Why did the sheep get detention? It was baaaaaad.
6+
Why couldn't the horse congress pass any bills? They all kept voting naaaaaay.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Title: Math Library
3+
* Description: Utility library for math-related functions
4+
* Author: Leslie Lewis
5+
* Date: 10/24/17
6+
*
7+
*/
8+
9+
10+
// App object
11+
var math = {};
12+
13+
// Get a random integer between two integers
14+
// Inspired by: http://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript
15+
math.getRandomNumber = function(min,max){
16+
min = typeof(min) == 'number' && min % 1 === 0 ? min : 0;
17+
max = typeof(max) == 'number' && max % 1 === 0 ? max : 0;
18+
return Math.floor(Math.random()*(max-min+1)+min);
19+
};
20+
21+
22+
// Export the library
23+
module.exports = math;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "basicExample",
3+
"version": "0.0.1",
4+
"license": "UNLICENSED",
5+
"private": "true",
6+
"description": "Simple file that declares a few functions and invokes them",
7+
"main": "index.js",
8+
"scripts": {
9+
"start": "node index.js"
10+
},
11+
"dependencies": {
12+
"jokes" : "0.1.3"
13+
}
14+
}

0 commit comments

Comments
 (0)