小编And*_*ndy的帖子

cURL和PHP:停止输出到屏幕

这个PHP脚本将所有数据减去XML打印到浏览器(我使用的是Chrome).如何将输出抑制到屏幕?

<html>
<head><title>Twitcap</title></head>
<body>
<?php
  function twitcap()
  {
    // Set your username and password
    $user = 'osoleve';
    $pass = '********';

    $ch = curl_init("https://twitter.com/statuses/friends_timeline.xml");

    curl_setopt($ch,CURLOPT_HEADER,0); // We want to see the header
    curl_setopt($ch,CURLOPT_TIMEOUT,30); // Set timeout to 30s
    curl_setopt($ch,CURLOPT_USERPWD,$user.':'.$pass); // Set uname/pass
    curl_setopt($ch,CURLOPT_RETURNTRANSER,1); // Do not send to screen

    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);

    $xml = new SimpleXMLElement( curl_exec($ch) );
    curl_close($ch);

    return $xml;
  }

  $content = twitcap();
  echo "Hello, world.<br /><br />";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

php xml twitter curl

30
推荐指数
1
解决办法
2万
查看次数

(随机)Common Lisp不是随机的吗?

好的,最后的问题,我将在Common Lisp完成我的猜数游戏!:D无论何时游戏开始(或者在第一场比赛后开始新游戏),都会调用以下函数.

