Programming Notes to Self

Helpful one liners, and more, that I may need later

Git Clone over SSH

July 8, 2021 — Using Git with your own servers—without a hub like GitHub or GitLab—is easy. This is the straightforward, quick and dirty way with no new concepts to learn. There are more advanced ways (like -bare), but I find 4 times out of 5 I just need a quick way to sync repos between machines.

git clone ssh://breck@example.com/home/breck/project

The one annoying thing here is your push will be rejected if your are pushing the branch that is currently checked out on the server. You can quickly check out a temporary branch, push main, and then check main back out on the server.

git push

Article source

Unpause

June 9, 2021 — After a decade buried in the digital attic, I recently uncovered this old blog and upgraded the content to use Scroll. It was a fun restoration project and interesting to me personally to see what types of technologies I was using a decade ago. It was fun to read that I was still uncertain if I would switch to a Mac. IIRC that Macbook Air would last me until 2016! It was followed by another Air, and then around the end of 2020 I upgraded to the current crop of machines, typing this on an M1 MacBook Pro.

Anyway, I also just remembered how nice and convenient it was to post these small snippets I need in my day-to-day coding work on a fast, ad free site. So decided to restart this blog.

Why not just start a fresh one? That might be a better idea. For now I plan to reuse this one. Perhaps split them later, if that makes sense.

If I do keep with it, this post is just to acknowledge that that's no bug, there was a 3,444 day gap between posts.

Article source

Git Ignore Global

January 4, 2012 — Create a global .gitignore file to ignore common pains:

vim ~/.gitignore_global .DS_Store* Icon? Thumbs.db git config --global core.excludesfile ~/.gitignore_global

Thanks to github

Article source

Execute commands on remote server via ssh

November 7, 2011 — Ever want to non interactively execute commands on a remote server?

ssh breckyunits.com 'df -h'

Article source

Cool Way to Duplicate a Finder Window in the Current Directory

October 14, 2011 — Sometimes I want to rearrange a directory. An easy way to do it is to use Cinch and have 2 windows side by side. It's a pain to open 2 windows to the same directory though, until I found this little script

Article source

Great Overview of Linux Command Line

October 11, 2011 — Just read an awesome overview of the command line

Article source

Find big files in Linux

October 6, 2011 — Edit: found a better way, use ncdu https://dev.yorhel.nl/ncdu

How to find files larger than a certain size:

find /etc -size +100k

Disk free space:

du

Article source

ack and ackmate

August 26, 2011 — So one common problem I have is writing code at a macro level---refactoring things in multiple files. Notepad++ used to make this easy with it's fast and powerful find/replace in folder feature. Textmate's built in find/replace in project is painfully slow.

Grep & Sed don't cut it either. I've been using some custom written perl scripts for my needs. But today I discovered ack & AckMate. Problem solved. Really tight integration with TextMate (though the default 4 key shortcut is terrible--need to change that).

This is probably something I would have learned faster had I been doing more pair programming with senior devs.

Article source

nohup and disown

August 22, 2011 — Just read a good guide on how to keep commands running when you exit ssh:

Basically:

nohup ./mycommand &

Adding the ampersand to the end of a command in Nix executes the command in the background and gives you back your shell. However, if you quit your terminal the process will be killed. The nohup command takes care of that.

What is nohup? It's another obfuscated Nix low level utility that is an abbreviation for "No Hangup Signal", in other words: if the terminal sends a hangup signal, normally that kills all running processes, but this says ignore that.

Wikipedia article on nohup.

Article source

New shortcuts

August 14, 2011 — Gmail:

gi - go to inbox c - compose j/k - go up and down, enter go to a page. gt - go to sent

Mac:

ctrl+a - home/start of line ctrl+e - end

Article source

Apache, SSL and self signed certificates

August 14, 2011 — Just read an excellent guide about how to create self-signed certificates.

Here's what it boils down to:

