小编Tha*_*you的帖子

如何使用master上的上游更改更新主题分支?

我在一个主题分支上开始做一些工作

    •-•-• < topic
   /
•-•       < master
Run Code Online (Sandbox Code Playgroud)

我推动主题分支

$ git push origin topic
Run Code Online (Sandbox Code Playgroud)

其他人将更改推送到主人

    •-•-• < origin/topic
   /
•-•-•—•   < origin/master
Run Code Online (Sandbox Code Playgroud)

如何更新我的本地主人并重新定义我的主题?

历史应该是这样的

        •-•-• < topic
       /
•-•-•—•       < master
Run Code Online (Sandbox Code Playgroud)

我在想什么

; update master
$ git checkout master
$ git fetch origin
$ git merge --ff-only origin/master

; rebase topic
$ git checkout topic
$ git rebase master
Run Code Online (Sandbox Code Playgroud)

问题

我的所有提交topic都被认为是未提交的.所以,当我尝试时git push origin topic,我得到了

 ! [rejected]        topic -> topic (non-fast-forward)
error: failed to push some refs …
Run Code Online (Sandbox Code Playgroud)

git git-rebase

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

JavaScript:如何将x添加到数组x次?

我想这与数组填充类似,但我想知道它是否可以简化.

var arr = [1,2,3],
    x   = 5;

for (var i=0; i<x; i++) {
  arr.push(x);
}

console.log(arr);
//=> [1, 2, 3, 5, 5, 5, 5, 5]
Run Code Online (Sandbox Code Playgroud)

有没有办法在不使用for循环的情况下执行此操作?


更新

即使有移动器聪明的解决方案,for循环似乎是最高性能的

阵列 - 填充 -  2 关于jsperf的基准

javascript arrays concat pad

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

如何使用CSS显示img alt文本?

我试过这个,它运行正常

<p alt="world">hello</p>
Run Code Online (Sandbox Code Playgroud)

用CSS

p::after {
  content: attr(alt);
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试时它不起作用

<img src="http://placehold.it/300x300" alt="my image caption">
Run Code Online (Sandbox Code Playgroud)

用CSS

img::after {
  content: attr(alt);
}
Run Code Online (Sandbox Code Playgroud)

是否可以为img使用CSS 输出替代文字?

请指出浏览器与您提供的任何解决方案兼容.

这是一个jsfiddle

css

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

我必须为TypeScript中的高阶函数类型指定参数名称吗?

试图使用TypeScript弄湿我的脚,但我一直遇到麻烦今天,一个旧功能浮出水面,并且作为练习,我很好奇是否可以将其转换为TypeScript。到目前为止,颈部已经完全疼痛。

declare type Ord = number | string;

// type signature for f sucks really bad
// (f: Ord => Ord => boolean) would be really nice, if possible
// but instead I have to give names (_) for the parameters? dumb
const arrayCompare = (f: (_: Ord) => (_: Ord) => boolean) => ([x,...xs]: Ord[]) => ([y,...ys]: Ord[]): boolean => {
  if (x === undefined && y === undefined)
    return true;
  else if …
Run Code Online (Sandbox Code Playgroud)

higher-order-functions typescript

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

是否有一种惯用的方法从PHP中的数组中获取可能未定义的键?

PHP人民,我已经厌倦了这样做

$value = isset($arr[$key]) ? $arr[$key] : null;
Run Code Online (Sandbox Code Playgroud)

或这个

$value = array_key_exists($key, $arr) ? $arr[$key] : null;
Run Code Online (Sandbox Code Playgroud)

不要没有人告诉我这样做

$arr   = array(1);
$key   = 5;
$value = $arr[$key];
// Notice: Undefined offset: 5
Run Code Online (Sandbox Code Playgroud)

我得了支气管炎.不是没有人有时间f'dat.


我想能做出一个功能......

function array_get(Array $arr, $key, $default=null) {
  return array_key_exists($key, $arr)
    ? $arr[$key]
    : $default
  ;
}
Run Code Online (Sandbox Code Playgroud)

但这是最好的(最惯用的)方式吗?

php arrays idioms

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

如何比较两个对象并获得它们差异的键值对?

我有两个对象:

1)

{A: 10, B: 20, C: 30}
Run Code Online (Sandbox Code Playgroud)

2)

