Friday, February 28, 2014

NERDTree Bookmarks in Vim

Overview
Vim is an extremely awesome tool for editing code, but with so many files in web applications, it can quickly become confusing to use. When you're trying to follow 4 or more files at a time, you may decide to leave files open even though you aren't really paying attention to them.

What we Want
What would be great to have is a way to bookmark files/folders, so that we can quickly go to them right when we need them without searching through hundreds of files/folders to find them.

Solution
NERDTree has a bunch of fantastic features, one of them being bookmarks. This is just their way of tagging files and allow you to quickly goto them when needed.

How to show the bookmarks section
To so the bookmarks section, just goto your NERDTree window and press Shift-B. This will toggle the bookmarks section, making it appear. If you want the bookmarks section to not be show, just hit Shift-B again.

How to create a Bookmark
To create a bookmark, just put your cursor over the file/folder you want to bookmark, then type and enter :Bookmark. This will create a bookmark in the bookmarks section. You can treat this as any other file/folder in NERDTree, and open it with "i" or "o".

How to Delete a Bookmark
To delete a bookmark, put your cursor over the file/folder you want to delete, then press Shift-D, then confirm by typing "y".

Conclusion
Bookmarks can make your programming experience much more enjoyable and is highly recommended over having a bunch of windows open at once

Resources
  • http://dailyvim.tumblr.com/post/51238147680/nerdtree-bookmarks


NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Thursday, February 27, 2014

How to goto the beginning or end of a line in Vim

Overview
Much of the time in vim you'll want to goto the beginning or end of a line. My solution thus far has been to just press "l" until I get to the end, but that takes a long time on some long lines. Another bad solution is to just hit "w" or "e" to go by every word. But that can be annoying because if your reflexes aren't good, the cursor will just end up on the next line

Solution

  • To goto the end of a line
    • hit "$". If your familiar with regular expressions, this signifies the end of a line. If you would like to goto the end of a line and enter edit mode, hit "A".
  • To goto the beginning of a line
    • hit "0" or "^". I personally find it easiest to hit "0", but if you're familiar with regular expressions, "^" signifies the beginning of a line. If you would like to goto the beginning of a line and enter edit mode, hit "I".
Conclusions
These commands will allow you to be a lot faster when editing your code.

Resources:
  • http://stackoverflow.com/questions/10243551/go-to-beginning-of-line-without-opening-new-line-in-vi
  • http://stackoverflow.com/questions/105721/how-to-move-to-end-of-line-in-vim


NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Wednesday, February 26, 2014

How to Reset your Branch to Remote Code on Github

Overview
Sometimes Github may be giving you issues and not allowing you to reset your local branch with your remote branch. If you don't have any code that you need saved on your local branch, here's a good way of fixing this situation

Solution
Issue these commands:

    git checkout master
    git branch -D <your_branch_name>
    git fetch
    git checkout <your_branch_name>

Explanation of Commands
1) git checkout master - What this does is checkout your master branch so you are no longer on the branch you want to reset
2) git branch -D <your_branch_name> - This deletes your local branch, even if files are not merged from your local machine to your remote github account. This will not delete anything that you have already pushed to github.
3) git fetch - This downloads all of the branches onto your local machine so that you can easily checkout any of them onto your local machine
4) git checkout <your_branch_name> - This checks out the branch you want to be on that was just downloaded from github.

Conclusion
This will reset all your local changes, so you have to be careful that your local changes are saved. You should be able to issue the command "git stash" before, then "git stash pop" after in order to maintain local changes, but I need to test this first to make sure it works before saying for sure.



NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Monday, February 24, 2014

How to Execute a Terminal Command From Vim

Overview
Vim is my editor of choice, mostly because I like how it looks, I like being able to solely use the keyboard and, after some practice, the commands are pretty intuitive and easy to learn. However, one major thing I need to do often in order to be effective at my job is to grep for variables and functions to follow the code's flow. But vim makes it difficult because it's run in the terminal that you opened it from, so unless you close out of your file you'll have to find other ways of executing the command.

