小编rub*_*bik的帖子

git branch:gh-pages

我在GitHub上有一个回购.最近我发现了GitHub的页面,我想使用它们.
我想创建这个新分支,然后,当我需要时,或者在master分支或gh-pages分支上提交.

我怎样才能做到这一点?我是否必须在我的仓库中创建另一个文件夹?

git git-branch github-pages

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

Argparse:如何处理可变数量的参数(nargs ='*')

我认为这nargs='*'足以处理可变数量的参数.显然它不是,我不明白这个错误的原因.

代码:

p = argparse.ArgumentParser()
p.add_argument('pos')
p.add_argument('foo')
p.add_argument('--spam', default=24, type=int, dest='spam')
p.add_argument('vars', nargs='*')

p.parse_args('1 2 --spam 8 8 9'.split())
Run Code Online (Sandbox Code Playgroud)

我认为最终的命名空间应该是Namespace(pos='1', foo='2', spam='8', vars=['8', '9']).相反,argparse给出了这个错误:

usage: prog.py [-h] [--spam SPAM] pos foo [vars [vars ...]]
error: unrecognized arguments: 9 8
Run Code Online (Sandbox Code Playgroud)

基本上,argparse不知道在哪里放这些额外的参数......为什么?

python argparse

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

multiprocessing.Pool - PicklingError:无法pickle <type'strread.lock'>:属性查找thread.lock失败

multiprocessing.Pool让我疯了......
我想要升级许多软件包,对于每一个软件包,我都要检查是否有更大的版本.这是由该check_one功能完成的.
主要代码在Updater.update方法中:我创建了Pool对象并调用该map()方法.

这是代码:

def check_one(args):
    res, total, package, version = args
    i = res.qsize()
    logger.info('\r[{0:.1%} - {1}, {2} / {3}]',
        i / float(total), package, i, total, addn=False)
    try:
        json = PyPIJson(package).retrieve()
        new_version = Version(json['info']['version'])
    except Exception as e:
        logger.error('Error: Failed to fetch data for {0} ({1})', package, e)
        return
    if new_version > version:
        res.put_nowait((package, version, new_version, json))

class Updater(FileManager):

    # __init__ and other methods...

    def update(self):    
        logger.info('Searching for updates')
        packages = Queue.Queue() …
Run Code Online (Sandbox Code Playgroud)

python pickle multiprocessing threadpool

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

将Yesod部署到Heroku,无法静态构建

我是Yesod的新手,我无法静态构建Yesod,因此我可以部署到Heroku.

我更改了默认的.cabal文件以反映静态编译

if flag(production)
   cpp-options:   -DPRODUCTION
   ghc-options:   -Wall -threaded -O2 -static -optl-static
else
   ghc-options:   -Wall -threaded -O0
Run Code Online (Sandbox Code Playgroud)

它不再构建.我得到了一大堆警告,然后是一大堆未定义的引用,如下所示:

Linking dist/build/personal-website/personal-website ...
/usr/lib/ghc-7.0.3/libHSrts_thr.a(Linker.thr_o): In function
`internal_dlopen':
Linker.c:(.text+0x407): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/unix-2.4.2.0/libHSunix-2.4.2.0.a(HsUnix.o): In
function `__hsunix_getpwent':
HsUnix.c:(.text+0xa1): warning: Using 'getpwent' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/unix-2.4.2.0/libHSunix-2.4.2.0.a(HsUnix.o): In
function `__hsunix_getpwnam_r':
HsUnix.c:(.text+0xb1): warning: Using 'getpwnam_r' in …
Run Code Online (Sandbox Code Playgroud)

linux haskell heroku static-linking yesod

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

在python启动时自动加载模块

我希望IPython或Python解释器在我启动它时自动加载模块.

可能吗?

例如,当我启动IPython时:

$ ipython

...

>>> from __future__ import division
>>> from mymodule import *

In [1]:
Run Code Online (Sandbox Code Playgroud)

像教程页面中的SymPy实时shell一样.

python module ipython autoload

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

Haskell:无法理解瓶颈

我解决了Project Euler问题,然后用Haskell维基上的问题面对我的解决方案.他们非常相似,但是我的时间是7.5秒,而另外0.6!我把它们都编成了.

我看起来如下:

main = print . maximumBy (compare `on` cycleLength) $ [1..999]
        where cycleLength d = remainders d 10 []
Run Code Online (Sandbox Code Playgroud)

和其中一个维基:

main = print . fst $ maximumBy (comparing snd) [(n, cycleLength n) | n <- [1..999]]
        where cycleLength d = remainders d 10 []
Run Code Online (Sandbox Code Playgroud)

我也尝试改变compare `on`,comparing cycleLength但性能保持不变.
因此,我必须得出结论,所有差异都在于计算运行中的值与在列表理解中进行转换.

虽然时间上的差异非常大:第二个版本的速度提升了12.5倍!

haskell list-comprehension

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

证书管理器颁发的证书显示为“颁发者:cert-manager.local”而不是 Let's Encrypt,并且不起作用

当我从 Chrome 浏览我的网站时,它说证书无效,如果我检查详细信息,我会看到以下内容:

Issued to:
Common Name (CN)    test.x.example.com
Organization (O)    cert-manager
Organizational Unit (OU)    <Not Part Of Certificate>

Issued by:
Common Name (CN)    cert-manager.local
Organization (O)    cert-manager
Organizational Unit (OU)    <Not Part Of Certificate>
Run Code Online (Sandbox Code Playgroud)

我不明白出了什么问题。从 cert-manager 的输出看来一切都很顺利:

I1002 15:56:52.761583       1 start.go:76] cert-manager "level"=0 "msg"="starting controller"  "git-commit"="95e8b7de" "version"="v0.9.1"
I1002 15:56:52.765337       1 controller.go:169] cert-manager/controller/build-context "level"=0 "msg"="configured acme dns01 nameservers" "nameservers"=["10.44.0.10:53"]
I1002 15:56:52.765777       1 controller.go:134] cert-manager/controller "level"=0 "msg"="starting leader election"
I1002 15:56:52.767133       1 leaderelection.go:235] attempting to acquire leader lease  cert-manager/cert-manager-controller...
I1002 15:56:52.767946 …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform kubernetes google-kubernetes-engine lets-encrypt cert-manager

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

检测未知来源的时间段

如何检测无限序列中的重复数字?我试过Floyd&Brent检测算法,但什么都没有......我有一个生成器,产生0到9(含)的数字,我必须认识到它的一个时期.

示例测试用例:

import itertools

# of course this is a fake one just to offer an example
def source():
    return itertools.cycle((1, 0, 1, 4, 8, 2, 1, 3, 3, 1))

>>> gen = source()
>>> period(gen)
(1, 0, 1, 4, 8, 2, 1, 3, 3, 1)
Run Code Online (Sandbox Code Playgroud)

python algorithm math floyd-cycle-finding

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

创建和定位浮动操作按钮

我正在尝试将FAB添加到卡片视图的底部,就像在此应用中一样: 应用图片

该按钮确实显示,但它不与卡片视图重叠.我正在使用Android Material Design Library.这是我的文件:

colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FFEB3B</color>
    <color name="colorAccentDark">#FBC02D</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

activity_main.xml:

    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    <LinearLayout
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/main_content"
        android:layout_below="@id/toolbar">

        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/stop_card"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_marginTop="5dp"
            card_view:cardCornerRadius="4dp">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:paddingTop="5dp"
                android:paddingRight="10dp"
                android:paddingBottom="5dp">

                <TextView
                    android:id="@+id/label_stop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Fermata"
                    android:textSize="25sp"
                    android:textStyle="bold"
                    android:singleLine="true" />

                <EditText
                    android:id="@+id/edit_stop"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="number"
                    android:ems="10"
                    android:layout_gravity="end" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="72dp" >

            <com.gc.materialdesign.views.ButtonFloat
                android:id="@+id/buttonFloat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-button material-design

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

Haskell vs. erlang:foldl的区别?

我注意到Haskell和Erlang之间存在差异foldl.

因为foldr,两种语言都返回相同的结果:

foldr (\x y -> 2*x+y) 4 [1, 2, 3] -- returns 49
lists:foldr(fun(X, Y) ?> X+2?Y end, 4, [1,2,3]). % returns 49
Run Code Online (Sandbox Code Playgroud)

但是返回值foldl是不同的:

foldl (\x y -> x+2*y) 4 [1, 2, 3] -- returns 16
lists:foldl(fun(X, Y) ?> X+2?Y end, 4, [1,2,3]). -- returns 43
Run Code Online (Sandbox Code Playgroud)

如何解释这种差异?

erlang haskell fold

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