Archive for May, 2007

Parsing CSV files sent via form post in Ruby on Rails

Thursday, May 31st, 2007

I’m not sure why it took me a while to figure this out but it did. The Ruby CSV documentation is really weak and really only explains how to read from a file. I googled around and couldn’t find anyone else talking about how to parse a CSV file sent via a form post (StringIO). I didn’t want to save it to a temp file just so I could follow the CSV docs examples. Here’s what I eventually got to work. Its so short and simple I feel silly for not figuring it out sooner.


parsed_file = CSV::Reader.parse(params[:dump][:file])
parsed_file.each do |row|
p row[0]
end

Extortion via Sender Score Certified

Friday, May 25th, 2007

Microsoft has a spam filter that once it thinks you’re a spammer will pretty much never allow you to send legitimate emails. For any internet based company, emails are critical to the operation and need to get through or there’s no business. Microsoft has developed an approach through Sender Score Certified where they’ll let you pay them to be whitelisted. Its pretty much the only way I found to get off their shit list. The cost is about $1500 in all and has taken me 3 months or so to complete. The whole process was a big run around over and over sending me to different people and sites to do silly tasks. People rarely responded to any emails or phone calls I made and I had all but given up on it when they finally responded with a few minor changes I needed to make to our site in order to complete the process. Email has always been a free thing to deliver. It seems to me that Microsoft has found a way to capitalize on the fact that online companies must be able to send emails by forcing them to pay to get added to their whitelist. Basically, if too many people click on this is spam then you’re learned as spam and you’re screwed. You’ve got to pay to get whitelisted at that point. Sucks for online companies but its a great, albeit sleazy, business strategy for Microsoft to make some extra cash.

An awesome free font website

Friday, May 18th, 2007

I was working on a site design for a project of mine and had a specific font in mind for part of it. I googled around and had some trouble finding a decent site with free fonts until I found DaFont.com. This site has hundreds of free true type fonts you can download. It was painstaking to manually searching through all these fonts for what I was looking for but I eventually found it. At least this site had enough fonts for me to look through to find what I was looking for and they’re all free too.

Minimizing MySQL data loss in the event of a system failure

Thursday, May 17th, 2007

Anyone in their right mind who is running a mission critical database is already doing daily backups of the database. Its not often feasible to backup the entire database more than that. Without a proper plan, you’re stuck with a possible 24 hour data loss in the event the server dies just prior to its next backup. All transactions throughout the day are lost.

Luckily you can configure MySQL to store binary logs of all transactions that modify data in the database. These logs are typically going to be much smaller than your entire database so you can simply back them up more frequently than your entire database backup. When recovering from a system failure you would simply first restore from a nightly backup. Then restore from your binary log backups to ultimately reduce your data loss to whatever interval your binary log backups are set to.

To do all this you need to add the following lines to your my.cnf file:

log-bin = /var/log/mysql/.whatever
binlog-do-db=

expire_logs_days=2

I like to store 2 days of binary logs just in case something is screwed up I have 2 days worth of transactions I can potentially restore from. When restoring you need to be careful not to repeat transactions from prior to your nightly backup. So, if your nightly backup was exactly at midnight, you want to make sure you restore only the binary logs that occurred after midnight. Then you need to set a cron job to do the backup for something like every 5 minutes and you’re good to go.

Monitary precision of a Ruby float

Wednesday, May 16th, 2007

I looked around and couldn’t seem to find a way to easily change the precision of a Ruby Float object to 2 decimals so I can use it as a dollar amount. I feel bad about posting this because I borrowed some of the code from another site but lost the link to it. Instead of extending the Float class I just wrote a function to do it for me. It takes a Float object and returns string. I returned a string instead of a Float because I’m using it in the view and outputting the result anyway. Anyway, here’s the helper function.


def monetize(number)
splitnum = number.to_s.split(".")[0]
scale = number.to_s.split(".")[1][0..1]
while scale.length < 2
scale = scale + '0'
end
"#{splitnum}.#{scale}"
end

Increasing mod_fcgid timeout

Tuesday, May 15th, 2007

Taken from: http://bsdcat.livejournal.com/164497.html

To increase the timeout of mod_fcgid add the following lines to your apache config.

IPCConnectTimeout 20
IPCCommTimeout 300