<commit_before><?php

namespace app\models;

use lithium\core\Libraries;
use lithium\util\Collection;
use cebe\markdown\GithubMarkdown;

class Eurekas extends \lithium\data\Model {

	protected $_meta = [
		'connection' => false
	];

	protected static $_parser;

	public static function init() {
		static::$_parser = new GithubMarkdown();
		static::$_parser->html5 = true;
	}

	public static function find($type, array $options = array()) {
		$files = static::_files();

		if ($type === 'all') {
			$results = [];

			foreach ($files as $file) {
				$results[] = static::create(compact('file'));
			}
			return new Collection(['data' => $results]);
		}
		if ($type === 'random') {
			return static::create([
				'file' => $files[abs(crc32(date('Y-m-d'))) % count($files)]
			]);
		}
	}

	protected static function _files() {
		return glob(Libraries::get(true, 'resources') . '/eurekas/*.md');
	}

	public function body($entity) {
		return static::$_parser->parse(file_get_contents($entity->file));
	}
}

Eurekas::init();

?><commit_msg>Cleanup eurekas.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2013, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace app\models;

use lithium\core\Libraries;
use lithium\util\Collection;
use cebe\markdown\GithubMarkdown;

class Eurekas extends \lithium\data\Model {

	protected $_meta = [
		'connection' => false
	];

	protected static $_parser;

	public static function init() {
		static::$_parser = new GithubMarkdown();
		static::$_parser->html5 = true;
	}

	public static function files() {
		return glob(Libraries::get(true, 'resources') . '/eurekas/*.md');
	}

	public function body($entity) {
		return static::$_parser->parse(file_get_contents($entity->file));
	}
}

Eurekas::init();

Eurekas::finder('all', function($self, $params, $chain) {
	$files = Eurekas::files();

	$results = [];

	foreach ($files as $file) {
		$results[] = Eurekas::create(compact('file'));
	}
	return new Collection(['data' => $results]);
});

Eurekas::finder('random', function($self, $params, $chain) {
	$files = Eurekas::files();
	return Eurekas::create([
		'file' => $files[abs(crc32(date('Y-m-d'))) % count($files)]
	]);
});

?>
{'fraction_non_alphanumeric': 0.18853893263342084, 'fraction_numerical': 0.004374453193350831, 'mean_word_length': 4.471291866028708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6162958', 'n_tokens_mistral': 849, 'n_tokens_neox': 766, 'n_words': 164}