Skip to content

Instantly share code, notes, and snippets.

View karlhorky's full-sized avatar

Karl Horky karlhorky

View GitHub Profile
@karlhorky
karlhorky / reduce.js
Created June 1, 2016 14:26
JavaScript: Produce new array from .reduce(), with map- and filter-like transformation in one step.
// Produce new array from .reduce(), with map- and filter-like transformation in one step.
// Example data courtesy of http://elijahmanor.com/reducing-filter-and-map-down-to-reduce/
const doctors = [
{ number: 1, actor: "William Hartnell", begin: 1963, end: 1966 },
{ number: 2, actor: "Patrick Troughton", begin: 1966, end: 1969 },
{ number: 3, actor: "Jon Pertwee", begin: 1970, end: 1974 },
{ number: 4, actor: "Tom Baker", begin: 1974, end: 1981 },
{ number: 5, actor: "Peter Davison", begin: 1982, end: 1984 },
{ number: 6, actor: "Colin Baker", begin: 1984, end: 1986 },
function getOrderDetails(orderID) {
return db.find( "orders", orderID ).then(order =>
db.find( "customers", order.customerID ).then(customer => ({order, customer}))
).then(({order, customer}) =>
Object.assign(order, {customer})
);
}
getOrderDetails( 1234 )
.then( displayOrder, showError );
@karlhorky
karlhorky / camelcase-constants.md
Created March 9, 2016 15:27
Use camelCase for ES2015 constants

Some links why to use camelCase for constants:

// Bad
const SERVICE_URL = 'https://www.example.com';

// Good
const serviceUrl = 'https://www.example.com';
@karlhorky
karlhorky / index.js
Created February 22, 2016 14:53 — forked from royriojas/index.js
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Rebuild to run it on the right
var esformatter = require( 'esformatter' );
var esformatterJSX = require( 'esformatter-jsx' );
//var collapser = require( 'esformatter-collapse-objects' )
var throttle = require( 'lodash.throttle' );
var hash = window.location.hash.substr( 1 );
var extend = require('extend');
var params;
@karlhorky
karlhorky / angular-mocks-ava-a-failing.js
Last active July 15, 2016 05:47
Concurrent Test Failures with AVA and angular-mocks
// Failing case
// Concurrent test runs
import test from 'ava';
import jsdom from 'jsdom';
// Angular dependencies
global.document = jsdom.jsdom('<!doctype html><html ng-app="app"><head><meta charset="utf-8"></head><body></body></html>');
global.window = document.defaultView;
global.Node = global.window.Node;
@karlhorky
karlhorky / include_when.twig
Last active February 4, 2016 07:47
Demo of potential include_when Twig tag
{% include_when {
'config.azubiTabs': 'azubi-tabs.twig'
} %}
{% include_when {
'config.footerUs': 'layouts/footer-us.twig',
default : 'layouts/footer.twig'
} %}
@karlhorky
karlhorky / channel_v3.json
Created January 4, 2016 12:23
Sublime Text Package Control Channel JSON (backup from live system on Jan 4, 2016)
This file has been truncated, but you can view the full file.
{"schema_version": "3.0.0", "repositories": ["https://bitbucket.org/jjones028/p4sublime/raw/tip/packages.json", "https://bitbucket.org/klorenz/sublime_packages/raw/tip/packages.json", "https://csch1.triangulum.uberspace.de/release/packages.json", "https://packagecontrol.io/packages_2.json", "https://packagecontrol.io/repository.json", "https://raw.githubusercontent.com/20Tauri/DoxyDoxygen/master/DoxyDoxygen.json", "https://raw.githubusercontent.com/Andr3as/Sublime-SurroundWith/master/packages.json", "https://raw.githubusercontent.com/AutoIt/SublimeAutoItScript/master/packages.json", "https://raw.githubusercontent.com/FichteFoll/sublime_packages/master/package_control.json", "https://raw.githubusercontent.com/Floobits/floobits-sublime/master/packages.json", "https://raw.githubusercontent.com/Harrison-M/indent.txt-sublime/master/packages.json", "https://raw.githubusercontent.com/Hexenon/FoxCode/master/packages.json", "https://raw.githubusercontent.com/Kaizhi/SublimeUpdater/master/packages.json", "https://raw.gi
@karlhorky
karlhorky / channel_v3.json
Last active March 25, 2019 12:31
Sublime Text Package Control Channel JSON (from Internet Archive's backup on Jan 3, 2016)
{"dependencies_cache": {"https://packagecontrol.io/repository.json": [{"name": "python-jinja2", "description": "Python Jinja2 module", "load_order": "51", "releases": [{"sublime_text": "*", "platforms": ["*"], "url": "https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-jinja2/get/2.8.0.zip", "version": "2.8.0"}], "authors": ["teddy_beer_maniac"], "issues": "https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-jinja2/issues"}, {"name": "pyyaml", "description": "Python PyYAML module", "load_order": "50", "releases": [{"sublime_text": "*", "platforms": ["*"], "url": "https://codeload.github.com/packagecontrol/pyyaml/zip/v3.11.0", "version": "3.11.0"}], "authors": ["FichteFoll"], "issues": "https://github.com/packagecontrol/pyyaml/issues"}, {"name": "lxml", "description": "lxml", "load_order": "10", "releases": [{"sublime_text": ">=3000", "platforms": ["osx-x64", "linux-x64", "windows-x64"], "url": "https://codeload.github.com/eerohele/sublime-lxml/zip/0.2.0", "version": "0.2.0"}], "authors
@karlhorky
karlhorky / github_comment_on_commit.py
Created November 21, 2015 08:50 — forked from rmcgibbo/github_comment_on_commit.py
Jenkins setup to automatically comment on github commits with build status
// Using the Jenkins Groovy Post build plugin to execute the following after every build
// https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
// It would be nice not to have to specify these here... the repo name should be available within the hudson
// api somehow, but I didn't know how to get it. The access token should maybe be saved in a config file, and
// read in at runtime?
GITHUB_REPO_NAME = 'myusername/myreponame'
GITHUB_ACCESS_TOKEN = 'my_github_api_v3_access_token'
@karlhorky
karlhorky / install-xcode-command-line-tools.sh
Created November 20, 2015 19:24
Install the Command Line Tools completely from the command line
# Ref http://apple.stackexchange.com/questions/107307/how-can-i-install-the-command-line-tools-completely-from-the-command-line/195963#195963
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
PROD=$(softwareupdate -l |
grep "\*.*Command Line" |
head -n 1 | awk -F"*" '{print $2}' |
sed -e 's/^ *//' |
tr -d '\n')
softwareupdate -i "$PROD" -v;