# The cool thing about SSL is it's just 2 text files. A public key and a private key. # They have a "pem" and a "crt" extension, but they are just plain text. Neat. # Okay, first step is to create a private key "pem" file. # every time you run this the random output pem file will be different: openssl genrsa -des3 -out private_key.pem 1024 # (enter passphrase) # Next, generate a "signing request". openssl req -new -key private_key.pem -out private_key_certificate_signing_request.csr # (for common name enter the full domain name: # (the extra options aren't necessary--just hit enter) # Next remove the password from the private_key. Otherwise you'd have to enter # that password at all sorts of inconvenient times.....be careful because # if someone gets this unencrypted ket, you'll need to get a new cert..so make your pem readable # only by root! cp private_key.pem private_key.pem.original openssl rsa -in private_key.pem.original -out private_key.pem # now you can generate your public self signed certificate: openssl x509 -req -days 365 -in private_key_certificate_signing_request.csr -signkey private_key.pem -out self_signed_public_certificate.crt # now copy the private key (pem file) and the public key ( crt file ) to your web server. mkdir /etc/httpd/certs cp self_signed_public_certificate.cert /etc/httpd/certs cp private_key.pem /etc/httpd/certs # you can delete the CRT file. you don't need that crap anymore. you got the cert/public key and the pem/private key. thats all you need rm private_key_certificate_signing_request.csr # if you don't have mod_ssl installed you need to install it. on fedora: yum install mod_ssl #now edit the apache config to let apache with mod_ssl know where the keys are: SSLEngine on SSLCertificateFile /etc/httpd/certs/self_signed_public_certificate.crt SSLCertificateKeyFile /etc/httpd/certs/private_key.pem

Article source

EC2 Command Line Tools

Step 2. Set Java path in your .bash_profile:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/

Step 3. test Java path is correct:

$JAVA_HOME/bin/java -version  Step 4. set ec2 path in your .bash_profile: export EC2_HOME=/Users/breck/Downloads/ec2-api-tools-1.4.4.1 export PATH=$PATH:$EC2_HOME/bin  Article source zip a directory in linux zip -r backup mydir/ zip -r backup . Article source Recursive Sed August 5, 2011 — As far as I can tell, sed doesn't have a recursive mode. Here's a little script that uses perl to simulate a recursive sed: #!/bin/bash perl -e "s/$1/$2/g;" -pi$(find . -type f)

I put this in a file named ~/rsed

Then in my .bash_profile:

alias rsed="~/rsed"

Now I can use it like so:

rsed old new

Article source

netstat

August 1, 2011 — Every wonder what's listening on what ports?

netstat -lp

Article source

Bash History

July 17, 2011 — Understanding and mastering bash history can:

1. Save you a lot of time, keystrokes, and errors.
2. Allow you to easily create shell scripts for common tasks (such as setting up a server).

Here's a terrific guide on using Bash History effectively.

Article source

Amazing SSH Tricks

July 16, 2011 — Just read an article that contains some amazing SSH tricks.

Article source

ngrep for packet monitoring

July 13, 2011 — I just came across a neat command line tool, ngrep, via this site.

Sample usage:

ngrep -q -W byline "^(GET|POST) .*"

Article source

Basic Linux Monitoring

July 9, 2011 — Show memory usage:

free -m

alias free="free -m" top

Show all processes

ps -a

Disk free space:

df

Article source

Creating a bootable Linux USB disk on Mac

• Convert iso to img on terminal:
hdiutil convert -format UDRW -o ~/path/to/new.img ~/path/to/source.iso
• Open Disk Utility. Right click the drive and click Information, then note the drive path (disk1 or disk2 for example)
• Right click the Disk and click Unmount
• Back in terminal:
sudo su root dd if=/path/to/new.img of=/dev/rDISKNUMBER bs=1m

July 8, 2011 — Where DISKNUMBER = disk1 or disk2 for example. Add that leading "r".

Back in Disk Utility, unmount/eject the disk.

Done!

Article source

Notepad++ HAML Syntax Highlighting and other custom extension mapping

July 3, 2011 — I want my HAML files to have PHP(or Ruby) syntax highlighting.

Settings > Style Configurator

Then click php and under "user ext" (in the bottom left) add haml

Article source

Mac Terminal Cursor Trick

July 3, 2011 — If you hold the "option" key while using the Mac terminal you can use your mouse and click on where you want the cursor to go. This comes in handy if you mistype a command and don't want to retype the whole thing. It also kind of negates the need for a "home" key on the terminal.

Article source

Apache Conf and Htaccess Examples

June 30, 2011 — Configuring Apache can be a pain. I'm going to try and collect links to great resources. The official docs are good, but they really need to add commenting so people can expand upon the resources available.

http://www.evolt.org/ultimate_htaccess_examples

Article source

Fix for "selinux 3.82" stuck while installing Ubuntu from USB Drive

