This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// transformations as an array of arrow functions | |
// example for transformations of an array, in this case [1,2,3] | |
const pipeline = [ | |
// transformation functions here | |
array => { array.pop(); return array; }, | |
array => array.reverse() | |
]; | |
pipeline.reduce((xs, f) => f(xs), [1, 2, 3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example: "kjzskjkjk" 3 => [ "kjz", "jzs", "zsk", "skj" ] | |
function justUniqueVals(arr) { | |
return arr.filter((item, index, self) => self.indexOf(item) == index); | |
// not performant for long arrays!!! use occurences hashmap instead | |
} | |
function hasUniqueVals(arr) { | |
const filtered = justUniqueVals(arr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
export PS1="\u@\[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$ " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitArrayInArraysBySection (arr) { | |
const returnsObject = arr.reduce((newArrSofar, item) => { | |
const toAdd = newArrSofar[item.section] ? [...newArrSofar[item.section], item] : [item] | |
return { | |
...newArrSofar, | |
[item.section]: toAdd | |
} | |
},{}); | |
return Object.values(returnsObject); // to return array actually | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment'); | |
const dateFromElastic = 1521806390519; | |
let dateUTC = moment.utc(dateFromElastic).format('YYYY-MM-DD HH:mm'); | |
// for interface display | |
let dateLocal = moment.utc(dateUTC).local().format('YYYY-MM-DD HH:mm'); | |
// for timeFilter to use as query | |
let dateBackToUTC = moment(dateLocal).utc().format('YYYY-MM-DD HH:mm'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDuration(startTime: Date, endTime: Date): string { | |
const milliseconds = moment(endTime).diff(startTime); | |
const duration = moment.duration(milliseconds); | |
const durationAsHours: number = Math.floor(duration.asHours()); | |
const restInMinutes: number = duration.minutes(); | |
const hours: string = | |
durationAsHours > 1 | |
? `${durationAsHours} hours and ` | |
: durationAsHours > 0 | |
? `${durationAsHours} hour and ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { Helmet } from 'react-helmet'; | |
import { Maybe } from 'tsmonad'; | |
export { | |
ReactFontFace as OurReactFontFace | |
}; | |
interface Config { | |
readonly google?: ReadonlyArray<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
input = "+15 -7 +16 +5 +12 +16 -4 +10 -1 +14 -16 +6 +4 +11 -2 +5 +4 +12 +13 +5 +16 +18 -3 -2 +9 -10 +12 -10 -17 +12 -14 -14 +11 +1 -16 +11 -5 +20 -1 +14 -15 -10 -5 +4 -17 -13 -2 -12 -15 +12 +8 -3 +13 +17 +21 +21 +8 +9 -5 -15 -19 -9 -17 -5 +15 +12 +14 +19 -2 +15 -6 +19 -2 +4 -5 -8 -4 +10 +1 -5 +10 +12 +14 -2 +11 -3 -15 -6 +14 +3 +8 +10 +14 +11 +18 +3 -4 -5 -13 +17 -12 -8 -5 +7 +7 -10 -19 +17 +1 +17 -5 -9 -10 -9 -1 -3 -14 +11 +1 +11 +1 +2 -17 +4 +19 +17 +6 +18 -4 +3 -13 +7 -3 +19 +5 +2 +6 +12 +5 -7 +10 +16 -9 -16 +11 +10 +2 +7 -16 +6 +16 +17 +11 +11 -14 +11 -16 -13 +6 +8 +10 -4 -5 +2 +5 -18 +19 -11 -5 -5 -5 -16 -5 +16 +7 -10 -20 -14 -18 +13 +9 -10 +18 -7 -8 -4 +13 +9 +18 +20 -10 -14 -22 -21 -10 +20 -7 -9 +1 +11 +6 +12 +14 -5 +16 +13 +8 -2 -13 -2 +11 +21 +9 -5 +1 +18 +6 +18 -17 +3 +7 -2 -3 +1 +7 +17 +16 +4 +13 +7 +17 -18 +17 +2 +19 -11 +2 +2 +1 -16 -19 -4 -17 -8 -5 +12 -8 +19 +3 +17 +3 +3 +8 +3 -13 +12 -7 +9 +16 +15 +3 -6 -10 +14 -13 -8 +4 +12 +19 +17 +18 -12 -11 +7 -1 -7 -28 -19 -6 +2 +15 +3 -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isMatchingBrackets(str) { | |
let stack = []; | |
const map = { | |
'(': ')', | |
'[': ']', | |
'{': '}' | |
}; | |
let answer = false; | |
for (let c of [...str]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transformer word = | |
String.toLower word | |
|> String.split " " | |
|> String.join "" | |
|> String.filter (\char -> char /= ',') | |
palindrome w = transformer w == (String.reverse <| transformer w) | |
isPalindrome = if palindrome "As I pee sir, I see Pisa " == True then "PALINDROME" else "NOT PALINDROME" |