Skip to content

Instantly share code, notes, and snippets.

View leepfrog's full-sized avatar

Andy Tran leepfrog

View GitHub Profile
@leepfrog
leepfrog / gist:5207638
Created March 20, 2013 19:23
SortPipe
Blocks.SortPipePlugin = Em.PipePlugin.extend
# Define a list of sorting properties
observes: Em.computed.alias('sortProperties')
# The sorting function to use
sortFunction: Em.compare
# Our sort routine
process: (inputArr) ->
# DS.ManyArray does not support sort()
@leepfrog
leepfrog / error
Last active December 14, 2015 21:58
Extra content at the end of the document.
Location: '/VirtualBox VMs/GitHubEnterprise/GitHubEnterprise.vbox', line 16563 (0), column 61.
/build/buildd/virtualbox-4.1.12-dfsg/src/VBox/Main/src-server/MachineImpl.cpp[707] (nsresult Machine::registeredInit()).
Result Code: NS_ERROR_FAILURE (0x80004005)
Component: VirtualBox
Interface: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}
class VotesController < ApplicationController
  def create
    @vote = Vote.find_or_initialize_by_submitted_by_ip(request.remote_ip)
    @vote.update_attributes(params[:vote]) if !@vote.has_user?(session[:user_id])
    render json: @vote
  end
end

class Vote &lt; ActiveRecord::Base
require '../../test_helper.coffee'
describe 'ArrayPipeline', ->
describe '#_setupPlugin()', ->
it 'should instantiate a plugin from a constant', ->
pipeline = Em.ArrayProxy.createWithMixins(Em.ArrayPipelineMixin,{})
pipeline.get('_processors.length').should.equal(0)
pipeline._setupPlugin(Em.PipePlugin)
App.Comment = DS.Model.extend
parentComment: DS.belongsTo("App.Comment", inverse: 'childComments')
childComments: DS.hasMany("App.Comment", inverse: 'parentComment')
App.BookIndexController = Ember.ArrayController.extend
content: [] # array of books
proxies: {} # proxy cache for books
# Creates and caches a proxy that will wrap around our book
createProxy: (book, id) ->
@proxies[id] = BookProxy.create
content: book
controller: this
@leepfrog
leepfrog / gist:4498789
Created January 10, 2013 02:11
A 1st draft for building Ember.ArrayPipeline / Ember.ArrayPipelinePlugin.
Ember.ArrayPipelinePlugin = Ember.Object.extend
#
# Public
#
# Define a set of properties you would like to observe on the array for
# reprocessing.
#
# If another plugin earlier in the pipeline observes the same property,
# then this plugin will wait to process until the other plugin in the pipeline
@leepfrog
leepfrog / gist:4464513
Last active December 10, 2015 16:58
Class extension to convert hamlbars to handlebars.
class File
def to_str
path
end
end
class Hamlbars::Converter
def self.process_directory(directory)
dir = Dir.open(directory)
@leepfrog
leepfrog / WebSocket.js.coffee
Created December 30, 2012 07:26
Android WebSockets plugin for Cordova 2.2
class WebSocket
constructor: (url) ->
cordova.exec (-> return true), (-> return false), "WebSocketPlugin", "createSocket", [url]
cordova.exec @_onerror, (->), "WebSocketPlugin", "registerCallback", ["onerror"]
cordova.exec @_onopen, (->), "WebSocketPlugin", "registerCallback", ["onopen"]
cordova.exec @_onclose, (->), "WebSocketPlugin", "registerCallback", ["onclose"]
cordova.exec @_onmessage, (->), "WebSocketPlugin", "registerCallback", ["onmessage"]
send: (message) ->
cordova.exec (-> return true), (-> return false), "WebSocketPlugin", "send", [message]
addImages: (files) ->
formData = new FormData()
# Attach block id
formData.append "attachments[book_id]", @get('content.id')
# Loop through the FileList and render image files as thumbnails.
for file in files
# Only process image files.
if file.type.match("image.*")