小编mba*_*tas的帖子

"brew link"有什么作用?

当我跑步时,brew doctor我得到了一个共同的警告:

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
# [...]
Run Code Online (Sandbox Code Playgroud)

对于要取消链接的小桶意味着什么?那到底brew link做了什么?

homebrew

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

使用图像+文本设置WPF按钮的样式

在我的C#/ WPF/.NET 4.5应用程序中,我有按钮,其中包含以下列方式实现的图像:

<Button Style="{StaticResource BigButton}">
  <StackPanel>
    <Image Source="Images/Buttons/bt_big_save.png" />
    <TextBlock>save</TextBlock>
  </StackPanel>
</Button>
Run Code Online (Sandbox Code Playgroud)

我有一个资源字典UIStyles.xaml,其中我声明了以下内容:

<Style TargetType="Button" x:Key="BigButton">
  <Setter Property="Cursor" Value="Hand" />
  <Setter Property="Height" Value="80" />
  <Setter Property="Width" Value="80" />
  <Setter Property="Foreground" Value="White" />
  <Setter Property="FontWeight" Value="Bold" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Border x:Name="border" 
            CornerRadius="5" 
            Background="#FF415360">
          <ContentPresenter x:Name="ButtonContentPresenter"
              VerticalAlignment="Center"  
              HorizontalAlignment="Center">
            <ContentPresenter.Resources>
              <Style TargetType="TextBlock">
                <Setter Property="TextAlignment" Value="Center" />
              </Style>
              <Style TargetType="Image">
                <Setter Property="Width" Value="10" />
                <Setter Property="Margin" Value="10" />
              </Style>
            </ContentPresenter.Resources>
          </ContentPresenter>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

光标,高度,边框等属性工作正常,但我无法设置TextBlock …

c# wpf xaml styles .net-4.5

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

Django使用runserver提供静态文件,但不提供foreman

我有相反的问题中所描述的这个问题.

当服务器启动时,我的Django站点可以正常工作,manage.py runserver但在启动服务器时不会提供静态文件foreman start.

我的目录结构:

project_name/
  project/
    settings.py
    ...
  app/
    ...
  venv/
    ...
  public/
    static/
      # static files go here #
    media/
      ...
  Procfile
  requirements.txt
  manage.py
Run Code Online (Sandbox Code Playgroud)

Procfile(如Djokuo on Heroku入门教程中所述):

web: gunicorn project.wsgi
Run Code Online (Sandbox Code Playgroud)

settings.py:

import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
UP_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '..'))
...
MEDIA_ROOT = UP_ROOT + '/public/media/'
...
STATIC_ROOT = UP_ROOT + '/public/static'
...
STATIC_URL = '/static/'
...
STATICFILES_DIRS = (
UP_ROOT + '/public',
UP_ROOT + '/public/static',
)
Run Code Online (Sandbox Code Playgroud)

就像我说的,所有这些都可以runserver在我的本地机器上正常工作,但不能正常工作foreman …

django heroku foreman

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

在C#中创建对象时订阅事件

在C#(.NET 4.5)中,我想在创建对象时订阅一个事件.

当然,以下内容可行:

CheckBox c = new CheckBox();
c.Name = "TheCheckBox";
c.Checked += c_Checked;
Run Code Online (Sandbox Code Playgroud)

但是想知道是否可以采取以下措施:

CheckBox c = new CheckBox() {
    Name = "TheCheckBox",
    Checked += c_Checked
}
Run Code Online (Sandbox Code Playgroud)

讨论后编辑:这是为了实现如下:

MyUniformGrid.Add(new CheckBox() {
    Name = "TheCheckBox",
    Checked += CheckHandler
});
Run Code Online (Sandbox Code Playgroud)

c# events

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

XAML 在不改变颜色的情况下改变背景不透明度

在我的C# / WPF / .NET 4.5应用程序中,我想实现一个Trigger在不改变控件颜色的情况下切换控件的背景不透明度。

通常要设置控件的背景画笔,我会使用以下内容Setter

<Setter TargetName="TargetControl" Property="Background">
<Setter.Value>
  <SolidColorBrush Color="Red" Opacity="0.2"/>
</Setter.Value>
Run Code Online (Sandbox Code Playgroud)

现在我处于一种情况,我只需要改变不透明度而不是颜色。在这种情况下,我的 setter 会是什么样子,我不在乎背景是什么颜色,但我想在更改不透明度的同时保留颜色?

更多细节:

这样做的原因是我正在研究ItemsControl背景颜色根据项目的变化而变化的地方AlternationIndex

<ItemsControl ItemsSource="{Binding SomeCollection}" AlternationCount="6">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <Grid x:Name="GridWithin">
      <!-- ... -->
      </Grid>
      <DataTemplate.Triggers>
        <!-- Aternating colors for each row -->
        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
          <Setter TargetName="GridWithin" Property="Background">
            <Setter.Value>
              <SolidColorBrush Color="Red" Opacity="0.2"/>
            </Setter.Value>
          </Setter>
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
          <Setter TargetName="AllGesturesDataTemplateGrid" Property="Background">
            <Setter.Value>
              <SolidColorBrush Color="Green" Opacity="0.2"/>
            </Setter.Value>
          </Setter>
        </Trigger>
        <!-- ... -->
        <!-- …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

使用pexpect和pxssh时的EOF

