Ruby random number by day
This is a cool little snippet of code that will return a random number, that changes by day:
def random_by_day(max_value)
srand Time.now.strftime("%m%d%Y").to_f
rand(max_value)
end
A Technology Blog
This is a cool little snippet of code that will return a random number, that changes by day:
def random_by_day(max_value)
srand Time.now.strftime("%m%d%Y").to_f
rand(max_value)
end
Came across a sweet rails log analyzer. Doesn’t require that you use syslog or anything like the other log parsers that are out there. This one will work right on your development or production log files. Its called RAWK and you can find it here: http://rubyforge.org/frs/?group_id=2517&release_id=15246
If you’re like me at all, you have run into this issue many times trying to upload your favorite Rails app to your webhost. This can be a very annoying and painful process if you do not understand what is going on exactly so I am going to outline a few tips to follow when attempting to release your new app, and if those tips do not work, I have my final tip that is actually quite useful. Here is my checklist:
These usually get the job done, and if you still have issues, feel free to comment here and I’ll try and help. One thing I have done in that past that helps out really well is to use a “skeleton” app. Basically what I do is the following:
- app
- config (Sometimes I link everything inside except the database.yml file and manage it only on the host)
- db
- lib
- test
- vendor
- Everything inside public folder except the dispatch files.
This has come in very useful for me as I do not have to worry about permissions on the dispatch files everything I svn up the public directory and my logs are contained by them self. I can also go into my actual app(not the skeleton one) and just run an svn up. You may have to work with the links a little bit to get it working. If anyone has any comments on this idea or improvements, I would love to hear them.
When trying to do a model.find(), I ran into the error, 'syntax error, unexpected tINTEGER Object::1'
. If you have a table that uses a magic or reserved name, such as type, you will get this error. This error was a pain in the ass, but I figured out that you can get by it:
class SomeModel < ActiveRecord::Base
self.inheritance_column = ''
end
The inheritance_column override is the key, basically giving it a different value to use. Hope this helps!
I found this cool little snippet of code somewhere on the internet. Anywhere you access an object in a view, adding the following will ensure the page doesn’t blow up:
<%= @object.association.variable rescue nil %>
Of course, you won’t know if you have an error now either.