June 27, 2011 — If you are installing Ubuntu from USB and are getting stuck at the "SELINUX 3.82" screen, you'll need to edit the selinux/selinux.cnf file on the USB stick and comment out the "vesamenu.c32" line, and remove the "ui" from the last line.

Article source

My Programming Setup

May 30, 2011 — Here's my setup. This is kind of for my reference but you can also check it out if you're interested.

• Macbook Air. 4GB. 256GB HD.
• VMWare Fusion almost solely to run Notepad++
• In Fusion I removed the Apple+W shortcut they map by default. Also, I map the Apple Key to the windows Ctrl key and the Mac control key to the Windows Key.
• I run Fusion in Unity mode and have the Windows taskbar at the bottom of the screen.
• I make the Mac tray pretty small at the bottom of the screen and set it to disappear.
• I run Cinch on my Mac to get the next drag and drop for side by side comparison function that comes with Windows 7.
• I run Dropbox on the Mac. I share a folder using Fusion to have access to it in Windows.
• I disable network access on the Windows virtual machine so I don't have to worry about viruses etc on that guy.
• I enabled a firmware password on my macbook.
• I add a lot of things to my bash_profile on the mac and pretty much always have at least 1 terminal window open.
• I use textmate on the mac occasionally but try to do all my work in Notepad++.
• I run MAMP on the Mac and WAMP on the WinVM.
• I bump up the font size on a lot of things like terminal etc.
• I go to "Keyboard" on the Mac and enable function keys. That way F1 works like you'd expect and you have to hit Fn+F1 to adjust the screen brightness.

Article source

What Happens When you Open a 1.7 GB text file?

May 27, 2011 — I downloaded the Verisign Master .com TLD zone file which weighs in at a hefty 1.7 GB. What happens when I open it with different programs on my Windows 7 Samsung netbook?

With Windows Notepad: You quickly get a "File is too large. Open with a different text editor." message. Graceful FAIL

With Microsoft Wordpad: Immediately got a "Not Responding". On the status bar it says "3% complete" but 3 minutes later it hasn't changed. I'm going to go ahead and CtrlAltDelete this one. Disgraceful FAIL.

With Notepad++: "File is too big" error. Graceful FAIL.

VIM in Cygwin: It appears frozen.

I will continue this post at a later date.

Article source

April 24, 2011 — Just create a new A Record with * as the host and your IP in the points to field.

Article source

Quickly Set up a Web Proxy Server

March 13, 2011 — Sometimes when abroad it becomes necessary to route your internet traffic through a proxy.

Here's a great article that shows how.

I also recommend the QuickProxy Firefox addon which lets you quickly toggle the proxy on and off.

Article source

A few new Tricks in Notepad++

March 12, 2011 — I've been on the road for a few months programming on a Windows 7 Samsung netbook. (I didn't want to bring the Macbook with me and risk breaking it or worse).

The one thing I love about Windows is Notepad++. Sorry Textmate, you just can't compete.

Here are some things I'm using a lot more now in Notepad++:

• Bookmarks. Hit Ctrl+F2 to set a bookmark on any line of code and then hit F2 to jump between bookmarks. Shift+F2 goes back a bookmark.
• SourceCookifier. This is a neat plugin that lets you jump to the definition of a function by hitting Ctrl+Shift+Enter. This is one feature from IDEs that I missed. It also provides a nice sidebar with a breakdown of your code(functions, vars, etc.).
• FileSwitcher. A plugin that lets you hit Ctrl+Shift+o and then just type the name of the file you want to work on. Much quicker way to switch files than clicking or ctrl tabbing.
• Goto. Ctrl+G lets you jump to a line number quick. I've used this in the past but am using it more often now.
• Column Editor. Pretty handy sometimes.
• Automation PHP Plugin. F9 to run your script. Great for quickly testing small sections of code.

Article source

RVM Quick Reference

December 12, 2010 — Return to the Mac OS X default Ruby install:

rvm system

Switch to Ruby 1.9.2:

rvm 1.9.2

Create a new gemset:

rvm gemset create rails3

Switch to newly created gemset:

rvm 1.9.2@rails3

Install rails 3 on new gemset:

gem install rails -v 3.0.3

rvm system

Install a new version of Ruby:

rvm install 1.9.2

Article source

Forward a port on a remote server to your local machine with an SSH Reverse Tunnel

December 4, 2010 — Say you are running a web server locally and want to show it to someone else remotely.

You have a few ways to do this:

2. Setup DNS to point a domain to your local IP.

