Skip to content

Instantly share code, notes, and snippets.

View markcode's full-sized avatar

Mark Ashcroft markcode

View GitHub Profile
@markcode
markcode / jotr.pm
Created February 9, 2012 07:19
Jot - Perl pixel server stored to Scribe
package Analumic::Jotr;
# *
# * Analumic - Analytics Statistics Logger "Jot".
# * Perl (mod_perl module) pixel server stored to Scribe and enhanced by GeoIP.
# * See web server config info (web_server_config.conf).
# * http://analumic.com
# *
use strict;
#these modules are now loaded in apache config
@markcode
markcode / _log-min.js
Created August 14, 2013 12:46
node.js: use for debugging app using console.log and util.inspect.
var LOGGING = 'debug'; // debug, alert, silent.
function _log(a,b){"debug"===LOGGING&&void 0!==b?console.log("debug - "+a+" > "+require("util").inspect(b,!0,99,!0)):"debug"===LOGGING&&void 0===b?console.log(a):"alert"===LOGGING&&console.log(a)};
@markcode
markcode / msg-codec-serialize.js
Last active December 21, 2015 03:58
Codec prototype for serializing messages in: json, msgpack or msgpack-js.
// require these modules: 'msgpack' (binding), 'msgpack-js' (pure javascript), JSON node.js built in function.
// config
var config = [];
config["messenger_codec"] = 'json'; // json, msgpack, msgpack-js
// codec for messenger to use: json, msgpack, msgpack-js.
var Codec = function() { };
@markcode
markcode / launch.js
Created August 22, 2013 22:03
Kurunt Launch
//
// Kurunt Launch
//
// Launches node.js apps through /etc/init.d/.
// Version: 0.1
// Author: Mark W. B. Ashcroft
//
// Copyright (c) 2013 Mark W. B. Ashcroft.
// Copyright (c) 2013 Kurunt.
//
@markcode
markcode / html_get_http_header
Created November 28, 2013 00:32
html, get http header values
// this works
function loadXMLDoc(url) {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
@markcode
markcode / jquery_each_json
Created November 28, 2013 01:29
get json and for each using jquery
$.getJSON('http://localhost:8888/data.json', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
@markcode
markcode / logging.js
Created December 18, 2013 23:28
Logging function for: quiet, benchmarking, debug and dumping.
// logging, dump, function. Can set: gconfig['loggin'] = 'quiet' || 'benchmarking' || 'debug'
var log = function(txt, benchmarking, dump) {
if ( dump != undefined ) {
console.log(txt + ' >> ' + require('util').inspect(dump, true, 99, true));
} else if ( gconfig['loging'] === 'benchmarking' ) {
if ( benchmarking === true ) {
console.log(txt);
}
} else if ( gconfig['loging'] === 'debug' ) {
@markcode
markcode / reprint.js
Last active March 3, 2024 15:01
node.js print resfeshing over the same line
var util = require('util');
var x = 0;
setInterval(function() {
process.stdout.write('hello: ' + x + '\r'); // needs return '/r'
// util.print('hello: ' + x + '\r'); // could use this too
x++;
}, 1000);
@markcode
markcode / Byte2Bits.js
Last active December 6, 2015 23:09
Node.js - Convert Byte (octet) to Bits Funcation
function Byte2Bits(octet) {
var bits = [];
var i = 0;
for ( i = 0; i < 8; i++ ) {
bits.push(octet >> 7 - i & 1);
}
return bits;
}
@markcode
markcode / index.js
Created May 18, 2017 09:45
Benchmark speed and standard deviation between md5 (2 bytes of) and crc for a hash key.
"use strict";
//
// Benchmark speed and standard deviation between md5 (2 bytes of) and crc for a hash key.
//
// Version: 0.0.1
// Author: Mark W. B. Ashcroft (mark [at] fluidecho [dot] com)
// License: MIT or Apache 2.0.
//
// Copyright (c) 2017 Mark W. B. Ashcroft.
// Copyright (c) 2017 FluidEcho.