Friday, 24 February 2017

Lab 6: Picking and Learning a Good Editor

For this lab, we are looking at several modern text editors that programmers use often for their work. This lab will require me to use 2 editors I have never used before and to experiment with them while logging my experience.

I think I'll try Nuclide (because I like the color purple).. and Atom because it looks cool.

One of the first instructions confused me:

"From the list of editors above, pick at least 2 that you've never used before and install them. Use the Mozilla Brackets repo to test the editor (i.e., try opening the entire project) in the chosen editors to see how they perform" 

 I thought it meant I had to run the Brackets software inside of my new editors, but the professor said that I had to play around with the file system using the editor instead. That makes much more sense now. Funny how I always interpret stuff in a strange way!!

To be honest, I can't tell yet the difference between Atom and Nuclide, because Nuclide seems to be a bonus part of Atom... so I'll talk about them like they are the same for now.

ATOM / NUCLIDE


1. Opening Projects / Files:
On the Welcome Guide page, you can open a project by clicking the 'Open Project' button and viewing folders on your computer. By clicking the folder, 'Brackets', it pulled in the entire project for me right away. I also have the option in the menu list to click File > Add File / Add Folder. Either method will get me the project I'm working on.

2. Changing Tab Options:
The default tab spacing appears to be 2 spaces. In order to change that, I need to go to:
File > Settings... then one the left menu of options choose 'Editor'. Going down editor's list of options you will find 'Tab Length' and change 'Default: 2'.

3. Opening the Editor from Command Line:
In order to open from command line, first open up the command line (Git Bash).
I searched for the file inside my directories and it was in /Desktop.
However, the file looked like: Atom.lnk
I googled about opening a .lnk file and the command is: "START Atom.lnk" [ The guide also said that if there was nothing other executable file with the name 'Atom', I could have just typed START Atom. ]

4. Searching For Strings/Files in Project:
I assume means like a 'Find' function or some version of grep. 
Luckily in the top menu, there is a 'Find' option. Choose option 'Find in Project' Ctrl+Shift+F. Type in any word(s) and the bar will pull up Project Find Results with all instances of those words. To find words inside the file in view in the editor, use the Find in Buffer option. If the words do not appear in the file you are viewing, ti shows no results. If it is in the file you are viewing, it will tell you how many instances are found in the file. By clicking find, it jumps to the first instance.

5. Split Screen Into Multiple Panes/Editors/Views:
For Panes - Go to the top menu under 'View' and choose 'Panes'. Here you can split up, down, left, right or focus on another pane beside the current pane. Splitting panes will make a replica of the current pane in focus and place it in the area you specified as a separate frame.

Original:




Pane Split:



It appears that editors and views are viewed inside the panes.. so creating more panes indirectly creates more editor windows and views. However, if you want a separate window for the project, click File > New Window. However, when I tried this, the program froze, so I don't recommend it...

6. Install Editor Extensions:
In case you have closed the welcome pages when the editor opens up, you can click File > Reload Window, and the Home, Welcome, and Welcome Guide tabs will reappear. From there go to Welcome Guide and select Install a Package. Or go to Settings and choose the option of Install.
From there you can input your package name into the textbox and search for it.

7. Using Multiple Cursors:
I searched online for the answers and the best sites were: 
https://atom.io/packages/multi-cursor
http://superuser.com/questions/957128/how-do-i-do-multi-line-editing-in-atom-editor
In windows, the keybindings for the OS are already mapped, so it interferes with the Atom program using multi-cursors. I think I have to go into the Settings and create my own set of keybindings for multiple cursors.


8. Some Common Key Bindings:
Some common key bindings readily available are:
a) alt+[#] -> press alt and a number and it will jump between the panes currently open by their number.
b) 















c)











9. Changing Key Bindings:
I had a hard time figuring out how to change key bindings. You can go into settings and view the key bindings that exist, but changing them wasn't easy to figure out intuitively. I googled the question one stack overflow question lead me in the right direction:
http://stackoverflow.com/questions/33023349/atom-disable-single-key-binding

I must:
a) Open settings with File > Settings
b) Click Keybindings
c) Filter the list by typing (for example ctrl[whatever-your-command-is] ) in the search box.
d) Click the clipboard icon next to the shortcut. This will copy the shortcut definition to your clipboard.
e) Click the hyperlinked text your keymap file.
f) Once inside the keymap.cson file, copy the clipboard to the file and make the changes to the keybindings functionality.


 


10. Enabling The Use of AutoComplete For HTML, JS, CSS,etc...:
There is a package (https://atom.io/packages/autoclose-html) which will complete the closing tag once an opening tag is created. Another package, https://atom.io/packages/autocomplete-plus, will offer a display of possible selections to choose from. There are other packages online that will most likely solve any other autocomplete needs by the editor if you search hard enough.


11. Changing Editor and Personal Preferences:
In order to change editor and personal preferences, you can always go into the Settings bar and mess around with the following features:





















You can probably get by with almost any changes to match your preferences by browsing and playing around with these headers.

========================================================================

The second editor that I will be experimenting with will be the Visual Studio Code.
Right away when I downloaded the program, a web tab opened up with a 'Documentation for Visual Studio Code: Getting Started' page opened up. Nice nice!

VISUAL STUDIO CODE

1. Opening Projects / Files:
Like almost any program out there, to open files and projects you go to the menu bar which will have an 'Open File...' or 'Open Folder...' command near at hand.



2. Changing Tab Options:
The default tab spacing appears to be four spaces. In order to change the tab spacing, I clicked File > Preferences > Settings. A settings.json file popped up and in the Commonly Used (10) list I saw "editor.tabSize": 4. I had to click the edit icon next to the code when I hovered the cursor over it. It copied that code over to the USER SETTINGS which opened up in a new tab and said to write my new code there to overwrite the default settings. I changed the number in the code listed on the USER SETTINGS tab, saved the changes to the settings.json file and that changed the tab spacing.

3. Opening the Editor from Command Line:
In order to open Visual Studio Code from the command line, simply open up the command line and type "Code". That will be enough to open up the editor program. Very easy!

4. Searching For Strings/Files in Project:
In order to find strings or files in the project, go to Edit > Find or > Find in Files. A list of all matching strings will show up that you can search through and click, giving that entry its own editor tab for you to work on.


5. Split Screen Into Multiple Panes/Editors/Views:
In order to split the screen into multiple editors, click View > Split Editor. Or you can type Ctrl+\ .

6. Install Editor Extensions:
In order to find extensions, click View > Extensions. A tab will open with a search bar and a list of extensions that are available. Each extension on the list has an Install button attached.

7. Using Multiple Cursors:
In the Selection menu, you can find a few commands like 'Add Cursor Above', 'Add Cursor Below', 'Add Cursor to Line Ends'. The keybindings say Alt+Ctrl+UpArrow/DownArrow, but that will be overridden by the OS keybindings which rotate the screen directions. You can simply click the commands in the menu and they will appear on the code you are working on. I was able to click three times on the 'Add Cursor Above' and created a 3-line cursor which all typed the exact keys I typed at the same time on every line.

8. Some Common Key Bindings:
One amazing thing right on the start up screen after you load a project is a few key commands to do some important stuff.






















Right away you can click Ctrl-Shift-P and a drop down window of commands with their keybindings will appear. You can debug, access Git, work with Extensions, change Views, work with Files, etc. It appears almost anything related to working with the program is a command in itself that can be found in this drop down. If you are working on a project and this Start Up screen goes away, click View > Command Palette and the drop down will reappear.

9. Changing Key Bindings:
In order to change key bindings, I read:
https://code.visualstudio.com/docs/customization/keybindings

I went to File > Preferences > Keyboard Shortcuts. It brought up two editor panes, one with the list of current default keybindings. The other pane had keybindings.json, which was a special page where I could make my own changes to overwrite the default settings.



10. Enabling The Use of AutoComplete For HTML, JS, CSS,etc...:
The editor on its own doesn't have an autocomplete feature. Its basic version allows you to start typing a word and hover the mouse cursor over it (or type Ctrl+Space), and it will give a drop down of possible keywords you might possibly mean to say. You can also download extensions that will help with autocomplete, likes IntelliSense or other offered programs.



11. Changing Editor and Personal Preferences:
For changing editor and personal preferences, simply go to File > Preferences > Settings or > Color Theme to make changes. In settings, all the possible variations of features are listed inside the settings list and all you need to do is change the User Settings file to overwrite the defaults.

-------------------------------------------

Overall, I found that I enjoyed the intuitive ease of figuring my way through Visual Studio Code more than I did with the Atom/Nuclide editors. I found that I had to mostly go through Google searching how to do things, while on Visual Studio Code editor, it placed everything I needed on the same page and made it clear what needed to be done. I did not make use of the extensions, because I find that my way of using editors is very basic and I am happy as long as the tab spacing looks nice and I can color-code the variables differently from the function names and generally block code. I think that Visual Studio Code would work better for me in the long run because it is efficient, makes intuitive sense to me, and I can accomplish a whole bunch of cool tasks without having to really know the keybindings, and I can change them as I see fit very easily if I wanted to.

Release 0.2 - Failed Release Topic

For my next contribution to Thimble I will be working on the issue:

https://github.com/mozilla/thimble.mozilla.org/issues/1700

In this issue, I will have to go through the processes of installing their software again, and document my journeys while doing so and giving recommendations + making the instruction set more read-able and accurate. I will be working on this during my study break week, so future results will be coming in shortly.

- February 24, 2017
-----------------------------------------------------------

The actual webpage we are editing is: Setting Up Thimble Without Virtualization

Some prerequisites for using Thimble without virtualization (Vagrant + Virtual Box) is:

Node.js 4.0 or greater. [ I have 6.9.5.0 ]
The website is missing a link to download it by the way: https://nodejs.org/en/

PostgreSQL 9.4 or above. https://www.postgresql.org/
I have the option of getting the Interactive Installer by EnterpriseDB or I can get the Graphical Installer by BigSQL. The Interactive installer appears to give a straightforward, fast setup for running postgreSQL. The Graphical  installer is a developer-friendly version with the complete postgreSQL environment. I don't think we are really developing on postgresSQL, so probably the fast setup version is better for our usage.

The download page will ask you for which PostgreSQL version you want (I chose 9.6.2) and what your computer's 32 or 64-bit operating system value is. [To find that, look up: https://support.microsoft.com/en-ca/help/827218/how-to-determine-whether-a-computer-is-running-a-32-bit-version-or-64-bit-version-of-the-windows-operating-system

g++ 4.8 or above: I'm pretty sure I don't have this, so I went looking for it. A topic search came up with a site that was a good start: http://www.cplusplus.com/forum/windows/106380/

Basically as a Windows user, I don't have Linux libraries like gcc or g++. So I need a Windows-type work-around. Currently minGW works for that( Minimalist GNU for Windows).

I went and downloaded the newest version from: https://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/64-bit/threads-win32/sjlj/x64-4.8.1-release-win32-sjlj-rev5.7z/download

you will need a 7-zip program to unpack it. I unpacked to my desktop. http://www.7-zip.org/download.html

then i got webmaker:
git clone --recursive https://github.com/mozilla/id.webmaker.org

git clone --recursive https://github.com/mozilla/login.webmaker.org

Next I believe I have to set up PostgreSQL before moving on to publish.webmaker.org

First I set up the id.webmaker. It suggested I create sample.env file.. but it was already there... i don't know if it made a refreshed version... but just heads up.

Next I did:
npm install
npm start --- kinda started then just did nothing so i stopped the process.. however on the localhost:1234 it was showing up.

Then I went to login.wemaker.
npm install
had a lot of ERR while installing
failure during start because of node.js version and other problems.








- March 10, 2017

Tried: https://docs.npmjs.com/getting-started/installing-node .

Check node.js version with 'node -v'
'npm install npm@latest -g'

then went back and try to npm install login.webmaker.



Still got the same errors.. so i researched node-gyp rebuild and found : https://github.com/websockets/bufferutil/issues/25









That's a possible thing to look into... did more research and basically everybody is crying about it and deleting files and dependencies left-right and center trying to fix the issue. I don't have the time to get into that kind of mess that nobody else has successfully figured out yet.

https://github.com/nodejs/node-gyp/issues/629

Basically it looks like this is a HUGE problem for Windows users... I may need to move on to a new Release Issue.

I may continue working on this and use it as my 4th and final release actually. We'll see.


Actually I kept going... and I looked at the error messages and it said:

gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Shanta\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin     \\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Shanta\login.webmaker.org\node_modules\bcrypt
gyp ERR! node -v v6.10.0
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1

I looked inside login.webmaker.org\node_modules.. and bcrypt isn't even there!

I also looked in C:\\Users\\Shanta\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin     \\node-gyp.js and I didn't even see "rebuild"

https://www.robertkehoe.com/2015/03/fix-node-gyp-rebuild-error-on-windows/

read https://github.com/nodejs/node-gyp and tried:
npm install -g node-gyp


- March 15, 2017

Another contributor made some changes to login.webmaker.org, which supposedly removed the depeendency on bcrypt, so I recloned it and attempted again. Seemed to work, now moving on to setting up postgreSQL... i couldnt use the initdb -D /usr/local/var/postgres
on my command line.. i should probably install it in the same User directory my other softwares are in.

- March 17, 2017

I tried setting up postgreSQL on my user folder... got this message:










- March 19, 2017

Wednesday, 15 February 2017

Release 0.1 - Fixing my first bug for Thimble

My first attempt at solving a real-world bug involved issue:

https://github.com/mozilla/thimble.mozilla.org/issues/1715

-------------------------------------------------------------

While running npm install I notice:
npm WARN deprecated nunjucks@2.3.0: potential XSS vulnerability in autoescape mode, and with escape filter was fixed in v2.4.3
We should update to 2.4.3 in both code bases.

---------------------------------------------------------------

The issue itself was a serious problem because it allowed the possibility of hacking into the system through code injections. The current version that Thimble and Brackets used a version of Nunjucks that was vulnerable, but an updated version claimed to have solved that problem.

The fix for the code would have been to inform Thimble and Brackets to use the updated version of Nunjucks when they installed their plugins.

I had to search for a bit to understand how that worked. I discovered the nunjucks 2.3.0 as a dependency inside the package.json file. So for the fix, I simply upgraded the version inside the package.json file. So this taught me that package.json has metadata that is relevant to how the whole project decides what plugins to use and other key information.

For Brackets, they did not have nunjucks included, so I entered a new line in their dependencies list to add nunjucks as well.

The overall difficulty of solving the problem was relatively low, but the improvement in the security of the software could potentially be huge, so I feel somewhat accomplished and proud of the difference I believe I made. It has given me more confidence in attempting to solve bigger problems and knowing that there is always something that can be improved, no matter how small, that can make a big difference in Open Source.

https://github.com/mozilla/thimble.mozilla.org/pull/1742

For more information about the process, check out:

http://osd600osp.blogspot.ca/2017/02/lab-3-fixing-bug-in-mozilla-thimble.html

--------------------------------

[February 24 Update]

So in waiting for a response to my pull requests, I apparently learned why the Brackets source code did not have the nunjucks dependency. I had actually been making a pull request to the Brackets owned by Adobe, not by Mozilla. They quickly pointed out my error and I got rid of my repository for Adobe and switched it out for Mozilla's. Sure enough, nunjucks was there, and I made the same changes as I did for Thimble and sent the pull request right away.


Monday, 13 February 2017

Lab 4: Working With GitHub

For this lab, we'll practice using GitHub.

The first thing I have to do is Fork the Spoon-Knife repository to my own repository. This basically means that all the code inside that repository is copied into my GitHub account.

Next I have to clone it to my own local machine. This means that the software can become available for my own computer to use.

I go into Git Bash, create a 'temp' folder for this lab, and copy the SSH key.

I then typed:

git clone git@github.com:Blackweda/Spoon-Knife.git while inside /temp folder.

I got this response:












Sigh... nothing ever seems to work right the first time in this course... I googled the problem and came to this website: https://help.github.com/articles/error-permission-denied-publickey/

Took a few steps:















Apparently I have no identity, so I'll need to generate my own keys: 
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ 

 I followed the steps and made ssh keys that are saved. Then I went back and did:


ssh-add ~/.ssh/id_rsa

Inside the /temp folder. It asked for my passphrase and then added the keys! 
Now let's try this all with git cloning again.
 
Again the same problem... but I took a look at the command I entered and made a few changes...
 
 

























As you can see... I changed:     git@github.com   ->        https://github.com
and I also changed:                   :Blackweda           ->        /Blackweda


NOW WE CAN GET BACK TO WORK...

I go into the Spoon-Knife/ folder and    git branch to make sure I'm on the master branch inside the cloned repository using Git Bash.

Added new file:




 






 



Created new branch and checked both branches:



























Then changed master back to its original version:








Because we are merging two branches that have different commit histories, git will use a recursive merge strategy, and create a new commit merge commit that connects these two branches.













Going through all the branches, I can see that the merged branch (name-and-food) has files from both of the other branches, while each the other branches do not contain the files from the other branches.

'name' has no food.txt
'food' has no Wayne.txt

Also when creating different versions of animals.txt, I noticed that my jungle-animals.txt had the same file as my water-animals.txt and the original animals.txt. So this means that they are all pointing to the same commit I suppose. I checked all three with 'git show' and I was correct.

I've realized through making some errors that having all three branches point to the same commit means that any changes in the branches will be seen by all branches because the commit is the same. Unless we commit the files personally inside a branch, all branches see changes.


 While I was going through the whole process, I had the hardest time with the animals / water-animals / jungle-animals part...

Initially I kept pointing them all to animals, and then changing the animals.txt without actually adding and committing them each time. This essentially made all branch versions of animals.txt point to the most recent version of animals.txt that was edited. 

I discovered I had to 'add' and 'commit' before 'checkout' so that the animals.txt version was local to that branch. 

The squashing just added the commit messages into another commit message, similar to merging branches, but you are merging commit messages instead.. and the rebasing meant that I had to make the changes to animals.txt all over again to make the new merge successful, as it was undoing the previous merging process and repeating the entire process for rebasing the new single commit.

Adding the gh-pages wasn't too hard, just had to setup in my GitHub account and check for the site through the 'Settings' option.













=========================================================================

Entire Instructions:

Git Branches

In this lab you will review working with branches, and learn how to use the special gh-pages branch on Github to host static web content.

1. Review: creating branches

Every git repo begins with a single branch named master. When you commit, the master branch is automatically updated to point to the most recent commit.
Recall from class that we can create a new branch by doing the following:
git checkout -b new-branch
The -b flag indicates that you want to first create the branch if it does not already exist, then switch to it and check it out to your working directory. You could also have written it like this:
git checkout -b new-branch master
In this case, we are explicitly specifying that we want new-branch to be created and point to the same commit to which master is pointing. Because we're already on the master branch, we don't have to do this--git will assume you want to use the current commit. We could also have written it like this:
git checkout -b new-branch HEAD
Here we explicitly specify that we want to use the latest commit on the current branch, also known as HEAD.
If we wanted to have new-branch get created pointing to something other than the latest commit, we can specify that commit instead. For example, if we want it to point back to two commits from the current one (i.e., go back in time), we'd do this:
git checkout -b new-branch HEAD~2
As you switch between branches, if you ever get confused about which branch you're on, use git status or git branch, both of which will indicate the current branch.

2. Resetting a Branch

Sometimes it's necessary to switch the commit to which a branch is pointing. For example, if you accidentally commit things on master vs. a new branch, and need to move master back to a commit in the same history as a remote repository (i.e., if you want to git pull upstream master to get new updates).
Let's walk through an example:
  1. On Github, fork the Spoon-Knife repository at https://github.com/octocat/Spoon-Knife
  2. Clone this repository to your local computer
  3. Confirm that you are on the master branch (i.e., use git branch)
  4. Create a new file called name.txt with your first name in it
  5. Use git to add and commit the new name.txt file.
  6. Confirm that you have 1 new commit on the master branch (i.e., use git log)
At this point we have a new commit on the master branch, but decide that we should have done this work on a new branch. Let's fix things so master is back where it should be, and we instead have a new branch:
  1. Create a new branch called name by doing git checkout -b name
  2. Confirm that you are now on the name branch
  3. Confirm that name and master both point to the same commit (i.e., use git show name and git show master)
We can now move our master branch back one commit, and leave our name branch where it is. We'll do that using the -B flag (note the capital), which will create or reset a branch:
  1. git checkout -B master HEAD~1
  2. Confirm that name and master both point to different commits (i.e., use git show name and git show master)

3. Merging

Next, let's experiment with merging. We'll start by creating a third branch:
git checkout -b fav-food master
This will create a fav-food branch which is pointing to the same commit as master. Confirm that you now have 3 branches (master, name, fav-food) using git branch.
On the fav-food branch, add a new file food.txt with a list of your favourite foods. When you're done, add and commit this file to the fav-food branch.
Let's now try combining our name and fav-food branches. If you're ever unsure about a merge, you can always try doing it on a new branch and see how it goes. Let's try doing our merge on a branch called name-and-food:
  1. Create a fourth branch that points to the same commit as name: git checkout -b name-and-food name
  2. Merge the fav-food branch into name-and-food. When you merge, you always switch to (i.e., checkout) the branch into which you want to merge first, then merge the other branch in: git merge fav-food. Because we are merging two branches that have different commit histories, git will use a recursive merge strategy, and create a new commit merge commit that connects these two branches.
  3. Confirm that you now have a new merge commit on the name-and-food branch (i.e., use git log).
  4. Confirm that the name-and-food branch contains both the name.txt and food.txt files, created on the earlier branches.
  5. Try switching back to your name branch, confirm that you don't have a food.txt file.
  6. Try switching back to your fav-food branch, confirm that you don't have a name.txt file.

4. Merge Conflicts

Git can automatically merge most things without any help. In the previous case, we added two separate files, and git had no trouble combining them. What if we had made changes to the same file?
Let's try an experiment that will simulate two separate lines of development on the same file:
  1. Create a new branch called animals that points to the same commit as master.
  2. Create a new file called animals.txt and add the names of three farm animals, one per line. For example, your animals.txt might look like this:
horse
cow
chicken
When you're done, commit the new animals.txt file to your animals branch. Now let's start two separate changes that both work on animals.txt:
  1. Create a new branch called water-animals that points to the same commit as animals.
  2. On the water-animals branch, edit animals.txt to add 3 water animals. When you're done, commit your changes to the water-animals branch. For example, your animals.txt might look like this:
horse
cow
chicken
whale
seahorse
dolphin
Let's repeat this process, but this time we'll focus on animals that live in jungles:
  1. Create a new branch called jungle-animals that points to the same commit as animals.
  2. On the jungle-animals branch, edit animals.txt to add 3 jungle animals. When you're done, commit your changes to the water-animals branch. For example, your animals.txt might look like this:
horse
cow
chicken
monkey
python
bird of paradise
Now let's merge our water-animals branch into animals:
  1. Switch to your animals branch
  2. Merge water-animals into animals (i.e., git merge water-animals)
  3. Confirm that your animals branch now contains the changes you made to animals.txt
Because our water-animals branch was ahead of our animals branch by 1 commit, git was able to do this merge using the fast-forward merge algorithm, which simply moves the branch ahead to align with the other branch. If you use git log you'll notice that there is no merge commit this time.
Next, let's merge our jungle-animals branch into animals as well. Since both of these branches touch the same lines of the same file, this won't work automatically, and we'll have to fix it manually:
  1. Switch to your animals branch
  2. Merge jungle-animals into animals (i.e., git merge jungle-animals)
Git will respond and indicate that there was an issue merging animals.txt:
Auto-merging animals.txt
CONFLICT (content): Merge conflict in animals.txt
Automatic merge failed; fix conflicts and then commit the result.
Let's fix the merge conflict. Confirm that we are mid-way through a merge and have a merge conflict using git status. You'll see something like this:
On branch animals
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

 both modified:   animals.txt

no changes added to commit (use "git add" and/or "git commit -a")

Open the animals.txt file. Here is what mine looks like:
horse
cow
chicken
<<<<<<< HEAD
whale
seahorse
dolphin
=======
monkey
python
bird of paradise
>>>>>>> jungle-animals
Notice the presence of <<<<<<< HEAD, =======, and >>>>>>> jungle-animals. These are conflict markers and show the different versions of the lines in question. Because we are merging into animals, it is our HEAD, and everything between <<<<<<< HEAD and ======= is what is on this branch. Everything between ======= and >>>>>>> jungle-animals is what is on the jungle-animals branch. Because both branches edit the same lines of the same file, git needs us to resolve the conflict. We have a few options:
  • Use what is in HEAD, and erase the lines from jungle-animals
  • Do the opposite and use what is in jungle-animals, and erase what is in HEAD
  • Combine the two sets of changes into one change
In this case, we just need to combine the entries into a single, longer list. He can simply remove the conflict markers and save the file. Here's what mine looks like when I'm done:
horse
cow
chicken
whale
seahorse
dolphin
monkey
python
bird of paradise
Now we can add and commit this conflict resolution in order to finish our merge. When we're done, we'll have a new merge commit that combines the changes from our two branches into animals.

5. Rebasing, Squashing

At this point our animals branch is where we want it, in terms of content; but it's a bit messy in terms of how we got there. Sometimes before we share (i.e., git push) branches to share with colleagues, we want to clean up our history. Wouldn't it be nice if we could take all the different commits we made, and combine them into a single commit that achieved the same result? We can, and it's called a rebase.
First, a few warnings. Unlike a merge, which always keeps your history intact, a rebase will alter your commit history. You should never do this to a branch that has been shared with other developers, since it will erase and re-create commits, which makes it impossible for others to collaborate with you on those commits. A rebase is only something you should do before you share your commits with others.
Let's practice a rebase on our animals branch, and squash our separate commits into one single commit:
  1. Switch to your animals branch
  2. Start an interactive rebase: git rebase -i master
This will open your editor and show you all of the commits on animals that are ahead of master. Mine looks like this:
pick 436a838 Adding animals.txt
pick 595f37e Added water animals
pick 3d7af87 Add jungle animals

# Rebase 21826a9..3b4d451 onto 21826a9 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
The comments at the bottom tell us what our options are. We can pick a commit to include it, squash a commit to combine it with the previous commit (like using git commit --amend), fixup a commit to squash and throw away the commit message, etc.
In our case, let's modify things to include the first commit, and squash the next two into it. To do so, edit the commit message like so, then save and exit your editor:
pick 436a838 Adding animals.txt
squash 595f37e Added water animals
squash 3d7af87 Add jungle animals
Git responds with the same merge conflict we had previously:
error: could not apply 3d7af87... Add jungle animals

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

Could not apply 3d7af871d2677c64399c674f6a5937b9bbc48852... Add jungle animals
If you run git status you'll see this:
interactive rebase in progress; onto 21826a9
Last commands done (3 commands done):
   squash 595f37e Added water animals
   squash 3d7af87 Add jungle animals
  (see more in file .git/rebase-merge/done)
No commands remaining.
You are currently rebasing branch 'animals' on '21826a9'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

 both modified:   animals.txt

no changes added to commit (use "git add" and/or "git commit -a")
The reason that our rebase is failing is because git is replaying our commits one-by-one on top of master, and as it does so, it's hitting a commit that is changing the same lines as a previous one. Once again, edit your animals.txt file to combine the merge conflict:
horse
cow
chicken
<<<<<<< HEAD
whale
seahorse
dolphin
=======
monkey
python
bird of paradise
>>>>>>> 3d7af87... Add jungle animals
Should become:
horse
cow
chicken
whale
seahorse
dolphin
monkey
python
bird of paradise
When you're done, git add animals.txt to signal to git that you've resolve the conflict. Then, you can tell git to continue running the rebase (i.e., do the next commit in your list): git rebase --continue. Finally, git finishes replaying all our commits, and gives us a chance to alter our new commit message:
# This is a combination of 3 commits.
# This is the 1st commit message:
Adding animals.txt

# This is the commit message #2:

Added water animals

# This is the commit message #3:

Add jungle animals

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Thu Feb 2 13:01:46 2017 -0500
#
# interactive rebase in progress; onto 21826a9
# Last commands done (3 commands done):
#    squash 595f37e Added water animals
#    squash 3d7af87 Add jungle animals
# No commands remaining.
# You are currently rebasing branch 'animals' on '21826a9'.
#
# Changes to be committed:
# new file:   animals.txt
#
You can change it, or leave it as is. Save and exit your editor. In the end, I have a single commit that combines all of my other commits into one:
$ git log
commit afc5bad7f651be478c69c4e117102bfeb183323c
Author: David Humphrey (:humph) david.humphrey@senecacollege.ca <david.humphrey@senecacollege.ca>
Date:   Thu Feb 2 13:01:46 2017 -0500

    Adding animals.txt

    Added water animals

    Add jungle animals

6. The gh-pages branch

For our final experiment, let's learn how to use Github's special gh-pages branch to host static web content.
First, let's convert our animals.txt file to HTML. Open the file and modify it so it's a proper HTML document, something like this:
 <!doctype html>
 <title>Learning about gh-pages</title>
 <body>
 <ul>
   <li>horse
   <li>cow
   <li>chicken
   <li>whale
   <li>seahorse
   <li>dolphin
   <li>monkey
   <li>python
   <li>bird of paradise
 </ul>
Next, commit your change, then use git mv to rename animals.txt to animals.html. Make sure you commit that rename change as well.
Now let's create a new branch named gh-pages that points to our current commit on animals:
git checkout -b gh-pages animals
Next, push your new gh-pages branch to Github and your forked repo:
git push origin gh-pages
Lastly, we can visit our hosted page at http://{username}.github.io/Spoon-Knife/animals.html. Mine is at https://humphd.github.io/Spoon-Knife/animals.html. There are more instructions here.
NOTE: it can take a few minutes for your gh-pages branch to get published.


 

Thursday, 9 February 2017

Lab 3: Fixing a Bug in Mozilla Thimble

For this lab, we had to choose a issue within Thimble to solve. I chose to go with:

https://github.com/mozilla/thimble.mozilla.org/issues/1536

The original person who created the issue made this comment:

"A user guiding teachers through Thimble noted that on their Chromebooks, Thimble interpreted both parts of double- and single-quotation mark pairs as closing quotations, breaking attribute values. We should make sure Thimble interprets opening and closing quotation mark keystrokes differently on Chromebooks or provide an easily discoverable work-around."

To start this lab, I followed David Humphrey's guide to fixing a bug in Thimble (http://blog.humphd.org/fixing-a-bug-in-mozilla-thimble/), which does involve some initial setup. I had to make 3 downloads:

1) Node.js
2) Vagrant       -> **stored in C:/Hashicorp/Vagrant**
3) Git

