Table of Contents

Kris Brown's fall2013 Opus

Now cracks a noble heart. Good-night, sweet Fun; And flights of angels sing thee to thy rest.

About Me

I'm filling this introduction space out, not just because I have to, but because I really want to. I enjoy eating regularly every day and getting an occasional seven to nine hours of sleep every twenty-four hours. I've never died before. I like music and things that I find funny. I don't like things that give me negative emotional, psyhical or mental responses. I have friends and enjoy their company. Visit my blog at blog.jeffgerstmann.net

C/C++ Programming Journal

The Week of August the 29th, 2013

During the first week of class we spent a lot of time familiarizing ourselves with the lab46 interface. As someone who has never involved myself with any type of ssh or IRC it was interesting experience doing both. While the IRC for our class chat is nice I'm not sure how much use I'll get out of it since it seems to be filled with people making jokes at each other. However, that may change over time as we begin more involved coding projects.

Speaking of coding we learned how to create output in C using the standard “Hello World” example. The code is as follows:

#include<stdio.h>
 
int main(int a, char** b) {
   printf( "Hello, World\n");
   return 17;
}

The first line of the code 1) tells the compiler to include the information from the standard input/output library. In the second line main is used to tell the program to begin executing the curly brace following it's function arguments indicates the statements that will go into the function “main”. printf is a function which when called produces the output of whatever is in the following parenthesis. In this case the produces output is a string of characters followed by the special characters “\n” which serve as a shorthand way to write the character for “New Line”. The semicolon after tells the compiler to execute the entire line then stop. The following line 2) simply tells the program to assign the number 17 to the output. The assigned number is arbitrary and serves only as an example of return values. Finally in the last line is an ending curly brace denoting the end of the statements involved in the “main” function.

Now that code is written and understood 3) it must be compiled. The code is saved as any file with the name ending in “.c”, I used the name “First.c” because that's the name the professor gave it. Since lab46 is a Linux environment the program we use to compile code is gcc, so we write “gcc First.c” in the command prompt in whichever directory the code was saved in. If not typed incorrectly the command prompt simply returns nothing. If looked in the directory an output code will now exist and, unless otherwise instructed, was named a.out. Now if you want to actually see the output you shouldn't type something like “view a.out” because for some reason it turns the entire command line interface into unreadable computer garbage and then you might as well just restart the terminal and work your way back to the directory. To produce the output you just need to type “./a.out” 4) and a line returns that reads “Hello, world” or whatever you typed in the printf argument. Then to see my returned value of 17 I just type “echo $?” which echoes the value of the last command entered.

That about sums up what I've learned in the first week of C/C++. I think I'll have some issues in the future understanding where things in the book “The C Programming Language” by Brian Kernighan and Dennis Ritchie differ from what we learn in class. For example, in the book it states the code for a Hello world program is:

#include <stdio.h>
 
main()
{
  printf("Hello, world\n");
}

In the book's version of the code the “main” function is passed no arguments and does not have “int” written before it. It seems that I should probably google it or ask the professor, but that seems like work for another day.

The Week of September the 6th, 2013

This week in cprog we learned about data types. The data type something is determines the possible values of that thing, the operations that can be done on that thing, the meaning of the data and the way that data is stored. We wrote a nice program that reports the size of some datatypes as well as their total range of values. The types we tested were the signed and unsigned types of char, short integer, integer, long integer and long long integer. Finding the values of the unsigned types was simple.

First you would have to declare the variable and initialize it's value:

  unsigned char uc;
  uc=0

Now you print the outputs inserting the variable into the string when needed:

  printf("An unsigned char is %hhu bytes\n", sizeof(uc));
 
  printf("Lower bounds is %hhu\n", (uc));
 
  printf("Upper bounds is %hhu\n", (uc-1));

