Skip to content

Instantly share code, notes, and snippets.

@distracteddev
distracteddev / example.js
Created April 8, 2012 18:12
Resourceful Question
BlogSettings.all(function(err, settings) {
winston.debug(JSON.stringify(settings));
if (settings == undefined) {
BlogSettings.create(self.req.body, function(err, settings) {
if (err) {
winston.error(err);
throw new(Error)(err);
}
self.res.end(JSON.stringify(settings));
winston.debug(settings);
@distracteddev
distracteddev / Get Blog Posts (Broken)
Created April 8, 2012 22:31
Resourceful Question (GET)
exports.getBP = function(id) {
var self = this;
if (arguments.length < 2) {
BlogPost.all(function(err, docs) {
if (err) throw err;
self.res.end(JSON.stringify(docs) + '\n');
winston.debug(docs);
return docs;
});
}
class About(Page):
header = models.TextField("Header Text")
offer = models.TextField("Offer Text")
testimonial = RichTextField(_("Testimonial"))
curriculum = models.TextField("Curriculum")
languageCenters = models.TextField("Language Centers")
dailySchedule = models.TextField("Daily Schedule")
image1 = models.ImageField(upload_to='about')
image2 = models.ImageField(upload_to='about')
image3 = models.ImageField(upload_to='about')
@distracteddev
distracteddev / index.js
Created April 15, 2012 04:13
Example of a Resourceful.js Model with a custom MapReduce Filter
var Resourceful = require('resourceful');
var tagFilter = {
map: function (post) {
post.tags.forEach(function (tag) {
emit(tag, 1);
});
},
reduce: function(keys, values) {
@distracteddev
distracteddev / index.js
Created April 15, 2012 04:18
A Node.js/Director route function
exports.getTags = function () {
var self = this;
BlogPost.tagFilter(function(err, tags) {
if (err) throw err;
console.log(tags);
self.res.end(JSON.stringify(tags));
});
};
@distracteddev
distracteddev / thanksforhelping.md
Created April 15, 2012 04:33
A Resourceful.js Question
@distracteddev
distracteddev / SafeClone.js
Created April 29, 2012 18:54
SafeClone to for jQuery UI so that it plays nice with Ember.js
$.fn.extend({
safeClone: function() {
var clone;
clone = $(this).clone();
clone.find('script[id^=metamorph]').remove();
clone.find('*').each(function() {
var $this;
$this = $(this);
return $.each($this[0].attributes, function(index, attr) {
if (attr.name.indexOf('data-bindattr') === -1) {
@distracteddev
distracteddev / dateHelper.handlebars.js
Created May 6, 2012 01:17
Handlebars Date Helper that doesn't require an array of Months and leverages Date()'s native Localization
Ember.Handlebars.registerHelper('date', function(path, options) {
date = options.contexts[0].get(path);
dateArray = date.toLocaleDateString().split(', ');
day = date.getDate() + '. ';
// Gets the name of the month form the locaized date string
// (A Nice trick to avoid using your own localized date-month maps)
month = dateArray.splice(1)[0].split(' ')[0] + ' ';
year = 1900 + date.getYear();
return month + day + year;
});
@distracteddev
distracteddev / request.js
Created May 10, 2012 23:31
A Modification to the Node.js Passport module that looks for flatiron/union and binds the request functions onto the appropriate object.
/**
* Module dependencies.
*/
// If flatiron/union is being used, then bind the following
// functions to the RoutingStream Prototype
try {
var union = require('union')
, req = union.RoutingStream.prototype;
}
@distracteddev
distracteddev / connection.js
Created July 16, 2012 22:39
Connect to a redisToGo instance (Heroku or Nodejitsu
// To get a Redis URL provided by Nodejitsu run the following in your terminal:
// $ jitsu databases create redis [name_of_database]
//
// This will output a message with your new Redis' instance URL. Copy/Paste it below:
var REDIS_URL = process.env.REDISTOGO_URL // REPLACE THIS WITH YOUR URL PROVIDED BY THE JITSU CLI
var Resourceful = require('resourceful-redis')
, url = require('url');
// A function helper to connect to redis using Heroku's redis url