I forked Bramble to my Github account, but when I tried to use:

$ git clone --recursive git@github.com:{your-username}/brackets.git
For some reason I got this response inside Git Bash:




















So this is my first set-back...

I googled the problem for about 5 minutes with no real progress. By chance I happened to look at the actual Brackets repo I had forked. I looked at the README.md and saw it had instructions of its own. I followed those instructions, typing:

git clone https://github.com/[yourusername]/brackets --recursive
Now it works!! All of the submodules are coming in. I navigated to the root of the directory I cloned:

ls -a  -> to view list of all folders
cd brackets   -> go to the new directory of the repo I cloned.






I did the command, and nothing happened for several seconds. I thought something was wrong, but eventually it started to do stuff (lots of deprecated warnings, then actual installations). From here on, I went back to David Humphrey's tutorial and followed onwards for getting Bracket set up on my local machine.
Futher down, I ran into a familiar problem again. Using -


$ git clone git@github.com:{your-username}/thimble.mozilla.org.git
I was not given access rights. I figured I'd use the same fix as the first problem up above and changed it to:

$ git clone https://github.com/Blackweda/thimble.mozilla.org.git

And that solved the problem again. I actually just realized now, I cloned the thimble.mozilla.org.git repo inside of my brackets folder... that may cause BIG problems in the future, but for now.. we'll just hope nothing goes terribly wrong.

Moving into the thimble directory I continued with: $ vagrant up and received this error message:















It is saying that I don't have any 3rd-party software for Vagrant to use.. I'm hoping this has nothing to do with the fact that I messed up directories, so I'm going to go ahead and download VirtualBox from the internet. Once I had it installed, I tried the command again in Git Bash.

Worked.





















Next, I will have solve the problem of the simple bug for Thimble. I will revisit this post with the results of my efforts shortly...

[Few Days Later...]

Apparently even before getting into trying to solve the bug, I tried to reproduce the problem on a Chromebook I borrowed, because the bug involved Chromebooks. Already the issue has been closed for now.




















I am thinking to switch to another issue:

https://github.com/mozilla/thimble.mozilla.org/issues/1715

========================================================
ISSUE 1715

While browsing files, I came into these:

thimble.mozilla.org/scripts/localize-client.js

and noted the following lines of code:

let nunjucks = require("nunjucks");

let template = nunjucks.configure(filePath, { noCache: true });


thimble.mozilla.org/package.json

"dependencies": {

"npm-run-all": "^1.5.1", "nunjucks": "^2.3.0"

thimble.mozilla.org/services/login.webmaker.org/Gruntfile.js


grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),




At this point I got curious, if I just happened to change the number inside the dependencies block,
would that automatically make the installs choose the next version?

This also gave me an idea that possible package.json is referenced in another file that will do some sort of initConfig() for setting up our Nunjucks??

So, in order to test this bug, it seems that I have to get rid of my Thimble and then re-install it and look to see what version of Nunjucks is loaded during installation. Looking at the vagrant commands, it looks like I'll have to PROVISION it. I tried 'vagrant provision' but the machine is saying:

$ vagrant provision
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.

So I typed in 'vagrant global-status' and it showed me the ID of my VM. I then typed in 'vagrant provision myID' and let it run. After doing so, my same virtual box is there... so I'll run through the processes that happened and see if Nunjucks was anywhere in the list of things affected. Unfortunately I did not see it... I'm going to try a command the professor mentioned in class - 'vagrant destroy'. This should completely remove my setup of Thimble I hope, so I can remake it and see the version of Nunjucks I have and see if the issue looks similar to what I have.

I'm looking for this:


npm WARN deprecated nunjucks@2.3.0: potential XSS vulnerability in autoescape mode, and with escape filter was fixed in v2.4.3
Let's go. I destroyed it, now I redo everything with 'vagrant init', then 'vagrant up' again. Uh oh.. got this....















So I decided to completely delete both the cloned versions of Brackets and Thimble from my local machine and start over... I asked some questions about how the package.json file, and I was correct in thinking that changing the version number will actually change what files the software downloads!