But what if your local computer is behind a NAT and you don't want to configure port forwarding on your router?

One option if you have a publicly facing server already is to create a reverse SSH tunnel with that server. This allows you to forward a port on that server to a port on your local server.

For instance, on my Mac OS X machine I open terminal and type this command:

ssh -nNT -R 3333:localhost:3333 username@yourdomain.com

This will connect to my server (yourdomain.com), and forward traffic from port 3333 on that server to my local machine. Now I can tell someone to go to yourdomain.com:3333 and that would be the equivalent of them going to localhost:3333.

Notes:

Make sure to add a rule to your IPTables config to allow inbound traffic to port 3333.

Article source

Features I Miss from Notepad++ in Textmate

October 16, 2010 — Here are a few things I really miss from Notepad++:

• When you doubleclick a word in Notepad++, all occurrences of that word are highlighted in green.
• Notepad++ has great autocompletion. Once you type a word in a document, that word is added to the autocompletion list. Autocompletion drops down inline too which is great.

If anyone nows how to replicate these things in Textmate please let me know! Thanks.

Article source

Git ignore a file that's in the repo

October 3, 2010 — Let's say you've got a file that's checked in like environment.rb that you want to edit for your local machine only and don't want to push the changes to your repository. It's easy, just do:

git update-index --assume-unchanged filepath

and to reverse:

git update-index --no-assume-unchanged filepath

Article source

October 2, 2010 — For the third time in my life I've gotten a Macbook. The previous two times I returned them. I'm hoping the third time is a charm.

After a week I'm finally starting to get used to it. I'm starting to really customize it and that seems to make all the difference. I've removed nearly everything from the dock, added a bunch of things to my bash profile, and a friend at work gave me a crash course in Textmate.

I've downloaded a program called Sizeup, which not only emulates the awesome "Snap" feature of Windows 7, but in fact is even better. It gives you the left/right 50% snap feature just like in Win7, but also lets you snap things into top/bottom and even snap things into quadrants. Pretty nice software.

Firefox is my favorite of the 3 browsers on the Mac. I loved Chrome on Windows because it was so fast, but this Air is so blazing fast that running Firefox or Chrome on Mac makes little difference.

I've added the Secret Preferences menu and turned "show all hidden files and folders" on. I hate not seeing everything in a folder.

I created an alias "dsdelete" to quickly recursively delete DS_Store hidden files (helpful when zipping folders for sharing).

I learned the "open ." command and changed the terminal color scheme.

I installed RubyMine and Web Developer Toolbar and Tamper Data and Charles and Dropbox. I'm still trying out VMWare Fusion and haven't decided if I want it yet.

I've slowly gotten used to the keyboard. I tried spaces but have turned it back off for now. Expose I hardly use yet.

All in all, I'm really enjoying the speed, instant on, the light weight of the computer, Ruby on a Mac (doing Rails dev on Windows is a pain), having a real terminal(cygwin is great, but native is better), and the fact that 50% of my CPU isn't dedicated to fighting viruses. I'm still developing slower on this machine but hoping that my speed will improve with time.

I'd say the odds at this point are 60-40 in favor of me sticking with it this time.

Article source

Remove all DS_Store files recursively

find . -type f -name ".DS_Store" -exec rm {} \;

Article source

Windows 7 Hosts File

August 14, 2010 — The file is located at:

windows/system32/drivers/etc/host

Mac hosts file:

/private/etc/hosts

Article source

Rubyful Soup

August 14, 2010 — I was a big fan of BeautifulSoup in Python and was excited to see a Ruby port. Sadly it's no longer being maintained.

To get v1.0.4 working with Ruby 1.9.2, I had to make the following changes to the rubyful_soup.rb file in my gems directory:

• Line 19 - comment out 'require 'jcode''
• Line 233 - remove the colon

Article source

VIM and Rails

August 13, 2010 — Check out this guide.

filetype on " Automatically detect file types. set nocompatible " We don't want vi compatibility. " Add recently accessed projects menu (project plugin) set viminfo^=! " Minibuffer Explorer Settings let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplModSelTarget = 1 " alt+n or alt+p to navigate between entries in QuickFix map <silent> <m-p> :cp <cr> map <silent> <m-n> :cn <cr> " Change which file opens after executing :Rails command let g:rails_default_file='config/database.yml' syntax enable set ruler " Ruler on set nu " Line numbers on set ruler " Ruler on set nu " Line numbers on set nowrap " Line wrapping offset nowrap " Line wrapping off set timeoutlen=250 " Time to wait after ESC (default causes an annoying set ts=2 " Tabs are 2 spaces set laststatus=2 " Always show status line.

