我很好奇localStorage通过在两个浏览器标签中同时覆盖它来破坏输入的可能性.我应该为本地存储创建互斥吗?
我已经在考虑这样的伪类:
LocalStorageMan.prototype.v = LocalStorageMan.prototype.value = function(name, val) {
//Set inner value
this.data[name] = val;
//Delay any changes if the local storage is being changed
if(localStorage[this.name+"__mutex"]==1) {
setTimeout(function() {this.v(name, val);}, 1);
return null; //Very good point @Lightness Races in Orbit
}
//Lock the mutext to prevent overwriting
localStorage[this.name+"__mutex"] = 1;
//Save serialized data
localStorage[this.name] = this.serializeData;
//Allow usage from another tabs
localStorage[this.name+"__mutex"] = 0;
}
Run Code Online (Sandbox Code Playgroud)
上述功能意味着本地存储管理器正在管理本地存储的一个特定密钥 - localStorage["test"]例如.我想将此用于greasomonkey用户脚本,其中避免冲突是一个优先事项.
我想使用开放的XML C#应用%(百分比)数字格式
我有数值3.6,我想在Excel中显示该数字为3.6%.
我如何实现这一目标?
我一直在寻找谷歌找到SHA256哈希的十六进制输出的样子.但我似乎无法找到它.
那么当SHA256哈希转换为十六进制时,它会是什么样子?
我无法在HTML5 Web工作者中访问jQuery .有没有办法可以做到这一点?
我曾批评一个答案,暗示preg_match了===,为了避免类型不匹配查找字符串偏移时.
不过,后来对答案的作者已经发现,preg_match实际上是显著快于多字节操作mb_strpos.Normal strpos比两个函数都快,但当然不能处理多字节字符串.
据我了解,mb_strpos需要做更多的东西比strpos.然而,如果正则表达式可以做到这一点几乎一样快的strpos,它是什么,mb_strpos这是否需要这么多的时间?
我怀疑这是一个优化错误.例如,PHP扩展可能比其原生函数慢吗?
mb_strpos($str, "??", 0 ,"GBK"): 15.988190889 (89%)
preg_match("/??/", $str): 1.022506952 (6%)
strpos($str, "dh"): 0.934401989 (5%)
Run Code Online (Sandbox Code Playgroud)
功能运行10 次6次.绝对时间(s)计算函数的10 6次运行的时间总和,而不是一次的平均值.
测试字符串是$str = "??dhgd????";.该测试可以在这里看到(向下滚动跳过测试类).
注意:根据评论员之一(和常识),preg_match比较时也不使用多字节,受到同样的错误风险strpos.
问题是,当imagettfbbox用于计算文本尺寸时,当输入文本以数字开头时,会返回太小的矩形.这是我的代码:
$fontSize = 150;
$font = "font/courier_new.ttf";
$text = $_GET["text"];
//Determine font dimensions
$bbox = imagettfbbox($fontSize, 0, $font, $text);
$bbox["width"]= abs($bbox[4]-$bbox[0]);
$bbox["height"]= abs($bbox[5]-$bbox[1]);
$im = imagecreatetruecolor($bbox["width"], $bbox["height"]);
echo "<b>Image size:</b>\n";
print_r($bbox);
// This part makes transparent background
imagesavealpha($im, true);
$bg = imagecolorallocatealpha($im, 254, 254, 254,127);
$text_color= imagecolorallocate($im, 0, 0, 0);
imagealphablending($im, false);
imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bg );
imagealphablending($im, true);
header("X-Img-Size: ".$bbox["width"]."x".$bbox["height"]."");
imagettftext($im, $fontSize, 0, 0, $bbox["height"], $text_color, $font, $text);
// This is output
header("Content-Type: text/html");
ob_start(); …Run Code Online (Sandbox Code Playgroud) 如何从hWnd获得显示器屏幕分辨率?
我正在使用hWnd,因为窗口可以位于多个监视器中的任何一个上.
即hWnd顶部/左侧坐标位于屏幕分辨率为800 x 600的显示器上.
我用一种名为PL/B的语言编程,它允许调用Windows API.
可以使用哪些Window API?
我正试图long long从控制台使用标准IO功能scanf.我开始时%lld:
scanf("%lld", &rule);
Run Code Online (Sandbox Code Playgroud)
抛出:
error: unknown conversion type character 'l' in format [-Werror=format=]
Run Code Online (Sandbox Code Playgroud)
我发现了更多变通方法,但它们也会抛出错误:
scanf("%I64d", &rule);
->error: ISO C does not support the 'I64' ms_scanf length modifier [-Werror=format=]
scanf("%"SCNd64"", &rule);
->error: expected ')' before 'SCNd64'
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?还有另外一招吗?
我正在使用这些标志编译最新版本的MinGw GCC: -pedantic -Wall -Werror -std=c99 -g -D HOME=1
所以我试图让Node.js工作.当然,它并不像宣传的那样容易:)
我碰巧在我的计算机上有两个python版本,但Node.js似乎只适用于较旧的版本,2.7.出错时,它还鼓励我将路径设置为PYTHON环境变量,并显示以下错误:
Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
Run Code Online (Sandbox Code Playgroud)
好的,我根据需要配置了变量:
C:\Users\Jakub>set PYTHON=C:\MYSELF\Programs\Python2.7\python.exe
C:\Users\Jakub>echo %PYTHON%
C:\MYSELF\Programs\Python2.7\python.exe
Run Code Online (Sandbox Code Playgroud)
你可以看到我曾经echo检查变量是否真的设置过.不幸的是,那npm东西无法读取它并且错误再次出现.这是我设置%PYTHON%变量后的完整日志:
C:\Users\Jakub>npm install minecraft-protocol
\
> ursa@0.8.5 install C:\Users\Jakub\node_modules\minecraft-protocol\node_modules\ursa
> node-gyp rebuild
|
C:\Users\Jakub\node_modules\minecraft-protocol\node_modules\ursa>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" rebuild ) else (rebuild)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack at failNoPython …Run Code Online (Sandbox Code Playgroud) javascript ×3
php ×2
c ×1
c# ×1
c99 ×1
gd ×1
html5 ×1
imagettftext ×1
jquery ×1
node.js ×1
npm ×1
openxml ×1
openxml-sdk ×1
performance ×1
python ×1
regex ×1
scanf ×1
sha256 ×1
strpos ×1
web-worker ×1
winapi ×1