Mostrar / Ocultar Avisos

Author Archive

Simple Syntax for XML node looping

Sometimes I really hate .Net blogs and C# websites.

All I wanted was the syntax to loop through the nodes of an XML document. You’d think that would be easy to find.

WRONG!

My search lead me to many long winded dissertations on to use XML for web services or someone’s home grown SAX implementation but no simple syntax that wasn’t buried in 1000 lines of code. Seriously, who is going to read 1000 lines of code in a blog post?

Anyway, I’ve distilled it below. I know it’s simple. But, I couldn’t find simple. Maybe my google skillz are lacking.

This code assumes you have “customer” nodes within your XML document and each customer has an attribute called “name”.

I realize the above code reassigns nodeValue each time through the loop, but I just wanted to show the syntax for retrieving an attribute value.

Installing ImageMagick and MiniMagick on Windows

I know this has been documented in other places so this is mostly for my own sanity. I want to use the attachment_fu plug-in by Rick Olson for my rails app to upload user avatars. I also want to resize the images and create a series of smaller thumbnails for use throughout the site.

Steps to install ImageMagick

  1. Download the Windows binary of ImageMagick. I used ImageMagick-6.3.5-4-Q16-windows-dll.exe
  2. Run the ImageMagick installer (The file you just downloaded) and accept the defaults.
  3. Open a command prompt to verify the install was successful
  4. Type >convert logo: logo.miff
  5. Type >imdisplay logo.miff
  6. If all went well with the install a little picture of blue wizard should appear.

Steps to install MiniMagick

  1. Install the gem from the command prompt with the command gem install mini_magick. You may be asked to install a few required dependencies. Say yes.
  2. Wait for the download and install to complete.

You should be good now to install attachment_fu, but that is beyond the scope of this article. Use the links below for more information

References:

Easy_Messages

A few weeks ago I was looking for Rails plug-in to provide simple messaging between users on a website. I came across Acts_As_Emailable by Matt Beedle. It was a good start but only gave me a model and some methods but I would still need to flesh out a controller and some views for my little private messaging project to be complete. The result of that work is this plug-in, Easy_Messages. I took Acts_As_Emailable as a starting point and added some controller methods, a few views, a helper, and some named routes.

Below are the installation instructions. This is my first Rails plug-in so let me know if you find something to refactor. I’m open to constructive criticism.

The code is hosted at RubyForge.

UPDATE I: I have created a new branch for 0.51, please use that one for the latest stable release

UPDATE II: I have removed the docs from branch 0.51 and placed them online here: http://easymessages.samuelschroeder.com. Now the generator should work like a charm

svn://rubyforge.org/var/svn/easymessages/branches/RB-0.51

The run the generator to create the model, migration, helper, and views.

script/generate easy_messages message account

Note: Easy_Messages assumes you have Acts_As_Authenticated installed with the defaults of a model named User and a controller named Account. And you must use the above line exactly. I have grand aspirations of making the generator fully dynamic someday but for now you’ll have to deal.

The generator should produce this output.

exists app/models/
exists app/helpers/
exists app/views/account
create app/models/message.rb
create app/helpers/easy_messages_helper.rb
create app/views/account/message_view.rhtml
create app/views/account/messages.rhtml
create app/views/account/send_message.rhtml
exists db/migrate
create db/migrate/###_create_easy_messages_messages.rb

Yes, I realize the redundant naming but once/if I get the dynamic generator going it would say ###_create_easy_messages_[MessageClassNames]s.

Now you have to do three manual changes to your code. First, add “easy_messages” to apps/model/user.rb.

Second, add “authenticated_commands” to apps/controllers/account_controller.rb.

Finally, you need to copy the named routes from vendor/plugins/easy_messages/config/easy_messages_named_routes.rb to config/routes.rb.

That should be it for the setup. So start your development server and point your brower to..

http://localhost:3000/account/inbox

There is also a complete RDoc listing in vendor/plugins/easy_messages/doc

Thanks to…

**Matt Beedle for writing and releasing Acts_As_Emailable.

** Rick Olson for writing and releasing the kick-ass Acts_As_Authenticated plug-in. It was been such a help when starting new projects.