The characters “%hhu” tell the code to expect some value and insert that into the string. Since the characters are hhu the value expected is an unsigned short short integer, or char for short. The sizeof function reports the byte size of the value in it's argument. A char happens to be 1 byte in size. In the second printf it simply returns the lower range of a char as zero since that's what I set uc to equal and any unsigned value cannot go lower than zero. In order to get the upper range of a char I simply subtracted 1 from the value of uc, and since uc cannot go below zero it just wraps around to it's highest value which is 255. The way to find the values for a signed datatype is more involved. Naturally I declared the variable and initialized it first.

  printf("A signed char is %hhd bytes\n", sizeof(sc));
 
  printf("Lower bounds is %hhd\n", ('(unsigned char)(uc-1)/2)+1);
 
  printf("Upper bounds is %hhd\n", ('(unsigned char)(uc-1)/2));

The reason for the d in “hhd” is because the “d” stands for “signed” where the “u” stood for “unsigned”. The reason for the ('( thing going on in the two last lines is because wiki syntax thinks I'm trying to make a footnote if I have two parenthesis right next to each other5). The apostrophe isn't suppose to be there at all and you should not write it if you're trying to copy this. As you can see by using some clever math magic we can find both the upper and lower ranges without having to do it in a calculator and then just copy the numbers down. The reason this works is because (uc-1)/2) makes the unsigned char variable created earlier have a value of half it's highest value. Since unsigned chars don't have floating point it rounds down to the nearest number which happens to be the highest value of a signed char which is 127. Then to make the lower value we just add one to it and report it as a signed char, since the signed char can't go that high it wraps around to it's lowest value which is -128. The reason signed upper ranges aren't the same number just with a different sign is because zero is considered a positive number. Now this is just repeated for the others replacing things when needed. Thanks to this program I learned that a long int and a long long int have the same values.

In reference to my previous journal entry the reason for our hello world code to have “int main(…” is because we wanted our code to return an integer. People write code like that when they want to use the return value of the program later. If the program is a program6) that the programmer intends to run as long as the machine is on then they wouldn't care about any return values and just leave that junk blank.

The Week of September the 13th, 2013

In cprog this week we had soooo much fun!7) We wrote some code to make usage of user input and program arguments. The first program we did would return a user's name, their first initial and their age. It was also an introduction to scanf and pointer variables. Some examples of important lines in this program are:

char *name;
name=NULL;
name=(char*)malloc(sizeof(char)*20);

In these lines we come to understand the use of memory allocation and arrays. In line won we set aside a char size variable and with the character “*” the variable has been specified to be a pointer variable that when called will point at a specific piece of memory and retrieve data from it. Next we have to set name to a specific value otherwise it might by default access memory we don't have permission to and the operating system will get upset. The Then on the last line we actually set aside a specific size of memory for name to point to. In that line we specify that the memory allocated by “malloc” will be the number of bytes in a char times twenty. 20 bytes. Moving on:

scanf("%s", name);
fi=*(name+0);
printf("%s, your name is %c(%hhu) and you are %hhu years old\n", name, fi, fi, age);

In the first line scanf is expecting some string because we wrote “%s” and whatever is entered is then passed to the alloced memory that is pointed at by name. In the second line we take the initial position of the array pointed to by name and assign to a variable we already created before called “fi”. In c arrays are counted starting at 0 so if we put 1 it would instead take the second letter of whatever was written into name. Then in the printf statement we just pass the array pointed to by name into the first part there then the “%c” denotes a character and the %hhu will return a number value of that character which should be the ASCII value for the character. Then it just spits the age back, we also made a variable for age and had scanf lines for that but there is no reason to write all that again.

The Week of September the 20th, 2013

Can you say “graphic design”? Can you say “pixels”? Can you say “visions of sugar plums dance in their heads”?. Well you don't even need to say it because you can express that stuff in C8). We learned all about the gd library of functions? “What's gd?”, I hear you ask as you struggle to contain the curiosity building in your undulating vocal chords. Well my friend, my dearest ally, my greatest companion in this cold lonely world, let me tell you. gd is a group of functions designed to let a user create images in the C language using colours and pixels. My the images you can create are boundless, you can create lines, rectangles, polygons and even spheres. Here is some choice lines on how you might start to do so:

#include<stdio.h>
#include<gd.h>
#define WHITE 4
File *out; //This line creates a file which will later have data put into in.
char outfile[] = "some location"; //This line decides where about the file will be sent.
gdImagePtr img; //This line initializes an image given the variable name img.
gdImageCreate (wide,high); //In a couple of lines not included I created the variables wide and high then gave them value. The image will now have a size equal to widexhigh pixels.
color[WHITE] = gdImageColorAllocate(img, 255, 255, 255); //An understanding of RGB color values tells us that 255,255,255 is pure white, which we have assigned to a variable named white.
gdImageFilledRectangle(img, 0,0, wide-1, high-1, color[WHITE]); // This line creates a white rectangle that takes up the entirety of the image size, it's white because it's a background.
out=fopen(outfile, "wb"); // The wb stands for "write, binary file"
gdImagePngEx(img, out, -1); //This line creates a png image which is sent to out.
fclose(out); //Now that out is sent the image and the image is sent to where it's stored we don't need out anymore after this program is run
gdImageDestroy(img); //This line destroys the variable "img", because we need to save space or something like that

Using these lines as a basis, and a further understanding of the gd library of functions, I have created a pretty image of a house, a snowman, and the logo for corning community college.9)

The Week of September the 30th, 2013

“Haha, those fools. By letting the government shut down they have released me, Sting'zorga, The King of Wasps”. With a crack of thunder and a flash of lightning Sting'zorga flew from his earthy prison deep beneath Monk's Mound10). A terrible darkness fell upon the world. “Now they cannot stop me, and I will do to them what I did to Whitney Houston”.

Meanwhile in the Hall of Justice11)! Flint Ironstag was just finishing up his daily regiment of one thousand squats and one thousand dead-lifts when he heard the familiar sound of Scooby's voice that was his ringtone. “Flint it's Obama, the president.” came a voice on the other line. “Yeah I know who you are”, Flint said. “Is this about Sting'zorga?”

“How did you know?” Obama said, shaking in his fashionable, yet professional, black shoes.

“I've known about him since what he did to Whitney. You tried to cover it up, but I saw past your schemes”. Flint took a swig of his trademark protein shake made from camel blood and crow brain.

“Please Flint, we need you to stop him. Do it for America. Do it for the government.”

“I'll do it, but not for America. Not for the government. I'll do it for Whitney.”

“Oh thank you Flint. Please hurry.” Obama begged.

“I can't hurry.” Flint said coolly. “Cardio kills gains.”

Flint arrived as fast as he could to the grave of Whitney Houston. “I knew I would find you here. Your hatred of Whitney makes you too predictable.” Flint said to the towering monstrosity that was the king of wasps.

“Ah Flint, you poor soul, you know you cannot stop me. No earthly weapon can imprison me, not since the Cahokia people have been destroyed.”

“Sting'zorga you are as arrogant as you are the king of wasps, by which I mean entirely. The knowledge of the Cakokia have been catalogued and preserved in a powerful language known as “C” the C stands for Cahokia.” Flint produced a laptop opened to the lab46 webpage. “Look upon my works ye mighty beast, despair!” As Flint Ironstag turned his laptop around to face Sting'zorga a image of polygons created using the gd library and a knowledge of arrays for the vertex coordinates appeared on the screen12).

“NO! C ARRAYS ARE MY ONLY WEAKNESS! CURSE YOU FLINT YOU HAVE DEFEATED ME.” A great flash of light turned the eternal darkness of Sting'zorga's wrath into a tremendous blinding flare. When the dust had settled and Flint regained his sight he saw Sting'zorga again. But he was different, smaller, less aggressive, preoccupied with the mountainous bouquet of flowers that was left on Whitney's grave. Sting'zorga was no longer the king of wasps, he was the king of bees. Within seconds Sting'zorga contracted colony collapse disorder and died. Flint took out his cell phone called Obama.

“It's over Obama, Sting'zorga is dead. Whitney has been avenged. And it was all thanks to the C programming language.”

“Oh glorious, wondrous day. In honour of your victory over Sting'zorga I'm making C the official language of America. And I'm giving Monsanto the highest civilian honour for creating the pesticides that are destroying the bee population worldwide.” Obama quickly hopped out of his chair and ran to Congress to tell the good news. Unfortunately the government was shutdown and Obama forgot Washington D.C. was closed until further notice. “I guess I'll just do it some other time.” He said in a dejected tone. With a slump in his shoulders and disappointment on his face he walked back to the Oval Office to complain about the ending to Breaking Bad of whitehouse.gov.

The Week of October the 3th, 2013

We also did some stuff with srand and we created our own function but whatever. scanf is the best input function ever.

The Week of October the 11th, 2013

This week we did a knowledge assessment and i made a whole bunch of binary operators in C. The binary operators were Not, And, Or, Exclusive Or, Halfsum, Halfcarry, Fullsum and Fullcarry. They were functions which I made in a file I called logiclib.c. The Not function is:

char nott(char biel)
{
     if (biel=PREFERRED)
         return(OTHER);
             else if (biel=OTHER)
                     return(PREFERRED);
                         else
                             return(1);
}

What it does is it takes a binary element(biel) and if the biel is the preferred character(this was initialized in a different area of the code) then the function returns the other character. If function is passed the other character it returns the preferred character. If neither are passed to the function then the function just returns “1” to signal that an error has occurred. The other operators work similarly.

qmowf.jpg

The Week of October the 18th, 2013

An introduction to C++ WOW WHAT AN ADVENTURE WE'VE EMBARKED ON. The important thing to know about C++ is that it's object oriented. This means it has classes and objects. I'm currently taking Java, so I'm not sure exactly what a class or object is, but It has something to do with combining functions and datatypes together, so that each function keeps the same datatype and you don't have crazy mazes of datatypes to work around. The first class we did was about animals. I named mine cats because cats were the first animal mention.

class animal{
   public:
      void listen();
      void tell(char *);
      animal();
      animal(char *);
   private:
      char sound[80];
};

This is what's called a class declaration. In the class declaration it sets out the public and private methods of the class. Here we can see the class has 4 public methods and one private method.

void animal :: listen()
{
    printf("%s\n", sound);
}

This is an example of method. Methods are like functions, feel free to use both words interchangeably and use both them in your code interchangeably as well. When defining the method of a class you must include the name of the datatype it returns, the name of the class followed by two colons and then the name of the method and it's parameters. This is so the method knows what it's returning and what class it belongs to. Methods are really ignorant and need to be reminded these things.

The Week of October the 25th, 2013

We did even more object oriented stuff but this time with shapes. Shapes are the craziest thing you could possible think of.

#ifndef _SQUARE_H                                                                     
#define _SQUARE_H
 
class square{
    public:
     square();
     void setside(int);
     int getside();
     int area();
     int perimeter();
   private:
     int x;
};
 
#endif
#include "square.h"                                                                   
 
 
square :: square()
{
x=0;
}
 
void square :: setside(int side)
{
    x=side;
}
 
int square :: getside()
{
    return(x);
}
 
int square :: area()
{
    return(x*x);
}
 
int square :: perimeter()
{
    return(4*x);
}

Above are the codes for a class definition of a square and the functions that go along with a square. Here you can see that it calculates area by multipling the sides together and calculates perimeter by multiplying one side by 4. I also made classes for a rectangle and a triangle.

The Night of November the First, 2013

13)

Wizard People, Dear Reader

The fantasy young adult series of books known as “Harry Potter” is a culturally phenomenon loved both by the people of my generation whom it was aimed at when the first book was written, but it also captures in people a true sense of adventure that seems to be universal. We should really ask ourselves why that is? What draws so many people of different backgrounds and personalities to this story? Nothing about Harry Potter seems to be truly original. Centaurs were imagined as a Greek myth, most likely as a cautionary tale about the dangers of trans-species loves, a theme that much like The Golden Mean or the dangers of hubris is constant throughout every Greek Myth. Horcruxes were a derivative of Sauron's ring of power, both of them have the same purpose in each story, which itself was already a retelling of Scandinavian myths of old. And perhaps that's really it.

People don't generally like truly unique things, at least not such a large grouping of people as the fans of Harry Potter. There are no absolutely unique stories left in the world, one man even proposes that there are only some forty or so stories possible with each piece of writing just being a type of one of those, or perhaps the type changes throughout the story. J.K. Rowling is no savant of literary wit. She bares no likeness to Mark Twain or James Joyce. The world she built with the Harry Potter novels falls far in comparison to the world's constructed by Tolkien or George R.R. Martin. What she succeeds in is the crafting of a narrative that uses familiar tropes and elements in such a way as to become truly universal. She has created a fantasy series that appeals to everyone. The easily disengaged reader looks at Lord of the Rings and scoffs at it's pacing and often overwhelming use of history. A Song of Fire and Ice is both too explicitly violent and sexual for any adult to condone letting their ten year old child read. Rowling has done for fantasy what Douglas Adams has done for Science Fiction, she has created a world with a lack of consistency that becomes glaringly apparent under any scope that is only somewhat critical, yet nobody cares. And we don't care because we're so excited for these characters and what wacky adventures they will have next.

“Wizard People, Dear Reader” is a retelling of the first Harry Potter movie by Brad Neely. The audio-track which is to be played alongside a DVD copy of the movie brings to light every valid criticism of every ridiculous cliche and use of trope in Harry Potter. It is an intelligent glaring criticism, and a loving parody, of Harry Potter that is so brilliant in it's execution it is disgusting. Brad Neely has created with this work something that presents itself initially as something so moronic that when it becomes apparent that it is in fact a work of hellish intelligence that it gives the listener a case of mental whiplash. The intellectual juxtaposition between the premise, the voice of Brad himself, and the things he says was so impressive that I found it so hard to believe I was hearing what I actually was. Brad's use of simile in this work is so outlandish and hyperbolic, but when paired with the over-the-top atmosphere of the entire event every simile becomes a reattachment to the reality of what you're viewing as well as an apt analogy for the often eerie, and hard to describe, feelings you experience when watching a movie that takes itself seriously while at the same time listening to a retelling that blatantly points out each inconsistency and appropriation of any literary trope throughout the entire story. The feeling you experience is what's known as cognitive dissonance, where your brain holds two conflicting ideas and forces upon you a feeling of guilt and confusion. The manifestation of this confusion creates a hilarious atmosphere that serves to lighten the mode of the criticism. You may not know that you just listened to someone fully, and unmercifully, deconstruct a beloved, possibly by you, fantasy series but your brain did.

“Wizard People, Dear Reader” is everything an intelligent critic should strive for. It's relentless wit is frightening and undeniably entertaining.

The Week of November the Eighth, 2013

This week we did some more stuff on the BigNum class. I created a decrement method. <codec> #include “bignum.h”

