V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  h0099  ›  全部回复第 7 页 / 共 8 页
回复总数  159
1  2  3  4  5  6  7  8  
2023-01-12 19:46:32 +08:00
回复了 Jamy 创建的主题 Linux 如何给 sh -c "echo $1,$2" 传递参数。
那您 c 写的 shc 解密程序里不也有 aes 加密时的密钥吗?您在同一个机器上加密又解密一坨 bash 字符串有啥意义?
除非您是在执行别人发给您的 bash ,而为了信任对方发送的 bash 的确是他亲自发的所以套了层 GPG
2023-01-12 18:05:51 +08:00
回复了 GGGG430 创建的主题 MySQL sql 中包含特殊字符问题
#11 @bjhc 回顾经典之把 UGC 图片的 blob 二进制全塞数据库里存然后每次获取图片都去查表

#12 @sadfQED2 phppdo/jdbc/dbdriver 层提供的 prepated statment 不是银弹,无脑 escape 掉用户输入中的所有 sql 语法所使用的特殊字符也不是银弹: https://phpdelusions.net/pdo/sql_injection_example#escaping
2023-01-12 18:02:01 +08:00
回复了 shendaowu 创建的主题 MySQL mysql 或者 mariadb 能不能限制某条语句的资源消耗?
#11 @shendaowu 既然阁下能够修改您要跑的程序的源码,那为什么不打开 https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html 看看哪些 sql 超级耗时然后 EXPLAIN https://dev.mysql.com/doc/refman/8.0/en/using-explain.html 他看看如何针对这个 sql 优化?
当然这样一个个去 tuning 可能太慢了
最省事也不需要改数据库表结构的方法就是#6 @Features 所说的单独开 replicate mysqld 从而实现您的`分三档,不太消耗资源的这类 SQL 语句立即同步执行,中等的异步限制资源执行,太消耗资源的就只能下半夜不限制资源执行`
但这仍然知道到底哪些 sql 查起来耗时,然后修改源码让这些 sql 去优先级低被各种限制使用系统资源了的 replicate mysqld 上执行
#3 @chnwillliu > 安卓系统自带的 webview 都是可以单独更新的
需要翻墙去 google play 才能获取更新
有些国产 ROM 偶尔也会推送 android webview 的更新,但您敢安装吗?
2023-01-12 17:55:13 +08:00
回复了 bronana 创建的主题 NGINX 想请教大家 nginx 如何判断 server_name
#5 @bronana 您忘了配置 https 版本以及监听 443 端口的 default listen ,我猜您现在执行
`curl -v -I 'Host: example.com' https://您的服务器 ip`
又会进入最初的`return 301 https://$host$request_uri`

#4 对此早有预言
> 一个常见错误是只设置了 port80 的 default server ,导致使用 http 或 https 协议请求 443 (或其他)端口时仍然会绕过 default server (因为 default 是针对单个 listen 端口的)
2023-01-12 17:52:40 +08:00
回复了 bronana 创建的主题 NGINX 想请教大家 nginx 如何判断 server_name
#4 @ETiV listen directive 必须加 default 修饰,不然按照 nginx 的脑瘫逻辑,他只会将他读到的所有 conf 文件中第一个出现的 listen 作为 default

#3
如果您所有的 nginx.conf 文件中只有这一个 server block 那么文档
http://nginx.org/en/docs/http/request_processing.html 对此早有预言
> If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour
2023-01-12 17:50:41 +08:00
回复了 KC35 创建的主题 程序员 突然好奇,消除歌曲中的人声技术上是怎么实现的?
2023-01-12 17:46:31 +08:00
回复了 horou 创建的主题 程序员 关于 sql 拼接和 sql 注入的问题
#5 @xuanbg 允许用户输入'和`意味着他可以逃出您亲自写的'和`包裹
例如执行 sql "SELECT `{用户输入}` FROM table"
这里的用户输入可以是"someFieldExistsInTable`, (SELECT * FROM secretTable), `anotherFieldExistsInTable"
导致实际执行的是"SELECT `someFieldExistsInTable`, (SELECT * FROM secretTable), `anotherFieldExistsInTable` FROM table",于是 secretTable 就也被读出来了

'同理
2023-01-12 17:35:56 +08:00
回复了 yezheyu 创建的主题 程序员 关于异步任务的一点疑问,有没有老哥帮忙解答下
https://stackoverflow.com/questions/33308121/can-you-bind-this-in-an-arrow-function 的第一个回答进一步指出:
> You cannot rebind this in an arrow function. It will always be defined as the context in which it was defined. If you require this to be meaningful you should use a normal function.
> From the ECMAScript 2015 Spec: http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation
> > Any reference to arguments, super, this, or new.target within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function.

