Skip to content

Instantly share code, notes, and snippets.

@mattpowell
mattpowell / shell.sh
Created July 26, 2011 06:37
shell alias/fn's/etc...
function ssh() {
#save all args (makes it easier to pass to ssh later)
local all_args=$*
#save path to ssh exec in current $PATH
local ssh_path=$(which ssh)
# host is second to last arg. see ssh -h
@mattpowell
mattpowell / gist:1153857
Created August 18, 2011 11:14
Code to index top 10k sites via phantomjs
will update this later
@mattpowell
mattpowell / CompileSoyTemplate.js
Created September 5, 2011 23:59
Compile Soy Templates on the Fly w/ Node
var fs=require('fs'),
//rawTemplate=fs.readFileSync('/dev/stdin').toString(),
spawn = require('child_process').spawn,
java=spawn(
'java'
,['-jar','build/SoyToJsSrcCompiler.jar','--mattHack','--shouldProvideRequireSoyNamespaces','--codeStyle','concat']
,{
cwd:"/Users/mpowell/Downloads/closure-templates-src/"
//,customFds:[process.stdin,process.stdout,process.stderr]
}
@mattpowell
mattpowell / distance.js
Created August 17, 2012 15:50 — forked from clauswitt/distance.js
Get the distance between two (world) coordinates - a nodejs module
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* Simple node js module to get distance between two coordinates. */
/* */
/* Code transformed from Chris Veness example code - please refer to his website for licensing */
/* questions. */
/* */
/* */
/* Latitude/longitude spherical geodesy formulae & scripts (c) Chris Veness 2002-2011 */
/* - www.movable-type.co.uk/scripts/latlong.html */
@mattpowell
mattpowell / index.js
Last active December 10, 2015 19:59
ssh-tunnel.js - I've been needing to set up tunnels in a couple of random projects lately, so, I thought I'd throw up what I've been using in to a gist so I can add it to my package.json's. I'll eventually make a real npm module out of this, but, want to flesh out and harden a few things first...
var Util = require('util'),
Ee = require('events').EventEmitter,
Fs = require('fs'),
Spawn = require('child_process').exec,
Crypto = require('crypto');
//this probably won't work well on other systems. also, this technique seems pretty fragile
function isRunning(pid, callback) {
Spawn('ps -hp ' + pid +' -o command', function(err, stdout) {
var isSuccess = !err && stdout.toString().indexOf('ssh') > -1;
@mattpowell
mattpowell / index.js
Created February 18, 2013 08:51
restli - While working w/ some rest.li services I found I needed to translate some of their data-structs to more usable/logical components... in JavaScript. This is what I have so far and it has been serving me well; however, I will concede that there may be a better approach :) Either case, creating this gist allows me to `npm install` without …
/**
TODO: these come back from restli requests... should we do anything w/ them?
X-LinkedIn-Type: com.linkedin.restli.common.ActionResponse
X-LinkedIn-Sub-Type: com.linkedin.janus.rest.api.JsonContentModel
*/
var keys = {
'0': 'string',
'1': 'int',
@mattpowell
mattpowell / index.js
Created February 18, 2013 09:02
sqlitecache - A super basic layer on top of sqlite for caching certain types of requests. Works well as a replacement (especially in dev) for memcached when working w/ limited/throttled services (like Embed.ly or LinkedIn's API).
var Sqlite = require('sqlite3').verbose();
function SqliteCache( config ) {
config = config || {};
this.db = new Sqlite.Database( config.db || void(0)); // will create an in-memory store if path is undefined.
this.bucket = config.bucket || '';
this.duration = config.duration || 1000 * 60 * 5;//defaults to 5 minutes
//initialize table
this.db.run("CREATE TABLE IF NOT EXISTS cache (key TEXT PRIMARY KEY ASC, expires INTEGER, result TEXT)");
@mattpowell
mattpowell / README.md
Last active June 2, 2016 22:31
Extracts info from a Cheerio-based DOM using a json object.

Usage

Code:

var DomExtractor = require('./index.js');
var html = '<h3 data-universe="marvel">List of Superheros:</h3><ul class="heros"><li data-id="1"><span>Spiderman<span></li><li data-id="2"><span>Captain America<span></li><ul>';
var query = {
      universe: 'h3[data-universe]',
 heros: {
@mattpowell
mattpowell / !Monaco-and-Snowpack.md
Last active September 6, 2021 06:40
Monaco Editor (VS Code) and Snowpack

Monaco Editor and Snowpack Example

Use Snowpack to extract and build JavaScript Modules and run in the browser.

Installation

  • Download and unzip this gist
  • npm install
  • npm run snowpack # optional, should run by default during npm install
  • npm run serve

About