Ramblings

May 27, 2010

Ruby, OS X, MAMP, MySQL, do_mysql and getting it installed

Filed under: install, mysql, osx, ruby, tip — michaelangela @ 7:33 am

This took a lot of time. In hopes that this will help someone else, I add this link.

How to install the MySQL/Ruby gem on Mac OS X Leopard

Here’s the situation. I have MAMP. For legacy reasons my current MAMP 1.7.2 is in a custom directory. I use ruby. In particular I wanted to use DataMapper in a project with ruby. I wanted to use it with MySQL. That requires do_mysql. It just would not install with all kinds of errors. Well one in particular. It complained of possibly missing headers or libraries. After a long search the above link surfaced from the depths of Google. It almost worked for me. Everything but the last command actually. So for me, the command I ended up using is something like:

sudo env ARCHFLAGS=”-arch i386″ gem install mysql — –with-mysql-dir=/Applications/MAMP_1.7.2/Library –with-mysql-include=/Applications/MAMP_1.7.2/Library/include/mysql –with-mysql-config=/Applications/MAMP_1.7.2/Library/bin/mysql_config

This is OS X 10.5.8 Leopard

Advertisements

December 14, 2009

Simpler Java asynch IO with JBoss Netty

Filed under: cool, education, groovy, java, mina, netty, tip — michaelangela @ 3:57 am

I don’t know what this will look like since I am using Scribfire which doesn’t like to deal with code very well… that should be a standard disclaimer on this site! I try to clean it up as best I can within a short timeframe though. 🙂

I recently wrote about some Java libraries/code that would simplify asynch socket communication. I hadn’t looked far enough! Looking for references on Groovy asynch programming I came across this:

ojug meeting tue oct 20th — grails and/or netty : Omaha Java Users Group

Netty has been getting some press as a potential successor to Apache’s Mina asynchronous I/O framework for building low-level custom protocols. E.g. previously I’ve used Mina to talk binary to a card processing system.

And checking in to MINA and Netty yielded some nice info. There is a great little tutorial on writing a simple server in MINA 2. But the simple Netty TelnetClient example was exactly what I was looking for. Specifically:

TelnetClient xref

TelnetClientHandler handler = new TelnetClientHandler();
bootstrap.setPipelineFactory(new TelnetPipelineFactory(handler));

For those more experienced with Java, I hadn’t seen a simpler way to assign what is essentially an event handler. The code I had seen before required using slots and keys or other bits that seemed a bit more verbose than needed. But then again that could be simply because of my inexperience in the language at this point. Seeing this immediately made sense coming from AS3. It’s not a closure like in AS3 where each event gets a method call of some sort, named or anonymous, but just a class that handles the events.

TelnetClientHandler xref

@Override
public void messageReceived(

ChannelHandlerContext ctx, MessageEvent e) {
// Print out the line received from the server.
System.err.println(e.getMessage());

}

Sweet and simple. Once that’s assigned you can go into your “do forever” loop and do the writing that needs to interact with the server.
TelnetClient xref

// Read commands from the stdin.
ChannelFuture lastWriteFuture = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (;;) {

String line = in.readLine();
if (line == null) {

break;

}
// Sends the received line to the server.
lastWriteFuture = channel.write(line + ‘\n’);

// If user typed the ‘bye’ command, wait until the server closes
// the connection.
if (line.toLowerCase().equals(“bye”)) {

channel.getCloseFuture().awaitUninterruptibly();
break;

}

}

Even without Groovy this is really straightforward. I guess a Groovy implementation of Netty would reduce all of this to like 3 lines of code? Heh. 🙂

December 11, 2009

Is it possible to add groovy code to a java project?

Filed under: groovy, java, tip — michaelangela @ 3:47 am

Yes and it’s not so crazy either. The fact that you can swap the extension of a Java class to .groovy and continue to build with it in groovy is pretty cool, too.

Wabi Sabi Software: A Tutorial for Adding Groovy to a Java Project

The steps are basically
a) download and install the Groovy GDK
b) add a how-to-compile-groovy task to your Ant build.xml (the task is included in the GDK)
c) add the groovy-all.jar file to your library path
d) add the groovy-plugin to your Eclipse project
e) enable groovy-nature in your Eclipse project
f) write a Groovy class and use it.

Overall this should take no more than twenty minutes or so. One of the really cool things is that once you have a Groovy class you can use it from your Java classes just like any other class…your Java code has no idea its using a class written in Groovy.
Now lets look at the steps listed above in cookbook manner.

December 8, 2009

sudo visudo and environment variables like JAVA_HOME

Filed under: bash, java, osx, tip — michaelangela @ 3:26 am

I was trying all sorts of incantations to get JAVA_HOME set. None worked. OS X. Bash. .bashrc, .profile, etc., etc. Turns out the following is the problem, and the solution.

sudo, JAVA_HOME and Mac OS X [Article] « elc technologies

The problem is that JAVA_HOME doesn’t get passed to sudo, so sudo cannot access it. I remembered two solutions to fix this problem, one by telling the env to keep the variable and the other by switching to root user and exporting the variable there.

So, the first solution is to make the JAVA_HOME variable available to sudo, first export it and then run sudo visudo and add the following line to it:

Defaults    env_keep +="JAVA_HOME"

[update]
In the end, it had to go in /etc/profile for it to take as noted below. Maven (mvn -v) just would not show the new version of java otherwise and builds done with maven would fail because they targeted the wrong version as well.

Compiling Java 1.6 projects using Maven on Mac OS X

You can declare this either as a one time export in your current shell above, in /etc/profile as I normally do or in any other startup file of your choice. Afterwards be sure to refresh your shell before you try again. This can be done either by closing your current terminal window and opening a new one or by sourcing whichever file you’ve put the above information into.

source /etc/profile

In order to make sure that it has taken effect one can output it in the shell as follows.

echo $JAVA_HOME

If it shows nothing then the shell has not picked up your change.

December 7, 2009

AS3 Iteration with valueobjects in collections

Filed under: as3, tip — michaelangela @ 7:28 am

Using valueobjects might be overkill for some really simple things that only require a couple of values where you can just throw an object together quickly. Unless speed is an issue where they strongly typed values have a lower overhead than plain objects (as I understand it). Unless you’re in a big app and you just made a change to some code and suddenly all your other uses of that object break and you’re not aware of it and null exceptions start flying and…. I digress. Having them in a set collection is great, too, for similar same reasons, plus the added ability to create convenience functions specific to that particular data set. But this post says it all very well with code to boot.

AS3: Collection, ValueObject, & Iterator

A while ago I blogged about converting Collection and Iterator classes to AS3 since storing data in ValueObjects has become a regular practice in my coding. I really like how VOs are strongly typed and how you use a Collection to hold all the data together nicely. I am working on a project right now that allowed me to see even better uses for these things so I added a couple of simple (but helpful) methods to my Collection class (most notably the ability to add an item at a specified index as well as output the data currently existing in the collection easily) and created a base ValueObject class that allows you to easily output the data in that VO.

Important to also note is the package move. I’ve moved everything into a com.reintroducing.data package as I believe this fits better with what these classes are actually doing. There is also interfaces for ValueObject and Collection as well.

Just so you don’t have to flip back and forth between posts, I’ll post the classes and data here with a little explanation of each.

Speeding up workflow with FDT

Filed under: cool, eclipse, tip, tool — michaelangela @ 6:40 am

Some of the following work with FlexBuilder (soon to be FlashBuilder) as well since they are both based on Eclipse.

FDT – Customize Your Workflow- Touch My Blog

We all come across things that end up saving us lots of time when used over and over again. If you use FDT, there are countless options available to enhance a development work-flow. Here are some of mine:

November 30, 2009

Eclipse PathTools and a 503 error for the DTD

Filed under: eclipse, tip, tool — michaelangela @ 10:17 am

The problem I was having with PathTools (which was only alluded to here) is that Eclipse simply failed to install it… after I installed it once already. Either way the error got me digging into my Eclipse config.

The error message was a seemingly unrelated “Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/html4/loose.dtd”. For whatever reason, Eclipse is actively trying to request and parse the DTD. According to the post below, the W3C gets hammered by these requests and have been actively blocking them with 503’s which is what I got when trying to install PathTools.

W3C Systeam’s blog – W3C’s Excessive DTD Traffic

A while ago we put a system in place to monitor our servers for abusive request patterns and send 503 Service Unavailable responses with custom text depending on the nature of the abuse. Our hope was that the authors of misbehaving software and the administrators of sites who deployed it would notice these errors and make the necessary fixes to the software responsible.

  • Pay attention to HTTP response codes

    This is basic good programming practice: check your return codes, otherwise you have no idea when something goes wrong.

This happens when trying to install PathTools from the update site given on the Google project page:

http://pathtools.googlecode.com/svn/trunk/PathToolsUpdateSite/site.xml

However searching Eclipse Plugin Central site for the plugin shows a different update site:

http://pathtools.googlecode.com/svn/trunk/PathToolsUpdateSite/

And it also shows that it needs Eclipse 3.4+. My install of FlexBuilder 3.2 is running Eclipse 3.3. And THAT turns out to be the crux of my problem. I installed it once (during some late night coding session no doubt) but it never showed up. It did show up in the “Manage Configuration” dialog though. So I disabled it, then deleted the related plugin and feature files, and to make sure it can actually install without the DTD error I tried again. It installed correctly except for the fact that it still doesn’t show up since this Eclipse is too old. So I’ll try a previous version to see if that’ll get it running here. Either that or see if I can get FlexBuilder running with 3.5.

[update]
I got Flex running on Eclipse 3.5 as per the directions noted in the line above. I’ll have to put it through it’s paces to see if it’s behaving correctly, but PathTools is oh very nice. 🙂

[update2]
Unfortunately the issues noted at the link for installing FB3.2 and Eclipse 3.5 happened for me as well so it’s back to my current working install for now.

EploreFS for Eclipse

Filed under: eclipse, tip, tool — michaelangela @ 9:44 am

In this post I mentioned trying to get PathTools to work and that I’d look into it later. That’s for another post upcoming in just a moment. But for now, there is ExploreFS mentioned below. It gets you to the folder where the asset is stored so you do still have to navigate to it but that’s still easier pretty good. Once it’s highighted (and you’re on a Mac) you can of course use Quicksilver to copy the highlighted file’s path to the clipboard.

Eclipse Plugins – RSS View, ExploreFS, and FreeMem

Eclipse Plugin: ExploreFS
ExploreFSExploreFS is a tiny plugin (~6KB) that opens a selected file in the folder of the native file manager. It adds “Explore in File System” to the context menu of Eclipse’s package explorer, resource navigator, and other views. Windows, Mac OS X, and Linux are supported.

Dealing with floating point numbers in AS3

Filed under: as3, math, tip — michaelangela @ 8:08 am

I’ve only seen it happen occasionally but the utility functions here and also that posted by Troy further down look quite helpful.

Floating-point errors got you down? – Josh Talks Flash

Many developers will never encounter issues when floating-point math fails to return the correct result. Every once in a while, when you’re expecting to see a number like 10.1 in your trace panel, you might actually see 10.1000000001. This isn’t a specific issue with Flash either. By it’s very nature, any sort of calculation with floating-point numbers can result in tiny, nearly insignificant errors anywhere in modern computing.

November 24, 2009

Revealing an asset in Eclipse in the Finder

Filed under: automation, cool, eclipse, tip — michaelangela @ 3:35 pm

So my previous post about using PathTools isn’t working at the moment but the tip below does get the file open in Finder (well Pathfinder in my case). External Tools can obviously be quite powerful.

In eclipse, reveal current file in filesystem – Stack Overflow

Great tip. On Mac OS X, replace the location with /usr/bin/open and the arguments should be just ${container_loc}. – zvikico Jul 22 at 5:27

Quicksilver + pbpaste + pbcopy

Filed under: automation, cool, osx, tip, tool — michaelangela @ 3:07 pm

After seeing the following post, many possibilities came to mind.

Notes: Pretty print XML

But working with XMPP and SAPO Broker, I’m always copy&pasting XML from one place to the other and it would be nice to format the XML snippet sitting in the clipboard.

This pipe does the trick quite nicely:

pbpaste | xmllint –format – | pbcopy

I wrapped this into a script, called x-xml-format-clipboard and now its just one command away from gratification.

In the end I came up with a couple that I use a lot after searching the web. The possibilities are endless but these are neat for me. In Eclipse I can’t easily transform text unless I install AnyEdit which I have on other systems. But I haven’t yet on this one. So the transforms are simple:

upper to lower:

#!/bin/bash

pbpaste | tr '[:lower:]' '[:upper:]' | pbcopy

lower to upper:

#!/bin/bash<br /><br />pbpaste | tr '[:upper:]' '[:lower:]' | pbcopy<br />

remove blank lines:

#!/bin/bash<br /><br />pbpaste | grep -v '^

These are made into executable scripts on my path which I can then pull up with Quicksilver. So now to remove blank lines, I select the text in any editor, trigger Quicksilver, highlight the command, press enter, and paste it back. Nice. Of course this means that you can do just about anything with this kind of thing as discussed here. | pbcopy
These are made into executable scripts on my path which I can then pull up with Quicksilver. So now to remove blank lines, I select the text in any editor, trigger Quicksilver, highlight the command, press enter, and paste it back. Nice. Of course this means that you can do just about anything with this kind of thing as discussed here.

Automating Firefox… from within…

Filed under: cool, dev, firefox, functional testing, testing, tip, tool — michaelangela @ 2:34 pm

This is just crazy cool. Just noting for future use.

MozLab | hyperstruct

MozRepl

Connect to Firefox and other Mozilla apps, explore and modify them from the inside, while they’re running.

Execute Javascript, play with browser GUI, sneak into HTML pages, examine functions and variables, redefine them on the fly, hot-fix bugs, …

November 23, 2009

Flash and Salesforce: HTTP POST using PHP but with no access to cURL

Filed under: cool, php, salesforce, tip — michaelangela @ 11:53 pm

Have a client who needs some Flash to HTTPS webservice functionality. Flash and HTTPS are a difficult pair when not on the same host and all the policy files aren’t in place. The simple solution is a proxy. But this particular client’s webserver doesn’t have cURL. What to do? Making streams with a custom context is really simple. Looks good too. In the end I didn’t use fopen, stream_get_contents, etc. though. I used file_get_contents.

HTTP POST from PHP, without cURL – Evil, as in Dr.

I don’t think we do a very good job of evangelizing some of the nice things that the PHP streams layer does in the PHP manual, or even in general. At least, every time I search for the code snippet that allows you to do an HTTP POST request, I don’t find it in the manual and resort to reading the source. (You can find it if you search for “HTTP wrapper” in the online documentation, but that’s not really what you think you’re searching for when you’re looking).

And there is also a note on php.net about doing this with https.

So in the end my code looked like (no closing php tag intentional):

<?php
$url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
$data = $_POST;
$data = http_build_query($data);
$result = do_post_request($url, $data);
echo $result;

function do_post_request($url, $data, $optional_headers = null)
{
   $params = array('http' => array(
                'method' => 'POST',
                'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
	                . "Content-Length: " . strlen($data) . "\r\n",
                'content' => $data
             ));
   if ($optional_headers !== null) {
      $params['http']['header'] = $optional_headers;
   }
   $ctx = stream_context_create($params);
   $response = file_get_contents($url, false, $ctx);
   if ($response === false) {
      throw new Exception("Problem reading data from $url, $php_errormsg");
   }
   //var_dump($response);
   return $response;
}

October 12, 2009

BASH command line history

Filed under: cool, linux, tip, tool — michaelangela @ 4:16 pm

Sweet. The page has more tips as well like getting partial stuff from your history. I don’t know how much of this will work on OSX but it’s still neat to see.

Access to command line history in BASH

To activate those two commands, add this to your .bashrc file:

