我正在通过ip范围查找国家数千万行.我正在寻找一种更快速的查找方式.
我有这种形式的180K元组:
>>> data = ((0, 16777215, 'ZZ'),
... (1000013824, 1000079359, 'CN'),
... (1000079360, 1000210431, 'JP'),
... (1000210432, 1000341503, 'JP'),
... (1000341504, 1000603647, 'IN'))
Run Code Online (Sandbox Code Playgroud)
(整数是将IP地址转换为普通数字.)
这样做的工作正确,但只需要太长时间:
>>> ip_to_lookup = 999
>>> country_result = [country
... for (from, to, country) in data
... if (ip_to_lookup >= from) and
... (ip_to_lookup <= to)][0]
>>> print country_result
ZZ
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向来更快地进行这种查找吗?使用上述方法,100次查找需要3秒.我想,10M行意味着需要几天时间.
命令:
bigxu@bigxu-ThinkPad-T410 ~/work/lean $ sudo ls
content_shell.pak leanote libgcrypt.so.11 libnotify.so.4 __MACOSX resources
icudtl.dat leanote.png libnode.so locales natives_blob.bin snapshot_blob.bin
Run Code Online (Sandbox Code Playgroud)
大多数时候它是正确的.但有时候它很慢.所以我说它.
命令:
bigxu@bigxu-ThinkPad-T410 ~/work/lean $ strace sudo ls
execve("/usr/bin/sudo", ["sudo", "ls"], [/* 66 vars */]) = 0
brk(0) = 0x7f2b3c423000
fcntl(0, F_GETFD) = 0
fcntl(1, F_GETFD) = 0
fcntl(2, F_GETFD) = 0
......
......
......
write(2, "sudo: effective uid is not 0, is"..., 140sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an …Run Code Online (Sandbox Code Playgroud) 我需要一个在启动时运行的脚本/bin/sh,类似于.bashrcfor /bin/bash.有没有办法做到这一点?
编辑:
我都尝试/etc/profile和~/.profile,我写了echo 'hello world'两个文件.这些都不起作用.当我输入sh控制台时,没有任何东西弹出.
我正在使用ArchLinux.
I am running a python script and using the os library to execute a gsutil command, which is typically executed in the command prompt on Windows. I have some file on my local computer and I want to put it into a Google Bucket so I do:
import os
command = 'gsutil -m cp myfile.csv gs://my/bucket/myfile.csv'
os.system(command)
Run Code Online (Sandbox Code Playgroud)
I get a message like:
==> NOTE: You are uploading one or more large file(s), which would run significantly faster if you enable …
我运行每周一次的crontab,它收集信息并创建一个日志文件.
我有一个脚本,我针对这个每周文件运行,只输出特定的状态行到我的显示器.
#!/bin/sh
# store newest filename to variable
HW_FILE="$(ls -t /home/user/hwinfo/|head -1)"
# List the Site name, hardware group, Redundancy or Health status', and the site divider
grep -i 'Site\|^\*\*\|^Redundancy\|^Health\|^##' /home/user/hwinfo/$HW_FILE
echo "/home/user/hwinfo/"$HW_FILE
exit 0
Run Code Online (Sandbox Code Playgroud)
这是一个示例输出:
Accessing Site: site01
** FANS **
Redundancy Status : Full
** MEMORY **
Health : Ok
** CPUs **
Health : Ok
** POWER SUPPLIES **
Redundancy Status : Full
##########################################
Accessing Site: site02
** FANS **
Redundancy Status : Full
** MEMORY …Run Code Online (Sandbox Code Playgroud) 我正在为linux构建系统的模块编写一个.spec文件,并遇到了一个小问题,想要分享它.
用于编写脚本文件:
cat <<EOF > /path/to/somewhere/script
#blah blah
EOF
chmod +x script
Run Code Online (Sandbox Code Playgroud)
当脚本在目标上运行时,存在指向脚本位置的错误,因为它在主机系统中.基本上$ 0是错误的.
通过在线查看一些示例代码后更改第一行来修复它:
cat <<'EOF' > /path/to/somewhere/script
#blah blah
EOF
chmod +x script
Run Code Online (Sandbox Code Playgroud)
想知道有什么不同以及第二次让它发挥作用的原因.
我的简单脚本是这样的:
#!/bin/sh
DEF=.file_name_with_a_leading_dot.sh
. ${DEF}
Run Code Online (Sandbox Code Playgroud)
注意顶行的/ bin/sh.当我运行这个简单的脚本时,我收到一个错误,找不到该文件.但是,如果我将该顶行更改为#!/ bin/bash,则脚本会在当前目录中找到该文件.
但是,在我的Ubuntu linux笔记本电脑上,我看到/ bin/sh是/ bin/bash的符号链接.那么,为什么我的脚本表现不同?
另外,我可以像这样运行脚本:
/bin/bash ./script.sh
Run Code Online (Sandbox Code Playgroud)
没关系.
那么,我错过了什么?
我正在研究clojure.core的来源.
(defmacro if-not
([test then] `(if-not ~test ~then nil))
([test then else]
`(if (not ~test) ~then ~else)))
Run Code Online (Sandbox Code Playgroud)
至于第二种形式,为什么不呢
([test then else] `(if ~test ~else ~then)
我知道如何将最后一个参数传递给函数,但我想知道如何在前两个函数之后获取函数的所有参数:
例如:
function custom_scp(){
PORT=$1
USER=$2
SOURCES=`ALL_OTHER_ARGS`
scp -P $PORT -r $SOURCES $USER@myserver.com:~/
}
Run Code Online (Sandbox Code Playgroud)
所以将三个文件发送到远程home目录就好像
$ custom_scp 8001 me ./env.py ./test.py ./haha.py
Run Code Online (Sandbox Code Playgroud)