Bad Solution
The bad solution to this is to have multiple terminals, one for code, and one for doing random commands, like grep. The problem with this is this can quickly get very clunky and hard to organize.

Good Solution
The proper solution to this is to issue the command in vim. You can issue any command in the terminal from vim by typing :! then then command. So to execute a grep command from the terminal, type this in your vim file:

        :! grep -r "<thing_you_are_searching_for>"

Replacing <thing_you_are_searching_for> with whatever word or phrase you want to replace. You will be taken back to the terminal and shown the results from your search. You can then go back to your vim session by hitting the "Enter" button on your keyboard.



NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Friday, February 21, 2014

Security: Make Sure None Of Your Passwords Are Stored On Your Computer

Overview
------------
We've all done stupid things in our lives. As programmers, we tend to do stupid stuff on our computers. One of those stupid things may be storing passwords in files on your computer.

We all have reasons why we may have done this. Whether we "needed" to add those passwords in to make a program work, or we wanted to save ourselves time by making a program that automatically logs into certain websites to scrape information.

Don't Store Passwords On Your Personal Computer
------------------------------------------------------------------
A good rule of thumb is to not store your password anywhere on your local computer. Because personal computers are very vulnerable from random stuff we download, going to sketchy sites and a large number of other things, it makes it easier for hackerz to gain control of your computer/log in as you. Because of this, anything you can view on your computer, whoever gains access to your computer can view the exact same thing. So any passwords you have on your computer will be compromised without even knowing it.

