Browsing category: Code
Handy HTTP requests with Curb and Ruby

June 13th, 2010 in Web Development, Code

While working on one of the projects, i tried to find multi-purpose HTTP request class that can use different network interfaces/ip addresses with retry option (if connection slow or server not responding for some reason). Check out  a small class wrapper build on top of Ruby Curb, implemented as a module.

Continue reading...

Dan Sosedoff Software Engineer
MPMusicPlayerController "Hello World!" iPhone app with source code

June 3rd, 2010 in iPhone/iPad, Code

Once I was listening to iPod music player on my iPhone and I decided to look up lyrics for a song that was playing. What do you usually do in that case? Right, go to Google in mobile Safari (that takes 40 seconds, AT&T 3G hi!). What next? Navigate through several adful websites and finally, yes! The good one that has lyrics… Wait, now you’re listening to a completely different song, ughh.

So, the idea came to my mind, why not just to create an app that identifies a song that’s playing right now, no Google, no clicking around, just give me my lyrics right away when I open the app!

Continue reading...

Roman Efimov Software Engineer
Rails MongoDB logging on Heroku with MongoHQ

June 2nd, 2010 in Web Development, Code

I love Heroku but it only retains your last 100 lines of logs. To save your log output you need to store them outside of the service. MongoDB is "fantastic for logging" and Heroku's MongoHQ add-on makes it easy to spin up a MongoDB instance. The first step is to add the MongoHQ add-on to your app:

$ heroku addons:add mongohq:free

You'll need to include Ruby's MongoDB driver Mongo in your .gems file:

mongodb-mongo --source gems.github.com

Next, install the mongo_db_logger plugin in your rails project (script/plugin install git://github.com/peburrows/mongo_db_logger.git) and include the library in your application controller:

class ApplicationController < ActionController::Base
include MongoDBLogging

helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
end

And then, to actually use it in your different environments, add the following line to your app’s "config/#{environment}.rb":

config.logger = MongoLogger.new

Once you've installed the plugin you will have to hard code connection information into the plugin. I edited mongo_logger.rb to connect to MongoDB via Heroku's evironment variable MONGOHQ_URL

begin
@mongo_collection_name = "#{Rails.env}_log"

uri = URI.parse(ENV['MONGOHQ_URL'])

@mongo_connection ||= Mongo::Connection.new(uri.host, uri.port, :auto_reconnect => true).db(uri.path.gsub(/^\//, ''))

@mongo_connection.authenticate(uri.user, uri.password)

# setup the capped collection if it doesn't already exist
unless @mongo_connection.collection_names.include?(@mongo_collection_name)
@mongo_connection.create_collection(@mongo_collection_name, {:capped => true, :size => 10.megabytes})
end
rescue => e
puts "=> !! A connection to mongo could not be established - #{e.message} - the logger will function like a normal ActiveSupport::BufferedLogger !!"
end

To learn more about the mongo_db_logger plugin, read Phil Burrows' article "Rails Logging with MongoDB"

Abi Noda is a software engineer at Doejo and partner at OrangeQC, a software as a service company offering quality control systems for food and janitorial service companies.

Abi Noda Software Engineer
CSS/JQuery navigation with menu items enlarging on hover without shifting adjacent elements

May 29th, 2010 in Web Design, Web Development, Code

Synopsis: Menu (navigation items) are popping out (font-size increased) on hover without pushing/shifting adjacent menu items.
Bonus: How to center navigation of undefined width.

I strongly encourage all web developers (designers, front-end developers or whatever) to solve all layout problems with simple CSS. Only after several hours of lamentation, declaring an anathema on IE6 (and even IE7), you guys are allowed to use a lovely JQuery.

Continue reading...

Masha Safina Front End Developer & Email Marketing
Make IE6 respect width (CSS)

May 27th, 2010 in Web Development, Code

What we do to emulate min-width in IE-6? We apply this css to container:

.container {
height:auto !important;
height:200px;
min-height:200px; }

Here's what happens: IE 6 doesn't understand !important, IE6 doesn't know what min-height is, IE6 doesn't care about height or width, it enlarges the container, as much as needed to fit content (css for ie6: min-height = height). So we set auto height for normal browsers, then add height for ie6 (acts like min-height) and true min-height for normal browsers.

If IE6 doesn't respect the height/width, what do we do when we need it to have fixed Height/Width CSS properties?

Continue reading...

Timur Zaynullin Information Architect & Developer
Javascript router

May 16th, 2010 in Web Development, Code

Let's say you're building a 3-pages website:

  1. Home
  2. User Settings -> Profile
  3. User Settings -> Account


Pretty basic. However, on the front end, you need to implement the following using Javascript:

  • Home page should have a carousel;
  • User Settings -> Profile should perform an AJAX request immediately after page loads;
  • User Settings -> Account should have a carousel, however, this time you must use another carousel plugin.


A non-trivial task and it's really easy to mess up your Javascript code. So, how would you handle this?

Continue reading...

Roman Efimov Software Engineer
CSS: Subscript and Superscript quick snippet

May 3rd, 2010 in Code

Subscript (<sub>) and Superscript (<sup>) html tags act quirky, if not styled (different behavior from browser to browser):

  1. line-height is affected
  2. font-size varies crazy
  3. position is jumping.

Here's a small snippet (apply directly, keep out of reach of children. Don't swallow!):

sub { height:0; line-height:1; vertical-align:baseline; _vertical-align:bottom; position:relative; font-size:0.7em; }
sup { bottom:.5em; }
sub { top:.25em; }

God bless the variety of browsers, standards and IE6. Life would be boring without those.

Timur Zaynullin Information Architect & Developer
Magento: How to add noindex, nofollow robots meta tag or change meta title or description on certain pages

May 1st, 2010 in Web Development, E-Commerce, Code

Here's a small tip on how to modify title, description or add meta robots tag on any magento page via xml layouts or layout updates.

It's obvious how to do that for CMS or products page (on the Meta Data tab). There you can change Meta description or keywords. What about robots meta tag? or changing titles or description on checkout page? You would need to do in case:

  • you don't want google to archive your products prices, therefore you would need to add noarchive to robots meta tag
  • you don't want duplicate or unnecessary content in search engines, so you would use noindex, follow
  • you want to update checkout/contact/send a friend page meta description or title.

The approach is very simple...

Continue reading...

Timur Zaynullin Information Architect & Developer
Fixing MySQL error 13 on Mac OS X 10.6.x

April 19th, 2010 in Code

I'm using XAMPP on Mac OS X 10.6.3.
Once I had to restore permissions and after that I started getting this error, every time I try to access InnoDB tables:

Can't create file '/var/folders/aX/aXYUzZmoHruKTlzkbVLQdU+++TM/-Tmp-/#sql10aac_1_0.frm' (errno: 13)

The problem was that my.cnf disappeared from the "/etc" folder, for some reason. This file should contain path to a MySQL temporary storage.
So, I performed the following simple steps to fix the issue:

Continue reading...

Roman Efimov Software Engineer