Skip to content

Instantly share code, notes, and snippets.

View jbailey4's full-sized avatar

Joshua Bailey jbailey4

View GitHub Profile
@jbailey4
jbailey4 / controllers.application.js
Last active August 3, 2018 17:55
json.parse ember array
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
arraySet: Ember.A([
{
name: 'foo',
childArray: Ember.A([
{ name: 'bar' },
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'a',
click() {
const selectedValue = Ember.get(this, 'selectedValue') || Ember.get(this, 'title');
this.onClick(selectedValue);
}
@jbailey4
jbailey4 / application.hbs
Last active December 16, 2015 03:46
Ember: Dynamically create/update props using only handlebar helpers
{{!--
Notice the onchange event binding
1. the get helper grabs the prop to change
2. the mut helper provides an interface to update that prop
3. the action helper packages up that interface into a callable function, which will update the prop
4. the callable function is invoked when the input changes and is passed the input's current value as the first argument, which is then used to set the prop
a. we obtain the input's current value by destructing the native Event object which is passed as an argument to the action helper, value="currentTarget.value" basically means Event.currentTarget.value
--}}
@jbailey4
jbailey4 / gist:e179b4167a4aa28b1738
Created January 5, 2015 01:45
ES6 average function
function average(...args) {
var sum = args.reduce((x, y) => x + y, 0);
return sum / args.length;
}
@jbailey4
jbailey4 / gist:a520b3df2d2ed8cce284
Created November 5, 2014 11:38
Reduce an array to its largest or smallest value, using Array.prototype.reduce
// silly method, just learning the reduce method
function findBigOrSmall (a, l) {
return a.reduce(function (x, y) {
return l ? x > y ? x : y : x > y ? x : y;
});
};
@jbailey4
jbailey4 / console.time
Last active August 29, 2015 14:02
Track how long (in milliseconds) a Javascript block takes to execute - using Chrome's console
// paste this in your Chrome's console to try it out, could be useful
// big loop
console.time( 'big-loop' );
var arrBig = [];
for ( var i = 0; i < 1000; i++ )
arrBig.push( i );
console.timeEnd( 'big-loop' );