小编Ian*_*hek的帖子

我可以在Docker容器中运行多个程序吗?

我试图从部署一个旨在在桌面上运行的应用程序的角度来绕过Docker.我的应用程序只是一个烧瓶Web应用程序和mongo数据库.通常我会在VM中安装它们,并将主机端口转发到来宾Web应用程序.我想尝试一下Docker,但我不确定我打算如何使用多个程序.文件说只有ENTRYPOINT,所以我怎么能有Mongo和我的烧瓶申请.或者他们需要在单独的包含中,在这种情况下他们如何相互交谈以及这如何使分发应用程序变得容易?

docker

132
推荐指数
6
解决办法
9万
查看次数

Chrome是否使用XPath 2.0?

我的印象是所有最新的浏览器现在都使用XPath 2.当我使用lower-case()uppser-case()(版本2中引入的功能)时,Chrome会抛出语法错误.然而,他们较旧的替代品translate()工作正常.

这是一个错误还是最新的Chrome实际上使用XPath 1?是否有命令/方法来找出XPath版本?

// Finds the element as expected.
$x('//h2/text()[. = "Delete"]') 

// Doesn't find the element (also expected).
$x('//h2/text()[. = "delete"]') 

// SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//h2/text()[lower-case(.) = "delete"]' is not a valid XPath expression.
$x('//h2/text()[lower-case(.) = "delete"]')
Run Code Online (Sandbox Code Playgroud)

selenium xpath google-chrome selenium-chromedriver

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

Phalcon重定向和转发

我是否理解正确,$this->dispatcher->forward()或者$this->response->redirect()我需要手动确保其余代码不会被执行?如下,或者我错过了什么?

public function signinAction()
{
    if ($this->isUserAuthenticated())
    {
        $this->response->redirect('/profile');
        return;
    }

    // Stuff if he isn't authenticated…
}
Run Code Online (Sandbox Code Playgroud)

phalcon

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

从Phalcon查询构建器获取原始sql

是否可以从Phalcon中的查询构建器实例中提取原始sql查询?像这样的东西?

$queryBuilder = new Phalcon\Mvc\Model\Query\Builder();
$queryBuilder
    ->from(…)
    ->where(…);

$rawSql = $queryBuilder->hypotheticalGetRawQueryMethod();
Run Code Online (Sandbox Code Playgroud)

phalcon

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

从CGImage获取像素格式

我理解位图布局和像素格式主题相当不错,但在处理通过加载的png/jpeg图像时出现问题NSImage- 我无法弄清楚我得到的是预期的行为还是错误.

let nsImage:NSImage = NSImage(byReferencingURL: …)
let cgImage:CGImage = nsImage.CGImageForProposedRect(nil, context: nil, hints: nil)!
let bitmapInfo:CGBitmapInfo = CGImageGetBitmapInfo(cgImage)
Swift.print(bitmapInfo.contains(CGBitmapInfo.ByteOrderDefault)) // True
Run Code Online (Sandbox Code Playgroud)

我的kCGBitmapByteOrder32Host是小端,这意味着像素格式也是小端 - 在这种情况下是BGRA.但是...... png格式是规范的大端,这就是字节实际排列在数据中的方式 - 与位图信息告诉我的方式相反.

有人知道发生了什么吗?当然,系统会以某种方式知道如何处理这个问题,因为png正确显示.是否有检测CGImage像素格式的防弹方式?GitHub提供完整的演示项目.


PS我正在通过CFDataGetBytePtr缓冲区将原始像素数据复制到另一个库缓冲区,然后进行处理和保存.为此,我需要明确指定像素格式.我正在处理的实际图像(我检查过的任何png/jpeg文件)显示正确,例如:

但是相同图像的位图信息给出了不正确的字节序信息,导致位图被处理为BGRA像素格式而不是实际的RGBA,当我处理它时,结果如下所示:

生成的图像演示了红色和蓝色像素之间的颜色交换,如果明确指定RGBA像素格式,一切都很完美,但我需要将此检测自动化.


PPS文档简要提到这CGColorSpace是定义像素格式/字节顺序的另一个重要变量,但我没有提到如何将它从那里拿出来.

core-graphics bitmap endianness swift

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

检查变量是否是Swift中的块/函数/可调用

在Swift中是否有一种简单明确的方法来检查某些东西是否是可调用的块/函数?在某些语言中,这是一件微不足道的事情,但也许我从Swift的错误角度看待这个问题?考虑以下.

func foo(){ print("foo") }
var bar: () -> () = { print("bar") }
var baz: () -> (Bool) = { print("baz"); return true }

print(foo) // (Function)
print(bar) // (Function)
print(baz) // (Function)

print(foo is () -> ()) // true
print(bar is () -> ()) // true
print(baz is () -> ()) // false
print(baz is () -> (Bool)) // true
Run Code Online (Sandbox Code Playgroud)

Swift知道它们都是函数,尽管没有这样的数据类型.我可以使用可靠的签名进行检查,但可能存在我不关心签名*并且只是想调用它的情况.例如:

func call(callable: () -> ()) {
    callable()
}

call(foo) // foo
call(bar) // bar
call(baz) …
Run Code Online (Sandbox Code Playgroud)

swift

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

关闭会话而不写入或销毁它

有没有办法关闭 PHP 会话而不写入或销毁它?我是否遗漏了某些内容,或者只有两个功能(session_write_close()session_destroy())重置session_status()PHP_SESSION_NONE?换句话说,如果我有一个打开的会话,我可以简单地关闭它而不影响外部会话数据,以便可以再次重新加载它。

