小编ash*_*ies的帖子

VSCode:所选环境中没有可用的Pip安装程序

我正在尝试在VSCode中的Python文件上运行autopep8 linter.

我按照这里的说明操作:https://code.visualstudio.com/docs/python/environments并选择我的翻译(⇧⌘P):/usr/local/bin/python

然后我尝试格式化我的代码,VSCode说没有安装autopep8,可以通过Pip安装.但是,当我尝试通过Pip安装时,它说There is no Pip installer available in the selected environment.

然后,我尝试通过从命令选项板中选择Python:Create Terminal来在当前环境中启动终端.

终端打开正常,pip存在,我甚至可以pip install autopep8在VSCode中打开的终端中,但是当我尝试运行Format Document命令时,我得到了相同的错误,autopep8并且pip在环境中不可用.

python pip visual-studio-code vscode-settings

43
推荐指数
8
解决办法
4万
查看次数

Python - 在decorator中获取原始函数参数

我正在尝试为WSGI + Werkzeug应用程序中的视图编写"login_required"装饰器.

为了做到这一点,我需要进入用户的会话,该会话可以通过传递给视图方法的Request对象访问.

不过,我无法弄清楚如何在装饰器中获取Request的实例.我看了PEP318,特别是第四个例子,但我不太明白.

这是我正在尝试的:

def login_required(*args, **kw):
    def goto_login(**kw):
        return redirect(url_for('login'))

    def decorate(f):
        # args[0] should be request
        args[0].client_session['test'] = True
        logged_in = 0
        if logged_in:
            return f
        else:
            return goto_login
    return decorate


@login_required()
@expose('/hello/<string:name>')
def hello(request, name):
    return render_template('say_hello.html', name=name)
Run Code Online (Sandbox Code Playgroud)

但我得到一个索引超出界限错误试图打电话args[0].

有没有办法可以访问传递给"login_required"装饰器中"hello"函数的请求参数?

python decorator

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

vim - 在交互模式下不识别别名?

从vim执行的命令相同的问题是没有识别bash命令别名,但是那里的解决方案不起作用.

我在〜/ .vimrc中设置了这些变量:

set shellcmdflag=-ic
set shell=/bin/bash\ -i
Run Code Online (Sandbox Code Playgroud)

我的〜/ .bash_aliases中有别名:

rgr() { if [ ! -z "$2" ]; then grep -rI --exclude=\*.svn\* "$1" * --include=$2 ; else grep -rI --exclude=*svn* "$1" * ; fi ; }
Run Code Online (Sandbox Code Playgroud)

从命令行执行时,它工作,但当我尝试从vim(:!rgr test)调用它时,我收到一条错误消息,vim退出:

bash: rgr: command not found

[4]+  Stopped                 vi ~/somefile
Run Code Online (Sandbox Code Playgroud)

如果我禁用交互模式,我只是得到"命令未找到"消息,并且vim不会退出.

如何让vim识别我的别名?我在OS X和Ubuntu上都重现了这种行为.

vim bash

21
推荐指数
3
解决办法
7204
查看次数

PHP如何将原始cookie解析为$ _COOKIE?

我有跨域AJAX请求的问题.

此问题涉及三台服务器.我们可以称他们为A1,A2,和.

A1A2运行相同的应用程序代码.它们是同一Web应用程序的两个临时实例.B是另一个Web应用程序.

我们需要从A Web应用程序到B应用程序执行跨域AJAX请求.我们尝试启用CORS但很难在IE <= 8中令人满意地工作,所以现在我们使用的是nginx代理规则.因此流程是:浏览器ajax请求 - > A1A2 - > nginx代理 - > B.

B是有状态的,需要用户的会话cookie才能运行.

我们看到的是,这在使用服务器A1时正常工作,但在使用服务器A2时,B无法提取cookie.

我查看了来自A1A2的请求的标题,它们是相同的.两者都在标题中有cookie行,两者都有相同的来源等.

B上我们看到$ _COOKIE ['session_key']在请求来自A2时为空,但在请求来自A1时正确填写.

奇怪的是,它只是缺少从标题中的cookie中拉出一个特定的cookie密钥,并且仅在请求来自A2时.它解析了A2中标题中的所有其他cookie ,它只是因为某些原因无法解析用户的会话cookie,但如果请求来自A1,它就可以了.

