小编Zna*_*kus的帖子

最快的插入方式,如果不存在,则在MySQL中获取id

有这张桌子.

| id | domain |
Run Code Online (Sandbox Code Playgroud)

id是主键.domain是一个独特的钥匙.

我想要:

  1. 如果新域已不存在,请插入新域.
  2. 获取该id域名.

现在我这样做:

INSERT INTO domains
SET domain = 'exemple.com'
ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id)
Run Code Online (Sandbox Code Playgroud)

然后PDO::lastInsertId()得到id.

但关键是这个速度尽可能快,所以我会问:我可以用更好的方式做到这一点吗?

mysql optimization performance pdo lastinsertid

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

Raspberry PI上的NodeJS中的long setTimeout

我有一个奇怪的问题,即长时间的setTimeout不会在Raspberry PI上触发,但它们在Ubuntu/x64和OSX上运行.

'use strict';

const delay = 1000 * 3600 * 8;
const date = new Date();

date.setTime(new Date().getTime() + delay);
console.log('Alarm set to', date.toString());

setTimeout(function () {
    console.log('Alarm!', new Date());
}, delay);
Run Code Online (Sandbox Code Playgroud)

此代码将Alarm!在Ubuntu/x64上8小时后回显,但它永远不会在RPI上触发.

作品:

  • Ubuntu的/ 64
  • OSX

不起作用:

  • RPI b +与Raspian 7(节点6.1)
  • 带有Raspian 8的RPI 3(节点4.4.4,6.0和6.1)

根据ps脚本Sl状态:Interruptible sleep (waiting for an event to complete), is multi-threaded (using CLONE_THREAD, like NPTL pthreads do).

在这个代码的更复杂版本中,我可以通过Web UI控制脚本,"警报"将在设置的时间后关闭,但仅在我访问Web UI时(唤醒应用程序?).

这是一个NodeJS错误还是我在做一些时髦的事情?

node.js raspberry-pi

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

Python中的For循环

在Python中执行此操作的最佳方法是什么?

for (v = n / 2 - 1; v >= 0; v--)
Run Code Online (Sandbox Code Playgroud)

我实际上是先尝试过谷歌,但据我所知,唯一的解决方案就是使用while.

python for-loop

5
推荐指数
3
解决办法
566
查看次数

首先使用:优化jQuery选择器

我有这种感觉$('.class:first')比跑得快$('.class').因此,只要我知道.class子集中只有一个,我就用它了.

是否:first使查询运行得更快,还是不必要?

optimization jquery jquery-selectors

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

PEAR错误require_once(Structures/Graph/Node.php):无法打开流

我正在尝试使用PEAR安装PHPUnit.无论命令我运行像pear install phpunit/PHPUnit,pear install Structures_Graph,pear upgrade,pear upgrade --force --alldeps...它总是以结束

警告:require_once(Structures/Graph/Node.php):无法打开流:第37行PEAR\Structures\Graph.php中没有此类文件或目录PHP警告:require_once(Structures/Graph/Node.php):未能open stream:第37行的C:\ wamp\bin\php\php5.3.4\PEAR\PEAR\Structures\Graph.p hp中没有这样的文件或目录

警告:require_once(Structures/Graph/Node.php):无法打开流:第37行的C:\ wamp\bin\php\php5.3.4\PEAR\PEAR\Structures\Graph.php中没有此类文件或目录PHP致命错误:require_once():无法在C:\ wamp\bin\php\php5中打开所需的'Structures/Graph/Node .php'(include_path ='C:\ wamp\bin\php\php5.3.4\pear')第37行的.3.4\PEAR\PEAR\Structures\Graph.php

致命错误:require_once():在C:\ wamp\bin\php\php5中打开所需的'Structures/Graph/Node.php'(include_path ='C:\ wamp\bin\php\php5.3.4\pear')失败第37行的.3.4\PEAR\PEAR\Structures\Graph.php

我尝试了这个问题的答案,并将ZIP下载并解压缩到C:\ wamp\bin\php\php5.3.4\PEAR\PEAR,但这只是替换了之前使用的Structures_Graph错误.

PEAR与go-pear.bat一起安装在Windows 7,PHP 5.3.4上的wamp安装中.

我还能尝试做些什么呢?

更新:应该说我已经尝试更改上面错误中报告的include_path,但没有成功.试图改变两者php.inipear.bat.

php pear phpunit

5
推荐指数
2
解决办法
5208
查看次数

容器外的元素而不创建滚动条

如果窗口太窄,我可以让横幅到达其容器之外,而不创建水平滚动条吗?

我以为我以前用负边距做过这件事,但现在无法让它发挥作用。

演示:http : //jsfiddle.net/Znarkus/s95uz/

<div id="main">
    <div id="banner">I want this to not create a horizontal scrollbar, when the window/frame is too narrow.</div>
    <div id="content">

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

?

css scrollbar

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

带有多个输入/输出文件夹的指南针

我想在一个命令中编译/观看Compass/SCSS文件,分布在多个文件夹中.据我所知,没有办法配置多个SCSS文件夹,再加上单独的CSS输出文件夹.

add_import_path几乎是我需要的,但我没有看到设置sass_dir每个导入路径的方法.

有没有办法做到这一点?
这个Quora的回答说没有,但我仍然抱有希望:)


更新:示例目录结构:

  • users/user1/css/< - scss目录
  • users/user1/css/generated/< - 生成的css目录
  • 用户/用户2/CSS /
  • 用户/用户2/CSS /生成/
  • 主题/ THEME1/CSS /
  • 主题/ THEME1/CSS /生成/
  • 主题/ THEME2/CSS /
  • 主题/ THEME2/CSS /生成/

compass-sass

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

/ etc/hosts不会影响PHP

我遇到了hosts文件和PHP的问题.运行PHP代码时root,将读取/ etc/hosts中的条目.但不是以我的用户或apache运行代码时.

root@server:/# cat /etc/hosts
127.0.0.1       mydomain.com

root@server:/# php -r "echo gethostbyname('mydomain.com');"
127.0.0.1

markus@server:/$ php -r "echo gethostbyname('mydomain.com');"
xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

php linux hosts

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

Nodejs - 将输出流输出到浏览器

var http = require("http");
var sys = require('sys')
var filename = process.ARGV[2];
var exec = require('child_process').exec;
var com = exec('uptime');


http.createServer(function(req,res){
  res.writeHead(200,{"Content-Type": "text/plain"});
  com.on("output", function (data) {
    res.write(data, encoding='utf8');
  });  
}).listen(8000);
sys.puts('Node server running')
Run Code Online (Sandbox Code Playgroud)

如何将数据流式传输到浏览器?

node.js

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

如何使用php中的curl将访问密钥作为HTTP标头传递

如何在PHP中发送下面提到的CURL请求?我将在php中使用哪些功能?

$ curl -H 'X-Sifter-Token: 343b1b831066a40e308e0af92e0f06f0' \
-H 'Accept: application/json' \ 
'http://example.sifterapp.com/api/projects'
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这段代码..但是它不起作用..请做必要的

$curlString = "";

$curlString .= "-H \"X-Sifter-Token: 343b1b831066a40e308e0af92e0f06f0\" \";

$curlString .= "-H \"Accept: application/json\" \";

$url="http://example.sifterapp.com/api/projects";


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlString);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else {
// Show me the result
var_dump($data);
curl_close($ch);
}
Run Code Online (Sandbox Code Playgroud)

php api rest

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