Skip to content

Instantly share code, notes, and snippets.

View kevinohara80's full-sized avatar

Kevin O'Hara kevinohara80

View GitHub Profile
@kevinohara80
kevinohara80 / benchmark.js
Created December 22, 2011 18:47
Javascript eval() benchmark
/* Test Eval */
var eval_string = 'var x = 1;'
+ 'if(x >= 1) {'
+ ' var y = x * 2;'
+ ' if(y==3) { y=3; }'
+ '}';
@kevinohara80
kevinohara80 / MergeTool.cls
Created January 18, 2012 21:05
Mustache merge class for Salesforce
public class MergeTool {
public static String mustacheMerge(String text, SObject obj) {
String p = '\\{\\{([^\\{\\}]*?)\\}\\}';
Pattern patt = Pattern.compile(p);
Matcher mat = patt.matcher(text);
Boolean foundValue = mat.find();
@kevinohara80
kevinohara80 / Async.cls
Created February 10, 2012 16:50
Pass sObjects into future methods for DML - Salesforce
/*
* Author: Kevin O'Hara
* Date: 02/10/2012
*
* Description: The Async class aims to circumvent a limitation of asynchronous (@future)
* methods in Salesforce. The current @future implementation will only allow for primitives
* or collections of primitives to be passed into an @future method. The Async class uses
* native JSON serialization/deserialization to allow for passing an SObject, or List<SObject>
* into an asynchronous method for DML operations. A helper method is also included for making
* the serialization processes simpler.
@kevinohara80
kevinohara80 / app.js
Created May 15, 2012 00:02
node.js proxy to salesforce REST
var fs = require('fs');
var bouncy = require('bouncy');
// load up your instance and port into environment variables
var instance = (process.env.instance) ? process.instance.env : 'na1';
var port = (process.env.port) ? process.env.port : 443;
// self-signed certificate created with openssl
var opts = {
key : fs.readFileSync(__dirname + '/key.pem'),
@kevinohara80
kevinohara80 / gist:3095399
Created July 12, 2012 02:58
setTimeout infinite loop
var vm = require('vm');
var code = function run() {
for(var i=0; i<Infinity; i++) {
i++;
}
};
var sandbox = {
setTimeout: setTimeout
@kevinohara80
kevinohara80 / child.js
Created July 25, 2012 00:53
killing a node.js child process with infinite loop
while(true) {
console.log('blah');
}
@kevinohara80
kevinohara80 / google.sh
Created July 25, 2012 17:16
Silly bash script so you can google something from the command line in Mac OSX
#!/bin/bash
QUERY="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")"
URL="https://www.google.com/search?q=$QUERY"
open $URL
@kevinohara80
kevinohara80 / app.js
Created September 7, 2012 20:38
Simple nested callback example
var express = require('express');
var request = require('request');
var app = module.exports = express();
app.configure(function() {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
@kevinohara80
kevinohara80 / scrape.js
Created October 26, 2012 20:52
Simple node.js WSJ Prime Rate scraper web service
var express = require('express');
var http = require('http');
var path = require('path');
var request = require('request');
var $ = require('cheerio');
var WSJ_PRIME_URL = 'http://www.bankrate.com/rates/interest-rates/wall-street-prime-rate.aspx';
var app = express();
@kevinohara80
kevinohara80 / app.js
Created October 31, 2012 15:38
Move socket.io setup to module for express 3.x
var app = express();
var server = require('http').createServer(app);
var io = require('./ioinit')(server);
server.listen(80);