我正在尝试使用暴力Python第2章中的Pxssh部分,通过Pexpect暴力强制SSH密码与SSH 交互中运行代码.使用两者和我得到类似的EOF错误.child.expect()pxssh

从Python控制台运行这些命令:

import pexpect
connStr = "ssh root@127.0.0.1"
child = pexpect.spawn(connStr)
ret = child.expect([pexpect.TIMEOUT, ssh_newkey, "[P|p]assword:"])
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
ne 1316, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
ne 1330, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pexpect.py", li
ne 1401, in expect_loop
    raise EOF (str(e) + '\n' + str(self))
EOF: End Of File …
Run Code Online (Sandbox Code Playgroud)

python pexpect python-2.7

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

C#JSON文件到列表中

在我的C# + WPF + .NET 4.5代码中,假设我已按Player以下方式定义了一个类:

public class Player {
  public string FirstName;
  public string LastName;
  public List<int> Cells;
  public string Level;
}
Run Code Online (Sandbox Code Playgroud)

我有一个myobjects.json文件,我在其中设法编写(使用JSON.NET)这些对象的序列化集合(前两个如下所示):

{
  "FirstName": "Foo",
  "LastName": "Fighter",
  "Cells": [
    1,
    2,
    3
  ],
  "Level": "46"
}{
  "FirstName": "Bar",
  "LastName": "Baz",
  "Cells": [
    104,
    127,
  ],
  "Level": "D2"
}
Run Code Online (Sandbox Code Playgroud)

我想这样做是为了读取文件,和反序列化这些对象和填充ListPlayerS:

using (Stream fs = openDialog.OpenFile())
using (StreamReader sr = new StreamReader(fs))
using (JsonTextReader jr = new JsonTextReader(sr)) …
Run Code Online (Sandbox Code Playgroud)

c# json json.net

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

使用 fast-csv 从文件中读取并写入数组

我正在使用fast-csvfromPath()方法从文件中读取数据。我想将这些数据写入一个数组(我随后将对其进行排序)。我希望下面的代码可以用于此目的,但事实并非如此:

var csv = require('fast-csv');

var dataArr = [];
csv.fromPath("datas.csv", {headers: true})
.on("data", data => {
  console.log(data);
  // > { num: '4319', year: '1997', month: '4', day: '20', ...
  dataArr.push(data);
});
console.log(dataArr);
// > []
Run Code Online (Sandbox Code Playgroud)

我可以使用此代码读取文件中的数据,但未填充数组。

什么是完成此操作的好方法,为什么上面的代码不起作用?

javascript csv

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

将密钥转换为VirtualKeyCode

在我的C#/ WPF/.NET 4.5应用程序中,我试图通过KeyEventHandler捕获按键,然后使用优秀的Windows输入模拟器来模拟按键(将手势,语音等命令映射到键盘).

麻烦的是,我得到的成员Key枚举从KeyEventHandlerRoutedEventArgs,但后来我需要通过一个VirtualKeyCodeSimulateKeyPress().

如何从去KeyVirtualKeyCode

// Trigger reader
private void Editor_CommandButton_Click(object sender, RoutedEventArgs e) {
  PressKeyModal.Visibility = System.Windows.Visibility.Visible;
  AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)Editor_HandleKeyDownEvent);
}
// Read key press from keyboard
private void Editor_HandleKeyDownEvent(object sender, KeyEventArgs e) {
  // Here is the culprit
  VirtualKeyCode CodeOfKeyToEmulate = ConvertSomehow(e.Key);
  // /culprit
  PressKeyModal.Visibility = System.Windows.Visibility.Hidden;
  RemoveHandler(Keyboard.KeyDownEvent, (KeyEventHandler)Editor_HandleKeyDownEvent);
}

// Later, emulate the key press
private void EmulateKeyPress(VirtualKeyCode codeOfKeyToEmulate( {
  InputSimulator.SimulateKeyPress(codeOfKeyToEmulate);
}
Run Code Online (Sandbox Code Playgroud)

c# wpf keyboard-events .net-4.5

3
推荐指数
1
解决办法
2203
查看次数

PythonAnywhere + virtualenv:"无法找到平台依赖库<exec_prefix> ..."

我在PythonAnywhere的virtualenv中运行了Python 2.7.3上的Django(1.5.1)站点.据我记忆,过去一切都很好.最近,虽然除了一些Django代码之外我没有改变任何东西,但是当我运行时,我得到以下消息pip:

(venv)11:34 ~ $ pip
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Traceback (most recent call last):
  File "/*~*//venv/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/*~*//venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 16, in <module>
    import sys, os, zipimport, time, re, imp, types
ImportError: No module named time
Run Code Online (Sandbox Code Playgroud)

不用说,pip产生上述错误后根本不起作用.

当我运行pythonvirtualenv 运行时,我再次收到以下错误:

(venv)11:34 ~ $ python
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python …
Run Code Online (Sandbox Code Playgroud)

python django pip virtualenv pythonanywhere

3
推荐指数
1
解决办法
5210
查看次数

将 Typekit / Adob​​e Fonts 与 @next/font 结合使用

当前的Next.js 字体优化文档@next/font API 参考描述了如何引入 Google Fonts 以及本地字体文件,但没有描述引入 Typekit / Adob​​e Fonts 的最佳实践。

使用 Typekit / Adob​​e Fonts 以便应用 Next.js 优化的最佳方法是什么?

typekit next.js

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