<?xml version="1.0" encoding="ISO-8859-1" ?>			<rss version="0.91">
			<channel>
			<title>Breck Yunits' Code Blog</title>
			<link>http://breckyunits.com/code/</link>
			<description>A blog specifically about coding and technical matters.</description>
			<language>en-us</language>
				<item>
						<title>Cygwin SSH Client Keep Alive</title>
						<link>http://breckyunits.com/code/cygwin_ssh_client_keep_alive</link>
						<description><p>Add this to your /etc/defaults/etc/ssh_config file to prevent SSH servers from disconnecting you after inactivity:</p>

<blockquote>
  <p>ServerAliveInterval 60</p>
</blockquote>
</description>
						</item><item>
						<title>A Pretty Picture</title>
						<link>http://breckyunits.com/code/a_pretty_picture</link>
						<description><p>body {
margin: 0px;
    padding: 0px;
    text-align:right;
}
div {
    height: 1px;
    width:1px;
    display:inline-block;
}</p>
</description>
						</item><item>
						<title>Augmented Gitignore</title>
						<link>http://breckyunits.com/code/augmented_gitignore</link>
						<description><p>.bundle
db/<em>.sqlite3</em>
log/*.log
*.log
tmp/**/*
tmp/*
doc/api
doc/app
*.swp
*~
.DS_Store</p>

<p>Source</p>
</description>
						</item><item>
						<title>Windows Flush DNS</title>
						<link>http://breckyunits.com/code/windows_flush_dns</link>
						<description><p>Open cmd.exe.</p>

<p>Run:</p>

<blockquote>
  <p>ipconfig /flushdns</p>
</blockquote>
</description>
						</item><item>
						<title>Insert a line of text to the top of a file</title>
						<link>http://breckyunits.com/code/insert_a_line_of_text_to_the_top_of_a_file</link>
						<description><p>If you have a massive text file you want to add a line to without opening the file, here's a quick solution:</p>

<blockquote>
  <p>sed -e '1i\text_to_insert' -i file.txt</p>
</blockquote>
</description>
						</item><item>
						<title>wget don't save file</title>
						<link>http://breckyunits.com/code/wget_dont_save_file</link>
						<description><blockquote>
  <p>wget -O /dev/null http://address.com</p>
</blockquote>
</description>
						</item><item>
						<title>ls color scheme</title>
						<link>http://breckyunits.com/code/ls_color_scheme</link>
						<description><p>found this helpful color scheme for ls. toss in your bash_profile.</p>

<p>alias ls="ls --color=auto"
LS_COLORS="di=31;1:ln=36;1:ex=31;1:<em>~=31;1:</em>.html=31;1:*.shtml=37;1"
export LS_COLORS</p>
</description>
						</item><item>
						<title>Dump MySQL schema only</title>
						<link>http://breckyunits.com/code/dump_mysql_schema_only</link>
						<description><p>I found this command to dump just the schema.</p>

<p>mysqldump -u root -pmypassword test_database --no-data=true --add-drop-table=false > test_dump.sql</p>

<p>You can then load the file easily.</p>
</description>
						</item><item>
						<title>gca alias for faster git</title>
						<link>http://breckyunits.com/code/gca_alias_for_faster_git</link>
						<description><p>One of my most frequent commands is:</p>

<p>git commit -am "message"</p>

<p>I made a simple alias to save keystrokes:</p>

<p>alias gca="git commit -am "</p>
</description>
						</item><item>
						<title>Recursive ls</title>
						<link>http://breckyunits.com/code/recursive_ls</link>
						<description><p>Add the -R option to ls to recursively list the contents of a directroy.</p>
</description>
						</item><item>
						<title>vim macros</title>
						<link>http://breckyunits.com/code/vim_macros</link>
						<description><p>Let's say you want to add comments to your php functions following the conventional format:</p>

<p>/**
* Returns the sum of 2 variables.
*
* @param int $a
* @param int $b
* @return int $sum
*/
function sum($a, $b)
{
 $sum = $a + $b;
 return $sum;
}</p>

<p>You can record a macro to help speed up the commenting process.</p>

<p>Just type q followed by the letter you want to assign the macro to (in this case let's use c), type your keystrokes, then hit q again to stop recording. Now hit c to replay your macro.</p>

<p>You can overwrite the macro by repeating the above steps.</p>

<p>Bonus tip:</p>

<p>Bookmarks.Use m + a letter to create a bookmark in vim. Then use the backtick plus the letter to return to the location.</p>

<p>Keyword completion. Use Ctrl+N to complete a word.</p>

<p>Notes
1. Vim macro tutorial.
2. Another great vim resource.</p>
</description>
						</item><item>
						<title>pwd while in a symlink directory</title>
						<link>http://breckyunits.com/code/pwd_while_in_a_symlink_directory</link>
						<description><p>to get the actual directory, run:</p>

<blockquote>
  <p>/bin/pwd</p>
</blockquote>
</description>
						</item><item>
						<title>Case sensitivity in MySQL table names and lower_case_table_names</title>
						<link>http://breckyunits.com/code/case_sensitivity_in_mysql_table_names_and_lowercasetablenames</link>
						<description><p>On linux, filenames and directories are case sensitive. file and File are different files.</p>

<p>On Windows, filenames are not case sensitive. file and File are the same file.</p>

<p>MySQL saves a database to disk. A "database" is saved in a directory, and each table is saved as a file in that folder.</p>

<p>Thus, say you transfer a database from Linux to Windows that has a table named "userBookmarks", this might cause a problem for you because MySQL on Windows will likely interpret it as "userbookmarks".</p>

<p>There's a setting in your my.cnf file called "lower_case_table_names".</p>

<p>The options are 0, 1, and 2.</p>

<p>1 is the default, and you shouldn't need to change it.</p>

<p>If you change it to 0 on Windows, you might run into problems. If you change it to 2, it doesn't seem to do much.</p>

<p>So what's the solution? Try to avoid capital letters in table names (use _ instead of camel case). When you can't do that, write your code for the Linux database (ie "select * from userBookmarks"), and your queries should translate fine on Windows since Windows will convert that to "select * from userbookmarks".</p>
</description>
						</item><item>
						<title>ANSI or ASCII and Unicode or UTF-8 and Newlines</title>
						<link>http://breckyunits.com/code/ansi_or_ascii_and_unicode_or_utf8_and_newlines</link>
						<description><p>The key things you need to know:</p>

<p>ANSI (aka ASCII) and UTF-8 (aka "UnicodeTransformation Format" or just "Unicode") are ways to encode text files into binary data.</p>

<p>I'm simplifying things but actually what I'm leaving out is not important. There are basically 2 character sets: ASCII or ANSI and UTF8 or Unicode. It's probably easiest to just call them ASCII and Unicode.</p>

<p>Unicode is the new guy, and is slowly replacing ASCII.</p>

<p>The main problem you'll run into with ASCII is line breaks. This isn't really an ASCII issue, it's a Windows issue but it often seems like it's an ASCII issue.</p>

<p>Windows does \r\n, whereas Unicode just does \n.</p>

<p>Here's an experiment you can do using Notepad++ and Notepad.</p>

<p>Open Notepad++ and start a new document.</p>

<p>Type in:</p>

<p>helloworld</p>

<p>Click "Edit", "EOL Completion" and click "Windows Format" (if it's gray, that means it's already on Windows format). Now cut and paste the text into Notepad. You'll see that it comes out on 2 lines. All good right?</p>

<p>Now go back to Notepad++ and click "Edit", "EOL Completion" and click "UNIX Format". Now cut and paste the text into Notepad. It's on 1 line, right?</p>

<p>Tada!</p>

<p>Now when you're having line problems just use this nifty feature in Notepad++.</p>

<p>Notes
1. Okay so this article turned out to be about line breaks and not about character encoding. I blame ADD.
2. Cast of Characters- ASCII, ANSI, UTF-8 and all that
3. ANSI versus Unicode</p>
</description>
						</item><item>
						<title>The BASH Programming Language</title>
						<link>http://breckyunits.com/code/the_bash_programming_language</link>
						<description><p>I used to use Python, Ruby or even PHP to write backend programs that would automate things like server management tasks, development and editing tasks, deployment tasks, backup tasks, and so forth.</p>

<p>Then I learned what is basically the BASH programming language, a language very similar to Python/Ruby/PHP etc., but is perfect for writing command line programs.</p>

<p>Here's the core of what you need to know:</p>

<p>Use the .sh file extension</p>

<p>A BASH script should have the .sh extension, just as a Python script has the .py extension, a php script has the .php extension, and a Ruby script has the .rb extension.</p>

<p>Start your scripts with #!/bin/bash</p>

<blockquote>
  <h1>!/bin/bash</h1>
</blockquote>

<p>PHP scripts start with</p>
</description>
						</item><item>
						<title>Cygwin Error: Could not resolve hostname X: Non-recoverable failure in name resolution</title>
						<link>http://breckyunits.com/code/cygwin_error_could_not_resolve_hostname_x_nonrecoverable_failure_in_name_resolution</link>
						<description><p>I've been getting this error a lot in Cygwin on Windows 7:</p>

<blockquote>
  <p>Could not resolve hostname X: Non-recoverable failure in name resolution</p>
</blockquote>

<p>It happens a lot when I run a deploy script or git push. Haven't found a solution yet, and am trying to track one down.</p>

<p>The problem is this bug is hard to reproduce. It happens only 5-10% of the time.</p>

<p>Edit #1:
Helpful article from Microsoft on Host Name Resolution</p>

<p>Edit #2:
Upon closer examination, it seems this error only happens with ssh:</p>

<blockquote>
  <p>ssh: Could not resolve hostname X: Non-recoverable failure in name resolution</p>
</blockquote>

<p>That's narrowed it down a bit but still no solution. Sadly because it only happens once or twice out of 10-20 times I run the "ssh" command, it's taking longer to pin down.</p>
</description>
						</item><item>
						<title>Plugins for Notepad++</title>
						<link>http://breckyunits.com/code/plugins_for_notepad</link>
						<description><p>Notepad++ is my go to editor.</p>

<p>The default plugins are great, but if you need more just visit the notepad++ plugins list.</p>

<p>To install a plugin:</p>

<ol>
<li>Download the zip file and unzip it.</li>
<li>Copy the dll to your Program Files/Notepad++/Plugins folder.</li>
</ol>

<p>The main plugin I've used so far is Explorer. I'll update this in the future with other ones.</p>

<p>That's it!</p>
</description>
						</item><item>
						<title>More tips on using rsync to deploy your website</title>
						<link>http://breckyunits.com/code/more_tips_on_using_rsync_to_deploy_your_website</link>
						<description><p>My post on deploying a website using rsync has gotten quite a few hits.</p>

<p>I thought I'd add some more tips:</p>

<ul>
<li>use the "--delete" option if you want to delete files on the destination directory that no longer exist in the source directory.</li>
<li>add "$1" after your options like this:
> rsync -rvz$1
Then you can easily do a DRY RUN. Just type:</li>
</ul>

<blockquote>
  <p>./deploy.sh n</p>
</blockquote>

<p>The n will get substituted for $1.</p>

<h3>Troubleshooting</h3>

<p>I've found a lot of times rsync appears to be copying the same files over and over.</p>

<p>There are a few things you can do to troubleshoot when rsync recopies the same files.</p>

<p>The options that I've found come in real handy are:</p>

<ol>
<li>The i option, which shows you why a file is being copied (all pluses means rsync thinks it doesn't exist in the destination; t means the times differ; s means the contents differ (?)).</li>
<li>The --modify-window=1 option. This lets you ignore differences in modified timestamps. You can set 1 to a high number to ignore large differences.</li>
</ol>
</description>
						</item><item>
						<title>Linux Go Back to Previous Directory</title>
						<link>http://breckyunits.com/code/linux_go_back_to_previous_directory</link>
						<description><p>Just type:</p>

<blockquote>
  <p>cd -</p>
</blockquote>

<p>To go back to the last directory you were in. Basically an "undo" for the cd command.</p>
</description>
						</item><item>
						<title>Should your source code be in one folder or should it be nested?</title>
						<link>http://breckyunits.com/code/should_your_source_code_be_in_one_folder_or_should_it_be_nested</link>
						<description><p>There are two ways to organize source code files for a project: flat or nested.</p>

<p>Here's a simple example of a flat structure(1 directory, 4 files):</p>

<blockquote>
  <p>myproject/
  - index.php
  - theme.css
  - helper_functions.php
  - logo.png</p>
</blockquote>

<p>Here's an example of a nested structure(4 directories, 4 files):</p>

<blockquote>
  <p>myproject/
  - index.php
  styles/
  -- theme.css
  images/
  -- logo.png
  helpers/
  -- helper_functions.php</p>
</blockquote>

<p>Both of these structures can accomplish the same thing. Which is better?</p>

<p>If you've worked with me on any project before, you'll know I prefer flatter structures. I try to resist adding directories as much as possible (you always have to add them eventually, but I like to fight it to minimize this effect).</p>

<p>I don't know why my gut tells me to minimize directories, so I thought I'd write about it and see if any rationale emerged.</p>

<p>Benefits of a Flat Structure</p>

<p>Benefit #1 - Quicker access to files</p>

<p>I primarily edit files using Notepad++ on Windows 7 or vim. If you keep all your files in 1 directory, you can open them faster ("Control+O", type a few letters on Win 7, or just "vim filename"). So, a flat structure gives you quicker access to files. I've never timed this before, but am pretty positive it works.</p>

<p>Benefit #2 - Avoid file path issues</p>

<p>Dealing with paths when working with a website is often the cause of careless bugs. If everything is in one directory, it makes it painless to include things on both the server side(include 'file.php';) and the client side ('src="script.hs"'). Once you start nesting directories, it's easy to make mistakes.</p>

<p>Benefit #3 - Easier to bring people up to speed</p>

<p>When I join an in-progress project or use a new library, I like to try and wrap my head around the whole thing. I can't do that if I have to dig into different directories to see all the files. Why hide 50% of the project in subdirectories?</p>

<p>Benefit #4 - Avoid overwriting issues</p>

<p>Occasionally you'll have a structure like this:</p>

<ul>
<li>index.php
> admin/
-- index.php</li>
</ul>

<p>You might accidentally overwrite one index with the other, or edit one index when you think you're editing the other. Doesn't happen too often, but occasionally it can be annoying. By sticking everything in one directory, you don't run into that problem as much.</p>

<p>Benefits of a Nested Structure</p>

<p>Of course there are benefits to having multiple directories, otherwise this style wouldn't be so popular.</p>

<p>Benefit #1 - Looks more organized</p>

<p>It's nice and neat to have your files tucked away into nicely labeled directories.</p>

<p>Benefit #2 - Easier for teams</p>

<p>It can be easier to divide work between team members when things are in different directories. For instance, why should the designers need their images mixed in with backend files?</p>

<p>Benefit #3 - A directory with too many files becomes unwieldy</p>

<p>I'll admit, once you have more than some threshold of files in a directory, it can quickly become hard to manage. If the files are nearly all of the same type (say, php files), then it's not as bad. But once you have 20 php files, 3 javascript files, 15 images, 4 css files, 2 bash files, 3 readmes, and 45 text files, it might be time to split things up.</p>

<p>My theory on why directories are bad.</p>

<p>Less paths create an easier mental model.</p>

<p>If you walk into a messy room, it can be hard to create a mental model of the contents of that room. This is the equivalent to a file structure like the one below:</p>

<p>Bad</p>

<blockquote>
  <p>myproject/
  - a_image.png
  - base_functions.php
  - dog.js
  - index.php
  - mike.png
  - names.csv
  - new_logo.jpg
  - test.php
  - xmlfunctions.php
  - zlib.js</p>
</blockquote>

<p>It's a mess.</p>

<p>If you walk into a room where everything is put away(clothes in the dresser, books on a bookshelf, odds and ends in the drawers) it's easier and an improvement. A room organized like this looks like the file structure below:</p>

<p>Ok</p>

<blockquote>
  <p>myproject/
  - index.php
  images/
  -- a_image.png
  -- mike.png
  -- new_logo.jpg
  php/
  -- base_functions.php
  -- test.php
  -- xmlfunctions.php
  scripts/
  -- dog.js
  -- zlib.js
  data/
  -- names.csv</p>
</blockquote>

<p>But now you've introduced the problem that to access nearly anything, you have to "open a drawer". You also can't see everything all at once.</p>

<p>Best</p>

<p>The optimal solution is to not put your stuff into drawers, but to:</p>

<ol>
<li>Remove as much stuff as possible.</li>
<li>Put the remaining stuff out in the open in neats piles in separate parts of the room.</li>
<li>If, and only if, you have a ton of the same type of thing, put those into their own drawer/cabinet.</li>
</ol>

<p>If you apply this algorithm to a sample project, you might get something like a project I just made with PHPUno</p>

<blockquote>
  <p>dropdate/
  - data/
  -- 1
  -- 2
  -- ..
  -- 578
  - index.php
  - logo.png
  - sprites.png
  - style.css
  - uno_controller.php
  - uno_app.php
  - uno_models.php
  - uno_helpers.php</p>
</blockquote>

<p>Search, don't sort</p>

<p>Gmail has an adage "search, don't sort". I think it applies here. Directories are a form of sorting, while autocomplete(which is integrated into practically everything nowadays) is a form of searching. By sticking everything into one directory, you enable search. Create multiple directories, and you disable search.</p>

<p>The Rule of Three</p>

<p>Here's a simple rule of thumb to help you organize your folder structure better:</p>

<ul>
<li>No folder in your project should have more than 3 subfolders.</li>
<li>There should not be more than 3 levels in any project.</li>
</ul>

<p>In other words, the directory "icon" should never have a subdirectory in it.</p>

<blockquote>
  <p>myproject/
  images/
  - icons/</p>
</blockquote>

<p>This means that any project should have at most 9 subdirectories.</p>
</description>
						</item><item>
						<title>Bug Workaround for JS Charts Error: Not enough data to display chart </title>
						<link>http://breckyunits.com/code/bug_workaround_for_js_charts_error_not_enough_data_to_display_chart_</link>
						<description><p>If you get this alert using JSCharts, here's a quick hack to fix it:</p>

<blockquote>
  <p>nullData = new Array( );
  myChart.setDataArray(nullData,"null");</p>
</blockquote>

<p>Add these 2 lines to your javascript.</p>

<p>Basically, if the first data set has only 1 data point, JSCharts will fire the alert. If it has 0 or 2+ data points, it won't. This fix creates an empty data series which disables this alert.</p>
</description>
						</item><item>
						<title>Change the file owner or group in Linux</title>
						<link>http://breckyunits.com/code/change_the_file_owner_or_group_in_linux</link>
						<description><p>Change the owner of a file or folder:</p>

<blockquote>
  <p>chown newowner filename</p>
</blockquote>

<p>Change the group of a file or folder:</p>

<blockquote>
  <p>chgrp newgroup filenameorfoldername</p>
</blockquote>
</description>
						</item><item>
						<title>How to load a sql file into MySql</title>
						<link>http://breckyunits.com/code/how_to_load_a_sql_file_into_mysql</link>
						<description><p>It's very simple thanks to pipes.</p>

<blockquote>
  <p>mysql -u username -p &lt; sqlfile.sql</p>
</blockquote>

<p>Make sure your sql file has a "use database" line.</p>
</description>
						</item><item>
						<title>Shortcut for switching to a Windows directory in Cygwin</title>
						<link>http://breckyunits.com/code/shortcut_for_switching_to_a_windows_directory_in_cygwin</link>
						<description><p>In cygwin it can be a pain to change to a Windows directory like <code>C:\Users\breck\Documents\My Dropbox</code>.</p>

<p>I made a small bash script called <code>wcd</code> that makes it easier.</p>

<h3>wcd</h3>

<pre><code>#!/bin/bash
echo $1
newpath=$(echo $1 | sed 's|\\|/|g' | sed 's|:||g' | sed 's|^C|/cygdrive/c|')
echo $newpath
cd "$newpath" 
</code></pre>

<p>The echos are just for debugging--I'm kind of new to bash scripting. Feel free to remove.</p>

<p>Make this file executable and add an alias into your bash_profile:</p>

<pre><code>alias wcd="source ~/wcd"
</code></pre>

<p>Now you can just type(or actually copy/paste) something like this:</p>

<pre><code>wcd "C:\Users\breck\Documents\My Dropbox"
</code></pre>

<p>...and that will take you to the Windows directory.</p>

<p>Notes</p>

<ol>
<li>wcd gist.</li>
</ol>
</description>
						</item><item>
						<title>Cygwin treats the Windows Clipboard like a file</title>
						<link>http://breckyunits.com/code/cygwin_treats_the_windows_clipboard_like_a_file</link>
						<description><p>In Linux every thing is a file. This is great because it means the Windows clipboard is a file too!</p>

<p>Want to copy the current cygwin directory into your clipboard?</p>

<blockquote>
  <p>pwd > /dev/clipboard</p>
</blockquote>

<p>Want to print the contents of the clipboard?</p>

<blockquote>
  <p>cat /dev/clipboard</p>
</blockquote>

<p>Notes</p>

<ol>
<li>Fun with Cygwin's /dev/clipboard.</li>
</ol>
</description>
						</item><item>
						<title>New tricks in Vim</title>
						<link>http://breckyunits.com/code/new_tricks_in_vim</link>
						<description><p>I learned some new tricks with vim today.</p>

<blockquote>
  <p>4G - Move to line #4</p>
  
  <p>mb - Mark the current spot as point b
  'b - Go back to point b</p>
  
  <p>vim file1 file2  - open 2 files at once</p>
  
  <p>:e file - edit a different file</p>
  
  <p>:split file - split the current window and edit a different file (vsplit for vertical split)</p>
  
  <p>ctrl+w j/k - move down/up a window</p>
  
  <p>:hide - hide the current window</p>
  
  <p>:ls - show current buffers</p>
</blockquote>

<p>Notes</p>

<ol>
<li><a href="http://www.cs.oberlin.edu/~kuperman/help/vim/windows.html" target="_blank" class="external">Vim Tips and Tricks</a></li>
</ol>
</description>
						</item><item>
						<title>Use cat to combine or print the contents of a file</title>
						<link>http://breckyunits.com/code/use_cat_to_combine_or_print_the_contents_of_a_file</link>
						<description><p>Print the contents of a file:</p>

<blockquote>
  <p>cat filename.txt</p>
</blockquote>

<p>Pipe the contents of the file to less, so you can view it one page at a time:</p>

<blockquote>
  <p>cat filename | less</p>
</blockquote>

<p>In less, the 3 key commands are:</p>

<ul>
<li>spacebar to go forward one page</li>
<li>b to go back one page</li>
<li>q to quit</li>
</ul>

<p>You can also do regular expression searches like in vim: /regex (n to go to next match)</p>

<p>Append file1 to the end of file 2:</p>

<blockquote>
  <p>cat file1 >> file2</p>
</blockquote>

<p>Combine two files into a third file:</p>

<blockquote>
  <p>cat file1 file2 > file3</p>
</blockquote>
</description>
						</item><item>
						<title>Pipes, standard output and standard input</title>
						<link>http://breckyunits.com/code/pipes_standard_output_and_standard_input</link>
						<description><p>In linux, standard input refers to the stream of bits that come from your keyboard.</p>

<p>Standard output refers to the stream of bits that appear on your screen(terminal).</p>

<p>You can change this around so that standard input comes from another source(say, a file) or so that standard output gets directed somewhere else (say, a file).</p>

<p>For example, say we wanted to email someone a file containing the contents of our home directory. We could do this:</p>

<blockquote>
  <p>ls ~ | vim -</p>
</blockquote>

<p>This will pipe the output from the ls command to vim. You can then edit and save this file normally as you would in vim.</p>

<p>There's another type of pipe you could use for this example: greater than.</p>

<blockquote>
  <p>ls ~ > contents.txt</p>
</blockquote>

<p>This will redirect the output to the contents.txt file.</p>

<p>You can also append output by using two greater than signs:</p>

<blockquote>
  <p>ls ~ >> some_file.txt</p>
</blockquote>

<p>As you would expect, the less than sign can be used to direct a file as standard in.</p>

<p>Notes</p>

<ol>
<li>Linux Phrasebook</li>
<li>pipe to vim.</li>
</ol>
</description>
						</item><item>
						<title>Run multiple commands at once</title>
						<link>http://breckyunits.com/code/run_multiple_commands_at_once</link>
						<description><p>Want to know how to run two or more linux commands sequentially? It's simple: use the semicolon ;.</p>

<p>For instance:</p>

<blockquote>
  <p>cd;ls</p>
</blockquote>

<p>This will change the directory to your home directory, then list the contents. You can use as many semicolons as you wish.</p>

<p>Another option is to use &amp;&amp; if you only want the next command to execute if the previous command executed successfully.</p>

<blockquote>
  <p>cd ~/myfiles; cp file.txt ~/backup/ &amp;&amp; rm file.txt</p>
</blockquote>

<p>This will only run the last command if the cp command executed successfully.</p>

<p>You can swap the &amp;&amp; for || to run a command if the previous one fails.</p>
</description>
						</item><item>
						<title>The only 5 git commands you need to know</title>
						<link>http://breckyunits.com/code/the_only_5_git_commands_you_need_to_know</link>
						<description><p>What's the difference between a great programmer who acts cool around girls and a great programmer who does not use version control?</p>

<p>Nothing--they both don't exist!</p>

<p>If <em>every single great programmer</em> uses version control, why do some beginning programmers avoid it?</p>

<p>Because version control is made to seem intimidating.</p>

<p>But version control is actually very easy!</p>

<p>If you are new to version control, there are only 5 commands you need to memorize. Can you memorize 5 words? Of course you can.</p>

<p>So memorize these 5 words and you'll be practically an expert at version control:</p>

<blockquote>
  <p>init</p>
  
  <p>add</p>
  
  <p>status</p>
  
  <p>commit</p>
  
  <p>push</p>
</blockquote>

<p>If you just start playing around with these 5 and only these 5 commands, you'll become a git master in no time.</p>

<p>Here's a simple practice session you can follow to start getting good.</p>

<h3>What is git?</h3>

<p>Git is a simple command line program like "wget" or "vim" that you install and use by typing commands. If you don't have git installed, try one of these commands:</p>

<blockquote>
  <p>yum install git-core</p>
  
  <p>apt-get install git-core</p>
  
  <p>sudo port install git-core</p>
</blockquote>

<p>Let's say you're creating a new website for your mom and want to use version control to do it.</p>

<blockquote>
  <p>mkdir moms_website</p>
  
  <p>cd moms_website</p>
  
  <p>git init</p>
</blockquote>

<p>This creates a git repository. Now type:</p>

<blockquote>
  <p>ls -a</p>
</blockquote>

<p>Do you see the new ".git" directory? That's the git repository. It's basically a folder that stores the whole history of your project. Now, when you type a git command, it will do something with the files in that folder. That's all that's really going on. You never need to go into that folder manually, I was just explaining what git is doing.</p>

<p>Now, let's create a file and add it to your repository.</p>

<blockquote>
  <p>vim index.php</p>
  
  <p>Hello World</p>
  
  <p>:wq</p>
  
  <p>git status</p>
</blockquote>

<p>This will show the presence of an untracked file, "index.php". Let's add this file.</p>

<blockquote>
  <p>git add index.php</p>
</blockquote>

<p>You've now added the file to git, let's <em>commit</em> our changes.</p>

<blockquote>
  <p>git commit -m "first commit"</p>
</blockquote>

<p>Now you've made your first commit.</p>

<p>The last command you'll need is <em>push</em>. It works like this:</p>

<blockquote>
  <p>git push</p>
</blockquote>

<p>That will upload your repository to an online host like github so that other people can collaborate.</p>

<p>Create a github account and follow the instructions for creating a new repository to test out this final command.</p>

<p>That's it! Those are the 5 commands you'll use over and over again. Master those and slowly you'll start learning a few other helpful git commands.</p>

<h4>Recap</h4>

<blockquote>
  <p>git init</p>
  
  <p>git status</p>
  
  <p>git add <em>filename</em></p>
  
  <p>git commit -m <em>"your message about what you changed and why"</em></p>
  
  <p>git push</p>
</blockquote>
</description>
						</item><item>
						<title>Use scp to download a file from a server</title>
						<link>http://breckyunits.com/code/use_scp_to_download_a_file_from_a_server</link>
						<description><p>You can easily grab a file off a server from the command line using secure copy:</p>

<p>scp user@domain.com:/home/user/fileyouwant.txt fileyouwant.txt</p>

<p>This will download the file from your server to your local computer.</p>
</description>
						</item><item>
						<title>Clear screen in cygwin</title>
						<link>http://breckyunits.com/code/clear_screen_in_cygwin</link>
						<description><p>Just hit ctrl+l</p>
</description>
						</item><item>
						<title>Use sed to find and replace</title>
						<link>http://breckyunits.com/code/use_sed_to_find_and_replace</link>
						<description><p>grep is to find what sed is to replace.</p>

<p>Say you noticed a few typos in a file. Say you typed imposible instead of impossible a few times in a file named "stuff.txt".</p>

<p>You can fix all occurrences using this one-liner:</p>

<p>sed 's/imposible/impossible/g' stuff.txt</p>

<p>Often it's more helpful to sed across multiple files.</p>

<p>sed -i 's/1.0.1/"1.0.1"/g' *.php</p>

<p>That's one command I used to add quotes around 1.0.1, which I forgot to do. Alas, it's not recursive.</p>

<p>Notes
1. sed tutorial.
2. find and replace with sed.
3. about.com on sed.
4. Very clear examples.</p>
</description>
						</item><item>
						<title>Unix date command</title>
						<link>http://breckyunits.com/code/unix_date_command</link>
						<description><p>Display the current unix timestamp:</p>

<p>date +%s</p>

<p>Handy way to view it from the command line.</p>
</description>
						</item><item>
						<title>Bash variables</title>
						<link>http://breckyunits.com/code/bash_variables</link>
						<description><p>$ FIVE=5
$ echo $FIVE
5
$ echo "The number five is $FIVE"</p>

<p>Variable scope</p>

<p>A shell script will launch a new shell that has a fresh scope.</p>

<p>$ FIVE = 5
$ vim myshellscript.sh</p>

<h1>!/bin/bash</h1>

<p>echo $FIVE
$ ./myshellscript.sh</p>

<p>Blank because the executed script doesn't affect the current shell. To make something affect the current shell, use the source command.</p>

<p>Export command.</p>

<p>Use the export command to change the scope of your variable to global for your shell.</p>

<p>To make a permanent global variable, add it to your .bash_profile like so:</p>

<p>MY_NAME=breck; export MY_NAME</p>

<p>Accept input.</p>

<p>Use the read command to accept input.</p>

<p>echo "What is 1+1?"
read ANSWER
echo "Your answer is $ANSWER"</p>

<p>Notes
1. Bash tutorial
2. Another tutorial.
3. Bash parameters</p>
</description>
						</item><item>
						<title>How to fix an overwhelmed Gmail Accout</title>
						<link>http://breckyunits.com/code/how_to_fix_an_overwhelmed_gmail_accout</link>
						<description><p>I have used the same Gmail address as my main email for over 5 years.</p>

<p>Since then:</p>

<p>I've made dozens of other emails that forward to this address.
I've signed up for hundreds of web apps and newsletters.</p>

<p>As a result, my Gmail account gets inundated with email. Here are the stats:</p>

<ul>
<li>16,054 unread emails in my inbox</li>
<li>29,236 emails total in my inbox</li>
<li>?? who knows how many total emails in my archive</li>
<li>3.683 GB of email</li>
<li>Using 49% of my Gmail quota</li>
</ul>

<p>My Gmail account had become a firehose.</p>

<p>This was bad for two reasons.</p>

<p>First, I started missing important emails. Not many, but a few per month. I had to write my own simple Bayes filter to find them.</p>

<p>Second, I couldn't do what most people do: use my inbox as a "todo" list. Most people immediately archive or delete an email when they're done with it. This is a great organizational trick. I wanted to do this again.</p>

<p>I considered starting a new email address and giving it out to important people, but that seemed like it would make my life more complex.</p>

<p>As it turns out, the solution was simple.</p>

<ul>
<li>Started liberally using the "Spam" button. I started clicking Spam on pretty much any type of mass email that wasn't very interesting to me. Will be interesting to see how this plays out.</li>
<li>Starred all the recent messages that I still had to deal with.</li>
<li>Archived all 29,000+ of my gmail messages at once.</li>
<li>Went back to the starred folder and moved the important messages to inbox.</li>
</ul>

<p>Notes
1. Thanks to this site for telling me how to archive all my gmail messages.</p>
</description>
						</item><item>
						<title>Seven aliases that can save you time</title>
						<link>http://breckyunits.com/code/seven_aliases_that_can_save_you_time</link>
						<description><p>Add these to your .bash_profile to speed up common tasks:</p>

<p>alias apr='sudo ./usr/sbin/apachectl restart' # restart apache
alias www='cd /var/www/html/' # enter your root web directory
alias hconf='vim /etc/httpd/conf/httpd.conf' # edit your apache config file
alias eprof='vim ~/.bash_profile' # edit this file
alias rprof='source ~/.bash_profile' # reload this file (after making edits)
alias pconf='vim /etc/php.ini' # edit php.ini
alias lsd="ls -l | egrep '^d'" # list only directories</p>
</description>
						</item><item>
						<title>List only directories using ls</title>
						<link>http://breckyunits.com/code/list_only_directories_using_ls</link>
						<description><p>the "ls" command lists all files and directories. What if you just wanted to list the directories?</p>

<p>ls -l | egrep '^d'</p>

<p>Add this to your .bash_profile and now you can just type "lsd" when you want list only directories. Who said lsd was a bad thing?</p>

<p>alias lsd="ls -l | egrep '^d'"</p>

<p>Notes
1. Found this tip here.</p>
</description>
						</item><item>
						<title>Turn off bell in cygwin</title>
						<link>http://breckyunits.com/code/turn_off_bell_in_cygwin</link>
						<description><p>The beep on tab completion in cygwin can be annoying. Here's how to turn it off:</p>

<p>vim ~/.inputrc</p>

<p>(Then add or uncomment this line)</p>

<p>set bell-style none</p>

<p>Save and restart your shell.</p>
</description>
						</item><item>
						<title>git clone without history</title>
						<link>http://breckyunits.com/code/git_clone_without_history</link>
						<description><p>If you're using a library from git in another project, you may want to download it without the history. Here's how:</p>

<p>git clone --depth 1 your_repo_url</p>

<p>http://git.or.cz/gitwiki/GitFaq#HowdoIdoaquickclonewithouthistoryrevisions.3F</p>
</description>
						</item><item>
						<title>Learn Symbolic Links in 30 seconds</title>
						<link>http://breckyunits.com/code/learn_symbolic_links_in_30_seconds</link>
						<description><p>Symbolic links are simple and can save you time.</p>

<p>Here's all you need to know:</p>

<p>ln -s actual_file_or_directory new_symbolic_link_name</p>

<p>Let's do a real example from your home directory:</p>

<p>ln -s /var/www/html/yourwebsiteroot/yourblog blog</p>

<p>Now when you login to your server you can just type "cd blog" to access the "/var/www/html/yourwebsiteroot/yourblog" folder.</p>

<p>Here's one more example from your home directory:</p>

<p>ln -s /etc/httpd/conf/httpd.conf httpd.conf</p>

<p>Now you can just type "vim httpd.conf" and edit your httpd.conf file quicker.</p>

<p>You can do all kinds of neat things with symlinks, but the simplest uses are often the ones you'll use most. (One of the cooler uses of symlinks is for deploying different versions of websites).</p>

<p>Notes
1. Aliases are another great time saver.</p>
</description>
						</item><item>
						<title>Create a new user in Linux</title>
						<link>http://breckyunits.com/code/create_a_new_user_in_linux</link>
						<description><p>Creating a new user in Linux is dead simple.</p>

<p>useradd bob</p>

<p>passwd bob</p>

<p>This adds a user "bob" and then prompts you to enter a password.</p>
</description>
						</item><item>
						<title>Use aliases to save time</title>
						<link>http://breckyunits.com/code/use_aliases_to_save_time</link>
						<description><p>Using aliases in Linux can save you a lot of time. Here's an example:</p>

<p>alias www='cd /var/www/html/'</p>

<p>Instead of typing "cd /var/www/html/" to enter your web directory, now you can enter "www", a savings of at least 14 keystrokes each time you use it.</p>

<p>This one will switch to the usr/sbin directory, restart apache, then switch to your home directory:</p>

<p>alias apr='cd /usr/sbin/;sudo ./apachectl restart;cd'</p>

<p>You can also just do:</p>

<p>alias apr='/usr/sbin/apachectl restart'</p>

<p>But the earlier example shows how you can string multiple commands together.</p>

<p>Bonus tip</p>

<p>Place these aliases in your HOME/.bash_profile file and they will be available each time you login to your machine.</p>

<p>Notes
1. "At least" 14 keystrokes, because the # of typos increases as the # of characters typed increases.</p>
</description>
						</item><item>
						<title>How I organize my Dropbox</title>
						<link>http://breckyunits.com/code/how_i_organize_my_dropbox</link>
						<description><p>Gmail encourages users to "search not sort". I do that.</p>

<p>Email works great for search. For files though, sorting is often better.</p>

<p>I have well over 20GB of files synced onto my Dropbox.</p>

<p>The rest of my computer is spotless(I use Windows 7 and do a fresh install every 30-60 days).</p>

<p>But the Dropbox can get cluttered.</p>

<p>I take a simple approach that is a hybrid of search and sort. Here's how to do it:</p>

<p>Put files into 2 sections: 
-Put commonly accessed folders in the root directory.
-Put everything else in a "Search" directory, which is in the Dropbox root directory.</p>

<ul>
<li>Create a folder in your root Dropbox directory named "Search". Plop anything in here.</li>
<li>Keep your most common folders in the root Dropbox directory. Sort these ones.</li>
<li>Every few weeks, move any rarely used files and folders into the "Search" directory. Bring any commonly used files and folders back out to the root Dropbox directory.</li>
</ul>

<p>End Result</p>

<p>Here's what the end result may look like:</p>

<p>-My Dropbox
--Music
--Photos
--Blog
--eBooks
--Company Docs
--Search</p>

<p>The first directories are the ones you access a lot and are well sorted and maintained. The last directory is a mess of random files and folders that you've collected. You can browse through it, but it's easier to just run a search on it when you need something.</p>

<p>This a hybrid of search and sort.</p>

<p>Notes
1. All of my coding work is done in my cygwin home directory and then pushed to github. These are the only files that I don't store in Dropbox, but I push them frequently so don't worry much about losing them.</p>
</description>
						</item><item>
						<title>Use git to get the latest source code only</title>
						<link>http://breckyunits.com/code/use_git_to_get_the_latest_source_code_only</link>
						<description><p>Say you want to get just the source code of a git repository without all the history(without the ".git" directory). Use this:</p>

<p>git clone --depth 1 git://github.com/breck7/brecksblog.git</p>
</description>
						</item><item>
						<title>What non-web software do you use the most?</title>
						<link>http://breckyunits.com/code/what_nonweb_software_do_you_use_the_most</link>
						<description><p>Here are the programs I use everyday, every week, and every month.</p>

<p>What software do you use the most? What are your "must haves"?</p>

<p>My Machines</p>

<p>My primary development machine is a basic Compaq laptop with 4GB, 230GB, x2 Core Athlon, running Windows Vista/7.</p>

<p>My secondary machine is an Asus EEE netbook with XP which is great for working on the road, at a coffee shop, or on a plane.</p>

<p>Most of our servers are slices from slicehost running Fedora.</p>

<p>On all my development machines I run Cygwin. Programs I run in Cygwin are noted by *.</p>

<p>The following is a list of the programs I use on my development machines.</p>

<p>Daily</p>

<p>Cygwin. I prefer Windows+cygwin over Macs, Fedora or Ubuntu, or Windows plus running virtualized machines.</p>

<p>Notepad++. I do half my editing in Notepad++ and half in Vim. I love Notepad++'s speed, reliability, and autocomplete.</p>

<p>Dropbox. Completely changed how I work. Allows me to work from multiple computers seamlessly. Allows me to share files easily with clients, family, and friends. Reinstalling Windows (which I do a few times per year), is made easy because all my important files are kept on my dropbox. The fact that install and uninstall is so easy and doesn't require a reboot really impresses me.</p>

<p>WAMP. The "AMP" stack is what I develop for mostly. WAMP gives me an easy local testing environment to try things out before pushing to a server.</p>

<p>Chrome. I spend most of my web time in Chrome. It's lighting fast. It's also simple. Tabs are done incredibly well.</p>

<p>Firefox. Still need this guy. The extensions are great. Firebug and the Web Developer's Extension I use at least weekly, close to daily. It's also nice to have 2 browsers going if you want to log in to the same site with 2 different accounts.</p>

<p>Skype. I don't use a cellphone, believe it or not. My Google Voice number points to my Skype In number. Skype allows me to not have a cellphone, which I greatly appreciate. My sister can call me from the Middle East just as easily and for the same price that my neighbors can call me from down the street.</p>

<p>*Vim. The only Nix editor I know and love. Vim took me a while to learn, but is becoming more and more indispensable the better I get at "typing in Vim".</p>

<p>*Git. Easy to use version control that makes sense. Paired with github, becomes indispensable.</p>

<p>*Rsync. Great for deploying simple websites and for downloading backups.</p>

<p>*Grep. Great when you need to track down a word or line across multiple files.</p>

<p>*Find. Simple and easy for finding files. I also use find over Windows 7's search occasionally.</p>

<p>*Cron. Simple and essential.</p>

<p>*SSH. Of course.</p>

<p>*Ruby. I keep irb running in a window when I need to do quick calculations.</p>

<p>Weekly</p>

<p>Navicat. Great way to keep an eye on databases. I also like it for creating and editing schemas. Find it easier to visualize a schema than to code it out.</p>

<p>Filezilla. Occasionally when I just want to drag and drop some things from or to a server.</p>

<p>Photoshop. I use an old version of Photoshop which is still way to advanced for me. But it's fast and gets the job done.</p>

<p>7zip. "Extract to here" is a great little feature that it adds to the right click menu.</p>

<p>Word &amp; Excel 2007. Solid programs. Too bulky for my liking, but necessary in many cases.</p>

<p>Monthly</p>

<p>Visual Studio. When I get an urge to write a new desktop program.</p>
</description>
						</item><item>
						<title>Fix permission problems using chmod</title>
						<link>http://breckyunits.com/code/fix_permission_problems_using_chmod</link>
						<description><p>Permission problems driving you crazy? Here's a common command to fix them:</p>

<p>chmod -R 755 directoryname</p>

<p>Change the file permissions of all directories and files in directoryname to 755.</p>
</description>
						</item><item>
						<title>Use the linux find command to find files</title>
						<link>http://breckyunits.com/code/use_the_linux_find_command_to_find_files</link>
						<description><p>Say you're looking for all files starting with the word "breck". Using the linux "find" command, it's simple:</p>

<p>find -name "breck*"</p>

<p>Will search the current directory and all subdirectories for files starting with the word "breck".</p>
</description>
						</item><item>
						<title>cron in 2 steps</title>
						<link>http://breckyunits.com/code/cron_in_2_steps</link>
						<description><p>cron lets you schedule linux commands to execute on a regular basis.</p>

<p>For instance, say we want to run the command "wget http://yourdomain.com/backup.zip" each hour, that downloads a backup of one of your websites.</p>

<p>Step 1: Write the cron command</p>

<p>Here is the cron command you would need:</p>

<p>0   *   *   *   *   wget http://yourdomain.com/backup.zip</p>

<p>You can either memorize the crontab syntax, or just this simple Javascript crontab gui will easily generate the code for you.</p>

<p>Step 2: Append the command to your crontab file</p>

<p>There are 2 crontab files that get executed every minute. 1 of them is found in /etc or similar and is controlled by root only. In addition, each user can have a crontab.</p>

<p>To add your command to crontab type:</p>

<p>crontab -e</p>

<p>This will open vim, and you can then paste and save your crontab file.</p>

<p>Viola!</p>

<p>Notes:
1. If you are using cron in cygwin, follow these steps after installing the cron package with the cygwin installer to install cron as a service:</p>

<p>cygrunsrv -I cron -p /usr/sbin/cron -a D</p>

<p>net start cron</p>

<p>If there are problems, check the cron.log file in your home directory.</p>
</description>
						</item><item>
						<title>Use grep to search multiple files at once</title>
						<link>http://breckyunits.com/code/use_grep_to_search_multiple_files_at_once</link>
						<description><p>grep lets you search through multiple text files at once.</p>

<p>I recently removed a feature from a project and wanted to make sure I removed all references to it. With grep it was easy:</p>

<p>grep -r picture *</p>

<p>This searched all the files in my current directory as well as all the files in each subdirectory, and printed the filename and line where the word "picture" appeared.</p>

<p>Then I went in and changed the 2 files that needed modifying.</p>

<p>Had I wanted to just search the current directory (without the subdirectories) I could have done:</p>

<p>grep picture <em>.</em></p>

<p>This would have searched through all the files in the current directory.</p>

<p>Had I wanted to search in just 1 specific file:</p>

<p>grep picture filename.txt</p>

<p>Had I wanted to do a case insensitive search:</p>

<p>grep -ir picture *</p>

<p>Had I wanted to exclude a directory and done a case insensitive search:</p>

<p>grep -ri "searchstring" --exclude="<em>&#46;svn</em>" *</p>

<p>(grep uses regular expressions)</p>

<p>Links
1. Wikipedia grep
2. Stackoverflow.</p>
</description>
						</item><item>
						<title>Use rsync to deploy your website</title>
						<link>http://breckyunits.com/code/use_rsync_to_deploy_your_website</link>
						<description><p>rsync is a nifty little tool that can deploy a website to a testing or production server.</p>

<p>Here's a one line command to deploy brecksblog:</p>

<blockquote>
  <p>rsync -arvuz /home/user/brecksblog breck32@breckyunits.com:/var/www/html/ --exclude '.git' --exclude 'deploy' --exclude 'README' --exclude 'posts.php'</p>
</blockquote>

<p>This one line will do a fast, incremental file transfer from my local directory to the web server.</p>

<p>I saved this file as "deploy", and then run it by typing:</p>

<blockquote>
  <p>./deploy</p>
</blockquote>

<p>The exclude option will exclude a file or directory from being synced.</p>

<p>Here's an explanation about the options I use:</p>

<p>I use rsync with these options:</p>

<blockquote>
  <p>rsync -arvuz /src/foo/ /dest/foo</p>
</blockquote>

<p>this will copy the contents of /src/foo/ into /dest/foo</p>

<p>options explained:</p>

<ul>
<li>a: archive mode (keep owner and permissions)</li>
<li>r: recurse into directories</li>
<li>v: increase verbosity</li>
<li>u: update only (don't overwrite newer files - if you have edited files in destination)</li>
<li>z: compress file data</li>
</ul>

<p>Notes</p>

<ol>
<li>If you are using a different port for SSH, say 333 do this: --rsh="ssh -p333"</li>
</ol>
</description>
						</item><item>
						<title>SSH into your server without a password</title>
						<link>http://breckyunits.com/code/ssh_into_your_server_without_a_password</link>
						<description><p>On your server:</p>

<p>vim /etc/ssh/sshd_config</p>

<p>Make sure allow rsa and the other RSA lines are uncommented</p>

<p>service sshd restart</p>

<p>Make sure the file ~/.ssh/authorized_keys exists(if it doesn't, make that directory and touch that file).</p>

<p>Run this on your client computer:</p>

<p>ssh-keygen -t rsa</p>

<p>(hit enter a bunch of times)</p>

<p>cat ~/.ssh/id_rsa.pub | ssh YOURUSERNAME@YOURDOMAIN.com "cat - >> ~/.ssh/authorized_keys"</p>

<p>Bam! Login without a password!</p>

<p>This is my setup on Fedora VM's running at slicehost.</p>

<h3>If you are having problems</h3>

<ol>
<li><p>Run sshd with the verbose option. -v</p></li>
<li><p>The problem is likely due to bad file permissions. The owner of the directory .ssh should be your user/group. The file permissions on it should be: 755. (I think)</p></li>
</ol>

<p>authorized_keys should be the same owner/group and file permissions should be:  644</p>
</description>
						</item><item>
						<title>Get VIM Working in Cygwin</title>
						<link>http://breckyunits.com/code/get_vim_working_in_cygwin</link>
						<description><p>I had trouble getting VIM behaving as expected under Cygwin.</p>

<p>Specifically, the backspace and arrow keys were behaving badly in insert mode.</p>

<p>The solution was dead simple.</p>

<p>Just run:</p>

<p>touch .vimrc</p>

<p>in your root directory.</p>

<p>Links:
Found this solution in the comment from Gregg
vimrc</p>
</description>
						</item><item>
						<title>About this Blog</title>
						<link>http://breckyunits.com/code/about_this_blog</link>
						<description><p>I constantly want to share little coding tidbits, snippets, or stories on how to solve specific little coding problems. Instead of clogging up the main blog with these shorter, more specific technical posts, I decided to launch a second blog.</p>

<p>This is it.</p>
</description>
						</item>			</channel>
			</rss>
		