我想从简单类型List创建一个更复杂的对象类型List.例如,List[String] => List[MyType].
我已经使用基于地图的方法给了它三个.带通配符的简单地图:
> case class telecom (name:String, longitude:Double, latitude:Double)
defined class telecom
> List("foo","bar").map(x:String => telecom(x,0,0)):List[telecom]
:1: error: ';' expected but ')' found.
Run Code Online (Sandbox Code Playgroud)
使用case类构造函数的模式匹配方法:
> def foo(c:List[String]){
| c match {
| case tc:List[telecom] => tc.map(telecom(_,0,0)):List[telecom]; println("matched telephonecomapny");
| case _ => println("matched nothing"); throw new ClassCastException(); }}
warning: there were unchecked warnings; re-run with -unchecked for details
foo: (c: List[String])Unit
> foo(List("foo","bar"))
java.lang.ClassCastException: java.lang.String cannot be cast to usda.rd.broadband.model.DatabaseTables$TelephoneCompany
at $anonfun$foo$1.apply(<console>:11)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206) …Run Code Online (Sandbox Code Playgroud) 得到一个文件,它有两个感兴趣的提交,都在Master分支上,都只修改一个文件foo:先前的提交AA,以及当前的版本HEAD.我想合并的文件的两个版本,保留两个位,为HEAD上Master.
我做了一件我觉得最简单的事情:
git checkout -b merge-purgatory AA
git commit -m "pulled foo back from previous commit for merging into HEAD."
git checkout master
git merge merge-purgatory
Run Code Online (Sandbox Code Playgroud)
它只是会覆盖当前HEAD的版本foo与AA版本.尝试更详细git checkout -m,同样的结果:愚蠢的覆盖.
如何强制git将AA版本foo视为与当前HEAD版本冲突的合并?
我在以下Windows Server 2k3批处理命令中遗漏了一些关于转义字符串或空格的内容(显而易见?).
FORFILES -m *.wsp -c "CMD /C C:\Program^ Files\Common^ Files\Microsoft^ Shared\web^ server^ extensions\12\bin\stsadm.exe^ -o^ addsolution^ -filename^ @FILE"
Run Code Online (Sandbox Code Playgroud)
导致以下错误
'C:\ Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe -o addsolution -filename"foobar.wsp"'无法识别为内部或外部命令,可运行程序或批处理文件.
但我无法弄清楚为什么.我正在处理Simon Sheppard先生的精美文档
给出一个类似(简化)的列表:
type foo(n:string,m:string,l:string) =
member f.name=n
member f.val1=m
member f.val2=l
let dates = [
foo("a","aa","aaa")
foo("b","bb","bbb")
]
Run Code Online (Sandbox Code Playgroud)
如何形成一个不可变的字典类型结构(例如,Map,IDictionary ......任何其他?)key:foo.name,value:foo?
我最好的猜测是
let fooDict = for f in foo do yield f.name,f
Run Code Online (Sandbox Code Playgroud)
但是for-comprehension语法只能用于制作列表,数组或seq?
以下类不使用反序列化(但序列化)System.Web.Script.Serialization.JavaScriptSerializer.
public class foo {
public KeyValuePair<string, string>? bar {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
尝试反序列化的结果System.NullReferenceException,当System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject到达bar属性.(注意,这是基于堆栈跟踪的推测.)
更改属性类型以KeyValuePair<string,string>修复问题,但我想尽可能保留Nullable类型.
JSON正是您所期望的:
{"foo": {
"bar": {
"Key":"Jean-Luc",
"Value":"Picard"
}
}}
Run Code Online (Sandbox Code Playgroud)
救命?
我需要匹配所有有效的 URL,除了:
http://www.w3.org
http://w3.org/foo
http://www.tempuri.org/foo
通常,除某些域之外的所有 URL。
这是我到目前为止所拥有的:
https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?
Run Code Online (Sandbox Code Playgroud)
将匹配足够接近我的需求的URL(但绝不是所有有效的URL!)(谢谢,http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/! )
https?://www\.(?!tempuri|w3)\S*
Run Code Online (Sandbox Code Playgroud)
将匹配所有包含www.,但不在tempuri或w3域中的 URL。
我真的想要
https?://([-\w\.]+)(?!tempuri|w3)\S*
Run Code Online (Sandbox Code Playgroud)
工作,但afaick,它似乎选择了所有http://字符串。
啊,我应该在乔姆斯基层次更高的地方做这件事!
如何在Scala XML中制作这种最小的HTML5
<!DOCTYPE html><title></title><p></p></html>?
当然,在Scala中制作类似HTML的XML很简单:
> val html = <html><title></title><p></p></html>
html: scala.xml.Elem = <html><title></title><p></p></html>
Run Code Online (Sandbox Code Playgroud)
但是,如何注入标记中带DOCTYPE前缀的属性html?
我尝试了两种方法:
使用scala.xml.Document和scala.xml.DocType,但是似乎都以写出文件或流为前提,而我只是将此XML对象保留在内存中。好像太多的仪式。
使用Attribute,
> import scala.xml.{Null, Text, Attribute}
> val d = <html /> % Attribute(None, "!DOCTYPE", Text(""), Null)
d: scala.xml.Elem = <html !DOCTYPE=""></html>
Run Code Online (Sandbox Code Playgroud)
这是封闭的,但不是前缀属性,并且具有顽皮的分配。
鉴于以下情况HashedAuthenticationCode:
import CryptoKit
let key = SymmetricKey(size: .bits256)
let message = "Hello world!".data(using: .utf8)!
let authenticationCode = HMAC<SHA256>.authenticationCode(for: message, using: key)
print(authenticationCode) // "HMAC with SHA256: c818a1400a9995d5faafbb5d41cc88a6701b5d1a4ded8ac169498319a2597e2a"
Run Code Online (Sandbox Code Playgroud)
我如何访问该c818a1400a9995d5faafbb5d41cc88a6701b5d1a4ded8ac169498319a2597e2a值?最终,这必须通过 a 进行编码和序列化URLSession,但我看不到获取 HAC 的“代码”部分的明显属性!
在Mac OS X 10.5(Leopard)w/Developer Tools上的默认Python安装上执行以下操作:
noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/bsddb/__init__.py", line 51, in <module>
import _bsddb
ImportError: No module named _bsddb
Run Code Online (Sandbox Code Playgroud)
很好,对吧?根据TMNC的建议或使用MacPorts等,如何在不放弃和安装/配置/维护我自己的Python软件包的情况下解决这个问题?
我通过MacPorts安装Python2.4和BSDDB解决了这个问题.
我的问题仍然存在:为什么默认安装被破坏并且可以修复它.
在一个全新create-react-native-app的 React Native 项目(使用)创建时,gradle 构建失败。
$ cd android/
$ ./gradlew build --debug
给出这个输出(截断到错误点)
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] InputStream: OriginalStream{jarFiles=[], folders=[], scopes=[SUB_PROJECTS], contentTypes=[CLASSES], dependencies=[prepareDebugDependencies, build dependencies configuration ':app:_debugApk' all dependencies]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] InputStream: OriginalStream{jarFiles=[], folders=[], scopes=[SUB_PROJECTS_LOCAL_DEPS], contentTypes=[CLASSES], dependencies=[prepareDebugDependencies, build dependencies configuration ':app:_debugApk' all dependencies]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] InputStream: OriginalStream{jarFiles=[], folders=[/Users/noel/w/crna-test/android/app/build/intermediates/classes/debug], scopes=[PROJECT], contentTypes=[CLASSES], dependencies=[compileDebugJavaWithJavac]}
16:17:09.777 [DEBUG] [com.android.build.gradle.internal.pipeline.TransformManager] OutputStream: IntermediateStream{rootLocation=/Users/noel/w/crna-test/android/app/build/intermediates/transforms/dex/debug, scopes=[PROJECT, PROJECT_LOCAL_DEPS, SUB_PROJECTS, SUB_PROJECTS_LOCAL_DEPS, EXTERNAL_LIBRARIES], contentTypes=[DEX], dependencies=[transformClassesWithDexForDebug]}
16:17:09.778 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project :app - Registering model element 'tasks.transformClassesWithDexForDebug' (hidden …Run Code Online (Sandbox Code Playgroud) scala ×2
android ×1
asp.net ×1
asp.net-ajax ×1
batch-file ×1
berkeley-db ×1
bsddb ×1
build.gradle ×1
cmd ×1
f# ×1
git ×1
html5 ×1
ios13 ×1
json ×1
list ×1
macos ×1
merge ×1
nullable ×1
osx-leopard ×1
python ×1
react-native ×1
regex ×1
swift ×1
url ×1
windows ×1
xml ×1