Skip to content

Commit 12bdfbf

Browse files
committed
set up file structure
1 parent 70781e5 commit 12bdfbf

Some content is hidden

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

44 files changed

+2547
-1
lines changed

.config/install.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
var
6+
fs = require('fs'),
7+
exec = require('child_process').exec;
8+
9+
function cloneNotes(complete) {
10+
var cmd = 'git clone https://github.com/OperationSpark/notes-bootcamp.git notes';
11+
var child = exec(cmd, function (err, stdout, stderr) {
12+
if (err) { return complete(err); }
13+
console.log('Successfully cloned notes!');
14+
complete();
15+
});
16+
}
17+
18+
function removeGitRemnants(complete) {
19+
var dir = 'notes/';
20+
var gitignore = dir + '.gitignore';
21+
if (fs.existsSync(gitignore)) { fs.unlinkSync(gitignore); }
22+
removeDirectoryRecursively(dir + '.git', complete);
23+
}
24+
25+
function removeDirectoryRecursively(path, complete) {
26+
var cmd = 'rm -r ' + path;
27+
var child = exec(cmd, function (err, stdout, stderr) {
28+
if (err) { return complete(err); }
29+
console.log('Successfully removed ' + path + '!');
30+
complete();
31+
});
32+
}
33+
34+
if (fs.existsSync('notes')) {
35+
try{
36+
console.log('Removing old notes...');
37+
removeDirectoryRecursively('notes', function(err) {
38+
if(err) { console.log(err); }
39+
install();
40+
});
41+
} catch (err) {
42+
console.log(err);
43+
}
44+
} else {
45+
install();
46+
}
47+
48+
function install() {
49+
cloneNotes(function (err) {
50+
if (err) { return console.log(err); }
51+
removeGitRemnants(function (err) {
52+
if (err) { return console.log(err); }
53+
console.log('All done, bye!');
54+
});
55+
});
56+
}

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
loglevel=silent

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: node_js
2+
node_js:
3+
- "4.0"
4+
5+
notifications:
6+
email:
7+
8+
9+
slack: operationspark:IVZ9qgp3Ge6RTeSl7nftvktM
10+
webhooks: https://greenlight.operationspark.org/api/webhooks/travisci
11+

README.md