Article source

PHPUnit Filter Option

August 10, 2010 — Say you are running PHPUnit from the command line and want to run just a specific test as opposed to a whole class of tests.

For example, say you have a tests.php file that contains a FileWriter_Test_Class with a test method named testFileWriter that you want to run.

Do this:

phpunit --filter testFileWriter FileWriter_Test_Class tests.php

Article source

Kill a Detached Rails Webrick Server

August 9, 2010 — From your rails app's root:

cat tmp/pids/server.pid kill -9 {pid}

Article source

Cygwin SSH Client Keep Alive

August 6, 2010 — Add this to your /etc/defaults/etc/ssh_config file to prevent SSH servers from disconnecting you after inactivity:

ServerAliveInterval 60

Article source

Augmented Gitignore

.bundle db/*.sqlite3* log/*.log *.log tmp/**/* tmp/* doc/api doc/app *.swp *~ .DS_Store

August 4, 2010 — Source

Article source

Windows Flush DNS

June 30, 2010 — Open cmd.exe. Run:

ipconfig /flushdns

Article source

Insert a line of text to the top of a file

May 29, 2010 — If you have a massive text file you want to add a line to without opening the file, here's a quick solution:

sed -e '1i\text_to_insert' -i file.txt

Article source

wget don't save file

wget -O /dev/null http://address.com

Article source

Recursive ls

March 10, 2010 — Add the -R option to ls to recursively list the contents of a directroy.

Article source

ls color scheme

March 10, 2010 — found this helpful color scheme for ls. toss in your bash_profile.

alias ls="ls --color=auto" LS_COLORS="di=31;1:ln=36;1:ex=31;1:*~=31;1:*.html=31;1:*.shtml=37;1" export LS_COLORS

Article source

gca alias for faster git

March 10, 2010 — One of my most frequent commands is:

git commit -am "message"

I made a simple alias to save keystrokes:

alias gca="git commit -am "

Article source

Dump MySQL schema only

March 10, 2010 — I found this command to dump just the schema.

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

You can then load the file easily.

Article source

vim macros

/** * Returns the sum of 2 variables. * * @param int $a * @param int$b * @return int $sum */ function sum($a, $b) {$sum = $a +$b; return $sum; } You can record a macro to help speed up the commenting process. 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. You can overwrite the macro by repeating the above steps. Bonus tip: Bookmarks.Use m + a letter to create a bookmark in vim. Then use the backtick plus the letter to return to the location. Keyword completion. Use Ctrl+N to complete a word. Notes Article source pwd while in a symlink directory March 1, 2010 — to get the actual directory, run: /bin/pwd Article source Case sensitivity in MySQL table names and lower_case_table_names February 27, 2010 — On linux, filenames and directories are case sensitive. file and File are different files. On Windows, filenames are not case sensitive. file and File are the same file. MySQL saves a database to disk. A "database" is saved in a directory, and each table is saved as a file in that folder. 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". There's a setting in your my.cnf file called "lower_case_table_names". The options are 0, 1, and 2. 1 is the default, and you shouldn't need to change it. 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. 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". Article source The BASH Programming Language February 25, 2010 — 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. 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. Here's the core of what you need to know: Use the .sh file extension 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. Start your scripts with #!/bin/bash #!/bin/bash Here's your first bash script (name it hello.sh): #!/bin/bash<br> echo "Hello World" The *echo* command prints a string and also a new line at the end. Running your script Your script must be **executable**. To make it executable, you need to change the file permissions. This would make your hello.sh script executable: chmod 777 hello.sh To run your script, from the directory where your script is located, type this: ./hello.sh The "./" substitutes the current directory. In other words, typing ./hello.sh is equivalent to typing the full path to the file such as this: /home/breck/hello.sh Command line Paramters Command line parameters are accessed with$1, $2, etc. Create a new script called hello2.sh. Put this in it: #!/bin/bash echo "Hello World" echo$1 echo $2 Now run your script like this: ./hello2.sh hi breck It should print this: Hello World hi breck The hi got stored in$1, and the breck got stored in $2. Functions Functions are pretty simple and straightforward: #!/bin/bash echo "Hello World" echo$1 echo $2 function hi_name { echo "hi" echo$1 } hi_name $3 Notice you don't need parenthesis and other junk. Name this file hello3.sh and run it with this: ./hello2.sh hi breck conor It should print this: Hello World hi breck hi conor Notice what's going on with parameter passing and scope. That's it for now. As you can see, BASH is a very clean, simple, yet powerful programming language. Get started with it slowly and gradually build up your skills with it. Article source ANSI or ASCII and Unicode or UTF-8 and Newlines February 25, 2010 — The key things you need to know: ANSI (aka ASCII) and UTF-8 (aka "UnicodeTransformation Format" or just "Unicode") are ways to encode text files into binary data. 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. Unicode is the new guy, and is slowly replacing ASCII. 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. Windows does \r\n, whereas Unicode just does \n. Here's an experiment you can do using Notepad++ and Notepad. Open Notepad++ and start a new document. Type in: hello<br>world 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? 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? Tada! Now when you're having line problems just use this nifty feature in Notepad++. 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 Article source Cygwin Error: Could not resolve hostname X: Non-recoverable failure in name resolution February 21, 2010 — I've been getting this error a lot in Cygwin on Windows 7: Could not resolve hostname X: Non-recoverable failure in name resolution 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. The problem is this bug is hard to reproduce. It happens only 5-10% of the time. Edit #2: Upon closer examination, it seems this error only happens with ssh: ssh: Could not resolve hostname X: Non-recoverable failure in name resolution 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. Article source Plugins for Notepad++ February 6, 2010 — Notepad++ is my go to editor. The default plugins are great, but if you need more just visit the notepad++ plugins list. To install a plugin: 1. Download the zip file and unzip it. 2. Copy the dll to your Program Files/Notepad++/Plugins folder. The main plugin I've used so far is Explorer. I'll update this in the future with other ones. That's it! Article source More tips on using rsync to deploy your website February 3, 2010 — My post on deploying a website using rsync has gotten quite a few hits. I thought I'd add some more tips: • use the "--delete" option if you want to delete files on the destination directory that no longer exist in the source directory. • add "$1" after your options like this:
rsync -rvz$1 Then you can easily do a DRY RUN. Just type: ./deploy.sh n The n will get substituted for$1.

