Skip to content

Instantly share code, notes, and snippets.

View owenallenaz's full-sized avatar

Owen Allen owenallenaz

View GitHub Profile
@owenallenaz
owenallenaz / application.cfc
Created September 5, 2012 00:52
Throw this in a folder and execute index.cfm and you'll see a multiple datasource error, even though only one datasource is used inside the cftransaction.
<cfcomponent>
<cfset this.name = "mySpecialApp">
<cfset this.datasource = "rc_cms">
<cfset this.ormEnabled = true>
<cffunction name="onError">
<cfdump var="#arguments#">
</cffunction>
</cfcomponent>
@owenallenaz
owenallenaz / application.cfc
Created October 21, 2012 19:02
Performance testing coldfusion - the importance of the debugger
component {
this.name = "testingApp";
public function onRequestStart() {
Application.component1 = CreateObject("component1");
Application.component2 = CreateObject("component2");
Application.component3 = CreateObject("component3");
}
}
@owenallenaz
owenallenaz / application.cfc
Created October 29, 2012 03:39
Scheduling in Coldfusion without cfschedule, server access, or the Coldfusion Administrator
component {
this.name = "testingApp";
public function onApplicationStart() {
// counter to prove the cron.cfm is firing
application.counter = 0;
}
public function onRequestEnd() {
// specify an index for the cache
@owenallenaz
owenallenaz / caught.js
Last active March 5, 2022 15:30
Showing that nodeJS domains do not catch synchronous errors. Hence the common practice is to enclose them in process.nextTick()
var domain = require("domain");
var d = domain.create();
d.on("error", function() {
console.log("domain caught");
});
try {
d.run(function() {
process.nextTick(function() {

Example showing async.waterfall which functions semantically the same as promises.

<script src="http://cdnjs.cloudflare.com/ajax/libs/async/1.22/async.min.js"></script>

<script>
	// waterfall wrapper to try/catch each method in a waterfall
	var catchWaterfall = function(arr, cb) {
		var calls = [];
		arr.forEach(function(val) {
@owenallenaz
owenallenaz / test.md
Created January 13, 2015 01:34
Multiple code blocks bring Dillinger to a halt.
foo
foo
foo
@owenallenaz
owenallenaz / result.txt
Last active September 29, 2015 21:48
Comparing object_sizeof and JSON.stringify
npm: 34ms
json: 7ms
317780 307781
@owenallenaz
owenallenaz / testPool.js
Created January 3, 2016 20:11
Testing worker based socket pooling mongodb
var async = require("async/");
var mongodb = require("mongodb");
var assert = require("assert");
mongodb.MongoClient.connect("mongodb://127.0.0.1/test", {}, function(err, conn) {
if (err) { throw err; }
var collection = conn.collection("test");
var newDocs = [];
@owenallenaz
owenallenaz / README.md
Created July 27, 2016 19:26
process.nextTick is required for proper domain entrance and preventing leaking of domains

In the following test code there are two things to look for.

"in cb 0 0 1" means that it is in the callback after the call to mongodb, and the numbers are "expectedNum actualNum stackSize". The expectedNum and actualNum match, and they do. The stackSize should always be 1. In the event the stackSize is not 1 it means that the domains are not being properly entered and exited. If the stackSize grows domains are leaking.

Another important marker is the "after exit" and "end call" blocks, they should always be undefined. In the event that they are not undefined it means that a domain is lingering after exit, which results in subsequent code being in a domain it shouldn't, as well as a possible memory leak.

From the test file it appears that both setImmediate and process.nextTick() work.

@owenallenaz
owenallenaz / results.txt
Last active October 31, 2016 08:17
Margin of error in polls with introduced bias
------------
test { populationSize: 100000000,
sampleSize: 1000,
bias: 50,
marginOfError: 0.030990321069650117 }
inMarginOfError { yes: 940, no: 60 }
predictedElections { wins: 513, ties: 34, losses: 453 }
------------
test { populationSize: 100000000,
sampleSize: 1000,