+101-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,101 @@
1-
# scratch-pad.github.io
1+
# scratch-pad.github.io
2+
3+
# Scratch Pad
4+
5+
Practice the basics of JavaScript by passing unit tests.
6+
7+
---
8+
9+
## Getting Started
10+
11+
1. To install Scratch-Pad into your workspace you can use our `opspark` utility! You should already have this installed, but you can make sure by running this script in your terminal:
12+
13+
```
14+
npm install --global opspark
15+
```
16+
17+
* As long as we have the `opspark` utility installed, we can install projects into our workspace! To do that, run the following command in your terminal:
18+
19+
```
20+
os install
21+
```
22+
23+
* You may have to sign in with GitHub, so make sure you know your login information!
24+
25+
* You will then be prompted for your class, so select whichever class you are currently taking.
26+
27+
* Then scroll through the available projects with your arrow keys and select `Scratch Pad`. Hit enter, confirm, and `opspark` will do its magic!
28+
29+
2. Once you have Scratch-Pad installed it should appear inside your `projects` directory. Open the Scratch-Pad directory and take a look at the files inside.
30+
31+
* It's important that you **do not move, or change the name of, any files in these directories**. If you do the tests we have written may not work, and you will have a lot of problems we'll have to solve!
32+
33+
* Inside the Scratch-Pad directory you should have several folders prefixed with `day-x`. Each of these folders correspond to one of the four days we will work on Scratch-Pad, with the `x` representing the specific day. If you open up `day-1` you will see that we have a `homework` directory, an `index.html`, and several `.js` files.
34+
35+
* If you **open and run the `index.html` file of `day-1`**, you can SEE what tests we have written for the day, and whether you are passing or failing those tests! You can run files by hitting the big "Run" button at the top of your workspace. Make sure you have the file you want to run selected!
36+
37+
* Our work is going to be done in the `.js` files, like `stringy.js` and `my-first-test.js`. A `.js` file is a JavaScript file, which is the language we are mainly learning in this course. Inside these JavaScript files we will be creating code that fulfills certain tests we have already created.
38+
39+
---
40+
41+
## app.js
42+
43+
The `app.js` file is an executable JavaScript file, a template for you to write and test JavaScript in the node.js environment.
44+
45+
You can execute the `app.js` file in Cloud9 by opening it and clicking the green "Run" button - this will allow you to use breakpoints on the file and debug and step-thru your code, which is very handy for understanding complex algorithms, especially higher order functions.
46+
47+
You can also execute the `app.js` file from the command line: if you're in the same directory as the app.js file, simply run the command:
48+
49+
```
50+
./app.js.
51+
```
52+
53+
You can duplicate this file and rename it to represent whatever other studies you're undertaking to better organize your notes, ie, `strings.js`, or, `recursion.js`, or, `functions.js`, etc.
54+
55+
Note, at the top of the `app.js` file, there's the <a href="https://github.com/OperationSpark/javascript-wiki/wiki/Shebang" target="_blank">linux shebang for the node binary</a>. Always leave this at the top of the file. This tells the operating system where to look for the program that should run your file, in this case, where to find node.
56+
57+
Also, below the shebang, note the `'use strict';` directive - this tells node we want to run our JavaScript in strict mode, which, among other things, will prevent our program from silently failing on certain errors. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode" target="_blank">Read more about strict mode here...</a>
58+
59+
---
60+
61+
## Getting Started with Debugging
62+
63+
Beyond cloud storage, and ease of sharing, one of the main reasons we start students off using Cloud9, and writing and submitting homework in the Scratch-Pad project, is that Cloud9 has a good debugger.
64+
65+
It is extremely important for you to begin debugging as you work. It's important to make use of `console.log(someValue);` to print expected values to the console and inspect your work. It is also highly valuable to get use to using breakpoints and the debugging tools of Cloud9 (and any other IDE you choose to use in the future)
66+
67+
<a href="https://docs.c9.io/docs/debugging-your-code" target="_blank">Watch this video on getting started with Node.js debugging in Cloud9</a>. This is how you should inspect your work in Scratch-Pad as you complete your homework assignments.
68+
69+
---
70+
71+
## Homework
72+
73+
Your homework assignments are located in JavaScript (.js) files in the directory `homework` of whichever day you are on.
74+
75+
---
76+
77+
### Checking your Code
78+
79+
As you code your solutions and save your work, you have four options for checking your code:
80+
81+
1. In the top level of the `Scratch-Pad` directory there is an `index.html` file. You can run this file to see ALL the tests we will be completing in this project!
82+
83+
2. In each `day-x` directory there is an `index.html` file. Running this file will run all the unit tests _only_ for that day.
84+
85+
3. In your terminal you can test your code using the `opspark` client. To do so, run the command `os test`.
86+
87+
4. To use the debugger and breakpoints and _step thru_ your code, you can run your code by **having the file selected in the text-editor** and clicking the green **Run** button. This will open up a new process in the console view that will output your log statements. Breakpoints will be caught by the debugger and you can step through and inspect your code at runtime.
88+
89+
**TIP** It's important to note the difference between running `.js` files and `.html` files! JavaScript can do a bunch of awesome things, as you will see. Running a `.js` file means you are having each line of JavaScript code in the file run, one by one, from top to bottom. What it will NOT do is create a web page for you. In c9, running a `.js` file results in a new tab that shows everything that is console.logged in that file.
90+
91+
If you want to see an actual web page, you should run an `.html` file. Anything with the suffix `.html` is going to be HTML, or Hypertext Markup Language. HTML is like the skeleton of a website, it is the structure, so when you want to see a visualization of something you use HTML. It's possible for HTML to access your JavaScript files and run them inside the website, which we will play with more later in the course.
92+
93+
---
94+
95+
### Submitting Scratch-Pad
96+
97+
You must submit the Scratch-Pad project by running `os submit`. Doing so will re-run the tests one last time to make sure you are passing all of them, then send the results to Greenlight if you have passed all tests.
98+
99+
**You must pass ALL the tests for EACH day to get a green light.**
100+
101+
If you do not have a green light when you submit, run `os test` to check if you are failing any tests. If you have any questions after that, consult your teacher.