Troubleshooting

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

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

The options that I've found come in real handy are:

1. 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 (?)).
2. 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.

Article source

Linux Go Back to Previous Directory

cd -

February 1, 2010 — To go back to the last directory you were in. Basically an "undo" for the cd command.

Article source

Should your source code be in one folder or should it be nested?

January 25, 2010 — There are two ways to organize source code files for a project: flat or nested.

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

📁myproject index.php theme.css helper_functions.php logo.png

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

📁myproject index.php 📁styles theme.css 📁images logo.png 📁 helpers helper_functions.php

Both of these structures can accomplish the same thing. Which is better?

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).

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.

Benefits of a Flat Structure

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.

Benefit #2 - Avoid file path issues

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.

Benefit #3 - Easier to bring people up to speed

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?

Benefit #4 - Avoid overwriting issues

Occasionally you'll have a structure like this:

index.php 📁admin index.php

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.

Benefits of a Nested Structure

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

Benefit #1 - Looks more organized

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

Benefit #2 - Easier for teams

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?

Benefit #3 - A directory with too many files becomes unwieldy

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.

My theory on why directories are bad.

Less paths create an easier mental model.

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:

📁myproject a_image.png base_functions.php dog.js index.php mike.png names.csv new_logo.jpg test.php xmlfunctions.php zlib.js

It's a mess.

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:

Ok

📁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

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.

Best

The optimal solution is to not put your stuff into drawers, but to:

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

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

📁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

Search, don't sort

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.

The Rule of Three

• No folder in your project should have more than 3 subfolders.
• There should not be more than 3 levels in any project.

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

📁myproject 📁images 📁icons

This means that any project should have at most 9 subdirectories.

Article source

Unix date command

January 19, 2010 — Display the current unix timestamp:

date +%s

Handy way to view it from the command line.

Article source

Bug Workaround for JS Charts Error: Not enough data to display chart

nullData = new Array( ); myChart.setDataArray(nullData,"null");

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.

Article source

Change the file owner or group in Linux

January 8, 2010 — Change the owner of a file or folder:

chown newowner filename

Change the group of a file or folder:

chgrp newgroup filenameorfoldername

Article source

How to load a sql file into MySql

January 6, 2010 — It's very simple thanks to pipes.

