Archive for the ‘Programming’ Category

Setup Wildcard Subdomain on Localhost for Development Work without /Etc/hosts TomFoolery

Posted 05 Mar 2010 — by admin
Category Programming

Step 1.

Open up your browser and visit http://www.hexxie.com. You can also go to anything.hexxie.com and everything.hexxie.com, which will resolve to your local machine (assuming it’s localhost at 127.0.0.1).

How it works

Super simple. I just pointed hexxie.com and *.hexxie.com to 127.0.0.1, which is everyone’s localhost address. If you’re on Rails just append the port number as usual. http://hexxie.com:3000 or on Django http://hexxie.com:8000. Or you can always fire those guys up on port :80 with sudo ./script/server -p80 for Rails
or sudo django-admin.py runserver 80

To set up your own just configure DNS to point your domain to 127.0.0.1 for the IP address. No more futzing with /etc/hosts

Originally got this tip from http://tbaggery.com/2010/03/04/smack-a-ho-st.html who has created his own service at smackaho.st

The word “Hexe” is German for “Witch”. I have a dog named “Hexxie” after the German word and that is the origin of the domain name hexxie.com, in case you’re wondering.

Installing Scala on Mac OS X Leopard

Posted 01 Oct 2009 — by admin
Category Programming

I followed the instructions from here http://arvinderkang.com/2009/09/01/installing-scala-on-snow-leopard/ but I used version 2.7.6 (rather than .5) I installed scala under /usr/local/scala so I had to include it to my path. Type

vim .bash_profile
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/scala/scala-2.7.6.final/bin:$PATH"

Now to download and install…

curl -O http://www.scala-lang.org/downloads/distrib/files/scala-2.7.6.final-installer.jar
sudo java -jar scala-2.7.6.final-installer.jar

This will launch an installer. Just follow the instructions and when it asks for the destination folder, remember that it’s in /usr/local/scala
Simple as pie!

Regular Expression for finding absolute URLs

Posted 15 Sep 2009 — by admin
Category Programming

Regular Expression for finding absolute URLs in a bunch of text… like a log file.

/(http:(.*?)\s)/

Send Mail in Ruby with a Pony

Posted 19 Aug 2009 — by admin
Category Programming

Great little gem that let’s you quickly and easily send out mail from your ruby scripts.

gem install pony

require 'rubygems'
require 'pony'

Pony.mail :from=>"me@example.com", :to=>"you@example.com", :subject=>"hello", :body=>"world"

Double Click Event Using Prototype Javascript Framework

Posted 11 Aug 2009 — by admin
Category Programming

Super simple to get double click “desktop” like functionality out of Prototype! For some reason, googling it doesn’t yield many useful results. http://www.google.com/#hl=en&q=double+click+in+prototype+javascript&aq=f&oq=&aqi=&fp=peEfEjG9pWY :(

Anyway, here is the code

	document.observe('dblclick', function(){
		alert("Hello World");
	});

Gem Information with Gem List

Posted 06 Aug 2009 — by admin
Category Programming

If you want to get version information about a gem the easiest way to do it is with this command

gem list 

For example

gem list activemerchant

will output the activemerchant versions I have installed. You can pass only part of the name like

gem list a

get the names of all gems (and versions) that start with “a”. There are a lot more options so here is a link to the gem command reference http://rubygems.org/read/chapter/10

The commands here are useful if you’ve installed a gem but the version you’ve configured in your environment.rb file is different. To quickly grab the right version, this command is pretty handy.

Fixing MySQL for Rails 2.2 Development on Mac OS X

Posted 03 Jul 2009 — by admin
Category Programming

Oh what trouble Rails 2.2 and MySQL (on Mac OS X) can be. Rails, as of version >= 2.2, no longer comes bundled with the MySQL adapter. This means you’ll need to install it yourself, but it appears that the gem for installing it is also broken.

This will fail

gem install mysql

What you need to do is tell the gem which MySQL to use. I installed MySQL with mac ports, http://macports.org , so I need to specify this when I run the installation command.

gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

Check out an earlier post explaining how to install MySQL with mac ports http://seanbehan.com/programming/installing-sphinx-search-engine-on-mac-os-x-or-ld-library-not-found-for-lmysqlclient/

You’re not out of the woods yet. Rails needs to know the location of the socket it uses to connect to the MySQL server. I created a symbolic link to the location Rails normally looks for this socket. You could specify the location of the socket in the config/database.yml file, however, then you’ll need to do this with each of your applications.

ln -s /private/tmp/mysql.sock /opt/local/var/run/mysql5/mysqld.sock

If there is an easier way to get MySQL back for Rails on Mac OS X please let me know. I’d love a quick fix to this problem.

Installing Sphinx Search Engine on Mac OS X… or ld: library not found for -lmysqlclient

Posted 30 Jun 2009 — by admin
Category Programming

If you are trying to install Sphinx on Mac OS X, it will most likely fail. The current version of MySQL bundled with Mac OS X is not supported and therefore, it will spit out the error message because it can’t find the correct libraries.

 ld: library not found for -lmysqlclient

There is a quick solution to the problem -upgrade mysql! You’ll need Mac Ports installed, available at

http://macports.org/

Run the command

sudo port install mysql5

This will not destroy any existing data from your previous MySQL installation. The mac port installation will take a while, and it will appear as if it is just hanging. It’s not. It just takes a while. I clocked it at 15 minutes on a relatively fast network connection. Drink a cappuccino!

After you have the upgrade you’ll need to download Sphinx available at:
http://sphinxsearch.com/downloads.html (latest stable) and build the Sphinx engine from source like so:

wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar xzvf sphinx-0.9.8.1.tar.gz
cd  sphinx-0.9.8.1/
./configure --with-mysql-libs=/opt/local/lib/mysql5/mysql/
--with-mysql-includes=/opt/local/include/mysql5/mysql/
make
sudo make install

Much thanks to this post b/c I spent forever trying to get the bundled version of MySQL linked properly:

http://www.fozworks.com/2008/9/5/rake-installation-of-sphinx-in-mac-osx

Protect a Directory with Apache, .htaccess and httpasswd

Posted 24 Jun 2009 — by admin
Category Programming

Apache comes with a command line utility called “htpasswd”. This utility will generate a username and password that you can use to authenticate against using a .htaccess file. Just run the utility like so:

  htpasswd -c /path/to/your/password/directory/and-your-password-filename jane_doe_username

This will prompt you for a password/confirm password.

Keep in mind that this will not create a user on the system. It will just create a password and associate it with a string, that is the username you’ll use to authenticate in your request.

Then you’ll need to add a .htaccess file in the directory that you want to protect, and in that file place the following code.

AuthType Basic
AuthName "Restricted Directory"
AuthUserFile /path/to/your/password/directory/and-your-password-filename
Require user jane_doe_username

Remember that the /path/to/your/password/directory will need to be owned by Apache. on Ubuntu, it’s by default the www-data user. Change ownership like so:

 chown -R www-data:www-data directory

Dot htaccess file for wordpress installation (.htaccess)

Posted 11 Jun 2009 — by admin
Category Programming

Login to your wordpress installation and scroll to and click the second to last link set “Settings”. You’ll need to configure wordpress to handle your new links as “permalinks”. Make a selection and copy the code into your .htaccess file. Wordpress will attempt to do this for you, but only if your webserver can read/write to the directory.

Permalink Settings

Permalink Settings

Permalink Settings

Permalink Settings

Add the .htaccess file to the root directory of your wordpress installation if wordpress informs you that it can’t get it to work. The file should be named “.htaccess” (w/out quotes).  This is a ‘hidden’ file so if you don’t see it, run the ls -lha command which will list all the files in the directory including hidden files.

Next you’ll want to edit your VirtualHost file. I used the default VirtualHost under /etc/apache2/sites-available/default You’ll need to make one modification to this file. You need to tell it to allow overrides, since we’ll be giving the .htaccess file the right to change configuration options. We need to change the line that says AllowOverrides None to AllowOverrides All

AllowOverrides All

AllowOverrides All