void BigNum::decrement() {

      int i=1;
      *(data+(length-1))=*(data+(length-1))-1;
   while(*(data+(length-i))!=0)
   {
     if (*(data+(length-i)) == 255)
     {
       *(data+(length-i)) = base-1;
       *(data+(length-i-1)) = *(data+(length-i-1))-1;
       i++;
     }
     else
     {
     break;
     }
   }

}

The most notable thing happening here is the line “if (*(data+(length-i)) == 255)” because what was happening when I was subtracting 1 from zero the char was rolling over up to 255, which produces a bunch of crazy character combinations. That is statement checks for if a spot becomes 255 then the next twos line change the 255 to whatever the base is minus 1 (so base 10 will give 9 as a result to that) and then subtracts one from the number to the left of that number. This works down an entire line of numbers. </code>

UNIX/Linux Fundamentals Journal

The Week of August the 29th, 2013

Much like in C/C++ programming we spent most of the week getting familiar with the lab46 interface and class chat, you can read about my experience with that on this very webpage. Unlike in cprog 14) we spent a larger amount of time playing around with the Linux command prompt and the various commands you can enter. Various such spells include, but are not limited to the following:

ls, cd, pwd, pom, cal, rm, cat

Some of these spells are more useful than the others. ls will show everything in the current directory. ls can do fancier things by typing something such as “ls -l” which will something include more information on each thing in the directory. cd stands for “Change Directory” and will change the command prompt to be in whatever directory is typed following cd. An example of this is “cd Desktop”. Typing cd without anything after it will return the command prompt to the highest level possible in my case it's simply “~”. pwd stands for “print working directory” and when I use it it returns the line “/home/kbrown38/src”. pom is perhaps one of the most useful 15) commands since it tells what the phase of the moon is. cal produces a calendar, and if you don't add a date afterwards will simply give the calendar for the current month, highlighting the day it is. You can use cal to do some “fun” things like looking up what day you were born on 16) or finding out that in 1752 September didn't have days from the 3rd to the 13th 17). rm is used to delete things. I could write rmdir src if I wanted to delete the directory src. By default for lab46 the rm comment already has applied to it “-i” which just opens a prompt asking if the user is certain they wish to delete something. The professor shared a fun story in which he accidentally told his computer to start deleting everything by writing the line “rm -rf m *”. In writing that code he told the computer to delete everything named “m” and by including a space then a “*” he told it to delete everything else on the computer as well. He wanted to write “rm -rf m*” which would instead of told the computer to delete everything starting with an m, I'm not sure I agree with either thing, but Linux gives you the power to do whatever thing you want. cat prints the contents of files and can used to combine files before printing the contents together. Writing “cat file1” will print the contents of file1 while writing “cat file1 file2” will print the contents of file1 followed then by another line with the contents of file2.

Messing with Linux commands was surprisingly enjoyable, but I already had issues trying to remember how to do some commands which I had to google for a refresher.

The Week of September the 6th, 2013

Turns out we have like labs and assignments in this class, who would've guessed?18) Anyway, this is my live blog of “lab0x1: Basic Utilities and their Manual Pages”, if you want a live blog of Lab0x0 too bad, I already did all that stuff so it wouldn't be live anymore. The objectives of this lab are to become familiar with tools and manual. Next it gives some things to read, all of which I will probably never read except for maybe the mage book19). First thing to do is list files. Just type the “ls” command, hit enter, and it'll spit back the names of every file in the directory some of them are different colours. The dark blue ones are directories, green is for executable files, yellow is device files for like mice and keyboards and such I suppose. Now I'm told to type “ls -l” and hit enter. It returned the names of every file but also gave the permissions for the file, the size of the file, the owner of the file, the date created/modified and the group owner of the file. As an example take a look at what it returns for the Desktop directory in my home directory.

  drwxr-xr-x 2 kbrown38 lab46 91 Aug 30 13:23 Desktop

The first bit is the permissions and each part stands for a particular thing. The first letter “d” means the file is a directory. The next three letters are the permissions I have to the file “r” means read, “w” means write and “x” means execute. I can do whatever I want to this file and frankly that seems like a lot of power for one person to have. The next three letters are the groups permissions so anybody else on lab46 can only read or execute the directory. The final three letters are the global permissions.

Now I have to change my directory to the /bin directory and report how large “grep” is and the timestamp of “cat”. I just typed “cd /bin” hit enter then type “ls -l” and hit enter. grep is 119288 bytes of memory and cat was last modified on April the 28th of 2010.

Nextly it's time to learn about copying things. I copied the message of the day file as directed into my home directory. Naturally doing an “ls” lists that I now have “motd” in the directory. I'm told to copy motd and name it as “lab1.text”. After doing that an “ls -l” shows that both files are the same size which doesn't mean inherently mean that two files are the same and I can check if they actually are by typing “diff motd lab1.text”. Doing so doesn't return anything because there are no differences.

Now I need to rename a file, but wait there isn't a rename command in Unix20). I just use the move command21) and “move” motd into lab1a.txt. An ls shows that motd doesn't exist but now lab1a.txt does. Then I move the lab1.text file into my src directory by using mv and sure enough ls commands show that it's in there now instead of where it was before. Now using the rm command I just delete that file from my src directory because I don't room for dumb text files where I keep all my class work. Then I just move the lab1a.txt into src rename it to lab1.file then delete it.

Now I'm doing stuff about symbolic links, but this journal entry is getting long so I'll keep it short. I created a symbolic link to src, then I created another copy of motd and put it in in src. I did this by typing the commands “cp /etc/motd motd2” then “mv motd2 src”. And it's in both src and the symbolic link to src. Then I removed motd2 and the symbolic link like the cruel Old Testament God I am.

The last subject of this lab is the manual. I looked up the page for du(1) by typing “man du”. If I wanted du to print in “human readable” form I'd type du -h somefile. I used du with and without the argument on the “xit” file in my home directory. It returned 4.0k both times. Now my command line looks like this

lab46:~$ du xit
4.0K    xit
lab46:~$ du -h xit
4.0K    xit

To make cp's operations verbose you use the argument “-v”. To make a backup of a file when using mv use the operation “-backup”.

In Conclusions: A lot of this stuff was already discussed in class and this journal is now longer than I'm comfortable with.

Case Study 0x1: Archive Handling, A response

