Skip to content

Instantly share code, notes, and snippets.

@aroc
aroc / side-comments-existing-comments-structure
Last active August 29, 2015 14:02
SideComments.js existing comments array structure
var existingComments = [
{
"sectionId": "1",
"comments": [
{
"authorAvatarUrl": "http://f.cl.ly/items/1W303Y360b260u3v1P0T/jon_snow_small.png",
"authorName": "Jon Sno",
"comment": "I'm Ned Stark's bastard. Related: I know nothing."
},
{
@aroc
aroc / side-comments-current-user-structure
Created June 15, 2014 19:34
SideComments.js currentUser structure
{
id: 1,
avatarUrl: "http://f.cl.ly/items/0s1a0q1y2Z2k2I193k1y/default-user.png",
name: "You"
}
@aroc
aroc / init-side-comments
Last active August 29, 2015 14:02
init-side-comments
// First require it.
var SideComments = require('side-comments');
// Then, create a new SideComments instance, passing in the wrapper element and the optional the current user and any existing comments.
sideComments = new SideComments('#commentable-area', currentUser, existingComments);
@aroc
aroc / side-comments-markup
Last active November 10, 2017 02:58
SideComments markup example
<div id="commentable-area">
<p data-section-id="1" class="commentable-section">
This is a section that can be commented on.
</p>
<p data-section-id="2" class="commentable-section">
This is a another section that can be commented on.
</p>
<p data-section-id="3" class="commentable-section">
This is yet another section that can be commented on.
</p>
@aroc
aroc / kill-core-audio
Created February 24, 2014 02:54
Kill's OS X core audio - afterwards connecting to airplay should work.
sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`
@aroc
aroc / border_arrow.css
Created July 10, 2013 21:40
Create an border arrow in css. Great for activity feeds and such.
.arrow {
position: absolute;
top: 15px;
left: -11px;
z-index: 100;
.back {
position: absolute;
top: 0;
left: 0;
var options = new Array();
$('select[name=select_name] > option').each(function (i) {
options[i] = $(this).text();
});
var string = "";
for (var i=0; i<options.length; i++) {
string += "\"" + options[i] + "\"" + ",";
if (i + 1 != options.length) {
string += "\n";
}
@aroc
aroc / gist:5715154
Created June 5, 2013 16:14
Factory Pattern for Backbone.js
// Allows you to create a child which is a copy of the parent and changing the child or parent doesn't affect one another.
// Calling "this" inside the child won't change attributes of the parent, as it is a copy and not connected through the prototype chain.
define(['jquery', 'underscore', 'backbone'], function ($, _, Backbone) {
// NOTE: This works in every scenario I've tested it in. However, this code looks bad
// and there may very well be a much cleaner + better way to handle this. Or maybe not
// because JS prototypes are crazy.
function childOfClass (parentFunction, newAttributes) {
@aroc
aroc / gist:5455534
Last active December 16, 2015 15:19
Keeping direct reference to the element you're inserting into the DOM at render time with Backbone.js
// pass in the $parentEl in the options so you can reference it.
render: function () {
this.$el = $(this.template({
...
})).appendTo(this.$parentEl);
// Call delegateEvents() afterwards if you have events in your view you want bound to the new this.$el
this.delegateEvents();
}
@aroc
aroc / backbone.validation.onlywhen.js
Created February 25, 2013 00:22
Change to Backbone.Validations to allow for a "onlyWhen" property that runs a model function, and if it returns false the validator is skipped.
var getValidators = function(model, attr) {
var attrValidationSet = model.validation ? model.validation[attr] || {} : {};
// If the validator is a function or a string, wrap it in a function validator
if (_.isFunction(attrValidationSet) || _.isString(attrValidationSet)) {
attrValidationSet = {
fn: attrValidationSet
};
}