Skip to content

Instantly share code, notes, and snippets.

View code-for-coffee's full-sized avatar

James code-for-coffee

  • Chicago, IL
View GitHub Profile
@code-for-coffee
code-for-coffee / ch3-table-row-view.hbs
Created February 4, 2015 05:52
Backbone Enterprise Practices - Ch3 Table Row View
{{!-- view-table-row-template --}}
<tr>
{{#each column}}
<td>{{this}}</td>
{{/each}}
</tr>
{{!-- end view-table-row-template --}}
@code-for-coffee
code-for-coffee / ch3-2.js
Created February 4, 2015 06:05
Backbone Enterprise Practices - Ch3 #2
// individual row
App.Models.TableRow = Backbone.Model.extend({
referenceSelf: function() {
return this;
},
initialize: function() {
var self = this.referenceSelf(),
<audio id="kablam!">
<source src="/assets/kablam.mp3" type="audio/mpeg">
</audio>
<button id="playSoundBtn">Kablam!</button>
@code-for-coffee
code-for-coffee / index.html
Last active August 29, 2015 14:22
FileReader Upload
<form action="/api/photo" method="post"></form>
<h3>Upload Image</h3>
<input type="file" name="image" class="mui-form-control">
<button class="mui-btn mui-btn-primary mui-btn-raised">My Button</button>
</form>
@code-for-coffee
code-for-coffee / js-setup.html
Created May 30, 2015 17:06
FileReader Upload
<script type="text/javascript">
$(document).ready(function(event) {
// select our input DOM element with a type of file
var fileInput = $('input[type="file"]')[0];
// select our form, too
var form = $('form')[0];
// prevent our form from submitting via POSTBACK
$(form).on('submit', function(event) {
@code-for-coffee
code-for-coffee / convertToBase64.js
Created May 30, 2015 17:28
Using FileReader to convert a file
/**
* convertToBase64
* @param binaryData: Input data from an <input type="file">
*/
function convertToBase64(binaryData) {
// use a FileReader
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader
var reader = new FileReader();
reader.onload = function (event) {
// try to read whatever file has been 'readAsDataURL'
// prevent our form from submitting via POSTBACK
$(form).on('submit', function(event) {
event.preventDefault();
var fileAsBase64 = convertToBase64($(fileInput).prop('files')[0])
// now, you can sent your file over via an $ajax call!
});
@code-for-coffee
code-for-coffee / tables.text
Created June 3, 2015 19:12
Draw a diagram that represents the following tables in a database
## Diagram a Database
- Owners HAVE MANY Pets
- Pets HAVE ONE Owner
- Pets and Owners have ONE Home
- Owners have:
- ID (int) as Primary Key
- Name (string)
- PetID (int) as Foreign Key
@code-for-coffee
code-for-coffee / tables.text
Created June 3, 2015 19:12
Draw a diagram that represents the following tables in a database
## Diagram a Database
- Owners HAVE MANY Pets
- Pets HAVE ONE Owner
- Pets and Owners have ONE Home
- Owners have:
- ID (int) as Primary Key
- Name (string)
- PetID (int) as Foreign Key