Skip to content

Instantly share code, notes, and snippets.

Jim Newbery froots

Block or report user

Report or block froots

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@froots
froots / .travis.yml
Created Oct 6, 2016
PhantomJS 2 install hack for Travis
View .travis.yml
before_install:
- "export PHANTOMJS_VERSION=2.1.1"
- "phantomjs --version"
- "export PATH=$PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin:$PATH"
- "phantomjs --version"
- "if [ $(phantomjs --version) != '$PHANTOMJS_VERSION' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi"
- "if [ $(phantomjs --version) != '$PHANTOMJS_VERSION' ]; then wget https://github.com/Medium/phantomjs/releases/download/v$PHANTOMJS_VERSION/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2; fi"
- "if [ $(phantomjs --version) != '$PHANTOMJS_VERSION' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi"
- "phantomjs --version"
@froots
froots / vector.js
Last active Oct 5, 2016
Stubbing Math.random()
View vector.js
export function random(vmin, vmax) {
return [
vmin[0] + Math.random() * (vmax[0] - vmin[0]),
vmin[1] + Math.random() * (vmax[1] - vmin[1])
];
}
@froots
froots / Car.js
Last active Jun 6, 2018
Stubbing module dependencies in ES2015 unit tests using Sinon.js or TestDouble.js.
View Car.js
// in /src directory
import {kphToMph} from './convert';
class Car {
constructor(speed) {
this.speed = speed;
}
getSpeedInMph() {
@froots
froots / UK Filco Majestouch-2 Tenkeyless.keylayout
Created May 23, 2014
Filco Majestouch 2 tenkeyless UK OS X keyboard layout
View UK Filco Majestouch-2 Tenkeyless.keylayout
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Created by Ukelele version 2.2.7 on 2014-01-18 at 17:44 (GMT)-->
<!--Last edited by Ukelele version 2.2.7 on 2014-01-18 at 17:59 (GMT)-->
<keyboard group="0" id="9190" name="UK Filco Majestouch-2 Tenkeyless" maxout="1">
<layouts>
<layout first="0" last="17" modifiers="30" mapSet="a8"/>
</layouts>
<modifierMap id="30" defaultIndex="7">
<keyMapSelect mapIndex="0">
View gist:9410296

Keybase proof

I hereby claim:

  • I am froots on github.
  • I am froots (https://keybase.io/froots) on keybase.
  • I have a public key whose fingerprint is 8C86 3E94 ECF6 E978 9020 18FD 8E09 E8E2 E366 3297

To claim this, I am signing this object:

@froots
froots / example.js
Created Nov 1, 2012
console.log during an Underscore.js chain()
View example.js
_.chain(myData)
.flatten()
.log()
.reverse()
.log()
.filter(function(item) { return item.active; })
.value();
@froots
froots / test.js
Created Oct 17, 2012
Example of desired behaviour of SinonJS onlyWithArgs() method
View test.js
beforeEach(function() {
global.fs = require('fs');
sinon.stub(fs, 'readFileSync').onlyWithArgs('my-file.txt').returns('Contents of file');
// Then require the module under test, which uses fs.readFileSync() internally
// require() uses original method with correct calling context
global.myModule = require('../src/my-module');
});
it('does something with the file', function() {
@froots
froots / gist:3164377
Created Jul 23, 2012 — forked from danscotton/gist:3164353
mocking with amd
View gist:3164377
// ----------------------------------------
// /path/to/dependency.js
define(function() {
return {
doSomethingWithIt: function() {
// blah
}
};
});
@froots
froots / example-spec.js
Created Jul 23, 2012
Require.js and Jasmine
View example-spec.js
define([
"modules/todo",
"modules/todos"
], function(Todo, Todos) {
describe("Todo", function() {
it("should set an attribute", function() {
var todo = new Todo({ title: "Do washing" });
expect(todo.get("title")).toEqual("Do washing");
});
View image_replacer.js
if (typeof (AC) === "undefined") {
AC = {}
}
AC.ImageReplacer = Class.create({
_defaultOptions: {
listenToSwapView: true,
filenameRegex: /(.*)(\.[a-z]{3}($|#.*|\?.*))/i,
filenameInsert: "_☃x",
ignoreCheck: /(^http:\/\/movies\.apple\.com\/|\/105\/|\/global\/elements\/quicktime\/|_(([2-9]|[1-9][0-9]+)x|nohires)(\.[a-z]{3})($|#.*|\?.*))/i,
attribute: "data-hires",
You can’t perform that action at this time.