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
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',
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) {
  1. Chicken
  2. Cows
  3. Sheep
  1. Egg
  2. Milk
  3. Wool
@alisdair
alisdair / invisible_proxy.rb
Created August 31, 2012 08:29
Invisible proxy example for Ruby
class FlatArray
instance_methods.each do |m|
undef_method(m) unless m =~ /(^__|^nil\?|^send$|^object_id$)/
end
def initialize(array)
@target = array
end
def respond_to?(symbol, include_priv=false)
@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 / another-component.component.js
Last active August 29, 2016 12:32
Assertion Failed: A helper named "example.edit" could not be found
import Ember from 'ember';
export default Ember.Component.extend({
});
@alisdair
alisdair / components.link-href.js
Last active January 26, 2017 10:03
Disabling links prototype
@alisdair
alisdair / .vimrc
Created July 4, 2017 13:17
Basic vimrc
call plug#begin()
Plug 'ctrlpvim/ctrlp.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'elixir-lang/vim-elixir'
Plug 'ervandew/supertab'
Plug 'joukevandermaas/vim-ember-hbs'
Plug 'leafgarland/typescript-vim'
Plug 'pangloss/vim-javascript'
Plug 'tomasr/molokai'
Plug 'tpope/vim-commentary'
@alisdair
alisdair / fake-statsd.rb
Created July 28, 2017 18:33
It's a statsd! Kind of!
#!/usr/bin/env ruby
require 'socket'
require 'optparse'
port = 8125
pattern = /./
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
@alisdair
alisdair / controllers.application.js
Last active September 27, 2017 14:22
Reject vs Catch: Failures and Exceptions Part 1
import Ember from 'ember';
const { RSVP } = Ember;
const success = (time) => new RSVP.Promise((resolve) => setTimeout(resolve, time));
const failure = (time) => new RSVP.Promise((_, reject) => setTimeout(reject, time));
export default Ember.Controller.extend({
logs: ['Initialized'],