这是我的Plunker:
http://plnkr.co/edit/oIei6gAU1Bxpo8VUIswt
单击该按钮时,应在"Hello World!"之前插入以下内容!跨度:
<script type="text/ng-template" id="tempTest">
<div>
<span>Properly Inserted</span>
</div>
</script>
Run Code Online (Sandbox Code Playgroud)
当然,减去脚本标签.
我通过动态插入以下div实现此目的:
<div ng-include="tempTest"></div>
Run Code Online (Sandbox Code Playgroud)
然后编译它.但是,如果查看日志,编译后剩下的唯一内容是:
<!-- ngInclude: tempTest -->
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?为什么我的插件没有正确编译?逻辑如下:
$scope.insert = function(){
// Create elements //
var container = angular.element('<div id="compiled-container"></div>');
var element = angular.element('<div ng-include="tempTest"></div>');
//Insert parent Container
$('#greeting').before(container);
// insert the element
$animate.enter(element, container);
// test insertion
console.log("Before Compile: " +container.html() )
$compile(element);
//look again after compile
console.log("After Compile: " +container.html() )
};
Run Code Online (Sandbox Code Playgroud) 在python中,我得到了一个64位整数.这个Integer是通过采用几个不同的8位整数并将它们拼接成一个巨大的64位整数而创建的.我的工作是再次分开他们.
例如:
Source number: 2592701575664680400
Binary (64 bits): 0010001111111011001000000101100010101010000101101011111000000000
int 1: 00100011 (35)
int 2: 11111011 (251)
int 3: 00100000 (32)
int 4: 01011000 (88)
int 5: 10101010 (170)
int 6: 00010110 (22)
int 7: 10111110 (190)
int 8: 00000000 (0)
Run Code Online (Sandbox Code Playgroud)
所以我想做的是获取我的源编号2592701575664680373并返回一个长度为8的数组,其中数组中的每个int都是上面列出的int.
我本来打算使用struct,但说实话,阅读文档并没有清楚地说明我将如何实现这一目标.
我有一个自托管的c#consol web API.它为使用AngularJS执行异步http请求的多个Web应用程序提供服务.它需要同时具有CORS支持和NTLM身份验证.
我目前都已启用,但看起来我实现它们的方式会导致它们自行取消.我相信这是由我最初的401服务器响应来解决的.这通常会导致两者之间的身份验证握手,但是在Fiddler中查看它,这个初始的401响应缺少一个Access-Control-Allow-Origin标记,这会导致浏览器放弃握手.我已经使用了一个应用程序并给它们相同的主机名来禁用CORS,并且握手工作正常.我通过用原始的HttpSelfHostConfiguration替换我的自定义NtlmSelfHostConfiguration来禁用NTLM身份验证,并且Access-Control-Allow-Origin标记完美地执行以允许CORS.只有当它们都处于活跃状态时,它才会起作用.
更新:我在CorsHandle中放置了一个不需要它的请求的断点,只是为了确保网络服务器在使用NtlmSelfHostConfiguration时可以实际调用它,并且它被成功命中.我只是想确保NtlmSelfHostConfiguration中没有任何物理上阻止Corshandle被调用的东西.一切正常,显然我需要找到一种方法来调用CorsHandle,即使是在身份验证失败的请求上也是如此.
这是我的意思:
Program.cs中:
using System.Web.Http;
using System.Web.Http.Validation.Providers;
using System.Web.Http.SelfHost;
namespace DCMAPI
{
class Program
{
static void Main(string[] args)
{
string BaseAddress = "http://localhost:8080/";
//NtlmSelfHostConfiguration is defined in HttpSelfHostConfiguration.cs
//it inherits from HttpSelfHostConfiguration
//and enables Ntlm Authentication.
var config = new NtlmSelfHostConfiguration(BaseAddress);
config.Routes.MapHttpRoute(
"API Default",
"api/{controller}/{id}",
new { id = RouteParameter.Optional });
//CorsHandler is also defined in CorsHandler.cs. It is what enables CORS
config.MessageHandlers.Add(new CorsHandler());
var appXmlType =
config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault
(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
config.Services.RemoveAll …Run Code Online (Sandbox Code Playgroud) 我的班级MyClass<t>有以下方法
private static bool TypeHasProperty(string NameOfPropertyToMatch)
{
var properties = typeof(t).GetProperties();
var requiredProperty = properties.First(
a => a.Name == NameOfPropertyToMatch);
if (requiredProperty == null)
{
return false
};
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是在静态方法的开头调用的:
MyClass<t>.SendToJavaScript(t InstanceOfType, string NameOfPropertyWithinType).
InstanceOfType在继续之前确保实际上具有该名称的属性,因为否则直到waaaaay下线才会抛出异常(此信息最终会被序列化并发送到Javascript应用程序,这需要知道要访问哪个属性为了做它的工作).
我想要一个好的,类型安全的方法来调用那个不会导致验证失败的方法,如果我决定稍后在线上更改我的属性的名称.
例如,我不想这样称呼它:
MyClass<Person>.SendToJavaScript(MyPerson, "Name")
Run Code Online (Sandbox Code Playgroud)
因为如果我决定改变Name到LastName,的Person课,我将不得不作出一定要进来,改变魔术字符串.
我想要的是这样的:
MeClass<Person>.SendToJavaScript(
MyPerson,
TypeOf(Person).Properties.Name.ToString())
Run Code Online (Sandbox Code Playgroud)
因此,如果我使用重构更改Name为LastName,IDE将扫描那里并更改我的调用.
这样的事情存在吗?或者我在重构时只需要小心一点?(我爱我一些F2)
假设我有一个可以序列化为字符串的简单数据类:
class Time(val hours: Int, val minutes: Int, val seconds: Int) {
fun serialize(): String {
return "%02d:%02d:%02d".format(hours, minutes, seconds)
}
}
Run Code Online (Sandbox Code Playgroud)
如何添加第二个构造函数来允许我使用序列化字符串构造此对象?我期望能够使用
constructor(serializedString: String) {
val subs = serializedString.split(":")
return Time(subs[0].toInt(),subs[1].toInt(),subs[2].toInt())
}
Run Code Online (Sandbox Code Playgroud)
但后来发现辅助构造函数实际上需要重写主构造函数。显然,我的辅助构造函数的形状或形式与我的主构造函数完全不同。
companion object包含静态deserialize方法的 a 吗?我喜欢使用的东西DataFrames是将函数调用链接在一起的能力.我遇到的问题是我很难找到允许你执行引用列的一个cast或一个withColumn操作的语法DataFrame.例如:
counts = sqlContext.read.format("com.databricks.spark.csv") \
.options(header=True) \
.load(path) \
.filter("cast(filterColumn as int) in (8, 11, 12)") \
.withColumn('newColumn',df.oldColumn.cast("date")) \ #<-- df doesn't exist, silly!
.groupBy(df.newColumn) \
.count() \
.collect()
Run Code Online (Sandbox Code Playgroud)
值得注意的是,在演唱会中演出非常有效filter.不幸的是,它似乎没有withColumn或groupBy支持那种字符串api.我试过这样做
.withColumn('newColumn','cast(oldColumn as date)')
Run Code Online (Sandbox Code Playgroud)
但只是因为没有通过以下实例而被大吼column:
assert isinstance(col, Column), "col should be Column"
Run Code Online (Sandbox Code Playgroud)
这是我试图做同样的事情时遇到的完全相同的问题 groupBy
我只需要咬紧牙关并将它们分开吗?
df = sqlContext.read.format("com.databricks.spark.csv") \
.options(header=True) \
.load(path) \
.filter("cast(filterColumn as int) in (8, 11, 12)")
counts = df.withColumn('newColumn',df.oldColumn.cast("date"))
.groupBy(df.newColumn) \ …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用ASP.NET Web API.
虽然我对模板和类似的事情没有任何反对意见,但我更愿意在信任为我生成的代码之前至少完全理解底层的内容.
我很难找到任何类型的指南,可以从头开始构建ASP.net WEB API,而不需要MCV Web API项目模板中提供的任何脚手架.
所以我的问题是:Web API的哪些部分是用于启动和运行API的简单代码?
此外,如果有一个指南,我没有找到有人可以指向我,这也将不胜感激.
假设我有以下课程:
public class Gender
{
public readonly string Name { get; set;}
public readonly char Abbreviation { get; set;}
public readonly string ChildName { get; set;}
public readonly int Number { get; set;}
public static Gender Male = new Gender { Name = "Male", Abbreviation = 'M', Number = 1, ChildName = "Boy" };
public static Gender Female = new Gender { Name = "Female", Abbreviation = 'F', Number = 2, ChildName = "Girl" };
public static Gender Unknown = …Run Code Online (Sandbox Code Playgroud) 假设我有一套套词:
d = {"foo":{1,2,3},
"bar":{3,4,5}}
Run Code Online (Sandbox Code Playgroud)
现在假设我想将值添加7到密钥中找到的集合中foo.这很容易:
d["foo"].add(7)
Run Code Online (Sandbox Code Playgroud)
但是,如果我们不确定已存在的密钥怎么办?事先检查并不觉得非常pythonic:
if "baz" in dict:
d["baz"].add(7)
else:
d["baz"] = {7}
Run Code Online (Sandbox Code Playgroud)
我试图变得聪明并做类似的事情
d["baz"] = set(d["baz"]).add(7)
Run Code Online (Sandbox Code Playgroud)
但是你只是KeyError试图在set构造函数中访问一个坏键.
我错过了什么,或者我需要咬紧牙关,看看我跳跃之前?我会理解,如果是这种情况,只要有一种简单的方法可以说"将此值添加到此位置找到的集合,或者如果该位置没有集合,则创建一个,并且然后把它放进去.
我有两个条件,ShouldCheckForErrors而且HasErrors
我的代码是
if(ShouldCheckForErrors && HasErrors)
{
//Do nothing
}
else
{
PassTest()
}
Run Code Online (Sandbox Code Playgroud)
我觉得这是一张很长的支票.有没有办法我可以做一次检查而不必使用else?
例如:
if(!ShouldCheckForErrors && !HasErrors)
{
PassTest()
}
Run Code Online (Sandbox Code Playgroud)
不工作,因为这将无法打电话PassTest()的时候ShouldCheckforErrors是true,但是HasErrors是false.(反之亦然)
我觉得我忘记了逻辑运算符.
我正在尝试编写一个在多个层上有边界的接口。例如,请考虑以下代码:
// the bound type on U is unexpected and doesn't compile
public interface CollectionNumberWrapper<T extends Collection<U extends Number>> {
void setData(T data);
U sumOfAllNumbersInCollection()
};
public class NumberCollection implements List<AtomicInteger>{
///...implement...
};
public class StringCollection implements Collection<String>{
///...implement...
};
//This should be legal
public class NumberCollectionWrapper implements CollectionNumberWrapper<NumberCollection>{
@Override
void setData(NumberCollection data){
//...
};
@Override
AtomicInteger sumOfAllNumbersInCollection(){
//...
}
}
//This should not be legal, the type parameter should be out of bounds
public class StringCollectionWrapper implements CollectionNumberWrapper<StringCollection>{
} …Run Code Online (Sandbox Code Playgroud)