Skip to content

Instantly share code, notes, and snippets.

View blake41's full-sized avatar

Blake Johnson blake41

  • http://blakejohnson.brandyourself.com/
View GitHub Profile
class User < ActiveRecord::Base
after_save :some_method, :on => :update
after_save :always
def some_method
puts "i only fire on update"
binding.pry
end
def always
big 0
data structures
algorithms
http://bigocheatsheet.com/
how does Computer memory actually work
when we allocate an array in ruby, it decides to use 5 “spaces” of memory
draw what this looks like
if we use less than this, it’s wasted, but on average we’ve found this is the most efficient
when we add the 6th element, we have to copy the whole array and double its size
JSON
[{
"title": "my products title",
"description": "this is a blob of html usually created by a WYSIWYG",
"vendor_id": "you can hard code this once we create you in the system",
"flavors": [
"chocolate",
"orange"
],
"image": "some url with an image",
  • what are the common problems backbone didn’t solve?
    • no data binding by default, no two way data binding by default
    • How do you render Views? - By default, Backbone's render method does nothing. To use it, you need to fill in your own rendering function. That could use a templating system like Underscore templates or Handlebars, jQuery manipulation of the DOM, or simple string inserts with .innerHTML(). You could use the same method for every View, or mix it up and use different methods for different Views.
    • How do you manage relationships between objects? - By default Backbone provides a way to manage sets of Models as a Collection, but it doesn't have any built-in utilities for handling nested Models or Collections. And if you want to nest your Views you're completely on your own. You can have a View manage it's child Views, have a single object that manages all Views, or let each View manage itself.
  • How do your Views communicate between each other? - Views will often need to communicate with

What are the core components of the JSMV* frameworks

  • Data Binding between HTML and a client-side JavaScript object model *backbone has no data binding
    • two way(everyone else)
  • View Templates
    • declarative DOM based (angular) *so here we’re decorating the DOM language itself
  • string templating based (underscore, mustache, handlebars)
def get_a_number(line)
if count = line.instance_variable_get("@count")
line.instance_variable_set("@count", count += 1)
else
line.instance_variable_set("@count", 1)
count = 1
end
line << count
count
end
@blake41
blake41 / app.js
Last active November 18, 2015 22:05
var app = app || {};
$(function() {
var myModel = new app.MyModel();
var libraryView = new app.LibraryView();
$( '#someIDinmyindex.html' ).append(libraryView.el);
});
- create index.html
- order matters
- load/require backbone files
- load models
- load views
- load app.js
- create an app global variable
- in an IIFE instantiate any views you need
- views initialize method
- should call its render method
for (var number in obj) {
obj[number].forEach(function(letter) {
answer[letter.toLowerCase()] = Number(number)
})
}
@blake41
blake41 / forms
Last active September 10, 2015 13:31
forms are HTML and follow HTTP conventions
forms are the combination of a get and a post
in sinatra we mainly build forms manually (in HTML)
in rails we mainly use "form helpers" to dynamically create forms
it's only the HTML you write that matters
the most important things about a form are the name attributes of the inputs and the action of the form.
the action of the form tells you where the form will post.
How does Sinatra/Rails parse query parameters (hint: it's really Rack doing it)?
http://spin.atomicobject.com/2012/07/11/get-and-post-parameter-parsing-in-rails-2/