app.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
var greeting = 'Welcome to Operation Spark';
6+
console.log(greeting);

day-1/homework/reverse-string.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// #!/usr/bin/env node
2+
3+
'use strict';
4+
5+
/**
6+
* 1: reverseString()
7+
*
8+
* a. Create a function called reverseString that takes a
9+
* String as its only input and returns a new String
10+
* representing the input String reversed. For example:
11+
*
12+
* reverseString('hello'); // => 'olleh'
13+
*
14+
* TIPS:
15+
* a. create something to collect the output you'll return.
16+
* b. you'll need a loop, which one is best? How do you know
17+
* when to stop looping?
18+
* c. how do you access individual characters of a String?
19+
* d. how do you concatenate Strings? What operator do we use?
20+
*/
21+
22+
function reverseString(input) {
23+
// YOUR CODE GOES BELOW HERE //
24+
25+
26+
27+
28+
// YOUR CODE GOES ABOVE HERE //
29+
}
30+
31+
32+
33+
34+
// DON'T REMOVE THIS CODE //////////////////////////////////////////////////////
35+
if (
36+
typeof process !== "undefined" &&
37+
typeof process.versions.node !== "undefined"
38+
) {
39+
// here, export any references you need for tests //
40+
module.exports.reverseString = reverseString;
41+
}

day-1/index.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Mocha Spec Runner</title>
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.3/mocha.min.css">
8+
</head>
9+
<body>
10+
<div id="mocha"></div>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.5.3/mocha.min.js"></script>
12+
<script>mocha.setup('')</script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js"></script>
14+
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.4.0/lodash.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.0.0/sinon.min.js"></script>
16+
<script>
17+
var assert = chai.assert;
18+
var expect = chai.expect;
19+
var should = chai.should();
20+
</script>
21+
22+
<!-- include source files here... -->
23+
<script src="my-first-test.js"></script>
24+
<script src="stringy.js"></script>
25+
<script src="homework/reverse-string.js"></script>
26+
27+
<!-- include spec files here... -->
28+
<script src="../spec/my-first-test.spec.js"></script>
29+
<script src="../spec/stringy.spec.js"></script>
30+
<script src="../spec/reverse-string.spec.js"></script>
31+
32+
<script>mocha.run()</script>
33+
</body>
34+
</html>

day-1/my-first-test.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// #!/usr/bin/env node
2+
3+
'use strict';
4+
5+
/**
6+
* IN CLASS EXERCISE: MY FIRST TEST
7+
*
8+
* The point of this little exercise is to get you familar with how we role with
9+
* working on and submitting assignments. You'll code, save, and check the tests.
10+
* You can preview the index html file to see all the tests that are currently passing
11+
* or failing. Save your code and hit the refresh button to see the current failing
12+
* or passing test update.
13+
*/
14+
15+
/**
16+
* Given an input value, print the value to the screen using console.log().
17+
*/
18+
function print(value) {
19+
// YOUR CODE BELOW HERE //
20+
21+
22+
// YOUR CODE ABOVE HERE //
23+
}
24+
25+
26+
27+
28+
29+
30+
// DON'T REMOVE THIS CODE //////////////////////////////////////////////////////
31+
if((typeof process !== 'undefined') &&
32+
(typeof process.versions.node !== 'undefined')) {
33+
// here, export any references you need for tests //
34+
module.exports.print = print;
35+
}

0 commit comments

Comments
 (0)