Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am connesc on github.
  • I am connesc (https://keybase.io/connesc) on keybase.
  • I have a public key whose fingerprint is AB79 B69B AD7D 2E99 3454 279E 3A34 111B 0314 5582

To claim this, I am signing this object:

@connesc
connesc / window.jq
Last active December 8, 2022 22:39
A window function for jq
# Context and benchmarks are available here: https://github.com/stedolan/jq/issues/1577#issuecomment-355756466
def window(values; $size; $step):
def checkparam(name; value): if (value | isnormal) and value > 0 and (value | floor) == value then . else error("window \(name) must be a positive integer") end;
checkparam("size"; $size)
| checkparam("step"; $step)
# We need to detect the end of the loop in order to produce the terminal partial group (if any).
# For that purpose, we introduce an artificial null sentinel, and wrap the input values into singleton arrays in order to distinguish them.
| foreach ((values | [.]), null) as $item (
{index: -1, items: [], ready: false};
@connesc
connesc / README.md
Last active August 29, 2015 14:23
Asynchronous promise handling with Bluebird

Asynchronous promise handling with Bluebird

This Gist serve as an illustration for a Stack Overflow thread. It contains a real situation, where a Bluebird promise needs to receive its handler asynchronously.

Context

The goal is to launch a long process, which writes a preview to stdout upon startup. The launchProcess() function should launch the process and return once the preview has been read. In particular, it should not wait for the completion of the process.

As an example, you would could think to a large file download (written to the disk), with the HTTP headers written to stdout as soon as they are received.

@connesc
connesc / pre-commit
Last active August 29, 2015 14:21
Git pre-commit hook for launching a test suite
#!/bin/sh
# Clean the working tree if needed
before="$(git rev-parse --verify --quiet refs/stash)"
git stash save --keep-index --include-untracked --quiet 'Git pre-commit hook'
after="$(git rev-parse --verify --quiet refs/stash)"
# Run tests
grunt jshint
status=$?