Skip to content

Instantly share code, notes, and snippets.

Robots.Views.HomePage = Backbone.RobotView.extend
template: Handlebars.compile($('#t-home-page').html())
events:
"click #dashboard-link" : "goDashboard"
initialize: ->
@render()
render: ->
@jhubert
jhubert / script.coffee
Created May 21, 2012 19:12
Array Product of Other Items in the Array
# Make it a prototype method for Array
Array.prototype.productOthers = ->
# Set some default values
[result, total, zeroIndex] = [[], 1, null]
# Loop through each item in the array
for num, index in @
# Set the default value to 0
result[index] = 0
@jhubert
jhubert / user_lists.coffee
Created May 23, 2012 06:54
Sample Layout of a view with self contained data
SkillRank.Views.DashboardUserLists = Backbone.View.extend
template: JST['dashboard/_user_lists']
initialize: ->
@collection = new SkillRank.Collections.Lists()
@collection.on('reset', @render, this)
@collection.fetch()
render: ->
@$el.html(@template(lists: @collection))
@jhubert
jhubert / data.js
Created July 10, 2012 17:28
Mustache vs Handlebars
data = { people: [{ name: 'jeremy' }], notTrue: false, label: 'People' }
YUI.add("import-waiting-view", (function(Y) {
var prototypeOptions = {
initializer: function() {
console.log('Initialized');
this.publish('finished', {
broadcast: true,
fireOnce: true
})
{"id":"ZT6wYoaBZ6L2s5a5o5fbrkKUHRUXYooY","key":"ZT6wYoaBZ6L2s5a5o5fbrkKUHRUXYooY","customer_list_id":"null","status":"created","created_at":"2012-08-27T05:18:38Z","updated_at":"2012-08-29T09:54:20Z","preview_columns":["name"," createdDate"," listName"," street"," city"," zip"],"preview_rows":[["Jeremy","","","1234 Road St"," San Francisco"," 94109"],["Jeremy","","","1234 Road St"," San Francisco"," 94109"],["Jeremy","","","1234 Road St"," San Francisco"," 94109"]],"preview_fields":{"field0":"name","field1":" createdDate","field2":" listName","field3":" street","field4":" city","field5":" zip"}}
@jhubert
jhubert / new.html.erb
Created September 24, 2012 05:31
Example of how to use the post-to-s3 ruby on rails gem
<h1>Upload Your File</h1>
<%= s3_upload_form_for(@upload) do %>
<p><%= label_tag :file, 'Select Your File' %></p>
<p><%= file_field_tag :file %></p>
<% end %>
@jhubert
jhubert / gist:3777908
Created September 24, 2012 19:43
Unable to post data using OAuth
YUI().use('gallery-oauth', 'io-xdr', 'json', function(Y) {
var url = 'http://api.example.com/v1/update.json',
data = { test: 'one' },
cfg = {
method: 'POST',
data: { data: Y.JSON.stringify(data) },
xdr: { use: 'native' }
},
signedURL,
request;
@jhubert
jhubert / A Matter of Security.md
Created September 30, 2012 10:16
Protect certain attributes and methods from being exposed

Overview

There can be a business or security requirement that certain fields on a model should never be exposed in an API. One approach to this is to tell the developers not to ever put the field in the API output, but I prefer to protect them at the model level because that's where the requirement actually is.

The goal of this is to have a simple way to specify fields that should be prevented from being exposed. This is one approach and I would love feedback both on the implementation and on the approach. Ideas and criticism are very welcome. :)

@jhubert
jhubert / describe.rake
Created October 22, 2012 23:24
Describe your unit tests in an easy to read format
namespace :test do
# Describe the tests that are run for the provided class or all classes
task :describe, :klass do |t, args|
name = args[:klass] ? args[:klass].underscore : '*'
classes = {}
files = Dir["test/*/#{name}_test.rb"]
files.each do |f|
file = File.read(f)
test_class = file.scan(/class\s([A-Z][\w]+)Test/).flatten