1. I was able to copy the files in the archives directory to my home directory by typing “cp 'filename' ~” in the command prompt. I did this separately for each one because I misread the problem at first and thought I only had to copy one.

2. To extract the .tar file I used the command “tar -xf “filename”.tar”, which I read about in the man page for tar. I unzipped the zip file by typing “unzip “file that ends in .zip but I didn't need to type the .zip part”, then it asked me some options which I didn't understand so I just said no. I found this information in the man page for unzip which I found existed by going to the man page for zip.

3. I created the arc.tar archive of the archives subdirectory by typing “tar -cf arc.tar archives” which is also something i read about using the man pages.

4. I compressed the arc.tar file by typing “gzip -9 arc.tar” the ”-9“ tells gzip to be as slow as it possibly can which allows it to compress all data so much the data implodes into a singularity. The file that was made is in fact “arc.tar.gz” and I put that file right in my repository because I follow the rules. Funny story actually, when I first tried to move the file into my UNIX directory I forgot that the directory was in all caps and instead created a file named “unix” in my src directory so I had to repeat step 3.

5. Zip doesn't seem to work fundamentally differently than tar and gzip, it just appears to do the things that both do at the same time. I suppose archives make more sense now, but I've had previous experience using zip.

The Week of September the 13th, 2013

Joseph Campbell once said “Computers are like Old Testament gods; lots of rules and no mercy.” If computers are Old Testament gods then vi is all the parts of the Bible that tell you how you need to wash your fruit if you don't want to go to hell. By that I mean, vi is a very useful tool for the eternal salvation of your soul and all those who fall to follow it's system deserve the terrible hellish punishment they get22). The most important thing about vi is that you don't need a mouse at all, in fact you can't even use it. Everything you can do in vi can be done with the keyboard by using command shortcuts. The second most important thing about vi is that it has two modes, one for inserting commands and the other for inserting actual text. The third most important thing about vi is that is you want to get out of vi you hit “ESC” then ”:“ then type “q!” and hit enter. Everything after that is on the same level of importance, so without further ado here are some commands of various importance:

ESC - This gets you into command mode even if you're in command mode.
i/I - Puts you into text insertion mode and makes the document ready to accept text getting inserted right into it.
h,j,k,l - Moves your marker left, down, up and right, respectively, one space. You can make it go more spaces by typing "some number" then hitting one of the keys
W/w, B/b - Moves you forward a word or back a word, can be given a number like the directional commands
^, $ - Takes you to the start of a line or goes back a line, look so many of these commands can be given numbers so just assume they all do
u - This an conditional undo, it will undo whatever you just did as long as you don't change what line you're on.
. - will repeat your last command
: - opens the extended command interface so you can make longer more complex commands

If you want to save or quit you need to open the extended command interface then type w or q, w means save and q means quit. You can combine then as “wq” to save and quit. After “playing” with vi we edited a file that changed how our vi/m looks. First we created a file in our home directory called ”.vimrc“. In that file we wrote stuff like:

:set cursorline - Makes a line appear at the bottom of the line the cursor is currently on
:set tabstop=4 - Sets tab to equal a number of indentations of the space key
:set number - Shows line numbers
:syntax on - Puts coding syntax on

There is more stuff you can do to edit how your vim looks but remember “Thou shalt not make unto thee any graven image…”.

The Week of September the 20th, 2013

I didn't know that we have weekly labs and case studies so I'm catching up on them now.

Lab 0x2: Files and Directories

1a. I changed directory to the root directory by typing “cd /” in the command line. 1d. By doing an ls -l I can see that I am not allowed in to the “lost+found” or “root” directories.

2. I was able to get to my home directory from the root directory by typing “cd home” then “cd kbrown38”. I found this out by using the “pwd” command in my home directory.

3. The current working directory after changing to the tmp directory is ”/tmp“.

4. The following pathnames and whether they are relative or absolute. a. src - Relative b. ../../../../../usr/etc/../man/man2 - Relative c. /var/public/unix - Absolute d. /usr/sbin - Absolute

5. My current working directory is the home directory: b. Changing to the ”.“ directory keeps me my home directory. It did not change nor would I expect it to. Because ”.“ refers to the current directory. d. Changing the the root directory and then the ”..“ keeps me in the root directory because there is no higher directory on the system.

6. The directories and what type of file it predominantly contains: a. /var/log - regular files b. /dev - special files c. / - directory files d. /etc/init.d - regular files

7a. The root user owns the vim file. 7b. Root can read, write and execute the file. 7c. The group can read, write and execute vim. 7d. Anyone else on the system can read, write or execute vim.

8. The following files and their permissions: a. /var/log/daemon.log - 640 b. /etc/resolv.conf - 644 c. /usr/bin/split - 755 d. my home directory - 701

9a. To assign write permission to the world I would enter “chmod xx2 'filename'”. 9b. To remove the execute bit from the owning group I would enter “chmod 0xx'filename'”.

10. The command used give my lab2 directory read/write/execute for me, no permissions for the group, and search-only for others was “chmod 701 lab2”

11. I don't know how to make an ascii tree.

12. The bin directories are different because /bin has 121 files in it, /usr/bin/ has 1408 files in it and /usr/local/bin/ has 38 files in it.

Case Study 0x2: Unconventional Naming

1. The three files I choose to gain access to were “just a simple file.txt”, “one, 'two' three, “four””, and “compress “this” file.data”. I gained access to these files using the commands “vim just*”, “vim one*”, and “vim com*”.

2. The files I gained access to using “\” were “change my\ name.file”, “one, 'two' three, “four”” and “just a simple file.txt”. The commands used were vim change\ my\
name.file, vim just\ a\ simple\ file.txt and vim compress\ \”this\“\ file.data.

3. Commands using quotes to access the three other files were:

  vim "#pico28903#"
  vim "( parenthesis & other odd things )"
  vim "??? can you delete me ???.abc"

4. To remove the only file in the challenge directory I used the command ” rm ./'- challenge round -' “.

Lab 0x2: Text Processing

2. To get wc to display line count type wc -l. The amount of lines in /etc/passwd is 27.

3. To display the first 16 lines of passwd you type “head -n 16 passwd”.

4. To display the last 8 lines of passwd type “tail -n 8 passwd”.

5. For this part I just logged in twice because I don't have friends. Typing echo “stuff” » /tmp/“groupfile” made the terminal doing “tail -f” see that stuff was being added to “groupfile”

