Skip to content

Instantly share code, notes, and snippets.

View jbreckmckye's full-sized avatar
🛸

Jimmy Breck-McKye jbreckmckye

🛸
View GitHub Profile
@jbreckmckye
jbreckmckye / Knockout foreachSorted
Last active August 29, 2015 14:07
Knockout simple sorted forEach
<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h4>Simple foreach</h4>
<ul data-bind="foreach: names">
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
@jbreckmckye
jbreckmckye / monads.markdown
Last active April 18, 2016 21:35
Old monad tutorial
layout title date comments categories
post
The gist of monads
2016-04-07 00:47:16 +0100
true
JavaScript
functional programming

Most monad tutorials are long, confusing, and ineffective. I cannot promise this one will be more clear, more interesting, or even more effective, but I can at least promise to make it brisk. You have nothing to lose by reading it.

var myFileName = 'commercial.js';
var fs = require('fs');
var input = fs.createReadStream(myFileName);
var text = '';
input.on('data', function (data) {
text += data;
});

What I am changing

This PR fixes a bug in the settings/motivations page:

image

Presently, it isn't possible to change the motivation more than once per page load. On the second change, we throw an exception:

vendors.min.js:9 Raven: Exception TypeError: Cannot convert undefined or null to object
'use strict';
module.exports = function compileJS(grunt) {
const babel = require('babel-core'),
Concat = require('concat-with-sourcemaps'),
config = grunt.config.get('tt'),
configHelper = require('../tt/config.js'),
fileSeparator = ';\n',
fs = require('fs'),
path = config.get('dir.public') + '/js',
@jbreckmckye
jbreckmckye / single-var.md
Created January 25, 2017 10:05
Get rid of that stupid single-var-declaration rule, once and for all

I don't like the single-var rule.

It annoys me for several reasons.

As a declaration grows, it becomes ambiguous

Here's a slice of code. What does it signify?

 peter: payPeter().toRob('paul'),
@jbreckmckye
jbreckmckye / AjaxTextureLoader.js
Created April 11, 2017 13:23
Loading THREE textures with onProgress events
const THREE = require('three');
function AjaxTextureLoader() {
/**
* Three's texture loader doesn't support onProgress events, because it uses image tags under the hood.
*
* A simple workaround is to AJAX the file into the cache with a FileLoader, then extract that into a
* texture with a separate TextureLoader call.
*/
@jbreckmckye
jbreckmckye / module.js
Created April 11, 2017 21:15
Self-instantiating module constructors
function Module(lodash, THREE, moment) {
this.thingy = stuff => lodash.zip(stuff, false);
this.majig = whatever => moment().format(whatever);
this.zxzzxz = blah => new THREE.TextureLoader().load(blah);
}
module.exports = new Module(
require('lodash'),
require('three'),
require('moment')
@jbreckmckye
jbreckmckye / selenium-js-example.js
Created April 19, 2017 09:20
Simple script to start up Chrome with Selenium, run an operation, take a screenshot and exit
const fs = require('fs');
const selenium = require('selenium-standalone');
const webdriver = require('webdriverio');
installSelenium()
.then(startSelenium)
.then(runTest)
.then(stopSelenium);
function installSelenium() {