Skip to content

Instantly share code, notes, and snippets.

View nlf's full-sized avatar

nlf nlf

  • Code4rena
  • Kennewick, WA
View GitHub Profile
var Plugin = function (model, options) {
// do something with options
model.extend({ factoryMethod: function () { /* do stuff */ }});
model.prototype.extend({ instanceMethod: function () { /* do other stuff */ }});
model.extendSchema(Joi.object({ some: 'field' }));
};
var request = new XMLHttpRequest();
request.onload = function () {
// request.status is the HTTP status code of the response
// request.responseText is whatever data the server sent back
// easiest for this would be something like
if (response.status === 200) {
// form posted ok
} else {
// form failed to post
var User = new WOG({
name: 'user',
schema: {
name: Joi.string().required(),
age: Joi.number().integer().default(20)
}
});
var Plugin = function (collection) {
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection();
if (!module.parent) {
server.start(function () {
console.log('started server');
});
}
exports.index = {
auth: 'session',
handler: function (request, reply) {
reply('resource index');
}
};
exports.create = {
auth: 'session',
handler: function (request, reply) {
var Joi = require('joi');
var obj = {
prop6: ["2015-06-07T14:21:46.295-07:00", "2015-06-07T18:21:46.295-07:00", "2015-06-07T20:21:46.295-07:00"]
}
var schema = Joi.object().keys({
prop6: Joi.array().includes(Joi.date().iso()).required()
});
console.log(Joi.validate(obj, schema))
function go() {
CMD=$1
GOBIN=`/usr/bin/which go`
OLDPATH="$GOPATH"
GOMODS=`pwd`/go_modules
if [ $CMD == "init" ]; then
echo "Initializing project $(basename `pwd`)..."
# Get a list of all (recursive) packages we depend on
DEPS=`go list -f '{{ join .Deps "\n" }}' 2>&1`
The question has come up a few times as to how releases are handled in the hapi ecosystem, so I'm going to explain hopefully all of it here for everyone. Let me know if there are questions.
The primary release tracking comes from github milestones. There must always be a milestone representing the next version to be released. For sanity's sake, it's assumed that the next version will be a patch release (i.e. if 6.7.0 is released the new milestone created will be "6.7.1"). If it's determined later that the new version should be a major or minor, edit the milestone's title and the paper trail is maintained. When a version is released, mark the milestone as closed and make a new milestone for the next version (i.e. "6.7.2"). This makes sure that when a release is made the milestone accurately documents all of the changes that were made as a result of that version.
Every change in functionality or bug fix must have an issue associated with it, and the commit related to the issue should mention the issue number
@nlf
nlf / .profile
Created September 10, 2014 20:59
restart riak and wait for vnodes to come up
function riboot() {
echo "stopping riak.."
riak stop >/dev/null 2>&1
echo "starting riak.."
riak start >/dev/null 2>&1
echo -n "waiting.."
until riak-admin test >/dev/null 2>&1; do echo -n "."; sleep 1; done
echo "done"
}
@nlf
nlf / test.js
Last active August 29, 2015 14:06
it('assigns an ephemeral port when requested twice', function (done) {
var server = new Hapi.Server(0);
var server2 = new Hapi.Server(0);
server.start(function () {
expect(server.info.port).to.be.a('number');
expect(server.info.port).to.be.above(0);
server2.start(function () {