Skip to content

Instantly share code, notes, and snippets.

<form onsubmit="return false;" class="pure-form" style="border-top: 1px solid #eee;border-bottom:1px solid #eee;background:#fafafa;margin:30px 0;padding:20px 10px;text-align:center">
<input id="user-input" autofocus type="text" placeholder="Type a word ..." style="width:100%;max-width:600px;outline:0" />
</form>
@johntitus
johntitus / request.js
Created November 10, 2016 00:34
How to use the Node.js Request module with defaults
var request = require('request').defaults({
headers: {
'X-header1': myvar,
'Content-Type': 'application/json'
}
});
// Now request will automatically send the headers specified above on every request.
request.get('http://www.example.com', function(err, resp, body){
//...
<results>
<result>
<title>Bob</title>
<description>A story about Bob</description>
</result>
<result>
<title>Alice</title>
<description>A story about Alice</description>
</result>
</results>
@johntitus
johntitus / xml.xml
Last active February 18, 2016 18:28
<results>
<result policy="bobPolicy">
<title>Bob</title>
<description>A story about Bob</description>
</result>
<result policy="alicePolicy">
<title>Alice</title>
<description>A story about Alice</description>
</result>
</results>
{ results : [
{ title : 'Bob', description : 'A story about bob.'},
{ title : 'Alice', description : 'A story about Alice.'}
]
}
@johntitus
johntitus / lambdaip.js
Created October 2, 2015 00:48
Get the public ip address of an AWS Lambda
var http = require('http');
exports.handler = function( event, context ){
http.get({'host': 'api.ipify.org', 'port': 80, 'path': '/'}, function(resp) {
resp.on('data', function(ip) {
context.succeed(ip.toString());
});
resp.on('error', context.fail);
});
};
@johntitus
johntitus / gist:1cbdaa5f0f3a9afbe35f
Created February 23, 2015 19:00
Multiple evaluates in PhantomJS work fine
var page = require('webpage').create();
var click = function( selector, callback ){
page.evaluate( function( selector ) {
var element = document.querySelector(selector);
var event = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
element.dispatchEvent(event);
return true;
}, selector );
@johntitus
johntitus / gist:8bb14c69f89e5241057f
Created February 23, 2015 18:19
Second page.evaluate is slow
var phantom = require('phantom');
var debug = require('debug')('phantom');
var p;
var click = function( selector, callback ){
var self = this;
p.evaluate( function( selector ) {
var element = document.querySelector(selector);
@johntitus
johntitus / gist:01b4b38c2f5061f61ef6
Created January 21, 2015 14:51
Finding Interesting Words with Words API
// This script finds "interesting words using Words API.
// https://www.wordsapi.com
var unirest = require('unirest'),
_ = require('underscore'),
async = require('async'),
fs = require('fs');
// Results will be stored in the words object.
var words = {};
@johntitus
johntitus / nodeWatermark.js
Created November 5, 2012 18:16
(Node.js) Watermark an image using ImageMagick from two streams.
/**
* Dependencies
*/
var fs = require('fs'),
request = require('request'),
cp = require('child_process'),
spawn = cp.spawn;
var image = request("http://medpreps.com/wp-content/uploads/2012/05/cma-practice-test.jpg");
var wm = request("https://github.com/linse/Gibberbot/diff_blob/f096f6d94b3fb745975ea5f61f5a43b47098598b/res/drawable/droid_watermark.png?raw=true");