{A: 10, B: 22, C: 30}
Run Code Online (Sandbox Code Playgroud)

你可以看到:除了一件事之外,几乎是平等的:关键B值是不同的.

我怎样才能进入我的someNewArr关键价值差异?

someNewArr:( {B: 22}我从第二个对象获取值)

我正在使用角度,我的意思是这样的:

    var compareTwoObjects = function(initialObj, editedObj) {
        var resultArr = [];
        angular.forEach(initialObj, function(firstObjEl, firstObjInd) {
            angular.forEach(editedObj, function(secondObjEl, secondObjInd) {
                if (firstObjEl.key === secondObjEl.key && firstObjEl.value !== secondObjEl.value){
                    resultArr.push({firstObjEl.key: secondObjEl.value});
                }
            })
        });
    });
Run Code Online (Sandbox Code Playgroud)

javascript arrays angularjs

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

为什么Firefox会出现语法错误,class是保留标识符?

在Firefox 43上使用以下代码打开名为index.html的文件会出现以下错误:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    "use strict";
    class RangeIterator {}
    </script>
    </head>
    <body>
    </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

我在控制台中看到以下错误:

SyntaxError: class is a reserved identifier
Run Code Online (Sandbox Code Playgroud)

知道我为什么会收到这个错误吗?

html javascript html5 ecmascript-6

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

是否可以使用JavaScript中的类型数组从4x Uint8转换为Uint32?

我在项目中做了一些按位操作,我想知道内置的类型数组是否会让我有些头疼,甚至可能会给我带来一点性能提升.

let bytes = [128, 129, 130, 131]
let uint32 = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]
//=> -2138996093
Run Code Online (Sandbox Code Playgroud)

我可以使用类型化数组来获得相同的答案吗?

// not actually working !
let uint8bytes = Uint8Array.from(bytes)
let uint32 = Uint32Array.from(uint8bytes)[0]
//=> ideally i'd get the same value as above: -2138996093
Run Code Online (Sandbox Code Playgroud)

问题:

我发现奇怪的是uint32上面的内容是否定的 - 显然不是很......没有签名,因为var的名字暗示......

如果我将二进制八位字节混合并解析它,我会得到免费的肯定答案

//         128          129          130          131
let bin = '10000000' + '10000001' + '10000010' + '10000011'
let uint32 = Number.parseInt(bin,2)

console.log(uint32)
// …
Run Code Online (Sandbox Code Playgroud)

javascript bit-manipulation bitwise-operators typed-arrays

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

打结的平等推理

我试图通过减少这个函数来包围Cont和callCC:

s0 = (flip runContT) return $  do
    (k, n) <- callCC $ \k -> let f x = k (f, x)
                             in  return (f, 0)
    lift $ print n
    if n < 3
        then k (n+1) >> return ()
        else return ()
Run Code Online (Sandbox Code Playgroud)

我设法达到了这一点:

s21 = runContT (let f x = ContT $ \_ -> cc (f, x) in ContT ($(f,0))) cc where
    cc = (\(k,n) -> let
        iff = if n < 3 then k (n+1) else ContT ($()) …
Run Code Online (Sandbox Code Playgroud)

monads continuations haskell lazy-evaluation tying-the-knot

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

如何在 PHP 中获取不存在文件的规范化路径(真实路径)?

脚本文件

$filename = realpath(sprintf("%s/%s", getcwd(), $argv[1]));
var_dump($filename);
Run Code Online (Sandbox Code Playgroud)

让我们尝试一些事情

[/foo/bar/bof] $ php script.php ../foo.txt
string(16) "/foo/bar/foo.txt"

[/foo/bar/bof] $ php script.php ../nonexistent.txt
bool(false)
Run Code Online (Sandbox Code Playgroud)

该死!realpath返回 false 因为文件不存在。

我想看到的../nonexistent.txt

string(24) "/foo/bar/nonexistent.txt"
Run Code Online (Sandbox Code Playgroud)

如何获取 PHP 中任何相对路径的规范化路径?

注意:我看到了一些有关解析符号链接路径的问题。这些问题的答案不适用于我的问题。

php path realpath canonicalization

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