Skip to content

Instantly share code, notes, and snippets.

channels.get(channel, (err, data) => {
...
if (onlyOnePlayed) {
channels.save(updateData, (err) => {
if (err) throw err;
bot.reply(message, `<@${user}> has played!`);
});
} else {
const gameResults = playerIDs.map((id) => `<@${id}> played ${players[id].played}`);
bot.reply(message, gameResults.join(' & '));
// reset the game data
channels.save({ id: updateData.id }, (err) => {
if (err) throw err;
});
}
if (!process.env.token) {
process.exit(1);
}
const Botkit = require('botkit');
const controller = Botkit.slackbot({
debug: true,
});
@captDaylight
captDaylight / auth.js
Last active November 22, 2016 20:17
Generating JWT for my current project
const jwt = require('jsonwebtoken');
const models = require('../models');
const Strategy = require('passport-local');
function generateToken(req, res, next) {
res.cookie('token',
jwt.sign({ id: req.user.id }, process.env.SECRET),
{
maxAge: 86400000,
httpOnly: true,
const jwt = require('jsonwebtoken');
const models = require('../models');
const Strategy = require('passport-local');
function generateToken(req, res, next) {
res.cookie('token',
jwt.sign({ id: req.user.id }, process.env.SECRET),
{
maxAge: 86400000,
httpOnly: true,
[
{
"Introduction": "# intro/n/n ## hello there...."
},
{
"Getting Started":
[
{
"Step One": "# stepone/n/n ## hello there..."
},
{
0: {
"Introduction": "# intro/n/n ## hello there...."
},
1: {
"Getting Started":
{
0: {
"Step One": "# stepone/n/n ## hello there..."
},
@captDaylight
captDaylight / markdownHeaderParse.js
Created February 21, 2018 16:54
Get the headers from markdown along with the header type
var re = /(#+)(.*)/;
var str = '## About Bottler\n\nThis is something about the project\n\n# something else\n';
function findAll(regex, sourceString, aggregator = []) {
const arr = re.exec(sourceString);
if (arr === null) return aggregator;
const newString = sourceString.slice(arr.index + arr[0].length);
return findAll(regex, newString, aggregator.concat([arr]));
(function() {
var searchQuery = window.location.search;
var ref;
var $form;
var userEmail;
if (searchQuery !== '' && searchQuery.indexOf('ref=') > -1) {
ref = searchQuery.split('=')[1];
console.log('ref',ref);
$form = $('form.newsletter-form');
router.put('/user/:refCode', function(req, res, next) {
if (!req.params.refCode) res.json({ result: 'error', msg: 'must send an referral code'});
var newEmail = req.body.email ? req.body.email : '';
mailchimp.get({
path: 'lists/' + listID + '/members?unique_email_id=' + req.params.refCode,
})
.then(function(search) {
const user = search.members[0];