Archive

Author Archive

sudo gem install -v=2.3.2 –include-dependencies –no-rdoc –no-ri rails

August 17th, 2010 dwright No comments

maybe, I'll remember this now.
Gem installation takes too long, and I use the online docs

uninstall specific versions of rails
$ sudo gem uninstall -v=2.3.5 rails
Successfully uninstalled rails-2.3.5
$ sudo gem uninstall -v=2.3.8 rails
Successfully uninstalled rails-2.3.8

Categories: ruby, ruby on rails Tags:

Mac OS X mkdir: /home/test: Operation not supported

August 10th, 2010 dwright No comments

Hmmm, trying to create a directory under '/home' on a Mac?

Well, Apple doesn't want you to (with good reason, automounter owns this dir, which makes it easier to do NFS mounts and such) so you shouldn't muck with it but if you really just 'have to do it', here is how you can.

Basically: Edit /etc/auto_master and remove or comment out the line that starts with "/home".

example:
sudo vim /etc/auto_master

before:

# Automounter master map
+auto_master            # Use directory service
/net                    -hosts          -nobrowse,hidefromfinder,nosuid
/home                   auto_home       -nobrowse,hidefromfinder
/Network/Servers        -fstab
/-                      -static

after:

# Automounter master map
+auto_master            # Use directory service
/net                    -hosts          -nobrowse,hidefromfinder,nosuid
#/home                   auto_home       -nobrowse,hidefromfinder
/Network/Servers        -fstab
/-                      -static

to have the change take effect without a reboot:
sudo automount

mkdir /home/test
ls -l /home/
total 0
drwxr-xr-x 3 root admin 102 Aug 10 11:33 test

