Skip to content

Instantly share code, notes, and snippets.

View psychobunny's full-sized avatar
❤️
Making forums great again™

Andrew Rodrigues psychobunny

❤️
Making forums great again™
View GitHub Profile
@psychobunny
psychobunny / conversion.MD
Created May 3, 2014 21:00
Converting HBS to templates.js syntax

Use this in a text editor that supports regex search (like Sublime Text)

Find all

\{\{#if ([\S]*)\}\}([\s\S]*?)\{\{else\}\}([\s\S]*?)\{\{/if\}\}

Replace With

<!-- IF $1 -->$2<!-- ELSE -->$3<!-- ENDIF $1 -->
@psychobunny
psychobunny / plugin.js
Last active August 29, 2015 14:01
Plugin example: Custom API homepage for NodeBB, returns topics instead of posts per category
var async = require('async'),
categories = module.parent.require('./categories');
var Plugin = {};
function renderHomepage(req, res, next) {
var uid = req.user ? req.user.uid : 0;
/*
* For reference, this is taken straight from controllers/index.js (controllers.home)
{
"categories": [
{
"cid": "1",
"name": "Announcements",
"description": "Announcements regarding our community",
"icon": "fa-bullhorn",
"bgColor": "#0059B2",
"color": "#fff",
"slug": "1/announcements",
{
"id": "nodebb-plugin-blog-comments",
"name": "NodeBB Blog Comments",
"description": "Lets NodeBB act as a comments engine/widget for your blog.",
"url": "https://github.com/psychobunny/nodebb-plugin-blog-comments",
"library": "./library.js",
"hooks": [
{
"hook": "filter:admin.header.build", "method": "addAdminLink"
},
@psychobunny
psychobunny / comments.php
Created May 24, 2014 00:50
Wordpress integration with NodeBB
<?php
if ( post_password_required() )
return;
?>
<a id="nodebb/comments"></a>
<script type="text/javascript">
var nodeBBURL = 'http://forum.burnaftercompiling.com',
articleID = '<?php echo the_ID(); ?>';
@psychobunny
psychobunny / mongo-ltrim.js
Created July 28, 2014 18:17
redis-like LTRIM for mongodb
module.listLTrim = function(key, start, stop, callback) {
module.getListRange(key, start, stop, function(err, value) {
if(err) {
if(typeof callback === 'function') {
return callback(err);
}
return;
}
db.collection('objects').update({_key: key }, {$set: value}, function(err, result) {
@psychobunny
psychobunny / library.js
Last active April 24, 2016 10:30
NodeBB plugin - adding main post data to category view
var topics = module.parent.require('./topics'),
async = module.parent.require('async');
var plugin = {};
plugin.addPostData = function(data, uid, callback) {
async.map(data.topics, function(topic, next) {
topics.getMainPost(topic.tid, uid, function(err, mainPost) {
topic.mainPost = mainPost;
next(err, topic);
@psychobunny
psychobunny / partials.js
Created February 12, 2015 16:43
Client-side partials parsing
var matches = null,
regex = regex = /[ \t]*<!-- IMPORT ([\s\S]*?)? -->[ \t]*/g,
apiCalls = [],
matchList = [],
deferredObjects = [];
while((matches = regex.exec(html)) !== null) {
var deferredObject = $.Deferred();
deferredObjects.push(deferredObject);
@psychobunny
psychobunny / debug.js
Last active April 16, 2020 09:46
NodeBB patch - Remove OP and replace it with first reply
// paste this in https://github.com/NodeBB/NodeBB/blob/master/src/routes/debug.js
// and then don't forget to remove it!
router.get('/remove-op', function(req, res) {
var db = require('../database'),
async = require('async');
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
async.eachLimit(tids, 50, function(tid, next) {
db.getSortedSetRange('tid:' + tid + ':posts', 0, 0, function(err, pid) {
@psychobunny
psychobunny / core.js
Last active August 29, 2015 14:18
FlightJS inspired components system for NodeBB
define('notifications', ['events', 'components'], function(events, components) {
var notifications = {};
notifications.init = function() {
events.initialize('notifications', function() {
this.register('icon.unread', markUnread);
this.register('icon.read', markRead);
});