Skip to content

Instantly share code, notes, and snippets.

View plrenaudin's full-sized avatar

Pierre-Louis Renaudin plrenaudin

  • Ireland (Remote)
View GitHub Profile
@plrenaudin
plrenaudin / flatten.test.js
Created May 11, 2019 12:05
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
/**
* Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
* @param {Array} arr The array of arbitrarily nested arrays of integers
* @returns {Array[number]} Flat array of integers
*/
const flatten = (arr = []) =>
arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val)), []);
it("works with no input", () => {
expect(flatten()).toEqual([]);
@plrenaudin
plrenaudin / gist:29b0b2dea2a5afae7cb4c5d508523ed1
Created January 31, 2017 12:20
Fish shell prompt variation with git support
// See https://geraldkaszuba.com/tweaking-fish-shell/ for git branch support
function git_branch
set -g git_branch (git rev-parse --abbrev-ref HEAD ^ /dev/null)
if [ $status -ne 0 ]
set -ge git_branch
set -g git_dirty_count 0
else
set -g git_dirty_count (git status --porcelain | wc -l | sed "s/ //g")
end
end
@plrenaudin
plrenaudin / spec
Created July 8, 2015 21:06
scorer spec
it "returns the result in order", ->
candidates = [
'Find And Replace: Selet All',
'Settings View: Uninstall Packages',
'Application: Install Update',
'install'
]
result = filter(candidates, 'install')
expect(result[0]).toBe candidates[3]
expect(result[1]).toBe candidates[2]