Skip to content

Instantly share code, notes, and snippets.

View alexmcpherson's full-sized avatar

Alex McPherson alexmcpherson

  • Colorado
View GitHub Profile
@alexmcpherson
alexmcpherson / MyView.js
Last active December 10, 2015 14:08
Another separation of concerns that's possible:
var MyView = Backbone.View.extend({
initialize: function() {
this.render();
this.model.on('change', this.update, this);
},
render: function() {
//Puts el on page, called ONLY once, by init
},
update: function() {
this.$el.html( /* Some template */ )
@alexmcpherson
alexmcpherson / MyView.js
Last active December 10, 2015 14:08
More granular view updating:
var MyView = Backbone.View.extend({
initialize: function() {
this.render();
//Two different update calls here, neither using .render()
this.model.on('change:first', this.updateFirst, this);
this.model.on('change:last', this.updateLast, this);
},
render: function() {
//Puts el on page, called ONLY once, by init
},
@alexmcpherson
alexmcpherson / upload.coffee
Created March 13, 2013 17:20
Image Preview on upload
handleFileUpload: (e) ->
file = e.target.files[0]
reader = new FileReader();
reader.onload = (e) =>
@image = new Image()
@image.onload = @renderImage
@image.src = e.target.result
reader.readAsDataURL(file)
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@alexmcpherson
alexmcpherson / build.bat
Created September 3, 2013 16:33
Grunt! Use Grunt!
@echo off
copy src\intro.js /B + src\core.js /B + src\tooltip.js /B temp1.js /B
copy src\models\*.js /B temp2.js /B
copy temp1.js /B + temp2.js /B + src\outro.js /B nv.d3.js /B
del temp1.js
del temp2.js
@alexmcpherson
alexmcpherson / pre-compilation.js
Last active December 31, 2015 21:39
Minifier error?
_update: function() {
//Kill old style
if (helpers.isDefAndNotNull(this.active)) { // <-- properly guarded here
this.active.el.removeClass('selected');
this.active.active = false;
}
// Grab the new state
this.active = this.states[this.currentIdx];
this.active.active = true;
@alexmcpherson
alexmcpherson / index.html
Last active August 29, 2015 13:56
Basic HTML structure
<html>
<head>
<!-- Metadata -->
</head>
<body>
<!-- Content -->
</body>
</html>
@alexmcpherson
alexmcpherson / index.html
Last active August 29, 2015 13:56
Essential HTML tags
<!DOCTYPE html> <!-- What 'schema' to use for the 'XML'. This means HTML5 -->
<html>
<head>
<title>My Page</title><!-- Shows in the browser, important for SEO (apparently :-) -->
</head>
<body>
<div>I'm a div, basically a box. I'm super useful.</div>
<p>
This is a paragraph, good for long strings of text.
@alexmcpherson
alexmcpherson / main.css
Created February 24, 2014 23:22
Basic CSS example
p {
color: #000000;
font-size: 1.2px;
}
.important {
font-weight: bold;
}
#main {
@alexmcpherson
alexmcpherson / index.html
Last active August 29, 2015 13:56
More advanced selectors
<html>
<head></head>
<body>
<div>
<span>Bold!</span>
<span>Not bold...</span>
</div>
<ul>