Skip to content

Instantly share code, notes, and snippets.

View poteto's full-sized avatar
🥔
ポテト

lauren poteto

🥔
ポテト
View GitHub Profile
#Refer: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem#Delaying_only_some_traffic
#Refer: http://www.bomisofmab.com/blog/?p=100
#Refer: http://drija.com/linux/41983/simulating-a-low-bandwidth-high-latency-network-connection-on-linux/
#Setup the rate control and delay
sudo tc qdisc add dev lo root handle 1: htb default 12
sudo tc class add dev lo parent 1:1 classid 1:12 htb rate 56kbps ceil 128kbps
sudo tc qdisc add dev lo parent 1:12 netem delay 200ms
#Remove the rate control/delay
sudo tc qdisc del dev lo root
speechSynthesis.getVoices().forEach(function(voice) {
var name = voice.name,
speech = new SpeechSynthesisUtterance("Hello, my name is " + name);
speech.voice = voice;
speechSynthesis.speak(speech);
});
// Ideally you would set up a flash message service as a dependency injection
// (which can be a little involved), but here's a quick hack
// P.S. this was transpiled down from CoffeeScript, so it might look a bit funky
App.Post = DS.Model.extend({
errorMessages: Em.A([]),
didBecomeDirty: Em.observer('isDirty', function() {
return Em.run.debounce(this, '_handleSave', 500, true);
}),
_handleSave: function() {
@poteto
poteto / computed-properties.js
Last active August 29, 2015 14:09
Slack-like loading messages in an Ember app
var computed;
App.computed = {};
computed = Ember.computed;
App.computed.sample = function(dependentKey) {
return (computed("" + dependentKey + ".@each", function() {
var items, length;
items = this.getWithDefault(dependentKey, Em.A([]));
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['range-slider'],
value: 0,
attributeBindings: ['data-slider'],
'data-slider': 0,
valueDidChange: Em.observer('value', function(){
import Ember from 'ember';
export default Ember.Mixin.create({
scrollTimeout: 100,
boundingClientRect: 0,
windowHeight: 0,
windowWidth: 0,
enteredViewport: Ember.computed('boundingClientRect', 'windowHeight', 'windowWidth', function() {
var rect, windowHeight, windowWidth;
scrollTimeout: 100,
boundingClientRect: 0,
windowHeight: 0,
windowWidth: 0,
_updateBoundingClientRect: function() {
var el;
el = this.$()[0];
this.set('boundingClientRect', el.getBoundingClientRect());
},
_scrollHandler: function() {
return Ember.run.debounce(this, '_updateBoundingClientRect', this.get('scrollTimeout'));
},
_bindScroll: (function() {
var scrollHandler;
scrollHandler = this._scrollHandler.bind(this);
Ember.$(document).on('touchmove.scrollable', scrollHandler);
Ember.$(window).on('scroll.scrollable', scrollHandler);
}).on('didInsertElement'),
enteredViewport: Ember.computed('boundingClientRect', 'windowHeight', 'windowWidth', function() {
var rect, windowHeight, windowWidth;
rect = this.get('boundingClientRect');
windowHeight = this.get('windowHeight');
windowWidth = this.get('windowWidth');
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= windowHeight &&
rect.right <= windowWidth
import Ember from 'ember';
var {
computed,
get,
set,
getWithDefault,
run
} = Ember;