Skip to content
Jul 2 10

Setting up a new dev environment

by admin

There are so many things i forget when setting up a new workstation. This time I took notes so I wont forget.

After installing VMWare fusion3 on my macbook pro I download the latest Ubuntu iso and start a new VM with it. I keep my work on TrueCrypt partitions. Then work my way down this list.

For starters

  1. sudo apt-get install git-core gitk git-gui
  2. sudo apt-get install subversion
  3. sudo apt-get install ssh-client
  4. sudo apt-get install ssh-server
  5. sudo apt-get install vim
  6. sudo apt-get install rake
  7. sudo apt-get install libxml2-dev

Then install sphinx
http://freelancing-god.github.com/ts/en/installing_sphinx.html
./configure, make, sudo make install

VMWare Tools
Turn off shared folders (i always get failures when i dont)
From the virtual machine menu, select install VMTools. Open the virtual DVD and put the zip file on the desktop and extract it there.
From a terminal cd Desktop/vmware…
Then sudo ./vmware-tools-install.pl
Enter key for all the defaults. Then run the networking stop and start commands at the end of the instructions.

Install Ruby

  1. sudo apt-get install ruby-full build-essential

or

  1. sudo aptitude install ruby build-essential libopenssl-ruby ruby1.8-dev

Install Apache

  1. sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev

Install Ruby Gems

  1. sudo apt-get install rubygems
  2. export PATH=/var/lib/gems/1.8/bin:$PATH

Install Rails

  1. sudo gem install rails

Install MySQL

  1. sudo apt-get install mysql-server mysql-client
  2. sudo apt-get install libmysql-ruby libmysqlclient-dev
  3. sudo gem install mysql

Install Passenger

  1. sudo gem install passenger
  2. sudo apt-get install apache2-threaded-dev libapr1-dev libaprutil1-dev
  3. sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module

[follow passenger instructions]

VMWare Network connections
Since FF is the default browser you need to make a small change to browse the web.
Open FF and put about:config in the URL. Then filter for ipv6 and set false to true and restart FF. You should be online.

Shared Folders
Use TrueCrypt to keep your work on and share /Volumes/[your TC Drive] with VMWare. You will need to shift+apple+g to get the got to folder dialogue to find /Volumes.
You can access the files in your VM here
/mnt/hgfs

Install Gems
[what ever gems you need ]

Configure Apache
(Sill on your VM)

  1. mkdir ~/rails_development
  2. cd ~/rails_development
  3. ln -s /mnt/hgfs/[your drive]/myapp myapp

Now cd to /etc/apachec2/sites-available and sudo scp 000-default myapp
then sudo vim myapp

  1.  
  2. <VirtualHost *:80>
  3.      ServerName myapp.ubuntu
  4.      RailsEnv development
  5.      DocumentRoot /home/wylie/rails_development/myapp/public
  6.      <Directory /home/wylie/rails_development/myapp/public>
  7.           AllowOverride all              
  8.           Options -MultiViews
  9.      </Directory>
  10. </VirtualHost>
  11.  

Then cd ../sites-enabled
and sudo ln -s ../sites-available/myapp
then sudo rm 000-default
Finally restart apache

Set your hostfile
(Back on OS X)
get the IP in your VM and edit your hosts file on OS X
sudo vim /etc/hosts
[ip of VM] myapp.ubuntu
then run dscacheutil -flushcache (i usually have to run this a few times for it to take)

Install the DB
create any databases you need for your apps

Dont’ forget the memcached

  1. sudo apt-get install memcached
  2. sudo /etc/init.d/memcached restart

Fire it up
open your browser and go to myapp.ubuntu

Permission fixes
if you put id in the command line in your VM you will see that UID is 1000. The problem is that VMWare puts you in as UID 501 and GID 20. We need to update Ubuntu to match
sudo vim /etc/passwd
Then find your user and change 1000:1000 to 501:20, save and exit
You wont be able to make any more changes so you need to reboot. You cant log in either so you need to Ctrl + Alt + f1 to switch to terminal. Login there.
Then, you need to cd to /home and change the permissions on everything in your user dir like this
sudo chown -R 501:20 wylie
Then you need to update the group file sudo vim /etc/group
find dialup and change that to wylie [your username]. Then you need to find your username and change 1000 to 20.
sudo reboot, login and permissions are now fixed. Its a good idea to update your apache in /etc/apache2/envars. Change www-data to your username in both places

Git GUI fixes
The text in the UI is huge so you can open synaptic package manage and search for tcl. mark the 8.5 version for install. Then search for the tk8.5 and mark that for instalation. Then in command line
sudo update-alternatives –config wish
select the option with 8.5. It should be number 3.
Now when you open git gui it should look normal

Now get to work…

Jun 25 10

Regular Expression Tools

by admin

A friend shared a RegEx tool that came in really handy. Its www.rubular.com. I dont’t get alot of opportunities to work with regex but when i do, having a new tool can make it almost fun.

I came up with this expression to match various URL’s that users enter that i could create new links from.

  1. (((https?):\/\/)?(([0-9a-zA-Z][-\w]*\.)+[a-zA-Z]{2,9}(:\d{1,4})?([-\w\/#~.?=&%@~])*))

Looks like cartoon swearing.

Mar 30 10

color scheme tool

by admin

How did I get this far without a tool like this?
A friend sent this link to me and I wanted to be sure that I never lost it.
http://colorschemedesigner.com/

Mar 2 10

jQuery Emoticon Selector Plugin

by admin

I couldn’t find an emoticon plugin for inserting an emoticon into a text area. I found plenty that converted the emoticon code into an image. So, I set out to write my first jQuery plugin.

If you choose to use this, keep in mind this was my first plugin and should be thoroughly tested before using it. And if you make it better I would very much like to see what changes you made.

Lets check it out.

The view has two components. The jQuery call and the div with the necessary elements. (my examples are how i used this in Ruby)

  1.  
  2. <% javascript_tag do %>
  3.   $(document).ready(function() {
  4.     $("div#emodiv").emoticate({icon: ’smiley-icon’, replacediv: ‘list’});
  5.   });
  6. <% end %>
  7.  

Then the div that you identified in the jQuery call.

  1.  
  2. <div id="emodiv">
  3.   <img src="/images/emoticons/emoticon-0100-smile.png" id="smiley-icon">
  4.   <div id="list"> </div>
  5.   <select name="emoticons">
  6.     <option value=":)">emoticon-0100-smile.png</option>
  7.     <option value="|-(">emoticon-0106-crying.png</option>
  8.     <option value=";)">emoticon-0105-wink.png</option>
  9.     <option value=":(">emoticon-0106-crying.png</option>
  10.     <option value="(pt)">279.png</option>
  11.     <option value="(ct)">104.png</option>
  12.     <option value="(au)">342.png</option>
  13.     <option value="(eg)">emoticon-0116-evilgrin.png</option>
  14.     <option value=":*">emoticon-0109-kiss.png</option>
  15.   </select>
  16. <div style="clear: both;"></div>
  17. <p>
  18.   <textarea id="comment_1"></textarea>
  19. </p>
  20. </div>
  21.  

What is going to happen is that the select and options will be changed to a UL list with the icon images. When an emoticon is clicked it will be inserted into the text area within the div. (The id for the textarea does need to be unique).

And here is the plugin.

  1.  
  2. (function($){
  3.  
  4.   $.fn.emoticate = function(options){
  5.  
  6.     var defaults = ({
  7.       replacediv:   ‘replaceme’,
  8.       image_path:   ‘/images/emoticons/’,
  9.       speed:        500,
  10.       icon:         ’smiley’
  11.     });
  12.     var options = $.extend(defaults, options);
  13.  
  14.     return this.each(function() {
  15.       var select = $(’select’, this);
  16.       var area = $(‘textarea’, this);
  17.       var icon = $("#" + defaults.icon, this);
  18.  
  19.       var emo =‘<div class="emoticon-box"><ul>’;
  20.       $(‘option’, select).each(function () {
  21.         var option    = $(this);
  22.         var emocode        = option.val();
  23.         var title    = option.text();
  24.         var link = $.fn.emoticate.emoticlick(title, emocode, defaults.image_path);
  25.  
  26.         emo += ‘<li>’
  27.             + link
  28.             + ‘</li>’;
  29.       }); //end option
  30.       emo += ‘</ul></div>’;
  31.  
  32.       select.remove(); //get rid of the select to make way for emotification
  33.       $("#" + defaults.replacediv, this).html(emo); //put the emotification HTML in the right div
  34.       $("#" + defaults.replacediv, this).hide(); //hide the emoticons
  35.      
  36.       var listdiv = $("#" + defaults.replacediv, this); //reset the var so it will work in the icon click.. this probably could be done better
  37.  
  38.       //bind the link for every a tag that is in the replaced div
  39.       $(‘a’, this).bind(‘click’, function() {
  40.         $.fn.emoticate.insertme(area.attr(‘id’), $(this).attr(‘id’));
  41.         return false;
  42.       }); //end bind
  43.  
  44.       //click the icon
  45.       $(icon, this).bind(‘click’, function (){
  46.         listdiv.show(defaults.speed);
  47.       });
  48.  
  49.       //function to click anywhere to hide the emoticons
  50.       $(document.body)click(function (){
  51.         listdiv.hide(defaults.speed);
  52.       });
  53.  
  54.  
  55.     }); //end select
  56.  
  57.   }; //end function
  58.  
  59.  
  60.   $.fn.emoticate.emoticlick = function(id,emocode, image_path){
  61.     return ‘<a href="#" id="’ + emocode +‘"><img src="’ + image_path + id + ‘"></a>’;
  62.   };
  63.  
  64.   $.fn.emoticate.insertme = function(areaId,text){
  65.     var txtarea = document.getElementById(areaId);
  66.     var scrollPos = txtarea.scrollTop;
  67.     var strPos = 0;
  68.     var br = ((txtarea.selectionStart || txtarea.selectionStart == ‘0′) ?
  69.     "ff" : (document.selection ? "ie" : false ) );
  70.       if (br == "ie") {
  71.       txtarea.focus(); var range = document.selection.createRange(); range.moveStart (‘character’, -txtarea.value.length);
  72.       strPos = range.text.length;
  73.     }
  74.     else if (br == "ff") strPos = txtarea.selectionStart;
  75.  
  76.     var front = (txtarea.value).substring(0,strPos);  
  77.     var back = (txtarea.value).substring(strPos,txtarea.value.length);
  78.     txtarea.value=front+text+back;
  79.     strPos = strPos + text.length;
  80.       if (br == "ie") {
  81.       txtarea.focus();
  82.       var range = document.selection.createRange();
  83.       range.moveStart (‘character’, -txtarea.value.length);
  84.       range.moveStart (‘character’, strPos);
  85.       range.moveEnd (‘character’, 0);
  86.       range.select();
  87.     }
  88.     else if (br == "ff") {
  89.       txtarea.selectionStart = strPos;
  90.       txtarea.selectionEnd = strPos;
  91.       txtarea.focus();
  92.     }
  93.     txtarea.scrollTop = scrollPos;
  94.   };
  95.  
  96. })(jQuery);
  97.  

Or you can download it here.

Dec 20 09

Installing passenger on ubuntu has some issues

by admin

I followed the instructions on the Ubuntu site and the modrails site and everything would install fine but I could never get passenger to serve pages to apache.

Passenger assumes the permissions of the default apache user. And if you don’t set up your default user as www-data when you install Ubuntu Passenger wont have permission to run the app.

Open up /etc/apache2/envvars and change the www-data user and group to match your default user and group and you should be set.

Oct 30 09

Watch the whitespace

by admin

I have been spending the last hour wondering why this doesnt work.

Post.find_by_sql["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]

Its because it needed to be like this:
Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]

yeah, you need that whitespace there.

Oct 25 09

Confusing signs

by admin

I like taking pictures of confusing signs. It reminds me to be more mindful about the messages I put on clients websites.

On a fishing trip to Yellowstone I came across these signs.

Bears drive?

Bears drive?


does excluded mean not allowed, or excluded from the not allowed list?

does excluded mean not allowed, or excluded from the not allowed list?

Oct 11 09

Making a sortable, dynamic grid

by admin

GridI came up against an interesting challenge on a current project. This was actually pretty fun to figure out. Here is what I came up with.

I needed to display a grid with columns and rows that had information in each cell. The information in the cells needed to be dynamic, or change based on a UI perspective.

Also, if there were more than 10 rows in a column, the remaining cells needed to wrap to the next column.

This is definitely a job for a helper so I wrote these methods for the helper to render this sortable, dynamic grid. So far it seems to be holding up when rendering grids of various columns and rows.

  1.  
  2.   def my_grid
  3.     @my_data =
  4.     @my_data += ‘<table>’
  5.     @my_data += ‘<tr>’
  6.    
  7.     num = 1
  8.     #this starts a new column for each category
  9.     @columns.each do |col|
  10.       cell = Cell.find(:all, :conditions => [‘category_id = ?’, col]) rescue nil
  11.          
  12.       count = cell.size
  13.       item = 0
  14.       itemtotal = 1
  15.       cell.each do |row|
  16.         #if this is the 0 item start a new column
  17.         if item == 0
  18.                 @my_data += self.start_col
  19.         end
  20.        
  21.         score = row.get_my_score(row.id, @grid, @user).to_s
  22.         @my_data += self.list_item(score, row, itemtotal)
  23.        
  24.         #if this is the 9th item, or is the last of the cells, close the column and reset count
  25.         item += 1
  26.         if item == 10 || itemtotal == count
  27.                 @my_data += self.end_col(num)
  28.                 num = num.to_i + 1
  29.                 item = 0
  30.         end
  31.         itemtotal += 1
  32.       end
  33.      
  34.      
  35.     end
  36.    
  37.     @my_data += ‘</tr>’
  38.     @my_data += ‘</table>’
  39.     #return @my_data
  40.   end
  41.  

  1.  
  2. def start_col
  3.     @start = ‘<td valign="bottom"><div style="position: relative; bottom: 0px; display: block;">’
  4.     @start += ‘<ul style="vertical-align: bottom">’
  5.     return @start
  6. end
  7.  

  1.  
  2. def end_col(num)
  3.     @end = ‘</ul>’
  4.     @end += num.to_s
  5.     @end += ‘</td>’
  6.     return @end
  7. end
  8.  

  1.  
  2. def list_item(score, row, item)
  3.     @list = ‘<li class=key_’+ score +‘>’
  4.     #some stuff here…
  5.     @list += ‘</li>’
  6.     return @list
  7. end
  8.  
Oct 3 09

What I think of my hackitosh netbook

by admin

The pros and cons of my new hacintosh netbook… Or as a friend of mine calls it… hackintrash.

First, why did I get a net book?
My MacBook Pro is just over 4 years old now. It have pretty much been working night and day since I have owned it. It’s my 3rd 15″ mac book. Its a great machine and I have more than got my monies worth, but now it is starting to show signs of wear and tear. Taking my netbook to the office is a good way for me to get some more mileage out of the macbook.

Next, the cons. There aren’t many if you don’t have unreal expectations of the smaller processor. But there are a few things to be aware of. Not everything will work flawlessly. Things like bluetooth, ethernet port and the VGA port may have some issues. The webcam will probably work, but the mic might have an issue.

Most of the netbooks on the market at the time of this writing have less powerful processors and video cards. So, if you’re thinking of running photoshop, think again. Don’t even think about Final Cut.

And, for what ever reason, my netbook likes to have a kernel panic about every 3 and a half days if I dont shut it down from time to time. But I like just closing the lid and putting it to sleep, so i put up with the panics.

Now the pros. For 90% of what I used my macbook for around home and the office, the netbook has been pretty seamless. Now with 3 computers in 3 locations, that I need to work on day to day, keeping information synced would seem a daunting challenge. A few key apps and services are key for me to keep things together.

All of my web dev projects for work, freelance and personal are now kept on SVN. Beanstalk has been a perfect companion for my netbook. I can keep my web development work in sync with all my computers very easily.

To keep documents synced up between all these machines I use DropBox. And all my email is web based so Im covered there.

And to keep all my notes, thoughts and ideas in sync, Evernote is perfect.

Its great moving from machine to machine with virtually no difference in my workflow.

Go to these sites for more information:
http://gadgets.boingboing.net/2008/12/17/osx-netbook-compatib.html
http://www.wired.com/gadgetlab/2009/05/eight-months-with-a-hackintosh-netbook-conclusion-fantastic/
http://osxdaily.com/2009/09/19/the-ultimate-resource-for-building-a-hackintosh-netbook-or-hackintosh-desktop/

Sep 30 09

Don’t get your servers wet

by admin

This is a sad site. 3 new xserves, rusted out.

09302009137Exposed racks are inexpensive… until the ceiling leaks. Needless to say the replacements are in a enclosed, hepa filtered, locked case. And there is a huge ceiling pan with a drain.

I will say, that I was impressed that the servers were still running and serving sites with standing water inside the case. Amazing!