Exemple #1
0
 /**
  * Stack test method.
  *
  * @param object IStack $stack The stack to test.
  */
 public static function test(IStack $stack)
 {
     printf("AbstractStack test program.\n");
     for ($i = 0; $i < 6; ++$i) {
         if ($stack->isFull()) {
             break;
         }
         $stack->push(box($i));
     }
     printf("%s\n", str($stack));
     printf("Using foreach\n");
     foreach ($stack as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $stack->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Top is %s\n", str($stack->getTop()));
     printf("Popping\n");
     while (!$stack->isEmpty()) {
         $obj = $stack->pop();
         printf("%s\n", str($obj));
     }
     $stack->push(box(2));
     $stack->push(box(4));
     $stack->push(box(6));
     printf("%s\n", str($stack));
     printf("Purging\n");
     $stack->purge();
     printf("%s\n", str($stack));
 }
 /**
  * PriorityQueue test method.
  *
  * @param object IPriorityQueue $pqueue The queue to test.
  */
 public static function test(IPriorityQueue $pqueue)
 {
     printf("AbstractPriorityQueue test program.\n");
     printf("%s\n", str($pqueue));
     $pqueue->enqueue(box(3));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(4));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(9));
     $pqueue->enqueue(box(2));
     $pqueue->enqueue(box(6));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(4));
     printf("%s\n", str($pqueue));
     printf("Using reduce\n");
     $pqueue->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Using foreach\n");
     foreach ($pqueue as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Dequeueing\n");
     while (!$pqueue->isEmpty()) {
         $obj = $pqueue->dequeueMin();
         printf("%s\n", str($obj));
     }
 }
Exemple #3
0
 /**
  * @see Log
  */
 public function flush($logs, $id, $stdout)
 {
     foreach ($logs as $log) {
         try {
             $vars = $options = array();
             foreach (module_const_array('params') as $param) {
                 list($name, $value) = array_map('trim', explode(',', $param, 2));
                 $vars[$name] = $value;
             }
             $vars['level'] = $log->fm_level();
             $value = $log->value();
             if (is_array($value)) {
                 $value = array_shift($value);
             }
             switch ($log->fm_level()) {
                 case 'error':
                 case 'warn':
                 case 'info':
                     $vars['priv'] = 1;
                     $vars['message'] = sprintf("%s:%s %s", pathinfo($log->file(), PATHINFO_FILENAME), $log->line(), str($value));
                     break;
             }
             if (isset($vars['message'])) {
                 $data = http_build_query($vars);
                 $header = array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($data));
                 $options = array('http' => array('method' => 'POST', 'header' => implode("\r\n", $header), 'content' => $data));
                 file_get_contents(module_const('url'), false, stream_context_create($options));
             }
         } catch (Exception $e) {
         }
         // print(sprintf('console.%s("[%s:%d]",%s);',$log->fm_level(),$log->file(),$log->line(),str_replace("\n","\\n",Text::to_json($log->value()))));
     }
 }
Exemple #4
0
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Application program number 3.\n");
     $status = 0;
     $p1 = new PolynomialAsOrderedList();
     $p1->add(new Term(4.5, 5));
     $p1->add(new Term(3.2, 14));
     printf("%s\n", str($p1));
     $p1->differentiate();
     printf("%s\n", str($p1));
     $p2 = new PolynomialAsSortedList();
     $p2->add(new Term(7.8, 0));
     $p2->add(new Term(1.6, 14));
     $p2->add(new Term(9.999000000000001, 27));
     printf("%s\n", str($p2));
     $p2->differentiate();
     printf("%s\n", str($p2));
     $p3 = new PolynomialAsSortedList();
     $p3->add(new Term(0.6, 13));
     $p3->add(new Term(-269.973, 26));
     $p3->add(new Term(1000, 1000));
     printf("%s\n", str($p3));
     printf("%s\n", str($p2->plus($p3)));
     return $status;
 }
 /**
  * Search tree test program.
  *
  * @param object ISearchTree $tree The tree to test.
  */
 public static function test(ISearchTree $tree)
 {
     printf("AbstractSearchTree test program.\n");
     printf("%s\n", str($tree));
     for ($i = 1; $i <= 8; ++$i) {
         $tree->insert(box($i));
     }
     printf("%s\n", str($tree));
     printf("Breadth-First traversal\n");
     $tree->breadthFirstTraversal(new PrintingVisitor(STDOUT));
     printf("Preorder traversal\n");
     $tree->depthFirstTraversal(new PreOrder(new PrintingVisitor(STDOUT)));
     printf("Inorder traversal\n");
     $tree->depthFirstTraversal(new InOrder(new PrintingVisitor(STDOUT)));
     printf("Postorder traversal\n");
     $tree->depthFirstTraversal(new PostOrder(new PrintingVisitor(STDOUT)));
     printf("Using foreach\n");
     foreach ($tree as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $tree->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Using accept\n");
     $tree->accept(new ReducingVisitor(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), ''));
     printf("Withdrawing 4\n");
     $obj = $tree->find(box(4));
     try {
         $tree->withdraw($obj);
         printf("%s\n", str($tree));
     } catch (Exception $e) {
         printf("Caught %s\n", $e->getMessage());
     }
 }
 /**
  * OrderedList test method.
  *
  * @param object IOrderedList $list The list to test.
  */
 public static function test(IOrderedList $list)
 {
     printf("AbstractOrderedList test program.\n");
     $list->insert(box(1));
     $list->insert(box(2));
     $list->insert(box(3));
     $list->insert(box(4));
     printf("%s\n", str($list));
     $obj = $list->find(box(2));
     $list->withdraw($obj);
     printf("%s\n", str($list));
     $position = $list->findPosition(box(3));
     $position->insertAfter(box(5));
     printf("%s\n", str($list));
     $position->insertBefore(box(6));
     printf("%s\n", str($list));
     $position->withdraw();
     printf("%s\n", str($list));
     printf("Using foreach\n");
     foreach ($list as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $list->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
 }
Exemple #7
0
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Application program number 6. (expression tree)\n");
     $status = 0;
     $expression = ExpressionTree::parsePostfix(STDIN);
     printf("%s\n", str($expression));
     return $status;
 }
 public function set_charge(OpenpearCharge $charge)
 {
     $this->handlename($charge->maintainer()->name());
     $this->name(str($charge->maintainer()));
     $this->mail($charge->maintainer()->mail());
     $this->role($charge->role());
     return $this;
 }
 /**
  * Digraph test method.
  *
  * @param object IDigraph $g The digraph to test.
  */
 public static function test(IDigraph $g)
 {
     printf("Digraph test program.\n");
     AbstractGraph::Test($g);
     printf("TopologicalOrderTraversal\n");
     $g->topologicalOrderTraversal(new PrintingVisitor(STDOUT));
     printf("isCyclic returns %s\n", str($g->isCyclic()));
     printf("isStronglyConnected returns %s\n", str($g->isStronglyConnected()));
 }
