One of the things we have to do at FilmAmora is generate a catalogue of our films. This is used in a few ways, but principally to drive our recommendations system.
I stumbled across this great blog entry:
Generating-Sitemaps-With-Rails that not only tells you a very nice way of generating sitemaps but also gave us great ideas for using the same technique to generate our catalogues.
Awesome!
Friday, 13 March 2009
Friday, 13 February 2009
ec2onrails EU
Well, necessity is the mother of invention. We needed new FilmAmora servers to deal with the increasing load. I also wanted to move to EU-based EC2 instances.
That meant rolling our own because I believe there are no publicly available ec2onrails instances that run in the eu-west region.
This was not as easy as I would have liked, so here's a little step by step.
1. Go to Alestic and get the id of the proper eu instance. (At this writing it is ami-ac032bd8)
2. Fire up an instance of this. I use Elastic Fox and you need to set the region to europe then choose this instance.
3. copy your pem's into the instance:
4. ssh into the instance
5. Get the build script
6. update so you can get git
7. get git
8. get ec2onrails and use the latest branch
9. Run the build script!
Your account number is the 12 digit number from your amazon access information page.
10. Register the instance
That's it!
You should now be able to go to Elastic Fox and launch and instance of this that will be in Europe!
That meant rolling our own because I believe there are no publicly available ec2onrails instances that run in the eu-west region.
This was not as easy as I would have liked, so here's a little step by step.
1. Go to Alestic and get the id of the proper eu instance. (At this writing it is ami-ac032bd8)
2. Fire up an instance of this. I use Elastic Fox and you need to set the region to europe then choose this instance.
3. copy your pem's into the instance:
scp -i IDENTITY {cert,pk}-*.pem root@HOSTNAME:/mnt/
4. ssh into the instance
ssh -i IDENTITY root@HOSTNAME
5. Get the build script
wget http://ec2ubuntu-build-ami.notlong.com
6. update so you can get git
apt-get update && apt-get upgrade -y
7. get git
apt-get install git-core
8. get ec2onrails and use the latest branch
git clone git://github.com/pauldowman/ec2onrails.git
cd ec2onrails
git checkout --track -b 0.9.9.1 origin/0.9.9.1
9. Run the build script!
bash ec2ubuntu-build-ami \
--script /root/ec2onrails/server/build-ec2onrails.sh \
--user YOUR_ACCOUNT_NUMBER \
--access-key YOUR_ACCESS_KEY \
--secret-key YOUR_SECRET_KEY \
--bucket BUKCET_NAME \
--prefix PREFIX \
--location EUYour account number is the 12 digit number from your amazon access information page.
10. Register the instance
ec2-register bucket/manifest.xml --region eu-west-1
That's it!
You should now be able to go to Elastic Fox and launch and instance of this that will be in Europe!
Labels:
amazon,
ec2onrails,
europe
Wednesday, 11 February 2009
DropDown menu for Blueprint tabbed menus
I love blueprint css! And I also love the tabs menu plugin for it. But, we neede drop down menus on FilmAmora. So I wrote a little extension that gives you that. It's not perfect, but, it works for now.
Find it here:
Blueprint_dd
Find it here:
Blueprint_dd
Labels:
blueprintcss,
css,
rails
Friday, 6 February 2009
BackgroundRb and Synchronous calls
BackgroundRb lets you also call the workers synchronously. This is quite neat as you can use it as a form of pseudo-proxy and all other kinds of goodies.
But, the documentation is lacking, so I am posting this for all you frustrated Googlers out there. Here is what you need to do.
Now, the BackgroundRb site tells you to call this like so to get a response back:
This, in fact, won't work.
You need to do this:
The second parameter (and make sure you put {} around your first set of args) is some freaky boolean to say, "no, seriously, I want a result back". Otherwise you get nil.
Bonus Tip!
When you define a method in a worker it HAS to accept arguments.
This won't work:
This will:
But, the documentation is lacking, so I am posting this for all you frustrated Googlers out there. Here is what you need to do.
class SampleWorker < BackgrounDRb::MetaWorker
set_worker_name :sample_worker
def create(args = nil)
# this method is called, when worker is loaded for the first time
end
def test_me args
puts "test_me 1 (puts)"
logger.debug("test_me hit (log)")
return "of course it works"
end
end
Now, the BackgroundRb site tells you to call this like so to get a response back:
MiddleMan.worker(:sample_worker).test_me(:arg => "1")
This, in fact, won't work.
You need to do this:
MiddleMan.worker(:sample_worker).test_me({:arg => "1"}, true)
The second parameter (and make sure you put {} around your first set of args) is some freaky boolean to say, "no, seriously, I want a result back". Otherwise you get nil.
Bonus Tip!
When you define a method in a worker it HAS to accept arguments.
This won't work:
def test_me
end
This will:
def test_me(something = 1)
end
Friday, 16 January 2009
Rails and eTags
In the never ending search for speed I've been doing a lot of stuff with 304 Conditional get's. Here is a good article about etags - which is a vital component to it!
Rails-ETags
Rails-ETags
Friday, 12 December 2008
MySQL and Leopard
I had such problems on my macbook (though not on the macpro) in getting mysql running.
This article seems to have helped.
This article seems to have helped.
Monday, 8 December 2008
checkboxes for multiple items
I am doing an interface where I want to list a bunch of things (index) and have a checkbox next to each of them. Then, using a button, edit or show all those selected items.
I am always running into this problem of checkboxes (maybe I am just stupid) so I spent some time and figured out a way that works for me. There are probably other solutions, but here is what I do:
First, in the index.html I have this javascript code:
Then I have the table of devices:
The result is that my ajax function will be called with a comma separated list of the ids of the selected devices.
I am always running into this problem of checkboxes (maybe I am just stupid) so I spent some time and figured out a way that works for me. There are probably other solutions, but here is what I do:
First, in the index.html I have this javascript code:
<% content_for :javascript do %>
<script type="text/javascript" charset="utf-8">
/* <![CDATA[ */
function editDevices() {
var device_count = document.getElementsByName('device[]').length;
var total="";
for(var i=0; i < device_count; i++){
if(document.forms['group_edit'].elements['device[]'][i].checked) {
if (total.length > 0) {
total += ","
}
total +=document.forms['group_edit'].elements['device[]'][i].value;
}
}
new Ajax.Request('<%= group_edit_devices_path %>', {
parameters: {
authenticity_token: encodeURIComponent('<%=form_authenticity_token%>'),
device_ids: total
}
}
);
}
function showDevices() {
var device_count = document.getElementsByName('device[]').length;
var total="";
for(var i=0; i < device_count; i++){
if(document.forms['group_edit'].elements['device[]'][i].checked) {
if (total.length > 0) {
total += ","
}
total +=document.forms['group_edit'].elements['device[]'][i].value;
}
}
new Ajax.Request('<%= group_show_devices_path %>', {
parameters: {
authenticity_token: encodeURIComponent('<%=form_authenticity_token%>'),
device_ids: total
}
}
);
}
/* ]]> */
</script>
<% end %>
Then I have the table of devices:
<table border="0" cellspacing="5" cellpadding="5">
<thead>
<tr>
<th> </th>
<th>Uid</th>
<th>Name</th>
<th>Ip</th>
<th># Displays</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<ul class="tabs">
<li><%= link_to_function "Show", "showDevices()" %></li>
<li><%= link_to_function "Edit", "editDevices()" %></li>
<li><%= link_to "Delete" %></li>
</ul>
</td>
</tr>
</tfoot>
<tbody>
<% for device in @devices %>
<tr>
<td><%= check_box_tag("device[]", device.id, false, :id => "device_#{device.id}") %></td>
<td><%=link_to_remote h(device.uid), :url => formatted_device_path(device, :js), :method => "get" %></td>
<td><%=h device.name %></td>
<td><%=h device.ip %></td>
<td><%= device.displays.count %></td>
</tr>
<% end %>
</tbody>
</table>
The result is that my ajax function will be called with a comma separated list of the ids of the selected devices.
Labels:
ajax,
checkboxes,
javascript,
rails,
views
Subscribe to:
Posts (Atom)