php session

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

自定义类的依赖注入在L4.2中陷入无限循环?

我一直在改变我的控制器和辅助类以使用依赖注入,似乎我的助手类被卡在无限循环中.

下面是我的自定义ServiceProvider和两个示例助手类.正如你所看到的,他们互相注入,所以他们不停地来回走动.

这个问题的解决方案是什么?我似乎犯了什么错误?我能做些什么,这样我可以运行于辅助类,如测试GeneralPerson,而嘲笑那些从他们内部叫助手类?

我认为可行的一种方法是在我的ServiceProvider中,执行以下操作:

if (isset($appmade->General)) { 
    // inject the General app that's already instantiated 
} else { 
    $abc = app::make('\Lib\MyOrg\General'); 
    $appmade->General = $abc; 
} 
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?

// /app/providers/myorg/MyOrgServiceProvider.php

namespace MyOrg\ServiceProvider;
use Illuminate\Support\ServiceProvider;
class MyOrgServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind('\Lib\MyOrg\General', function ($app) {
            return new \Lib\MyOrg\General(
                $app->make('\Lib\MyOrg\Person'),
                $app->make('\App\Models\User')
            );
        });

        $this->app->bind('\Lib\MyOrg\Person', function ($app) {
            return new \Lib\MyOrg\Person(
                $app->make('\Lib\MyOrg\General'),
                $app->make('\App\Models\Device')
            );
        });
    }
}

// /app/libraries/myorg/general.php

namespace Lib\MyOrg;
use App\Models\User;
use Lib\MyOrg\Person;
class …
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing laravel laravel-4

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

检查应用程序范围书签下的路径是否可在沙盒应用程序内写入

我有一个OS X应用程序,它存储应用程序范围的书签以持久访问某些目录.我能够毫无问题地写入这些目录,但是我的代码中有一部分我要进行额外的检查以确认路径是可写的并且失败了.

var fileManager: NSFileManager = NSFileManager.defaultManager()
var baseUrl: NSURL = try! NSURL(byResolvingBookmarkData: data, …)
var fileUrl: NSURL = url.URLByAppendingPathComponent("foo.txt")

// Changing this order has no effect, I make only the first start access call,
// the second one is to demonstrate that it's not working.

baseUrl.startAccessingSecurityScopedResource() // true
fileUrl.startAccessingSecurityScopedResource() // false

// File manager confirms that base path is writable, but anything inside
// it – not. This worked perfectly fine before sandboxing the app.

fileManager.isWritableFileAtPath(baseUrl.path!) // true
fileManager.isWritableFileAtPath(fileUrl.path!) …
Run Code Online (Sandbox Code Playgroud)

security sandbox objective-c appstore-sandbox swift

5
推荐指数
0
解决办法
218
查看次数

使 CIContext.render(CIImage, CVPixelBuffer) 与 AVAssetWriter 一起使用

我想使用 Core Image 处理一堆对象并将它们转换为macOSCGImage上的 QuickTime 影片。以下代码演示了所需内容,但输出包含大量空白(黑色)帧

\n\n
import AppKit\nimport AVFoundation\nimport CoreGraphics\nimport Foundation\nimport CoreVideo\nimport Metal\n\n// Video output url.\nlet url: URL = try! FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("av.mov")\ntry? FileManager.default.removeItem(at: url)\n\n// Video frame size, total frame count, frame rate and frame image.\nlet frameSize: CGSize = CGSize(width: 2000, height: 1000)\nlet frameCount: Int = 100\nlet frameRate: Double = 1 / 30\nlet frameImage: CGImage\n\nframeImage = NSImage(size: frameSize, flipped: false, drawingHandler: {\n    NSColor.red.setFill()\n    $0.fill()\n    return true\n}).cgImage(forProposedRect: nil, context: nil, …
Run Code Online (Sandbox Code Playgroud)

core-graphics core-image avfoundation metal

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

此页面要求您确认是否要离开

我在我的网站安装上运行behat测试.运行测试时出现以下错误.我转而使用firefox,因为我遇到了新的chromedriver 2.10的问题.我可以解决这个问题吗?

错误信息:

Modal dialog present: This page is asking you to confirm that you want to leave - data you have entered may not be saved.

Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'jesus-ProLiant-MicroServer', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.6.0_32'

Session ID: 2d072ef8-60e8-494b-b389-96e954041fb0
Driver info: org.openqa.selenium.firefox.FirefoxDriver

Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=31.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
Run Code Online (Sandbox Code Playgroud)

firefox drupal behat mink ubuntu-12.04

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

从PHP脚本运行"sudo"命令?

我想从PHP运行一个"sudo"命令,我已经阅读了网络上的所有教程,但没有解决方案.至少我已经将LAMP的默认"nobody"用户添加到根组 - 但没有效果.

echo exec("sudo echo hi");
Run Code Online (Sandbox Code Playgroud)

关于安全的说明:

虽然这里的一些人由于坚信这会造成一个破坏整个互联网的大安全漏洞而贬低这一点,但有一些有效的案例,例如在测试中.从PHPUnit/Behat套件运行安装脚本来配置环境可能需要sudo权限.这些脚本无法从应用程序访问,也不会产生安全漏洞,因为事实上它们有助于确保不存在此类漏洞.

php linux sudo

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