function platform_new($nom)
{
    try {
        $result = sql_do('INSERT INTO ' . DB_PREF . '_platforms (name_pf) VALUES (\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
 public function testCanBeInstantiated()
 {
     $string = new StringBuffer('string');
     $this->assertEquals('string', $string->get());
     $string = new StringBuffer(new TestToStringObject());
     $this->assertEquals('string', $string->get());
     $string = str('string');
     $this->assertEquals('string', $string->get());
 }
function license_new($nom, $term)
{
    try {
        sql_do('INSERT INTO ' . DB_PREF . '_licenses (name_lic,terms) VALUES (\'' . str($nom) . '\',\'' . str($term) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
function language_new($nom)
{
    try {
        sql_do('INSERT INTO ' . DB_PREF . '_languages (name_lang) VALUES (\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
function license_new($nom, $term)
{
    $id_lic = pick_id('licenses_id_lic_seq');
    try {
        sql_do('INSERT INTO licenses (id_lic,name_lic,terms) VALUES (\'' . int($id_lic) . '\',\'' . str($nom) . '\',\'' . str($term) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return $id_lic;
}
function language_new($nom)
{
    $id_lang = pick_id('languages_id_lang_seq');
    try {
        sql_do('INSERT INTO languages (id_lang,name_lang) VALUES (' . int($id_lang) . ',\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return $id_lang;
}
Exemple #16
0
 function str($str)
 {
     if (is_array($str)) {
         foreach ($str as $k => $v) {
             $str[$k] = str($v);
         }
     } else {
         $str = stripcslashes($str);
     }
     return $str;
 }
 protected function _getOrderNum()
 {
     $str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
     $str = str(str_shuffle($str), 0, 12);
     $sn = date('Ymd') . $str;
     $orders = M('Orders');
     $where = array('order_sn' => $sn);
     $res = $orders->where($where)->find();
     echo $orders->getLastSql();
     die;
 }
Exemple #18
0
 protected function __after_save__()
 {
     self::recount_favorites($this->package_id());
     C($this)->commit();
     $timeline = new OpenpearTimeline();
     $timeline->subject(sprintf('<a href="%s">%s</a> <span class="hl">liked</span> <a href="%s">%s</a>', url('maintainer/' . $this->maintainer()->name()), R(Templf)->htmlencode(str($this->maintainer())), url('package/' . $this->package()->name()), $this->package()->name()));
     $timeline->description(sprintf('<a href="%s">%s</a>: latest %s. %d fans.', url('package/' . $this->package()->name()), $this->package()->name(), $this->package()->latest_release()->fm_version(), C(OpenpearFavorite)->find_count(Q::eq('package_id', $this->package_id()))));
     $timeline->type('favorite');
     $timeline->package_id($this->package_id());
     $timeline->maintainer_id($this->maintainer_id());
     $timeline->save();
 }
Exemple #19
0
function str($arr)
{
    static $temp = array();
    foreach ($arr as $k => $v) {
        $temp[] = $k;
        if (!empty($v)) {
            str($v);
        } else {
            $str = implode(">", $temp);
            echo $str . "\n";
        }
        array_pop($temp);
    }
}
 /**
  * SortedList test method.
  *
  * @param object ISortedList $list The list to test.
  */
 public static function test(ISortedList $list)
 {
     printf("AbstractSortedList test program.\n");
     $list->insert(box(4));
     $list->insert(box(3));
     $list->insert(box(2));
     $list->insert(box(1));
     printf("%s\n", str($list));
     $obj = $list->find(box(2));
     $list->withdraw($obj);
     printf("%s\n", str($list));
     printf("Using foreach\n");
     foreach ($list as $obj) {
         printf("%s\n", str($obj));
     }
 }
Exemple #21
0
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Box main program.\n");
     $status = 0;
     $box = box(false);
     printf("%s\n", str($box));
     $box = box(57);
     printf("%s\n", str($box));
     $box = box(1.5);
     printf("%s\n", str($box));
     $box = box('test');
     printf("%s\n", str($box));
     $box = box(array(1, 2, 3));
     printf("%s\n", str($box));
     return $status;
 }
Exemple #22
0
 protected function __after_create__()
 {
     try {
         if ($this->mail()) {
             list($account, $password) = OpenpearConfig::gmail_account();
             $mail = new Gmail($account, $password);
             $mail->to($this->maintainer_to()->mail(), str($this->maintainer_to()));
             $mail->from($mail->from(), 'Openpear');
             $mail->subject($this->subject());
             $mail->message(strip_tags($this->fm_description()));
             $mail->send();
         }
     } catch (Exception $e) {
         Log::debug($e);
     }
 }
Exemple #23
0
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Application program number 4.\n");
     $status = 0;
     $p1 = new PolynomialAsSortedList();
     $p1->add(new Term(4.5, 5));
     $p1->add(new Term(3.2, 14));
     printf("%s\n", str($p1));
     $p2 = new PolynomialAsSortedList();
     $p2->add(new Term(7.8, 3));
     $p2->add(new Term(1.6, 14));
     $p2->add(new Term(9.999000000000001, 27));
     printf("%s\n", str($p2));
     $p3 = $p1->plus($p2);
     printf("%s\n", str($p3));
     return $status;
 }
Exemple #24
0
 function show()
 {
     global $menu, $sections, $page, $user;
     $data = array('query' => $GLOBALS['_SERVER']['QUERY_STRING'], 'STR_CLOSE' => $this->str('close'), 'menu' => $menu->getMenu($sections), 'page' => $page, 'act' => $this->editForm(), 'login' => $user['fullname'] ? $user['fullname'] : $user['login'], 'STR_LOGOUT' => str('logout', 'tmenu'), 'title' => $this->object->GetTitle());
     if (isset($_POST['do']) && $_POST['do'] == "save") {
         $result = $this->saveObject();
         echo $result;
         exit;
         // чтобы не вызывался парсинг во фрейме
     } elseif (isset($_POST['do']) && $_POST['do'] == "apply") {
         $result = $this->saveObject(true);
         echo $result;
         exit;
         // чтобы не вызывался парсинг во фрейме
     }
     return Parse($data, 'index.tmpl');
 }
 /**
  * Set test method.
  *
  * @param object IPartition $p A partition to test.
  */
 public static function test(IPartition $p)
 {
     printf("AbstractPartition test program.\n");
     printf("%s\n", str($p));
     $s2 = $p->findItem(2);
     printf("%s\n", str($s2));
     $s4 = $p->findItem(4);
     printf("%s\n", str($s4));
     $p->join($s2, $s4);
     printf("%s\n", str($p));
     $s3 = $p->findItem(3);
     printf("%s\n", str($s3));
     $s4b = $p->findItem(4);
     printf("%s\n", str($s4b));
     $p->join($s3, $s4b);
     printf("%s\n", str($p));
 }
Exemple #26
0
 /**
  * Surround a string with certain character/s
  *
  * @param string $str           The string value to be surrounded
  * @param string $fence         [optional] The fence to be used. Pair characters are also detected as well.
  * @param boolean $redundant    [optional] If redundant fence characters shall be removed first, default is FALSE
  * @param boolean $escape       [optional] If quotes shall be escaped, default is TRUE
  * @return string
  */
 public static function Surround($str, $fence = '"', $redundant = false, $escape = true)
 {
     $str = $escape ? addslashes($str) : $str;
     $isUnique = isset(self::$_Fences[$fence]);
     if ($isUnique) {
         $thisFence = [$fence, self::$_Fences[$fence]];
         if (!$redundant) {
             $str = rtrim(ltrim($str, $thisFence[0]), $thisFence[1]);
         }
         $str = str("{0}{1}{2}", $thisFence[0], $str, $thisFence[1]);
     } else {
         if (!$redundant) {
             $str = trim($str, $fence);
         }
         $str = str("{0}{1}{0}", $fence, $str);
     }
     return $str;
 }
 /**
  * DoubledEndedPriorityQueue test method.
  *
  * @param object IPriorityQueue $pqueue The queue to test.
  */
 public static function test(IPriorityQueue $pqueue)
 {
     printf("AbstractDoubledEndedPriorityQueue test program.\n");
     AbstractPriorityQueue::test($pqueue);
     printf("%s\n", str($pqueue));
     $pqueue->enqueue(box(3));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(4));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(9));
     $pqueue->enqueue(box(2));
     $pqueue->enqueue(box(6));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(4));
     printf("%s\n", str($pqueue));
     while (!$pqueue->isEmpty()) {
         $obj = $pqueue->dequeueMax();
         printf("%s\n", str($obj));
     }
 }
Exemple #28
0
function deal()
{
    if (empty($_REQUEST['answer'])) {
        fail("answer缺失");
    }
    if (empty($_REQUEST['id'])) {
        fail("id缺失");
    }
    $conn = @mysql_connect("localhost", "root", "mobilenewspaper") or die("数据库链接错误");
    $right = array(8, 4, 4, 1, 1, 2, 1, 1, 2, 4, 8, 8, 4, 2, 1, 4, 4, 1, 1, 8, 4, 1, 8, 7, 15, 7, 7, 5, 7, 3);
    list($score, $type) = calc($_REQUEST['answer'], $right);
    mysql_select_db("qa", $conn);
    $result = mysql_query("select id from questionnaire order by id desc limit 1", $conn);
    $row = mysql_fetch_assoc($result);
    $id = $row['id'] + 1;
    $SQL = "INSERT INTO questionnaire (titleid, score, answer) VALUES ( " . $_REQUEST['id'] . "," . str($score) . ",\"" . $_REQUEST['answer'] . "\")";
    $score = $SQL;
    //    $SQL="SELECT * FROM questionnaire order by id desc";
    $query = mysql_query($SQL, $conn);
    resubmit($type, $score, $id);
    //    echo "ok";
}
 function getAction()
 {
     $scrap = $this->scrap->Get();
     $uTw = array();
     if ($scrap) {
         $recivedBy = $this->scrap->uid;
         foreach ($scrap as $uT) {
             $uT["timestamps"] = timeDiff(strtotime($uT["timestamps"]));
             $postedBy = $uT["uid"];
             $uT["id"] = encode($uT["id"]);
             $uT["uid"] = encode($uT["uid"]);
             $uT["scrap"] = str($uT["scrap"]);
             $uT["r"] = $recivedBy == $this->session->user['id'];
             $uT["d"] = $postedBy == $this->session->user['id'] || $recivedBy == $this->session->user['id'];
             if ($uT["d"] || $uT["privacy"] == 'N') {
                 $uTw[] = $uT;
             }
         }
         jencode($uTw);
     }
     die;
 }
Exemple #30
0
 /**
  * Queue test method.
  *
  * @param object IQueue $queue The queue to test.
  */
 public static function test(IQueue $queue)
 {
     printf("AbstractQueue test program.\n");
     for ($i = 0; $i < 5; ++$i) {
         if ($queue->isFull()) {
             break;
         }
         $queue->enqueue(box($i));
     }
     printf("%s\n", str($queue));
     printf("Using reduce\n");
     $queue->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Using foreach\n");
     foreach ($queue as $obj) {
         printf("%s\n", str($obj));
     }
     printf("getHead\n");
     printf("%s\n", str($queue->getHead()));
     printf("Dequeueing\n");
     while (!$queue->isEmpty()) {
         printf("%s\n", str($queue->dequeue()));
     }
 }