我正在尝试使用php:// stderr来编写日志来工作.我正在使用Slim框架,它@fopen('php://stderr', 'w')用于日志记录,并且真的希望它能够工作.
以下测试用例应该有效,但只有第一个用于:
// 1. error_log - works fine
error_log("Written through the error_log function", 0);
// 2. PHP wrapper, ie php://stderr - does not work
$stderr = fopen( 'php://stderr', 'w' );
fwrite($stderr, "Written through the PHP error stream" );
fclose($stderr);
// 3. PHP wrapper also, different syntax, just to be safe - no effect either
file_put_contents( "php://stderr","Hello World" );
// 4. PHP wrapper, this time using this elusive constant referred to in the manual - result: "Notice: …Run Code Online (Sandbox Code Playgroud) 一个文件应该声明新的符号(类、函数、常量等)并且不会引起其他副作用,或者它应该执行带有副作用的逻辑,但不应该两者都做。
考虑一个 config.php 文件中的这个例子(我自己的):
/**
* Parsing the database URL.
* DATABASE_URL is in the form:
* postgres://user:password@hostname:port/database
* e.g.:
* postgres://u123:pabc@ec2.eu-west-1.compute.amazonaws.com:5432/dxyz
*/
$url = parse_url(getenv('DATABASE_URL'));
define('DB_HOST', $url['host']);
define('DB_NAME', substr($url['path'], 1)); // get rid of initial slash
define('DB_USER', $url['user']);
define('DB_PASSWORD', $url['pass']);
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我实际上没有尊重建议。phpcs理所当然地会抱怨它,因为变量:
FILE: config.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
1 | WARNING | A file should declare new symbols (classes, functions, constants, etc.) and cause no other side …Run Code Online (Sandbox Code Playgroud) 是否有一种简单的方法来扩展下面的代码,以便div.someclass在不存在时自动创建?
d3.select("body").select("div.someclass").selectAll("p")
.data([ 1, 2, 3 ])
.enter()
.append("p")
.text(function (d, i) {
return "index: " + i + ", value: " + d;
});
Run Code Online (Sandbox Code Playgroud)
我还处于学习D3JS的早期阶段.我对它的理解至今是"而不是告诉D3如何做,你告诉D3你想要什么".所以我很惊讶地看到上面的代码需要<div class="someclass"></div>在HTML中声明.
另一种方法是以编程方式插入div:
/** Append HTML placeholder programmatically **/
placeholder = d3.select("body").append("div").attr("class", "someclass");
/** Bind the data to the DOM **/
/** instead of telling D3 how to do something, tell D3 what you want: in the absence of <p>, this will return a virtual selection **/
placeholder.selectAll("p")
.data([ 1, 2, …Run Code Online (Sandbox Code Playgroud) 考虑这个简单的 HTML 块:
<div id="somediv">
<btn id="somebutton">Abc</btn>
<div class="nested">
<span id="span1">Blah blah blah</span>
<span id="span2">Bleh bleh bleh</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想使用 D3JS 动态地重新创建它。
这适用于此目的:
(function() {
var somediv = d3.select( 'body' ).append( 'div' ).attr( 'id', 'somediv' );
somediv.append( 'btn' )
.attr( 'id', 'somebutton' )
.html( 'Abc' );
var nested = somediv.append( 'div' )
.attr( 'class', 'nested' );
nested.append( 'span' ).attr( 'id', 'span1' ).html( 'Blah blah blah' );
nested.append( 'span' ).attr( 'id', 'span2' ).html( 'Bleh bleh bleh' );
})();
Run Code Online (Sandbox Code Playgroud)
……然而,它非常冗长,有四个命令和两个临时变量……最重要的是,它不容易阅读——不喜欢它。
我正在寻找一种在单个命令中执行此操作的方法。
到目前为止,我有这个: …
我使用 Postgres 一段时间了,但对 PL/pgSQL 完全陌生。
\n\n我正在努力让基本的for 循环发挥作用。
\n\n这工作正常:
\n\n-- Without SELECT\nDO $$\nBEGIN \n FOR counter IN 1..6 BY 2 LOOP\n RAISE NOTICE 'Counter: %', counter;\n END LOOP;\nEND; $$;\nRun Code Online (Sandbox Code Playgroud)\n\n但我真正想要的是迭代查询的结果SELECT。
我一直遇到这个错误:
\n\n\n\n\n查询错误:错误:行循环的循环变量必须是记录或行变量或标量变量列表
\n
对我来说听起来很晦涩,谷歌搜索也没有帮助。
\n\n我想使用我自己的数据中的一个表(我希望使用 a SELECT * FROM mytable WHERE \xe2\x80\xb9whatever\xe2\x80\xba),但我意识到我什至无法让for 循环处理更简单的 data。
拿着它:
\n\n-- with a SELECT\nDO $$\nBEGIN \nRAISE NOTICE 'Get ready to be amazed\xe2\x80\xa6';\nFOR target IN …Run Code Online (Sandbox Code Playgroud) OpenAI 提供了一个 Python 客户端,目前版本为 0.27.8,它同时支持 Azure 和 OpenAI。
\n以下是如何使用它为每个提供商调用 ChatCompletion 的示例:
\n# openai_chatcompletion.py\n\n"""Test OpenAI\'s ChatCompletion endpoint"""\nimport os\nimport openai\nimport dotenv\ndotenv.load_dotenv()\nopenai.api_key = os.environ.get(\'OPENAI_API_KEY\')\n\n# Hello, world.\napi_response = openai.ChatCompletion.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "user", "content": "Hello!"}\n ],\n max_tokens=16,\n temperature=0,\n top_p=1,\n frequency_penalty=0,\n presence_penalty=0,\n)\n\nprint(\'api_response:\', type(api_response), api_response)\nprint(\'api_response.choices[0].message:\', type(api_response.choices[0].message), api_response.choices[0].message)\nRun Code Online (Sandbox Code Playgroud)\n和:
\n# azure_openai_35turbo.py\n\n"""Test Microsoft Azure\'s ChatCompletion endpoint"""\nimport os\nimport openai\nimport dotenv\ndotenv.load_dotenv()\n\nopenai.api_type = "azure"\nopenai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") \nopenai.api_version = "2023-05-15"\nopenai.api_key = os.getenv("AZURE_OPENAI_KEY")\n\n\n# Hello, world.\n# In addition to the `api_*` properties above, mind the difference in arguments\n# as well …Run Code Online (Sandbox Code Playgroud) 上下文:我正在研究SVG中的信息图.我希望通过动画来使文档变得生动,特别是通过链接动画.我已经熟悉SVG,但最近才开始学习SVG动画.
由于SMIL已被弃用,我正试图在纯SVG中制作动画.
看看这篇文章(特别是最后的Handy Dandy替换参考图表),我的印象是我需要停止使用suc hattributes:
fill="freeze"
repeatCount="indefinite"
begin="hover"
begin="circ-anim.begin + 1s"
Run Code Online (Sandbox Code Playgroud)
...因为他们是SVG SMIL的一部分.
但是,如果我查看Mozilla上的SVG参考,我会在列表中看到<animate>并且<animateTransform>没有关于它们是SMIL的警告,或者需要停止使用它们.
此外,Chrome通常会在控制台中警告不要使用SMIL动画,但在使用<animate>或<animateTransform>(无论是在SVG文档中,还是在包含内联或对象SVG的HTML文档内)时,我都看不到这样的警告.)
长话短说,我不清楚什么是SMIL,什么是纯SVG.任何人都可以对这个主题有所了解吗?我可以使用<animate>和<animateTransform>?