小编Tob*_*bbe的帖子

使git diff正确显示UTF8编码的字符

我有一个带有瑞典字符的文件(åäö),用UTF8编码.

如果我cat的文件显示正常,但如果我这样做git diff,则打印特殊字符,例如,<F6>.

示例git diff输出:

-            name: 'Magler<F6>d, S<F6>der<E5>sen',
Run Code Online (Sandbox Code Playgroud)

我想看到的:

-            name: 'Magleröd, Söderåsen',
Run Code Online (Sandbox Code Playgroud)

我发现了另一个与git和编码问题相关的问题:git,msysgit,accents,utf-8,权威答案 它说所有问题都应该在git 1.7.10中修复.我有1.8.1.2版

我该怎么做才能使git diff正确显示åäö?

git encoding utf-8

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

Java InputStream编码/字符集

运行以下(示例)代码

import java.io.*;

public class test {
    public static void main(String[] args) throws Exception {
        byte[] buf = {-27};
        InputStream is = new ByteArrayInputStream(buf);
        BufferedReader r = new BufferedReader(
                new InputStreamReader(is, "ISO-8859-1"));
        String s = r.readLine();
        System.out.println("test.java:9 [byte] (char)" + (char)s.getBytes()[0] + 
                " (int)" + (int)s.getBytes()[0]);
        System.out.println("test.java:10 [char] (char)" + (char)s.charAt(0) + 
                " (int)" + (int)s.charAt(0));
        System.out.println("test.java:11 string below");
        System.out.println(s);
        System.out.println("test.java:13 string above");
    }
}
Run Code Online (Sandbox Code Playgroud)

给了我这个输出

test.java:9 [byte] (char)? (int)63
test.java:10 [char] (char)? (int)229
test.java:11 string below
?
test.java:13 string …

java encoding iso-8859-1

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

从Web浏览器控件中运行的JavaScript脚本调用C++函数

我在我的c ++应用程序中嵌入了一个Web浏览器控件.我希望在Web浏览器控件中运行的javascript能够调用c ++函数/方法.

我发现有三种方法可以做到这一点:

  1. 实现一个充当中间人的ActiveX组件.(此处的实施细节:http://blogs.msdn.com/b/nicd/archive/2007/04/18/calling-into-your-bho-from-a-client-script.aspx)
  2. 使用window.external.(也在上面的链接中讨论过,但没有提供实现)
  3. 将自定义对象添加到窗口对象

我想第三个选项,但我没有找到任何有关如何做到这一点的工作示例.有人可以告诉我该怎么做,或链接到某个网上的工作示例.

最接近我发现的一个例子是Igor Tandetnik在webbrowser_ctl新闻组的一个帖子中的第一个回复.但我担心我需要更多的帮助.

我嵌入了一个IWebBrowser2控件,我没有使用MFC,ATL或WTL.

编辑:

通过Igor在我之前链接的线程中给出的伪代码,以及代码项目文章" 从C++创建JavaScript数组和其他对象 "中找到的代码,我已经生成了一些代码.

void WebForm::AddCustomObject(IDispatch *custObj, std::string name)
{
    IHTMLDocument2 *doc = GetDoc();
    IHTMLWindow2 *win = NULL;
    doc->get_parentWindow(&win);

    if (win == NULL) {
        return;
    }

    IDispatchEx *winEx;
    win->QueryInterface(&winEx);

    if (winEx == NULL) {
        return;
    }

    int lenW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name.c_str(), -1, NULL, 0);
    BSTR objName = SysAllocStringLen(0, lenW);
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name.c_str(), -1, objName, lenW);

    DISPID dispid; 
    HRESULT hr = winEx->GetDispID(objName, fdexNameEnsure, …
Run Code Online (Sandbox Code Playgroud)

javascript c++ windows com iwebbrowser2

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

有关"警告C4312:'type cast'"的问题

这是我的代码:

HWND WebformCreate(HWND hParent, UINT id)
{
    return CreateWindowEx(0, WEBFORM_CLASS, _T("about:blank"),
        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, 100, 100, hParent,
        (HMENU)id, GetModuleHandle(NULL), 0);
}
Run Code Online (Sandbox Code Playgroud)

这是我收到的警告:

warning C4312: 'type cast' : conversion from 'UINT' to 'HMENU' of greater size
Run Code Online (Sandbox Code Playgroud)

这些是我的问题:

  1. 为什么编译器认为转换为更大的类型是个坏主意?
  2. 什么是摆脱警告的最佳方法?(我不想禁用它.)
  3. 像这样做双重类型转换:(HMENU)(UINT_PTR)id摆脱警告.为什么/怎么样?
  4. 禁用"检测64位可移植性问题"(Wp64)也会消除警告.为什么弃用Wp64?我可以买吗?

c++ 64-bit winapi

8
推荐指数
2
解决办法
9728
查看次数

为什么JList选择会出现两次?

我有一个带有一些项目的JList.我已经为选择列表中的项目时添加了一个监听器.以下是选择列表中的项目时会发生什么的代码:

private void questionaireNamesListValueChanged(ListSelectionEvent evt) {
    try {
        inputPanel.setEnabled(false);
        inputPanel.setVisible(false);
        inputTextField.setText("");
        inputStatusLabel.setText("");
        int questionaireIndex = questionaireNamesList.getSelectedIndex();

        // Why will this be printed twice?
        System.out.println("Questionaire Index: " + questionaireIndex);

        if (remoteQuestionServer.getQuestionCount(questionaireIndex) == 5) {
            answerQuestionButton.setEnabled(true);
            addQuestionButton.setEnabled(false);
        } else {
            addQuestionButton.setEnabled(true);
            answerQuestionButton.setEnabled(false);
        }
    } catch (RemoteException ex) {
        ex.printStackTrace();
    }
} 
Run Code Online (Sandbox Code Playgroud)

你可以在上面我发表一个System.out.print声明,每当我点击列表中的某些内容时,我就会获得该项目的两个输出,例如.

Questionaire Index: 4
Questionaire Index: 4
Questionaire Index: 2
Questionaire Index: 2
Questionaire Index: 0
Questionaire Index: 0
Questionaire Index: 2
Questionaire Index: 2
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

谢谢,帕特里克

java swing jlist

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

如何禁用测试的vue.js转换?

我有一个vue.js组件,它使用该<transition>元素为hide/show设置动画.

为了加快测试,我想禁用动画.我怎样才能做到这一点?

* { transition: none !important }建议在这里:https://github.com/vuejs/vue/issues/463但它似乎没有什么区别.

我在这里创造了一个小提琴:https://jsfiddle.net/z11fe07p/2268/

运行"测试"的最后一个输出是"3.显示应该是"无",它是:块".如果我将超时增加到100,或删除<transition>元素,我得到预期的输出"3.显示应该是"无",它是:无"

那么如何禁用动画以便我可以摆脱这些setTimeout调用呢?

编辑:

我尝试删除所有的CSS样式,但仍然有同样的问题.所以问题是通过简单地拥有<transition>元素来触发的.

编辑2:

更新了小提琴,没​​有造型,只是<transition>元素.还包括要求$nextTick()确保这不是它表现奇怪的原因.

将呼叫更改为wait100,wait10而您将看到测试开始失败

https://jsfiddle.net/z11fe07p/2270/

编辑3:

将示例代码放在这里,这样每个人都可以更轻松地玩:)

