Skip to content

Instantly share code, notes, and snippets.

View jboxman's full-sized avatar

Jason Βoxman jboxman

View GitHub Profile
require 'chef/log'
keys = []
search(:node, "keys_ssh_host_rsa_public") do |node|
keys << node
end
Chef::Log.info keys.inspect
/*
Copyright (c) 2010, Jason Boxman <jasonb@edseek.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
@jboxman
jboxman / object_keys.js
Created February 20, 2016 16:48
Ways to return a new object with only specified keys
// Pure JavaScript
var keys = ['name', 'display_name', 'status', 'logo'],
o = {},
k;
while(k = keys.shift()) {o[k] = channel[k]}
@jboxman
jboxman / txt
Created August 16, 2016 02:41
long build
> react-slingshot@5.0.0 build /Users/jasonb/projects/lb-take-2
> babel-node tools/build.js && npm run open:dist
Generating minified bundle for production via Webpack. This will take a moment...
Webpack stats: Hash: 7e6d42bcd85a9382cecd
Version: webpack 1.13.1
Time: 73872ms
Asset Size Chunks Chunk Names
favicon.ico 1.41 kB [emitted]
flags.png 28.1 kB [emitted]
var rejectedPromise = Promise.reject(new Error('Whatever'));
const p = new Promise(
(fulfill, reject) => {
setTimeout(() => rejectedPromise.then(fulfill, reject), 1000);
}
);
p.then(value => console.log(value)).catch(console.log('rejected'));
@jboxman
jboxman / envs.js
Created May 29, 2017 00:12
Export config based upon process.env.NODE_ENV
// From: https://raw.githubusercontent.com/dozoisch/koa-react-full-example/master/config/config.js
const path = require('path');
const _ = require('lodash');
const env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const base = {
app: {
root: path.normalize(path.join(__dirname, '../')),
@jboxman
jboxman / example.js
Created May 29, 2017 00:26
Kyle Simpson's example for tagged template literals in ES6
// https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20%26%20beyond/ch2.md#tagged-template-literals
function foo(strings, ...values) {
console.log( strings );
console.log( values );
}
var desc = "awesome";
foo`Everything is ${desc}!`;
@jboxman
jboxman / codingame-descent.js
Created June 6, 2017 15:04
A solution to the descent codingame challenge
const test = require('tape');
const Random = require('random-js');
/*
Game Input
Within an infinite loop, read the heights of the mountains from the standard
input and print to the standard output the index of the mountain to shoot.
Input for one game turn
@jboxman
jboxman / addnMapReduce.js
Created June 12, 2017 15:45
Exercise from Kyle Simpson's Functional-Lite programming course
function addnMapReduce(...args) {
// Can do args.slice(1).reduce(..., args[0]) to skip num(0) no-op
return args.reduce((prev, cur) => () => add2(prev, cur), num(0))();
}
function num(number) {
return () => number;
}
function add2(fn1, fn2) {
@jboxman
jboxman / silent_gen.js
Last active June 25, 2017 12:57
silence console.log for a Promise in a test
function *silentLog(p) {
function restoreLog() {return console.log = logg, undefined;}
const logg = console.log;
console.log = function() {}
const [fulfill, reject] = yield;
p().then(fulfill, reject).then(restoreLog, restoreLog);
}
function withSilentLog(youPromised, handleFulfill = function() {}, handleReject = function() {}) {
const it = silentLog(youPromised);