31 May 15 Worship Set

Published on:

G Great Big God O
Em Rich Mullins - Awesome God https://www.youtube.com/watch?v=MJL_bChiTI0
D - What a friend we have in jesus https://www.youtube.com/watch?v=XTdPqq6DyQc
E - You are my all in all https://www.youtube.com/watch?v=zC617kE1maU
E Phil Wickham - This is Amazing Grace https://www.youtube.com/watch?v=XFRjr_x-yxU
C Brenton Brown - Holy https://www.youtube.com/watch?v=oOiSxeUinXk
C Brenton Brown - Joyful https://www.youtube.com/watch?v=AfJWaQJDi7k

Recycle Bin

Bb Jeremy Camp - Give me Jesus https://www.youtube.com/watch?v=DmX7EZMLHm0

Chris Tomlin - Awesome is the Lord Most High https://www.youtube.com/watch?v=AP7vObd4Rco
G? Johnny Cash - Old Rugged Cross https://www.youtube.com/watch?v=fuudlTywjsM
? Gather - Leaning on the Everlasting Arms https://www.youtube.com/watch?v=MvNdFIZRJRQ
G Willie Nelson - Just a Closer Walk with Thee https://www.youtube.com/watch?v=OOKaircCiGI
https://www.youtube.com/watch?v=lh7Q4AOSONc
G? Willie Nelson - Just a Little Walk with Jesus https://www.youtube.com/watch?v=EeoesHNu07U
https://www.youtube.com/watch?v=__obh6iLb4I
https://www.youtube.com/watch?v=aU4oMhncApc
https://www.youtube.com/watch?v=WxLA1NX9gxY

New Life - My Savior Lives https://www.youtube.com/watch?v=aZLqd07IEo0
??? - Were you there https://www.youtube.com/watch?v=xu_GW2osRVA
Tim Hughes - Everyting https://www.youtube.com/watch?v=SOY-eHUsHdM
It's So Sweet To Trust In Jesus

Ansible when first host in group

Published on:

Here is how you run a task on just the first host in a group. We have multiple kafka servers, but we only need to run the task to create new topics on the first one. And we want that task to be a part of our playbook that deploys and configures all the kafka servers.

# some task that creates kafka topics
when: inventory_hostname == groups["{{some_var}}-kafka"][0]

hapi-auth-cookie

Published on:

hapi-auth-cookie is deceivingly simple to use.

Authenticate someone.

// do some logic to make sure we are who we say we are.
// then just set the auth session to some non-null object.

request.auth.session.set({must: 'be any old non-null object'});

Log them out.

request.auth.session.clear();

So you are logged in when there's a non-null object in auth session and you are logged out when there isn't. Simple.

Here's the setup.

var hapi = require('hapi');
var cookie = require('hapi-auth-cookie');
var server = new hapi.Server();

// register the cookie scheme.
server.register(cookie, function(err) {

  // give our auth strategy a name 'any_name_will_do'
  // hapi-auth-cookie's scheme is named 'cookie', so that needs to be
  // the second param.
  server.auth.strategy('any_name_will_do', 'cookie', {
    password: 'G00b#rBuTz',
    cookie: 'yo-cookie',
    isSecure: false
  });
});

// create a route that uses our auth strategy, and you won't 
// be able to get to that route unless you are authenticated.
server.route({
  method: 'GET',
  path: '/private/{foo*}',
  config: {
    auth: 'any_name_will_do',
    handler: {
      directory: {
        path: 'web/private'
      }
    }
  }
});

Whatever you pass to request.auth.session.set() will be available in request.auth.credentials. But it will only be there on secured routes. That tripped me up a bit. I figured it should always be there for every route.

server.ext('onPostAuth', function(request, reply) {
  console.log('request.auth.credentials', request.path, request.auth.credentials);
  reply.continue();
});

onPostAuth always happens even if you aren't authenticated.

The output below shows that for the favicon request there was nothing in auth credentials even though I am authenticated. But the private request did have my creds.

request.auth.credentials /favicon.ico null
request.auth.credentials /private/ {must: 'be any old non-null object'}

Super simple connect

Published on:

I was curious what it would take to write a super simple implementation of the Node.js connect library: https://github.com/senchalabs/connect.

// This should be compatible with https://github.com/senchalabs/connect
// Allows you to stick a stack of middleware in to process the request
// and response in a pipeline fashion.
var url = require('url');

