Thumbnails are missing when uploading new image
Posted on March 7, 2010 - Filed Under wordpress
Just a quick note - if You are experiencing missing thumbnails in image upload in Wordpress, then probably Your PHP installation misses php-gd module.
It is module by default installed on FreeBSD, but on Debian based Linux You have to add it by hand (apt-get install php5-gd).
I had to move my blogs to new, temporary host, with Linux on board instead of FreeBSD. Then I have noticed that when I want to publish new post I can only insert in it uploaded image in original size - not very handy. It took 15 minutes of googling and finally dive into wp-includes/media.php to check how these thumbnails are generated.
Popularity: 1% [?]
Ruby for Startups
Posted on January 19, 2010 - Filed Under RubyOnRails
I’ve found this interesting - a bunch of info from Mike Subelsky (creator of OtherInbox) how to use Ruby and Rails in challenging startup environment (each startup’s environment is challenging :)) )
Popularity: 4% [?]
Email verification - regexp
Posted on January 13, 2010 - Filed Under Ruby, Uncategorized, web
Many times before when I was supposed to collect emails from users I was googling to find some regexp to verify email syntax. At least I was aware that regexp challenging email address syntax is a bullshit ;) I was working few years as Unix sysadmin mostly on mail servers, so I had some idea how RFCs related to email are bloated ;) and contain so many exceptions ;)

Step back and think again. Image CC by Vivianna_love
From some time I do use following regexp to verify email address:
/.+@.+[.].+/
This should check if:
- there is @ sign somewhere inside
- at least one character is before @ sign
- at least 3 chars (with one dot) are after @ sign
Why such simple rules? I have found comment on StackOverflow, that man should step back and think why is checking email address?
I want just to help users and stop them making simple mistakes in theirs emails. Like not providing @ at all. Or eating .com in gmail.com address. And that’s it - email will be probably shortly after that verified with only reliable method via sending email to this address.
And if You insist to verify emails with more strict regular expression, please do remember that plus sign is perfectly valid character before @. Many regexps found via google are forgetting that…
Popularity: 5% [?]
Extracting fixtures
Posted on September 24, 2009 - Filed Under RubyOnRails
I’m still using fixtures. Shame, I know.
Why I do use them instead of Factory Girl or other solution like that? Well, fixtures can be much more closer to real data than mocks from Factory. How come, You ask? Fixtures are imaginary data exactly like mocks from other sources!
My answer is: that depends how You create fixtures. If You create them by hand, indeed they are disconnected from real world (like all mocks).

What is Your real data/mocks ratio? CC by hsing
But I prefer to extract fixtures from real (production) database. That way I can easily pick entries created by users which are edge cases. The only trouble is with creating fixtures. For some time I’m using modified extract_fixtures rake task. I have added some conditions to extracting process - SQL condition to select only particular records and adjusted syntax to recent rake.
This is useful especially when You are about to take over application code which has no tests. Extracting real data is quick way to start write integration tests (in such case they have are most efficient - time invested and application code coverage).
How to extract fixtures without pain?
Popularity: 12% [?]
Logger - simple, yet powerful Rails debugging tool
Posted on September 15, 2009 - Filed Under RubyOnRails, tips
I don’t know about You, but logs are for me most powerful debugging tool. Placing many logger.debug or logger.info can quickly provide info what is happening inside Rails application.
This approach is especially useful when something wrong is happening and trigger is unknown. Placing many logging directives can provide data for analysis what could be a reason.

CC by Admond
Default Rails logger has one serious flaw which makes logs on production sites almost useless - messages are not grouped in calls. If You have many processes of Rails running and logging to single file, some requests will be processed in parallel and You have log entries mixed. With default log format there is no way to say which entry is from which process.
Since Rails 2.0 we have ActiveSupport::BufferedLogger, but it solves other problem - number of disk writes and file locks - You can set after how many entries log will be flushed to disk.
AnnotatedLogger
Here comes AnnotatedLogger for a rescue. The idea is to take each message and prefix it with PID of Rails process. As long You don’t run Rails in multithread mode, this is unique ID which will make log entry distinguishable.
class AnnotatedLogger < Logger
def initialize *args
super *args
[:info, :debug, :warn, :error, :fatal].each {|m|
AnnotatedLogger.class_eval %Q|
def #{m} arg=nil, &block
pid = "%.5d:" % $$
if block_given?
arg = yield
end
super "%s %s" % [pid, arg.gsub(/\n/,"\n%s" % pid)]
end
|
}
end
end
Now in Rails::Initializer.run do |config| section of config/environment.rb define AnnotatedLogger as default Rails logger:
config.logger = AnnotatedLogger.new "log/#{RAILS_ENV}.log"
Of course You can add other data to log entries (timestamp?). Here is an example of log entries:
24551:Processing SearchController#processing (for [FILTERED] at 2009-09-15 15:11:24) [GET]
24551: Session ID: df260892836fc619ec666f894e7d8e88
24551: Parameters: {[FILTERED]}
24542: Airport Load (0.216460) SELECT * FROM [FILTERED]
24542: Completed in 0.24903 (4 reqs/sec) | Rendering: 0.01298 (5%) | DB: 0.22554 (90%) | 200 OK [FILTERED]
24551: Search Columns (0.004711) SHOW FIELDS FROM [FILTERED]
24551: Rendering template within layouts/blank
24551: Rendering search/processing
Without PIDs You would expect that Airport Load entry is part of SearchController#processing for session with ID df260892836fc619ec666f894e7d8e88. In reality this is output from processing different request.
What else?
This how I do deal with logs from Rails application. Do You have other ideas how to make logging more usable not only in development environment?
PS
I have just other idea - probably You could use BufferedLogger with disabled auto flushing and patch ActionController to flush manually all entries after request was processed - then all messages would be dumped in single block.
Popularity: 16% [?]
older entries »


