我正在尝试创建自定义REST API.我创建了自己的模块Custom/Restapi.Custom [Namespace],Restapi [Module name].
在etc文件夹中,我创建了config.xml和api2.xml.以下是代码 - :
config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Custom_Restapi>
<version>0.1.0.0</version>
</Custom_Restapi>
</modules>
<global>
<models>
<restapi>
<class>Custom_Restapi_Model</class>
</restapi>
</models>
</config>
Run Code Online (Sandbox Code Playgroud)
api2.xml
<config>
<api2>
<resource_groups>
<restapi translate="title" module="Custom_Restapi">
<title>Custom Rest API</title>
<sort_order>10</sort_order>
</restapi>
</resource_groups>
<resources>
<restapi translate="title" module="Custom_Restapi">
<group>restapi</group>
<model>restapi/api2_restapi</model>
<title>Testing My Rest API</title>
<sort_order>10</sort_order>
<privileges>
<admin>
<create>1</create>
<!-- <retrieve>1</retrieve>
<delete>1</delete>-->
</admin>
<!-- <customer>
<create>1</create>
<retrieve>1</retrieve>
<delete>1</delete>
</customer>
<guest>
<create>1</create>
<retrieve>1</retrieve>
<delete>1</delete>
</guest>-->
</privileges>
<routes>
<route_entity>
<route>/custom/createwebsite/:s</route>
<action_type>entity</action_type>
</route_entity>
</routes>
<versions>1</versions>
</restapi>
</resources>
</api2>
Run Code Online (Sandbox Code Playgroud)
模型目录结构
应用程序\代码\本地\自定义\ RESTAPI …
在Chrome的网络开发者工具中,可以通过按下来随时中断F8.
通常,我想通过按下F8来在拖放操作期间断开并检查元素.但这不起作用.
在没有运行自定义脚本的情况下是否有原生的Chrome方式快捷方式?
debugging drag-and-drop google-chrome google-chrome-devtools
我已经能够BST通过几个来源找到几个自平衡的细节,但是我没有找到任何好的描述,详细描述哪个最适合在不同的情况下使用(或者如果它真的无关紧要).
我想要一个BST最适合存储超过一千万个节点的东西.节点的插入顺序基本上是随机的,我永远不需要删除节点,因此插入时间是唯一需要优化的东西.
我打算用它来存储益智游戏中先前访问过的游戏状态,以便我可以快速检查是否已经遇到过以前的配置.
如何以ajax方式发布表单数据,而不使用jquery或其他库.
我想定义一个ajaxForm函数,它可以序列化表单数据和AJAX帖子,然后通过javascript回调.
如果我有以下表格:
<form action="url" method="POST">
<table>
<tr><td>label...</td><td><input name="input1" type="text"/></td></tr>
<tr><td>label...</td><td><input name="input2" type="checkbox"/></td></tr>
<tr><td>label...</td><td><select name="input3"><options....></select></td></tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
我通过javascript获取了表单元素,然后将表单元素和回调函数传递给ajaxForm(表单,回调)函数.
任何人都可以举一个例子吗?非常感谢....
我已将jquery表单插件迁移到纯javascript.我很高兴与你们分享.
https://github.com/guileen/ajaxform.js
button.onclick = function(){
ajaxForm(form, function(xmlhttp){
alert(xmlhttp.status);
alert(xmlhttp.responseText);
});
}
Run Code Online (Sandbox Code Playgroud) 在处理另一个问题的答案时,出现了一个奇怪的错误,该错误与event匿名函数中可用的对象有关而没有被传入.在Chrome中,下面的工作正常,但FF会抛出错误.
$(document).ready(function() {
$("#uspsSideboxTrackingClose").click(function() {
event.preventDefault();
console.log(event);
});
});
Run Code Online (Sandbox Code Playgroud)
铬:

