Skip to content

Instantly share code, notes, and snippets.

@lkptrzk
lkptrzk / script-boilerplate.js
Created October 23, 2015 16:46
nodejs script boilerplate
var Async = require('async');
exports.script = function () {
var options = internals.parseOptions();
var context = {
options: options,
state: {},
var Aws = require('aws-sdk');
var DynamoClient = require('dynamodb-doc').DynamoDB;
// This script uses the Shared Credentials File. See reference below for more:
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
Aws.config.update({ region: 'us-east-1' });
var internals = {};
@lkptrzk
lkptrzk / fetch-s3-folder.js
Created November 14, 2014 00:48
fetch all files from s3 bucket with given prefix and stream them to disk
// fetch-s3-folder.js
//
// usage: node fetch-s3-folder.js bucketName folderPath
// ex: node fetcb-s3-folder.js our-bucket /my-folder/cool-subfolder
//
// to install dependencies, run following in same folder as this script:
// mkdir node_modules && npm install async knox mkdirp
//
// also expects a `config.json` in same directory with AWS credentials
var SerialPort = require('serialport').SerialPort;
var util = require('util');
if (!process.argv[2]) {
console.error('specify device');
process.exit(1);
}
var PATH = process.argv[2];
var DATA = {};
@lkptrzk
lkptrzk / check-git
Created November 9, 2014 14:57
check state of a git repo
#!/bin/bash
git pull && \
git remote prune origin && \
git status && \
git stash list && \
git branch -a
@lkptrzk
lkptrzk / plain-js-date-math.js
Created May 28, 2014 16:58
one way to do it...
var thirtyDays = 1000 * 60 * 60 * 24 * 30;
var today = new Number(new Date());
new Date(today + thirtyDays);
@lkptrzk
lkptrzk / pretty-json
Created May 15, 2014 16:18
pretty print json from stdin
#!/usr/bin/env node
var concat = require('concat-stream');
process.stdin.pipe(concat(function (data) {
var json = JSON.parse(data);
var str = JSON.stringify(json, null, 2);
@lkptrzk
lkptrzk / node-irc-bot.js
Last active August 29, 2015 14:00
node irc bot
// quick sketch based on http://davidwalsh.name/nodejs-irc
var Irc = require('irc')
var settings = {
channels: [
'#node.js'
],
server: 'irc.freenode.net',
botName: 'idlebot'
@lkptrzk
lkptrzk / get-spumko-makefiles.js
Last active August 29, 2015 13:58
get-spumko-makefiles.js
// node get-spumko-makefiles.js && vim *.Makefile
var Async = require('async')
var Fs = require('fs')
var Request = require('request')
Request({
uri: 'https://api.github.com/orgs/spumko/repos',
headers: {
'User-Agent': ' '
@lkptrzk
lkptrzk / index.js
Created March 13, 2014 19:50
requirebin sketch
console.log('logging:')
console.log(asdf)
console.log(foo)
function asdf () {
// noop
}
var foo = function () {
// asdf