Skip to content

Instantly share code, notes, and snippets.

View kalyco's full-sized avatar

Kayla Comalli kalyco

  • 6 River Systems
  • Boston, MA
View GitHub Profile
@kalyco
kalyco / ember order of operations
Created June 9, 2015 17:55
Ember's order of operations
1. User hits a URL
2. Ember's Router recognizes it and passes it to a Route object
3. The Route sets up a Controller and supplies it with a Model
4. The Model provides the View layer (represented by a Template) access to the data
5. Any properties defined by the Model are available to the Controller
ex: if User has first_name, your template has direct access to it through the Controller
*** don't need to define an empty controller method like in Rails ***
*** Ember will also generate the controller for you if one does not exist ***
@kalyco
kalyco / ember event response
Last active August 29, 2015 14:22
Binds the field to a property in the controller and lets Ember handle keeping things updated. In this example a controller is set up with 2 properties 'number' and 'timesTwo'
// in the controller
App.NumberController = Ember.ObjectController.extend({
number: 1,
timesTwo: function() {
return Number(this.get('number')) * 2;
}.property('number') //tells it to treat it as a dynamic property that updates whenever number updates.
});
//in the template
{{input type="text" value=number size=50}} x2 = {{timesTwo}}
@kalyco
kalyco / ember view
Created June 9, 2015 16:05
View main function: 1. Creating reusable components. 2. Setting up logic to handle events
App.ProfilePhotoView = Ember.View.extend({
click: function(evt) {
this.get('controller').send('ExpandProfilePhoto');
}
});
App.UserController = Ember.ObjectController.extend({
actions: {
expandProfilePhoto: function() {
//get the expanded picture and display it
@kalyco
kalyco / ember controller
Created June 9, 2015 15:26
ember controllers are different from rails controllers in that their primary function is to provide the logic to access data from the model. In this example, the user has different first_name, last_name properties, but wants to show a full name. This is something that a controller would be used for.
App.UserController = Ember.Object.Controller.extend({
fullName: function() {
return this.get("first_name") + " " + this.get("last_name");
}
})
@kalyco
kalyco / ember model hook
Created June 9, 2015 14:03
In ember first create the route object, then use the model hook to get the data you need from it.
App.UserRoute = Ember.Route.extend({
model: function(params) {
return this.store.find(user, params.user_id);
}
)};
@kalyco
kalyco / dijkstra.rb
Last active August 29, 2015 14:20 — forked from yaraki/dijkstra.rb
#!/usr/bin/ruby1.9.1 -Kw
# -*- coding: utf-8 -*-
class Edge
attr_accessor :src, :dst, :length
def initialize(src, dst, length = 1)
@src = src
@dst = dst
@length = length
@kalyco
kalyco / deaf_grandma
Created November 20, 2014 23:33
Deaf Grandma
puts 'SONNY..? IS THAT YOU..?'
input1 = ''
bye_count = 0
while bye_count < 3
input1 = gets.chomp
if input1 == 'BYE'
bye_count += 1
puts 'NO. NOT SINCE '+(rand(1920..1956)).to_s
elsif input1.upcase == input1
puts puts 'NO. NOT SINCE '+(rand(1920..1956)).to_s