How to Fix This
---------------------
What you should do is search your computer and find all of the passwords that you use to log into websites/bank sites and any other important things, like social security numbers, and remove them. In order to do this without your computer recording the command, type this command (MAKE SURE THERE'S A SPACE IN FRONT OF IT) in your terminal:

 grep -r "<your_password_you_want_to_find>" /

Make sure you replace <your_password_you_want_to_find> with the password you are trying to find on your system. Here's an explanation of what this command does:

space at the beginning - The space at the beginning tells the terminal not to record this command in your bash history (in the ~/.bash_history file). You'll want to be sure this will work first by issuing the command "echo $HISTCONTROL" in your terminal. The output you want to see is either "ignoreboth" or "ignorespace". If neither of those is the output in the terminal, then you'll want to set that variable like this: "export HISTCONTROL=ignorespace"

grep - This command is the standard search in unix. It searches for the word/phrase given to it

-r - recursively look in all directories that you specify. This allows you to look inside the directories in the folder you specify, allowing you to search the entire system

"<your_password_you_want_to_find>" - This is the word/phrase that is being searched for. If you wanted to find variations of a password, you can make this into a regex expression.

/ - This makes the command run under the root directory (The lowest directory there is) so that you can search the entire computer.

Removing the Passwords
--------------------------------
Once the grep command find all of the occurrences of your password, you need to go into each file and remove the password.

Conclusion
--------------
Removing passwords from your computer is important to ensure your security from hacking attacks. Some passwords for things like websites or databases you create may need to be stored on your computer, but you should never have to store things like your email password or social security numbers on your personal computers.

Resources
-------------
- http://stackoverflow.com/questions/8473121/execute-command-without-keeping-it-in-history
- http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/

NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Thursday, February 20, 2014

Adding Desktop Workspaces in Ubuntu

Overview
Having 4 Workspaces in Ubuntu is fantastic. You're able to have whatever windows you want cleanly open, while still keeping your screen clean and organized. However, 4 Workspaces is not always enough. For me, having 2 more workspaces would allow me to be a much more productive

CompizConfig Settings Manager
In order to add more screens to your setup, you'll have to download CompizConfig Settings Manager. goto your application "Ubuntu Software Center" and search for "CompizConfig Settings Manager". Download the application, then open it.

Once the application is open, Search for and click on "General Options". In the new menu, click on the "Desktop Size" tab in the top right. In this new tab you'll see 3 options:
  • "Horizontal Virtual Size"
    • If you want to add a column of new Workspaces, then add 1 to this
  • "Vertical Virtual Size"
    • If you want to add a row of new Workspaces, then add 1 to this
  • "Number of Desktops"
    • I'm not sure what this option does

When You're Finished
When you're finished making edits, just close the application and you'll now have more workspaces!


NOTE: This guide is currently in rough draft form and could be improved with clearer instructions and pictures. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Wednesday, February 19, 2014

Learning Programming Effectively

Overview
If you ask most programmers how to become great at programming, you'll usually get the same response, "Program." While experience in writing code is extremely important in learning how to be a great programmer it doesn't quite capture the full picture of how to learn programming effectively.

First Things First: Please Take All This Advice With A Grain of Salt
I've found the worst thing you can do is nothing at all. Do whatever you enjoy doing to learn. If you are doing nothing because you want to do something "right," then that will just hinder you and your talent. So whatever advice you don't like here, just ignore.

The best way to learn anything is to start a passion/obsession for it. Just do whatever you need to do to love coding. If you become proficient, you start applying some of these techniques.

Taking the Athlete Approach
Becoming the top in your field is very similar no matter what you're doing. Because athletics has refined their training strategy over many years, I like to take that as an example.

Practicing
If you look at College Athletes, they typically train for around 4-5 hours (or longer) every weekday (I used to be one of them), taking a couple days off to rest. During these practices they typically run drills, learn how to refine their skills, learn new skills, watch film of themselves and others, and scrimmage/play the game.

Practicing Learned Skillz
If you're like me, you don't like doing repetitive stuff. If you do it once, then you want to say it's done and you'll never have to do it ever again. However, this is not great learning-wise. Athletes will do the same stuff over and over again because that's what allows them to get faster and/or stronger at that activity, as well as commit it to memory. If you want to get better at programming, you'll have to practice doing things over and over again. If you do this, you won't forget if you run into the issue ever again (which is extremely likely), you'll be able to use that knowledge on other issues, and you'll be a lot faster at writing code like that.

Practicing for Speed
The faster you are at performing certain tasks like debugging, writing code or finding the correct files to edit, the more time you will have to be a better programmer. Doing speed excercises, like writing a certain python program over and over quickly, or getting to different folders/files in unix as fast as you can, or debugging a bug faster and faster, will allow you to be a faster programmer and be able to retain information in your brain for fast retrieval.

Learning from Mistakes
Most athletes don't have train alone: They have coaches to help them get better and teach them how to get over personal hurdles. Programming has something actually better: A community of coaches/teachers.

I'm pretty sure most programmers know this one, but I'll repeat it here: You can Google Anything! Google is a fantastic resource for debugging errors in your code. The programmer community is one of the largest communities on the internet. Older programmers know how tough learning how to program can be, and it seems almost all want to give back to the younger generation. Because of this generosity, we have communities like Stack Overflow to help you learn how to fix bugs you've encountered. All you need to do is type in your error in Google and you should get at least a couple results. If you can't find anything from Google, goto Stack Overflow yourself and ask the question!

Learning new information
Athletes like to look up information to see how they could improve their techniques or how to train better. Programmers need to learn more information about specific technologies, or research to see if there are any new programs or technologies. Again, we have Google to the rescue. Google anything, find something you want to learn about, and take notes! Study it like something you'd study in school (Unless you don't want to).

Taking and Reviewing Notes
You need a way of remembering things you've done. If you don't remember, then you'll be bound to repeat looking up stuff on Google, which is inefficient as well as annoying to do. By taking notes, you'll be able to easily review important details and commands you've learned.

Along with taking notes on things you've done, you should also write comments in your code! If you ever go back to the code you've written, you want to be able to easily find out what you were thinking. Also, you want others to be able to read your code and find out what the heck you were thinking.

Taking notes is hitting a save button in a video game. If you were fixing a bug and you need to go back to it another day, then sometimes you'll have to go all the way back to the beginning, retrying things you've already done to try to fix it. If you write notes, you can be caught up to speed extremely quickly and won't have to redo things you've already done.