var handlers = [];
var errHandlers = [];

// Not sure if this is exactly the same workflow that connect uses but . . .
//
// Loop over all the handlers in order. Each one will process the
// request and/or reponse in some way (or not). As long as the handler
// calls next() we keep going. If one of the handlers doesn't call next()
// we are done (we assume at that point the handler called res.end() or
// something similar).
//
// If one of the handlers calls next(err) we are done with
// handlers and we start looping over the errHandlers. As long as the
// errHandlers call next we keep going. If one of the errHandlers doesn't
// call next we are done.
function handleRequest(req, res) {
  var hI = 0;
  var eI = 0;
  var pf;
  var next = function next(err) {
    if (err) {
      pf = errHandlers[eI++];
    } else {
      pf = handlers[hI++];
    }
    if (!pf) {
      return res.end('not found', 404);
    }
    if (!pf.path || url.parse(req.url).pathname.indexOf(pf.path) === 0) {
      if (pf.fn.length > 3) {
        pf.fn(req, res, err, next);
      } else {
        pf.fn(req, res, next);
      }
    } else {
      next(err);
    }
  };
  next();
}

handleRequest.use = function use(path, fn) {
  if ((typeof path) !== 'string') {
    fn = path;
    path = null;
  }
  if (fn.length > 3) {
    errHandlers.push({
      path: path,
      fn: fn
    });
  } else {
    handlers.push({
      path: path,
      fn: fn
    });
  }
};

module.exports = handleRequest;

Here's how you would use it. Pretty much the same as connect.

var http = require('http');
var serveStatic = require('serve-static');
var send = require('send');
var session = require('cookie-session');
var middleman = require('./app/middleman');
var api = require('./app/api');

middleman.use(session({
  keys: ['#KDIEkd@%vv11', 'xidk4%d']
}));

middleman.use(serveStatic('web'));

api(middleman);

middleman.use(function(req, res, next) {
  send(req, 'web/index.html').pipe(res);
});

var server = http.createServer(middleman);

server.listen(9494);
server.timeout = 2000;

console.log('listening on 9494');

nginx configuration

Published on:

Did a brew install of nginx which puts config files in /usr/local/etc/nginx.

Then simplified the nginx.conf file to this.

events {
    worker_connections  1024;
}
include servers/*;

Added the following to /etc/hosts.

127.0.0.1 note

Added servers/note.conf.

http {
    # So my goal here is to have all static stuff handled by nginx
    # and everything else handled by node app.
    server {
        root /Users/jstein/github/take-note;
        server_name note;
        location / {
            proxy_pass http://localhost:6543;
        }
        # So this allows nginx to serve index.html from
        # /Users/jstein/github/take-note/html if the path matches /
        # exactly. You can have parameters like /?foo=bar&zoo=man#whatever
        location = / {
            root html;
            index  index.html;
        }
        # This location is needed as well to serve index.html as /
        location = /index.html {
            # root /html; # 404 not found
            # root html; # gives me /usr/local/var/www/index.html !?!
            # don't know why i have to put full path in here.
            root /Users/jstein/github/take-note/html;
        }
        # All the rest of our static assets besides index.html should
        # be under specific folders. This is faster than regex and
        # better organization.
        location ^~ /img/ {
            # let the poor users browser our img folder if they want,
            # but then will need to specify the trailing slash.
            autoindex on;
        }
        location ^~ /js/ {
            autoindex on;
        }
        location ^~ /css/ {
            autoindex on;
        }
    }
}

You can browse the app at http://note or http://note/anything/but.the/excluded.folders.

You can get a directory listing of the images, javascript or css at http://img/, http://js/, http://css/. Trailing slash is required.

nginx brew install results

Published on:
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx at login:
    ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
    nginx
==> Summary
?  /usr/local/Cellar/nginx/1.8.0: 7 files, 964K

bash save command before running

Published on:

Imagine you want to save a command to a variable (maybe so you can echo it out) before running it.

There's nothing special about saving it to a variable. However, when you go to run the saved command you may end up with a headache if you don't use eval.

If your command is simple it may work without eval, but more complex commands will start to do strange things.

Use eval!

CMD="curl -s http://google.com"
echo "$CMD"
RESULT=$(eval $CMD)
echo "$RESULT"