Recent Posts by Ed Laczynski

Subscribe to Recent Posts by Ed Laczynski 26 posts found

Pages: 1 2

Oct 4, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Working with arrays of hashes

bump… anyone have any ideas?

 
Oct 1, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Working with arrays of hashes

Jeff Yes, excluding entries that don’t have a certain market would be a good way to put it

Also, you bring up a good point. It would be neat to know how to “group by” as well.

 
Sep 30, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Working with arrays of hashes

I have a project that I want to avoid using a database for, so I’ve chosen to use data stored as arrays of hashes to persist information about a collection of objects.


    @CaseStudies = Array.new
    @CaseStudies << { :product => Product::APPS, :market => Market::EDUCATION, 
                      :client_name => 'Foo', :logo => '/img/_logos/foo_logo.jpg' }
    @CaseStudies << { :product => Product::APPS, :market => Market::BUSINESS, 
                      :client_name => 'Bar', :logo => '/img/_logos/bar_logo.jpg'}
    @CaseStudies << { :product => Product::APPS, :market => Market::EDUCATION,
                       :client_name => 'Lorem Ipsum', :logo => '/img/_logos/lorem_logo.jpg' }
Now, I can figure out how to sort this list, but I am having the darndest time trying to filter it.
<% 
#this works but it is not sufficient. i want to filter by :market as well as sort
@CaseStudies.sort_by { |casestudy| casestudy[:client_name] }.each do |casestudy| -%>
<%= casestudy[:product]%><br/>
<%= casestudy[:client_name]%><br/>
<% end-%>
 

In the simplest case, I’d like to filter by :market. Any thoughts? So far I have a workaround by performing boolean logic on the display of each |casestudy|, but this can’t be the right way—it still requires an evaluation of data that I should be able to filter out from the get-go.

 
Sep 25, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / New Article: Converting from ASP.NET to Rails: Part 2

Hey fellow softies: I am writing a series of “Back to basic” concepts and conversion tutorials for .NET developers starting out with Ruby on Rails development.

http://idisposable.net/2007/09/25/converting-from-aspnet-to-rails-part-2/

Again, thanks to this blog for inspiring this series.

Best Ed

 
Sep 5, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Profanity Filter

Nathan I had a similar problem I wanted to solve.

I found this REST API that you might want to use. Combined with liberal use of memcached, it can be a speedy, low-footprint solution. If you persisted results in a database, you could eventually build up a sizable word list of your own.

http://www.webpurify.com/

 
Sep 1, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Being able to search for nearby items based on zip code

no problem xgamerx, good luck with your app..

 
Aug 30, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / ASP.NET -> Rails Equivalent for Placeholder.Visible?

No problem, I’ll see if I can figure out how to create read-only permissions for SVN.

The North Dakota page seemed to work for me, but it might be geonames (I use that to build the city list instead of keeping a local database of geography). I have to figure out how to persist that stuff to disk instead of memcached so that I don’t need to call it successfully more than once.

 
Aug 30, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Being able to search for nearby items based on zip code

[update: I blogged about this today, some more detail can be found here]

Geokit will solve your problem.

http://geokit.rubyforge.org/

What is GeoKit?

“Geokit is a Rails plugin for building location-based apps. It provides geocoding, location finders, and distance calculation in one cohesive package. If you have any tables with latitude/longitude columns in your database, or if you every wanted to easily query for “all the stores within a 50 mile radius,” then GeoKit is for you”

I use GeoKit on one of my apps. It is fantastic. Here is some sample code:

    include GeoKit::Geocoders

        def get_location( location )

       loc = MultiGeocoder.geocode( location )   # ask GeoKit to find your city

       return loc

    end

        def calculate
           start_city = get_location("Hoboken NJ")
           end_city = get_location("Los Angeles CA")
           distance = start_city.distance_to( dest )

           #thats it!  really?? yes.
        end

(sorry I can’t get code indentation to look right here – there are two methods, get_location and calculate)
 
Aug 29, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / ASP.NET -> Rails Equivalent for Placeholder.Visible?

Thanks again SoR.

I am almost “done” (as we all know, that is never true) with my first production Rails App.

Here is what I’ve managed to build:

  • a industry-specific search portal / quote engine using geonames, geokit, and ym4r gems/plugins for geography/mapping and yahoo local search api for data
  • memcached for storage of web service call output
  • pound/mongrel_cluster to serve it all on a linux VPS. performance tested with httperf and profiled with ruby_prof. i am probably going to move to ngnix/mongrel_cluster based on what i’ve been reading about ngnix
  • developed in TextPad on my MacBook Pro

All this from a .NET developer who hasn’t used an Apple since 1st grade LOGO. Thank you EVERYONE for your help in getting me going here.

I am going to post up some stuff here and on the blog to explain what I did, and hopefully make it better (first thing is to implement the block strategy for “placeholders” as described by Mike). Here is the site BTW: http://tinyurl.com/38gpl5

To that point, is there any software available that I can use to publish my code, without giving everyone access to my SVN repository? i was thinking i could add a link to my rails apps (this might catch on) that other rails developers could pick up to view source code…

 
Aug 22, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / ASP.NET -> Rails Equivalent for Placeholder.Visible?

