From 6e2c8b5873ad8a8484e3d6497bc307b47ce46782 Mon Sep 17 00:00:00 2001 From: Lasher09 Date: Sun, 9 Mar 2014 22:58:56 +0000 Subject: [PATCH 1/8] played with the pipes files --- pipes/README.md | 482 ++++++++++++++++++++++++++++++++++++ pipes/molecules/cubane.pdb | 20 ++ pipes/molecules/ethane.pdb | 12 + pipes/molecules/methane.pdb | 9 + pipes/molecules/octane.pdb | 30 +++ pipes/molecules/pentane.pdb | 21 ++ pipes/molecules/propane.pdb | 15 ++ 7 files changed, 589 insertions(+) create mode 100644 pipes/README.md create mode 100644 pipes/molecules/cubane.pdb create mode 100644 pipes/molecules/ethane.pdb create mode 100644 pipes/molecules/methane.pdb create mode 100644 pipes/molecules/octane.pdb create mode 100644 pipes/molecules/pentane.pdb create mode 100644 pipes/molecules/propane.pdb diff --git a/pipes/README.md b/pipes/README.md new file mode 100644 index 0000000..b219313 --- /dev/null +++ b/pipes/README.md @@ -0,0 +1,482 @@ +Pipes Exercise - INLS 560 +========================= + +**Attribtution: this exercise was adapted from [Software Carpentry bootcamps](https://github.com/swcarpentry/bc) under a CC-BY license** + +Complete the exercise below before the end of Spring Break. If you need extra help, use your resources, including [this extra material](http://software-carpentry.org/v5/novice/shell/index.html) from Software Carpentry. + +## What to turn in + +* A pull request containing a correctly formatted post **that you have previewed on Nitrous** +* In the post, describe your process working through this exercise +* Include answers to the five challenges at the bottom of this page + +
+ +#### Objectives + +* Redirect a command's output to a file. +* Process a file instead of keyboard input using redirection. +* Construct command pipelines with two or more stages. +* Explain what usually happens if a program or pipeline isn't given any input to process. +* Explain Unix's "small pieces, loosely joined" philosophy. + +
+ +Now that we know a few basic commands, +we can finally look at the shell's most powerful feature: +the ease with which it lets us combine existing programs in new ways. + +First, clone the project repo and change directories into it.: + +``` +git clone https://github.com/silshack/pipes.git +cd pipes +``` + +We'll start with a directory called `molecules` +that contains six files describing some simple organic molecules. +The `.pdb` extension indicates that these files are in Protein Data Bank format, +a simple text format that specifies the type and position of each atom in the molecule. + +~~~ +$ ls molecules +cubane.pdb ethane.pdb methane.pdb +octane.pdb pentane.pdb propane.pdb +~~~ + +Let's go into that directory with `cd` and run the command `wc *.pdb`. +`wc` is the "word count" command: +it counts the number of lines, words, and characters in files. +The `*` in `*.pdb` matches zero or more characters, +so the shell turns `*.pdb` into a complete list of `.pdb` files: + +~~~ +$ cd molecules +$ wc *.pdb + 20 156 1158 cubane.pdb + 12 84 622 ethane.pdb + 9 57 422 methane.pdb + 30 246 1828 octane.pdb + 21 165 1226 pentane.pdb + 15 111 825 propane.pdb + 107 819 6081 total +~~~ + +> #### Wildcards +> +> `*` is a [wildcard](http://software-carpentry.org/v5//gloss.html#wildcard). It matches zero or more +> characters, so `*.pdb` matches `ethane.pdb`, `propane.pdb`, and so on. +> On the other hand, `p*.pdb` only matches `pentane.pdb` and +> `propane.pdb`, because the 'p' at the front only matches itself. +> +> `?` is also a wildcard, but it only matches a single character. This +> means that `p?.pdb` matches `pi.pdb` or `p5.pdb`, but not `propane.pdb`. +> We can use any number of wildcards at a time: for example, `p*.p?*` +> matches anything that starts with a 'p' and ends with '.', 'p', and at +> least one more character (since the '?' has to match one character, and +> the final '\*' can match any number of characters). Thus, `p*.p?*` would +> match `preferred.practice`, and even `p.pi` (since the first '\*' can +> match no characters at all), but not `quality.practice` (doesn't start +> with 'p') or `preferred.p` (there isn't at least one character after the +> '.p'). +> +> When the shell sees a wildcard, it expands the wildcard to create a +> list of matching filenames *before* running the command that was +> asked for. This means that commands like `wc` and `ls` never see +> the wildcard characters, just what those wildcards matched. This is +> another example of orthogonal design. + +If we run `wc -l` instead of just `wc`, +the output shows only the number of lines per file: + +~~~ +$ wc -l *.pdb + 20 cubane.pdb + 12 ethane.pdb + 9 methane.pdb + 30 octane.pdb + 21 pentane.pdb + 15 propane.pdb + 107 total +~~~ + +We can also use `-w` to get only the number of words, +or `-c` to get only the number of characters. + +Which of these files is shortest? +It's an easy question to answer when there are only six files, +but what if there were 6000? +Our first step toward a solution is to run the command: + +~~~ +$ wc -l *.pdb > lengths +~~~ + +The `>` tells the shell to [redirect](http://software-carpentry.org/v5/gloss.html#redirect) the command's output +to a file instead of printing it to the screen. +The shell will create the file if it doesn't exist, +or overwrite the contents of that file if it does. +(This is why there is no screen output: +everything that `wc` would have printed has gone into the file `lengths` instead.) +`ls lengths` confirms that the file exists: + +~~~ +$ ls lengths +lengths +~~~ + +We can now send the content of `lengths` to the screen using `cat lengths`. +`cat` stands for "concatenate": +it prints the contents of files one after another. +There's only one file in this case, +so `cat` just shows us what it contains: + +~~~ +$ cat lengths + 20 cubane.pdb + 12 ethane.pdb + 9 methane.pdb + 30 octane.pdb + 21 pentane.pdb + 15 propane.pdb + 107 total +~~~ + +Now let's use the `sort` command to sort its contents. +This does *not* change the file; +instead, it sends the sorted result to the screen: + +~~~ +$ sort lengths + 9 methane.pdb + 12 ethane.pdb + 15 propane.pdb + 20 cubane.pdb + 21 pentane.pdb + 30 octane.pdb +107 total +~~~ + +We can put the sorted list of lines in another temporary file called `sorted-lengths` +by putting `> sorted-lengths` after the command, +just as we used `> lengths` to put the output of `wc` into `lengths`. +Once we've done that, +we can run another command called `head` to get the first few lines in `sorted-lengths`: + +~~~ +$ sort lengths > sorted-lengths +$ head -1 sorted-lengths + 9 methane.pdb +~~~ + +Using the parameter `-1` with `head` tells it that +we only want the first line of the file; +`-20` would get the first 20, +and so on. +Since `sorted-lengths` contains the lengths of our files ordered from least to greatest, +the output of `head` must be the file with the fewest lines. + +If you think this is confusing, +you're in good company: +even once you understand what `wc`, `sort`, and `head` do, +all those intermediate files make it hard to follow what's going on. +We can make it easier to understand by running `sort` and `head` together: + +~~~ +$ sort lengths | head -1 + 9 methane.pdb +~~~ + +The vertical bar between the two commands is called a [pipe](http://software-carpentry.org/v5//gloss.html#pipe). +It tells the shell that we want to use +the output of the command on the left +as the input to the command on the right. +The computer might create a temporary file if it needs to, +or copy data from one program to the other in memory, +or something else entirely; +we don't have to know or care. + +We can use another pipe to send the output of `wc` directly to `sort`, +which then sends its output to `head`: + +~~~ +$ wc -l *.pdb | sort | head -1 + 9 methane.pdb +~~~ + +This is exactly like a mathematician nesting functions like *sin(πx)2* +and saying "the square of the sine of *x* times π". +In our case, +the calculation is "head of sort of word count of `*.pdb`". + +Here's what actually happens behind the scenes when we create a pipe. +When a computer runs a program—any program—it creates a [process](http://software-carpentry.org/v5//gloss.html#process) +in memory to hold the program's software and its current state. +Every process has an input channel called [standard input](http://software-carpentry.org/v5//gloss.html#standard-input). +(By this point, you may be surprised that the name is so memorable, but don't worry: +most Unix programmers call it "stdin". +Every process also has a default output channel called [standard output](http://software-carpentry.org/v5//gloss.html#standard-output) +(or "stdout"). + +The shell is actually just another program. +Under normal circumstances, +whatever we type on the keyboard is sent to the shell on its standard input, +and whatever it produces on standard output is displayed on our screen. +When we tell the shell to run a program, +it creates a new process +and temporarily sends whatever we type on our keyboard to that process's standard input, +and whatever the process sends to standard output to the screen. + +Here's what happens when we run `wc -l *.pdb > lengths`. +The shell starts by telling the computer to create a new process to run the `wc` program. +Since we've provided some filenames as parameters, +`wc` reads from them instead of from standard input. +And since we've used `>` to redirect output to a file, +the shell connects the process's standard output to that file. + +If we run `wc -l *.pdb | sort` instead, +the shell creates two processes +(one for each process in the pipe) +so that `wc` and `sort` run simultaneously. +The standard output of `wc` is fed directly to the standard input of `sort`; +since there's no redirection with `>`, +`sort`'s output goes to the screen. +And if we run `wc -l *.pdb | sort | head -1`, +we get three processes with data flowing from the files, +through `wc` to `sort`, +and from `sort` through `head` to the screen. + +This simple idea is why Unix has been so successful. +Instead of creating enormous programs that try to do many different things, +Unix programmers focus on creating lots of simple tools that each do one job well, +and that work well with each other. +This programming model is called [pipes and filters](http://software-carpentry.org/v5/gloss.html#pipe-and-filter). +We've already seen pipes; +a [filter](http://software-carpentry.org/v5/gloss.html#filter) is a program like `wc` or `sort` +that transforms a stream of input into a stream of output. +Almost all of the standard Unix tools can work this way: +unless told to do otherwise, +they read from standard input, +do something with what they've read, +and write to standard output. + +The key is that any program that reads lines of text from standard input +and writes lines of text to standard output +can be combined with every other program that behaves this way as well. +You can *and should* write your programs this way +so that you and other people can put those programs into pipes to multiply their power. + +> #### Redirecting Input +> +> As well as using `>` to redirect a program's output, we can use `<` to +> redirect its input, i.e., to read from a file instead of from standard +> input. For example, instead of writing `wc ammonia.pdb`, we could write +> `wc < ammonia.pdb`. In the first case, `wc` gets a command line +> parameter telling it what file to open. In the second, `wc` doesn't have +> any command line parameters, so it reads from standard input, but we +> have told the shell to send the contents of `ammonia.pdb` to `wc`'s +> standard input. + +#### Nelle's Pipeline: Checking Files + +Nelle has run her samples through the assay machines +and created 1520 files in the `north-pacific-gyre/2012-07-03` directory described earlier. +As a quick sanity check, she types: + +~~~ +$ cd north-pacific-gyre/2012-07-03 +$ wc -l *.txt +~~~ + +The output is 1520 lines that look like this: + +~~~ +300 NENE01729A.txt +300 NENE01729B.txt +300 NENE01736A.txt +300 NENE01751A.txt +300 NENE01751B.txt +300 NENE01812A.txt +... ... +~~~ + +Now she types this: + +~~~ +$ wc -l *.txt | sort | head -5 + 240 NENE02018B.txt + 300 NENE01729A.txt + 300 NENE01729B.txt + 300 NENE01736A.txt + 300 NENE01751A.txt +~~~ + +Whoops: one of the files is 60 lines shorter than the others. +When she goes back and checks it, +she sees that she did that assay at 8:00 on a Monday morning—someone +was probably in using the machine on the weekend, +and she forgot to reset it. +Before re-running that sample, +she checks to see if any files have too much data: + +~~~ +$ wc -l *.txt | sort | tail -5 + 300 NENE02040A.txt + 300 NENE02040B.txt + 300 NENE02040Z.txt + 300 NENE02043A.txt + 300 NENE02043B.txt +~~~ + +Those numbers look good—but what's that 'Z' doing there in the third-to-last line? +All of her samples should be marked 'A' or 'B'; +by convention, +her lab uses 'Z' to indicate samples with missing information. +To find others like it, she does this: + +~~~ +$ ls *Z.txt +NENE01971Z.txt NENE02040Z.txt +~~~ + +Sure enough, +when she checks the log on her laptop, +there's no depth recorded for either of those samples. +Since it's too late to get the information any other way, +she must exclude those two files from her analysis. +She could just delete them using `rm`, +but there are actually some analyses she might do later where depth doesn't matter, +so instead, she'll just be careful later on to select files using the wildcard expression `*[AB].txt`. +As always, +the '\*' matches any number of characters; +the expression `[AB]` matches either an 'A' or a 'B', +so this matches all the valid data files she has. + +
+ +#### Key Points + +* `command > file` redirects a command's output to a file. +* `first | second` is a pipeline: the output of the first command is used as the input to the second. +* The best way to use the shell is to use pipes to combine simple single-purpose programs (filters). + +
+ +
+ +#### Challenges + + +1. If we run `sort` on this file: + + ~~~ + 10 + 2 + 19 + 22 + 6 + ~~~ + + the output is: + + ~~~ + 10 + 19 + 2 + 22 + 6 + ~~~ + + If we run `sort -n` on the same input, we get this instead: + + ~~~ + 2 + 6 + 10 + 19 + 22 + ~~~ + + Explain why `-n` has this effect. + +2. What is the difference between: + + ~~~ + wc -l < mydata.dat + ~~~ + + and: + + ~~~ + wc -l mydata.dat + ~~~ + +3. The command `uniq` removes adjacent duplicated lines from its input. + For example, if a file `salmon.txt` contains: + + ~~~ + coho + coho + steelhead + coho + steelhead + steelhead + ~~~ + + then `uniq salmon.txt` produces: + + ~~~ + coho + steelhead + coho + steelhead + ~~~ + + Why do you think `uniq` only removes *adjacent* duplicated lines? + (Hint: think about very large data sets.) What other command could + you combine with it in a pipe to remove all duplicated lines? + +4. A file called `animals.txt` contains the following data: + + ~~~ + 2012-11-05,deer + 2012-11-05,rabbit + 2012-11-05,raccoon + 2012-11-06,rabbit + 2012-11-06,deer + 2012-11-06,fox + 2012-11-07,rabbit + 2012-11-07,bear + ~~~ + + What text passes through each of the pipes and the final redirect in the pipeline below? + + ~~~ + cat animals.txt | head -5 | tail -3 | sort -r > final.txt + ~~~ + +5. The command: + + ~~~ + $ cut -d , -f 2 animals.txt + ~~~ + + produces the following output: + + ~~~ + deer + rabbit + raccoon + rabbit + deer + fox + rabbit + bear + ~~~ + + What other command(s) could be added to this in a pipeline to find + out what animals the file contains (without any duplicates in their + names)? + +
diff --git a/pipes/molecules/cubane.pdb b/pipes/molecules/cubane.pdb new file mode 100644 index 0000000..f4c4370 --- /dev/null +++ b/pipes/molecules/cubane.pdb @@ -0,0 +1,20 @@ +COMPND CUBANE +AUTHOR DAVE WOODCOCK 95 12 06 +ATOM 1 C 1 0.789 -0.852 0.504 1.00 0.00 +ATOM 2 C 1 -0.161 -1.104 -0.624 1.00 0.00 +ATOM 3 C 1 -1.262 -0.440 0.160 1.00 0.00 +ATOM 4 C 1 -0.289 -0.202 1.284 1.00 0.00 +ATOM 5 C 1 1.203 0.513 -0.094 1.00 0.00 +ATOM 6 C 1 0.099 1.184 0.694 1.00 0.00 +ATOM 7 C 1 -0.885 0.959 -0.460 1.00 0.00 +ATOM 8 C 1 0.236 0.283 -1.269 1.00 0.00 +ATOM 9 H 1 1.410 -1.631 0.942 1.00 0.00 +ATOM 10 H 1 -0.262 -2.112 -1.024 1.00 0.00 +ATOM 11 H 1 -2.224 -0.925 0.328 1.00 0.00 +ATOM 12 H 1 -0.468 -0.501 2.315 1.00 0.00 +ATOM 13 H 1 2.224 0.892 -0.134 1.00 0.00 +ATOM 14 H 1 0.240 2.112 1.251 1.00 0.00 +ATOM 15 H 1 -1.565 1.730 -0.831 1.00 0.00 +ATOM 16 H 1 0.472 0.494 -2.315 1.00 0.00 +TER 17 1 +END diff --git a/pipes/molecules/ethane.pdb b/pipes/molecules/ethane.pdb new file mode 100644 index 0000000..d59ac91 --- /dev/null +++ b/pipes/molecules/ethane.pdb @@ -0,0 +1,12 @@ +COMPND ETHANE +AUTHOR DAVE WOODCOCK 95 12 18 +ATOM 1 C 1 -0.752 0.001 -0.141 1.00 0.00 +ATOM 2 C 1 0.752 -0.001 0.141 1.00 0.00 +ATOM 3 H 1 -1.158 0.991 0.070 1.00 0.00 +ATOM 4 H 1 -1.240 -0.737 0.496 1.00 0.00 +ATOM 5 H 1 -0.924 -0.249 -1.188 1.00 0.00 +ATOM 6 H 1 1.158 -0.991 -0.070 1.00 0.00 +ATOM 7 H 1 0.924 0.249 1.188 1.00 0.00 +ATOM 8 H 1 1.240 0.737 -0.496 1.00 0.00 +TER 9 1 +END diff --git a/pipes/molecules/methane.pdb b/pipes/molecules/methane.pdb new file mode 100644 index 0000000..7908351 --- /dev/null +++ b/pipes/molecules/methane.pdb @@ -0,0 +1,9 @@ +COMPND METHANE +AUTHOR DAVE WOODCOCK 95 12 18 +ATOM 1 C 1 0.257 -0.363 0.000 1.00 0.00 +ATOM 2 H 1 0.257 0.727 0.000 1.00 0.00 +ATOM 3 H 1 0.771 -0.727 0.890 1.00 0.00 +ATOM 4 H 1 0.771 -0.727 -0.890 1.00 0.00 +ATOM 5 H 1 -0.771 -0.727 0.000 1.00 0.00 +TER 6 1 +END diff --git a/pipes/molecules/octane.pdb b/pipes/molecules/octane.pdb new file mode 100644 index 0000000..581be2e --- /dev/null +++ b/pipes/molecules/octane.pdb @@ -0,0 +1,30 @@ +COMPND OCTANE +AUTHOR DAVE WOODCOCK 96 01 05 +ATOM 1 C 1 -4.397 0.370 -0.255 1.00 0.00 +ATOM 2 C 1 -3.113 -0.447 -0.421 1.00 0.00 +ATOM 3 C 1 -1.896 0.386 -0.007 1.00 0.00 +ATOM 4 C 1 -0.611 -0.426 -0.198 1.00 0.00 +ATOM 5 C 1 0.608 0.405 0.216 1.00 0.00 +ATOM 6 C 1 1.892 -0.400 0.001 1.00 0.00 +ATOM 7 C 1 3.113 0.429 0.414 1.00 0.00 +ATOM 8 C 1 4.397 -0.374 0.199 1.00 0.00 +ATOM 9 H 1 -4.502 0.681 0.785 1.00 0.00 +ATOM 10 H 1 -5.254 -0.243 -0.537 1.00 0.00 +ATOM 11 H 1 -4.357 1.252 -0.895 1.00 0.00 +ATOM 12 H 1 -3.009 -0.741 -1.467 1.00 0.00 +ATOM 13 H 1 -3.172 -1.337 0.206 1.00 0.00 +ATOM 14 H 1 -1.992 0.668 1.044 1.00 0.00 +ATOM 15 H 1 -1.849 1.286 -0.621 1.00 0.00 +ATOM 16 H 1 -0.515 -0.707 -1.248 1.00 0.00 +ATOM 17 H 1 -0.659 -1.326 0.417 1.00 0.00 +ATOM 18 H 1 0.520 0.671 1.270 1.00 0.00 +ATOM 19 H 1 0.645 1.314 -0.386 1.00 0.00 +ATOM 20 H 1 1.979 -0.666 -1.054 1.00 0.00 +ATOM 21 H 1 1.855 -1.309 0.604 1.00 0.00 +ATOM 22 H 1 3.030 0.696 1.467 1.00 0.00 +ATOM 23 H 1 3.155 1.337 -0.188 1.00 0.00 +ATOM 24 H 1 4.493 -0.641 -0.854 1.00 0.00 +ATOM 25 H 1 4.368 -1.282 0.801 1.00 0.00 +ATOM 26 H 1 5.254 0.230 0.498 1.00 0.00 +TER 27 1 +END diff --git a/pipes/molecules/pentane.pdb b/pipes/molecules/pentane.pdb new file mode 100644 index 0000000..1eef172 --- /dev/null +++ b/pipes/molecules/pentane.pdb @@ -0,0 +1,21 @@ +COMPND PENTANE +AUTHOR DAVE WOODCOCK 95 12 18 +ATOM 1 C 1 2.484 -0.389 0.322 1.00 0.00 +ATOM 2 C 1 1.261 0.350 -0.243 1.00 0.00 +ATOM 3 C 1 -0.027 -0.348 0.199 1.00 0.00 +ATOM 4 C 1 -1.249 0.421 -0.326 1.00 0.00 +ATOM 5 C 1 -2.536 -0.311 0.047 1.00 0.00 +ATOM 6 H 1 2.471 -1.420 -0.033 1.00 0.00 +ATOM 7 H 1 2.443 -0.371 1.412 1.00 0.00 +ATOM 8 H 1 3.393 0.112 -0.016 1.00 0.00 +ATOM 9 H 1 1.324 0.350 -1.332 1.00 0.00 +ATOM 10 H 1 1.271 1.378 0.122 1.00 0.00 +ATOM 11 H 1 -0.074 -0.384 1.288 1.00 0.00 +ATOM 12 H 1 -0.048 -1.362 -0.205 1.00 0.00 +ATOM 13 H 1 -1.183 0.500 -1.412 1.00 0.00 +ATOM 14 H 1 -1.259 1.420 0.112 1.00 0.00 +ATOM 15 H 1 -2.608 -0.407 1.130 1.00 0.00 +ATOM 16 H 1 -2.540 -1.303 -0.404 1.00 0.00 +ATOM 17 H 1 -3.393 0.254 -0.321 1.00 0.00 +TER 18 1 +END diff --git a/pipes/molecules/propane.pdb b/pipes/molecules/propane.pdb new file mode 100644 index 0000000..21ad7c4 --- /dev/null +++ b/pipes/molecules/propane.pdb @@ -0,0 +1,15 @@ +COMPND PROPANE +AUTHOR DAVE WOODCOCK 95 12 18 +ATOM 1 C 1 1.241 0.444 0.349 1.00 0.00 +ATOM 2 C 1 -0.011 -0.441 0.333 1.00 0.00 +ATOM 3 C 1 -1.176 0.296 -0.332 1.00 0.00 +ATOM 4 H 1 1.516 0.699 -0.675 1.00 0.00 +ATOM 5 H 1 2.058 -0.099 0.827 1.00 0.00 +ATOM 6 H 1 1.035 1.354 0.913 1.00 0.00 +ATOM 7 H 1 -0.283 -0.691 1.359 1.00 0.00 +ATOM 8 H 1 0.204 -1.354 -0.225 1.00 0.00 +ATOM 9 H 1 -0.914 0.551 -1.359 1.00 0.00 +ATOM 10 H 1 -1.396 1.211 0.219 1.00 0.00 +ATOM 11 H 1 -2.058 -0.345 -0.332 1.00 0.00 +TER 12 1 +END From 1232bf91e1fc53ca1fbf154f2f5fbae99d5decb5 Mon Sep 17 00:00:00 2001 From: Lasher09 Date: Wed, 19 Mar 2014 15:31:31 +0000 Subject: [PATCH 2/8] Here is my Pipes post. --- .index.html.swp | Bin 0 -> 12288 bytes 2014-03-13-sunhwapipesfilter.md | 29 ++ _config.yml | 2 +- _drafts/2014-01-22-simplyhowto.md | 94 ---- .../2013-01-02-brittanysanotherbranchtest.md | 7 + _posts/2013-01-25-sunhwaanotherbranch.md | 7 + _posts/2013-03-05-julieseiferttestpost.md | 6 + _posts/2014-01-01-XuxiangTestsPost.md | 11 + _posts/2014-01-01-bdferrtestpost2.md | 7 + _posts/2014-01-01-brittanystestpost.md | 10 + _posts/2014-01-01-chunxitest.md | 10 + _posts/2014-01-01-ethanstestpost.md | 10 + _posts/2014-01-01-mandystestypost.md | 9 + _posts/2014-01-01-oaktestpost.md | 9 + _posts/2014-01-01-sophiatestpost2.md | 9 + _posts/2014-01-01-sunhwatestpost.md | 10 + _posts/2014-01-08-firstpostethan.md | 17 +- _posts/2014-01-16-turtledrawing.md | 3 +- _posts/2014-01-22-pythonbasicsethan.md | 4 +- _posts/2014-01-30-ThuMaiListsStrings.md | 8 +- _posts/2014-02-05-Leitestytest.md | 13 + _posts/2014-02-05-ThuMaiNitrous.md | 16 + _posts/2014-02-05-bdferrsamplenewpost.md | 10 + _posts/2014-02-05-brittanytest.md | 14 + _posts/2014-02-05-juliesboxpost.md | 14 + _posts/2014-02-05-madelinetest.md | 14 + _posts/2014-02-05-mandynitroustestpost.md | 16 + _posts/2014-02-05-sierrapost.md | 14 + _posts/2014-02-05-sophiatestpost.md | 15 + _posts/2014-02-05-test.md | 14 + _posts/2014-02-05-testest.md | 14 + _posts/2014-02-05-testtesty.md | 14 + _posts/2014-02-05-testytest.md | 12 + _posts/2014-02-05-yonghaotesttest.md | 12 + _posts/2014-02-05-zachTest.md | 12 + _posts/2014-02-09-codingbatsierra.md | 5 +- .../2014-02-12-sunhwacodingbatexercises2.md | 93 ++++ _posts/2014-02-14-ChunxiCodingBat2.md | 109 ++++ _posts/2014-02-14-bdferrcodingbat2a.md | 184 +++++++ .../2014-02-14-sophiacodingbatexercises2.md | 71 +++ _posts/2014-02-14-yonghao's-codingbat2.md | 131 +++++ _posts/2014-02-15-Lei_PythonBasics2.md | 88 ++++ _posts/2014-02-15-libbycodingbat2.md | 62 +++ _posts/2014-02-15-lyonscodingbatp2.md | 127 +++++ _posts/2014-02-16 madelinecodingbat2.md | 63 +++ _posts/2014-02-16-blucka12-codingbat2.md | 54 ++ _posts/2014-02-16-jessicascodingbat2post.md | 106 ++++ _posts/2014-02-16-juliesecondbat.md | 53 ++ _posts/2014-02-16-secondcodingbatsierra.md | 56 ++ _posts/2014-02-19-Ha.md | 20 - _posts/2014-02-19-nitrouspostklm.md | 9 + _posts/2014-02-19-simpleblogklm.md | 87 ++++ _posts/2014-02-19-thetestiness.md | 16 + _posts/2014-02-20-mandysimpleblogpost.md | 25 + _posts/2014-02-20-zbaySimple1.md | 12 + _posts/2014-02-21-ThuMaiSimpleHack.md | 28 + _posts/2014-02-21-herokusierra.md | 21 + _posts/2014-02-21-sunhwaherokupost.md | 42 ++ _posts/2014-02-22-ChunxiSimpleHack1.md | 23 + _posts/2014-02-22-brittanyheroku.md | 21 + _posts/2014-02-22-libbyherokuapp.md | 19 + _posts/2014-02-22-yonghao's-blog.md | 87 ++++ _posts/2014-02-23-LeiSimpleBlog.md | 27 + _posts/2014-02-23-Xuxiang's-HerokuApp.md | 22 + _posts/2014-02-23-bdferrsimpleblog.md | 43 ++ _posts/2014-02-23-blucka12-herokupost.md | 13 + _posts/2014-02-23-herokupost.md | 16 + _posts/2014-02-23-jessicasfirstsimplepost.md | 54 ++ _posts/2014-02-23-julieheroku.md | 43 ++ _posts/2014-02-23-madelineheroku.md | 12 + _posts/2014-02-23-sophiasimpleblog.md | 29 ++ _posts/2014-02-24-lyonssimplepost.md | 37 ++ _posts/2014-02-26-LeiTest.md | 10 + _posts/2014-02-26-jskaastestpost.md | 10 + _posts/2014-02-26-juliestestpost.md | 10 + _posts/2014-02-26-libbyflaskabout.md | 36 ++ _posts/2014-02-26-lyonsasimpleabout.md | 17 + _posts/2014-02-26-simpleaboutklm.md | 56 ++ _posts/2014-02-27-JulieSimplePost.md | 31 ++ _posts/2014-02-27-ThuMaiSimpleMod.md | 57 +++ _posts/2014-02-27-brittanyssimplehackmods.md | 95 ++++ _posts/2014-02-27-chunxisimple2.md | 45 ++ _posts/2014-02-27-mandyssimpleaboutme.md | 49 ++ _posts/2014-02-27-sophiaaboutpage.md | 40 ++ _posts/2014-02-28-LeiAboutMePage.md | 40 ++ _posts/2014-02-28-aboutme.md | 46 ++ _posts/2014-02-28-bdferrmoresimple.md | 89 ++++ _posts/2014-02-28-blucka12-herokuaboutme.md | 51 ++ .../2014-02-28-jessicasdoingmorewithsimple.md | 60 +++ _posts/2014-02-28-sunhwaabout.md | 41 ++ _posts/2014-02-28-yonghaosecondblog.md | 85 +++ _posts/2014-03-04-XuxiangDoMore.md | 41 ++ _posts/2014-03-05-libbypipesfilters.md | 37 ++ _posts/2014-03-05-lyonsabranchingtest.md | 10 + _posts/2014-03-05-lyonsapipesfilters.md | 80 +++ _posts/2014-03-05-pipesfiltersklm.md | 72 +++ _posts/2014-03-06-juliepipespost.md | 18 + _posts/2014-03-07-ThuMaiPipesFilters.md | 73 +++ _posts/2014-03-10-mandyspipesandfilters.md | 49 ++ _posts/2014-03-12-brittanyspipesfilters.md | 69 +++ _posts/2014-03-13-sophiapipesfilters.md | 34 ++ _posts/2014-03-13-sunhwapipesfilter.md | 36 ++ _posts/2014-03-15-ChunxiPipes.md | 71 +++ _posts/2014-03-15-yonghao-Pipefileter.md | 60 +++ _posts/2014-03-16-ThuMaiPipesFilters.md | 73 +++ _posts/2014-03-16-bdferrpipesandfilters.md | 70 +++ _posts/2014-03-19-Laura-Pipes-post.md | 65 +++ _posts/2014-05-02-jessicaiotestpost.md | 15 + _posts/elliott/2014-03-05-ninth.md | 19 + _posts/exercises/2014-02-22-simplyhowto.md | 36 ++ _posts/exercises/2014-02-26-simplemore.md | 16 + _posts/exercises/2014-03-16-pipefilter.md | 484 ++++++++++++++++++ _posts/how-tos/2014-03-05-branching.md | 65 +++ css/main.css | 2 +- feedback.markdown | 2 +- simplehack | 1 + 116 files changed, 4600 insertions(+), 140 deletions(-) create mode 100644 .index.html.swp create mode 100644 2014-03-13-sunhwapipesfilter.md delete mode 100644 _drafts/2014-01-22-simplyhowto.md create mode 100644 _posts/2013-01-02-brittanysanotherbranchtest.md create mode 100644 _posts/2013-01-25-sunhwaanotherbranch.md create mode 100644 _posts/2013-03-05-julieseiferttestpost.md create mode 100644 _posts/2014-01-01-XuxiangTestsPost.md create mode 100644 _posts/2014-01-01-bdferrtestpost2.md create mode 100644 _posts/2014-01-01-brittanystestpost.md create mode 100644 _posts/2014-01-01-chunxitest.md create mode 100644 _posts/2014-01-01-ethanstestpost.md create mode 100644 _posts/2014-01-01-mandystestypost.md create mode 100644 _posts/2014-01-01-oaktestpost.md create mode 100644 _posts/2014-01-01-sophiatestpost2.md create mode 100644 _posts/2014-01-01-sunhwatestpost.md create mode 100644 _posts/2014-02-05-Leitestytest.md create mode 100644 _posts/2014-02-05-ThuMaiNitrous.md create mode 100644 _posts/2014-02-05-bdferrsamplenewpost.md create mode 100644 _posts/2014-02-05-brittanytest.md create mode 100644 _posts/2014-02-05-juliesboxpost.md create mode 100644 _posts/2014-02-05-madelinetest.md create mode 100644 _posts/2014-02-05-mandynitroustestpost.md create mode 100644 _posts/2014-02-05-sierrapost.md create mode 100644 _posts/2014-02-05-sophiatestpost.md create mode 100644 _posts/2014-02-05-test.md create mode 100644 _posts/2014-02-05-testest.md create mode 100644 _posts/2014-02-05-testtesty.md create mode 100644 _posts/2014-02-05-testytest.md create mode 100644 _posts/2014-02-05-yonghaotesttest.md create mode 100644 _posts/2014-02-05-zachTest.md create mode 100644 _posts/2014-02-12-sunhwacodingbatexercises2.md create mode 100644 _posts/2014-02-14-ChunxiCodingBat2.md create mode 100644 _posts/2014-02-14-bdferrcodingbat2a.md create mode 100644 _posts/2014-02-14-sophiacodingbatexercises2.md create mode 100644 _posts/2014-02-14-yonghao's-codingbat2.md create mode 100644 _posts/2014-02-15-Lei_PythonBasics2.md create mode 100644 _posts/2014-02-15-libbycodingbat2.md create mode 100644 _posts/2014-02-15-lyonscodingbatp2.md create mode 100644 _posts/2014-02-16 madelinecodingbat2.md create mode 100644 _posts/2014-02-16-blucka12-codingbat2.md create mode 100644 _posts/2014-02-16-jessicascodingbat2post.md create mode 100644 _posts/2014-02-16-juliesecondbat.md create mode 100644 _posts/2014-02-16-secondcodingbatsierra.md delete mode 100644 _posts/2014-02-19-Ha.md create mode 100644 _posts/2014-02-19-nitrouspostklm.md create mode 100644 _posts/2014-02-19-simpleblogklm.md create mode 100644 _posts/2014-02-19-thetestiness.md create mode 100644 _posts/2014-02-20-mandysimpleblogpost.md create mode 100644 _posts/2014-02-20-zbaySimple1.md create mode 100644 _posts/2014-02-21-ThuMaiSimpleHack.md create mode 100644 _posts/2014-02-21-herokusierra.md create mode 100644 _posts/2014-02-21-sunhwaherokupost.md create mode 100644 _posts/2014-02-22-ChunxiSimpleHack1.md create mode 100644 _posts/2014-02-22-brittanyheroku.md create mode 100644 _posts/2014-02-22-libbyherokuapp.md create mode 100644 _posts/2014-02-22-yonghao's-blog.md create mode 100644 _posts/2014-02-23-LeiSimpleBlog.md create mode 100644 _posts/2014-02-23-Xuxiang's-HerokuApp.md create mode 100644 _posts/2014-02-23-bdferrsimpleblog.md create mode 100644 _posts/2014-02-23-blucka12-herokupost.md create mode 100644 _posts/2014-02-23-herokupost.md create mode 100644 _posts/2014-02-23-jessicasfirstsimplepost.md create mode 100644 _posts/2014-02-23-julieheroku.md create mode 100644 _posts/2014-02-23-madelineheroku.md create mode 100644 _posts/2014-02-23-sophiasimpleblog.md create mode 100644 _posts/2014-02-24-lyonssimplepost.md create mode 100644 _posts/2014-02-26-LeiTest.md create mode 100644 _posts/2014-02-26-jskaastestpost.md create mode 100644 _posts/2014-02-26-juliestestpost.md create mode 100644 _posts/2014-02-26-libbyflaskabout.md create mode 100644 _posts/2014-02-26-lyonsasimpleabout.md create mode 100644 _posts/2014-02-26-simpleaboutklm.md create mode 100644 _posts/2014-02-27-JulieSimplePost.md create mode 100644 _posts/2014-02-27-ThuMaiSimpleMod.md create mode 100644 _posts/2014-02-27-brittanyssimplehackmods.md create mode 100644 _posts/2014-02-27-chunxisimple2.md create mode 100644 _posts/2014-02-27-mandyssimpleaboutme.md create mode 100644 _posts/2014-02-27-sophiaaboutpage.md create mode 100644 _posts/2014-02-28-LeiAboutMePage.md create mode 100644 _posts/2014-02-28-aboutme.md create mode 100644 _posts/2014-02-28-bdferrmoresimple.md create mode 100644 _posts/2014-02-28-blucka12-herokuaboutme.md create mode 100644 _posts/2014-02-28-jessicasdoingmorewithsimple.md create mode 100644 _posts/2014-02-28-sunhwaabout.md create mode 100644 _posts/2014-02-28-yonghaosecondblog.md create mode 100644 _posts/2014-03-04-XuxiangDoMore.md create mode 100644 _posts/2014-03-05-libbypipesfilters.md create mode 100644 _posts/2014-03-05-lyonsabranchingtest.md create mode 100644 _posts/2014-03-05-lyonsapipesfilters.md create mode 100644 _posts/2014-03-05-pipesfiltersklm.md create mode 100644 _posts/2014-03-06-juliepipespost.md create mode 100644 _posts/2014-03-07-ThuMaiPipesFilters.md create mode 100644 _posts/2014-03-10-mandyspipesandfilters.md create mode 100644 _posts/2014-03-12-brittanyspipesfilters.md create mode 100644 _posts/2014-03-13-sophiapipesfilters.md create mode 100644 _posts/2014-03-13-sunhwapipesfilter.md create mode 100644 _posts/2014-03-15-ChunxiPipes.md create mode 100644 _posts/2014-03-15-yonghao-Pipefileter.md create mode 100644 _posts/2014-03-16-ThuMaiPipesFilters.md create mode 100644 _posts/2014-03-16-bdferrpipesandfilters.md create mode 100644 _posts/2014-03-19-Laura-Pipes-post.md create mode 100644 _posts/2014-05-02-jessicaiotestpost.md create mode 100644 _posts/elliott/2014-03-05-ninth.md create mode 100644 _posts/exercises/2014-02-22-simplyhowto.md create mode 100644 _posts/exercises/2014-02-26-simplemore.md create mode 100644 _posts/exercises/2014-03-16-pipefilter.md create mode 100644 _posts/how-tos/2014-03-05-branching.md create mode 160000 simplehack diff --git a/.index.html.swp b/.index.html.swp new file mode 100644 index 0000000000000000000000000000000000000000..7ad4d9cb1b2eceb37991c1c2e245a2327c74fc80 GIT binary patch literal 12288 zcmeI2O^ggd6vqpv!6F>Q?P>9mFdw@7JRUw`+7&i?xQt*&Qd2 z4&ubYorA>P$yFlUTt)n=x@LCR@s&7`yh{G*sj64+z53OwP9`%8jdQ2Z&}{9XK-(fj zWA6Rg$LoZ6vQ`M$Hi^pY#LrtQvxT&XtI;Kybyaot(BbKsNh@xa4(qy~Cs}u zWKn#r)-#Lgqy;?21en0zAyAl3_2|^x!I|lXb+{|oN!zy0{T<)zg$XbLCcp%k025#W zOn?b6f&YSl>8}yDkSV_IySC3i*L?T%U4AeDCcp%k025#WOn?b60Vco%m;e)C0{VCE+7Io3 zZchnu7CHiLhdyl-;vIAiYC&tEr42${hUTG*&=Keh^7#P0fnGt+p-0d|$mV(vx(g|Y z8xvpxOn?b60Vco%n83eFAgo8p)s`R%>qTmx_S34NZqJ{58TRSH;{B} zzfyL_W{E0(u(YtTY^#KIZE}@$%kbU|Hp|O8F>y^6rl)d!-ajwa`nl>12Gnel$%}Xx zoCpzZIB!QuMt!A?U+;1fE+BT8CM_{Jo6{aa7CXVoZa9-BYS){OS#@=BqOkII@tNxeMoGy`~W zHL@UeT;!>(D8J>h7mQ+<#H6<3!n$nH!V-y!KbvoF94?DHF^ppS{u)|K+lJW-+bQi} z^ryG#*A?OXJ2SYq|0TB-MdXKVa5w4CpfqSwN3K49cZjY8+JM_tc@k@CtIWtG!-sNg zX=R_jR!0-K@{X_W$L&O>)iEz4HY=4n%p|a{kznZ6`?OiuSBUdxJGwLoi= bigHigh: + if small>=(goal-bigHigh*5): + return goal-bigHigh*5 + else: + if small >= (goal-big*5): + return goal - big*5 + + return -1 +``` + + diff --git a/_posts/2014-02-14-ChunxiCodingBat2.md b/_posts/2014-02-14-ChunxiCodingBat2.md new file mode 100644 index 0000000..9ac93a1 --- /dev/null +++ b/_posts/2014-02-14-ChunxiCodingBat2.md @@ -0,0 +1,109 @@ +--- +layout: post +author: chunxi +title: Chunxi's CodingBat2 +date: 2014-02-14 +--- + +Post by Chunxi Zhang + +## Chunxi's CodingBat2 + +**Choose three exercise.** + + +**1.String2-xyz_there** + + + This question did take me some time. I thought several different ways to express my idea. But I do not know a method which can + Then I change my thoughts. It could be 2 circumstances. If the 'xyz' is str[0:3], no matter where the '.' is, it will return + True. And if there are '.xyz', it will return false. I can use != to except the '.'. + + + ``` + def xyz_there(str): + for i in range(len(str)): + if str[i] != '.' and str[i+1:i+4] == 'xyz': + return True + if str[0:3] == 'xyz': + return True + return False + ``` + +**2.Logic2-make_bricks** + + + I am impressed with this question is because it took me some time to understand the request. After watching the vedio to understand +what brick means, I begin to code. The code isself is not hard. But it is problematic to know what exactly I want. + + ``` + def make_bricks(small, big, goal): + if goal % 5 >= 0 and goal % 5 - small <= 0 and small + 5*big >= goal: + return True + else: + return False + ``` + + +**3.Logic2-long_sum** + + This question is strightforward. But I spent more time on debugging. The original code of mine is + + ``` +def lone_sum(a, b, c): + + if a == b: + return c + if a == c: + return b + if b == c: + return a + if a == b == c: + return 0 + + else: + return a+b+c + + ``` + +However, it cannot pass the test. At first, I did not what is wrong. Then I read the test carefully and I found out all the problem +happened when a=b=c. So I noticed that the problem is about the order. a = b= c should be ordered first. + + ``` +def lone_sum(a, b, c): + if a == b == c: + return 0 + if a == b: + return c + if a == c: + return b + if b == c: + return a + + else: + return a+b+c + + ``` + + **Pictures** + + **warmup2** + + ![Image](http://farm3.staticflickr.com/2825/12522673384_ba1eac389f_m.jpg) + + **string2** + + ![Image](http://farm6.staticflickr.com/5516/12522685604_d424de12a5_m.jpg) + + **list2** + + ![Image](http://farm8.staticflickr.com/7348/12522205865_50f00c22f2_m.jpg) + + **logic2** + + ![Image](http://farm4.staticflickr.com/3789/12522217755_815f9b86cc_m.jpg) + + + + + diff --git a/_posts/2014-02-14-bdferrcodingbat2a.md b/_posts/2014-02-14-bdferrcodingbat2a.md new file mode 100644 index 0000000..c7236b3 --- /dev/null +++ b/_posts/2014-02-14-bdferrcodingbat2a.md @@ -0,0 +1,184 @@ +--- +layout: post +author: bdferr +title: CodingBat 2 +--- + +I realize I posted these in my first CodingBat post already, but here they are again. + +![Warmup-2 image](http://i.imgur.com/G9jiOfB.png) + +![Logic-2 image](http://i.imgur.com/fxqcvPP.png) + +![String-2 image](http://i.imgur.com/p5Dhx4y.png) + +In the List-2 section, I could not quite finish the sum67 problem, so after quite a bit of time working on it, +I am leaving it for now. As you can see, I did get it to partially work, and I did get the other problems +in that section done. + +![List-2 image](http://i.imgur.com/PyRVMk5.png) + +![Sum67 image](http://i.imgur.com/2KLaTod.png) + +The sum67 problem was particularly maddening, of course. The goal was to remove every item +in a string from a 6 to the next 7, and sum the results (the sum was easy enough). +I had two different versions of it, each of which passed 8 tests but failed the rest. +Both produce lists of the index positions of the 6s and 7s, and use them for iterative string concatenation. +My latest efforts to improve either of them resulted in either no change or error messages. +I actually ended up with more than two versions. +I suspect there is something fundamental which I am missing here. + +My first version manages to identify the 6s and 7s, but does not seem to recognize +the space between them; i.e. in a list like [6, 7, 8, 6, 7] it would return zero, where it should +return 8. It also does not recognize when the 7s are superfluous, i.e. in [9,6,7,7] it would give me +9 rather than 16. It looks like this: + +``` +def sum67(nums): + seven_found = False + n = 0 + start_slices = [] + end_slices = [] + b = 0 + six_count = nums.count(6) + seven_count = nums.count(7) + if nums == []: + return 0 + elif 6 not in nums and 7 not in nums: + return nums + else: + while six_count > 0 or seven_count > 0: + if nums[n] == 6: + start_slices += str(n) + n += 1 + six_count -= 1 + elif nums[n] == 7: + end_slices += str(n) + n += 1 + seven_count -= 1 + else: + n+=1 + for a in start_slices: + for b in end_slices: + nums = nums[:int(a)] + nums[int(b)+1:] + start_slices = start_slices[:int(a)] + start_slices[int(b)+1:] + end_slices = end_slices[:int(b)] + end_slices[int(b)+1:] + return sum(nums) +``` + +I made a second version in response to these problems, but it does not entirely solve them. +The details might be too complicated to fully explain in this post. Basically, though, +I want to (and apparently don't) have a function which can run two simultaneous for loops on two separate lists. +For example, if I have a list called lista [a, b, c, d] and a list called listb [w, x, y, z], I want my code +to generate the slices [a:w], [b:x], [c:y], and [d:z]. I know the slicing is a separate function, +but I need to be able to conection a with w, then b with x, and so on. +Nesting one for loop inside another is what I attempted in my first version, but it does not +seem to quite do the same thing. Instead I believe it generates [a:w], [a:x], [a:y], +a:z], and then [b:w], [b:x], and so on. This explains why what is removed includes what I did not +want to remove, when it is between two strings which I actually did want to remove. +I ultimately attempted several approximations but still can't seem to quite get this double loop function. +Here is one unsuccessful attempt. This version can’t seem to deal with multiple 6s and 7s, +not even recognizing anything beyond the first pair: + +``` +def sum67(nums): + n = 0 + b = 0 + start_slices = [] + end_slices = [] + six_count = nums.count(6) + seven_count = nums.count(7) + if nums == []: + return 0 + elif 6 not in nums and 7 not in nums: + return nums + else: + while six_count > 0 or seven_count > 0: + if nums[n] == 6: + start_slices += str(n) + n += 1 + six_count -= 1 + elif nums[n] == 7: + end_slices += str(n) + n += 1 + seven_count -= 1 + else: + n+=1 + for a in start_slices: + if end_slices[0] < a: # in other words if there is a 7 located before a 6 + end_slices = end_slices[1:] # remove it from the list of 7 positions, + # and don't do anything with it. + else: + nums = nums[:int(a)] + nums[int(end_slices[0])+1:] + if len(start_slices) > 1: + start_slices = start_slices[1:] + else: + start_slices = [] + if len(end_slices) > 1: + end_slices = end_slices[1:] + else: start_slices = [] + return sum(nums) +``` + + +This problem showed me that there are things I do not understand in programming, +even while I seem to understand all the relevant elements for that problem. + +I am sure everyone else will be saying the same thing, +but I honestly do agree with the founder of CodingBat that the MakeBricks problem +is particularly interesting. I initially attempted it using loops, +and got errors attempting a nested for loop. More importantly, though, +I noticed I was advised to do it without any iteration at all, which I found baffling. + +I restrained myself from watching the full video explaining it, and simply proceeded +based on the hint that I should use the modulus operator. After numerous attempts, +I realized that simply applying the modulus to the number 5 was not always appropriate. +If the goal divided by 5 was larger than the number of large bricks available, the result +would be misleading; if the number of small bricks was sufficient to cover the remainder, +it would give the false impression that the goal could be met. I found the use of the modulus +to completely replace iteration very interesting. My code looked like this: + +``` +def make_bricks(small, big, goal): + if small >= goal: + return True + elif big * 5 + small < goal: + return False + elif big != 0 and goal % (big * 5) <= small: + return True + elif big * 5 > goal and (goal % 5 == 0 or goal % 5 <= small): + return True + else: + return False +``` + + +I also enjoyed a similar problem, in which there was a goal number of kilos +of chocolate. One problem was that the instructions were not exactly clear, though. The line +"Return the number of small bars to use, assuming we always use big bars before small bars" +was particularly misleading. What they actually wanted, based on the test results, +was not that the big bars should all be used before beginning with the small bars, +and one test result showed that what they wanted was even farther removed than that: +“make_chocolate(4, 1, 4)” expects an answer of 4, when this clearly requires using no big bars at all. Possibly they forgot to say that big bars can be omitted when the goal is less than 5. +Regardless, I was able to solve this with similar curious applications of the modulus operator +to what I did in the Make Bricks problem. This was my code: + + +``` +def make_chocolate(small, big, goal): + if goal < 5 and small >= goal: + return small + elif goal < 5 and small < goal: + return -1 + elif small + big * 5 < goal: + return -1 + elif goal % (big * 5) <= small: + bars = goal - (big * 5) + return bars + else: + bars = goal % 5 + if small >= bars: + return bars + else: + return -1 +``` diff --git a/_posts/2014-02-14-sophiacodingbatexercises2.md b/_posts/2014-02-14-sophiacodingbatexercises2.md new file mode 100644 index 0000000..76b64cd --- /dev/null +++ b/_posts/2014-02-14-sophiacodingbatexercises2.md @@ -0,0 +1,71 @@ +--- +layout: post +author: slaffer +title: Sophia's CodingBat Marathon Part 2 +--- + +##Three Exercises + +**1. String: end_other** + +*Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: s.lower() returns the lowercase version of a string.* + +Many of these exercises were challenging for me. I liked this exercise because the hint provided by codingbat was very useful and I was able to come up with the solution in a relatively short time, which was a pleasant change from some of the other exercises (see below). + +``` +def end_other(a, b): + lower_a = a.lower() + lower_b = b.lower() + if lower_a.endswith(b.lower()): + return True + elif lower_b.endswith(a.lower()): + return True + else: + return False +``` + +**2. Lists: sum13** + +*Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count.* + +This is an exercise that I thought I understood the concept but could not figure out the answer. I used my resources and found someone on stackoverflow who also had problems with this exercise, which can be found [here] (http://stackoverflow.com/questions/11059910/skipping-elements-in-a-list-python). Seeing the correct code supplied by a user helped me to better understand the problem. Although it wasn't as satisfying as figuring out the answer myself, walking through this code was a good learning experience. + +``` +def sum13(nums): + sum = 0 + skip = False + for i in nums: + if i == 13: + skip = True + continue + if skip: + skip = False + continue + sum += i + return sum +``` + +**3. Logic: make_chocolate** + +*We want make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of small bars to use, assuming we always use big bars before small bars. Return -1 if it can't be done.* + +A couple of the logic exercises also stumped me and I used this [blog](http://gregorulm.com/coding-bat-python-logic-2/) to help me work through the answers. After trying exercises for awhile and being stuck it was really a big help. On the making chocolate exercise I had not made the connection to add a variable ```maxBig``` that could be used to determine if there was enough big bars to meet the goal. After figuring this logical step out, I was able to modify my code in a way that made sense to me and solved the problem. + +``` +def make_chocolate(small, big, goal): + maxBig = goal/5 + + if small + big*5 < goal or small < goal%5: + return -1 + elif big >= maxBig: + return goal - maxBig*5 + elif big <= maxBig: + return goal - big*5 +``` + +##Screenshots of Checkmarks + +![warmup2](http://i.imgur.com/yk6FTzi.png) +![strings2](http://i.imgur.com/sCZGonm.png) +![lists2](http://i.imgur.com/x561iyJ.png) +![logic2](http://i.imgur.com/Sc05cJa.png) diff --git a/_posts/2014-02-14-yonghao's-codingbat2.md b/_posts/2014-02-14-yonghao's-codingbat2.md new file mode 100644 index 0000000..e4210e8 --- /dev/null +++ b/_posts/2014-02-14-yonghao's-codingbat2.md @@ -0,0 +1,131 @@ +--- +layout: post +author: yonghao +title: yonghao's Second Codingbat's Practice +--- + +# Screenshot: + +**Warmup 2:** + +![Warmup2 image](http://farm8.staticflickr.com/7434/12529756494_b08e97ea26_o.png) + +**String 2:** + +![String2 image](http://farm4.staticflickr.com/3744/12529756534_d129b99e22_o.png) + +**List 2:** + +![List2 image](http://farm4.staticflickr.com/3832/12529404723_27a6c49f18_o.png) + +**Logic 2:** + +![Logic2 image](http://farm4.staticflickr.com/3745/12529756604_dcca04846f_o.png) + +# Comments: + + + +**List 2, sum67** + +I tried several ways and finally make it work. + +At first, I write another def called delete 67, it looks like this: + +``` +def delete67: + pos6=-1 + pos7=-1 + for i in range(len(nums)-1): + if nums[i]==6: + pos6=i + break + for j in range(pos6,len(nums)-1): + if nums[j]==7 and j>pos6: + pos7=j + break + del nums[pos6:pos7+1] +``` +Then I try to call the function in main function, it works for all the test, but failed in "other test". +I dont know what is "other test" and can't solve it, so I change another way. + +My code: + +``` +def sum67(nums): + for i in range(0, len(nums)): + if nums[i] == 6: + nums[i] = 0 + for j in range(i+1, len(nums)): + if nums[j] == 7: + nums[j]=0 + i = j + 1 + break + else: + nums[j]=0 + return sum(nums) + +``` + +The code works. Can anyone help me to find the error in former function? + +**List2 centered_average:** + +My thought: Travel all the elements in list, and each time call min and max method. every time compare the current element with the current min/max number. +And get the new min/max number. After we travel the whole array, we can get the min and max number in the array. And when can use the sum of all the numbers in list minus min and max number. + +My code: + +``` +def centered_average(nums): + min_1=nums[0] + max_1=nums[0] + result=0 + for i in nums: + min_1=min(i,min_1) + max_1=max(i,max_1) + for i in nums: + result+=i + return (result-min_1-max_1)/(len(nums)-2) + +``` + +**Logic 2: Make_Bricks** + +It's a little hard. I try different ways to solve it, and finally, I got idea from the help video and use mod to solve it. +Fitstly, I tried to use a loop to solve it, my code like that: + +``` +for i in range(big): + if 5*i= goal + +``` +It has two steps to judge. +Firstly: judge weather bricks are enough: + +``` +small+5*big>=goal +``` + +Secondly: Judge weather small bricks is enough. + +``` +goal%5 - small <= 0 +``` + +Then the problem is solved. It's a gret idea to use mod, and I think mod will help me in the future! + + +**Logic 2: make_chocolate** + +The problem is similar to make_bricks and I use a similar method to solve it. diff --git a/_posts/2014-02-15-Lei_PythonBasics2.md b/_posts/2014-02-15-Lei_PythonBasics2.md new file mode 100644 index 0000000..88dc104 --- /dev/null +++ b/_posts/2014-02-15-Lei_PythonBasics2.md @@ -0,0 +1,88 @@ +--- +layout: post +author: lei +title: Lei Wang's CodingBat Exercise2 +date: 2014-02-15 +--- + +# The Exercises + +**1. The first one I found hard was the Logic-2 exercise called make_bricks. In some cases, it needs to use lots of little bricks instead of a big brick. Finally, I found it can be simply coded as following.** + +``` +def make_bricks(small, big, goal): + goal = goal - 5*min(big,goal/5) + return goal-small <= 0 +``` + +**2. The second one I liked is the Logic-2 exercise called lone_sum. At first, I thought I should list all situation it might happen as following.** + +``` +def lone_sum(a, b, c): + if a == b == c: + return 0 + elif a == b: + return c + elif a == c: + return b + elif b == c: + return a + else: + return a + b + c +``` + + +**However, we can use 'not in' which make the script much more brief and neat.** + + +``` +def lone_sum(a, b, c): + sum = 0 + if a not in [b,c]: + sum += a + if b not in [a,c]: + sum += b + if c not in [a,b]: + sum += c + return sum + +``` + +**3. I found the most hardest is list-2 exercise called sum67. A lot of cases should be taken into consideration. At first, I came up with a script as following.** + +``` +def sum67(nums): + for i in nums: + if 6 in nums: + six = nums.index(6) + seven = nums.index(7) + for i in range(six,seven+1): + nums.pop(six) + return sum(nums) +``` + +**However, it cannot pass if the first 7 comes before the first 6. Then, after several tries, I got the following solution which works fine!!** + + +``` +def sum67(nums): + sum = 0 + flag = True + for i in nums: + if i == 6: + flag = False + continue + if i == 7 and not flag: + flag = True + continue + if flag: + sum += i + return sum +``` + +# The Screenshots +Here are my screenshots: +![Warmup-1 screenshot] (http://www.unc.edu/~leiw/images/python/warmup2.jpg) +![Lists-1 screenshot] (http://www.unc.edu/~leiw/images/python/list2.jpg) +![Logic-1 screenshot] (http://www.unc.edu/~leiw/images/python/logic2.jpg) +![Strings-1 screenshot] (http://www.unc.edu/~leiw/images/python/string2.jpg) diff --git a/_posts/2014-02-15-libbycodingbat2.md b/_posts/2014-02-15-libbycodingbat2.md new file mode 100644 index 0000000..c065e41 --- /dev/null +++ b/_posts/2014-02-15-libbycodingbat2.md @@ -0,0 +1,62 @@ +--- +title: Libby's Coding Bat exercises, Part Deux +author: libbby +layout: post +--- + +# The Exercises +Some of these were real doozies. I would have been entirely lost on some, were it not for the long winded people on stackoverflow who like to correct each other & provide detailed explanations. + +### 1. String-2: double_char +This was one of the easier ones for me - I got all green on the first go. If only the logic problems went so painlessly... + +_Given a string, return a string where for every char in the original, there are two chars._ + +``` +def double_char(str): + result = '' + for letter in str: + result = result + letter*2 + return result + +``` + +### 2. Logic-2: make_bricks +Oh dear oh dear oh dear. This problem. +For something that is 6 lines of code, it was incredibly hard to work out. +The first thing we need to do, is determine if there actually enough bricks total to meet the goal, whether or not they are the right sizes. If not, it's an automatic False. +If there are enough, we need to then determine what the remainder is when you divide the goal by 5. If there are enough small bricks to cover the remainder, it's True. +Otherwise, False. + +_We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops._ + +``` +def make_bricks(small, big, goal): + if goal > small + big*5: + return False + elif (goal%5 <= small): + return True + else: return False +``` + +### 3. Logic-2: no_teen_sum +This one took a little while, because for some reason I was getting hung up on what now looks like a really simple conditional. Just goes to show that taking a break can be VERY helpful when coding. + +_Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "def fix_teen(n):"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main no_teen_sum()._ + +``` +def fix_teen(n): + if(n>12 and n < 20): + if(n != 15 and n != 16): + n = 0 + return n +def no_teen_sum(a, b, c): + return (fix_teen(a) + fix_teen(b) + fix_teen(c)) +``` + +# The Screenshots +Here are my screenshots: +![Warmup-2 screenshot] (http://i972.photobucket.com/albums/ae206/fluffbrain/INLS560/screen_warmup2.png) +![Lists-2 screenshot] (http://i972.photobucket.com/albums/ae206/fluffbrain/INLS560/screen_list2.png) +![Logic-2 screenshot] (http://i972.photobucket.com/albums/ae206/fluffbrain/INLS560/screen_logic2.png) +![Strings-2 screenshot] (http://i972.photobucket.com/albums/ae206/fluffbrain/INLS560/screen_string2.png) diff --git a/_posts/2014-02-15-lyonscodingbatp2.md b/_posts/2014-02-15-lyonscodingbatp2.md new file mode 100644 index 0000000..6fa1f97 --- /dev/null +++ b/_posts/2014-02-15-lyonscodingbatp2.md @@ -0,0 +1,127 @@ +--- +layout: post +author: allen +title: Allen Codingbat Exercises Part 2 +date: 2014-02-15 +--- + +These Codingbat exercises were a bit more complicated than the last set. But most +of them were still pretty short, even if they took longer to figure out. Here's +the screenshots + +## Warmups 2 + +![Warmup Checklist](http://i.imgur.com/rE4d9cN.png) + +I completed the Warmups. + +##Strings 2 + +![Warmup Checklist](http://i.imgur.com/r3mcHCz.png) + +I completed the Strings + +##Lists 2 + +![Warmup Checklist](http://i.imgur.com/F57XrrU.png) + +I completed the Lists + +##Logic 2 + +![Warmup Checklist](http://i.imgur.com/n5JI1qx.png) + +I completed the Logic! + +And here are 3 exercises I thought were interesting and/or challenging and/or +the first three exercises because I was lazy and didn't want to look around for +the ones that were actually difficult or interesting. + +##string_splosion + +* +Given a non-empty string like "Code" return a string like "CCoCodCode".* + +I just like the word stringsplosion. + +{% include python %} + +def string_splosion(str): + result = "" + for i in range(len(str)+1): + result = result + str[:i] + return result + +print string_splosion('Code') +print string_splosion('abc') +print string_splosion('ab') + +{% include endpython %} + +##array123 + +*Given an array of ints, return True if .. 1, 2, 3, .. appears in the array somewhere. * + +I like this problem because it shows how important it is to test for every possible +case that might be entered. In this problem I was able to get a checkmark and +complete the problem by doing this: + +``` +def array123(nums): + if 1 in nums and 2 in nums and 3 in nums: + return True + return False +``` + +However this ignores a really obvious case which is if the numbers 1, 2, and 3 +are all in the array but not in the order 1, 2, 3. Weirdly, codingbat did not test +for that case and so I was able to complete the problem using code that doesn't work +for all cases. + +Here's the actual solution: + + +``` +def array123(nums): + for i in range(len(nums)-2): + if nums[i]==1 and nums[i+1]==2 and nums[i+2]==3: + return True + return False +``` + +Output: + +``` +array123([1, 1, 2, 3, 1]) → True +array123([1, 1, 2, 4, 1]) → False +array123([1, 1, 2, 1, 2, 3]) → True +``` + +##string_match + +*Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings.* + +This one tripped me up for a bit because the problem forgot to mention that one +string could be longer than the other one. So I was getting a lot of index out of +range results. After figuring that out, the problem was a fairly simple for loop +with a boolean expression to check the substrings. + +``` +def string_match(a, b): + count = 0 + shorter = min(len(a), len(b)) + for i in range(shorter-1): + if a[i] == b[i] and a[i+1] == b[i+1]: + count += 1 + return count +``` + +Output: + +``` +string_match('xxcaazz', 'xxbaaz') → 3 +string_match('abc', 'abc') → 2 +string_match('abc', 'axc') → 0 +``` + +That's my stuff! diff --git a/_posts/2014-02-16 madelinecodingbat2.md b/_posts/2014-02-16 madelinecodingbat2.md new file mode 100644 index 0000000..cc24caa --- /dev/null +++ b/_posts/2014-02-16 madelinecodingbat2.md @@ -0,0 +1,63 @@ +--- +layout: post +author: madeline +title: Madeline's Codingbat Post 2 +--- + +![] http://i.imgur.com/l3sQqbS.png + +This is not me at my most brilliant, but I did my best. + +## cat_dog + +Return True if the string "cat" and "dog" appear the same number of times in the given string. + +I found the answer to this one online. str.count is a built-in function. The reason there are not more of these is because Python would require almost infinite built-in functions to do the things required of it. + +``` +def cat_dog(str): + if str.count("dog") == str.count("cat"): + return True + else: + return False +``` + +## lone_sum + +Given 3 int values, a b c, return their sum. However, if one of the values is the same as another of the values, it does not count towards the sum. + +Since there are only three values in this one, I simply went through each scenario and used if statements for them. + +``` +def lone_sum(a, b, c): + if a == b == c: + return 0 + if a == b: + return c + if a == c: + return b + if b == c: + return a + else: + return a + b + c +``` + +## lucky_sum + +Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So for example, if b is 13, then both b and c do not count. + +Because there were only 3 values, I only had to go through the scenarios to find the sums. I am sure a loop would have been better. + +``` +def lone_sum(a, b, c): + if a == b == c: + return 0 + if a == b: + return c + if a == c: + return b + if b == c: + return a + else: + return a + b + c +``` diff --git a/_posts/2014-02-16-blucka12-codingbat2.md b/_posts/2014-02-16-blucka12-codingbat2.md new file mode 100644 index 0000000..0d52b9c --- /dev/null +++ b/_posts/2014-02-16-blucka12-codingbat2.md @@ -0,0 +1,54 @@ +--- +layout: post +author: blucka12 +title: Codingbat Exercise +--- + +``` +def lone_sum(a, b, c): +``` + + #first sign of green, brought to you by: + # lone_sum = int(a + b + c) + # return (a + b + c) + #then I worked on eliminating the variables that must be excluded, adding the "else" statement at the end: + +``` +lone_sum = int(a + b + c) + + if a == b: + return (c) + if a == c: + return (b) + if b == c: + return (a) + else: + return (a + b + c) +``` + + #that got me most of the way, with one red box left + + + + #I got an error for (3,3,3) ->0, and had to go back to the beginning and insert: + +``` + lone_sum = int(a + b + c) + + if (a == b) and (a == c): + return 0 + if a == b: + return (c) + if a == c: + return (b) + if b == c: + return (a) + + else: + return (a + b + c) +``` + + + #Yay + +Check out the io page here: http://blucka12.github.io/spring2014/ diff --git a/_posts/2014-02-16-jessicascodingbat2post.md b/_posts/2014-02-16-jessicascodingbat2post.md new file mode 100644 index 0000000..ee9eecf --- /dev/null +++ b/_posts/2014-02-16-jessicascodingbat2post.md @@ -0,0 +1,106 @@ +--- +layout: post +author: jskaa +title: Jessica's Coding Bat Post Part II +--- + +#Firstly, Those Glorious Screenshots + +###Warmup II + +![Warmup II Screenshot](http://puu.sh/6YW9l.png "Warmup II") + +###String II + +![String II Screenshot](http://puu.sh/6YWcE.png "String II") + +###List II + +![List II Screenshot](http://puu.sh/6YWeA.png "List II") + +###Logic II + +![Logic II Screenshot](http://puu.sh/6YWbr.png "Logic II") + + +#The Interesting Bits + +###Logic II: make_chocolate + +I don't know why I struggled with this one, when it was so similar to the previous make_bricks problem in the same set. +I think it was mostly just getting tripped up with the information given to me and my new variable which I had defined. I spent +over 10 minutes changing pieces of the code and getting a bunch of reds, but after breaking out the pencil and paper, +it was smooth sailing. It really helps to write out the math sometimes, even if it is very simple! + +My solution ended up being: + +``` +def make_chocolate(small, big, goal): + max_big = goal / 5 + + if big>=max_big: + if small >= (goal-(max_big*5)): + return goal-(max_big*5) + else: + return -1 + elif big=goal-(big*5): + return goal-(big*5) + else: + return -1 +``` + +There is probably a way of writing this which is much shorter and more efficient, but this way makes all the +calculations very clear, which is quite nice for a beginner like me. + +###List II: sum67 + +This one gave me the most trouble, but at least I learned something cool in the process! For the previous sum13 problem, +I came up with what may be a sort of patchwork answer by finding all items where were 13 in the array, and setting those, +as well as the next immediate item in the array equal to 0, then summing up the array of integers. However, I couldn't +do that for this one, because obviously I don't know how many numbers to get rid of. I first tried slicing, but it got +pretty messy and I scratched that. So, what to do? Well, I went and bothered a programmer friend of mine for some hints. +He gave me a bit of a hint to create a boolean variable which would either sum or not sum the item at that index based +upon it being True or False. Eureka! (or not so much a sudden 'Eureka' as a mistake-filled 10 minutes of trying to think +through what in the world I was doing. It's much easier when things are verbose! + +My end code was: + +``` +def sum67(nums): + skipping = False + sum = 0 + for i in range(len(nums)): + if nums[i] == 6 and not skipping: + skipping = True + + elif nums[i] == 7 and skipping: + skipping = False + + elif not skipping: + sum += nums[i] + return sum +``` + +Once again, there might be a more succinct way of writing it, but this is nice and easy for anyone to glance at and +understand. + +###String II: end_other + +Good thing we had that hint! Before clicking on the hint, I was preparing to figure out a way to go through each few +items and then compare the strings. I'm not even sure how I was planning on doing that! Luckily Python has several +very nice methods which are there to make our lives easier. Just a nice little example of how knowing what tools you +have available can make things much easier! + +My code was: + +``` +def end_other(a, b): + a_lower = a.lower() + b_lower = b.lower() + return a_lower.endswith(b_lower) or b_lower.endswith(a_lower) +``` + +Nice and simple! + + diff --git a/_posts/2014-02-16-juliesecondbat.md b/_posts/2014-02-16-juliesecondbat.md new file mode 100644 index 0000000..abce5d7 --- /dev/null +++ b/_posts/2014-02-16-juliesecondbat.md @@ -0,0 +1,53 @@ +--- +layout: post +author: julie +title: Julie's Second Coding Bat Exercise +--- + +First, here's my checkmarks: + +![Turtle Image](http://i.imgur.com/JuPqneq.png) +![Turtle Image](http://i.imgur.com/Baj9FiR.png) +![Turtle Image](http://i.imgur.com/mQaRugX.png) +![Turtle Image](http://i.imgur.com/QogGbkv.png) + +As you can see, I couldn't figure out the sum 67 one. + +The first one I thought was interesting was the string exercise **end_other.** With this exercise and others, it took me a while to realize that I needed to use the string methods, but once I did, everything was a lot easier. I realized that for this one I first had to turn all the strings into all lower case so that it could comepare them. Here is the code: + + +``` +def end_other(a, b): + a = a.lower() + b = b.lower() + if b.endswith(a) or a.endswith(b): + return True + else: + return False +``` + + +I also liked the **lucky_sum** one because I thought it was pretty easy and I figured it out right away, although I wonder if there is a shorter way to solve it rather than going through every possibility: + + +``` +def lucky_sum(a, b, c): + if a == 13: + return 0 + elif b == 13: + return a + elif c == 13: + return a + b + else: + return a + b + c +``` + +Finally, I liked the **big_dif** exercise because I was proud of myself for coming up with such a short, easy solution: + +``` +def big_diff(nums): + return max(nums) - min(nums) +``` + + + diff --git a/_posts/2014-02-16-secondcodingbatsierra.md b/_posts/2014-02-16-secondcodingbatsierra.md new file mode 100644 index 0000000..24e5863 --- /dev/null +++ b/_posts/2014-02-16-secondcodingbatsierra.md @@ -0,0 +1,56 @@ +--- +layout: post +author: srmoore5 +title: Coding Bat 2 +date: 2014-02-16 +--- + + +Screenshot + +![codingbat2](http://farm3.staticflickr.com/2812/12575600995_61167fc5a3.jpg) + + +3 Interesting Exercises + +Logic 2 lucky_sum +- simple, logical and fun + + +``` + +def lucky_sum(a, b, c): + if a == 13: + return 0 + elif b == 13: + return a + elif c == 13: + return a + b + else: + return a + b + c + +``` + +String 2 count_hi +I forgot how to do this one for a moment. + +``` +def count_hi(str): + a = str.split('hi') + return len(a) - 1 + +``` + +Warmup 2 array123 + + +``` +def array123(nums): + # Note: iterate with length-2, so can use i+1 and i+2 in the loop + for i in range(len(nums)-2): + if nums[i]==1 and nums[i+1]==2 and nums[i+2]==3: + return True + return False + + ``` + diff --git a/_posts/2014-02-19-Ha.md b/_posts/2014-02-19-Ha.md deleted file mode 100644 index 1d11d96..0000000 --- a/_posts/2014-02-19-Ha.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -layout: post -author: Grant -title: Grants's first post ---- - -I totaly stole Elliot's first test post. - -Here's the text of my post. - -## This is a heading - -**this is bold** - -*this is italics* - -* this -* is -* a -* list diff --git a/_posts/2014-02-19-nitrouspostklm.md b/_posts/2014-02-19-nitrouspostklm.md new file mode 100644 index 0000000..f929ca1 --- /dev/null +++ b/_posts/2014-02-19-nitrouspostklm.md @@ -0,0 +1,9 @@ +--- +layout: post +author: katielmeyer +title: Nitrous test post +date: 2014-02-19 +--- + + +Another Nitrous test... \ No newline at end of file diff --git a/_posts/2014-02-19-simpleblogklm.md b/_posts/2014-02-19-simpleblogklm.md new file mode 100644 index 0000000..c50f583 --- /dev/null +++ b/_posts/2014-02-19-simpleblogklm.md @@ -0,0 +1,87 @@ +--- +layout: post +author: katielmeyer +title: Simple Flask blog +date: 2014-02-19 +--- + +My blog is currently live on heroku: http://silshack-katielmeyer.herokuapp.com/ + +When I first tried to deploy the blog in class I got an 'application error' when I tried to view the app. After Grant fixed the environment setup script, +I followed the instructions on the smartypant's blog under Trouble, and was annoyed that it didn't same to make any difference: the error was still +there. It's really convenient that Grant handled all the complexity behind the app to make it easier, but the downside of skipping that complexity +is that you can't really debug if you're not learning the process yourself. So I figured since it was only a few short steps anyway, I'd scrap the whole +thing and follow the steps again, assuming it was my error and I'd missed something. It was only after I got the new blog app on heroku that I realized +I'd just forgotten to push the changes from the fixed scripts to heroku... + +Anyway, now that it's up there, I really like this app! It's certainly no WordPress, the name 'Simple' is very fitting. But it does +just about everything you'd need a little blog to do. + +One weird thing I noticed: I uploaded a JPG of a piglet through the browser admin interface (because, why not) into my first post. It worked fine. +I pulled the udpates from heroku, then I changed my font in the settings.py config file, and pushed back to heroku. Somehow that broke +the image link. I checked the simplhack uploads folder and saw it wasn't there, so I uploaded it to that directory through nitrous, committed, pushed. +(I've had similar issues at work with version control software, Rational Team Concert, not transferring images). No luck. Here's where a little more +complexity in the admin interface might be useful. + +UPDATE: About five minutes after writing that I figured out the filename the blog post was referencing was one it had assigned to the upload image. +When I manually changed it to match the filename of the image that was actually in the uploads directory, it worked fine. So maybe there's still +a problem with pulling down images from the heroku instance of the app into nitrous, but I guess you can push them into heroku from nitrous. + +I played around a bit in the CSS, changing some of the text formatting. I didn't like the red hover text, so I switched it to blue in layout.css. + + +I also wanted some special formatting on the blog title text, so I added a new class for it on the h1 element in the layout template, and +got rid of the line break element (
) to bring the tagline up a bit... + +``` +
+

{{ config.BLOG_TITLE }}

+ ``` + + ...Then added styles for it in layout.css. + +``` + +h1.blog-title a{ + font-size: 60px; + font-family: 'Shadows Into Light', serif; + color: #555; + border-bottom: none; + line-height: 55px; +} +h1.blog-title a:hover { + color:#04E0CA; +} + +``` + +And I wanted a special Google font (Shadows into Light) for that blog title, so I had to tack it into on the layout template. + +``` + + + +``` + +Finally, to play around with the layout I nixed the fixed sidebar (so it'll scroll down with the posts) and increased the sidebar width. Since this app +uses Bootstrap (a 12-column responsive framework, http://getbootstrap.com/) I could do that easily in the layout.html template by just changing +the classes of the div elements for the sidebar and main content. + +For the sidebar: + +``` + +
+ +``` + +For the main content: + +``` + +
+ + +``` + +Since my sidebar isn't fixed anymore, I got rid of the 'hidden phone' columns between the sidebar and main content. diff --git a/_posts/2014-02-19-thetestiness.md b/_posts/2014-02-19-thetestiness.md new file mode 100644 index 0000000..24b0cb8 --- /dev/null +++ b/_posts/2014-02-19-thetestiness.md @@ -0,0 +1,16 @@ +--- +layout: post +author: blucka12 +title: The Tastiness, Baybay! +date: 2014-02-19 +--- + +``` +Here we go again, baby!!! + +#I am certain that I will forget something, but it will work out... + +#I'm feeling fairly uplifted by the smoothness of this Nitrous business... + +``` + diff --git a/_posts/2014-02-20-mandysimpleblogpost.md b/_posts/2014-02-20-mandysimpleblogpost.md new file mode 100644 index 0000000..129f668 --- /dev/null +++ b/_posts/2014-02-20-mandysimpleblogpost.md @@ -0,0 +1,25 @@ +--- +layout: post +author: agooch +title: Mandy's Simple Blog Post Adventure +--- + +Here is my blog: http://silshack-agooch.herokuapp.com/. It isn't much, but it's functional. + +As for my process, I can honestly say I was doing very well until getting to the ./setupenv1.sh portion of the exercise. Since it was busted, I was unable to finish my assignment in class. This meant I had to pick up from where I left off, but I ran into more issues when Nitrous kept giving me errors. + +I decided to just scrap everything and start over, because it was getting frustrating. After this, my code worked perfectly and I was able to push everything through to the heroku master. + +I will freely admit that it took me a bit to figure out where to go from there. I went into the simple.py file, but was not sure what I was supposed to do. Anyway, I realized at some point that I needed to checkout my actual app page. I went there and added the /admin to the URL to log in. + +The interface is really simple, so it was pretty easy to figure out. I created a basic post and used the drag and drop feature to add a picture that was sitting on my work computer. + +As for the bonus section, well, I didn't really want to mess up the app's layout too badly, so all I did was edit some of the colors in the layout.css file. I also added an image to the 404 template that I found on Google. Nothing too big, but it was nice to see the edits reflected in my page after pushing them through Nitrous. + +Note: I did have an issue at one point when editing. I changed some colors to the CSS layout page and pushed it through. When I went back to my blog the image of my dog was no longer visible. I'm not sure why this happened and couldn't find anything in my code, so I just deleted the post and created another one. + +I got my color codes here: http://www.huecode.com/ + +Here is the 404 image: + +![404 Image](http://i.imgur.com/4foYoqY.jpg) diff --git a/_posts/2014-02-20-zbaySimple1.md b/_posts/2014-02-20-zbaySimple1.md new file mode 100644 index 0000000..3a91917 --- /dev/null +++ b/_posts/2014-02-20-zbaySimple1.md @@ -0,0 +1,12 @@ +--- +layout: post +author: zbay +title: Zach's First Simple Post +date: 2014-02-20 +--- + +I made my first post on SimpleHack. It's nothing much, as you'd expect for a first post. You can find my post at [this link](http://silshack-zbay.herokuapp.com/). + + +As I understand it, I executed some scripts that set up a blogging application on top of a database in a cloud environment. At first, I thought that I had to code within simple.py in order to make a post. This seemed a far from simple task, and required some serious code comprehension. More careful reading of the _instructions_, however, clarified that I merely had to log in as an admin to make a post. What a relief! +Truth be told, I'm fuzzy on how Heroku works. I'm sure I'll figure it out as we work on it in through class. diff --git a/_posts/2014-02-21-ThuMaiSimpleHack.md b/_posts/2014-02-21-ThuMaiSimpleHack.md new file mode 100644 index 0000000..f63b682 --- /dev/null +++ b/_posts/2014-02-21-ThuMaiSimpleHack.md @@ -0,0 +1,28 @@ +--- +author: tlchristian +title: Thu-Mai's Simple Blog Post Post +layout: post +date: 2014-02-21 +--- + +This week was an interesting exercise in the mechanics of pushes and pulls. I am a very visual person, so I'm glad that Elliott provided diagrams explaining how data get moved between our individual repositories to the primary class site. It helped me tremendously in understanding what this git business is all about. Thanks for that. + +After Grant's on-the-fly debugging, I was able to easily go through the process of setting up my instance of Simple onto Heroku. Simple it is. I checked out the .css files to see if I could hack the layout and make pretty colors and fonts. I was able to make some color changes by playing with the code below in the layout.css file: + +``` +body { + background: #fff; + color: #222; +} +``` + +I quickly realized that this defeats the purpose of the whole Simple layout concept. Minimalism it is. (Though at the same time, I am digging what Katie did with her Simple blog--a nice balance of minimalism *and* style.) + +I also have to point out that tech folks have awfully good customer service. I had some issues with my nitrous.io box hanging up. Apparently, there was a huge traffic surge in our area at the time, which likely caused my box to be unable to connect for a while. All was well just a few minutes after I sent them a note. Very cool. + +And [here is my first Simple Blog post](http://silshack-tlchristian.herokuapp.com/). Kids and iPhoto are hilarious! + + +--- + + diff --git a/_posts/2014-02-21-herokusierra.md b/_posts/2014-02-21-herokusierra.md new file mode 100644 index 0000000..7292e63 --- /dev/null +++ b/_posts/2014-02-21-herokusierra.md @@ -0,0 +1,21 @@ +--- +layout: post +author: srmoore5 +title: Heroku Nitrous Sierra Post +date: 2014-02-21 + +--- +Here is a link to my Heroku Blog: http://silshack-srmoore5.herokuapp.com/?page=0 + +The process of creating a Heroku blog seemed simple. Over time I became frustrated +but I later realized that internet connectivity issues at UNC was causing the problem! +After much refreshing, pulling, adding and typing incorrect commands--my blog appeared +and it worked. Annoying, but worth it? Yes. And I do enjoy typing my posts in Nitrous instead of +Github which requires an excessive about of committing. I always edit my work many times throughout +the process and Github is not very friendly towards excessive editors. + +Fortunately, being able to access Nitrous and Heroku on any computer saved the day when I was unable +to use the internet on my mac. Thanks to help from Grant--I am done! I'd like to try creating more apps and +see how they interact with one another. I do have a second app, but I'm not entirely certain how to +use them together without confusing myself. + diff --git a/_posts/2014-02-21-sunhwaherokupost.md b/_posts/2014-02-21-sunhwaherokupost.md new file mode 100644 index 0000000..148c0e7 --- /dev/null +++ b/_posts/2014-02-21-sunhwaherokupost.md @@ -0,0 +1,42 @@ +--- +layout: post +author: sunhwap +title: sunhwa's heroku first post +date: 2014-02-21 +--- + +After SSH key was added to my Heroku account, I was able to go on to my heroku site: +http://silshack-sunhwa.herokuapp.com. The site let me type my first post when I added /admin to this url. +I made some attempts to make a few changes to CSS layout codes to hope to get the site to look better but failed. +Then I later realized thanks to Grant's help that I have to do git push for the changes to be reflected on Heroku site. +So to make a change in background color to Heroku site, I inserted the background color code in the layout.html: + +``` +