Skip to content

Instantly share code, notes, and snippets.

@ciberch
ciberch / JSONActivityStreamsExample
Created October 15, 2010 16:21
JSON Activity Streams Example
{"items": [
{
"verb": "post", // Id which maps to specification submitted to activity streams registrar
"postedTime": "2010-12-12T12:12:12Z",
"title": "Plain Text",
"summary": "Plain Text", // Have not decided on plain text only
"permalinkUrl": "...",
"to": [{"id" : "acct:john.doe@example.org"}], // We should use person constructs here
"cc": [{"id":"acct:jane.doe@example.org"}],
"bcc": [{"id":"acct:jean.deux@example.org"}],
@ciberch
ciberch / SocialcasHomeStreamSample.xml
Created April 20, 2011 17:15
Example for how to create a Socialcast Home Stream Web part
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Home Stream </Title>
<FrameType>Default</FrameType>
<Description>The Socialcast Reach Web Part brings your Socialcast Community into SharePoint</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>wpz</ZoneID>
<PartOrder>1</PartOrder>
<FrameState>Normal</FrameState>
<Height>500px</Height>
@ciberch
ciberch / mysql.js
Created May 22, 2012 18:20
Activity Query with Relational DB
User.hasMany("bugs", Bug, "creatorId");
Bug.belongsTo("user", User, "creatorId");
Project.hasMany("bugs", Bug, "projectId");
Bug.belongsTo("project", Project, "projectId");
User.hasMany("commits", Commit, "creatorId");
Commit.belongsTo("user", User, "creatorId");
Project.hasMany("commits", Commit, "projectId");
@ciberch
ciberch / mongoose-query.js
Created May 22, 2012 19:23
Activity Streams Mongoose Query
// https://github.com/ciberch/activity-streams-mongoose
Activity.find().sort('published', 'descending').limit(10).run(
function (err, docs) {
var activities = [];
if (!err && docs) {
activities = docs;
res.render('index', {activities: activities});
}
});
@ciberch
ciberch / redis.js
Created May 22, 2012 19:30
Publishing and Activity to Redis
var redis = require("redis");
var publisher = redis.createClient(options.redis.port, options.redis.host);
if(options.redis.pass) {
publisher.auth(options.redis.pass);
}
function publish(streamName, activity) {
activity.save(function(err) {
if (!_.isArray(activity.streams)) {
activity.streams = []
var streamLib = require('activity-streams-mongoose')({
mongoUrl: app.siteConf.mongoUrl,
redis: app.siteConf.redisOptions,
defaultActor: defaultAvatar
});
var authentication = new require('./authentication.js')(streamLib, app.siteConf);
// Moved normalization to only be done on pre save
streamLib.types.UserSchema.pre('save', function (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();
@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 / 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 / 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},