Reviewing Video
I don't think a lot of people will take this one seriously, but reviewing video of yourself programming/learning can significantly help you become a better programmer. It allows you to examine your actions, allowing you to take note and fix things later. It allows you to take notes on things like code and commands later so you don't have to bother yourself while you're in the zone. It allows you to review things at a later date and share with others so that they may learn how to do things they didn't know how to do before.

If you want help setting up your environment to be able to automagically take video from the terminal, and reduce the size of the file, please comment/message me and I will show you how. It's a bit too complicated to explain here, but it's really cool once you've gotten it going.

How to Apply This Strategy of Learning
Here's a decent way of applying these learning techniques
*This should be done at least once a day for about 30 minutes*
Take Film
- Look over yesterdays stuff
  - quickly go over commands in the terminal
  - Try to write any programs and code learned yesterday again quickly
- Repeat until feel comfortable
Stop Film
Review Film at 8 times speed & Write Down notes you feel would help

*This should be done for every new thing you do, trying to limit yourself to programming thing per hour*
Take Film
-  Review What have learned previously
-  Run the new commands/code you've learned
-  Write Code
  - Write Comments as you go
  - Keep text file of what you've done
  - If you don't know something:
    - Look it up
    - Write down the thing w/ comments & fix code
Stop Film
Review Film at 8 times speed (or faster) & Write Down notes you feel would help

Conclusion
If you are just getting started learning how to program, please don't pay too much attention to this post. The most important thing you can do is develop a passion for programming and to start writing programs or, if you are more of a beginner, taking classes at sites like Code Academy or TeamTreehouse. However, if you're an intermediate programmer trying to become a great programmer, maybe try some of these techniques if you feel like it.



NOTE: Please note that I am not an expert at this topic and this info can certainly be improved. If you have questions, comments or suggestions for this blog post, please comment! Also, this guide is currently in rough draft form. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).

Tuesday, February 18, 2014

Programmer's Guide to Note Taking

Overview
I've always been an avid note taker, but it always seemed that I would go from one note taking app to another. I thought all my problems were solved when I found out about Google Docs. It seemed like the perfect solution for me to view notes across my 4 computers. Google Docs allows you to sync instantly over the internet, write down and organize notes on any computer with an internet connection and share painlessly with others over the internet. It was fantastic for a long time, but always had an issue: you needed an internet connection.

Reason For Issue
I would sporadically go without internet connection in dire situations: When I was bored, in a meeting or at my Girlfriend's mum's house. In these situations I would be left without my notes and not know what to do.

Possible Solutions
There are apps for google docs that you could download in order for your notes to be downloaded locally and synced up when you have internet connection. However, I found most of these apps were either hard to use, or required you to buy it.

There was also a way to download your google docs using "googlecl". This seemed like a perfect solution at first, but apparently the code is broken in several key areas, like uploading a document to a specific folder, so it isn't a great solution if you have multiple folders.

Programmer's Solution
I've learned to love Github. All of the pushing of code up and pulling it down locally, collaborating, etc. It's just a fantastic tool for programmers to write code and be able to manage the code effectively. But the awesomeness doesn't have to stop with coding.

By creating a new repository just for note taking, you're able to easily pull down your repository to each computer you want to write notes on. Because you're a programmer, you'll be able to then take notes on your favorite text editor. To save time on formatting, you can take notes in markdown format, which is easy to learn and take notes on. You can collaborate easily with others if you want to create a repository of notes on a class.

One thing to note is these notes won't be private unless you make the repository private. Github has a fantastic deal for college students. They give free micro subscriptions to college students for four years, which give you 5 free private repos. If you aren't a college student, then you'll have to pay $7 a month to have private repos.

Other People Who've Tried This
Here's another person who's tried this note taking strategy: Cory's Blog

NOTE: Please note that I am not yet an expert at this topic and this info can certainly be improved. If you have questions, comments or suggestions for this blog post, please comment! Also, this guide is currently in rough draft form. If you would like it to be more in depth, I will be extremely happy to improve on this, all you need to do is ask in the comments and I will do it asap (I just don't want to spend forever on something no one reads and/or cares about).