Skip to content

Instantly share code, notes, and snippets.

@polotek
polotek / candor_variable_test.js
Created March 13, 2012 23:08
Variable scope proposal for candor language
// All variables MUST be initially declared using a keyword.
// Let's use "var"
var g = "global"
h = "bad" // ReferenceError, cannot find undeclared variable "h"
foo() {
var b;
console.log(a) // ReferenceError, cannot find undeclared variable "a"
console.log(b) // "nil", undeclared variables default to nil (since candor doesn't do undefined right?)
@polotek
polotek / 1.js
Created February 4, 2012 07:31
Potential apis for procstreams chdir support
var $p = require('procstreams');
// this is the one I'm leaning towards. simple and intuitive
// cd is a special chain function that changes dir
// and keeps state for subsequent proc chains
$p.cd('tests')
.and('cat test-simple.js')
.pipe('grep data')
.then
@polotek
polotek / from_benchmark.js
Created January 24, 2012 01:36
Deep object clone
// From benchmark.js - https://github.com/bestiejs/benchmark.js/blob/33aca33e4986386d782bbc7c2ab85cf34ed90bd2/benchmark.js
/**
* A deep clone utility.
* @static
* @memberOf Benchmark
* @param {Mixed} value The value to clone.
* @returns {Mixed} The cloned value.
*/
function deepClone(value) {
var accessor,
@polotek
polotek / a_module.js
Created January 17, 2012 20:31
Some node gotchas
exports.somethingAsync = function(callback) {
setTimeout(function() {
callback(null "done");
}, 100);
}
exports.failingAsync = function(callback) {
setTimeout(function() {
callback(new Error("failed"));
}, 100);
var fs = require('fs')
var DataCollector = function(arr) {
this.setFiles(arr)
}
DataCollector.prototype = {
setFiles: function(arr) {
this.files = arr
}
@polotek
polotek / hex2rgb.js
Created January 9, 2012 18:58
Convert hex colors to rgba
/**
* hex2rgb - function for converting hex colors to rgb(a)
*
* Shout out to http://hex2rgba.devoth.com/
*
* @hex (String) - The hex value. Can be prefixed with "#" or not. Can be
* long format (6 chars) or short format (3 chars)
* @opacity (number between 0 and 1) - This is an optional float value that
* will be used for the opacity
*
@polotek
polotek / Base\ File.sublime-settings.json
Created January 9, 2012 06:33
Sublime Text 2 - User File settings
{
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme"
, "fold_buttons": false
, "font_size": 16.0
, "tab_size": 4
, "word_wrap": true
, "rulers": [72]
, "translate_tabs_to_spaces": true
, "wrap_width": 72
, "draw_white_space": "all"
// FAILS=0
// for i in tests/test-*.js; do
// echo $i
// node $i || let FAILS++
// done
// exit $FAILS
var fs = require('fs')
, glob = require('glob')
, $p = require(__dirname + '/..');
diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js
index a057bfc..7476818 100644
--- a/node/handler/APIHandler.js
+++ b/node/handler/APIHandler.js
@@ -75,8 +75,8 @@ exports.handle = function(functionName, fields, req, res)
//check the api key!
if(fields["apikey"] != apikey)
{
- res.send({code: 4, message: "no or wrong API Key", data: null});
- return;
var log4js = require('log4js')
, lsyslog = require('log4js-syslog')
//, syslog = require('node-syslog')
log4js.addAppender(lsyslog.appender(), 'syslog');
//syslog.init("node-syslog", syslog.LOG_PID | syslog.LOG_CONS, syslog.LOG_USER);
var logger = log4js.getLogger('syslog');
setInterval(function() {