6. The ”-f“ feature for tail would probably be good to check what's happening in a file that gets changed frequently without having to open it each time. I can't think of an example of a file like that though.

Case Study 0x3: The Puzzle Box

1. File says that file.txt is an ASCII text file. Using cat I can see that file.txt is in fact a simple text file with ASCII text in it. When compressed file says the file.txt.gz is a gzip compressed file. When decompressed and then reexamined file still reads that file.txt is an ASCII text file.

2. So this text file called abcd.txt ends in .txt but when I cat that shit it's not a text file at all. What's up with that? Man this file is garbage. I couldn't figure out to copy and paste stuff in the terminal so I copied it into the firefox url bar and then wrote it manually into the terminal.

The Week of September the 27th, 2013

Case Study 0x4: Unix Messaging Tools

1. I bothered jwebb4 with the talk command.

2. When jwebb4 had his messaging turned off and I tried to write him it didn't work. When I had my messaging turned off and wedge tried to talk to me it didn't even show up.

3. I tired to ytalk with wedge but he was refusing messages, man that guy is so mean.

4. I talked with mhuff3 and wedge on ytalk. When mhuff3 left the talk and returned I had to accept his return. I opened a shell in ytalk by hitting ESC and then “s”.

Lab 0x4: Unix Shell Basics

1. By using ls -a I can see files that I otherwise wouldn't.

3. The .bash_history files keeps track of the last 500 commands I've entered into the command line.

4.

a. My Shell is /bin/bash
b. My mail directory is /home/kbrown38/Maildir
c. The terminal I'm using is an xterm
d. My path is/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin 

5. By using echo $PATH I echoed the path variable.

6.

a. My alias to ls is 'ls --color=auto'
b. The arguments aliased to ls are --color=auto
c. --color=auto as an argument for ls colorizes the output when standard output is connected to the terminal.

7.

a. When I unalised ls my output was all the same color.
b. There is not an alias for ls anymore
c. ls -F will append an indicator to classify files.

8.

b. To create an ls alias with original argument as well the indicator argument I typed: alias ls="ls -F --color=auto"
c. ls is now written as an alias again.
d. When I list the files in my home directory they are both, in color, and have indicators.

9.

d. The You got it line in my history is number 531.
g. Using history recall I ain't got it again, because bash is acting up.

10. The up arrow feature is useful because then I don't have to keep typing gcc -0 filename filename.c everytime I want to compile something.

11.

b. /usr is filled when I typed cd /u then hit tab
d. /usr/bin comes up when I add /b and hit tab
f. My current working directory is now /usr/bin
h. ls v did not beep
j. Pressing tab just gave me an ls of everything in 
i. To tab compLete ls vimtutor I just typed ls vimt then hit tab.

The Week of October the 3th, 2013

Lab 0x5: More UNIX Shell Explorations

1a. My current working directory after cding into the “shell” directory I made is /home/kbrown38/src/UNIX/shell 1d. I used “touch filename” to create the files.

2b. Entering the command “ls file*” returned the names of all the files. 2d. By typing “ls file?” I got an error “file1 file2 file3 file4 filea” because the ”?“ added any one character the the end of filename string. Those are all the files that have one extra character. 2f. By typing “ls file[23]” I got “file2 file3”, because the brackets say that the character after “file” needs to be either a 2 or 3. 2h. By typing “ls file[24a]*” I got “file2 file4 file41 filea” Because the little star after the brackets means “include anything you want”. And file41 is the only one that has a 2,4 or a and then a little something extra after it.

3b. After redirecting the motd to file1 when I view file1 it has the motd in it. 3d. I appended ”-This is text-“ to file1 and now it's in there right under the motd.

4b. When I wrote “More text…” to file1 it erased all the other text that was there before it. This is because I didn't append it I just wrote it in. 4d. I did ls file* | grep “file1” > file2 and now file2 has “file1 file1234” in it. It's because file1 and file1234 are the only file files followed by 1 and then any other characters.

5b. I typed “ls file555” and yeah, I got an error. 5d. I tried it again by doing “ls file555 > /dev/null” And the error doesn't go away, file555 still doesn't exist and redirecting STDOUT ain't gonna do shit about that. 5f. I finally did it with “ls file555 2> /dev/null” and now the error is gone. That's the beauty of STDERR redirection, If something bad happens I don't have to fucking see it. 5h. I typed “cat < file2” And it showed me what was in file2.

6. I typed ls -l /bin|less to get a long listing of the bin directory that I can page down on.

7b. I typed “echo $PATH” and it returned my path variable. 7d. I typed “echo “$PATH”” and it returned the same thing because double quotes lets the command line expand variables. 7f. I typed “echo '$PATH'” and it returned “$PATH” because the single quotes just does a literal quotation.

8. The “wc” commands prints newline, word count and byte size for files. If I wanted to just get line count I'd type “wc -l”

9. I typed “cat /etc/motd|wc -l” and it told me that there was 15 lines in the motd. WOOOOOOOOOW!

10a. To get all files 4 characters in length in the /bin directory I typed ” ls|egrep “^….$” “. 10b. To get the files that begin with my initials I typed ” ls|egrep “^[kb]…” “. What a violent response I got. 10c. To get all files that start with abc or rst I typed ” ls|egrep “^[abcABC].*[rstRST]$” “. There are five things. They are: bzcat, bzip2recover, bzless, cat, chvt

11. To get the contents of “Long File $PATH for Shell Lab.text” I entered the command ” cat 'Long File $PATH for Shell Lab.text' “.

Case Study 0x5: Web Pages

1. I took the cs.html file and i didn't rename it because it's fine how it is but I changed some stuff up so go check it out. http://lab46.corning-cc.edu/~kbrown38/cs.html

2. Hey I've heard of this great website. “http://lab46.corning-cc.edu/~kbrown38/ex0.html” Just take a look.

3. http://lab46.corning-cc.edu/~kbrown38/kbrown38.html

The Week of October the 11th, 2013

lab 0x6

1. To make script1.sh executable I typed “chmod 700 script1.sh”. It worked when I ran it again.

2. This is my script to take a year and subtract it from the current year.

 echo "Enter your birth year"
 read birthyear
 x=`echo "date +%Y"`                                                                    
 let answer=$x-$birthyear
 echo "$answer"

