function change(){
item = document.getElementById("first");
item.value = "second";
item.id = "second";
}
ob = document.getElementById("first");
ob.addEventListener("click",change);
Run Code Online (Sandbox Code Playgroud)
<input id="first" type="button" value="first">
Run Code Online (Sandbox Code Playgroud)
单击输入时,它变为:
<input id="second" type="button" value="second">
Run Code Online (Sandbox Code Playgroud)
我的要求是编写javascript代码,这样当你点击id为的输入时,second
网页就会刷新.也就是说,要更改当前的输入元素:
<input id="second" type="button" value="second">
Run Code Online (Sandbox Code Playgroud)
进入上一个:
<input id="first" type="button" value="first">
Run Code Online (Sandbox Code Playgroud)
这是我的尝试:
function change(){
item = document.getElementById("first");
item.value = "second";
item.id = "second";
}
ob = document.getElementById("first");
ob.addEventListener("click",change);
function previous(){
document.execCommand('Refresh')
}
ob = document.getElementById("second");
ob.addEventListener("click",previous);
Run Code Online (Sandbox Code Playgroud)
<input id="first" type="button" value="first">
Run Code Online (Sandbox Code Playgroud)
error: Uncaught TypeError: Cannot read property 'addEventListener' of null
at line27.
Run Code Online (Sandbox Code Playgroud) 打开一个名为"伏藏"终端,并运行创建的文件callback.sh
用/bin/bash callback.sh
.
cat callback.sh
#!/bin/bash
myCallback() {
echo "callback function called at $(date)"
}
trap myCallback SIGUSR1
sleep 20
Run Code Online (Sandbox Code Playgroud)打开一个名为"termB"的新终端并运行:
pkill -USR1 -f callback.sh
Run Code Online (Sandbox Code Playgroud)在termA中20秒后显示以下内容; 它永远不会在termA中显示:
callback function called at Mon Nov 19 08:21:52 HKT 2018
Run Code Online (Sandbox Code Playgroud)
结论证实,当Bash在前台执行外部命令时,它不处理任何接收的信号,直到前台进程终止(参见信号陷阱).
做一点改变callback.sh
:
cat callback.sh
#!/bin/bash
myCallback() {
echo "callback function called at $(date)"
}
trap myCallback SIGUSR1
while true; do
read -p "please input something for foo: " foo
done
Run Code Online (Sandbox Code Playgroud)
添加无限while循环并删除sleep 20
.
打开一个名为"特玛"终端,运行创建的文件callback.sh …
我想用简单的AES加密来加密文件,这是我的python3源代码.
import os, random, struct
from Crypto.Cipher import AES
def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
if not out_filename:
out_filename = in_filename + '.enc'
iv = os.urandom(16)
encryptor = AES.new(key, AES.MODE_CBC, iv)
filesize = os.path.getsize(in_filename)
with open(in_filename, 'rb') as infile:
with open(out_filename, 'wb') as outfile:
outfile.write(struct.pack('<Q', filesize))
outfile.write(iv)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += ' ' * (16 - len(chunk) % 16)
outfile.write(encryptor.encrypt(chunk.decode('UTF-8','strict')))
Run Code Online (Sandbox Code Playgroud)
它适用于某些文件,遇到某些文件的错误信息,如下所示:
encrypt_file("qwertyqwertyqwer",'/ tmp/test1',out_filename = None,chunksize = 64*1024) …
start.py代码如下.
import threading
class myThread(threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
def run(self):
currentThreadname = threading.currentThread()
print "running in ", currentThreadname
thread = myThread(1,"mythrd")
thread.start()
Run Code Online (Sandbox Code Playgroud)
用python启动它两次.
python start.py
running in <myThread(mythrd, started 140461133485824)>
python start.py
running in <myThread(mythrd, started 140122860668672)>
Run Code Online (Sandbox Code Playgroud)
run.py代码如下.
import threading
class myThread(threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
def run(self):
currentThreadname = threading.currentThread()
print "running in ", currentThreadname
thread = myThread(1,"mythrd")
thread.run()
Run Code Online (Sandbox Code Playgroud)
run.py只有一行不同于start.py.
现在启动run.py两次.
python run.py
running …
Run Code Online (Sandbox Code Playgroud) 类型apple
在其名称是输入goods
和类型9
在其名称输入price
,点击submit
,现在确认窗口弹出,无论你点击yes
或no
,数据将发送到price.php
.
我的期望:
当你点击时yes
,数据会发送到price.php
,当你点击时no
,数据不会发送到price.php
,我的js有什么问题?
ob = document.getElementById("submit");
function check(){
if(document.getElementById("price").value < 10){
var flag = window.confirm(" are your sure the price is less than 10 ?");
if(flag){
return true;
}else{
exit;
}
}
}
ob.addEventListener("click",check,false);
Run Code Online (Sandbox Code Playgroud)
<form action="price.php" method="post">
<table>
<tr>
<td>goods</td>
<td><input type="text" name="goods"></td>
</tr>
<tr>
<td>price</td>
<td><input type="text" id="price" name="price"></td>
</tr>
<tr><td colspan=2><input type="submit" id="submit" value="submit"></td></tr> …
Run Code Online (Sandbox Code Playgroud)环境:debian9 + vim7.4.
cat .bashrc
add(){
echo $(expr $1 + $2)
}
Run Code Online (Sandbox Code Playgroud)
现在在vim中编辑一个文件
add 1 5
Run Code Online (Sandbox Code Playgroud)
在命令模式下运行它:w !bash
,发生错误.
bash: line 1: add: command not found
shell returned 127
Run Code Online (Sandbox Code Playgroud)
1. set shellcmdflag=-ic
在/ etc/vim/vimrc和.bashrc以及.vimrc中添加.
2.reboot
3.vim test.sh
进入命令模式
:verbose set shellcmdflag
shellcmdflag=-ic
Last set from ~/.vimrc
Run Code Online (Sandbox Code Playgroud)
4.在test.sh中输入两行
ls
add 5 6
:w !bash
a1.sh test.py
bash: line 2: add: command not found
shell returned 127
Run Code Online (Sandbox Code Playgroud)
:execute '! source ~/.bashrc; source '.expand('%:p')
可以发出两个命令:ls
并add
运行.
重启后,
1.add函数无法调用 …
使用for循环启动多进程.
import os
from multiprocessing import Process
def run_proc(name):
print('child process %s (%s) running ...' %(name,os.getpid()))
if __name__ == '__main__':
print('parent process %s.' %os.getppid())
for i in range(5):
p = Process(target=run_proc,args=(str(i),))
print('process will start'+str(i))
p.start()
p.join()
print('process is end')
Run Code Online (Sandbox Code Playgroud)
我得到了结果.
parent process 6497.
process will start
process will start
child process 0 (6984) running ...
process will start
process will start
process will start
child process 2 (6986) running ...
child process 1 (6985) running ...
child process 3 (6987) …
Run Code Online (Sandbox Code Playgroud) 我以这种方式为js完成安装了tern_for_vim和YouCompleteMe.
1安装节点
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source ~/.nvm/nvm.sh
nvm install node
Run Code Online (Sandbox Code Playgroud)
2安装tern_for_vim
$ cd ~/.vim/bundle
git clone https://github.com/marijnh/tern_for_vim
Run Code Online (Sandbox Code Playgroud)
3安装YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
$ ./install.sh --clang-completer --tern-completer
Run Code Online (Sandbox Code Playgroud)
4编辑.tern-project
vim .tern-project
{
"libs": [
"browser",
"underscore",
"jquery"
],
"plugins": {
"node": {}
}
}
Run Code Online (Sandbox Code Playgroud)
现在来vim test.js.
输入document.
test.js文件后弹出js完成.
然后vim test.html 在test.html文件中
输入后弹出没有js完成document.
.
怎么解决?
我想转换b'\xc2\xa0\x38'
成b'x38'
python3.
b'\xc2\xa0\x38'.replace(u'\xc2\xa0',"")
b'\xc2\xa0\x38'.replace(u'\xc2a0',"")
TypeError: a bytes-like object is required, not 'str'
Run Code Online (Sandbox Code Playgroud)
在网页中,c2 a0
表示NO-BREAK SPACE,其unicode点为U + 00A0.
Unicode code point character UTF-8 (hex.) name
U+00A0 c2 a0 NO-BREAK SPACE
Run Code Online (Sandbox Code Playgroud)
注意:c2a0
是不可打印的,字符列在这里是空白的.
如何用replace方法转换b'\xc2\xa0\x38'
成b'\x38'
?
LAMP安装在我的本地电脑上,因为我知道该字符串xxxx
可以/tmp/test
用下面的PHP函数写入.
file_put_contents("/tmp/test","test1 test2")
Run Code Online (Sandbox Code Playgroud)
cat ajax_get.php
<?php
$str = "test1 test2";
ini_set('display_errors', 1);
error_reporting(E_ALL);
$str = implode(" ",$_GET);
file_put_contents("/tmp/test",$str);
print($str);
?>
Run Code Online (Sandbox Code Playgroud)
为什么命令file_put_contents("/tmp/test",$str);
中ajax_get.php
不能工作?
这是没有用的,以取代file_put_contents
与
$handle=fopen("/tmp/test","w");
fwrite($handle,$str);
fclose($handle);
Run Code Online (Sandbox Code Playgroud)
如果我更改下面的语句,可能是目录权限的问题 ajax_get.php
file_put_contents("/tmp/test",$str);
Run Code Online (Sandbox Code Playgroud)
成
file_put_contents("test",$str);
Run Code Online (Sandbox Code Playgroud)
并运行上一个进程,在其中ajax_get.php
创建一个文件/var/www/html/test
cat /var/www/html/test
test1 test2
Run Code Online (Sandbox Code Playgroud)
显示/tmp
目录的权限.
ls -al /tmp
total 76
drwxrwxrwt 16 root root 12288 Dec 10 18:39 .
drwxr-xr-x 23 root root 4096 Dec 1 08:03 ..
Run Code Online (Sandbox Code Playgroud)
.
是当前目录/tmp
,其权限是777(rwxrwxrwx),为什么不能通过/tmp
PHP …
python ×4
javascript ×3
bash ×2
python-3.x ×2
vim ×2
autocomplete ×1
bash-trap ×1
byte ×1
confirm ×1
encryption ×1
function ×1
html ×1
html5 ×1
linux ×1
php ×1
refresh ×1
replace ×1
string ×1
webpage ×1