我已经使用了tcpdump并取了每个的pcaps并将它们区分开来,标题中没有任何内容看起来特别不同.

我发现这个Stack Overflow问题并且人们说这是因为他的cookie标题字符串太长了:什么可能导致cookie没有设置在$ _COOKIE中,当它在$ _SERVER时我不认为太长,因为我的只有249个字符在成功和失败的情况下都是如此.

我正在考虑从$ _SERVER中删除cookie并手动解析它们,但这听起来真的很愚蠢,我更愿意找出潜在的问题.

php cookies session-cookies

9
推荐指数
1
解决办法
1051
查看次数

git svn repo上的"git rebase <branch>"改变了远程跟踪目的地?

我有一个git svn repo.我在这里有多个发布分支.我正在准备一个新的版本,作为其中的一部分,我想我会从之前的版本中做一个"git rebase"来完成任何尚未合并的更改.

所以我建立了我的分支......

git branch new_release remotes/svn-branches/new_release
git branch old_release remotes/svn-branches/old_release
Run Code Online (Sandbox Code Playgroud)

然后我做了改变...

git checkout new_release
git rebase old_release
# watch it pull a bunch of commits
git svn dcommit
    Committing to https://svn.mysvn.net/repo/releases/old_release ...
Run Code Online (Sandbox Code Playgroud)

在我做了"svn dcommit"后,我差点把裤子弄坏了.它在Subversion中收藏了我的旧版本分支!

为什么远程跟踪分支因为进行rebase而改变?

我如何解决自己陷入困境的局面?

编辑:好的,为了让自己离开,我相信我可以做到以下几点:http://svnbook.red-bean.com/en/1.5/svn.branchmerge.basicmerging.html#svn.branchmerge.basicmerging.undo

由于new_release分支上只有少数提交被拉到old_release,我可以在SVN repo上单独手动还原它们.我仍然对这里发生的事感到困惑.

EDITx2:是的,这里有一些验证步骤.

  1. 设置两个git分支,远程跟踪SVN分支
  2. 看看其中一个分支机构
  3. 运行git svn info并观察URL指向SVN中的正确位置
  4. git rebase <other_branch>
  5. git svn info再次运行并观察更改的URL以指向SVN中的其他分支位置

svn git git-svn

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

Python HMAC-SHA1与Java HMAC-SHA1的结果不同

我从http://tools.ietf.org/html/rfc6238借用了HMAC-SHA1 Java代码,并略微修改它以使用已知输出的已知密钥/消息对进行硬编码.

然后我尝试在Python中编写相同的代码来验证结果,但是我在Python和Java中获得了不同的值.

已知Java值很好.