如果您能解释下图中的所有行为,那您就已经理解 js 的两种函数声明语法所带来的截然不同的 this 上下文作用域捕获进闭包罪恶行径了
https://i.imgur.com/LADQMDz.png
2023-01-12 17:28:26 +08:00
回复了 yezheyu 创建的主题 程序员 关于异步任务的一点疑问,有没有老哥帮忙解答下
#36 @yezheyu this 到底指向什么恶俗玩意跟异步同步毫无关系,他完完全全是由显式的.bind/apply/call 或隐式的闭包上下文捕获决定的

- 显式的.bind/apply/call:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
的第一个参数 thisArg 就可以改变任何函数的 this 指向

- 隐式的闭包上下文捕获:
完整的 function ()语法`function () {}`(不论匿名还是具名)会从他的声明处寻找 this 指向,然后把自身的 this 指向声明处上级(本级是正在声明的 fun 自身)的 this
从声明处而不是执行处上下文获得 this 捕获进闭包的证明:
https://i.imgur.com/YPkI1r9.png
`b.call({a:1})`将 arrow fun`b`的 this 修改为了一个`{a:1}` object ,但其 return 的会从上下文捕获 this 的 function()语法的回调函数的 this 并没有跟着变成{a:1},而仍然是最初声明 b 时从 b 那捕获的 this=window ( b 又从 global scope 那捕获了 this=window )
即便把 b 改成 function()语法也不影响:
https://i.imgur.com/rFnSyfT.png

而 arrow fun 语法`() => {}`不会进行任何从上下文中捕获 this 的罪恶行径,也无法通过.bind/apply/call 来在声明后再次显式修改他内部的 this 指向,可以说 arrow fun 就根本没有 this
https://i.imgur.com/2yrghsH.png

> 那为啥 button 点击事件的回调函数中 this 会指向事件的触发对象 button 呢?而不是 window ?

您可以理解为有一个`buttonClickCallback.call(buttomElement, clickEvent)`的 js 被执行
您也可以自己执行这个`.call(buttomElement)`,同样会改变回调(只要不是用 arrow fun 语法声明的)的 this 为 button
2023-01-12 17:14:15 +08:00
回复了 yezheyu 创建的主题 程序员 关于异步任务的一点疑问,有没有老哥帮忙解答下
#35 @Al0rid4l 估计他感觉到的`阻塞主线程`是发生在`XHR 下载图片二进制数据`之后的`再自行处理`阶段
#23 @h0099 对此早有预言:
> 对于下载好的资源,你怎么处理,就算只是打印一下,也必须让主线程处理。

如果阁下所说的`打印一下`是指`console.log(await(await fetch('https://www.v2ex.com')).text())`这样的 js 代码,那么 network thread 当然会把 response body 传回给 js thread 从而作为您所调用的的`Response.text()`返回的 promise 的 reslove 值
2023-01-12 04:25:58 +08:00
回复了 bronana 创建的主题 NGINX 想请教大家 nginx 如何判断 server_name
首先 if is evil https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
我想阁下现在遇到的问题是请求任何`非`列出来的这些子域时(例如`curl -I `Host: example.com` -v http://您的服务端 IP`)仍然会匹配这个 block 导致进入`return 301 https://$host$request_uri`
如果您所有的 nginx.conf 文件中只有这一个 server block 那么文档 http://nginx.org/en/docs/http/request_processing.html 对此早有预言
> If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour

要想在 80 和 443 上搭建正确的 default http(s) server 您可以参考 https://serverfault.com/questions/847978/best-practice-to-handle-default-server-and-public-ip-in-nginx
一个常见错误是只设置了 port80 的 default server ,导致使用 http 或 https 协议请求 443 (或其他)端口时仍然会绕过 default server (因为 default 是针对单个 listen 端口的)
http://nginx.org/en/docs/http/ngx_http_core_module.html#listen 进一步指出:
> The default_server parameter, if present, will cause the server to become the default server for the specified address:port pair. If none of the directives have the default_server parameter then the first server with the address:port pair will be the default server for this pair.