Hey there everyone.

Does anyone know of a “best practice” Rails technique for hiding and showing things like page headings and content?

In ASP.NET, I used to do this:

<asp:Placeholder id="plHeading" Visible='<%# someExpressionThatReturnsBoolean %>' runat="server"> 
THIS IS A HEADING THAT SHOWS CONDITIONALLY 
</asp:Placeholder>

In Rails, I’ve been doing this:

<% if ( someExpression ) -%>    
HEADER
<% end -%></h2>

# OR 

<% if ( someExpression ) -%>
<%= someValue %>
<% end -%>


Is there a more elegant way to do this? When the expression that you are evaluating is long lke this: (params[:state] && @cities.total_results_count.to_i > 0 ) and you have to repeat it, it becomes somewhat cumbersome and I figured nothing should be cumbersome in Rails.

Thanks

 
Aug 22, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Mephisto vs. Typo vs ?

thanks.. since i am not going to be doing too much customization, i think i am just going to try out wordpress for now anyway.

 
Aug 17, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Mephisto vs. Typo vs ?

Softies – I want to convert my blog from blogger.com hosted to a Rails-powered blog that I can host myself.

Can you tell me the reasoning behind using Mephisto vs. Typo? Any other blog software that I should consider? thanks ed

 
Aug 14, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Tutorial: How to virtualize your PC and run it in Mac OS X

Hey everyone, I was inspired by the great sense of community here to give back a bit. This tutorial should hopefully demonstrate how easy it is to switch to a Mac and keep your existing .NET/Win32 environment available.

The conversion process took me a few hours (only about 20 minutes of actual “Screen time”) and was pretty painless. The biggest hurdle was calling Microsoft for phone activation of Windows.

Here is the article, enjoy:

http://www.idisposable.net/2007/08/tutorial-how-to-virtualize-your-pc-and.html

Thanks Ed

 
Aug 14, 2007
Avatar Ed Laczynski 26 posts

Topic: Rails on Windows / memcached on Win32

Yep, sure did.

I installed the cached_model gem AND the memcache-client gem as well (even though memcache-client is supposed to be a dependency of the former).

I’ll keep digging.

 
Aug 14, 2007
Avatar Ed Laczynski 26 posts

Topic: Rails on Windows / memcached on Win32

Hey guys, hope all is well. I’ve been hibernating with my Rails and Ruby books and have been able to put together some pretty neat little Rails apps. Thank you to everyone here who has helped me make the switch.

Anyway, I’ve come across a slight issue. I am developing on Mac OS X – I was able to successfully get memcached to work using the instructions here: http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails

Now I am deploying to a Win32 server. Everything works great, except that my app reports a “uninitialized constant [classname]:Cache” when attempting to use the cache. I assume all the code should basically “work” since I have memcache and the cache_model gem install on my Win32 instance.

Has anyone had any experience running Rails/Memcache on Win32?

 
Jul 24, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Newbie Question: Relating models (and therefore tables)

I am going to try to get out to the Essential Rails sessions.

So, I was able to build a simple Rails app, with your help, and it is starting to make sense to me now.

A few notes on your code sample:
<table>
  <% @products.each do |product| %>
  <tr>
    <td><%= @product.name %></td>  # should be product.name
    <td><%= @product.description %></td> # should be product.description
    <td><%= number_to_currency(@product.cost) %></td>
  </tr>
</table>
It was helpful to figure that out myself actually because I got the gist of variable scoping. @product would reference a class variable, which product isn’t, ergo an error is thrown.

I am still not convinced that I won’t ever need to use a stored procedure, but I am going to move forward.

My challenge now is figuring out how to order things but I can RTM for that.

Thanks again!

 
Jul 22, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Newbie Question: Relating models (and therefore tables)

Thank you, this makes more sense to me now. Yes, the tables I mentioned were for illustrative purposes only, you are correct I’d probably have LineItems.

First of all, thank you so much for your help. If I am asking too many questions, let me know and I’ll start RTFM’ing more. Since you guys “get” .NET and Ruby this is an invaluable resource for me, as I am not a noob development wise, only with Rails.

I have to stop thinking in SQL (which I love, by the way, I really do like SQL, so this isn’t going to be easy) and start thinking in ORM terms.

I am going to experiment with has_many and belongs_to and all of the other relationship semantics I’ve started reading about. I bought Agile Development in Rails and Programming Ruby too, so hopefully I’ll be up to speed soon.

Now, I am going to play devils advocate and say I have a very large group of tables, and for performance reasons it would make more sense in some specific instances to display my data directly from a synthetic view (I come across this every day; we have related tables with millions of rows and lots of index tuning).

How would I “bind” (for lack of a better word in Ruby-speak) a query that I’ve come up with on my own, without the help of ActiveRecord?

Secondary question, are there any resources that describe T-SQL equivalents for Ruby? I would probably want to use ActiveRecord as you’ve described for most of my stuff, but I am sure I am going to run into walls with the following scenarios:
  • doing GROUP BYs
  • subqueries
  • multiple-query transactions/ stored procedure calls etc…

If there isn’t, I’ll start writing one as I think this would be a good resource for fellow Softies.

Thanks again Jeff!!!

 
Jul 20, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Newbie Question: Relating models (and therefore tables)

Totally helps. Essentially, the do loop is equivalent to a repeater, the |product| is equivalent to DataSource.

Now, what about displaying data that isn’t easily bundled into a model?

For example, assume a database with two tables, products and orders. products has a primary key of product_id and a column called product_name. orders has a primary key of order_id and product_id , with another column called order_date

I want to show joined data with these two tables. In .NET/SQL Server I would do this:

string sql = “SELECT product_id,product_name,order_id,order_date FROM products INNER JOIN orders on products.product_id = orders.product_id”;

DataSet ds = SqlHelper.Execute( sql ); // psuedo code

myRepeater.DataSource = ds;

Since the ORM of ActiveRecord is per entity, and models tie only to that entity (I know I am probably missing some huge Ruby feature here) – how do I load / iterate over this type of data?

Also how do you do that code block formatting in the posts?

 
Jul 19, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Newbie Question: Relating models (and therefore tables)

Ok, I am just getting started with Ruby on Rails. Bought a MacBook Pro just to keep myself sequestered from Windows/.NET land.

My goal: I want to create a page that binds (for lack of a better term; remember I am a .NET guy) a set of data from related models/tables.

I used to accomplish this like this:
  • Create a DataSet
  • Fill that DataSet with a executed results of view/stored procedure/sql statement
  • Add a repeater WebControl to a web form
  • Fill in the ItemTemplate with DataBinding expressions

Now, I understand Ruby doesn’t have DataSets, Repeaters, or DataBinding expressions. And I am sure I could figure this out, but since you guys are ex-.NET’ers, I was hoping you could help me understand this quickly.

Thanks!

 
Jul 17, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Tempted to take the plunge, but have some questions first

Thanks Jeff.

I bought the MacBook Pro 15”, the juiced up model with the bigger harddrive (160GB) and 2.5Ghz (i think) processor. It is silly fast. I went for the bigger drive now because I am going to run VMWare Fusion with an image of my previous ThinkPad laptop.

Before I saw your reply, I thought about the Locomotive thing a bit more and decided it was too easy, and like you said, would likely lock me into a specific configuration. I wanted to get myself more familiar with the shell as well (coming from Linux back in the day, but without much practice lately).

I started following this tutorial: http://www.robbyonrails.com/articles/2007/06/19/installing-ruby-on-rails-and-postgresql-on-os-x-second-edition

I am about half way through now. I like postgreSql better than mySql personally anyway so I figured I would give it a shot.

 
Jul 16, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Tempted to take the plunge, but have some questions first

Ok – bought it, now I am going to dive in.

What first? Use apt-get (or whatever the Mac OSX equivalent is) and install everything manually? Or just use Locomotive? I am leaning on the latter method to get up and running quickly (in the spirit of Ruby development*)

http://www.idisposable.net/2007/07/ok-got-macbook-now-i-want-to-learn-ruby.html

  • i don’t personally know the spirit of Ruby development, but I hear he is great at parties
 
Jun 25, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Considering the switch to force myself to learn Ruby

thanks for the tip. I am going to order a macbook (pro probably) this week. I am sure i’ll be back for more help! thanks everyone…

 
Jun 21, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Considering the switch to force myself to learn Ruby

The keyboard and mouse are actually my major pain points right now with the switch.

I tried out some coworkers iBook and MacBook (black edition—very slick).

Two cringey things for me, someone who wrote his first program in LOGO on an Apple ][ in the early 80’s:

  1. I couldn’t figure out how to do the equivalent of alt-tab switching between windows in the same application. In other words I was in the mac browser and it popped a new window open. Alt-tab would keep switching me to another app, but not the other window. I learned F10 would bring up the other window but I had to hit another key to select it (right/left arrow). This could prove pretty annoying because I like to rock the keyboard.
  1. Right mouse button. Right mouse button. Right mouse button… I know, I know, “I’ll get used to it” “Plug in an external mouse” “Use the 4h club key” ... But I abuse my right-mouse button on my thinkpad. I’ll just have to get over it.

idisposable

 
Jun 20, 2007
Avatar Ed Laczynski 26 posts

Topic: Mac Switchers / Considering the switch to force myself to learn Ruby

Thanks for the information.

I can work my way around a command line, I actually started developing way back in college on Slackware Linux using vi.

Not that I want to go back to exclusive command-line oriented computing, but I am excited to get back into a bash-ish prompt.. Always makes you feel cool to whip things up that way.

I think I am going to take the plunge - now I am trying to decide - should I buy the black MacBook (will match nicely with my Thinkpad), or a MacBook Pro…

 
Jun 19, 2007
Avatar Ed Laczynski 26 posts

Topic: General Ruby/Rails Discussion / Rails and .NET

Bump this up, I’d love to know if anyone has done any cooperative .NET/Ruby apps.

Next page

Pages: 1 2