Friday, May 29, 2015

Python: SimpleHTTPServer

Whats nice about building a website is that you can just change the resolution on the desktop browser and see how the page renders on a smaller resolution, right? Wrong. At least In my experience I've found it to be invaluable to review the website on an actual mobile devices. Evidently this command is one of the most popular terminal commands. It's definitely one of my favorites.

Challenge: Review a website on mobile devices.

Solution: Use pythons SimpleHTTPServer to host the pages on a local port from the command line using

$ python -m SimpleHTTPServer 2000

The command  $ python -m .. is used to run a python module. In this case I am using the SimpleHTTPServer module which will serve the files of the current directory. This module has been merged to http.server in Python3. Running this command with the argument 2000 servers the files to the local server to that port When I did not specify the port it defaulted  to port 8000.

On my mobile devices, that were hooked up to the local internet,  I just entered the local ip address of my computer followed by :2000, my specified port. To find the  ip address of my computer I used the command $ ifconfig | grep "inet". Looking it up now, this one $ ifconfig | grep "inet" | grep -v | cut -d\ -f2 is better because my command returns multiple inet addresses and extra text.

Friday, May 1, 2015

GitHub : A Cheat Sheet

This post is for me in the future, or any one else who is just starting or wanting to clean up their GitHub game.

First Things First

    $ git status
    • If five seconds have passed by and you haven't typed git status, you're doing it wrong.
  • Remember git is your friend. When errors come up do not panic or make hasty changes. First slowly read through the comment git provided with the error. Often you will find your solution is provided.

Get Started

    $ git clone <repo_url>
    • To get the repository you want to work on create a local copy in your current directory

Per Feature You Implement - Create a new branch

    $ git checkout <latest_qa_or_production_branch>
    • Will switch you to the specified directory, this updates your local directory files to match those in this existing branch
    $ git pull origin <latest_qa_or_production_branch>
    • Will pull changes from the locally stored branch and merge them onto the locally checked out branch
    $ git checkout -b <new_feature_branch_name>
    • Will create a new branch locally and make that your working directory
    • -b saves you from having to write git branch < .. > before git checkout < .. >

Per Change You Make to the Feature

    $ git add <file_changed_or_directory_changed>
    • Updates the index to have all the changes made in the file or directory specified
    • If you enter $ git status at this point you will see a list of the "Changes to be committed"
    $ git commit -m <commit message>
    • Stores the current copy of the index and a log message from the user, basically it packages up the changes you've made and your message explains why they are needed
    $ git pull origin <latest_qa_or_production_branch>
    • This step is vital to check that your changes are compatible with the existing branch
      • Fun times. This could be the step that is the most exciting as you have to muddle through merge conflicts
    $ git push origin <new_feature_branch_name>
    • Hurray! You have now pushed your local changes to the remote repository
    Go to GitHub
    • Create a pull request setting the 'base' to the <latest_qa_or_production_branch> and 'compare to' <new_feature_branch_name>
    • Review the highlighted differences
    • Merge pull request
      • Note: As I am currently just working on my own projects I merge my own pull requests, but of course with a team you may not be merging your own requests.
To Tie It Up

    $ git checkout <latest_qa_or_production_branch>
    $ git pull origin <latest_qa_or_production_branch>