Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am ninjascribble on github.
  • I am ninjascript (https://keybase.io/ninjascript) on keybase.
  • I have a public key whose fingerprint is 60AF 9BEF 9AA5 096F 3D02 0DD8 8FCB 002C DD72 1C15

To claim this, I am signing this object:

var config = require('../../config');
var bunyan = require('bunyan');
var logger = bunyan.createLogger({
name: 'CCL',
stream: process.stdout,
level: config.get('LOG_LEVEL')
});
module.exports = {
get: function(module, opts) {
@ninjascribble
ninjascribble / Gruntfile.js
Last active August 29, 2015 14:08
grunt-express-server with grunt-contrib-watch
module.exports = function(grunt) {
var PROJ_ROOT = __dirname;
var BUILD_ROOT = PROJ_ROOT + '/build';
var pkg = grunt.file.readJSON('package.json');
var pkgDependencies = Object.keys(pkg.dependencies).map(function(val) {
return 'node_modules/' + val + '/**';
});
@ninjascribble
ninjascribble / dump_packets.sh
Last active August 29, 2015 14:07
tcp packet dump filtered by port
# -i: The interface to listen on
# -s: Setting snaplen to 0 sets it to the default of 65535
# -B: Buffer size in KiB
# -w: File to write packets to
tcpdump -i en1 -s 0 -B 524288 -w out.pcap dst port 8080
@ninjascribble
ninjascribble / nodejs-intro.md
Last active March 4, 2019 20:36
Introduction to NodeJS
ec2.describeInstances(params, handleResponse);
function handleResponse(err, data){
if (err) {
console.log("Error", err);
return;
}
else {
var status = data.Reservations[0].Instances[0].State;
; (function () {
var Controls = Controls || {};
var fallback = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2N81d/4HwAHYAL7mbvoAwAAAABJRU5ErkJggg==';
var classname = 'deferred-img';
Controls.Image = function (node, options) {
this.state = 'ready';
this.node = node || document.createElement('figure');
if ('document' in this) {
this.document.addEventListener('DOMContentLoaded', function() {
dimsum.parse(document.getElementsByTagName('body')[0]);
});
}
/** NodeJS with Express */
var express = require('express')
, http = require('http')
, app = express();
http.createServer(app).listen(3000);
app.get('/', function(req, res) {
console.log(req.get('user-agent'));
});
@ninjascribble
ninjascribble / user-agent-match.js
Created March 8, 2013 22:07
user agent matching on the client-side
/** User-agent pattern matching */
var browser = 'unknown'
, version = 'unknown'
, patterns = {
android: /android\s([0-9.]*)/i
chrome: /chrome\/([0-9.]*)/i,
firefox: /firefox\/([0-9.]*)/i,
ie: /msie\s([0-9.]*)/i,
ipad: /ipad.version\/([0-9.]*).safari/i,
iphone_4: /iphone\sos\s4.version.mobile\/([0-9.]*).safari/i,