小编Xan*_*unn的帖子

git update-index - 在目录上保持不变

git 1.7.12

我想将给定目录下的所有文件标记为假设未更改.

1)git update-index --assume-unchaged dir/给出"忽略路径".

2)git update-index --assume-unchaged dir/*快速失败,因为它会遇到未被跟踪的文件,因此它给出"致命:无法标记文件"并退出.

3)尝试生成要标记的文件列表. cd进入所需目录然后运行git ls-files | tr '\n' ' ' | git update-index --assume-unchanged.这不会产生任何错误消息,但不会成功标记文件.命令的第一部分git ls-files | tr '\n' ' '正确生成了我要标记的所有文件的空格分隔列表.如果我将该命令的输出复制并粘贴到命令行,则该git update-index命令有效.什么不使用管道?

不,我添加dir到.gitignore 是不够的.我需要将这些文件放在存储库中,但是需要在本地进行不需要的更改,以便用户可以进行拉取.

git command-line pipe

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

Haskell如何创建Word8?

我想编写一个简单的函数,它分割一个ByteString[ByteString]使用'\n'作为分隔符.我的尝试:

import Data.ByteString

listize :: ByteString -> [ByteString]
listize xs = Data.ByteString.splitWith (=='\n') xs
Run Code Online (Sandbox Code Playgroud)

这会引发错误,因为它'\n'是一个Char而不是一个Word8,这Data.ByteString.splitWith是期待的.

如何打开这个简单的字符为Word8ByteString会玩?

string haskell bytestring

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

Haskell:扫描列表并为每个元素应用不同的函数

我需要扫描文档并为文件中的每个字符串累积不同函数的输出.在文件的任何给定行上运行的函数取决于该行中的内容.

我可以通过为我想要收集的每个列表完整传递文件来非常低效地执行此操作.示例伪代码:

at :: B.ByteString -> Maybe Atom
at line
    | line == ATOM record = do stuff to return Just Atom
    | otherwise = Nothing

ot :: B.ByteString -> Maybe Sheet
ot line
    | line == SHEET record = do other stuff to return Just Sheet
    | otherwise = Nothing
Run Code Online (Sandbox Code Playgroud)

然后,我会将这些函数映射到文件中的整个行列表中,以获得Atoms和Sheets的完整列表:

mapper :: [B.ByteString] -> IO ()
mapper lines = do
    let atoms = mapMaybe at lines
    let sheets = mapMaybe to lines
    -- Do stuff with my atoms …
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming list

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

Haskell List Concatenation vs.(head:tail)格式

我总是以这种格式编写生成列表的递归函数:

recursiveFunc :: [a] -> [b]
recursiveFunc (x:xs) = [change x] ++ resursiveFunc xs where
    change :: a -> b
    change x = ...
Run Code Online (Sandbox Code Playgroud)

我意识到上面的任何功能都可以针对a -> b案例编写,然后简单地编写map一组[a],但请以这个淡化情况为例.

HLint建议更换[change x] ++ recursiveFunc xschange x : recursiveFunc xs.

这个建议纯粹是美学的,还是对Haskell如何执行函数有一些影响?

haskell list

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

Haskell自定义数学类型和类

有没有办法让类实例返回一个不属于实例类型的值?一个例子是想要为两个向量的标量积返回Double类型的值:

--  data structure to contain a 3D point in space
data Point3D = Point3D !Double !Double !Double
    deriving (Eq, Ord)

instance Num Point3D where
    -- Multiplication, scalar == Dot product
    Point3D x1 y1 z1 * Point3D x2 y2 z2 = x1*x2 + y1*y2 + z1*z2 :: Double
Run Code Online (Sandbox Code Playgroud)

此外,有没有办法定义运算符如何在不同类型的函数之间工作?例如,我想定义Point3D x y z + Double a = Point3D (x + a) (y + a) (z + a)

math haskell types class operator-overloading

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

两个Objective-C内存管理问题:泄漏检测是否始终正确?为什么autorelease工作但不释放?

我刚刚发现了以下内容:正如我所料,在我返回它之前释放我的对象会导致应用程序崩溃:

   + (NSString *)descriptionOfExpression:(NSArray *)anExpression {
    NSMutableString *expressionDescription;
    expressionDescription = [[NSMutableString alloc] init];  
    for (id object in anExpression) {
    //Do stuff to expressionDescription
    }

    [expressionDescription release];
    return expressionDescription;
}
Run Code Online (Sandbox Code Playgroud)

但是,我没想到以下会导致内存泄漏:

    + (NSString *)descriptionOfExpression:(NSArray *)anExpression {
    NSMutableString *expressionDescription;
    expressionDescription = [[NSMutableString alloc] init];  
    for (id object in anExpression) {
    //Do stuff to expressionDescription
    }

    return expressionDescription;
    [expressionDescription release];
}
Run Code Online (Sandbox Code Playgroud)

最终,我的解决方案是这样做,而是:

    + (NSString *)descriptionOfExpression:(NSArray *)anExpression {
    NSMutableString *expressionDescription;
    expressionDescription = [[NSMutableString alloc] init];  
    for (id object in anExpression) {
    //Do stuff to …
Run Code Online (Sandbox Code Playgroud)

iphone memory-leaks memory-management objective-c

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

Python 3.2.2函数在非空变量上返回None

我正在编写一个简单的脚本来下载.mp4 TEDTalks给出一个TEDTalk网站链接列表:

# Run through a list of TEDTalk website links and download each
# TEDTalk in high quality MP4

import urllib.request

#List of website links
l = [
        "http://www.ted.com/index.php/talks/view/id/28",
        "http://www.ted.com/index.php/talks/view/id/29",
    ]

# Function which takes the location of the string "-480p.mp4",
# d = 1 less that location, and a string and returns the
# full movie download link
def findFullURL(d, e, s):
    a = s[d]
    if a != "/":
        #Subtract from d to move back another letter
        d …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

Haskell访问列表理解中的元组数据

我已经定义了一个自定义类型如下:

-- Atom reference number, x coordinate, y coordinate, z coordinate, element symbol, 
--      atom name, residue sequence number, amino acid abbreviation
type Atom = (Int, Double, Double, Double, Word8, ByteString, Int, ByteString)
Run Code Online (Sandbox Code Playgroud)

我想收集所有具有一定残留序列号nm的原子.

这样会很好:

[x | x <- p, d == nm]
where
    (_, _, _, _, _, _, d, _) = x
Run Code Online (Sandbox Code Playgroud)

其中p是原子列表.

但是,这不起作用,因为我不能在列表推导之外访问变量x,也不能想到从列表推导中访问特定元组值的方法.

是否存在我缺少的元组方法,或者我应该使用不同的数据结构?

我知道我可以编写一个递归函数来解包并检查列表p中的每个元组,但我实际上是试图在已经递归的函数中使用这个嵌套,所以我宁愿不需要引入那种复杂性.

haskell types tuples

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

Python副作用我不明白

def group_move(group, damper):
    # Make a copy to test values
    new = group

    # See what the original group value is
    print("Test = " + str(group.ctris[0].p1.x))
    dr = some float
    dx = some float
    dy = some float
    # Make changes to new
    moveGroup(new, dr, dx, dy)
    # See if those changes produce allowed values
    if (off_board_check(new) == 1):
        damper += 2.0
        # Reset to original to try again
        print("Test Here = " + str(group.ctris[0].p1.x))
        group_move(group, damper)
    else:
        # If …
Run Code Online (Sandbox Code Playgroud)

python side-effects

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

make_pair是原子的吗?

std::pair<Object, OtherObject*> currentData;

void OnCallback()
{
    Object object = getObject();
    OtherObject* otherObject = new OtherObject();
    currentData = std::make_pair(object, otherObject);
}
Run Code Online (Sandbox Code Playgroud)

make_pair原子?将make_pair字段从其返回值复制或移动到currentData?如果我有另一个线程访问该值currentData,那么访问它时是否有任何潜在currentData的价值不完整?

不幸的是,我没有在标准文档中看到任何相关信息make_pair.

c++ thread-safety atomicity

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