So … where is the PHP equivalent of Django Admin? Or the multitude of Rails Admin plugins?
I don’t care what framework it sits on as long as the out-of-the-box functionality is awesome.
So … where is the PHP equivalent of Django Admin? Or the multitude of Rails Admin plugins?
I don’t care what framework it sits on as long as the out-of-the-box functionality is awesome.
I’ve just released the first pass of a Ruby on Rails Plugin called Acts As Scheduled.
acts_as_scheduled allows you to manage scheduled events for your models.
A good example of this is scheduling the update of RSS Feeds in a background process using Cron or BackgroundRB.
With acts_as_scheduled your schedule manager can simply call “Model.find_next_scheduled()” to grab the next item from the database.
At the moment it assumes you are working with MySQL.
All you need to get started is to add two extra columns to your table:
t.integer frequency
t.datetime last_scheduled
frequency is the number of seconds for your schedule.
last_scheduled is the date and time the record was last processed.
Ruby on Rails is real smart with times, so you don’t have to worry too much about calculating frequency values:
model.frequency = 1.day
model.frequency = 1.minute
model.frequency = 10.second
In your model class your simply declare “acts_as_scheduled” and you now have two extra methods find_next_scheduled and schedule_complete.
find_next_scheduled
Returns the next scheduled record from the table.
The next scheduled record is calculated as “the record who’s last_scheduled value is less than the current time minus the specified frequency in seconds”.Which is the complex way of saying “if freqency is 1 minute, return the record if it was last_scheduled more than 1 minute ago”
If there is more than one record, records scheduled to occur more frequently will be handled first (so records with minute schedules are returned before records with daily schedules.
schedule_complete
Sets the record’s last_scheduled value to Time.now
Example
class ScheduledItem < ActiveRecord::Base
acts_as_scheduled
endschedule_minute = ScheduledItem.new(:frequency => 1.minute, :last_scheduled => 2.seconds.ago)
schedule_minute.saveschedule_day = ScheduledItem.new(:name =>”day”, :frequency => 1.day, :last_scheduled => 25.hours.ago)
schedule_day.save#returns thing_day because it was last_scheduled 25 hours ago
schedule_day = ScheduledItem.find_next_scheduled
schedule_day.do_some_stuff
schedule_day.schedule_complete
schedule_day.save
For various reasons I need to be able to be able to accept some script input from the client.
The basic requirement is to be able to accept some Ruby code from the client in order to allow customisation of the HTML output from an RSS feed.
This is obviously a rather dangerous thing. I essentially need to allow arbitrary Ruby to be executed with an eval
However, in Ruby, we can run code in SAFE mode.
At Level 4:
Ruby effectively partitions the running program in two. Nontainted objects may not be modified. Typically, this will be used to create a sandbox: the program sets up an environment using a lower
$SAFElevel, then resets$SAFEto 4 to prevent subsequent changes to that environment
The core of my approach is to create a new Thread, set the SAVE level to 4 and call a method.
feed = FeedNormalizer::FeedNormalizer.parse(open(self.url))
thread = Thread.start {
$SAFE = 4
html = safe_method(feed, script)}
}
thread.join #wait for the thread to finish
The safe_method itself does a sanity check on the safe level. The method takes a feed object and a script - the script is processed using eval and because the feed object is in the context, the script has access to it. However, the safe level prevents any malicious code from attempting to use Ruby magic and meta-programming to gain access to variables outside the thread or any globals
def safe_method(feed,script)
if ( $SAFE < 4 )
raise “SecurityException: attempting to execute UNSAFE script”
endhtml = “”
eval(script)
return html
end
The user can then pass in code that looks like:
html << “<h2>#{feed.title}</h2>”
html << “<ul>”
feed.entries.each do |entry|
html << “<li><a href=\”#{entry.urls.first}\”>#{entry.title}</a></li>”
end
html << “</ul>”
And the feed is processed without (too much) risk.
I am very pleased to announce the availibility of the Hypothetical Megastructure “but will it scale” t-shirt.
The t-shirt provdes the wearer with the following powers:
“BUT WILL IT SCALE“?
Available in LARGE, EXTRA-LARGE, GRID, and the apparently defunct N-TIER.
I like to wear mine in a cluster (simply buy two or more t-shirts and wear simultaneously).
Your credit report
Lil Wayne Ringtones
Pink Floyd Ringtones
Buy Zyban
Linux VPN
Atarax
Fix credit score
Calan
Internet VPN xp
Credit history report
Valium
Credit cards instant approval
Aldactone
Celexa
Annuel credit report
Diflucan
Cheap Avandia
Improving your credit score
Cheap Capoten
My credit report
Buy Synthroid
Buy Allegra
Credit reporting system
Nextel Ringtones
Buy Viagra
Best credit card rebates
Advair Diskus
Imdur
Buy Viagra
Tramadol
Netgear VPN
Diazepam 5mg
Buy Prednisone
Credit report score chart
Cheap Zoloft
Buy Xenical
Torn up credit card application
Nexium
Phentermine No Prescription
Yerba Diet
Totally free credit report
Zoloft
Avodart
Download Ringtones
Cipro
Buy Nexium
Cheap credit card processing
Nolvadex
Credit card reporting
Instant credit cards approval
Levitra
Cheap Acomplia
Paxil
Risperdal
Online Cialis Professional
Florida free credit report
Capoten
Buy Zyrtec
Buy Motrin
Phentermine
Hoodia
Buy Remeron
Cheap Flomax
Ativan Online
Cheap Colostrum 800
Providian credit card application
VPN setup xp
Set up a VPN
Online Viagra Soft Cialis Soft
Credit reports com
Atarax
Celexa
Buy Augmentin
Torn up credit card application
Cheap Paxil
Norco
Vicodin
My favourite new plugin for Ruby on Rails is backup_fu.
backup_fu makes managing Amazon S3 backups really simple.
I have been running my own Rake Task for MySQL Backup to Amazon S3, but I’ve switched my projects over to backup_fu instead because it has much better control over your backups and will even backup stored files.
I’ve also created a patch for backup_fu that allows you to specify the mysqldump options. It should get rolled into an upcoming release, but if you would like it sooner, just contact me at toby…@info-architects.net.
The unfortunate tragedy of my life is that I don’t get to develop in Ruby on Rails all the time. No, unfortunately for me, a large number of my clients need work done in PHP.
Which, as already indicated in several previous nuanced discussions, I hate.
I mean, really really HATE.
But that’s not the point of this post.
After being seriously burnt by the twin miseries of CakePHP’s poor documentation and desperately misguided attempt to mimic Rails I went looking for a new PHP MVC framework for a recent project.
Crucial requirements:
I really wanted something that was pure VC, leaving out the M.
Views, Controllers and Models can go to hell.
PHP’s complete lack of dynamicism (and yes, I know PHP 5 has a crack at it, but whatever) means any attempt at Hibernate or Rails-style ORM is doomed to failure. And after screaming at CakePHP every time a finder returns an array of nested hashes of arrays of hashes and you can never work out how to just iterate through the records I’ve gone back to ADODB. You run a query and are returned a Record Set. I know this just reveals how long I spent in the late 90s hacking ASP, but if any language was still living in the late 90s, it’s PHP. And it’s actually quite good at it.
Where was I?
Right. Clean View/Controller mechanism. No Models.
Enter CodeIgniter.
It’s incredibly simple, the only assumption it makes is that you may never need most of the stuff it includes, so everything is an option, and it has great documentation.
CodeIgniter: I Don’t Hate It.
If you really have to use PHP, it’s worth a look.
Rob Mayhew prepared this ToDo List Tutorial
Update: This code pretty much also provides you with a REST API.
Oh yes: Rails 2.0 has been released
For some tips on moving your codebase to version 2.0:
I’ll be moving some of my projects and will be blogging about my experiences.
RailsCamp is on this weekend. 40 uber-geeks gathered to immerse themselves in Ruby On Rails.
It should be pretty cool.
I haven’t prepared any materials, but might present something on Amazon Web Services - I did this for the Melbourne Ruby User Group a little while ago.