Skip to content

Instantly share code, notes, and snippets.

View alisdair's full-sized avatar
🏋️‍♂️
I'm probably snatching right now

Alisdair McDiarmid alisdair

🏋️‍♂️
I'm probably snatching right now
View GitHub Profile
@alisdair
alisdair / controllers.application.js
Last active August 14, 2016 15:12
Eggs & Milk Minder 0.1
import Ember from 'ember';
const { Controller, computed } = Ember;
export default Controller.extend({
total: computed('model.eggs', 'model.milk', function() {
return this.get('model.eggs') + this.get('model.milk');
})
});
@alisdair
alisdair / duration-parser.js
Last active March 7, 2018 17:33
Natural language duration parser
const units = [
{
names: ['day', 'dy', 'd'],
seconds: 86400
}, {
names: ['hour', 'hr', 'h'],
seconds: 3600
}, {
names: ['minute', 'min', 'm'],
seconds: 60
import Ember from 'ember';
import Duration from 'app/utils/duration';
const { computed, run } = Ember;
export default Ember.Component.extend({
classNames: ['panel'],
classNameBindings: ['isEditing::clickable'],
keyDown(event) {
import Ember from 'ember';
function clamp(min, max, number) {
return Math.min(Math.max(number, min), max);
}
const clampPercent = clamp.bind(undefined, 0, 100);
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
@alisdair
alisdair / components.spotify-song.js
Created April 17, 2016 15:44
Test stub for component -> helper -> service
import Ember from 'ember';
export default Ember.Component.extend({
});
// Generates a function which returns a random element of xs, where the same
// input value always returns the same element.
//
// Useful in situations like test data factories, where you want to choose a
// random element from a list of fake test data, but the same input integer
// should return the same value every time.
export default function(xs) {
var memo = {};
return function (i) {
@alisdair
alisdair / jsbin.tenig.css
Last active August 29, 2015 13:56
Ember.js: simple regexp-based validation component
* {
box-sizing: border-box;
}
form {
padding: 10px;
max-width: 400px;
}
.input {
margin: 0 0 10px 0;
position: relative;
  1. Chicken
  2. Cows
  3. Sheep
  1. Egg
  2. Milk
  3. Wool
@alisdair
alisdair / jquery.wraplines.js
Created August 14, 2013 15:02
jQuery wraplines plugin Copyright (c) 2010 Paul Bennett (http://pmbennett.net) Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
/*
* jQuery wraplines plugin
*
* Copyright (c) 2010 Paul Bennett (http://pmbennett.net)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
jQuery.fn.wraplines = function(options) {
@alisdair
alisdair / kill-sticky.js
Created May 29, 2013 13:43
Kill sticky headers.
(function () {
var i, elements = document.querySelectorAll('body *');
for (i = 0; i < elements.length; i++) {
if (getComputedStyle(elements[i]).position === 'fixed') {
elements[i].parentNode.removeChild(elements[i]);
}
}
})();