3. This is my script for a guessing game.

  #!/bin/bash                                                                           
  #
  pick=$(($RANDOM % 20))
  echo "Guess a number between 1 and 20"
  read guess
  for((i=1; i<4; i++)); do
     if [ "$guess" -ne "$pick" ]; then
       echo "Guess again"
       read guess
     elif [ "$guess" -eq "$pick" ]; then
       echo "You did it!"
       break
     fi
  done

4a. To print the count all on one line I would 4b. To change the loop to go from 20 to 2, iterating 2 each time, I would type. for23);do

5a. The loop iterates 7 times. 5b. The fifth time through the loop, the colour will be blue. 5c. I'm modified the script so that when the colour is violet it will say “The final colour is”

#!/bin/bash                                                                           
#
echo -n "First color is: "
for color in red orange yellow green blue indigo violet; do
    if [ $color == "violet" ]; then
      echo -n "The final color is $color"
    elif [ $color == "indigo" ]; then
      echo "$color"
    else
      echo "$color"
      echo -n "Next color is: "
    fi
done

6. My code for creating files is as follows

#!/bin/bash                                                                           
#
 
for((i=1; i<9; i++));do
    touch file$i
done
for((i=1; i<9; i++));do
    `echo "$i" >> file$i`
done
echo "Pick a number between 1 and 8"
read x
for((i=8; i>=$x; i--));do
    `mv file$i file$((${i}+1))`
done
touch file$x
echo "$x" >> file$x

7. Here is the histogram script.

#!/bin/bash                                                                           
#
 
if [ -z "$1"] ; then 
   echo -n "Enter a path: "
   read path
   chk=`ls $path 2>&1 | grep 'No such file' | wc -l ` 
   if [ "$chk" -eq 1 ] ;then 
   path=`pwd ` 
   fi
else
   path="$1" 
fi 
echo $path 
cd $path 
max=0 
for file in `ls -1d *`;do
   c=`echo $file | wc -c` 
   data[$c]=$((${data[$c]}+1))
   if [ "$max" -lt "$c" ];then 
      max=$c 
   fi 
done 
for ((i=1; i <= $max; i++)) ;do
   printf "%2d |" $i
   if [ -z "${data[$i]}" ]; then
     data[$i]=0
   fi
   for ((j=0; j<${data[i]}; j++));do
     echo -n "*" 
   done 
   echo 
done   

Case Study 0x6

1c. Block devices in the /dev directory include xvda1, xvda2 and xvda3 1d. Character devices in the /dev directory include tty7, tty8 and tty9

2b. / is mounted on xvda1 2c. /home is mounted on nfs: /home 2d. tmp is mounted on xvda2 2f. Lab46 seems to use Xen Virtual Disk for it's storage.

3. The PTYs of my sessions are /dev/pts/35 and /dev/pts/37

4. The permissions for my terminals are 620, my messaging statuses are +.

5. I changed my messaging status with mesg and not it's -. This prevents/allows people to message me because + and - are sacred and must always be respected.

6. I cat'd the motd and redirected the output to my tty. It's pretty much the same thing as if I hadn't redirected anything.

7. I redirected the motd to null by using cat /etc/motd»/dev/null. Null would be useful if I ever needed a lot of zeroes.

The Week of October the 18th, 2013

Lab 0x7: Job Control and Multitasking

1. I listed my current processes using the ps command. The output is:

kbrown38  6124  0.0  0.1  89100  2028 ?        SN   12:05   0:00 sshd: kbrown38@pts/0
kbrown38  6125  0.5  0.1  13644  1996 pts/0    SNs  12:05   0:00 -bash
kbrown38  6188  0.0  0.0   8588   992 pts/0    RN+  12:08   0:00 ps u -u kbrown38

If I was logged in multiple times ps would show me processes happening in both terminals. I didn't have to instruct ps to do anything it did it because that was the default setting for ps.

2. To list all the processes in user oriented format I typed ps -e. This is the line running inetd:

root      1140  0.0  0.0   8328   380 ?        Ss   May10   0:00 /usr/sbin/inetd

I ran top for a while and the most active processes were usually irssi, and if nothing else my top was the most active one.

3. Count.c is an ascii c program text. I complied it using the included instructions and now it executes. I ran it using ./count. I would put my home directory in my path if i wanted $PATH to see this executable.

4. output is a file and it took 35 seconds to complete. When I used ”&“ at the end of it it returned [1]6452. Then it returned and said it took 48 seconds to run.

5. This is my command line to do task 1 in number 5. sleep 8|ls /var » multitask.lab.txt & I did this because it's what I was asked to do.

6. I cannot log out because there are stopped jobs. This is probably there so someone doesn't forget they have stopped jobs and logout halfway through.

8. I didn't end up logging out.

8. a. Hangup is 1) SIGHUP b. Terminate is 15) SIGTERM c. Kill is 9) SIGKILL d. Interrupt is 2) SIGINT

9. Both instances of my log in are listed in a who command.

kbrown38 + pts/0        2013-10-31 12:47 00:01        6525 (REDACTED)
smeas    + pts/2        2013-05-10 16:24 00:42        1516 (REDACTED)
vcordes1 + pts/3        2013-10-31 12:48   .          6811 (REDACTED)
alius    + pts/13       2013-05-13 16:26 21:02       14720 (REDACTED)
wedge    - pts/23       2013-10-31 08:36 00:25       31091 (REDACTED)
kbrown38 + pts/30       2013-10-31 12:49   .          6881 (REDACTED)

My tty on one is /dev/pts/30 and the other is /dev/pts/0. The PID of my logins are 6884 and 6528.

10. I typed kill -9 6884 to terminate one of my login sessions. I am no longer logged in twice and my other terminal says that it's not logged into lab46.

11.

statd     1233  0.0  0.0  14596   516 ?        Ss   May10   0:00 /sbin/rpc.statd

There doesn't seem to be anything special about this PID

root      1190  0.0  0.0  14676   584 ?        Ss   May10   3:02 /usr/sbin/cron

cron is a daemon used to run scheduled commands.

Case Study 0x7: Scheduled Tasks

I made a Phenny bot named PhenHONK, Honk Honk motherfucker. I made it tell me about G from wolfram alpha.

2. I found the process ids of my bot by typing this command:

pgrep -u kbrown38, python

The Week of October the 25th, 2013

For future reference: The UNIX public directory is located at /var/public/unix

Lab 0x8: The UNIX Programming Enviroment

I compiled everything using the following commands:

as -o helloASM.o helloASM.S
ld -o helloASM helloASM.o
gcc -o helloC helloC.c
g++ -o helloCPP helloCPP.cc
javac helloJAVA.java
Case Study 0x8: Data Types in C

1. The limits.h file is in /usr/include. My spell for find was “find -P / -name limits.h

2. There are 8 bits in a char. There are 2 unique states for a char. Signed short ints go from -32768 to 32767. Short ints have 16 bits. There are 32 bits in an int and the range goes from -2147483648 to 2147483647. There are 32 bits in a long long int.

3. I compiled dtypes.c by tpying gcc -o dtypes dtypes.c.

4.

unsigned int before: 0 	 after: 4294967295
signed short int before: 0 	 after: -1

4294967295 happens to be the highest number possible using 32 bits. Since a signed int can be negative it makes sense for 0-1=-1.

5. It makes sense for a %hd to go from 32767 to -32768 when adding one because it roles over to the lowest possible value. This is my c code:

#include <stdio.h>   
 
int main()
{
   unsigned int a, x;
   signed short int b, y;
 
   a = 0; // zero not letter "O"
   b = 32767;
   x = a - 1;
   y = b + 1;
 
//    printf("unsigned int before: %u \t after: %u\n", a, x);
   printf("signed short int before: %hd \t after: %hd\n", b, y);
 
   return(0);
}

7. There's my code for part 7.

#include <stdio.h>                                                                    
 
int main()
{
   unsigned long long int a, x;
   signed long long int b, y;
 
   a = 0; // zero not letter "O"
   b = 0;
   x = a - 1;
   y = (((a-1)/2)+1);
 
   printf("maximum unsigned long long int %llu\n", x);
   printf("minumun signed long long int %lld\n", y);
 
   return(0);
}

The Week of November the First, 2013

Lab 0x9: Pattern Matching with Regular Expressions

1. I grepped for system in the /etc/passwd file by typing “cat passwd|grep System”. I got this “gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh”

2. By typing cat passwd|grep '^[b-d][aeiou]' i got this:

daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh

3.

To find lines that started with my initials I did cat passwd|grep '^[kb]' and got:

bin:x:2:2:bin:/bin:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh

To find any line starting with r followed by a lowercase vowel and ending in h I typed and got:

root:x:0:0:root:/root:/bin/bash

4a. I fixed all the center tags by typing 'cat regex.html|sed s/centre/center/g' b. I fixed all the closing center tags by typing the above with 'sed s\/CENTRE\/center/g' piped to the end of it. c. When I tried to replace <b> with <strong> by doing ” cat regex.html|sed s/centre/center/g|sed s\/CENTRE\/center/g|sed s/<b>/<strong>g” I kept getting errors about b not being a file or directory. This error confused me so badly that I actually don't know what I'm doing at all anymore.

Case Study 0x9: Fun with grep

1a. I found all instances of coast in the pelowar.txt file by typing cat pelopwar.txt|grep coast, this also gave me an instance of coasting. 1b. There were 9 matches to previous search. 1c. To find just coast and not coasting I typed cat pelopwar.txt|egrep '(coast\>)' 1d. 8 matches 1e. cat pelopwar.txt|egrep 'Dorian$' 1f. cat pelopwar.txt|egrep '^Again'

2a. I found lines that started or Athens or Athenians by typing cat pelopwar.txt|egrep '(^Athens|^Athenians)' 2b. 8 matches 2c. I did accomplish it with one call to egrep using extended regexps. 2d. I found all instances of Corinth and Corinthians that ended a line by typing cat pelopwar.txt|egrep '(Corinth$|Corinthians$)' 2f. I did that.

3. I tried to use fgrep to do the search from 2a and I got nothing. It's because fgrep only uses literal strings so I can't just take that shit and and put it into fgrep.

4a. “Display the first 4 lines of the last(1) command's output that begin with any of your initials. Include your output too.” This was my command: last|grep '^[kb]'|head -n 4 This was my output:

bkrishe3 pts/10       184.52.75.124    Tue Nov 12 20:19 - 20:26  (00:06)
kbrown38 pts/3        cpe-67-241-225-2 Tue Nov 12 19:32   still logged in
bh011695 pts/0        cpe-74-67-87-78. Tue Nov 12 10:13 - 10:14  (00:00)
khoose2  pts/0        cpe-69-205-140-1 Mon Nov 11 20:24 - 20:29  (00:04)

4b. “Using sort(1), alphabetize the output of the lastlog(8) command and use grep(1) to search for all lines that begin with a lowercase 'e' through 'g', then print out the first 4 lines of the resulting output.” This was my command: lastlog|sort|grep '^[efg]'|head -n 4 This was my output:

eberdani         pts/63   10.100.20.29     Tue Feb 22 10:12:22 -0500 2011
efarley                                    **Never logged in**
egarner                                    **Never logged in**
egleason         pts/50   cpe-24-94-60-90. Thu Dec 20 17:28:38 -0500 2012

The Week of November the Eighth, 2013

Portfolio

cprog

unix

1)
#include<stdio.h>
2)
return 17;
3)
Note that the term “understood” is used very loosely in this example
4)
Note again that this is a Linux interface and you may need to do something else
5)
I love footnotes though
6)
Hopefully any program is a program
7)
lol xD #yoloswag
8)
The first two at least
10)
Pre-Columbian earthwork located in current Madison County Illinois.
11)
2432 Patterson Street, Pittsburgh, Pennsylvania
13)
Happy Birthday Rich Evens.
14)
That's C/C++ Programming for short. By writing “cprog” instead of “C/C++ Programming” I've saved both myself time, by reducing the amount I type, and I've saved you, the reader, time by reducing the amount of characters you need to read.
15) , 18)
I'm joking
16)
Monday
17)
This is because of the Gregorian Reformation of the British calendar system
19)
UNIX for the Beginning Mage
20)
What ever shall I do?
21)
mv
22)
As Dante Alighieri said “The hottest places in hell are reserved for those who, in times of great word processing, use Nano”
23)
i=20; i>2; i=i-2