我一直在使用我的MySQL数据库的索引,而现在却从不正常了解到他们.通常我会在我要搜索的任何字段上放置索引或使用WHERE子句进行选择,但有时它看起来不是那么黑白.
MySQL索引的最佳实践是什么?
示例情况/困境:
如果一个表有六列并且所有这些列都是可搜索的,那么我应该将它们全部索引还是不索引?
.
索引的负面性能影响是什么?
.
如果我有一个VARCHAR 2500列可以从我的网站的部分搜索,我应该索引吗?
所以我正在尝试制作一个下载webcomics的Python脚本,并将它们放在桌面上的文件夹中.我在这里发现了一些类似的程序,但是没有什么比我需要的更好.我发现最相似的那个就在这里(http://bytes.com/topic/python/answers/850927-problem-using-urllib-download-images).我尝试使用此代码:
>>> import urllib
>>> image = urllib.URLopener()
>>> image.retrieve("http://www.gunnerkrigg.com//comics/00000001.jpg","00000001.jpg")
('00000001.jpg', <httplib.HTTPMessage instance at 0x1457a80>)
Run Code Online (Sandbox Code Playgroud)
然后我在计算机上搜索了一个文件"00000001.jpg",但我找到的只是它的缓存图片.我甚至不确定它是否将文件保存到我的电脑上.一旦我理解了如何下载文件,我想我知道如何处理剩下的文件.基本上只是使用for循环并将字符串拆分为'00000000'.'jpg'并将'00000000'递增到最大数字,我必须以某种方式确定.有关最佳方法或如何正确下载文件的任何建议吗?
谢谢!
编辑6/15/10
这是完成的脚本,它将文件保存到您选择的任何目录中.由于一些奇怪的原因,文件没有下载,他们只是做了.任何关于如何清理它的建议都将非常感激.我目前正在研究如何找到网站上存在的许多漫画,以便我可以获得最新的漫画,而不是在引发一定数量的异常后退出程序.
import urllib
import os
comicCounter=len(os.listdir('/file'))+1 # reads the number of files in the folder to start downloading at the next comic
errorCount=0
def download_comic(url,comicName):
"""
download a comic in the form of
url = http://www.example.com
comicName = '00000000.jpg'
"""
image=urllib.URLopener()
image.retrieve(url,comicName) # download comicName at URL
while comicCounter <= 1000: # not the most elegant solution
os.chdir('/file') # set …Run Code Online (Sandbox Code Playgroud) 我试图找到运行具有自己范围的for循环的最快方法.我比较的三种方法是:
var a = "t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t".split();
// lodash .each -> 1,294,971 ops/sec
lodash.each(a, function(item) { cb(item); });
// native .forEach -> 398,167 ops/sec
a.forEach(function(item) { cb(item); });
// native for -> 1,140,382 ops/sec
var lambda = function(item) { cb(item); };
for (var ix = 0, len = a.length; ix < len; ix++) {
lambda(a[ix]);
}
Run Code Online (Sandbox Code Playgroud)
这是在OS X上的Chrome 29上.您可以在此处自行运行测试:
Lodash的.each速度几乎是原生的两倍.forEach?而且,它比平原更快for?巫术?黑魔法?
我有一个我希望全球可用的脚本.我用标准的hashbang开始了它:
#! /usr/bin/env python
Run Code Online (Sandbox Code Playgroud)
并将其链接到我的virtualenv的bin目录:
~/environments/project/env/bin/myscript
Run Code Online (Sandbox Code Playgroud)
并将该目录添加到我的路径中.当我运行命令时:
myscript
Run Code Online (Sandbox Code Playgroud)
我的其中一个库出现导入错误.但是,如果我激活虚拟环境并运行脚本,它将按预期工作.
我已经排除了符号链接的问题(我也试过在bin文件夹中移动脚本).我也尝试用python运行脚本
python ~/environments/project/env/bin/myscript
Run Code Online (Sandbox Code Playgroud)
以前我使用的是激活环境然后运行我的脚本的脚本,但我觉得从这个文件夹运行的脚本应该与virtualenv的解释器和site-packages一起运行.任何关于为什么这可能不起作用的想法或某些方法我可以调试这个?
我目前正在我的app.js/server.js文件中提供所有我的HTML,如下所示:
app.get('/', function(req, res) {
res.render('index.html');
});
app.get('/about', function(req, res) {
res.render('about.html');
});
app.get('/projects', function(req, res) {
res.render('projects.html');
});
Run Code Online (Sandbox Code Playgroud)
我想如果我有15个以上的HTML页面,这可能不是调用它们的最佳方式.有没有更好的方法从另一个文件或位置提供服务,并使用导出或其他东西只能在app.js上调用一个函数或其他东西.它可能是路由的用途,但也许我不太了解它.
(添加了同一文件中的更多代码)
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/public');
// used below code to render html files
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.use(express.favicon("public/img/favicon.ico"));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
Run Code Online (Sandbox Code Playgroud) 我用过pm2我的Node.js脚本,我喜欢它.
现在我有一个python脚本,它收集EC2上的流数据.有时脚本会爆炸,我希望进程管理器像pm2一样重启.
对于python,是否有与pm2相同的东西?我一直在四处搜寻,找不到任何东西.
这是我的错误
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 430, in filter
self._start(async)
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 346, in _start
self._run()
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 286, in _run
raise exception
AttributeError: 'NoneType' object has no attribute 'strip'
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90:
Run Code Online (Sandbox Code Playgroud)
这是一个简单的数据收集脚本
class StdOutListener(StreamListener):
def on_data(self, data):
mydata = json.loads(data)
db.raw_tweets.insert_one(mydata)
return True
def on_error(self, status):
mydata = json.loads(status)
db.error_tweets.insert_one(mydata)
if __name__ == '__main__':
#This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pycharm进行django开发,我无法忍受白色背景.有人可以提供下载模式文件的地方吗?手动切换所有颜色既繁琐又耗时.
是否可以使用科莫多图模式?
如何覆盖Bootstrap 3上的媒体查询?
例如,我有我的自定义样式表,我想覆盖最小宽度:768px到最小宽度:1200px的媒体查询.
每次我这样做都不会应用设置.但是,如果我在Bootstrap自己的css文件上更改了该媒体查询,那么它可以工作!
有关更多说明:
bootstrap.css:
@media (min-width: 768px) {
.navbar-header {
float: left;
}
}
Run Code Online (Sandbox Code Playgroud)
我的custom.css:
@media (min-width: 1200px) {
.navbar-header {
float: left;
}
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我.
从Firefox开发者网站,我知道Firefox使用
objectURL = window.URL.createObjectURL(file);
Run Code Online (Sandbox Code Playgroud)
获取文件类型的URL,但在chrome和其他webkit浏览器中我们有window.webkitURL.createObjectURL()检测url.
我不知道如何基于浏览器引擎交换这些功能,我需要在两种浏览器上工作(Chrome和firefox)
https://developer.mozilla.org/en/DOM/window.URL.createObjectURL
我正在尝试优化我的 Python 代码。之间:
y = x*x
Run Code Online (Sandbox Code Playgroud)
或者
y = x**2
Run Code Online (Sandbox Code Playgroud)
如果我需要在一个速度关键的程序中进行一万亿次迭代,我应该选择哪一个?
python ×5
javascript ×2
node.js ×2
performance ×2
cpu-speed ×1
css ×1
dom ×1
express ×1
html ×1
html5 ×1
indexing ×1
lodash ×1
mysql ×1
pycharm ×1
python-2.7 ×1
rundeck ×1
static-files ×1
themes ×1
ubuntu ×1
urllib ×1
urllib2 ×1
virtualenv ×1