mysql -u username -p < sqlfile.sql

Make sure your sql file has a "use database" line.

Article source

Shortcut for switching to a Windows directory in Cygwin

January 1, 2010 — In cygwin it can be a pain to change to a Windows directory like C:\Users\breck\Documents\My Dropbox.

I made a small bash script called wcd that makes it easier.

Variable scope

December 18, 2009 — A shell script will launch a new shell that has a fresh scope.

$FIVE = 5$ vim myshellscript.sh #!/bin/bash echo $FIVE$ ./myshellscript.sh

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

Export command.

Use the export command to change the scope of your variable to global for your shell.

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

MY_NAME=breck; export MY_NAME

Accept input.

Use the read command to accept input.

echo "What is 1+1?" read ANSWER echo "Your answer is \$ANSWER"

Notes

1. Bash tutorial 2. Another tutorial 3. Bash parameters

Article source

How to fix an overwhelmed Gmail Accout

December 17, 2009 — I have used the same Gmail address as my main email for over 5 years. Since then:

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

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

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

My Gmail account had become a firehose.

This was bad for two reasons.

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.

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.

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.

As it turns out, the solution was simple.

• 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.
• Starred all the recent messages that I still had to deal with.
• Archived all 29,000+ of my gmail messages at once.
• Went back to the starred folder and moved the important messages to inbox.

Notes

1. Thanks to this site for telling me how to archive all my gmail messages.

Article source

Seven aliases that can save you time

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

Article source

List only directories using ls

December 13, 2009 — the "ls" command lists all files and directories. What if you just wanted to list the directories?

ls -l | egrep '^d'

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?

alias lsd="ls -l | egrep '^d'"

Notes

1. Found this tip here.

Article source

Turn off bell in cygwin

December 11, 2009 — The beep on tab completion in cygwin can be annoying. Here's how to turn it off:

vim ~/.inputrc (Then add or uncomment this line) set bell-style none

Article source

git clone without history

December 11, 2009 — If you're using a library from git in another project, you may want to download it without the history. Here's how:

git clone --depth 1 your_repo_url

http://git.or.cz/gitwiki/GitFaq#HowdoIdoaquickclonewithouthistoryrevisions.3F

Article source

Learn Symbolic Links in 30 seconds

December 5, 2009 — Symbolic links are simple and can save you time.

Here's all you need to know:

ln -s actual_file_or_directory new_symbolic_link_name

Let's do a real example from your home directory:

ln -s /var/www/html/yourwebsiteroot/yourblog blog

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

Here's one more example from your home directory:

ln -s /etc/httpd/conf/httpd.conf httpd.conf

Now you can just type "vim httpd.conf" and edit your httpd.conf file quicker.

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).

Notes

Aliases are another great time saver.

Article source

Create a new user in Linux

December 5, 2009 — Creating a new user in Linux is dead simple.

useradd bob passwd bob

This adds a user "bob" and then prompts you to enter a password.

Article source

Use aliases to save time

November 28, 2009 — Using aliases in Linux can save you a lot of time. Here's an example:

alias www='cd /var/www/html/'

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.

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

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

You can also just do:

alias apr='/usr/sbin/apachectl restart'

But the earlier example shows how you can string multiple commands together.

Bonus tip

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

Notes

1. "At least" 14 keystrokes, because the # of typos increases as the # of characters typed increases.

Article source

Use git to get the latest source code only

November 27, 2009 — Say you want to get just the source code of a git repository without all the history(without the ".git" directory). Use this:

git clone --depth 1 git://github.com/breck7/brecksblog.git

Article source

How I organize my Dropbox

November 27, 2009 — Gmail encourages users to "search not sort". I do that. Email works great for search. For files though, sorting is often better.

I have well over 20GB of files synced onto my Dropbox. The rest of my computer is spotless(I use Windows 7 and do a fresh install every 30-60 days). But the Dropbox can get cluttered. I take a simple approach that is a hybrid of search and sort. Here's how to do it:

Put files into 2 sections:

• commonly accessed folders in the root directory.
• everything else in a "Search" directory, which is in the Dropbox root directory.
• Create a folder in your root Dropbox directory named "Search". Plop anything in here.
• Keep your most common folders in the root Dropbox directory. Sort these ones.
• 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.

End Result

Here's what the end result may look like:

-My Dropbox --Music --Photos --Blog --eBooks --Company Docs --Search

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.

This a hybrid of search and sort.

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.