Java代码:

 import java.lang.reflect.UndeclaredThrowableException;
 import java.security.GeneralSecurityException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import java.math.BigInteger;
 import java.util.TimeZone;
 import java.util.Arrays;


 public class make_hmac {

     private make_hmac() {}


     private static byte[] hmac_sha(String crypto, byte[] keyBytes,
             byte[] text){
         try {
          System.out.println("Key is..." + bytesToHex(keyBytes) + "\n");
             Mac hmac;
             hmac = Mac.getInstance(crypto);
             SecretKeySpec macKey =
                 new SecretKeySpec(keyBytes, "RAW");
             hmac.init(macKey);
             return hmac.doFinal(text);
         } catch (GeneralSecurityException gse) {
             throw new UndeclaredThrowableException(gse);
         }
     }


     private static byte[] hexStr2Bytes(String hex){ …
Run Code Online (Sandbox Code Playgroud)

python java sha1 hmac

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

C信号量和线程之间的"障碍"

我正在尝试解决我们的操作系统教授在之前的考试中向我们展示的问题,以便为下一个考试做准备.

问题是有两个并发执行的线程,可能会在不同的时间内完成.在特定线程完成之后,它需要阻塞直到另一个线程完成,然后它们可以继续执行.

对我来说,这在概念上看起来很简单,但我的代码并没有像我认为的那样工作.

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>

#define N 10

sem_t t_1_sem;
sem_t t_2_sem;

void *thread(void *vargp);
/* shared by both threads*/
struct {
    int count;
} thread_count;

int main() {
    pthread_t tid, tid1;

    thread_count.count = 0;

    sem_init(&t_1_sem, 0, 1);
    sem_init(&t_2_sem, 0, 1);
    printf("Hello from main thread! tid:%ld pid:%d\n", pthread_self(), getpid());
    pthread_create(&tid, NULL, thread, NULL);
    pthread_create(&tid1, NULL, thread, NULL);

    pthread_join(tid, NULL);
    pthread_join(tid1, NULL);

    exit(0);
}

void *thread(void *vargp) {
    int i, tid;

    int val, val2;
    sem_getvalue(&t_1_sem, …
Run Code Online (Sandbox Code Playgroud)

c multithreading semaphore

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

Junit和Java类路径问题 - OS X.

我正在尝试运行junit4.7附带的样本测试并遇到一些困难.

java是尊重我的CLASSPATH:

me@dinosaurhunter ~/Desktop> export CLASSPATH=
me@dinosaurhunter ~/Desktop> echo $CLASSPATH

me@dinosaurhunter ~/Desktop> java junit.textui.TestRunner junit.samples.AllTests
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner
me@dinosaurhunter ~/Desktop> source /etc/profile 
me@dinosaurhunter ~/Desktop> echo $CLASSPATH
:/Library/Java/Extensions/junit/:/Library/Java/Extensions/junit/junit.jar
me@dinosaurhunter ~/Desktop> java junit.textui.TestRunner junit.samples.AllTests
Exception in thread "main" java.lang.NoClassDefFoundError: junit/framework/Test
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at junit.runner.BaseTestRunner.loadSuiteClass(BaseTestRunner.java:207)
    at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:100)
    at junit.textui.TestRunner.start(TestRunner.java:179)
    at junit.textui.TestRunner.main(TestRunner.java:138)
Run Code Online (Sandbox Code Playgroud)

但正如你所看到的,它无法找到junit/framework/Test......我看着/Library/Java/Extensions/junit/junit.jar它,但它包括在内.

/Library/Java/Extensions/junit/junit.jar是一个符号链接.这样可以吗?

java macos junit classpath

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

ANSI C getc导致Linux上的段错误而不是OS X

我有一些我在Mac上开发的ANSI C代码,但是当我尝试在我们学校的Linux服务器上运行时,我得到了段错误.

导致我麻烦的具体行是getc来自文件指针.

该文件确实存在.

这是有问题的方法:

// inits lists with all data in fp file pointer
// returns # of lines read
int init_intlists(FILE *fp, INTLIST *lists[]) {
    int c, ctr;

    ctr = 0;

    // need to use a linked list to store current number
    // for non 1-digit numbers...
    INTLIST *cur_num = NULL;
    int cur_num_len = 0;
    while ((c = getc(fp)) != EOF){
        if(c != '\n' && c != ' '){
            c = c - 48;
            if(cur_num == …
Run Code Online (Sandbox Code Playgroud)

c malloc file-io readline segmentation-fault

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

PHP array_merge重新加密 - 它是如何工作的?

昨天我头疼.

基本上我有一个带有字符串键的数据的关联数组(包含数值,但仍然是引用的字符串)<select>作为选项放在一个框中.我想在占位符值的前面添加一个占位符值.

我试图使用array_merge:

$placeholder = "Month";
$source = array
(
    '01' => '01 - January',
    '02' => '02 - February',
    '03' => '03 - March',
    '04' => '04 - April',
    '05' => '05 - May',
    '06' => '06 - June',
    '07' => '07 - July',
    '08' => '08 - August',
    '09' => '09 - September',
    '10' => '10 - October',
    '11' => '11 - November',
    '12' => '12 - December'
);

$source = array_merge(array('' => $placeholder), $source);
Run Code Online (Sandbox Code Playgroud)

我看到了奇怪的结果 …

php array-merge

0
推荐指数
1
解决办法
1136
查看次数

zsh——似乎不区分大小写?

我试图将一些名称相同但大小写不同的文件复制到同一目录中。

请参阅以下步骤:

~/tmp $ echo "First" > test
~/tmp $ echo "Second" > Test
~/tmp $ ls
test
~/tmp $ cat test
Second
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

macos zsh

0
推荐指数
1
解决办法
400
查看次数