Sunday, June 19, 2016

The Code 7 Project - Problem 1 - Sums

(Python Output Screenshot in Terminal)

The Code 7 Project - Problem 1 - Sums

"Goodies" in this blog post: 

  • My solution code in Python (GitHub link & description below).
  • The 3-5 essential commands for GitHub command-line.
  • Other links.

Things I practiced while working through this problem:

  • Coding in Python (function, dictionary, file reading, unittest, ...).
  • Running Python code (as a "script" file, as opposed to "line-by-line" in Python IDLE).
  • GitHub commands in command-line (in terminal for Mac).
  • Googling.

Problem 1 Description:  Read a data file and tally sums, while displaying each total sum as soon as possible, i.e. you can't just do all the sums after reading the whole data fileYou have to output each sum as soon as possible, while reading line-by-line.  In other words, you have to tally sums on-the-fly.  But sums of what?  In the original example problem, the sums to be calculated are of--and I quote--"the number of red-haired students in each grade, in each school, in each city, and in each state", taken from a data file.  One key assumption is that the data file is already sorted, as was the example data in the original problem description.  I re-created that data in a CSV file (problem1.csv), to be read by my Python code (problem1.py).

Links, Links, Links:  Programming Practice —> Github —> Blog:

My Overall Strategy:  "Strategic Google searches".  :)  Sometimes the first results aren't always the best.  I didn't always find what I needed on w3schools or Stack Exchange.  For GitHub command-line, I even found a visual explanation, but I eventually figured out it still didn't meet my needs.  Sometimes I had to rephrase and try different search terms.  Learning Python was less overwhelming with this website (simple, interactive, no Python install needed)learnpython.org
---

Some useful notes for using GitHub (basically Dropbox for code) with command line:

I found these 2 web pages helpful for extracting the essential commands:

  1. readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1/ 
  2. readwrite.com/2013/10/02/github-for-beginners-part-2/

And here's my summary of the essential commands:

(I already set up my account, login, password, etc. as well as the repo on the GitHub website.) 
  • Navigate to the folder of problem1.pyType "ls" (lowercase L and S) and hit Enter to see what files/folders there are, and type "cd <folder name>" and Enter to go down a folder path.  The first few lines in the picture at the beginning of this blog post show this in action.
  • Type these 5 commands in the command-line, in order (just replace "hchiam" with your username, and "code7" with your GitHub folder name):
git init 
git add problem1.py 
git commit -m “problem 1 
git remote add origin https://github.com/hchiam/code7.git 
git push

And then after that, to update/add files (I committed 2 files at the same time):

 (Notice the similarity of the git commands to the ones just mentioned above.)
  • Navigate to the folder containing the files problem1.py and problem1.csv.
  • Type these 3 commands in the command-line, in order:
git add problem1.py problem1.csv 
git commit -m "Starting with the actual code" 
git push
---

Extra note on how I ran the python file (the simplest way):

  • Open the command-line program.
  • Navigate to the file folder.  In this case, to the folder with problem1.py in it.
  • Type this 1 command:
python problem1.py
  • That's it.

_________________________

LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics

Friday, June 17, 2016

Code 7 Project + Github + Blog


The "Code 7 Project"*:  
I'll be practicing general programming skills by building 7 simple programs over 7 different weekends (when my other commitments allow it). 

Project breakdown: 
  1. Get a short list of simple programming practice problems.
  2. Program some working code for 1 problem by the end of 1 day.
  3. Commit to Github account.
  4. Post to this blog.

Simple Practice Problems:
From a quick Google search, I got 2 websites:
  1. http://blog.smartbear.com/programming/7-silly-programming-challenges-to-do-for-fun
  2. https://adriann.github.io/programming_problems.html 
The first link should not be overwhelming.  With just 7 seemingly straightforward practice problems, it should be manageableFor problem # 7 however, I wanted to have something more motivating for me, with more general problem-solving problems, and not just mathSo I also found the second link has many problems that I can use to keep going on as long as I want.  I decided that I want to do these problems, instead of the "Project Euler" problems, for #7.  I may also group code for the problems from this website once I start working on this set, especially in the beginner levels. 

Strategies I Can Think of Right Now:
  1. Set dates in my planner for each of the 7 problems.
  2. Decide ahead of time which programming language to use for each practice problem.
  3. Figure out how to easily get around to using the language (minimal installation besides what I already have installed).
  4. Sort of related to 3:  find websites that can teach me to do that quickly.
  5. Put it down as a to-do with a checklist on Habitica (formerly known as HabitRPG).
From initial these strategies, here are my notes so far:

Programming Practice —> Github —> Blog:

http://blog.smartbear.com/programming/7-silly-programming-challenges-to-do-for-fun/

  1. in Python
  2. in Java
  3. in Python https://opentechschool.github.io/python-beginners/en/simple_drawing.html
  4. in Scratch
  5. in SQL http://www.w3schools.com/sql/default.asp and type it into the online code and just copy and paste the code into a text file
  6. in HTML5 canvas http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_path add lines and fill and just copy and paste the code into a text file
  7. do not do, and instead go to: the next website: https://adriann.github.io/programming_problems.html (all of them in python) [EDIT:  I'm actually planning to use the websites CheckiO and CodeWars.  I'm already using them on weekdays.  You can see my current levels at http://hchiam.blogspot.ca/p/current-programming-xp.html]
 (I already have Python, Java, and Scratch installed, so I can just create SQL and HTML5 code online on the w3schools websites.)


_________________________
*Disclaimer:  I do not own the phrase "Code 7".  Any appearance of similarity to brands, sayings, phrases, etc. is purely coincidentalI'm just using it as a convenient, simple name for this project.
_________________________

LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics

Wednesday, June 8, 2016

Quick Vector Graphics Lesson

 
A Test Vector Graphic Drawing

Inkscape is actually surprisingly easy to learn.  
It took me less than an hour to do these 3 things:  install, create, & embed.

1) Download & install Inkscape (and also XQuartz if you're using a Mac):  

 inkscape.org/en/download 

2) Learn how to create the donut above 

(The techniques are easy to pick up on if you have a context to use them in.  Follow the steps but also pause to experiment with the alternate controls to see how they work, like intersect, difference, union, etc. as well as the control and shift buttons in combination/isolation.)
youtube.com/watch?v=s41_-qsmA7s 

3) BONUS:  Learn how to embed the .svg file into a webpage, like I've done above 

(I've also adjusted the frame size to 300 x 300.)
tech.spoilertv.com/2012/05/embedding-pdf-or-other-documents-into.html



LINKS TO OTHER STUFF: 

Favourites
Programming
Original Art
Games

Chinese Learning Projects:
 - Book
 - HSK 1
 - HSK 5
 - Homonyms Mnemonics