Skip to content

Instantly share code, notes, and snippets.

@daffl
daffl / expression.pegjs
Last active July 25, 2018 10:31
An expression grammar for PEGJS
start = (text / enclosedexpression)*
text =
characters:$((!open) c:any)+ {
return {
type: 'text',
value: characters
}
}
@daffl
daffl / app.js
Created February 5, 2015 20:25
Isomorphic web-components
var express = require('express');
var app = express();
var shared = require('./shared');
var todos = [];
app.engine('html', shared.engine);
app.use('/', express.static(__dirname + '/public'));
app.use('/:section', function(req, res) {
res.render('index', {
@daffl
daffl / .jshintrc
Created March 17, 2015 05:06
My standard JSHint configuration
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": "nofunc",
@daffl
daffl / readme.md
Created April 2, 2015 02:43
Global .gitignore

There are files that should not be included in Git repositories (like IDE settings, OS generated files, temporary files etc.). Instead of adding them to the .gitignore file for each repository over again you can use a global .gitignore file:

Create a .gitignore_global file in your home directory (subl ~/.gitignore_global) with the following content:

# OS files
.DS_Store
.DS_Store?
.Spotlight-V100
.Trashes
Icon?
@daffl
daffl / app.js
Last active August 29, 2015 14:19
Using CanJS 2.2 with StealJS and NPM
import $ from 'jquery';
import stache from 'can/view/stache/stache';
const template = stache('Hello {{message}}!');
$(() => {
$('body').append(template({ message: 'David' }));
});
@daffl
daffl / hooks-examples.js
Created May 10, 2015 22:03
feathers-hooks examples
// Add a delay to test slower connections
function addDelay(delay) {
return function(hook, next) {
setTimeout(next, delay);
}
}
function timestamp(name) {
return function(hook, next) {
hook.data[name] = new Date();
@daffl
daffl / app.js
Last active January 7, 2017 08:06
User service with hooks
var feathers = require('feathers');
var mongodb = require('feathers-mongodb');
var hooks = require('feathers-hooks');
var bodyParser = require('body-parser')
var crypto = require('crypto');
var nodemailer = require('nodemailer');
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
@daffl
daffl / app.js
Last active August 29, 2015 14:20
An Epress middleware example
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json())
.use(function(req, res, next) {
// Add the username to the parsed body
// set by bodyParser middleware
req.body.username = 'David';
next();
@daffl
daffl / feathers.js
Created June 24, 2015 14:13
Get the request object in a service
var app = feathers()
.configure(feathers.rest())
.use(function(req, res, next) {
req.feathers.request = req;
next();
})
.use('/todos', {
get: function(id, params, callback) {
params.request
}
@daffl
daffl / app.js
Created June 25, 2015 14:33
Authentication for SocketIO and REST APIs
var app = feathers()
.configure(feathers.rest())
.configure(feathers.socketio(function(io) {
io.use(function(socket, next) {
socket.feathers.user = socket.request.session.user;
next();
});
}))
.use(function(req, res, next) {
req.feathers.user = req.session.user;