Skip to content

Instantly share code, notes, and snippets.

View johnathan-sewell's full-sized avatar

Johnathan Sewell johnathan-sewell

  • BLAST
  • Copenhagen
View GitHub Profile
@johnathan-sewell
johnathan-sewell / jira-story-subtasks.js
Last active August 29, 2015 14:22
Jira Story Subtasks
//open "Quick Sub Tasks" dialog
document.getElementById('subtasks-link-link').click();
//slam in the template
var textArea = document.getElementById('tasks-code');
textArea.value = '- FE Implementation / issueType:"FE Sub-Task"' + '\u000A' +
'- FE PR / issueType:"FE Code Review"' + '\u000A' +
'- BE Implemenation / issueType:"BE Sub-Task"' + '\u000A' +
'- run db/schema changes past Fed / issueType:"Technical task"' + '\u000A' +
'- verify deploy instructions / issueType:"Technical task"' + '\u000A' +
@johnathan-sewell
johnathan-sewell / code-reviews.markdown
Last active August 29, 2015 14:14
Code review checklist
  • _.clone(options) passed in to a function - Is a simple clone correct / enough? Because nested objects and arrays will be copied by reference (underscore clone: Create a shallow-copied clone of the provided plain object. Any nested objects or arrays will be copied by reference, not duplicated.).

  • Escape all user entered content before rendering to template

  • If you need to pass a html entity into a template (like  ) use the unicode equivalent (\u2009) to avoid having to unescape it (and open up a potential vulnarability)

  • double escaping

    model.escape('name'); //template will *also* escape
@johnathan-sewell
johnathan-sewell / backbone-constructor.js
Created January 13, 2015 14:25
Backbone constructor for named objects when debugging
//replace initialize
initialize: function(attrs) {
//initialize here
},
//with
constructor: function User(attrs) {
Backbone.Model.apply(this, arguments);
//initialize here
},
@johnathan-sewell
johnathan-sewell / JS-tricks.js
Last active August 29, 2015 14:08
Interesting JavaScript tricks
/* Get an Array from arguments
arguments does not have a prototype link to Array.prototype, it's just array-like
(it has a length property). Use slice to get an array from arguments.
The slice() method returns a shallow copy of a portion of an array into a new array object.
arr.slice([begin[, end]])
*/
function duckCount() {
return Array.prototype.slice.call(arguments).filter(function(obj) {
@johnathan-sewell
johnathan-sewell / animated-charts
Last active August 29, 2015 14:08
Animated charts
http://www.fusioncharts.com/explore/energy-consumption-dashboard/
http://www.jchartfx.com/animations.aspx
http://dashingdemo.herokuapp.com/sample
https://demo.geckoboard.com/dashboards/028B79D4CECE70C9
https://demo.geckoboard.com/dashboards/3CE850BCB3EDF3A2
@johnathan-sewell
johnathan-sewell / osx-machine-setup.md
Last active October 3, 2017 06:52
OSX Machine Setup

OSX Machine Setup

Sublime Text 3

Setup a command line alias to 'sublime'

alias sublime='"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"'

Packages

@johnathan-sewell
johnathan-sewell / TypeError.js
Created May 21, 2014 19:19
Use TypeError when checking input parameter types
if (!options) {
throw new TypeError('options (object) is required');
}
if (!options.username || !_.isString(options.username)) {
throw new TypeError('options.username (string) is required');
}
@johnathan-sewell
johnathan-sewell / 0_reuse_code.js
Created May 21, 2014 14:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@johnathan-sewell
johnathan-sewell / Jasmine it in forEach.js
Created May 8, 2014 08:42
Dry Jasmine "it" blocks in forEach
describe('validation', function() {
['startDate', 'endDate'].forEach(function(key) {
it('expects ' + key + ' to be in ISO format', function() {
model.set(key, '2014-04-29T15:04:53.078Z');
expect(model.isValid()).toEqual(true);
model.set(key, '2014/04/29');
expect(model.isValid()).toEqual(false);
});
});
});
@johnathan-sewell
johnathan-sewell / pre_start_nodejs
Created April 29, 2014 12:51
OpenShift start script for Ghost
#!/bin/bash
echo "Exporting Node Environment (production)"
export NODE_ENV=production
# If there is a grunt file, run $ grunt prod
if [ -f "${OPENSHIFT_REPO_DIR}"/Gruntfile.js ]; then
(cd "${OPENSHIFT_REPO_DIR}"; node_modules/grunt-cli/bin/grunt prod)
fi