Skip to content

Instantly share code, notes, and snippets.

View nathanaschbacher's full-sized avatar

Nathan Aschbacher nathanaschbacher

View GitHub Profile
@nathanaschbacher
nathanaschbacher / result.html
Created August 6, 2017 04:29
Exposing List Bullet Markers in cmark
<h1>Heading</h1>
<ul>
<li>asterisk list 1</li>
<li>asterisk list 2</li>
</ul>
<ul>
<li>hyphen list 1</li>
<li>hyphen list 2</li>
<li>hyphen list 3</li>
</ul>
@nathanaschbacher
nathanaschbacher / Versioning, Soft Delete, and Restore.md
Last active December 14, 2015 07:39
One simple example of an implementation for a transaction/audit journal and restoring lost/deleted objects for a known key.

##Driver

Customers often request “versioning” or “restore/undo” functionality, as a means of data recovery from user error (as opposed to recovery from hardware failure or data loss errors, at which Riak already excels). If an object is changed or deleted by the end user, but later needs to be restored, is there a way to either look at a transaction log to undo the damage, or to explicitly restore the object to a previous version?

##Overview

This solution provides one simple example of an implementation for a transaction/audit journal and restoring lost/deleted objects for a known key. A separate global transaction/audit journal could also be built to provide an index to get an object key in the case where you don't know it beforehand, but that use case is outside the scope of this document.

The algorithm used here depends only on Riak's key/value functionality for two reasons. First, to show that a solution to the problem can be simply and efficiently implemented with a key/value pattern. Second, relyin

@nathanaschbacher
nathanaschbacher / coercion.js
Created November 2, 2012 17:36
Javascript instance to instance coercion
var inspect = require('util').inspect;
var Class1 = function Class1() {
this.frank = "costanza";
this.__defineGetter__('prop', function() {return 5;});
this.__defineGetter__('fromClass1', function() {return 5;});
}
Class1.prototype.heyThere = function() {}
@nathanaschbacher
nathanaschbacher / replacer_test.js
Created October 26, 2012 02:33
Trying to get a JSON replacer to detect Ctor type...
var Foo = function Foo() {
this.id = 1;
}
var Bar = function Bar(foo) {
this.id = 2;
this.buddies = {};
}
Bar.prototype.toJSON = function() {
@nathanaschbacher
nathanaschbacher / raw_http_res.txt
Created October 9, 2012 22:23
Using the Node.js core HTTP parser for my whims
HTTP/1.1 200 OK
Date: Mon, 19 Jul 2004 16:18:20 GMT
Server: Apache
Last-Modified: Sat, 10 Jul 2004 17:29:19 GMT
ETag: "1d0325-2470-40f0276f"
Accept-Ranges: bytes
Content-Length: 9328
Connection: close
Content-Type: text/html
@nathanaschbacher
nathanaschbacher / raphs_obj.js
Created September 12, 2012 06:12
Quick type couriering lesson for Raph
var MyClass = function MyClass() {
this.property = 'something';
}
var temp = new MyClass();
console.log(temp instanceof MyClass); // prints 'true'
temp = JSON.parse(JSON.stringify(temp));
@nathanaschbacher
nathanaschbacher / benchmark.js
Created June 18, 2012 02:26
Comparing encode/decode performance of MsgPack Node.js implementations against JSON.
var msgpack = require('msgpack-js');
var msgpack2 = require('msgpack2');
var os = require('os');
console.log(" OS: " + os.type() + " " + os.release() + " (" + os.arch() + ")");
console.log("RAM: " + os.totalmem()/1048576 + " MB (total), " + os.freemem()/1048576 + " MB (free)");
console.log("CPU: " + os.cpus()[0].speed + " MHz " + os.cpus()[0].model);
for(var r = 1; r < 4; r++) {
console.log("\nRun #" + r + ":");
@nathanaschbacher
nathanaschbacher / myRole
Created June 8, 2012 19:40
Trying to override defaults in Riak chef cookbook for Riak Control user/pass
override_attributes(
"riak" => {
"control" => {
"enabled" => true,
"userlist" => { "default_user" => ["!merge:user", "!merge:pass", "Pablo", "Turbine2012"]}
}
}
)
@nathanaschbacher
nathanaschbacher / gist:2722971
Created May 18, 2012 03:21
Helping innociv get at his cookies
var cookie_str = "__utmb=7853809.51.10.1337306437; uniquekey=133730899192d4bf232ce84c6";
var uniquekey = cookie_str.split('uniquekey=')[1];
console.log(uniquekey);
@nathanaschbacher
nathanaschbacher / expensive_process.js
Created May 7, 2012 19:23
Trying to work with Node.js child_process
module.exports = function(input, args) {
var expensiveResults = // Do some computationally expensive stuff with input and args...
this.emit('results', expensiveResults);
}