Skip to content

Instantly share code, notes, and snippets.

module.exports.bootstrap = function (cb) {
redisClient.subscribe('scoredTweets');
redisClient.on( 'message', function ( channel , message ) {
console.log( REDIS , MESSAGE_RECEIVED, SCORED_TWEETS )
sails.io.emit( 'scoredTweets' , message );
});
cb();
};
@mattisfrommars
mattisfrommars / PubSub.js
Last active December 19, 2015 02:39
Pub/Sub module, allowing subscription to events, as well as adding callbacks to be fired only when multiple, events (dependencies) have been fired.
define([],function(){
var subscribed = {};
/**
* Subscription Object, holds an idientifier and a callback
* @param eventName
* @param callback
* @returns {{eventName: *, callback: *}}
* @constructor
*/
var Subscription = function (eventName, callback) {
@mattisfrommars
mattisfrommars / gist:5390465
Created April 15, 2013 19:02
Doing some parallax? Might need a class like this!
var Viewport = function($, window) {
var that = this;
var $window = $(window);
$window.resize(function(){ that.windowWasResized(window); });
$window.scroll(function(){ that.windowWasScrolled(window); });
that.windowWasResized(window);
};
$.extend(Viewport.prototype, {
height : 1,
windowWasResized : function(w) { this.height = $(w).height(); },
@mattisfrommars
mattisfrommars / gist:5363987
Created April 11, 2013 14:48
Wrapper for requestAnimationFrame that accepts a callback and duration. Gives the callback a "completion" value between 0 and 1 every animation frame
var animateObject = function (callback, duration) {
var startTime = 0;
var slideFrame = function(animationMiliSeconds) {
startTime = startTime || animationMiliSeconds;
var timeTaken = animationMiliSeconds - startTime;
var completion = timeTaken / duration;
if (animationMiliSeconds <= startTime+duration) {
@mattisfrommars
mattisfrommars / My Media Query Mixins
Created March 29, 2013 11:24
Shorthand media query mixins, example usage: @include minwidth (280px) { body { background-color: green; } }
@mixin minwidth ($width) {
@media only screen and (min-width : $width ) {
@content;
}
}
@mixin maxwidth ($width) {
@media only screen and (max-width : $width ) {
@content;
}
}
@mattisfrommars
mattisfrommars / _retinaSprite.scss
Created March 21, 2013 13:58
Compass retina sprite mixin
/*
@author: Matt Jewell - mattjewell.co.uk
Borrows HEAVILY from thulstrup / compass-retina-sprites.scss https://gist.github.com/thulstrup/2140082
but ditches the media queries and serves retina to all
*/
// SET UP SPRITES
@import "autosprite/*.png";
$sprite-map: sprite-map("autosprite/*.png");
monthContainers.each(function(){
var posts = $(this).children('.post:visible');
if (posts.length === 0) { /* hide the date */ }
else { /* show the date */ }
})