;;; Play the game
(defun play ()
    ;; If it's their first time playing this session,
    ;; make sure to greet the user.
    (unless (> *number-of-guesses* 0)
        (welcome-user))
    ;; Reset their remaining guesses
    (setq *number-of-guesses* 0)
    ;; Set the target value
    (setq *target*
        ;; Random can return float values,
        ;; so we must round the result to get
        ;; an integer value.
        (round
            ;; Add one to the result, because
            ;; (random 100) yields a number between
            ;; …
Run Code Online (Sandbox Code Playgroud)

lisp random sbcl common-lisp

14
推荐指数
1
解决办法
6776
查看次数

线性搜索算法优化

我刚刚完成了计算机科学1的作业问题(是的,这是家庭作业,但是听我说!).现在,作业完成并且有效,所以我不需要帮助.我的问题涉及我正在使用的算法的效率(我们尚未对算法效率进行评分,我只是非常好奇).

我对目前提出的函数使用线性搜索算法的修改版本(即我想出了,全部由我自己!),以检查如何在给定的彩票多的数字相匹配的中奖号码,假设两机票上的数字和绘制的数字按升序排列.我想知道,有没有办法让这个算法更有效率?

/*
 * Function: ticketCheck
 *
 * @param struct ticket
 * @param array winningNums[6]
 *
 * Takes in a ticket, counts how many numbers
 * in the ticket match, and returns the number
 * of matches.
 *
 * Uses a modified linear search algorithm,
 * in which the index of the successor to the
 * last matched number is used as the index of
 * the first number tested for the next ticket value.
 *
 * @return int numMatches …
Run Code Online (Sandbox Code Playgroud)

c algorithm performance

11
推荐指数
2
解决办法
3248
查看次数

Common Lisp错误未被理解

我试图在Lisp中编写一个数字猜谜游戏作为一个耗时的项目.但是,当我尝试使用SBCL加载程序时,我收到以下错误:

debugger invoked on a SB-C::INPUT-ERROR-IN-COMPILE-FILE in thread #<THREAD
                                                                    "initial thread" RUNNING
                                                                    {AA14959}>:
  READ failure in COMPILE-FILE at character 477:
    end of file on #<SB-SYS:FD-STREAM
                     for "file /home/andy/Dropbox/Programming/Common Lisp/number-game.lisp"
                     {B4F45F9}>

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE] Ignore runtime option --load "number-game.lisp".
  1: [ABORT   ] Skip rest of --eval and --load options.
  2:            Skip to toplevel READ/EVAL/PRINT loop.
  3: [QUIT    ] Quit SBCL (calling #'QUIT, killing …
Run Code Online (Sandbox Code Playgroud)

lisp sbcl common-lisp

7
推荐指数
1
解决办法
2504
查看次数

通过PHP访问Twitter API

我正在努力使我的脚本网格与OAuth而不是Basic Auth,我被卡住了.到目前为止,我现在只是在进行身份验证,但我无法做到这一点.这段代码:

<?php

  include 'config.php';
  include 'twitteroauth/twitteroauth.php';

  // Use config.php credentials
  $conn = new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET);

  // Use application's registered callback URL
  // And get temporary credentials using made connection
  $tempCred = $conn->getRequestToken();

  // Use 'Sign in with Twitter'
  // for Redirect URL
  $rURL = $conn->getAuthorizeURL($tempCred);

  echo '<a href="'.$rURL.'">1. Click me first!</a><br />';
Run Code Online (Sandbox Code Playgroud)

工作得很好.但是,当我进入这一步时:

  // Build a new TwitterOAuth connection
  // Now that the app has verified credentials
  $conn = new TwitterOAuth(CONSUMER_KEY,
                           CONSUMER_SECRET,
                           $_SESSION['oauth_token'],
                           $_SESSION['oauth_token_secret']);

  // Get non-temporary credentials from Twitter …
Run Code Online (Sandbox Code Playgroud)

php twitter oauth

6
推荐指数
1
解决办法
1841
查看次数

使用链接列表添加和减去Bigints

我差不多完成了这项任务,这让我很伤心.这是我关于三个不同部分的第三篇文章,老实说我很尴尬,因为我正在努力解决这个问题.

赋值本身是一个程序,使用链表执行大整数的加法和减法(我慢慢开始讨厌链接列表,在Lisp之外).除了实际的加法和减法之外,现在一切似乎都在起作用.我不确定它是否是算术函数,因为它们之前有点工作(但从不100%),但是与S/O社区一起检查并没有什么坏处(通常我不会要求这么多帮助完成作业,因为我更喜欢自己解决问题,但这是一个非常糟糕和忙碌的一周,截止日期即将来临.

我写的算术函数如下,任何人都可以帮我挑出错误吗?

/*
 * Function add
 *
 * @Paramater STRUCT* Integer
 * @Parameter STRUCT* Integer
 *
 * Takes two linked lists representing
 * big integers stored in reversed order,
 * and returns a linked list containing
 * the sum of the two integers.
 *
 * @Return STRUCT* Integer
 * 
 * TODO Comment me
 */
struct integer* add( struct integer *p, struct integer *q )
{
    int carry = 0;

    struct integer *sHead, *sCurr;
    struct integer *pHead, *qHead;

    pHead = …
Run Code Online (Sandbox Code Playgroud)

c linked-list

5
推荐指数
1
解决办法
6049
查看次数

检测任意字符串的字符集/脚本

我正在清理实体(人员、组织等)的“个人资料”数据库,个人资料的一个这样的部分是用 UTF-8 编码的本地脚本(例如泰语)中的个人姓名. 在之前的数据结构中,我们没有捕获名称的字符集,因此现在我们有更多的无效值记录,无法手动查看。

此时我需要做的是,通过脚本,确定任何给定名称的语言/脚本。使用以下示例数据集:

Name: "??????????"
Script: NULL

Name: "?????"
Script: NULL
Run Code Online (Sandbox Code Playgroud)

我需要结束

Name: "??????????"
Script: Thai

Name: "?????"
Script: Amharic
Run Code Online (Sandbox Code Playgroud)

我不需要翻译名称,只需确定它们的脚本即可。是否有一种既定的技术可以解决此类问题?

utf-8

5
推荐指数
1
解决办法
187
查看次数

在CSS中嵌入PHP

我正在尝试创建一个可变背景,其中图像会根据一天中的时间而变化.我已经使用过这段代码,但是我在某个地方做了一些事情并没有注意到功能已经崩溃了.有人可以向我解释为什么这不起作用?

<html>
<?php

    function day()
    {
        if ( $hour >= 6 && $hour <= 18 )
        {
        return 1;
        } else { return 0; }
    }

?>

<style type="text/css">

body
{

    background-image: url('<?php echo (day() ? 'images/day_sheep.jpg'
                                             : 'images/night_sheep.jpg'); ?>');
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-color: silver
}

a {text-decoration:none;}
a:link {color:#ff0000;}
a:visited {color:#0000FF;}
a:hover {text-decoration:underline;}

</style>

</html>
Run Code Online (Sandbox Code Playgroud)

css php

4
推荐指数
1
解决办法
1009
查看次数

PyQt入门

我正在使用Python和Qt测试快速GUI编程中的一些示例,但在这里或其他地方遇到了绊脚石.当我复制到下面的练习时(逐字,从书中):

import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)

try:
    due = QTime.currentTime()
    message = "Alert!"

    if len(sys.argv) < 2:
        raise ValueError

    hours, mins = sys.argv[1].split(":")
    due = QTime(int(hours), int(mins))

    if not due.isValid():
        raise ValueError
    if len(sys.argv) > 2:
        message = " ".join(sys.argv[2:])

except ValueError:
    message = "Usage: alert.pyw HH:MM [optional message*]" # 24hr Clock

while QTime.currentTime() < due:
    time.sleep(20) # 20 seconds

label = QLabel("<font color=red size=72><b>" + …
Run Code Online (Sandbox Code Playgroud)

python qt pyqt

4
推荐指数
1
解决办法
5026
查看次数

检查Tic-Tac-Toe的胜利

好的,所以我已经完成了我的最新项目,一个(不可否认的是不太好)在Common Lisp中实现了Tic Tac Toe(整个程序可以在这里找到),但我最后一部分被困在了最后一个部分.我无法弄清楚如何获得检查胜利者工作的功能.函数(及其从属函数)如下所示:

(defun check-for-win ()
    (cond ((is-line 1 2 3) t)
            ((is-line 1 4 7) t)
            ((is-line 1 5 9) t)
            ((is-line 2 5 8) t)
            ((is-line 3 6 9) t)
            ((is-line 3 5 7) t)
            ((is-line 4 5 6) t)
            ((is-line 7 8 9) t))
    nil)

(defun is-line (a b c)
    (let ((a (aref *board* (- a 1)))
              (b (aref *board* (- b 1)))
              (c (aref *board* (- c 1))))
        (if (and 
                  (eql a b) …
Run Code Online (Sandbox Code Playgroud)

lisp common-lisp

4
推荐指数
1
解决办法
1165
查看次数

标签 统计

common-lisp ×3

lisp ×3

php ×3

c ×2

sbcl ×2

twitter ×2

algorithm ×1

css ×1

curl ×1

linked-list ×1

oauth ×1

performance ×1

pyqt ×1

python ×1

qt ×1

random ×1

utf-8 ×1

xml ×1