Scott Swezey The more I learn, the less I know.

25Jul/104

Dealing with Heroku startup lag

Update: I think I may have been fairly high on cold medicine when I wrote this. It really isn't a good way to go about handling anything, unless maybe your site is just a playground with no traffic. Let's be honest here, if you have real visitors coming to your site: just pay for more dyno's and don't mess with silly hacks like this. </update>

So, if you haven't tried Heroku yet, you really should. It has got to be the most awesome way to deploy and manage a rails app that I have ever seen. But this article isn't another Heroku review, instead it is my attempt at getting around one minor pitfall with Heroku.

The problem? If you're site doesn't get much traffic, and you are on the free "1 dyno" plan, your dyno's (rails processes) tend to go offline. This means your next visitor sees your page load for a few seconds before they see anything. It's not terrible, but I wouldn't call it ideal, either.

But I think I have found a simple solution to ease the "pain" of this "problem." (Sarcasm intended): Heroku serves static files from varnish... no delay on those while we wait for the rails app to start.

 

 

So what's happening? Someone comes along to www . my cool site . com, but there are no active dyno's. As expected, they get sent to index.html, which fires off an AJAX request to the rails app. As soon as it gets a successful result, it redirects the user to the /home path within my rails site. Assuming there are active dyno's, this all happens very quickly. If the dyno's are off, a loading message fades in and a few seconds later they get redirect.

I know it isn't perfect... but it should work until my site gets busier and I can pay for more dyno's.

20Jun/100

iterate through each child association of a active record class

I came across this today while trying to find a better way to deal with error messages in rails. IMHO, it is genius and just what I was looking for.

12Apr/100

Killing Trackback Spam

So I have had repeated issues with one site repeatedly sending mass trackbacks about a post of mine that they stole. Until now, askimet has been marking them as spam and I then manually delete them, but I am sick of clearing several of these per day. So I am trying out some plugins to fix this problem. The first wordpress plugin I am trying is WP-Spam-Free and it looks good. It was easy to install, seems fully featured, and claims to have some pretty advanced methods at detecting and blocking this stuff without interfering with worthwhile comments and trackbacks.

Anyways, stay tuned for an update on how well this works out.

Tagged as: No Comments
4Apr/100

Today on Twitter: Cool background generator + great resources from smashingmag

As ususal, I woke up today with a good number of tweets from last evening, and as usual @smashingmag posted some really great ones. Check them out:

2Apr/100

How to create a ruby gem

Yehuda Katz (@wycats) just did a fantastic write up on making gems and how to use .gemspec properly. Be sure to check it out on his blog: http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/

Tagged as: , , No Comments
27Mar/100

Today on Twitter: Top 25 most dangerous programming mistakes

I saw this great read in my twitter feed today. It's a good read up for anyone just getting into programing, and even more season programmers may get something from it. Check it out.

http://www.codinghorror.com/blog/2009/01/top-25-most-dangerous-programming-mistakes.html

26Mar/100

Problems Upgrading Magento Commerce to 1.4.0.1?

Protip for anyone trying to upgrade to the latest Magento. I had all kinds of issues with packages conflicting with one another and basically stopping me from upgrading anything. A short bit of googling later I learned that the issue could be with custom themes that require old versions of specific packages. So I looked and saw that I had a default_blue and default_iphone theme that weren't included with the regular magento install. So I removed those, refreshed and was able to upgrade Magento in no time.

It was definitely much easier than xcart!

24Mar/100

Kickstarting mongrel with 503 errors.

So, I'm a total sucker for punishment, and thus I run a very small rails (mongrel) app on my website (shared host). Every once in a while, the mongrel app dies for some reason (server was rebooted, power loss, etc), and the PID file isn't removed. So I tried an experiment. I told apache to use a PHP file for 503 errors (Service Unavailable -- or what my users see when apache tries to rewrite to a mongrel that isn't there). Then I wrote setup the PHP file to try and start rails, and email me if it fails. Read below for all of the PHP code and shell files used.

19Mar/101

Increasing the PHP CLI Memory Limit

I recently ran into an issue where a client's cron job refused to run because of fatal errors and running out of memory. The default php.ini allowed up to 128M, but the CLI just wouldn't accept that.

It turns out that there is an easy solution:

10Jan/100

Random SQL query in Ruby on Rails

SQL doesn't seem to have a good standard on the name for a random function. In my app, I wanted to select a record that had not been updated recently. So I went with a ORDER BY 'last_cache DESC, RAND()'

This would be perfect if I was using MySQL... But I use SQLite for development on my local machine. SQLite wants the function to be called RANDOM(). To make matters worse, Rails doesn't seem to have a database agnostic way to go about this.

So for the short term, I went with a little hack to get things working everywhere. In my config/development.rb I defined SQL_RANDOM_FUNCTION = 'RANDOM()' and I also defined it in my config/production.rb file as 'RAND()'. Then in any query I need the random function, I just concat SQL_RANDOM_FUNCTION to the string and it all works.

It isn't really ideal, but it isn't like my DB will randomly change to PGSQL overnight, without me knowing.

Tagged as: No Comments