```nginx
server {
listen 80 fastopen=256 default_server;
listen 443 fastopen=256 ssl default_server;
server_name _ "";
access_log path/to/log/default.access.log;
error_log path/to/log/default.error.log;

ssl_certificate /etc/nginx/snippets/self-signed-ssl.crt; # 使用 openssl 生成的自签名证书 https://stackoverflow.com/questions/10175812/how-to-generate-a-self-signed-ssl-certificate-using-openssl
ssl_certificate_key /etc/nginx/snippets/self-signed-ssl.key;

return 444; # https://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return The non-standard code 444 closes a connection without sending a response header. https://www.reddit.com/r/Network/comments/e8aveo/nginx_explain_http_444_like_im_five/
}
2023-01-12 00:53:43 +08:00
回复了 zhengjian 创建的主题 信息安全 请帮忙测试这个帖子中的 XSS 是否有效
2023-01-11 22:42:07 +08:00
回复了 Jamy 创建的主题 Linux 如何给 sh -c "echo $1,$2" 传递参数。
@webcape233 估计他复制粘贴来的 bash 里有一大堆的$1 $2 $3 $4 $5 $6 $7 $8 $9 他懒得查找替换,而您又不可能声明 1=a ( bash 变量名不能数字开头)
2023-01-11 21:36:16 +08:00
回复了 Jamy 创建的主题 Linux 如何给 sh -c "echo $1,$2" 传递参数。
https://unix.stackexchange.com/questions/144514/add-arguments-to-bash-c
第一个回答的机翻:

/bin/bash -c 'echo "$0" "$1"' foo bar
/bin/bash -c 'echo "$@"' bash foo bar
在第一种情况下,显式传递 echo 参数$0 和$1 ,在第二种情况下,使用"$@"to 正常扩展为“除 $0 之外的所有位置参数”。请注意,在这种情况下,我们也必须传递一些要使用的东西$0 ;我选择了“bash”,因为这$0 通常是什么,但其他任何东西都可以。

至于这样做的原因,而不是仅仅将您直接提供的任何参数传递给您列出的命令:请注意文档说“命令是从字符串中读取的”,复数形式。换句话说,这个方案允许你做:

/bin/bash -c 'mkdir -p -- "$1" && cd -P -- "$1" && touch -- "$2"' bash dir file
2023-01-11 21:29:37 +08:00
回复了 yezheyu 创建的主题 程序员 关于异步任务的一点疑问,有没有老哥帮忙解答下
@biguokang 建议深入学习贯彻泛银河系格雷科技分部邪恶组织四叶重工炼铜本部叶独头子叶独群组联合体陈意志第三帝国元首炼铜傻狗橙猫领导下的四叶 TG 本部( https://t.me/n0099_tg https://t.me/n0099official )话语体系文风:
https://sora.ink/archives/1574
https://github.com/n0099/TiebaMonitor/issues/24
https://github.com/Starry-OvO/aiotieba/issues/64
2023-01-11 21:26:42 +08:00
回复了 shendaowu 创建的主题 MySQL 如何防止大量耗时的数据库查询影响网页加载速度?
2023-01-11 21:25:52 +08:00
回复了 shendaowu 创建的主题 MySQL mysql 或者 mariadb 能不能限制某条语句的资源消耗?
#8 @shendaowu 通过控制进程的资源用量使得您也可以在一个系统上跑两个 mysqld
#10 @lululau 很明显他只是装个现有的程序来跑所以无法修改其内部结构 https://www.v2ex.com/t/908246
2023-01-11 20:53:03 +08:00
回复了 shendaowu 创建的主题 MySQL mysql 或者 mariadb 能不能限制某条语句的资源消耗?
可以基于#6 所说的单独开个 mysqld 进程作为只读 replicate 服务端
然后修改`innodb_buffer_pool_size`( https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size )和`innodb_redo_log_capacity`/`innodb_log_file_size`以约束进程常驻占用内存量: https://dev.mysql.com/doc/refman/8.0/en/innodb-redo-log.html#innodb-modifying-redo-log-capacity
根据每个 sql 的特点可能会产生巨大的临时表( https://dev.mysql.com/doc/refman/8.0/en/internal-temporary-tables.html ),您可以把默认 1G 的`temptable_max_ram`也调低 https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_temptable_max_ram
限制进程硬盘 io: https://unix.stackexchange.com/questions/48138/how-to-throttle-per-process-i-o-to-a-max-limit
限制进程 cpu 使用率: https://manpages.ubuntu.com/manpages/trusty/man1/cpulimit.1.html
2023-01-11 20:45:29 +08:00
回复了 GGGG430 创建的主题 MySQL sql 中包含特殊字符问题
另外如果您要导入的这个几百 m 的文件是合法的 csv (但您说`包含很多 mysql 保留字或者其他特殊字符,那大概率也有一大堆的,`),那您可以试试 LOAD DATA INFILE https://dev.mysql.com/doc/refman/8.0/en/load-data.html
1  2  3  4  5  6  7  8  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1013 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms · UTC 23:36 · PVG 07:36 · LAX 16:36 · JFK 19:36
Developed with CodeLauncher
♥ Do have faith in what you're doing.