So what I'm going to do is this:

1. Get the most recent version of Brackets and Thimble and fork them.
2. Clone both versions of the issue branches to my local machine.
3. Create an issue-1715 branch in both repositories. (My concern is: do I do this on GitHub or inside       my local machine??)
4. Change the package.json file inside my local machine for both of the software packages.
5. Test that they work.
6. Push both issues back to the GitHub account.
7. Make a pull request back to the original repositories.


While re-cloning Brackets and Thimble again, I realized that my cloned version is also a repository because I saw the (master) branch designation... So I suppose that only when I do '$ npm run build' will the software actually be working on my local machine, but the repository is actually present.

So what I did was:

Inside Git Bash, while on the master branches of Thimble and Brackets, I made another branch for my issue:

git checkout -b issue-1715

When I went inside Thimble's package.json file, I saw nunjucks at version 2.3.0. I quickly made a change to 2.4.3. Inside Bracket's package.json file, I actually didn't see nunjucks at all!! So I added a line inside their dependencies section with "nunjucks": "2.4.3",

Once I did that, I [git add] and then [git commit] both of them. I then pushed them both back to my GitHub repos:


$ git push origin issue-1715
Going back to my GitHub account, it shows a notification that I pushed something.














I will click the 'Compare & pull request' and proceed on both repositories. The pull requests are here:

https://github.com/adobe/brackets/pull/13105
https://github.com/mozilla/thimble.mozilla.org/pull/1742


Setting up Thimble and Brackets wasn't too much of a hassle, because I simply followed the instructions. The hardest parts was understanding the differences between what my Forked Repo was, and what my Cloned Repo was.. and where to make changes.

I basically learned that I had to Fork another group's project, clone it to my local machine, make a branch in the version of my machine, make the changes and push it back to my GitHub repo... then make a pull request back to the group project where it came from.

The bug itself was a simple fix: simply to tell the software to look for the better version of nunjucks while it is installing its plugins.. I edited the version inside package.json so that while the software is looking for its dependencies, it will get the correct version.



[Check Back A Few Days Later]

I went back and saw this posted on the Brackets page:


 


  So two things mentioned: 

Changing the dependencies changes nothing if the code never uses it. Also, I needed to be in the Brackets version of Mozilla, not the original Brackets used by many different softwares!! So let's go do that.