bind ‘”\e[A”‘:history-search-backward
bind ‘”\e[B”‘:history-search-forward

Now you can easily summon any command from the history by typing the command and pressing Up arrow. You might continue pressing Up arrow until you find the command instance you wish to execute again.

September 22, 2009

Messy XML that needs a quick clean up?

Filed under: automation, cool, tip, tool, xml — michaelangela @ 12:26 am

Really neat and nifty. This is for when you have those one liner strings of XML in a log or something (like CharlesProxy’s response pane) and you want to view it all nicely. Normally CharlesProxy does an excellent job… for well formatted XML. At least some code I was working with really wasn’t well formatted and even the noble Charles just gave me a oneliner. xmlling cleaned it right up though. Nice.

Notes: Pretty print XML

In case you didn’t know, you can pretty print XML with the xmllint command line tool that comes with libxml2, and its installed by default with Mac OS X.

September 21, 2009

Printing from OS X 10.5 to a Canon Pixma MX330 shared on a Windows XP box

Filed under: cool, mac, osx, tip, tool, windows — michaelangela @ 6:34 pm

Since there are no drivers available to print to a shared Pixma MX330 that I am aware of, I have been unable to print to the printer. And because there are no drivers that allow the DNS-323 to host the Pixma MX330 as well, that was out, too.

The following did work though, except actually printing to the printer. In step 5, instead of doing IP > LPR over IP, I used Advanced > Windows type, and used the smb://username:password@ip_address/GhostcriptLPR and that has been working today so far.

This process will ask for your XP disk to install a couple of specific DLLs when you get to adding the new services.

How to Use a Printer Attached to a Windows XP Computer in Mac OS X

This document gives a detailed explanation of how to set up an HP DeskJet 722C printer that is attached to a Windows XP computer so that the printer can be used by a Mac OS X computer on a local area network (LAN). If your printer is slightly different, or you have a different version of Windows, or you’re using a different Unix than Mac OS X, you’ll have to adapt these instructions with your own creativity.

September 9, 2009

And an example on how to use JSFL

Filed under: automation, cool, flash, tip, tool — michaelangela @ 1:14 am

And this is cool, too. I’m always looking for productivity tips and this is very cool. It really opens up a lot of possibilities.

deleteaso » Fix Textfields JSFL

Today Seb was having some issues when dealing with embedded fonts – read his post. He came up with some ActionScript ways to get around it. Well another way would be to use JSFL. A couple of my team members at Fuel Industries wrote the following JSFL script. It goes through your library and searches out any dynamic textfields. Once it finds one it makes sure it’s on a whole pixel, turns the auto kern off, embeds “UpperCase, LowerCase, Numerals, Punctuation” characters, and makes it not selectable. But you could make it do pretty much anything you can through JSFL.

Update multiple bitmaps at once in Flash CS3

Filed under: cool, flash, tip, tool — michaelangela @ 1:13 am

Just wanted to keep a note on this for future reference. Very helpful!

onebyoneblog » Blog Archive » Flash UI Panel to Edit the Properties of Multiple Bitmaps

Basically, it’s just as I described – you highlight multiple Bitmaps in your .fla’s library, adjust the settings (allow smoothing, lossy/lossless, jpg compression quality), then click on the “execute” button and – presto – all items are instantly changed.

September 2, 2009

Should I check it or not! Uncheck it, and leave a note

Filed under: as3, flash, flex, tip — michaelangela @ 12:12 am

Since this is being developed for others, the final concensus is to uncheck it and leave a README.txt that explicitly says so. 🙂

Accessing named MovieClips placed on the stage in Flash CS3 while staying true to OOP best-practices « dispatchEvent()™

I happen to agree with Sarah that the best way to work is to uncheck the checkbox and declare all of your variables yourself. This is the only way that really enforces good practices when you are using classes behind your MovieClips in the library.

September 1, 2009

More on strongly typed references to timeline instances

Filed under: as3, cool, flash, flex, tip — michaelangela @ 11:58 pm

And this states the issue well in a short sentence. Developing for Flash outside of the Flash IDE breaks into two camps if the “Automatically Declare Stage Instances” is checked or not. The solution mentioned below is another way (closer to the way I do) to get a reference not only as a movie clip but as a specific class object. That’s helpful when you’re adding linkages to your symbols with external classes.

Re: [Flashcoders] Automatically Declare Stage Instances andinheritance.

I think unchecking that box is the best way to handle this, but the other options presented are useful for working around these issues. My main worry seems to be incompatibilities with people who may write code using the box checked, which it is by default. It seems that this checkbox forks all AS3 code into two exclusive camps. I hope I make the right choice. 😦 C

On Mon, May 12, 2008 at 3:58 AM, Cor <[EMAIL PROTECTED]> wrote:
> This will do the trick:
>
> private var okButton:SimpleButton = getChildByName(‘okButton’) as SimpleButton;

Other helpful shortcuts and tips for both os x and windows

Filed under: osx, tip, tool, windows — michaelangela @ 11:55 pm

Mostly notes for reference. Although Ctrl+F2 doesn’t seem to work without first going somewhere else like the dock with Ctrl+F3. Odd… maybe something I broke already. 🙂

Keyboard – XvsXP.com, Mac OS X vs. Windows XP

Most special characters can be typed with the help of the option key. Use option when typing a letter or symbol, and OS X will substitute a special character. For instance, option-shift-4 will type a cent sign instead of a dollar sign.

In addition, typing characters with accents is extremely easy. Type option-e, for example, and OS X will insert a forwards accent, highlighted in yellow. Then, type another letter — an “e,” “a,” etc. — and OS X will place that letter below the accent mark. This lets you easily type words like “résumé.” You can use other option key combinations to type other accents as well, letting you easily type letters like “ñ” (option-n + n) or “ü” (option-u + u).

Getting strongly typed objects from flash cs3

Filed under: as3, cool, flash, flex, tip — michaelangela @ 11:53 pm

I have done this for AS2 using Flash Develop, and something similar to it using PureMVC for a Flash CS3 project developed within FlexBuilder, but it’s nice to see it “approved” of sorts. The issue? How do you access objects on the timeline in a strongly-typed manner. The blog post itself describes the situation well and this solution handles it well enough for me. The good thing is with this solution is that the movie clip name can of course change in the FLA and you only have this to update to keep it in sync.

Flex and Flash Developer – Jesse Warden dot Kizz-ohm » Blog Archive » Designer vs. Developer: Declaring Stage Instances

I think I’ve seen this approach in the Essential ActionScript 3 book and I’ve used it.

1. Leave the option turned on, so the Flash IDE will generate all the properties.
2. For every thing I need to refer and use code hinting I would do the following:

private function get scroller { return this[“mcScroller”]; }

or something like this.

Other helpful shortcuts and tips for both os x and windows

Filed under: osx, tip, tool, windows — michaelangela @ 10:53 pm

Mostly notes for reference. Although Ctrl+F2 doesn’t seem to work without first going somewhere else like the dock with Ctrl+F3. Odd… maybe something I broke already. 🙂

Keyboard – XvsXP.com, Mac OS X vs. Windows XP

Most special characters can be typed with the help of the option key. Use option when typing a letter or symbol, and OS X will substitute a special character. For instance, option-shift-4 will type a cent sign instead of a dollar sign.

In addition, typing characters with accents is extremely easy. Type option-e, for example, and OS X will insert a forwards accent, highlighted in yellow. Then, type another letter — an “e,” “a,” etc. — and OS X will place that letter below the accent mark. This lets you easily type words like “résumé.” You can use other option key combinations to type other accents as well, letting you easily type letters like “ñ” (option-n + n) or “ü” (option-u + u).

OS X list of os x shortcuts

Filed under: cool, osx, tip — michaelangela @ 10:45 pm

Many I knew, some I didn’t. But the author is right that it helps. The Tips & Tricks page has some nice notes as well.

Dan Rodney’s List of Mac OS X Keyboard Shortcuts & Keystrokes

I like to figure out the fastest way to do things. I hope these shortcuts will help you become the power user that lies within. These keystrokes should work on Mac OS 10.6 Snow Leopard and 10.5 Leopard (many also work on 10.4 Tiger). I add new shortcuts as I find them, so check back! I’m still exploring Snow Leopard and will be updating this page as I discover new goodies.

Another note on debugging Flash with Flex

Filed under: flash, flex, tip, tool — michaelangela @ 9:40 pm

Neato. Just making notes but it’s good to see. 🙂

BUT REMEMBER TO SET “Permit debugging”. Drove me crazy for a while until I saw I hadn’t… 😛

Big Bad Code » Blog Archive » Using Flexbuilder to edit and debug Flash Applications

Now you have the full power of Flexbuilder to code and debug and you still have the Flash IDE to layout movieclips and rapidly prototype things. Sweet.

Older Posts »

Blog at WordPress.com.