NOTE: I wouldn't do anything 'important' with this directory as it's easy to forget you altered this and an upgrade will plow over this directory, removing all data. (this dir is also not included in any Time Machine backups.

Categories: Mac OSX Tags:

undefined method `destroy’ for #Svn::Ext::Core::Apr_pool_wrapper_t

August 10th, 2010 dwright No comments

If you receive this error Mac OSX Snow Leopard and you have Installed the newest Svn libs (binaries) from collab net. i.e. http://svnbinaries.open.collab.net/servlets/ProjectDocumentList (http://www.collab.net/downloads/community/)

this fix worked for me: (taken from http://www.jroller.com/carlossg/entry/using_subversion_ruby_bindings

",... you need to remove the preinstalled subversion, install the newer one from Collabnet, and move some files around.

mv /Library/Ruby/Site/1.8/svn /Library/Ruby/Site/1.8/svn.bak
mv /Library/Ruby/Site/1.8/universal-darwin9.0/svn /Library/Ruby/Site/1.8/universal-darwin9.0/svn.bak
ln -s /opt/subversion/lib/svn-ruby/svn /Library/Ruby/Site/1.8/svn
ln -s /opt/subversion/lib/svn-ruby/universal-darwin/svn /Library/Ruby/Site/1.8/universal-darwin9.0/svn

Categories: Mac OSX Tags:

Subversion Ruby Bindings Gem Library

August 9th, 2010 dwright No comments

I had a need to access a svn repository programmatically from Ruby and couldn't find a subversion client for ruby in a gem type of reusable library, so I took a shot at writing one. It is just a simplified API (released as a gem) on top of the subversion-ruby bindings. I also started a web app version, which is in progress but has basic functionality at this point.

http://rubygems.org/gems/svn_wc - svn_wc provides programmatic access to basic svn functions, utilizing the Subversion Ruby Bindings, exposing their functionality in a simplified way
source: http://github.com/dvwright/svn_wc

http://rubygems.org/gems/svn_wc_tree - svn_wc_tree provides an Web Application Front End GUI to a working copy of an remote SVN Repository. (rough and in progress)

Maybe this/these will be useful for someone else as well.

Categories: ruby Tags:

Reinstall MySQL on Mac OSX Snow Leopard (keeping past data)

August 6th, 2010 dwright No comments

Reinstall MySQL (Community Server) on Mac OSX Snow Leopard (or How to downgrade to an older version of MySQL)

First, Read (or glance at this, especially if you are also using Rails/Ruby) upgrading-to-snow-leopard recommends using the 64 bit mysql

UPDATE:Do yourself a favor, if on Snow Leopard install the 64 bit (x86_64) MySQL server version! (The *.dmg) (then if you have to build the mysql ruby gem, do so with:
sudo env ARCHFLAGS="-arch x86_64" && sudo gem install -v=2.7 mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include

Overview:
Recently, I upgraded from Leopard to Snow Leopard, for the most part it was quick and easy (about 1 hour, completely unattended)

Afterwards, I did however have to reinstall several apps, notably for me was MySQL.

I have 2 databases which I need for local development, which are fairly large and take a while to populate, so I wanted to maintain this data if possible. Unfortunely, since I did not dump the data before upgrading my OS and now, could not start the mysql server, there was no way to do the 'standard' mysql dump.

In my case, I was previously using a dev snapshot of the db, I wanted to install the same version to minimize issues. If it worked I can always do a proper data dump and upgrade to another version then.

Steps
Here is what I did which worked for me. (you will need to use the Terminal application for this, see 'Utilities')

In my case, I am using, mysql-5.4.3-beta-osx10.5-x86, your version may (probably will) be different, adjust the command to fit your version.

Back up past data
cd /usr/local
sudo tar -zcvf mysql-5.4.3-beta-osx10.5-x86.tar.gz mysql-5.4.3-beta-osx10.5-x86/
sudo mv mysql-5.4.3-beta-osx10.5-x86.tar.gz ~/Documents/

the first command places you in the correct directory
the second makes a tar archive (compressed) copy of the database files.
the third moves that into you home 'Documents' directory (for safe keeping)
(now your data should be safe and sound)

Now Uninstall Mysql: (be careful with these commands, you cant 'undo' them)
(taken from: uninstalling-mysql-on-mac-os-x-leopard pasted here for convenience)
To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:
• sudo rm /usr/local/mysql
• sudo rm -rf /usr/local/mysql*
• sudo rm -rf /Library/StartupItems/MySQLCOM
• sudo rm -rf /Library/PreferencePanes/My*
• edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
• rm -rf ~/Library/PreferencePanes/My*
• sudo rm -rf /Library/Receipts/mysql*
• sudo rm -rf /Library/Receipts/MySQL*

The last two lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version
• sudo rm -rf /var/db/receipts/com.mysql.*
(above needed to work for Snow Leopard)

Now Install Mysql:
Now go find a *.dmg of the same version, you were running. (you will probably have to grab it from an archive somewhere, I found mine here: http://archive.sunet.se/pub/databases/relational/mysql/Downloads/MySQL-5.4

Install both the mysql package and startup items package.

they should have installed with no issues.
try starting the server.

to start:
Library/StartupItems/MySQLCOM/MySQLCOM start
to stop:
Library/StartupItems/MySQLCOM/MySQLCOM stop

if that doesn't work (those are text files, you can 'less' them)
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop

test a login
mysql -uroot (Enter)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.4.3-beta MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Great, that means it's working, Now, stop the database.

Load past data into New database
Get you old data into this instance.
cd ~/Documents/
sudo tar xzvf mysql-5.4.3-beta-osx10.5-x86.tar.gz

(this will uncompress your past data into this dir)

sudo mv mysql-5.4.3-beta-osx10.5-x86/data/YOURDB /usr/local/mysql-5.4.3-beta-osx10.5-x86/data/
sudo mv mysql-5.4.3-beta-osx10.5-x86/data/YOUR_OTHER_DB /usr/local/mysql-5.4.3-beta-osx10.5-x86/data/

All Done
now start your db, all should be well. (you will have to recreate any other mysql users you had)

Categories: Mac OSX, MySQL, ruby, ruby on rails Tags: ,

perl fun with encoding cp-1252

July 30th, 2010 dwright No comments

perl/ruby fun with encoding cp-1252 (windows encoding)

(In each of the following, you can substitute, 'perl' for 'ruby' and the example will work as well.)

[dwright~(74)]$ perl -le 'print "\xe2\x80\x9c"'

[dwright~(77)]$ perl -le 'print "\xe2\x80\xa6"'

[dwright~(78)]$ perl -le 'print "\xe2\x80\xa2"'

[dwright~(79)]$ perl -le 'print "\xe2\x80\xa3"'

[dwright~(80)]$ perl -le 'print "\xe2\x80\xa4"'

[dwright~(81)]$ perl -le 'print "\xe2\x80\xa5"'

[dwright~(82)]$ perl -le 'print "\xe2\x80\xa7"'

http://www.eki.ee/letter/chardata.cgi?ucode=2023
decimal: ‣
UTF-8 (e2, 80, a3)
[dwright~(79)]$ perl -le 'print "\xe2\x80\xa3"'

http://www.eki.ee/letter/chardata.cgi?ucode=2024
decimal:․
UTF-8 (e2, 80, a4)
[dwright~(80)]$ perl -le 'print "\xe2\x80\xa4"'

http://www.eki.ee/letter/chardata.cgi?ucode=2026
decimal: …
UTF-8 (e2, 80, a6)
[dwright~(83)]$ perl -le 'print "\xe2\x80\xa6"'

[dwright~(85)]$ perl -C2 -le 'print "\x{2026}"'

[dwright~(90)]$ perl -C2 -MHTML::Entities -le 'print decode_entities("…")'

[Notice, above is an Ellipses and not '...']

Axe smart quotes from string: (when string is unicode (perl's UTF8 flag is set)
i.e
after something such as:
use Encode qw/decode/;
$s = decode("UTF-8", $s);

$s =~ s/\x{201A}/,/g; # 0x201A Single low-9 quotation mark
$s =~ s/\x{201B}/`/g; # 0x201B Single high-reversed-9 quotation mark
$s =~ s/\x{201C}/"/g; # 0x201C Left double quotation mark
$s =~ s/\x{201D}/"/g; # 0x201D Right double quotation mark

Categories: UTF-8, Unicode, perl Tags:

disable smart quotes in WordPress

July 30th, 2010 dwright No comments

By default WordPress uses 'smart quotes' (a Microsoft invention).

When using WordPress for blogs which have code examples, or excerpts meant to be input into a computer, the smart quotes are not desirable.

for example:
A blog entry, which was input such as:

perl  -le 'print length "ñëâôàæø"'

will display as:

perl  -le ‘print length “ñëâôàæø”’'

when cut and pasted from the blog will produce this (when run from the command line):
$ perl -le ‘print length “ñëâôàæø”’

Unrecognized character \xE2 at -e line 1.

Here is a fix, which will correct all displayed blog entries (past one as well), since it's a plugin.

Alternatively, you can also install this plugin: http://wordpress.org/extend/plugins/raw-html/ (which can do other things as well, such as let you insert 'raw html' into your posts.

i.e. To prevent a part of your post or page from being filtered by WordPress, wrap it in <!--start_raw-->...<!--end_raw--> or [RAW]...[/RAW] tags

references:
http://www.fourmilab.ch/webtools/demoroniser/
how-to-turn-off-wordpress-smart-quotes
http://journal.brokenclay.org/wp_archives/2004/06/15/smart-quote-fix/

Categories: Uncategorized Tags:

easiest jQuery image preview (on select)

July 30th, 2010 dwright No comments

problem space:
You have a select list of images (as urls, or can access the url through an
id, or some such way). When you select a new image you want to see the image
'previewed'.

<script type="text/javascript">
  jQuery(document).ready(function() {
    $('#images_link').change(function(){
      var img_url = $('#images_link :selected').text();
      $('#preview_image').html('<p><img src="'+img_url+'"/></p>');
      $('#preview_image').dialog();
    });
  });
</script> 

<body>
  <label for="images_link">Image</label><br />
    <select id="images_link" name="images[link]">
      <option value=""></option>
      <option value="1">http://example.com/images/foo.png</option>
      <option value="2">http://example.com/images/bar.png</option>
      <option value="3">http://example.com/images/baz.png</option>
    </select>

 <div id='preview_image'><p></p></div>
</body>
Categories: jQuery Tags:

easiest jquery hover image re-sizer

July 27th, 2010 dwright No comments

problem space:
you have some images on an html page which display as 'thumbnails' (i.e reduced size images), when you hover over them with a mouse, you want them to expand to full size (or larger, anyway).

For this example, pretend you are one of those lazy people who does not want to make a smaller 'thumbnail' image for every image you have (hey, it happens ;) (although, I think there are some online services which can do this [generate thumbnails on the fly] in real time now)

So, anyway, you cheat by using the full size image and setting a height and width smaller values

<html>
<head>
<script type="text/javascript">
  jQuery(document).ready(function() {
    $(".img-frame").hover(
      function() {
        $(this).removeAttr('width');
        $(this).removeAttr('height');
      },
      function () {
        $(this).attr("width", 50);
        $(this).attr("height",  50);
      }
    );
  });
</script>
</head>

<body>
<img src="foo.png" height="50px" width="50px" class="img-frame"/>
<img src="bar.png" height="50px" width="50px" class="img-frame"/>
<img src="baz.png" height="50px" width="50px" class="img-frame"/>
</body>
</html>

I think the above is self-explanatory, but I will give a synopsis anyway.

When you 'hover' (mouseover) an image with the 'img-frame' class set, the width and height attributes are removed, the image will display at full size, when you 'mouseoff' the image, the height and width are restored to their original value.

there are many variations you could do here, you could limit the hover size,
(instead of $(this).removeAttr('width');, you could use $(this).attr("width", 200);) for example

Categories: jQuery Tags:

Vi Mode in Readline Applications

July 2nd, 2010 dwright No comments

I found this awhile ago and it's proved very handy, I am repeating it here because it took me awhile to figure out where I found it again.

Vi Mode in Readline Applications

If you find that you do like using vi editing mode (set -o vi), add 'set editing-mode vi' to your .inputrc, and vi mode will work in any readline based client, eg psql, irb, mysql, python shell, unfortunately does not work on the cpan shell. (I guess it doesn't' use readline, not that big a deal)

orig ref: http://dailyvim.blogspot.com/2009/06/vi-mode-in-readline-applications.html

Categories: linux, vim Tags: