我正在编写一个PowerShell脚本,需要发出Web请求并检查响应的状态代码.
我试过写这个:
$client = new-object system.net.webclient
$response = $client.DownloadData($url)
Run Code Online (Sandbox Code Playgroud)
以及:
$response = Invoke-WebRequest $url
Run Code Online (Sandbox Code Playgroud)
但只要网页的状态代码不是成功状态代码,PowerShell就会继续并抛出异常,而不是给我实际的响应对象.
即使加载失败,如何获取页面的状态代码?
我想从纬度和经度双倍构造一个DbGeography点.
我知道我可以将我的双打转换为字符串并使用该DbGeography.FromText方法.
var latitude = 50.0d;
var longitude = 30.0d;
var pointString = string.Format(
"POINT({0} {1})",
longitude.ToString(),
latitude.ToString());
var point = DbGeography.FromText(pointString);
Run Code Online (Sandbox Code Playgroud)
但是将我的双打转换为字符串似乎是浪费,以便DbGeography可以再次将它们解析为双倍.
我试着像这样直接构建DbGeography:
var point = new DbGeography()
{
Latitude = 50,
Longitude = 30
};
Run Code Online (Sandbox Code Playgroud)
但纬度和经度属性是只读的.(这是有道理的,因为DbGeography类比单个点处理更多)
所述DbGeography类还提供了一种FromBinary采用一个字节阵列的方法.我不确定如何武装我的纬度和经度加倍到正确格式化的字节数组.
是否有一种更简单的方法来构建纬度和经度的DbGeography实例比顶部的代码加倍?
我正在尝试编写我的第一个AngularJS指令:一个涉及该link函数.正在加载该指令,但是当我在我的页面中使用它时,该link函数不会被调用.
这是小提琴:http://jsfiddle.net/jCUSh/115/
这是HTML:
<div ng-app="biApp">
<google-maps-symbol></google-maps-symbol>
</div>
Run Code Online (Sandbox Code Playgroud)
和JavaScript:
var appModule = angular.module('biApp', []);
appModule.directive('googleMapsSymbol', function () {
console.log("Directive was run");
return {
link: function (scope, elem, attrs) {
console.log("Link was called");
}
};
});
Run Code Online (Sandbox Code Playgroud)
我敢打赌,我做错了一些简单的事情.
在Haskell中,我可以定义一个这样的函数:
foo :: Int -> Int
foo n = n + 1
Run Code Online (Sandbox Code Playgroud)
如果我想成为肛门,我可以在最后一行添加类型签名,如下所示:
foo :: Int -> Int
foo n = n + 1 :: Int
Run Code Online (Sandbox Code Playgroud)
我也可以用bar这样的类型类定义一个函数:
class Rel a b where
aToB :: a -> b
bar :: (Rel a b) => a -> b
bar a = aToB a
Run Code Online (Sandbox Code Playgroud)
但是,如果我在执行中添加类型签名bar(良性更改,或者我认为),我会收到编译错误.
bar :: (Rel a b) => a -> b
bar a = aToB a :: b
Run Code Online (Sandbox Code Playgroud)
这是错误:
Could not deduce (Rel a b1) arising …Run Code Online (Sandbox Code Playgroud) 请参阅以下代码:
std::function<int(int)> makeFibonacci() {
std::function<int(int)> fibonacci = [&fibonacci](int n) {
if (n == 1) {
return 1;
}
if (n == 2) {
return 1;
}
return fibonacci(n-1) + fibonacci(n-2);
};
return fibonacci;
};
int main() {
std::function<int(int)> fibonacci = makeFibonacci();
std::cout << fibonacci(6) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,数字8按预期输出.但是,当我将捕获更改&fibonacci为仅fibonacci用于副本捕获时,程序实际上会main在其运行的第一行上进行段错误makeFibonacci.
如果fibonacci(第2行)是makeFibonacci函数的局部函数,因此当函数退出时超出范围,如何通过引用捕获并递归使用?另外,为什么当我通过副本捕获lambda时程序会出现段错误?
我试图使用c ++类型系统删除复制构造函数,以防止复制对象.
struct DeleteCopyConstructor {
DeleteCopyConstructor() {};
DeleteCopyConstructor(DeleteCopyConstructor& op2) = delete;
DeleteCopyConstructor(const DeleteCopyConstructor& op2) = delete;
};
DeleteCopyConstructor f() {
DeleteCopyConstructor d;
// initialize d...
return d;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
error: use of deleted function ‘DeleteCopyConstructor::DeleteCopyConstructor(const DeleteCopyConstructor&)’
Run Code Online (Sandbox Code Playgroud)
我读过有关复制省略,但它似乎是一个编译器优化,所以我认为它不适用.如何在d不触发复制构造的情况下返回?
因此,我想做一些高级的类型级黑客技术,我真的希望能够编写一个概念,要求类型具有constexpr int与其关联的值,稍后我可以在与整数std::array模板参数。
可以写
template<typename T>
concept bool HasCount = requires {
typename T::count;
};
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的;我想T::count成为一个static constexpr int。但是,代码(甚至不包括所需的constexpr)
template<typename T>
concept bool HasCount = requires {
int T::count;
};
Run Code Online (Sandbox Code Playgroud)
在 GCC 7.3.0 上编译时不会出现“错误:预期的主表达式在 'int' 之前”。
另一个失败的尝试:可以这样写,这需要static int T::count():
template<typename T>
concept bool HasCount = requires {
{T::count()} -> int;
};
Run Code Online (Sandbox Code Playgroud)
但不是这个,这就是我想要的:
template<typename T>
concept bool HasCount = requires {
{T::count()} -> constexpr int;
{T::count() constexpr} -> int; // or …Run Code Online (Sandbox Code Playgroud) 我正在安装Unity.Unity安装程序说它必须以root身份运行,这是因为Chromium Embedded Framework必须以root身份运行.为什么Chromium Embedded Framework必须以root身份运行?
Unity安装程序在这里指出了我,但该页面没有提到root权限.
这是控制台输出,为后人:
lol@localhost:unity(0)\ ./unity-editor-installer-5.4.0b23+20160628.sh
This installer must be run as root.
Run Code Online (Sandbox Code Playgroud)
以及安装程序的相关代码段:
# chrome-sandbox requires this: https://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
chown root "${EXTRACT_SUBDIR}/Editor/chrome-sandbox"
chmod 4755 "${EXTRACT_SUBDIR}/Editor/chrome-sandbox"
Run Code Online (Sandbox Code Playgroud)
编辑7月15日:找到这个帖子.有人可以帮助确认chrome-sandbox上不再需要root所有权和SUID吗?
我正按照这些说明进行构建,但在运行cros_sdk时仍然需要root密码.
我有一个 Haskell 程序,可以定期记录一些数据。当我将其作为后台进程运行时,除非我将缓冲模式更改为NoBuffering. 我不明白为什么默认设置LineBuffering不起作用。
这是我的测试程序:
import Control.Concurrent (forkIO, threadDelay)
import Control.Monad (forever)
import System.IO (BufferMode(..), hSetBuffering, stdout)
main :: IO ()
main = forever $ do
-- hSetBuffering stdout NoBuffering
threadDelay $ 1000 * 1000
putStrLn "log"
Run Code Online (Sandbox Code Playgroud)
当我在控制台中正常运行该程序时,我得到预期的输出:
$ ./Main
log
log
log
Run Code Online (Sandbox Code Playgroud)
每秒输出一次“log”。当我将其重定向到文件时,它也按预期工作:
$ ./Main >log
^C
$ cat log
log
log
log
Run Code Online (Sandbox Code Playgroud)
但是,当我将其作为后台进程运行时:
$ ./Main >log &
$ cat log
Run Code Online (Sandbox Code Playgroud)
那么日志文件中不会写入任何内容,除非我取消注释将 stdout 缓冲设置为NoBuffering.
我使用该hGetBuffering函数来确定默认缓冲设置,它是LineBuffering. 考虑到每个“log”语句确实位于不同的行,为什么我需要将缓冲模式设置为NoBuffering以便将日志写入日志文件?IE 当缓冲区模式设置为 …
通常,您可以针对实例化的模板类部分地专门化模板类.例如
template<class T>
struct specialize_me {};
template<class T>
struct specialize_me<std::vector<T>> {
static const int foo = 3;
};
Run Code Online (Sandbox Code Playgroud)
模板类specialize_me部分专门针对实例化的模板类std::vector<T>.对于任何类,在specialize_me实例化时选择此特化.std::vector<T>T
int main() {
std::cout << specialize_me<std::vector<int>>::foo; // Compiles.
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何针对实例化的嵌套模板类专门化模板模板类:
// Nested template class.
template<class T>
struct Either {
template<class U>
struct Or {};
};
template<template<class> class T>
struct specialize_me_2 {};
template<class T>
struct specialize_me_2<Either<T>::template Or> {
static const int foo = 3;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当我使用任何类的类实例化时,不会选择特化.我的猜测是,这是因为编译器将不得不证实或否认,"目前存在这样相同类型的实例化",以便选择我的专业化,它没有被编程也没有规定这样做.specialize_me_2Either<T>::template OrTTEither<T>::template …
c++ ×4
haskell ×2
angularjs ×1
c++-concepts ×1
class ×1
copy-elision ×1
geospatial ×1
lambda ×1
oop ×1
powershell ×1
templates ×1
typeclass ×1