This file contains hidden or 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
#!/bin/sh | |
# For example, to pass "foo" as argument 1: | |
# curl -sSL https://example.com/example.sh | sh -s -- foo | |
# For more details see: https://www.baeldung.com/linux/curl-fetched-script-arguments | |
echo "ARGUMENT 1: ${1}" |
This file contains hidden or 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 R from 'ramda'; | |
// Used for HTML form where you can select individual year, month and day from dropdowns | |
// Last 20 years in reverse order | |
const years: number[] = R.unfold( | |
(n: number) => n < new Date().getFullYear() - 20 || [n, n - 1], | |
new Date().getFullYear(), | |
); | |
// All the calendar months |
This file contains hidden or 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
#!/usr/bin/env sh | |
export BAR="living on the edge" | |
export FRED="be careful!" | |
eval "echo \"$(cat file_with_vars.txt)\"" |
This file contains hidden or 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<title>The most minimal valid HTML4 document</title> | |
<p>At least some other content than a title is required, no head or body</p> | |
</html> |
This file contains hidden or 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 { defineStep } = require('cucumber'); | |
const arity = require('util-arity'); | |
/** | |
* Wrap a step function so it is passed the `world` scope as the first argument. | |
* Allows writing step definitions in a "purer" more functional style without | |
* worry about what `this` is, which is especially annoying when calling functions | |
* from other functions. | |
* | |
* Internal helpers expect world as the first argument, which is fine when they're |
This file contains hidden or 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
/** | |
* Chain an arbitrary number of async functions so they are executed in | |
* sequence until the final one resolves, or one of them rejects. | |
* | |
* @param {...Function} fns - multiple async functions | |
* @return {Function} | |
*/ | |
function chain(...fns) { | |
if (fns.length === 0) throw new Error('chain: at least one argument required!'); | |
const fn = fns.shift(); |
This file contains hidden or 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
var foo = () => console.log(this); // foo() - `this` is undefined | |
var bar = function() { console.log(this) }; // bar() -`this` is window (in browser) | |
var fred = function() { console.log(arguments) }; // fred(1) - [1] | |
var dave = () => console.log(arguments); // dave(1) - Reference error, arguments is undefined! |
This file contains hidden or 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
/** | |
* You have 2 promises either of which may fail or succed. | |
* | |
* You want to run a handler after all have failed or succeeded and have access to the result of each promise. | |
* | |
* How? | |
*/ | |
const Promise = require('bluebird'); | |
var fail = n => new Promise((resolve, reject) => setTimeout(function() { reject('fail!') }, n*100)); |
This file contains hidden or 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 serializeObject($form) { | |
var counters = {}, | |
serialized = {}; | |
$form.serializeArray().forEach(function(input) { | |
// Split name into tokens, fixing numeric indexes where neccessary | |
var tokens = input.name.split('[').map(function(value) { | |
value = value.replace(']', ''); | |
if(value === '') { |