Skip to content

Instantly share code, notes, and snippets.

View jgable's full-sized avatar

Jacob Gable jgable

  • Making Other People Money
  • Redwood City, CA
  • X @jacob4u2
View GitHub Profile
@jgable
jgable / postsByTag.js
Created November 13, 2013 19:46
Posts by tag
postsByTag: function (tagId) {
return dataProvider.Tag.findOne({id: tagId}).then(function (found) {
if (!found) {
return when.resolve([]);
}
// TODO: Trim data sent back
return when.resolve(found.related("posts"));
});
}
@jgable
jgable / index.js
Created September 27, 2013 19:52
Ghost Kudos Plugin Example
var fs = require('fs'),
path = require('path'),
_ = require('underscore'),
when = require('when'),
express = require('express'),
GhostPlugin = require('../../../core/server/plugins/GhostPlugin'),
knex = require('../../../core/server/models/base').Knex,
KudosPlugin;
KudosPlugin = function (ghost) {
@jgable
jgable / magicalexport.js
Created September 17, 2013 17:59
Ghost Magical Export thingy
if (!process.env.NODE_ENV) {
console.log("Please explicitly set your node environment before running this command: > NODE_ENV=production node exporter.js");
return;
}
var fs = require('fs'),
path = require('path'),
_ = require('underscore'),
@jgable
jgable / CSSSelectors.js
Created September 11, 2013 18:12
Stylesheet Selector
var styleSheets = document.styleSheets,
totalRules = 0;
styleSheets = Array.prototype.slice.call(styleSheets, 0);
styleSheets.forEach(function (stylesheet) {
if (!stylesheet.cssRules) {
return;
}
@jgable
jgable / SocketsModel.js
Created August 28, 2013 18:34
A WebSocket Based Backbone Model
var SocketsModel = Backbone.Model.extend({
sockets: null,
autoListen: true,
// Mapping of channel to callback name (like events hash)
channels: function () {
var chans = {};
chans["data"] = "onSocketData";
chans["error"] = "onSocketDataError";
@jgable
jgable / logger.coffee
Created July 24, 2013 14:48
Slimer Logger Script
# Description:
# Logs chat to Redis and displays it over HTTP
#
# Dependencies:
# "redis": ">=0.7.2"
# "moment": ">=1.7.0"
#
# Configuration:
# LOG_REDIS_URL: URL to Redis backend to use for logging (uses REDISTOGO_URL
# if unset, and localhost:6379 if that is unset.
@jgable
jgable / Backbone_BaseViews.js
Last active December 17, 2015 21:19
Backbone Base Views
/* global Backbone, _, $ */
Backbone.TemplateView = Backbone.View.extend({
// Set this to your stache name, or a function that takes template data and returns html
template: null,
render: function () {
var template = this.getTemplate();
// Set the html based on the template
module.exports = function(grunt) {
var cfg = {
jshint2: {
options: {
jshint: {
node: true,
unused: true,
undef: true
}
},
@jgable
jgable / oslo-mexico.js
Last active December 16, 2015 17:09
Walltime Conversion between time zones
var rightNow = new Date(),
chicagoWallTime = WallTime.UTCToWallTime(rightNow, "America/Chicago"),
osloWallTime = WallTime.UTCToWallTime(rightNow, "Europe/Oslo"),
backToUTCTime = WallTime.WallTimeToUTC("America/Chicago", chicagoWallTime);
var formatWallTime = function(wt) {
// Format a walltime; 4/26/2013 9:21:13
return [wt.getMonth(), wt.getDate(), wt.getFullYear()].join("/") + " " + [wt.getHours(), wt.getMinutes(), wt.getSeconds()].join(":");
};
@jgable
jgable / default.js
Created April 22, 2013 20:17
Building a Better Grunt Plugin
module.exports = function(grunt) {
grunt.registerMultiTask('{%= short_name %}', 'Your task description goes here.', function() {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
punctuation: '.',
separator: ', '
});
// Iterate over all specified file groups.