火狐:
ReferenceError:未定义事件
众所周知
$("#uspsSideboxTrackingClose").click(function(event) { .. }
Run Code Online (Sandbox Code Playgroud)
适用于两种浏览器.这是违规代码.这是Chrome或FF的错误,还是两种浏览器的预期行为?哪个浏览器是对的?
我想肯定地知道YouTube视频是否是宽屏或不使用v3 API.有许多旧视频的比例为4:3,因此我需要检测到这一点.
这可以通过API v2实现,但现在正式退役.以下是API v3文档.
API调用看起来像这样:
https://www.googleapis.com/youtube/v3/videos?id=[VIDEOID]&part=snippet&key=[DEVELOPERKEY]
Run Code Online (Sandbox Code Playgroud)
此外,缩略图数据始终返回4:3的尺寸,因此这没有帮助.这是一个例子:
[thumbnails] => Array
(
[default] => Array
(
[url] => https://i.ytimg.com/vi/nnnnnnnnn/default.jpg
[width] => 120
[height] => 90
)
...
)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
(我目前黑客通过在缩略图那里搬弄是非4黑条分析像素这样的:3个视频会)
以下是4:3比例的视频示例:
https://www.youtube.com/watch?v=zMJ-Dl4eJu8(老武侠视频)
和16:9中的一个:
https://www.youtube.com/watch?v=7O2Jqi-LhEI(一个新的锻炼视频)
更新:一个有希望的建议是探索,fileDetails.videoStreams[].aspectRatio但似乎这只适用于视频所有者.否则请求fileDetails结果
请求无法访问用户评级信息.可能会发生此错误,因为请求未得到适当授权
目标:我正在尝试通过 htaccess 设置两个标头:
X-Robots-Tag: noindex, nofollow
Location: http://example.com/foo
Run Code Online (Sandbox Code Playgroud)
PoC:在 PHP 中可以做到这一点,效果很好:
header( "X-Robots-Tag: noindex, nofollow", true );
header( "Location: " . $url, 302 );
Run Code Online (Sandbox Code Playgroud)
问题:在我的.htaccess文件中,我有这个:
# Do not let robots index anything from /out/
RewriteCond %{REQUEST_URI} ^/?out/?
Header set X-Robots-Tag "noindex, nofollow"
...
# Redirect /out/example/ type links
RewriteRule ^/?out/example/(.*)$ "http://example.com/$1" [R=302,L]
Run Code Online (Sandbox Code Playgroud)
我确定在某处我没有看到一个简单的错误,但是如果我检查http://localhost/out/example/foo的Location标头,标头已设置,但X-Robots-Tag不是。
HTTP/1.1 302 Found
Date: Wed, 08 Jun 2016 23:59:18 GMT
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Connection: …Run Code Online (Sandbox Code Playgroud) 无论我尝试什么,使用无头 Chrome 60(和 59)的全页屏幕截图的最大高度为 16,348 像素。
这不是内存问题。没有段错误,也没有,例如,FATAL:memory_linux.cc(35) Out of memory.消息。没有任何。捕获屏幕截图是“成功的”。更改屏幕截图格式 - PNG 或 JPEG - 没有影响。
屏幕截图的宽度可能会有所不同,但保存的屏幕截图的高度始终限制在 16,348 像素。例子,
1600x16384、1200x16384、2400x16384等
我正在使用这个最少的代码(完整源代码)进行放大截图:
const upscale = 2;
const viewportWidth = 1200;
const viewportHeight = 800;
....
// Set up viewport resolution, etc.
const deviceMetrics = {
width: viewportWidth,
height: viewportHeight,
deviceScaleFactor: 0,
mobile: false,
fitWindow: false,
scale: 1 // Relative to the upscale
};
await Emulation.setDeviceMetricsOverride(deviceMetrics);
await Emulation.setVisibleSize({width: viewportWidth, height: viewportHeight});
await Emulation.setPageScaleFactor({pageScaleFactor: upscale});
// Navigate to target …Run Code Online (Sandbox Code Playgroud) 假设我有两个bash函数:
dock() { sudo docker $@ ;}
Run Code Online (Sandbox Code Playgroud)
和
dock-ip() { sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $@ ;}
Run Code Online (Sandbox Code Playgroud)
如何使用第二个函数进行 bash自动完成?
使用第一个,就像添加一样简单:
_completion_loader docker; complete -F _docker dock
Run Code Online (Sandbox Code Playgroud)
这不适用于第二个.Docker的自动完成源位于/usr/share/bash-completion/completions/dockerDebian Stretch上.我有更多的函数,如dock-run,dock-exec等等,所以我不想为每个函数编写自定义完成函数.
另外,complete -F _docker_container_inspect dock-ip只是部分工作; tab仅列出容器,而不是完成部分字符串.
研究:
如何自动完成嵌套的多级子命令?< - 需要自定义功能
https://superuser.com/questions/436314/how-can-i-get-bash-to-perform-tab-completion-for-my-aliases < - 仅对顶级命令自动执行
为什么这段代码会导致无限递归?
class Foo {
public static function newFoo() { return new Foo(); }
public function __toString() {
return "{${Foo::newFoo()}}";
}
}
echo new Foo(); // Infinite recursion
new Foo(); // Finishes normally
Run Code Online (Sandbox Code Playgroud)
这是因为__toString()返回一个对象吗?但这是不可能的,因为根据文档
此方法必须返回一个字符串,否则会发出致命的E_RECOVERABLE_ERROR级别错误.(参考)
或者它只是在__toString()方法中无限递归?
php ×3
javascript ×2
.htaccess ×1
ajax ×1
alias ×1
apache ×1
aspect-ratio ×1
autocomplete ×1
bash ×1
centos ×1
debugging ×1
docker ×1
global ×1
http-headers ×1
jquery ×1
magento ×1
node.js ×1
recursion ×1
redirect ×1
rest ×1
screenshot ×1
tostring ×1
youtube ×1
youtube-api ×1