Skip to content

Instantly share code, notes, and snippets.

@ciberch
ciberch / render_json_rabl.rb
Created June 2, 2014 20:51
Rendering json string with Rabl Engine
Rabl::Renderer.json(obj, "bla/show", format: :json, view_path: "views")
@ciberch
ciberch / resque-jobs.rb
Created December 31, 2013 21:23
Resque Jobs - Clear or Retry
#count jobs
Resque::Failure.count
# Requeue all jobs in the failed queue
(Resque::Failure.count-1).downto(0).each { |i| Resque::Failure.requeue(i) }
# or
# Clear the failed queue
Resque::Failure.clear
@ciberch
ciberch / watch.sh
Created December 10, 2013 20:17
Install watch
curl -O http://ktwit.net/code/watch-0.2-macosx/watch
chmod +x watch
./watch
sudo mv watch /usr/local/bin/
@ciberch
ciberch / activity_stream_view.js
Created September 10, 2012 19:51
The Activity Stream View in Backbone
var ActivityStreamView = Backbone.View.extend({
el: '#main_stream', // el attaches to existing element
initialize: function(){
_.bindAll(this, 'render', 'appendItem'); // every function that uses 'this' as the current object should be in here
this.collection = new ActivityList();
this.collection.bind('add', this.appendItem); // collection event binder
this.maxSize = 20;
},
render: function(){
@ciberch
ciberch / activity.js
Created September 10, 2012 19:45
Activity Backbone Model
var Activity = Backbone.Model.extend({
url : "/activities",
// From activity-streams-mongoose/lib/activityMongoose.js
defaults: {
verb: 'post',
object: null, //ActivityObject
actor: null, //ActivityObject
url: '',
title: '',
content: '',
@ciberch
ciberch / activity_create_view.js
Created September 10, 2012 19:35
Activity Create Backbone View
var ActivityCreateView = Backbone.View.extend({
el: '#new_activity',
initialize: function(){
_.bindAll(this, 'newAct', 'render', 'changeType', 'includeLocation', 'sendMessage');
this.trimForServer = App.helper.trimForServer;
var streamName = this.$el.find('#streamName').val();
var verb = this.trimForServer(this.$el.find('#verb-show'));
var objectType = this.trimForServer(this.$el.find('#object-show'));
@ciberch
ciberch / types.js
Created September 6, 2012 21:10
Snippet showing how to store location for Activity Streams in MongoDB via Mongoose
var LocationHash = {
displayName: {type: String},
position: {
latitude: Number,
longitude: Number
}
};
var ActivityObjectHash = {
id: {type: String},
@ciberch
ciberch / server2.js
Created September 6, 2012 16:46
Resize photos using Imagemagick and Node.js
var im = require('imagemagick');
var Guid = require('guid');
function reducePhoto(req, res, next){
var photoIngested = req.photosUploaded['original'];
if (photoIngested) {
var sizeName = sizes[req.nextSizeIndex].name;
var destPath = photoIngested.metadata.path + '-' + sizeName ;
var nameParts = photoIngested.metadata.filename.split('.');
var newName = nameParts[0] + '-' + sizeName + '.' + nameParts[1];
@ciberch
ciberch / asms-client.js
Created September 6, 2012 00:46
Using distinct
var getDistinct = function (req, res, next, term, init){
var key = 'used.' + term;
req[key] = init ? init : [];
var query = {streams: req.session.desiredStream};
asmsDB.Activity.distinct(term, query, function(err, docs) {
if (!err && docs) {
_.each(docs, function(result){
req[key].push(result);
});
next();
@ciberch
ciberch / server.js
Created September 5, 2012 22:59
Using ImageMagick to get photo Metadata with Node.js
var im = require('imagemagick');
var Guid = require('guid');
var siteConf = require('./lib/getConfig');
var lib = new require('./lib/asms-client.js')(app, cf).streamLib;
function ingestPhoto(req, res, next){
if (req.files.image) {
im.identify(req.files.image.path, function(err, features){
if (features && features.width) {
var guid = Guid.create();