Recommend Me

ASP.Net 2.0 and It’s Crazy Strict Install Order OR Be Careful When Installing Windows Components

Recently, I re-imaged my work machine and had to re-install all of my development tools. See here for a list. The one thing I did pay attention to was to make sure IIS was installed before Visual Studio and ASP.Net 2.0. If you do it backward you’re in for a fun filled day of error messages leading your nowhere. But, I did it right so I didn’t have to worry.

Then this morning everything went to hell and the very descriptive errors appeared and I spent a few hours googling and trying some of the Kbases at Microsoft. Nothing worked until I tried this which states the cause as…

The most probable cause for this error is that you must have installed Internet Information Services (IIS) after the installation of Microsoft .NET Framework 2.0.

But remember I did do it in the right order. Right? To make a long boring story short I was messing around with adding and removing some Windows Components from the Add/Remove Programs wizard and sowhere along the line it must have reinstalled part of IIS. Either that or the Network Gnomes are back.

The Simple Development Life

I recently installed a new hard drive on my development PC and thought it would be a good time to refresh my environment since it was suffering from Windows rot. Man, was that experience an eye opener as to the tools I use. Here is my alphabetized list.

I had to install more things like mail clients, printers, etc. as well. I just found it amazing at the number of tools I have to use in my professional life

Trying to Install Ruby Gems On Windows Though a Proxy Server

As with most larger businesses we have a corporate firewall which can lead to small annoyances, such as not being able to connect to rubyforge.org to download new gems. I recently had a new hard drive installed at work so, of course, I had to spend too much time reinstalling all of my development tools. Visual Studio 2005 takes way too long, btw.

Yesterday, I spent a good hour trying to get Rails with the standard gem install rails –include-dependencies. No luck due to our firewall. So I checked the ruby gems doc to find the correct install parameters. Still no luck. No matter which combination I tried to tell gem to look remotely through the proxy server it still wouldn’t go. So I asked the Google to help out and after reading through blog entries and message boards I stumbled upon one that talked about setting environment variables in linux. Well, I’m a windows guy so that didn’t help much but it gave me the idea to try and set a Windows environment variable. What the hell, right?

So, I added a User Variable for my account called http_proxy with the value of http://<proxyserveraddress>:8080, rebooted, ran plan old vanillia gem install rails –include-dependencies, and magically, it worked. See below the fold for details.

Read the rest of this entry »

Rails Rake Task for Resetting Your Database

The code below was given to me by Jonathan Viney when we worked on a Rails project together last summer and I’ve found it very useful. It is a rake task that will drop your developement dB and restore it based on your migrations and test fixtures. And as a good Rails developer I’m assuming you are using both.

Ugh.  I really need to find the bug killing my formatting in the SyntaxHighlighter.

How to Return a Generic .Net DataSet from the OpenEdge AppServer

Recently at work we needed a good, and easy, way to get data stored in our massive ERP system running an OpenEdge database to some of our .Net apps. At first, we just had ASP.Net connect directly to the database through ODBC which was good enough for our prototype. However, if we were to continue using this method it would require our Microsoft developers to learn a totally new and convoluted schema. Plus, they would have to use embedded SQL statements like…

** dbBroker and GetDataTableBySQL are part of our in-house framework but you can get the idea.

Embedded SQL is a code maintenance nightmare in my opinion. I’ve never liked mixing languages like this. Fortunately, OpenEdge comes with a better way call the Open Client Toolkit (sorry, no link). To quote the product literature the Open Client Toolkit is used “to generate .NET, Java, and Web services proxies for accessing business logic.” In our case we used it to create DLLs which we can reference in our Visual Studio projects.

[I will post another article on the specifics of using ProxyGen from the Open Client Toolkit to create .Net DLLs]

This process works much better as our MS developers can just make a call to the methods in the DLLs (I’ll write about this is another article) and not have to worry about the ERP’s crazy schema while our Progress developers can actually create real business logic procedures to aggregate data. The only problem with this scenario is that every time we want to add to the AppServer code we must regenerate the DLLs and make the .Net apps reference them properly. Talk about a pain in the ass.

Here is how we I solved this problem. Read the rest of this entry »