小编Sat*_*vik的帖子

获取元素的实际浮点宽度

我正在使用jQuery(v1.7.1),我需要得到一个元素的绝对浮点宽度,但所有jQuery的宽度方法似乎都是对宽度值进行四舍五入.

例如,如果元素的实际宽度是20.333333px,则jQuery的width方法返回20,即忽略小数值.

你可以在这个jsFiddle上看到我的意思

所以,我的问题是:如何获得元素宽度的浮点值?

css floating-point jquery width

44
推荐指数
2
解决办法
3万
查看次数

PHP深度扩展阵列

如何对多维关联数组进行深度扩展(用于解码的JSON对象).我需要PHP的等价于jQuery的$.extend(true, array1, array2)数组而不是JSON和PHP.

这是我需要的一个例子(array_merge_recursive似乎没有做同样的事情)

$array1 = ('1'=> ('a'=>'array1a', 'b'=>'array1b'));
$array2 = ('1'=> ('a'=>'array2a', 'c'=>'array2b'));

$array3 = array_extend($array1, $array2);

//$array3 = ('1'=> ('a'=>'array2a', 'b'=>'array1b', 'c'=>'array2b'))
Run Code Online (Sandbox Code Playgroud)

注意如果array1具有相同的值,则array2将如何覆盖array1(如类的扩展如何工作)

php jquery json array-merge

20
推荐指数
1
解决办法
6432
查看次数

readimageblob:将SVG转换为PNG时出现致命错误

我正在尝试使用Image-Magick和PHP将SVG文本转换为PNG图像.此SVG是使用NVD3生成的图表,我想让我的用户将其下载为图像.

基本上,我将用JSON编码的SVG数据发送到PHP处理程序,该处理程序应该将其作为PNG图像输出.

