This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testMap() { | |
$model = $this->_model; | |
$model::config(array('connection' => false)); | |
$collection = new DocumentSet(compact('model')); | |
$collection->map(function($data) {return $data;}) | |
$this->assertEqual($model, $collection->model()); // passes because map() doesn't run | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Brute force | |
sum = 0 | |
(1..999).each do |num| | |
sum = sum + num if (num % 3 == 0 || num % 5 == 0) | |
end | |
puts "Brute force: #{sum}" | |
# More rubyish, but still brute force | |
sum = (1..999).inject(0) {|sum,num| (num % 3 == 0 || num % 5 == 0) ? sum + num : sum} | |
puts "More rubyish but still brute force: #{sum}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 4000000 | |
# Brute force | |
def fib(num) | |
if num < 2 | |
num | |
else | |
fib(num - 2) + fib(num - 1) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$clusters_list = Cluster::all(array('conditions' =>array( | |
'id' => array('!=' => implode(',', $form_clusters->map(function($cluster) { | |
return $cluster->id; | |
}, array('collect' => false)))), | |
))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a finder for clusters not linked to 'object' | |
static::finder('unlinked', function($self, $params, $chain) { | |
$object = $params['options']['object']; | |
unset($params['options']['object']); | |
// @todo Shouldn't make a direct call to getClusters, but should instead | |
// have a protected array of things that can be linked | |
$ids = $object->getClusters()->map(function($cluster) { | |
return $cluster->id; | |
}, array('collect' => false)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = 600851475143 | |
# Brute force | |
def is_prime?(n) | |
limit = Math.sqrt(n).round | |
(2..limit).each do |i| | |
return false if n % i == 0 | |
end | |
return true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handle attaching children | |
$('#unattached_children a.add').click(function() { | |
var icons = $(this).parent(); | |
var child_type = // work out what the name of the child is | |
// Update label text | |
$('#attached_children>label').html('Attached '+child_type); | |
// Move the item to the attached items list | |
$('#AttachedItems .list').append($(this).closest('.item')); | |
$('#attached_children .list .item:last-child').append('<input name="'+child_type+'[]" type="hidden" value="'+$('#attached_children .list .item:last-child').attr('id')+'" />'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bson (1.2.0) | |
bson_ext (1.2.0) | |
cucumber (0.10.0) | |
gherkin (2.3.2) | |
mechanize (1.0.0) | |
mongo (1.2.0) | |
mysql (2.8.1) | |
rake (0.8.7) | |
rdoc (2.5.8) | |
selenium-client (1.2.18) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failing Scenarios: | |
cucumber ./cluster_create.feature:6 # Scenario: View the clusters page | |
cucumber ./cluster_create.feature:21 # Scenario: Create a new cluster | |
cucumber ./cluster_create.feature:27 # Scenario: Create a cluster and be directed to the clusters page | |
cucumber ./cluster_create.feature:77 # Scenario: Create a cluster and be directed to the clusters page | |
cucumber ./cluster_create.feature:86 # Scenario: Create a cluster when no forms exist | |
cucumber ./unit_update.feature:183 # Scenario: View a unit that has one item and see the item position | |
cucumber ./unit_update.feature:191 # Scenario: View a unit that has two items and see the item position | |
cucumber ./unit_retrieve.feature:34 # Scenario: Visit units page with one unit and see view link | |
cucumber ./form_retrieve.feature:28 # Scenario: Visit forms page with one form and see view link |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then /^I should see element "([^"]*)" before element "([^"]*)"$/ do |first, second| | |
xpath = "//*[@id='#{first}']/following-sibling::*[@id='#{second}']" | |
response_body.should have_xpath(xpath) | |
end |