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
// 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
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
// 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
$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
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
# 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
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
/** | |
* Applies a callback to a copy of all data in the collection | |
* and returns the result. | |
* | |
* Overriden to load any data that has not yet been loaded. | |
* | |
* @param callback $filter The filter to apply. | |
* @param array $options The available options are: | |
* - `'collect'`: If `true`, the results will be returned wrapped | |
* in a new Collection object or subclass. |
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
Exception thrown in -::lithium\data\source\database\adapter\{closure}() on line 342: | |
SELECT * FROM `units` AS `Unit` WHERE `name` = 'Unit 1' AND `0` = 'id != 1' LIMIT 1;: Unknown column '0' in 'where clause' | |
Trace: | |
lithium\core\Object::_filter(), line 245 | |
lithium\data\source\database\adapter\MySql::_execute(), line 343 | |
lithium\core\Object::invokeMethod(), line 169 | |
lithium\data\source\{closure}, line 265 | |
lithium\core\Object::_filter(), line 245 | |
lithium\data\source\Database::read(), line 287 | |
lithium\data\{closure}, line 455 |