但是,这会引发以下错误:

Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `' @ blob.c/BlobToImage/347' in svg2png.php:4 Stack trace: #0 svg2png.php(4): Imagick->readimageblob('
Run Code Online (Sandbox Code Playgroud)

用于转换图像的PHP脚本:

<?php
    /* Derived in part from: http://stackoverflow.com/a/4809562/937891 */
    $svg=json_decode($_REQUEST["svgData"]);
    $im=new Imagick();
    $im->readImageBlob($svg);
    $im->setImageFormat("png24");
    header("Content-Type: image/png");
    $thumbnail = $im->getImageBlob();
    echo $thumbnail;
?>
Run Code Online (Sandbox Code Playgroud)

HTML:

<form id="exportSpendTrendTrigger" method="POST" action="svg2png.php" target="_blank">
    <input id="exportSpendTrendSvgData" type="hidden" name="svgData" />
    <input type="submit" class="btn" value="Export" />
</form>
<div id="spendtrend">
    <svg></svg>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

exportSpendTrend = function (e) { …
Run Code Online (Sandbox Code Playgroud)

php jquery json imagick

10
推荐指数
2
解决办法
9883
查看次数

让CodeMirror遵循TextArea

如何使CodeMirror与TextArea同步,以便光标位置,选择和数据在两者上保持相同?

我正在将CodeMirror与MobWrite一起使用.CodeMirror只使用textArea来读取输入,而MobWrite可以在给定的TextArea上处理选择等,问题是让CodeMirror与TextArea同步.

javascript synchronization textarea codemirror

6
推荐指数
1
解决办法
2031
查看次数

为什么不执行脚本标记?

我试图在Meteor应用程序中包含Google Plus One按钮以进行协作草图绘制,我注意到script模板内的标签未执行.

<template name="gplus">
    <!-- Place this tag where you want the +1 button to render. -->
    <div class="g-plusone" data-href="{{url}}"></div>

    <!-- Place this tag after the last +1 button tag. -->
    <script type="text/javascript">
        console.log("Google Plus button");
        (function() {
            var po = document.createElement('script');
            po.type = 'text/javascript';
            po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(po, s);
        })();
    </script>
</template>
Run Code Online (Sandbox Code Playgroud)

我通过将脚本移动到单独的JavaScript文件来获得工作按钮,但我仍然想知道为什么内联脚本不起作用.

我在控制台上看到了脚本标记,但脚本本身并没有运行.Meteor如何做到这一点?

meteor

6
推荐指数
1
解决办法
2050
查看次数

调试Laravel 5工匠会迁移意外的T_VARIABLE FatalErrorException

artisan migrateLaravel 5项目上运行时,它失败并出现以下情况FatalErrorException:

$ artisan migrate -vvv --force

[Symfony\Component\Debug\Exception\FatalErrorException]语法错误,意外'$ table'(T_VARIABLE)

如何获取导致错误的文件和行?

如果无论如何相关,我在使用WAMP的Windows 7 x64机器上 - PHP 5.6和Laravel Framework 5.1.10版(LTS).

debugging laravel artisan artisan-migrate laravel-5.1

5
推荐指数
1
解决办法
8450
查看次数

使用Python2.7在GAE上运行web2py作为WSGI应用程序

如何设置在GAEWeb2Py [Version 1.99.4 (2011-12-14 14:46:14) stable]作为WSGI应用程序运行?Python2.7.2

目前,我的app.yaml文件看起来像:

#  For Google App Engine deployment, copy this file to app.yaml
#  and edit as required
#  See http://code.google.com/appengine/docs/python/config/appconfig.html
#  and http://web2py.com/book/default/chapter/11?search=app.yaml

application: my-app-name
version: 1
api_version: 1

# use this line for Python 2.5
#
# runtime: python

# use these lines for Python 2.7
# upload app with: appcfg.py update web2py (where 'web2py' is web2py's root directory)

runtime: python27
threadsafe: true
# …
Run Code Online (Sandbox Code Playgroud)

google-app-engine wsgi web2py thread-safety python-2.7

4
推荐指数
1
解决办法
1431
查看次数

Web2Py的参考手册

我最近从PHP切换到Web2Py,并想知道Web2Py是否有像PHP这样的手册.在web2py的书和密友博客都很好,但我期待为在web2py中可用的类和方法的快速参考.

web2py reference-manual

3
推荐指数
1
解决办法
547
查看次数

存储配置详细信息

我有一堆字符串和整数常量,我在我的应用程序的不同位置使用.我打算将它们放在一个集中的位置,以便将来更容易更改它们.我可以想到以下方法:

1)将它们作为单个变量存储在模型中 db.py

settings_title = "My Amazing App"
settings_ver = 2.0
settings_desc = "Moar and Moar cats"
Run Code Online (Sandbox Code Playgroud)

2)将它们作为一个词典,存储在 db.py

settings = { "title": "My Amazing App",
    "ver" = 2.0,
    "desc" = "Moar and Moar cats"
}
Run Code Online (Sandbox Code Playgroud)
  • 使用该模型是个好主意db.py吗?我听说它是​​针对每个请求进行评估的.可以在那里设置设置有明显的开销吗?
  • 这两种方法之间在性能方面有什么区别吗?
  • 有没有更好的方法呢?

python web2py

3
推荐指数
1
解决办法
818
查看次数

检测python变量值的变化

有什么方法可以在python中每次变量值更改时调用函数?

像听众一样吗?

具体来说,我指的 像GAE-Session这样的脚本之间仅共享变量的情况 。(使用Cookies,Memcache等共享数据)

示例:ScriptA和ScriptB,共享一个会话变量。当脚本B进行更改时,SctiptA必须调用一个方法来处理该更改。

python session google-app-engine onchange global-variables

2
推荐指数
1
解决办法
5405
查看次数

Python:有效地迭代多维列表

我正在使用for循环迭代二维列表:

def itr(lpic, lH, lW, x, y):
    '''lpic=2D-Array; lH=Row_count; lW=Column_count;'''
    stack = []
    range_x = range(x-1, x+2)
    range_y = range(y-1, y+2)
    append = stack.append
    for i in range_x:
                if 0<=i<lH:#i is a valid index *Updated
                    for j in range_y:
                        if (0<=j<lW) and (lpic[i][j]=="0"):
                            lpic[i][j] = "1"
                            append([i, j])
    return stack
Run Code Online (Sandbox Code Playgroud)

我想知道是否有更好的方法来对Python2.5做同样的事情.

python loops multidimensional-array

2
推荐指数
2
解决办法
2751
查看次数

如何防止web2py自动编码html实体?

我想打印出HTML的用户提交产生的markdown,由

{{=markdown(post.message)}}
Run Code Online (Sandbox Code Playgroud)

通过输入降价功能的地方

from gluon.contrib.markdown.markdown2 import markdown
Run Code Online (Sandbox Code Playgroud)

We2Py似乎自动编码HTML-Entities,因此每个都<被转换成&lt;每个>转换成&gt;.我该如何防止这种情况发生?

在这样做时我是否需要记住任何安全问题?此外,任何人都可以告诉我如何HTML在将数据存储到数据库时将其剥离,同时保留markdown

html markdown web2py html-entities

2
推荐指数
1
解决办法
2551
查看次数

适用于Windows的AppEngine Python SDK无法使用EOFError运行应用程序

我在项目中使用Google AppEngine Python SDK for Windows,在尝试启动应用程序时出现以下错误.

2011-09-30 17:20:21 Running command: "['C:\\Python25\\pythonw.exe', 'C:\\Program Files\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8086', 'E:\\Programming\\Python\\notepyd']"
    WARNING  2011-09-30 11:51:10,549 urlfetch_stub.py:108] No ssl package found. urlfetch will not be able to validate SSL certificates.
    ERROR    2011-09-30 11:51:15,627 dev_appserver_main.py:644] <type 'exceptions.EOFError'>: 
    2011-09-30 17:21:15 (Process exited with code 1)
Run Code Online (Sandbox Code Playgroud)

这发生在停电后.我如何解决它?

python google-app-engine

1
推荐指数
1
解决办法
665
查看次数