Ejemplo n.º 1
0
/**
 */
function bmod2($x, $m, $mu)
{
    $xl = count($x) - (count($m) << 1);
    if ($xl > 0) {
        return bmod2(array_concat(array_slice($x, 0, $xl), bmod2(array_slice($x, $xl), $m, $mu)), $m, $mu);
    }
    $ml1 = count($m) + 1;
    $ml2 = count($m) - 1;
    $rr = 0;
    $q3 = array_slice(bmul(array_slice($x, $ml2), $mu), $ml1);
    $r1 = array_slice($x, 0, $ml1);
    $r2 = array_slice(bmul($q3, $m), 0, $ml1);
    $r = bsub($r1, $r2);
    if (count($r) == 0) {
        $r1[$ml1] = 1;
        $r = bsub($r1, $r2);
    }
    for ($n = 0;; $n++) {
        $rr = bsub($r, $m);
        if (count($rr) == 0) {
            break;
        }
        $r = $rr;
        if ($n >= 3) {
            return bmod2($r, $m, $mu);
        }
    }
    return $r;
}
Ejemplo n.º 2
0
 private function requireFiles()
 {
     // Include all files in the /app/external folder (but not the ones inside sub-folders)
     $requires_directories = array('app/external');
     $core_requires = array('app/model', 'app/controllers', 'app/views');
     $all_requires = array_concat($core_requires, $requires_directories);
     foreach ($all_requires as $dir) {
         $dir_handle = opendir(DISK_ROOT . $dir);
         while (false != ($file = readdir($dir_handle))) {
             if (substr($file, strlen($file) - strlen(".php")) === ".php") {
                 require_once DISK_ROOT . $dir . '/' . $file;
             }
         }
     }
     // Also require the phpmailer control
     require_once DISK_ROOT . 'framework/external/phpmailer/class.phpmailer.php';
 }
Ejemplo n.º 3
0
 * @param {array} $secondArray 
 */
function array_concat($firstArray, $secondArray)
{
    $iLimit = count($secondArray);
    for ($i = 0; $i < $iLimit; $i++) {
        $firstArray[] = $secondArray[$i];
    }
    return $firstArray;
}
use Abraham\TwitterOAuth\TwitterOAuth;
// Open connection to Twitter
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// Get a bunch of Tweets about fish
$statusData = $connection->get("search/tweets", ["q" => 'fish', "count" => 25, "lang" => 'en']);
// Extract the statuses from the object
$statuses = $statusData->statuses;
// Array to hold appropriate words
$words = [];
// Iterate over the statuses
foreach ($statuses as $status) {
    $words = array_concat($words, extractNLengthWords(7, $status->text));
}
// Iterate over the words, converting them to lowercase
foreach ($words as &$word) {
    $word = strtolower($word);
}
// Remove duplicates
$words = array_unique($words);
// Echo out a random item from our array of words
echo '{ "word": "' . $words[array_rand($words)] . '" }';
Ejemplo n.º 4
0
 public function testConcatCastToArray()
 {
     $this->assertSame([1], array_concat([1]));
     $this->assertSame([1], array_concat(1));
 }
 protected function performSave($data, $fork)
 {
     $entity = $this->getLocalyMappedEntityToSave($data, $fork);
     $connection = $this->getPropelConnection();
     try {
         $connection->beginTransaction();
         $entity->setLastComputed(0);
         $personDict = array();
         foreach ($entity->getGrouppeople() as $groupPerson) {
             $personDict[$groupPerson->getId()] = $groupPerson;
         }
         $evePersonDict = array();
         foreach ($entity->getGroupEvepeople() as $groupEvePerson) {
             $evePersonDict[$groupEvePerson->getId()] = $groupEvePerson;
         }
         $groupPersonTypesDict = $this->groupPersonTypeService->get();
         $allDataPersons = array();
         $allDataEvePersons = array();
         foreach ($groupPersonTypesDict as $groupPersonType) {
             $dataByType = $data->{$groupPersonType['name']};
             $allDataPersons = array_concat($allDataPersons, $dataByType->persons);
             $allDataEvePersons = array_concat($allDataEvePersons, $dataByType->evePersons);
         }
         $this->cleanupOldEnties($entity, 'GroupPerson', $allDataPersons);
         $this->cleanupOldEnties($entity, 'GroupEvePerson', $allDataEvePersons);
         foreach ($groupPersonTypesDict as $groupPersonTypeId => $groupPersonType) {
             $dataByType = $data->{$groupPersonType['name']};
             foreach ($dataByType->persons as $dataPerson) {
                 $personExists = property_exists($dataPerson, 'id');
                 $personEntity = $personExists ? $personDict[$dataPerson->id] : new ECP\GroupPerson();
                 $personEntity->setGroupPersonTypeId($groupPersonTypeId);
                 $personEntity->setUserId($dataPerson->user->id);
                 $this->prepareSubentitySave2($connection, $entity, 'GroupPerson', $personEntity, !$personExists);
                 $allDataPersons[] = $dataPerson;
             }
             foreach ($dataByType->evePersons as $dataEvePerson) {
                 $evePersonExists = property_exists($dataEvePerson, 'id');
                 $evePersonEntity = $evePersonExists ? $evePersonDict[$dataEvePerson->id] : new ECP\GroupEvePerson();
                 $evePersonEntity->setGroupPersonTypeId($groupPersonTypeId);
                 $evePersonEntity->setName($dataEvePerson->name);
                 $this->prepareSubentitySave2($connection, $entity, 'GroupEvePerson', $evePersonEntity, !$evePersonExists);
                 $allDataEvePersons[] = $dataEvePerson;
             }
         }
         if (!$this->isCurrentUserStillAdminInGroup($entity)) {
             throw new ValidationException('You cannot remove yourself from the admin list of a group. Please make sure you are always on the admin list before you try to save a group.');
         }
         $entity->save($connection);
         $this->saveGroupAccess($connection, $entity, null);
         $connection->commit();
         return $this->createIdObj($entity->getId());
     } catch (Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }