问:
Upgrading a web site project from .NET 2.0 to 4.5.2: missing ScriptManager, ScriptService, ScriptMethod
Tried to upgrade a .NET 2.0 web site project in VB to 4.5.2 and that broke compilation with the errors

```<code>BC30002 Type 'ScriptManager' is not defined.
BC30002 Type 'System.Web.Script.Services.ScriptMethod' is not defined.
BC30002 Type 'System.Web.Script.Services.ScriptService' is not defined.
</code>```

Tried Import System.Web.UI but it did not work and there was a warning that the import was unnecessary. Same with System.Web.Extensions.

The first error occurs on the line:

```<code>Public ReadOnly Property ScriptManagerObject() As ScriptManager
    Get
        Return Me.ScriptManager1
    End Get
End Property
</code>```

The member is defined in ASPX as

```<code><asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="AutoComplete.asmx" />
    </Services>
</asp:ScriptManager>
</code>```

What should I do to point the compiler at the correct namespace for ScriptManager etc?

EDIT:

Tried adding this line to the ASPX page:

```<code><%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>
</code>```

Did not work.

Tried adding a reference to System.Web.Extensions for 4.0 framework. Did not work.

Tried deleting the ScriptManager1 object from ASPX and re-adding it from the Toolbox under the same name. It is still not found as a member of the page's class. How can we solve this mystery?

答:
This is the answer: https://stackoverflow.com/a/19128973/2721750
Reverting to 3.5 and repeating the upgrade to 4.5.2
Apparently it makes more changes to web.config and includes tons more assembly references, some of whom might have been missed on the initial upgrade.

Body:
Tried to upgrade a .NET 2.0 web site project in VB to 4.5.2 and that broke compilation with the errors

BC30002 Type 'ScriptManager' is not defined.
BC30002 Type 'System.Web.Script.Services.ScriptMethod' is not defined.
BC30002 Type 'System.Web.Script.Services.ScriptService' is not defined.

Tried Import System.Web.UI but it did not work and there was a warning that the import was unnecessary. Same with System.Web.Extensions.

The first error occurs on the line:

Public ReadOnly Property ScriptManagerObject() As ScriptManager
    Get
        Return Me.ScriptManager1
    End Get
End Property

The member is defined in ASPX as

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="AutoComplete.asmx" />
    </Services>
</asp:ScriptManager>

What should I do to point the compiler at the correct namespace for ScriptManager etc?

EDIT:

Tried adding this line to the ASPX page:

<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>

Did not work.

Tried adding a reference to System.Web.Extensions for 4.0 framework. Did not work.

Tried deleting the ScriptManager1 object from ASPX and re-adding it from the Toolbox under the same name. It is still not found as a member of the page's class. How can we solve this mystery?


来源: stackexchange

问:
How to extract the non-empty elements of list in R?
I have very big list, but some of the elements(positions) are NULL, means nothing inside there.
I want just extract the part of my list, which is non-empty. Here is my effort, but I faced with error:

```<code>ind<-sapply(mylist, function() which(x)!=NULL)
list<-mylist[ind]

#Error in which(x) : argument to 'which' is not logical
</code>```

Would someone help me to implement it ?

答:
Try this:

```<code>list(NULL, 1, 2, 3, NULL, 5) %>%
     purrr::map_if(is.null, ~ NA_character_) %>% #convert NULL into NA
     is.na() %>% #find NA
     `!` %>%     #Negate
     which()     #get index of Non-NULLs
</code>```

or even this:

```<code>list(NULL, 1, 2, 3, NULL, 5) %>%
     purrr::map_lgl(is.null) %>%
     `!` %>% #Negate
     which()
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have very big list, but some of the elements(positions) are NULL, means nothing inside there.
I want just extract the part of my list, which is non-empty. Here is my effort, but I faced with error:

ind<-sapply(mylist, function() which(x)!=NULL)
list<-mylist[ind]

#Error in which(x) : argument to 'which' is not logical

Would someone help me to implement it ?

Body:
Try this:

list(NULL, 1, 2, 3, NULL, 5) %>%
     purrr::map_if(is.null, ~ NA_character_) %>% #convert NULL into NA
     is.na() %>% #find NA
     `!` %>%     #Negate
     which()     #get index of Non-NULLs

or even this:

list(NULL, 1, 2, 3, NULL, 5) %>%
     purrr::map_lgl(is.null) %>%
     `!` %>% #Negate
     which()


问:
Kentico - Display query string as value of input field
I want to display the query string (if it's not empty) as the value of an input field, something like this <input name="campaign" type="hidden" value="ABC Campaign {% if (QueryString.GetValue("utm_source") != null) { return "| QueryString.GetValue("utm_source")"} %}" />

but couldn't make it work due to all the double quotes. I've tried escaping the quotes with back slash but didn't work. Could you help?
(The above code is placed inside the Form > Layout)

答:
Even shorter!

```<code>{% Convert.ToString(QueryString.utm_source, "") %}
</code>```

But if you want it to have a | before it, then you'll have to use

{% string.isnullorwhitespace(QueryString.utm_source) ? "" : "|"+QueryString.utm_source %}

Body:
Even shorter!

{% Convert.ToString(QueryString.utm_source, "") %}

But if you want it to have a | before it, then you'll have to use

{% string.isnullorwhitespace(QueryString.utm_source) ? "" : "|"+QueryString.utm_source %}


问:
Java: Algorithm to match a string with unknown characters
I have data stored in a database.
Database has 3 columns:
2 columns containing 6-character numeric strings (matching),
1 column contains the result

User can input 2 strings, I have to create an algorithm to match strings and get the result.

The allowed values are numbers from 0 to 9, *, X and Y

```<code>EXAMPLE:

match1    match2      RESULT

123456    123*56      A
1234X8    123*X8      b
1*4567    1*5435      c
345**7    ******      d
12454X    12X124      E
123X5Y    123Y12      F
</code>```

Represents any possible value
X and Y represent any value but different from themselves

if user insert:

```<code>123456 , 123756 ----> result are A

123498 , 123198 ----> result are B

123456 , 123412 ----> no results......because to obtain "F"....y
                      have to be equals from inputs and 6!=4
</code>```

答: This is not the way ... so it was simple. You have to test the X and Y characters too. X represents any value but must be the same for all positions, but must be different from Y</p>

Body:
I have data stored in a database.
Database has 3 columns:
2 columns containing 6-character numeric strings (matching),
1 column contains the result

User can input 2 strings, I have to create an algorithm to match strings and get the result.

The allowed values are numbers from 0 to 9, *, X and Y

EXAMPLE:

match1    match2      RESULT

123456    123*56      A
1234X8    123*X8      b
1*4567    1*5435      c
345**7    ******      d
12454X    12X124      E
123X5Y    123Y12      F

Represents any possible value
X and Y represent any value but different from themselves

if user insert:

123456 , 123756 ----> result are A

123498 , 123198 ----> result are B

123456 , 123412 ----> no results......because to obtain "F"....y
                      have to be equals from inputs and 6!=4


问:
Command failed due to signal: Segmentation fault: 11
I'm getting the error ...

Command failed due to signal: Segmentation fault: 11

... when trying to compile my Swift app. I'm using Xcode 6.1, trying to build for an iPhone 5 on iOS 8.1.

My Code

```<code>import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var username: UITextField!
    @IBAction func signIn(sender: AnyObject) {

        PFUser.logInWithUsernameInBackground(username.text, password:"mypass") {
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = " "
                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }

             println(error)
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        Parse.setApplicationId("key here")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
</code>```

And the error text!

```<code>CompileSwift normal arm64 /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift
    cd /Users/Alec/Desktop/Re-Chat/Re-Chat
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o
0  swift                    0x0000000108145a68 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x0000000108145f54 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff86631f1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fd0ac1eb010 _sigtramp + 633049360
4  swift                    0x00000001075d4517 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::AnyFunctionRef) + 1303
5  swift                    0x00000001075c599e swift::Lowering::SILGenFunction::visitFuncDecl(swift::FuncDecl*) + 190
6  swift                    0x000000010760987c swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 380
7  swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
8  swift                    0x000000010760a0a5 swift::Lowering::SILGenFunction::visitIfStmt(swift::IfStmt*) + 757
9  swift                    0x000000010760c8f6 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 166
10 swift                    0x00000001076097e8 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 232
11 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
12 swift                    0x00000001075d52dd swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 205
13 swift                    0x00000001075b4234 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 196
14 swift                    0x00000001075eef71 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
15 swift                    0x00000001075e1866 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 2870
16 swift                    0x00000001075e24da swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 6058
17 swift                    0x00000001075cfa0b swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 235
18 swift                    0x00000001075ae824 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&) && + 196
19 swift                    0x0000000107604a69 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 233
20 swift                    0x00000001075f371c swift::Lowering::SILGenFunction::emitInjectOptionalValueInto(swift::SILLocation, swift::Lowering::RValueSource&&, swift::SILValue, swift::Lowering::TypeLowering const&) + 268
21 swift                    0x00000001075e9b8d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 36445
22 swift                    0x00000001075e3e2b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 12539
23 swift                    0x00000001075e202b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4859
24 swift                    0x00000001075cfab6 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
25 swift                    0x00000001075bffc4 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 836
26 swift                    0x00000001075bf582 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 98
27 swift                    0x00000001075b7ff8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1128
28 swift                    0x00000001075b751a swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 58
29 swift                    0x00000001075e0d81 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 81
30 swift                    0x00000001075ea00d swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 237
31 swift                    0x0000000107609829 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 297
32 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
33 swift                    0x00000001075d4ee0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 256
34 swift                    0x00000001075b3659 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 233
35 swift                    0x00000001075cea93 swift::ASTVisitor<SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 355
36 swift                    0x00000001075cd7eb SILGenType::emitType() + 203
37 swift                    0x00000001075c85ae swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
38 swift                    0x00000001075b555b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 395
39 swift                    0x00000001075b581a swift::SILModule::constructSIL(swift::Module*, swift::SourceFile*, swift::Optional<unsigned int>) + 314
40 swift                    0x00000001075b5968 swift::performSILGeneration(swift::SourceFile&, swift::Optional<unsigned int>) + 72
41 swift                    0x000000010748be18 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 3432
42 swift                    0x000000010748996d main + 1677
43 libdyld.dylib            0x00007fff8aa4c5c9 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o
1.  While emitting SIL for 'signIn' at /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:14:15
2.  While silgen closureexpr SIL function @_TFFC7Re_Chat14ViewController6signInFS0_FPSs9AnyObject_T_U_FTGSQCSo6PFUser_GSQCSo7NSError__T_ for expression at [/Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:16:80 - line:45:9] RangeText="{
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                // Do stuff after successful login.

                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = ""
                    // other fields can be set just like with PFObject

                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }

             println("error")
            }
        }"
</code>```

答: I had exactly the same issue, and after many hours of debugging, I found out it was because I was accessing a subscript by using .subscript() instead of between []. XCode thinks this is perfectly valid, but gives this segmentation fault error when building.</p>

Body:
I'm getting the error ...

Command failed due to signal: Segmentation fault: 11

... when trying to compile my Swift app. I'm using Xcode 6.1, trying to build for an iPhone 5 on iOS 8.1.

My Code

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var username: UITextField!
    @IBAction func signIn(sender: AnyObject) {

        PFUser.logInWithUsernameInBackground(username.text, password:"mypass") {
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = " "
                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }

             println(error)
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        Parse.setApplicationId("key here")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

And the error text!

CompileSwift normal arm64 /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift
    cd /Users/Alec/Desktop/Re-Chat/Re-Chat
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o
0  swift                    0x0000000108145a68 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x0000000108145f54 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff86631f1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fd0ac1eb010 _sigtramp + 633049360
4  swift                    0x00000001075d4517 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::AnyFunctionRef) + 1303
5  swift                    0x00000001075c599e swift::Lowering::SILGenFunction::visitFuncDecl(swift::FuncDecl*) + 190
6  swift                    0x000000010760987c swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 380
7  swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
8  swift                    0x000000010760a0a5 swift::Lowering::SILGenFunction::visitIfStmt(swift::IfStmt*) + 757
9  swift                    0x000000010760c8f6 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 166
10 swift                    0x00000001076097e8 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 232
11 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
12 swift                    0x00000001075d52dd swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 205
13 swift                    0x00000001075b4234 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 196
14 swift                    0x00000001075eef71 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
15 swift                    0x00000001075e1866 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 2870
16 swift                    0x00000001075e24da swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 6058
17 swift                    0x00000001075cfa0b swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 235
18 swift                    0x00000001075ae824 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&) && + 196
19 swift                    0x0000000107604a69 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 233
20 swift                    0x00000001075f371c swift::Lowering::SILGenFunction::emitInjectOptionalValueInto(swift::SILLocation, swift::Lowering::RValueSource&&, swift::SILValue, swift::Lowering::TypeLowering const&) + 268
21 swift                    0x00000001075e9b8d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 36445
22 swift                    0x00000001075e3e2b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 12539
23 swift                    0x00000001075e202b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4859
24 swift                    0x00000001075cfab6 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
25 swift                    0x00000001075bffc4 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 836
26 swift                    0x00000001075bf582 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 98
27 swift                    0x00000001075b7ff8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1128
28 swift                    0x00000001075b751a swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 58
29 swift                    0x00000001075e0d81 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 81
30 swift                    0x00000001075ea00d swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 237
31 swift                    0x0000000107609829 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 297
32 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
33 swift                    0x00000001075d4ee0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 256
34 swift                    0x00000001075b3659 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 233
35 swift                    0x00000001075cea93 swift::ASTVisitor<SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 355
36 swift                    0x00000001075cd7eb SILGenType::emitType() + 203
37 swift                    0x00000001075c85ae swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
38 swift                    0x00000001075b555b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 395
39 swift                    0x00000001075b581a swift::SILModule::constructSIL(swift::Module*, swift::SourceFile*, swift::Optional<unsigned int>) + 314
40 swift                    0x00000001075b5968 swift::performSILGeneration(swift::SourceFile&, swift::Optional<unsigned int>) + 72
41 swift                    0x000000010748be18 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 3432
42 swift                    0x000000010748996d main + 1677
43 libdyld.dylib            0x00007fff8aa4c5c9 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o
1.  While emitting SIL for 'signIn' at /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:14:15
2.  While silgen closureexpr SIL function @_TFFC7Re_Chat14ViewController6signInFS0_FPSs9AnyObject_T_U_FTGSQCSo6PFUser_GSQCSo7NSError__T_ for expression at [/Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:16:80 - line:45:9] RangeText="{
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                // Do stuff after successful login.

                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = ""
                    // other fields can be set just like with PFObject

                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }

             println("error")
            }
        }"


问:
SQL Database Recursive Relationship
So I’m attempting to teach myself databases and SQL, and I’m trying to play around with making a database in management studio, and I have a question regarding recursive relationships in a table. Say I have a table called ‘Customers’ and in that table I have an int called Customer_ID as the primary key that is also an identity incrementing by 1, an nchar(125) called ‘Customer_Name’, and another int called Customer_Parent_ID (I don’t know whether I should make this an identity or not). How do I go about forming the relationships that there are customers, and I want to track that some of those customers may be parents of other customers (Think of companies, for example say both Microsoft and LinkedIn are customers, but Microsoft is also LinkedIn’s parent company and I want to show that relationship). I attached a picture of what I THINK it should look like… but again, total newbie here and any recommendations would be much appreciated.

Thank you so much!

EDIT: Added SQL Code and removed accidental mysql tag.

答: I think your question is somehow similar to this one, and the simple answer is you set a foreign key on Customer_Parent_ID column and refers to the Customer_ID column, so any id number that appears in the Customer_Parent_ID must also present in the Customer_ID column.</p>

Title: SQL Database Recursive Relationship


问:
ListView text is truncated -- how do I display the entire text of an item?
Here's a picture of a System.Windows.Forms.ListView using LargeIcons

The selected item shows all it's text

e.g. The top left item shows only 11 characters of its name, it's shown fully if that's selected. How can I make it show all the text(or atleast more than 11 characters), for items that's not selected ?

答:
There is DrawItem event http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.drawitem.aspx. Inside this event you have access to System.Drawing.Graphics.DrawString method.

```<code>void view_DrawItem(object sender, DrawListViewItemEventArgs e)
    {
        e.Graphics.DrawString(e.Item.Text, drawFont, Brushes.Black,
            new RectangleF(e.Item.Position.X,
                e.Item.Position.Y,
                20,
                160));

    }
</code>```

I entered some values for width/height, but you should use MeasureString or similar method.
Also do not forget to set OwnerDraw=true on ListView, otherwise it will not work.

ContentLicense: CC BY-SA 2.5

Body:
There is DrawItem event http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.drawitem.aspx. Inside this event you have access to System.Drawing.Graphics.DrawString method.

void view_DrawItem(object sender, DrawListViewItemEventArgs e)
    {
        e.Graphics.DrawString(e.Item.Text, drawFont, Brushes.Black,
            new RectangleF(e.Item.Position.X,
                e.Item.Position.Y,
                20,
                160));

    }

I entered some values for width/height, but you should use MeasureString or similar method.
Also do not forget to set OwnerDraw=true on ListView, otherwise it will not work.


问:
pick item from list at random, each has different chance
I wanted to write a simple function that allows to roll random item from list, i did it with this code:

```<code>this.resources = [false, 'nitrogen', 'silicon', 'cobalt', 'magnesium'];

this.assign_resource = function() {
    var index = tools.rnd(0, this.resources.length - 1);
    return this.resources[index];
};
</code>```

But it doesn't play well, so i wanted to change it to different system that allows a list of items (including empty one) and it picks one at random but each one has different chance (for example this one has 10%, this one has 20%). Maybe someone could help me with this kind of function.

Edited -----

for example this could be new list:

```<code>this.resources = [
    { type: 'empty', chance: 30 },
    { type: 'nitrogen', chance: 10 },
    { type: 'silicon', chance: 20 },
    { type: 'cobalt', chance: 30 },
    { type: 'magnesium', chance: 10 }
];
</code>```

How to use it now to make it happen properly?

Edited 2 -----

I am trying to figure out well done programming solution using math rather then simply duplicating items in array, answers presented in this topic are just work arounds to a problem.

答:
I'd solve it by having an array of objects with a chance to be the result, totalling 1.0, then picking a random number between 0 and 1, and then iterating over the resources and check if adding it to a cumulative total includes your random number.

var resources = [
  { resource: false, chance: 0.2 },
  { resource: 'nitrogen', chance: 0.1 },
  { resource: 'silicon', chance: 0.2 },
  { resource: 'cobalt', chance: 0.45 },
  { resource: 'mangesium', chance: 0.05 }
];

function get_result(resouceList) {
  //get our random from 0 to 1
  var rnd = Math.random();

  //initialise our cumulative percentage
  var cumulativeChance = 0;
  //iterate over our resources
  for (var i = 0; i < resouceList.length; i++) {

    //include current resource
    cumulativeChance += resouceList[i].chance;

    if (rnd < cumulativeChance)
      return resouceList[i].resource;
  }

  return false;
}

//test
console.log(get_result(resources));
console.log(get_result(resources));
console.log(get_result(resources));
console.log(get_result(resources));
console.log(get_result(resources));```

Body:
I wanted to write a simple function that allows to roll random item from list, i did it with this code:

this.resources = [false, 'nitrogen', 'silicon', 'cobalt', 'magnesium'];

this.assign_resource = function() {
    var index = tools.rnd(0, this.resources.length - 1);
    return this.resources[index];
};

But it doesn't play well, so i wanted to change it to different system that allows a list of items (including empty one) and it picks one at random but each one has different chance (for example this one has 10%, this one has 20%). Maybe someone could help me with this kind of function.

Edited -----

for example this could be new list:

this.resources = [
    { type: 'empty', chance: 30 },
    { type: 'nitrogen', chance: 10 },
    { type: 'silicon', chance: 20 },
    { type: 'cobalt', chance: 30 },
    { type: 'magnesium', chance: 10 }
];

How to use it now to make it happen properly?

Edited 2 -----

I am trying to figure out well done programming solution using math rather then simply duplicating items in array, answers presented in this topic are just work arounds to a problem.


问:
Batch script - Issue to use conditional statements
I have a batch script which needs to check for computer IP address range and a text file under user profile, if both are met then it has to go to end otherwise calls a batch file then continue to check for another IP range and text file and so on..

IP ranges and text file are as follow:

IP 10.0.50.xxx, 10.0.51.xxx:
search for %username%10.txt

IP 10.0.1.xxx, 10.0.5.xxx: search for
%username%11.txt

IP 10.0.60.xxx: search for %username%12.txt

IP
10.0.100.xxx: search for %username%13.txt

I tried multiple variation of if else and && || statements without luck. The scripts only checks for the text file but not the IP range.

I removed the else , if statements and only pasted the code I'm using. Can anyone please have a look and let me know the best method to implement else, if into this code? Thank you

```<code>  for %%a in (50,51) do if not exist "%USERPROFILE%\%username%10.txt" (  IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call sydprintmap.bat
)
  for %%a in (1,5) do if not exist "%USERPROFILE%\%username%11.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call melprintmap.bat
)
  for %%a in (60) do if not exist "%USERPROFILE%\%username%12.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call wynprintmap.bat
)
  for %%a in (100) do if not exist "%USERPROFILE%\%username%13.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call adlprintmap.bat
)
</code>```

PS:
What I need is:

1: if IP address is within range and the text file exists then go to end.

2- If IP address is within range but the text file doesn't exist then run the specific script.

3- if IP address is not within range then go to next line (without checking for relevant text file)

答:
I'm not sure if I fully understand the task, but you may try this:

@Echo Off
For /F "Tokens=2 Delims=:" %%A In ('IPConfig^|FindStr/IRC:"\<IPv4.*\ :\ 10\.0\.[156]\."'
) Do For /F "Tokens=3 Delims=." %%B In ("%%A") Do Set "byte3=%%A"

If "%byte3%" GEq "50" If "%byte3%" LEq "51" If Not Exist "%UserProfile%\%UserName%10.txt" sydprintmap.bat
If "%byte3%" Equ "1" If Not Exist "%UserProfile%\%UserName%11.txt" melprintmap.bat
If "%byte3%" Equ "5" If Not Exist "%UserProfile%\%UserName%11.txt" melprintmap.bat
If "%byte3%" Equ "60" If Not Exist "%UserProfile%\%UserName%12.txt" wynprintmap.bat
If "%byte3%" Equ "100" If Not Exist "%UserProfile%\%UserName%13.txt" adlprintmap.bat
```

Body:
I have a batch script which needs to check for computer IP address range and a text file under user profile, if both are met then it has to go to end otherwise calls a batch file then continue to check for another IP range and text file and so on..

IP ranges and text file are as follow:

IP 10.0.50.xxx, 10.0.51.xxx:
search for %username%10.txt

IP 10.0.1.xxx, 10.0.5.xxx: search for
%username%11.txt

IP 10.0.60.xxx: search for %username%12.txt

IP
10.0.100.xxx: search for %username%13.txt

I tried multiple variation of if else and && || statements without luck. The scripts only checks for the text file but not the IP range.

I removed the else , if statements and only pasted the code I'm using. Can anyone please have a look and let me know the best method to implement else, if into this code? Thank you

  for %%a in (50,51) do if not exist "%USERPROFILE%\%username%10.txt" (  IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call sydprintmap.bat
)
  for %%a in (1,5) do if not exist "%USERPROFILE%\%username%11.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call melprintmap.bat
)
  for %%a in (60) do if not exist "%USERPROFILE%\%username%12.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call wynprintmap.bat
)
  for %%a in (100) do if not exist "%USERPROFILE%\%username%13.txt" (   IPConfig|FindStr/IRC:"IPv4 .*: 10.0.%%a.">Nul 2>&1 && call adlprintmap.bat
)

PS:
What I need is:

1: if IP address is within range and the text file exists then go to end.

2- If IP address is within range but the text file doesn't exist then run the specific script.

3- if IP address is not within range then go to next line (without checking for relevant text file)


问:
Two DataTable in One Page - Second one initialising weird
I have two dataTable in my page and I have a method like below:

```<code>function ToDataTable()
{
    $(".dataTable").css("width", "100%");

    $(".dataTable").each(function ()
    {
        var $that = $(this);

        /* Start of method */
        function ToDataTableInternal()
        {
           var table = $that.DataTable({
               responsive: {
                   details: { type: "column", target: -1 },
               },
               columnDefs: [{
                       className: "control", orderable: !1, targets: -1,
                   },
                   { orderable: !1 }],
               "paging": false,
               "ordering": false,
               "info": false,
               "searching": false,
                retrieve: true
           });
        }
        /* End of method */

        if ($that.is(":visible"))
        {
            ToDataTableInternal()
        }
        else
        {
            // Observe all invisible parents or table to trigger
            // ToDataTableInternal method if made visible
            var $arr = $(this).parentsUntil(":visible").filter(function ()
            {
                return $(this).css("display") === "none";
            }).add($(this));

            var observers = [];

            $arr.each(function ()
            {
                var observer = new MutationObserver(function (mutations)
                {
                    mutations.forEach(function (mutation)
                    {
                        if ((mutation.attributeName === 'style' ||
                               mutation.attributeName === 'class') &&
                                 $that.is(":visible"))
                        {
                            ToDataTableInternal();

                            for (var i = 0; i < observers.length; i++)
                            {
                                // Disconnect observers
                                observers[i].disconnect();
                            }
                        }
                    });
                });

                observers.push(observer);
                observer.observe(this, {
                    attributes: true
                });
            });
        }
    });
}
</code>```

The reason I have this method is that when table's display is none, it really lags browser(especially IE, where I cannot do anything for minimum of 5 seconds) which is the reason of that I'm changing the table to DataTable after it made visible.

But the problem with calling methods individually is the second DataTable doesn't have the same settings which I passed on.(The first one has) Instead, second one has filters, paging, sort elements in it too.

If I call both at the same time, nothing out of ordinary happens. What may be the problem?

EDIT: I can't reproduce the same behaviour in fiddles.

答:
There seems to be no problems in another environments when I'm trying to do the same thing.

An another library we use is causing problems and there is no problem with DataTable library.

Body:
I have two dataTable in my page and I have a method like below:

function ToDataTable()
{
    $(".dataTable").css("width", "100%");

    $(".dataTable").each(function ()
    {
        var $that = $(this);

        /* Start of method */
        function ToDataTableInternal()
        {
           var table = $that.DataTable({
               responsive: {
                   details: { type: "column", target: -1 },
               },
               columnDefs: [{
                       className: "control", orderable: !1, targets: -1,
                   },
                   { orderable: !1 }],
               "paging": false,
               "ordering": false,
               "info": false,
               "searching": false,
                retrieve: true
           });
        }
        /* End of method */

        if ($that.is(":visible"))
        {
            ToDataTableInternal()
        }
        else
        {
            // Observe all invisible parents or table to trigger
            // ToDataTableInternal method if made visible
            var $arr = $(this).parentsUntil(":visible").filter(function ()
            {
                return $(this).css("display") === "none";
            }).add($(this));

            var observers = [];

            $arr.each(function ()
            {
                var observer = new MutationObserver(function (mutations)
                {
                    mutations.forEach(function (mutation)
                    {
                        if ((mutation.attributeName === 'style' ||
                               mutation.attributeName === 'class') &&
                                 $that.is(":visible"))
                        {
                            ToDataTableInternal();

                            for (var i = 0; i < observers.length; i++)
                            {
                                // Disconnect observers
                                observers[i].disconnect();
                            }
                        }
                    });
                });

                observers.push(observer);
                observer.observe(this, {
                    attributes: true
                });
            });
        }
    });
}

The reason I have this method is that when table's display is none, it really lags browser(especially IE, where I cannot do anything for minimum of 5 seconds) which is the reason of that I'm changing the table to DataTable after it made visible.

But the problem with calling methods individually is the second DataTable doesn't have the same settings which I passed on.(The first one has) Instead, second one has filters, paging, sort elements in it too.

If I call both at the same time, nothing out of ordinary happens. What may be the problem?

EDIT: I can't reproduce the same behaviour in fiddles.


问:
Can Azure Blob storage container name be made case insensitive?
We have a picture server with lots of files serving the files over http. They are currently accessed through urls with the format

http://pictures.example.com/Pictures/xx/yyyyyy/zzzzzzzzzzzzzzzzzzzzzzzzzzzzz.jpg

We have a plan to move them to Azure blob storage and since the urls to the current pictures are used in several external systems we would like to keep the urls identical.

In Azure Blob storage the first part of the blob url is the name of the container. Our existing urls are named Pictures/xxx. Container names can, however, only have lowercase letters.

Do I have to create an Azure App Service just for url redirection or is there some way around this?

答:
Blob containers must be lower-case. Blob names can be mixed case.

There is no workaround to this, as it's part of the service.

You mentioned creating an app service for url redirection. Note that, if you choose to access your blobs directly, vs through your app service, you will not be able to perform any redirection.

More info on naming rules here.


问:
How to make my UserForm code change the output cell of the code every time I run said UserForm in Excel
I have researched the web but can't find the solution that helps me.

I have a Excel Sheet and have created a UserForm that has a InkPicture Box and is set to allow a person to open the user form and draw their signature. There is a CommandButton assigned to take the signature and save it from the clipboard onto the PC. I Have another CommandButton assigned to retrieve said saved picture from the PC path and bring it back to a specific sheet in my workbook and insert it at a specific cell.

My need is the following:
I need the Code I'm using to update what cell it will insert the image at every time I click on the button. (In other words. I need the code to go from C3 to C50 on one digit increase every time I push the button and after it reaches revert back to C3)

Can this be done?

This code brings the image back to my sheet but every time the CommandButton is clicked the image gets inserted in C3(therefore all images are on top of each other as opposed to below each other):

```<code>Private Sub CommandButton4_Click()

Dim ws As Worksheet
Dim ImgPath As String
Dim W As Double, H As Double
Dim L As Long, T As Long

Set ws = ThisWorkbook.Sheets("Mobile POS Log Sheet")

'~~> This is my current pic file path
ImgPath = "C:\Users\raphaelo\Downloads\test.gif"

With ws
    W = 30                  '<~~ Width
    H = 11                  '<~~ Height
    L = .Range("c3").Left   '<~~ This is what should be changing each time I run the command
    T = .Range("c3").Top    '<~~ This is what should be changing each time I run the command
     '<~~ Both the L and T Range entries should change to the next cell (C3 to C4 to C5 and so on) One digit up every time I run the Command Code
     '<~~ Unless it's the Placement entry below?
    With .Pictures.Insert(ImgPath)
        With .ShapeRange
            .LockAspectRatio = msoTrue
            .Width = W
            .Height = H
        End With
        .Left = L
        .Top = T
        .Placement = 1 '<~~ Not sure if this is the one that should change one digit up each time I run the Command instead?
    End With
End With
</code>```

Please guide me in the right direction! What would be the code that automatically re-calculates itself to assign the Output to a different cell in a column every time it's ran?

答:
I must have misunderstood your question.  Instead of the "last used row" you need to find the last row in column "C" that has a shape in it.  This changed code will find the last row with a shape in column C, then it will add 2 rows to that number, and then place the image two rows beneath the lowest one.  You can change those rows to however many you need.  You might get an error if there are no shapes on the sheet when this is run.  If so then you will have to create an error capture for that.</p>

```<code>Private Sub CommandButton4_Click()

Dim ws As Worksheet
Dim ImgPath As String
Dim W As Double, H As Double
Dim L As Long, T As Long
Dim myArr() As Variant, myArrCounter As Long
Dim newRowNumb As Long

Set ws = ThisWorkbook.Sheets("Mobile POS Log Sheet")

'////////////////////////////////////////   This section will find the row of the bottom most shape in Column C
ReDim myArr(1 To 1)
myArrCounter = 0

For Each wshape In ws.Shapes
    myArrCounter = myArrCounter + 1
    If myArrCounter = 1 And wshape.TopLeftCell.Column = 3 Then
        myArr(myArrCounter) = wshape.TopLeftCell.row
    Else:
        If wshape.TopLeftCell.Column = 3 And wshape.TopLeftCell.row > myArr(UBound(myArr)) Then
            ReDim Preserve myArr(1 To myArrCounter)
            myArr(myArrCounter) = wshape.TopLeftCell.row
        End If
    End If
Next wshape
newRowNumb = myArr(UBound(myArr)) + 2 ' this adds two rows to place the new picure.  Change the "2" to how many rows you need

'~~> This is my current pic file path
ImgPath = "C:\Users\raphaelo\Downloads\test.gif"

    With ws
        W = 30                  '<~~ Width
        H = 11                  '<~~ Height
        L = .Range("c" & newRowNumb).Left   '<~~ This is what should be changing each time I run the command
        T = .Range("c" & newRowNumb).Top    '<~~ This is what should be changing each time I run the command
         '<~~ Both the L and T Range entries should change to the next cell (C3 to C4 to C5 and so on) One digit up every time I run the Command Code
         '<~~ Unless it's the Placement entry below?
        With .Pictures.Insert(ImgPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = W
                .Height = H
            End With
            .Left = L
            .Top = T
            .Placement = 1 '<~~ Not sure if this is the one that should change one digit up each time I run the Command instead?
        End With
    End With

End Sub
</code>```

Body:
I have researched the web but can't find the solution that helps me.

I have a Excel Sheet and have created a UserForm that has a InkPicture Box and is set to allow a person to open the user form and draw their signature. There is a CommandButton assigned to take the signature and save it from the clipboard onto the PC. I Have another CommandButton assigned to retrieve said saved picture from the PC path and bring it back to a specific sheet in my workbook and insert it at a specific cell.

My need is the following:
I need the Code I'm using to update what cell it will insert the image at every time I click on the button. (In other words. I need the code to go from C3 to C50 on one digit increase every time I push the button and after it reaches revert back to C3)

Can this be done?

This code brings the image back to my sheet but every time the CommandButton is clicked the image gets inserted in C3(therefore all images are on top of each other as opposed to below each other):

Private Sub CommandButton4_Click()

Dim ws As Worksheet
Dim ImgPath As String
Dim W As Double, H As Double
Dim L As Long, T As Long

Set ws = ThisWorkbook.Sheets("Mobile POS Log Sheet")

'~~> This is my current pic file path
ImgPath = "C:\Users\raphaelo\Downloads\test.gif"

With ws
    W = 30                  '<~~ Width
    H = 11                  '<~~ Height
    L = .Range("c3").Left   '<~~ This is what should be changing each time I run the command
    T = .Range("c3").Top    '<~~ This is what should be changing each time I run the command
     '<~~ Both the L and T Range entries should change to the next cell (C3 to C4 to C5 and so on) One digit up every time I run the Command Code
     '<~~ Unless it's the Placement entry below?
    With .Pictures.Insert(ImgPath)
        With .ShapeRange
            .LockAspectRatio = msoTrue
            .Width = W
            .Height = H
        End With
        .Left = L
        .Top = T
        .Placement = 1 '<~~ Not sure if this is the one that should change one digit up each time I run the Command instead?
    End With
End With

Please guide me in the right direction! What would be the code that automatically re-calculates itself to assign the Output to a different cell in a column every time it's ran?

Body:
I must have misunderstood your question.  Instead of the "last used row" you need to find the last row in column "C" that has a shape in it.  This changed code will find the last row with a shape in column C, then it will add 2 rows to that number, and then place the image two rows beneath the lowest one.  You can change those rows to however many you need.  You might get an error if there are no shapes on the sheet when this is run.  If so then you will have to create an error capture for that.

Private Sub CommandButton4_Click()

Dim ws As Worksheet
Dim ImgPath As String
Dim W As Double, H As Double
Dim L As Long, T As Long
Dim myArr() As Variant, myArrCounter As Long
Dim newRowNumb As Long

Set ws = ThisWorkbook.Sheets("Mobile POS Log Sheet")

'////////////////////////////////////////   This section will find the row of the bottom most shape in Column C
ReDim myArr(1 To 1)
myArrCounter = 0

For Each wshape In ws.Shapes
    myArrCounter = myArrCounter + 1
    If myArrCounter = 1 And wshape.TopLeftCell.Column = 3 Then
        myArr(myArrCounter) = wshape.TopLeftCell.row
    Else:
        If wshape.TopLeftCell.Column = 3 And wshape.TopLeftCell.row > myArr(UBound(myArr)) Then
            ReDim Preserve myArr(1 To myArrCounter)
            myArr(myArrCounter) = wshape.TopLeftCell.row
        End If
    End If
Next wshape
newRowNumb = myArr(UBound(myArr)) + 2 ' this adds two rows to place the new picure.  Change the "2" to how many rows you need

'~~> This is my current pic file path
ImgPath = "C:\Users\raphaelo\Downloads\test.gif"

    With ws
        W = 30                  '<~~ Width
        H = 11                  '<~~ Height
        L = .Range("c" & newRowNumb).Left   '<~~ This is what should be changing each time I run the command
        T = .Range("c" & newRowNumb).Top    '<~~ This is what should be changing each time I run the command
         '<~~ Both the L and T Range entries should change to the next cell (C3 to C4 to C5 and so on) One digit up every time I run the Command Code
         '<~~ Unless it's the Placement entry below?
        With .Pictures.Insert(ImgPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = W
                .Height = H
            End With
            .Left = L
            .Top = T
            .Placement = 1 '<~~ Not sure if this is the one that should change one digit up each time I run the Command instead?
        End With
    End With

End Sub


问:
Catching Content-Security-Policy exceptions with Javascript
We have implemented CSP in our huuuge one-page web app. We keep getting errors time to time and some errors were result of improperly handled user-form inputs and some seem to originate from within user's browser.

Is there a way to harvest more data on client side when CSP exception happens? The server-side report misses vital data. We know source source URL, blocked URL, violated rule/directive... but that is not helpful as we don't know what was on the screen at the moment and if it is user's browser to blame.

We need to know

what javscript module was being viewed at the time/what JS layer/detail

where was the original source/trigger to request that resource - was it our fault of displaying uncleaned form-embedded HTML injected by some robot or was it user's infected browser inserting these malware links?

Is there some hook like window.onCSPException=func that we can hook on and run client-side analysis? We need to distinguish fast our problems from client browser's problems.

答:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#Enabling_reporting:

By default, violation reports aren't sent. To enable violation reporting, you need to specify the report-uri policy directive, providing at least one URI to which to deliver the reports:

Content-Security-Policy: default-src 'self'; report-uri http://reportcollector.example.com/collector.cgi

Then you need to set up your server to receive the reports; it can store or process them in whatever manner you feel is appropriate.


问:
alternative to copy_to in sparklyr for large data sets
I have the code below that takes a dataset does a SQL transformation on it using a wrapper function calling the spark SQL API using Sparklyr. I then use "invoke("createOrReplaceTempView", "name")" to save the table in the Spark environment as a spark data frame so that I can call is in a future function call. Then I use dplyr code "mutate" to call a hive function "regexp_replace" to transform letters to numeric (0). I them need to call an SQL function again.

However to do so I seem to have to use the "copy_to" function from sparklyr. On a large data set the "copy_to" function causes the following error:

```<code>Error: org.apache.spark.SparkException: Job aborted due to stage
failure: Total size of serialized results of 6 tasks (1024.6 MB) is
bigger than spark.driver.maxResultSize (1024.0 MB)
</code>```

Is there an alternative to "copy_to" that allows me to get a spark data frame that I can then call with SQL API?

Here is my codeL

```<code> sqlfunction <- function(sc, block) {
  spark_session(sc) %>% invoke("sql", block)
 }

sqlfunction(sc, "SELECT * FROM
test")%>%invoke("createOrReplaceTempView",
"name4")

names<-tbl(sc, "name4")%>%
  mutate(col3 = regexp_replace(col2, "^[A-Z]", "0"))

copy_to(sc, names, overwrite = TRUE)

sqlfunction(sc, "SELECT * FROM
test")%>%invoke("createOrReplaceTempView",
"name5")

final<-tbl(sc, "name5")
</code>```

答:
It'd help if you had a reprex, but try</p>

```<code>final <- names %>%
  spark_dataframe() %>%
  sqlfunction(sc, "SELECT * FROM test") %>%
  sdf_register("name5")
</code>```

Body:
I have the code below that takes a dataset does a SQL transformation on it using a wrapper function calling the spark SQL API using Sparklyr. I then use "invoke("createOrReplaceTempView", "name")" to save the table in the Spark environment as a spark data frame so that I can call is in a future function call. Then I use dplyr code "mutate" to call a hive function "regexp_replace" to transform letters to numeric (0). I them need to call an SQL function again.

However to do so I seem to have to use the "copy_to" function from sparklyr. On a large data set the "copy_to" function causes the following error:

Error: org.apache.spark.SparkException: Job aborted due to stage
failure: Total size of serialized results of 6 tasks (1024.6 MB) is
bigger than spark.driver.maxResultSize (1024.0 MB)

Is there an alternative to "copy_to" that allows me to get a spark data frame that I can then call with SQL API?

Here is my codeL

 sqlfunction <- function(sc, block) {
  spark_session(sc) %>% invoke("sql", block)
 }

sqlfunction(sc, "SELECT * FROM
test")%>%invoke("createOrReplaceTempView",
"name4")

names<-tbl(sc, "name4")%>%
  mutate(col3 = regexp_replace(col2, "^[A-Z]", "0"))

copy_to(sc, names, overwrite = TRUE)

sqlfunction(sc, "SELECT * FROM
test")%>%invoke("createOrReplaceTempView",
"name5")

final<-tbl(sc, "name5")

Body:
It'd help if you had a reprex, but try

final <- names %>%
  spark_dataframe() %>%
  sqlfunction(sc, "SELECT * FROM test") %>%
  sdf_register("name5")


问:
Different installed app size on different devices
My app apk file size is about 25 MB. When I install it (debug or release version) on my Sony Xperia (Android 4.0.4), application size is about 30 MB. But some users complain, that installed app size is about 80 MB, for example on Galaxy Ace 2 device (Android 4.x). It is application size right after installation.

How can installed application size differ more than 2 times on different devices?

I use Android SDK Tools Rev. 22.3; SDK Build-tools 18.0.1.

答:
Depending on your development environment, and the settings you choose, you probably are using what's called "Multiple APK Support".

Pretty much you can optimize your app for different devices. Some people do this manually by testing on a bunch of different emulators, but there are also settings you can toggle to automatically do some optimizations for you. Even if you didn't do it intentionally, you're likely using some kind of Multiple APK application settings.

You can read more about Multiple APK Support here: https://developer.android.com/google/play/publishing/multiple-apks.html


问:
Definition of Type in .NET
This question gives me curiosity... When you want to define a type you must say GetType(Type) ex.: GetType(string), but ain't String a type itself?

Why do you need to use GetType in those situations? And, if the reason is because it is expecting a Type 'Type'... why isn't the conversion implicit... I mean, all the data is there...

答:
GetType(string) will return the same information.  Look at it like you would a constant.  The only other way to get the Type object that represents a string would be to instantiate the string object and call o.GetType().  Also, this is not possible for interfaces and abstract types.

If you want to know the runtime type of a variable, call the .GetType() method off of it, as the runtime type may not be the same as the declared type of the variable.

Title: Definition of Type in .NET


问:
Replace gives different outcomes based on length of string
I use the following code to convert values entered in US format (0.8) to a propper format (0,8).

For row = 2 To rowg
    For col = 7 To 8
        If InStr(wsg.Cells(row, col), ".") > 0 Then
            wsg.Cells(row, col).Value = Replace(wsg.Cells(row, col), ".", ",")
        End If
    Next col
Next row

This usually works well, except for the case that there are 4 decimal places. In the case of 19.1991 it gets converted to 191991, instead of 19,1991. Whilst this is done the format of the cell also changes automatically to the numberformat, instead of the text format I set in my code. For values with 1 or 2 decimal places this doesn't happen.

答:
You can use CDbl to coerce the string returned by Replace to a Double using regional settings rather than US defaults for VBA:

```<code>wsg.Cells(row, col).Value = CDbl(Replace(wsg.Cells(row, col), ".", ","))
</code>```

Body:
You can use CDbl to coerce the string returned by Replace to a Double using regional settings rather than US defaults for VBA:

wsg.Cells(row, col).Value = CDbl(Replace(wsg.Cells(row, col), ".", ","))


问:
How to append text to end of current line using Vim function?
I'd like to append text to the end of a current line in Vim. I'd like to do this within the context of a function.

How can this be done? Do I need to escape/sanitise the text?

答:
You could use the normal command with the execute command:

```<code>let text_for_appending = ' # a comment'
execute "normal! A" . text_for_appending
</code>```

The exclamation mark is included to prevent any key mappings from being expanded. See :help :normal for more details.

Body:
You could use the normal command with the execute command:

let text_for_appending = ' # a comment'
execute "normal! A" . text_for_appending

The exclamation mark is included to prevent any key mappings from being expanded. See :help :normal for more details.


问:
How to pass a variable from a child component template to a parent component in angular2?
I have created 4 components. They are
1.Icon component
2.Toolbar Component
3.Design Component and
4.Tree Component

In Icon component I have imported around 10 icons from css and assigned a value for it.

In toolbar component I have rendered those 10 icons by using Icon component.

In Design and Tree template I used toolbar component but it will display all 10 icons in both design and tree page. I want to show only a set of icons in design and another set in tree. Is there any way we can restrict what icons should display in Design and Tree in toolbar component.

```<code>Toolbar.component.ts:
import {Component, Input, Output, EventEmitter} from "@angular/core";

@Component({
selector: 'toolbar',
templateUrl: './toolsbar.template.html'
})

export class ToolBar {

@Output() iconClicked: EventEmitter<string> = new EventEmitter<string>();
@Input() page: string;

onClicked(icontype: string): void {
    this.iconClicked.emit(icontype)
}
}
</code>```

Design Template.html

                        <toolbar (iconClicked)="onToolIconClicked($event)" >     </toolbar>

Toolabar.template.Html

```<code><div style="float: right">
<tool-icon [id]="'btn-refresh'" [type]="'refresh'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-add'" [type]="'add'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-edit'" [type]="'edit'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-delete'" [type]="'delete'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-import'" [type]="'import'" (iconClicked)="onClicked($event)">
<tool-icon>

<tool-icon [id]="'btn-collapse'" [type]="'collapse'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-expandall'" [type]="'expandall'" (iconClicked)="onClicked($event)">
<-tool-icon>
<tool-icon [id]="'btn-expanddiff'" [type]="'expanddiff'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-selectall'" [type]="'selectall'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-selectnone'" [type]="'selectnone'" (iconClicked)="onClicked($event)">
<tool-icon>
 tool-icon [id]="'btn-selectdiff'" [type]="'selectdiff'" (iconClicked)="onClicked($event)">
<tool-icon>
</code>```

But I want to render any 2 icons only in the design page. Kindly provide some suggestions

答:
In angular 2 for pass a variable from a child component to parent component is used through event with a output property and EventEmitter that implement the pattern observable.

Example in child component you declare a output property

```<code>@Output() onProductSelected: EventEmitter<any>;
</code>```

and in parent component in template

```<code><child-product (onProductSelected)=setProduct($event)></child-product>
</code>```

where $event is the value that you want to pass to parent component

Body:
I have created 4 components. They are
1.Icon component
2.Toolbar Component
3.Design Component and
4.Tree Component

In Icon component I have imported around 10 icons from css and assigned a value for it.

In toolbar component I have rendered those 10 icons by using Icon component.

In Design and Tree template I used toolbar component but it will display all 10 icons in both design and tree page. I want to show only a set of icons in design and another set in tree. Is there any way we can restrict what icons should display in Design and Tree in toolbar component.

Toolbar.component.ts:
import {Component, Input, Output, EventEmitter} from "@angular/core";

@Component({
selector: 'toolbar',
templateUrl: './toolsbar.template.html'
})

export class ToolBar {

@Output() iconClicked: EventEmitter<string> = new EventEmitter<string>();
@Input() page: string;

onClicked(icontype: string): void {
    this.iconClicked.emit(icontype)
}
}

Design Template.html

                        <toolbar (iconClicked)="onToolIconClicked($event)" >     </toolbar>

Toolabar.template.Html

<tool-icon [id]="'btn-refresh'" [type]="'refresh'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-add'" [type]="'add'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-edit'" [type]="'edit'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-delete'" [type]="'delete'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-import'" [type]="'import'" (iconClicked)="onClicked($event)">
<tool-icon>

<tool-icon [id]="'btn-collapse'" [type]="'collapse'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-expandall'" [type]="'expandall'" (iconClicked)="onClicked($event)">
<-tool-icon>
<tool-icon [id]="'btn-expanddiff'" [type]="'expanddiff'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-selectall'" [type]="'selectall'" (iconClicked)="onClicked($event)">
<tool-icon>
<tool-icon [id]="'btn-selectnone'" [type]="'selectnone'" (iconClicked)="onClicked($event)">
<tool-icon>
 tool-icon [id]="'btn-selectdiff'" [type]="'selectdiff'" (iconClicked)="onClicked($event)">
<tool-icon>

But I want to render any 2 icons only in the design page. Kindly provide some suggestions

Body:
In angular 2 for pass a variable from a child component to parent component is used through event with a output property and EventEmitter that implement the pattern observable.

Example in child component you declare a output property

@Output() onProductSelected: EventEmitter<any>;

and in parent component in template

<child-product (onProductSelected)=setProduct($event)></child-product>

where $event is the value that you want to pass to parent component


问:
Access another twig template within another
I'm working with Bolt CMS and the following and it prints out the file name.

```<code>{% for image in record.gallery %}
  {{ image.filename }}
{% endfor %}
</code>```

But what I want to do is to render these inside an img tag, and doing so causes a 404 because the images are stored within the files directory.

I've attempted to do the following which according to the Bolt CMS is how you access uploaded files in the files directory:

```<code>{% for image in record.gallery %}
  {{ asset('image.filename', 'files') }}
{% endfor %}
</code>```

But it doesn't seem to work. How do I access image.filename within the asset tag?

答:
I have solved this myself! Just needed to remove the quotes.</p>

```<code>{% for image in record.gallery %}
  {{ asset(image.filename, 'files') }}
{% endfor %}
</code>```

Body:
I'm working with Bolt CMS and the following and it prints out the file name.

{% for image in record.gallery %}
  {{ image.filename }}
{% endfor %}

But what I want to do is to render these inside an img tag, and doing so causes a 404 because the images are stored within the files directory.

I've attempted to do the following which according to the Bolt CMS is how you access uploaded files in the files directory:

{% for image in record.gallery %}
  {{ asset('image.filename', 'files') }}
{% endfor %}

But it doesn't seem to work. How do I access image.filename within the asset tag?

Body:
I have solved this myself! Just needed to remove the quotes.

{% for image in record.gallery %}
  {{ asset(image.filename, 'files') }}
{% endfor %}


问:
How to perform bulk insert into SQLServer from one machine to another?
i have running nifi instance in one machine and have SQL Server in another machine.

Here i can try to perform bulk insert operation with bulk insert Query in SQLserver. but i cannot able insert data from  one machine and move it into SQL Server in another machine.

If i run nifi and SQL Server in same machine then i can able to perform bulk insert operation easily.

i have configured GetFile->ReplaceText(BulkInsertQuery)-->PutSQL processors.

I have tried both nifi and sql server in single machine then bulk insert works but not works when both instances in different machines.

I need to get all data's from one machine and write a query to move that data into SQL runs in another machine.

Below query works when nifi and sql server in same machine

```<code>BULK INSERT BI FROM 'C:\Directory\input.csv' WITH (FIRSTROW = 1, ROWTERMINATOR = '\n', FIELDTERMINATOR = ',', ROWS_PER_BATCH = 10000)
</code>```

if i run that query in another machine then it says..,"FileNotFoundError" due to "input.csv" in Host1 machine but runs query in sql server machine (host2)

Can anyone give me suggestion to do this?

答:
Since I cannot comment, and this may be stupid to ask, but when you run on two separate machines, could you not have a batch job preform move to a common network location? Or FTP the needed data to a location on your SQL machine?
Since I do not know what Nifi is, I'm not sure, but making sure nifi moves the data to a common location accessible by both your SQL and NIFI machines is the first thing I would do. Then just run your bulk insert while point to this location.</p>

```<code>BULK INSERT BI FROM 'Some network directory' WITH 'you with clauses'
</code>```

Body:
i have running nifi instance in one machine and have SQL Server in another machine.

Here i can try to perform bulk insert operation with bulk insert Query in SQLserver. but i cannot able insert data from  one machine and move it into SQL Server in another machine.

If i run nifi and SQL Server in same machine then i can able to perform bulk insert operation easily.

i have configured GetFile->ReplaceText(BulkInsertQuery)-->PutSQL processors.

I have tried both nifi and sql server in single machine then bulk insert works but not works when both instances in different machines.

I need to get all data's from one machine and write a query to move that data into SQL runs in another machine.

Below query works when nifi and sql server in same machine

BULK INSERT BI FROM 'C:\Directory\input.csv' WITH (FIRSTROW = 1, ROWTERMINATOR = '\n', FIELDTERMINATOR = ',', ROWS_PER_BATCH = 10000)

if i run that query in another machine then it says..,"FileNotFoundError" due to "input.csv" in Host1 machine but runs query in sql server machine (host2)

Can anyone give me suggestion to do this?

Body:
Since I cannot comment, and this may be stupid to ask, but when you run on two separate machines, could you not have a batch job preform move to a common network location? Or FTP the needed data to a location on your SQL machine?
Since I do not know what Nifi is, I'm not sure, but making sure nifi moves the data to a common location accessible by both your SQL and NIFI machines is the first thing I would do. Then just run your bulk insert while point to this location.

BULK INSERT BI FROM 'Some network directory' WITH 'you with clauses'


问:
Loop through a string and wrap each word in a div - PHP
Im getting a websites "keywords" for my web ranker. Its returning the result I need, but I want to wrap each keyword its returning into a span tag.

This is how im  getting the keywords:

```<code>$websiteTags = get_meta_tags('http://www.'.$website.'/');

dd($websiteTags);
</code>```

Which gives me this:

Them I just call the $websiteTags['keywords']; to get this result:

I need to wrap each word in that string in a span tag so it will look nicer in the frontend, because right now its just putting out that long string.

My question is, how would I  loop through that string and wrap each keyword in a span tag.

I have tried doing foreach loops, str_replace() and looked online, but could not find the solution I need.

答:
@Bas answer worked the best for me. I copied what he had:

```<code> $keyword = explode(",",$websiteTags['keywords']);
</code>```

Then in the frontend, I just did this:

```<code>@foreach($keyword as $key => $w)
        <span class="label label-success">{{ $w }}</span>
@endforeach
</code>```

Also, Alexey Mezenin answer works too.

In backend:

```<code>$keyword = '<span class="label label-success">'.str_replace(', ', '</span><span class="label label-success">', $websiteTags['keywords']).'</span>';
</code>```

Frontend:{!! $keyword !!}

Body:
Im getting a websites "keywords" for my web ranker. Its returning the result I need, but I want to wrap each keyword its returning into a span tag.

This is how im  getting the keywords:

$websiteTags = get_meta_tags('http://www.'.$website.'/');

dd($websiteTags);

Which gives me this:

Them I just call the $websiteTags['keywords']; to get this result:

I need to wrap each word in that string in a span tag so it will look nicer in the frontend, because right now its just putting out that long string.

My question is, how would I  loop through that string and wrap each keyword in a span tag.

I have tried doing foreach loops, str_replace() and looked online, but could not find the solution I need.

Body:
@Bas answer worked the best for me. I copied what he had:

 $keyword = explode(",",$websiteTags['keywords']);

Then in the frontend, I just did this:

@foreach($keyword as $key => $w)
        <span class="label label-success">{{ $w }}</span>
@endforeach

Also, Alexey Mezenin answer works too.

In backend:

$keyword = '<span class="label label-success">'.str_replace(', ', '</span><span class="label label-success">', $websiteTags['keywords']).'</span>';

Frontend:{!! $keyword !!}


问:
Lombok Builder with defaults in Spring Data
I have the following (simplified) class:

```<code>@Entity
@Data
@Builder
@NoArgsConstructor // @Builder creates the all-args version but I need this one elsewhere.
@AllArgsConstructor(access = AccessLevel.PRIVATE) // Having @NoArgsConstructor disables the @AllArgsConstructor needed by @Builder unless I have this explicitly applied
public class MyClass {

  // ...
  @Builder.Default
  private String foo = "Some Default Value"
  // ...

}
</code>```

This works fine in the general case, but a problem comes about when this Entity gets built by Spring (specifically Spring Data Repository in response to a REST request to create it).  Spring sees the all-args constructor and uses it, setting a null value for foo (in this case it wasn't set in the POST data) and I end up with a null value for foo instead of the expected "Some Default Value".  The @Builder.Default.

It does not work to simply create the setter and prevent nulls.  I could write out the AllArgsConstructor explicitly, but that (somewhat) defeats the purpose of Lombok to some extent.  Not a horrible solution, but not ideal.

Can anyone think of any workarounds for this?

答: I was able to work around this using a PrePersist annotation in my model class.  With the PrePersist I can make sure that null values get their defaults set regardless of when they were set to null, or by whom.  Not truly a fix for this, but something I should probably be doing anyway so it's an acceptable workaround.</p>

Body:
I have the following (simplified) class:

@Entity
@Data
@Builder
@NoArgsConstructor // @Builder creates the all-args version but I need this one elsewhere.
@AllArgsConstructor(access = AccessLevel.PRIVATE) // Having @NoArgsConstructor disables the @AllArgsConstructor needed by @Builder unless I have this explicitly applied
public class MyClass {

  // ...
  @Builder.Default
  private String foo = "Some Default Value"
  // ...

}

This works fine in the general case, but a problem comes about when this Entity gets built by Spring (specifically Spring Data Repository in response to a REST request to create it).  Spring sees the all-args constructor and uses it, setting a null value for foo (in this case it wasn't set in the POST data) and I end up with a null value for foo instead of the expected "Some Default Value".  The @Builder.Default.

It does not work to simply create the setter and prevent nulls.  I could write out the AllArgsConstructor explicitly, but that (somewhat) defeats the purpose of Lombok to some extent.  Not a horrible solution, but not ideal.

Can anyone think of any workarounds for this?


问:
TableView Section Footers doesn't resize its width after rotation
I have a table view with header and footer in every section.
When the device rotates, the headers resizes to fit the table's width, but the footers remains with portrait width.

I tried setting a large width in the xib file, and it works for the header, but no effect on footer.

I also tried doing a reload data in

```<code>viewWillTransitionToSize
</code>```

and it works, but I feel like is not the best way to do it, it also has a weird animation while rotating.

答:
I solved it, with estimatedRowHeight.
I don't know why but after that, the footer resized properly.</p>

Body:
I have a table view with header and footer in every section.
When the device rotates, the headers resizes to fit the table's width, but the footers remains with portrait width.

I tried setting a large width in the xib file, and it works for the header, but no effect on footer.

I also tried doing a reload data in

viewWillTransitionToSize

and it works, but I feel like is not the best way to do it, it also has a weird animation while rotating.


问:
Importing Function From Unmanaged DLL in C# Application
I need to import a function that I wrote in C++, and is now compiled into a DLL, into my C# application.  Everything builds without errors or warnings, but when I step through the code the first function call into the DLL throws an Exception with a message of "Unable to find an entry point named 'CreateScanEngine" in DLL 'WMIQuery.dll'."  The function is declared like so in my C# application:

```<code>internal static class WMIQuery
{
    [DllImport("WMIQuery.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    internal static extern void CreateScanEngine();
}
</code>```

Dependency Walker shows the function there in the DLL as such:

Ordinal: 1(0x0001)

  Hint: 0(0x0000)

  Function ^: void CreateScanEngine(void)

  Entry Point: 0x00001860

Dependency Walker also shows these errors/warnings for the DLL:

Error: At least one required implicit or forwarded dependency was not found.

  Warning: At least one delay-load dependency module was not found.

  Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Will this make a difference?  Also, I tried adding the DLL as a reference to the C# project, and I got this error:

A reference to [my DLL] could not be added.  Please make sure that the file is accessible, and that it is a valid assembly or COM component.

Does anyone know what I'm doing wrong?  Thanks.

答:
Don't use Dependency Walker, it unmangles the exported name of the function and doesn't tell you the real export name.  Note that it is smart enough to see that it takes no arguments and has no return value.  It can only do this if it sees the name as decorated by the C++ compiler.

Use Dumpbin.exe /exports on the DLL to see the real name.  It ought to be "?CreateScanEngine@@YGXXZ", use the EntryPoint property in the [DllImport] attribute.   You may also want to declare the function with extern "C" so this name mangling doesn't happen.

Body:
I need to import a function that I wrote in C++, and is now compiled into a DLL, into my C# application.  Everything builds without errors or warnings, but when I step through the code the first function call into the DLL throws an Exception with a message of "Unable to find an entry point named 'CreateScanEngine" in DLL 'WMIQuery.dll'."  The function is declared like so in my C# application:

internal static class WMIQuery
{
    [DllImport("WMIQuery.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    internal static extern void CreateScanEngine();
}

Dependency Walker shows the function there in the DLL as such:

Ordinal: 1(0x0001)

  Hint: 0(0x0000)

  Function ^: void CreateScanEngine(void)

  Entry Point: 0x00001860

Dependency Walker also shows these errors/warnings for the DLL:

Error: At least one required implicit or forwarded dependency was not found.

  Warning: At least one delay-load dependency module was not found.

  Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Will this make a difference?  Also, I tried adding the DLL as a reference to the C# project, and I got this error:

A reference to [my DLL] could not be added.  Please make sure that the file is accessible, and that it is a valid assembly or COM component.

Does anyone know what I'm doing wrong?  Thanks.