Article source

What non-web software do you use the most?

November 26, 2009 — Here are the programs I use everyday, every week, and every month.

What software do you use the most? What are your "must haves"?

My Machines

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

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.

Most of our servers are slices from slicehost running Fedora.

On all my development machines I run Cygwin. Programs I run in Cygwin are noted by *.

The following is a list of the programs I use on my development machines.

Daily

• Cygwin. I prefer Windows+cygwin over Macs, Fedora or Ubuntu, or Windows plus running virtualized machines.
• Notepad++. I do half my editing in Notepad++ and half in Vim. I love Notepad++'s speed, reliability, and autocomplete.
• 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.
• 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.
• Chrome. I spend most of my web time in Chrome. It's lighting fast. It's also simple. Tabs are done incredibly well.
• 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.
• 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.
• *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".
• *Git. Easy to use version control that makes sense. Paired with github, becomes indispensable.
• *Grep. Great when you need to track down a word or line across multiple files.
• *Find. Simple and easy for finding files. I also use find over Windows 7's search occasionally.
• *Cron. Simple and essential.
• *SSH. Of course.
• *Ruby. I keep irb running in a window when I need to do quick calculations.

Weekly

• 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.
• Filezilla. Occasionally when I just want to drag and drop some things from or to a server.
• 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.
• 7zip. "Extract to here" is a great little feature that it adds to the right click menu.
• Word & Excel 2007. Solid programs. Too bulky for my liking, but necessary in many cases.

Monthly

• Visual Studio. When I get an urge to write a new desktop program.

Article source

Use the linux find command to find files

November 25, 2009 — Say you're looking for all files starting with the word "breck". Using the linux "find" command, it's simple:

find -name "breck*"

Will search the current directory and all subdirectories for files starting with the word "breck".

Article source

Fix permission problems using chmod

November 25, 2009 — Permission problems driving you crazy? Here's a common command to fix them:

chmod -R 755 directoryname

Change the file permissions of all directories and files in directoryname to 755.

Article source

cron in 2 steps

November 25, 2009 — cron lets you schedule linux commands to execute on a regular basis.

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.

Step 1: Write the cron command

Here is the cron command you would need:

0 * * * * wget http://yourdomain.com/backup.zip

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

Step 2: Append the command to your crontab file

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.

crontab -e

This will open vim, and you can then paste and save your crontab file.

Viola!

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:

cygrunsrv -I cron -p /usr/sbin/cron -a D net start cron

If there are problems, check the cron.log file in your home directory.

Article source

Use grep to search multiple files at once

November 22, 2009 — grep lets you search through multiple text files at once.

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

grep -r picture *

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.

Then I went in and changed the 2 files that needed modifying.

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

grep picture *.*

This would have searched through all the files in the current directory.

Had I wanted to search in just 1 specific file:

grep picture filename.txt

Had I wanted to do a case insensitive search:

grep -ir picture *

Had I wanted to exclude a directory and done a case insensitive search:

grep -ri "searchstring" --exclude="*\.svn*" *

(grep uses regular expressions)

Article source

Use rsync to deploy your website

November 21, 2009 — rsync is a nifty little tool that can deploy a website to a testing or production server.

Here's a one line command to deploy brecksblog:

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

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

I saved this file as "deploy", and then run it by typing:

./deploy

The exclude option will exclude a file or directory from being synced.

Here's an explanation about the options I use. I use rsync with these options:

rsync -arvuz /src/foo/ /dest/foo

This will copy the contents of /src/foo/ into /dest/foo. Options explained:

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

Notes

1. If you are using a different port for SSH, say 333 do this: --rsh="ssh -p333"

Article source

November 20, 2009 — On your server:

vim /etc/ssh/sshd_config

Make sure allow rsa and the other RSA lines are uncommented

service sshd restart

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

Run this on your client computer:

ssh-keygen -t rsa

(hit enter a bunch of times)

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

This is my setup on Fedora VM's running at slicehost.

If you are having problems

1. Run sshd with the verbose option. -v

2. 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) authorized_keys should be the same owner/group and file permissions should be: 644

Article source

Get VIM Working in Cygwin

November 20, 2009 — I had trouble getting VIM behaving as expected under Cygwin. Specifically, the backspace and arrow keys were behaving badly in insert mode.

touch .vimrc

• Found this solution in the comment from Gregg
• vimrc

Article source

November 18, 2009 — 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.

This is it.

Article source