Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / 1 - install chocolatey.cmd
Created December 30, 2016 06:50
windows + chocolatey = awesome
@echo off
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: Current permissions inadequate.
pause
exit 1
@cowboy
cowboy / mixin.js
Last active June 4, 2023 05:29
JavaScript ES6 - mixins with super
// This mixin might be used to extend a class with or without its
// own "foo" method
const mixin = Base => class extends Base {
foo() {
// Only call super.foo() if it exists!
if (super.foo) {
super.foo();
}
console.log('mixin');
@cowboy
cowboy / index.js
Created September 16, 2016 16:01
Webpack: build error converting a lib's ... spread operator to ES5?
// npm install && npm run build
// In output.js, spreadTest(...args) is converted to ES5
function spreadTest(...args) {
return args;
}
console.log(spreadTest(1, 2, 3));
// But the ...args inside of this lib's "audit" function is NOT converted to ES5
import 'react-axe';
@cowboy
cowboy / esnextbin.md
Last active March 25, 2021 03:57
esnextbin sketch
@cowboy
cowboy / esnextbin.md
Created August 25, 2016 23:48
esnextbin sketch
this.OnClickOutside = this.onClickOutside;
@cowboy
cowboy / objects-vs-tuples.js
Last active June 4, 2023 05:29
javascript / es2015: should functions returning multiple, separate values return an object or tuple (array)?
// This function returns 2 separate values via an object with 2 properties.
function returnTwoValuesObj(str) {
const length = str.length;
const hasSpaces = str.indexOf(' ') !== -1;
return {length, hasSpaces};
}
// This function returns 2 separate values via an array (effectively a tuple) with 2 items.
function returnTwoValuesTuple(str) {
const length = str.length;
@cowboy
cowboy / query.sql
Last active September 30, 2018 18:05
postgres sql query
-- This is the result I want:
--
-- foo | bar | description
-- -----+-----+-------------
-- 3 | 4 | two
-- 1 | 2 | four
-- 5 | 6 | five
--
-- Which I can get with this query, but can I do it
-- more simply?
@cowboy
cowboy / promise-batch-arrays.js
Created June 22, 2016 16:18
javascript / bluebird: promise batch arrays
import Promise from 'bluebird';
function getBatches(arr, length) {
let i = 0;
const result = [];
while (i < arr.length) {
result.push(arr.slice(i, i + length));
i += length;
}
return result;