new Vue({
  el: '#app',
  template: `
    <span>
      <button @click="test()">Run test</button>
      <transition>
        <p v-show="show">Hello, world!</p>
      </transition>
    </span>
  `,
  data() {
    return {
      show: false,
    };
  },
  methods: {
    test() {
      const wait10 = _ => new Promise(resolve => …
Run Code Online (Sandbox Code Playgroud)

javascript css animation vue.js vuejs2

6
推荐指数
2
解决办法
3329
查看次数

绑定数据更改时Winforms列表框不更新

下图显示了我的代码的工作原理.当我按下按钮2时,列表框会更新,但不会在我按下按钮1时更新.为什么?

伪代码http://i44.tinypic.com/mj69oj.gif

问题线程是否相关?如果是,我应该在哪里添加对(Begin)Invoke的调用?

需要注意的一件有趣的事情是,如果我先按下button1然后按下按钮2,则单击button2时会显示button1单击生成的数据.所以似乎doFoo生成的数据在某处缓冲,然后在按下button2后推送到列表框.

编辑:

我尝试将AddNumber添加到表单代码中,并在listBox1.InvokeRequired返回true时添加对Invoke的调用.这解决了问题,但不是最好的设计.我不希望GUI必须"担心"如何将项添加到模型的一部分列表中.

如何在添加到列表类内部列表的同时保持逻辑,同时在列表更改时仍然更新gui?

编辑2:

现在我们已经确认这是一个线程问题,我已经更新了图像,以便更接近地反映我正在处理的实际代码的设计.

虽然Lucero的建议仍然解决了这个问题,但我希望能找到一些不需要表格来了解dll或CDllWrapper的东西.

模型(ListBoxDataBindingSource等)应该对视图(列表框,按钮,标签等)一无所知

c# data-binding multithreading listbox winforms

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

在 Vista/7 (C++) 上获取音量变化通知

每当 Windows Vista/7 上的主音量发生变化时,我都会尝试收到通知。这是我正在使用的代码:

#include <audiopolicy.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <windows.h>
#include <shlwapi.h>
#include <iostream>
#include <Tchar.h>

static const GUID AudioSessionVolumeCtx = { 0x2715279f, 0x4139, 0x4ba0, { 0x9c, 0xb1, 0xb3, 0x51, 0xf1, 0xb5, 0x8a, 0x4a } };

template <class T> void SafeRelease(T **ppT)
{
    if (*ppT)
    {
        (*ppT)->Release();
        *ppT = NULL;
    }
}

class CAudioSessionVolume : public IAudioSessionEvents
{
public:
    static HRESULT CreateInstance( UINT uNotificationMessage, HWND hwndNotification, CAudioSessionVolume **ppAudioSessionVolume )
    {
        CAudioSessionVolume *pAudioSessionVolume = new (std::nothrow) 
            CAudioSessionVolume(uNotificationMessage, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi windows-vista windows-7

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

Windows 上 npm run 脚本中 shell 脚本的退出状态

我有一个非常简单的 shell 脚本,test.sh

#!/usr/bin/env bash

exit 1
Run Code Online (Sandbox Code Playgroud)

我从我的test运行脚本中调用它package.json

"scripts": {
  "test": "test.sh && echo \"unexpected output\""
},
Run Code Online (Sandbox Code Playgroud)

运行npm test我得到这个:

$ npm test

> testtest@1.0.0 test C:\Users\[path]\testtest
> test.sh && echo "unexpected output"

"unexpected output"
Run Code Online (Sandbox Code Playgroud)

看起来 npm 并不关心 test.sh 的非零退出代码。我没想到会看到“意外的输出”。

"test"当命令执行的步骤之一(test.sh在本例中)因错误退出时,如何使命令的执行停止?

在我的 package.json 中:"test": "test.sh && echo $?",
这是输出:

$ npm test

> testtest@1.0.0 test C:\Users\[path]\testtest
> test.sh && echo $?

$?
Run Code Online (Sandbox Code Playgroud)

有了这个:"test": "test.sh && echo \"$?\"",
我得到这个:

$ npm …
Run Code Online (Sandbox Code Playgroud)

windows bash node.js npm

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

将多个公钥与 webauthn 用户关联

我正在实施 webauthn 作为概念验证。

我希望我的用户能够使用多个不同的“平台”身份验证器登录。例如,桌面计算机上的 Windows Hello 和 iPhone 上的 Face ID。每个身份验证器都有自己的公钥,将其发送到 RP,并将其存储在数据库中。

当用户登录(调用navigator.credentials.get())时,我如何知道服务器(RP)上要使用什么公钥?或者我应该全部尝试一下?

根据https://www.w3.org/TR/webauthn/#usecase-new-device-registration ,单个用户拥有多个设备似乎是受支持的方案,所以我猜测有某种官方或最佳方案- 实践实现这一点的方法。

那么,如果用户有多个与之关联的公钥,我如何知道在验证登录/断言签名时使用哪一个呢?

webauthn

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

如何使引导下拉列表与输入组一样宽?

我有这个:

下拉截图

这是代码

<div class="col-xs-8 col-xs-offset-2">
    <form role="form">
        <div class="input-group">
            <input type="text" class="form-control">
            <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                    <span class="caret"></span>
                </button>
                <ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-right" role="menu">
                    <li class="input"><a href="#">black</a></li>
                    <li class="input"><a href="#">white</a></li>
                    <li class="input"><a href="#">red</a></li>
                    <li class="input"><a href="#">blue</a></li>
                    <li class="input"><a href="#">yellow</a></li>
                </ul>
            </div>
        </div>
    </form>
</div>
Run Code Online (Sandbox Code Playgroud)

小提琴:http://jsfiddle.net/ytqyowgt/

如何使下拉列表与输入字段+按钮一样宽?

html css twitter-bootstrap

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

在 React 中,使用 TypeScript,如何使用 RefForwardingComponent 和 forwardRef 将 ref 传递给自定义组件?

我正在尝试将 ref 传递给自定义组件(以便我可以将焦点设置到该组件)。

但我不断收到此错误

const RefComp: React.RefForwardingComponent<HTMLInputElement, Props>
Type '{ value: string; onChange: Dispatch<SetStateAction<string>>; ref: MutableRefObject<HTMLInputElement | undefined>; }'
is not assignable to type 'IntrinsicAttributes & Props & { children?: ReactNode; }'.
  Property 'ref' does not exist on type 'IntrinsicAttributes & Props & { children?: ReactNode; }'.ts(2322)
Run Code Online (Sandbox Code Playgroud)

这是我的代码

import * as React from 'react';
import {useRef, useState, RefForwardingComponent, forwardRef} from 'react';

interface Props {
    value: string;
    onChange(event: string): void;
}

const RefComp: RefForwardingComponent<HTMLInputElement, Props> = forwardRef<
    HTMLInputElement,
    Props
>(({value, onChange}, …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-hooks

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