Skip to content

Instantly share code, notes, and snippets.

@quadrophobiac
quadrophobiac / .sh
Last active May 16, 2017 12:51
CURLs for the ODI's Bothan
## practical examples of how to use the Bothan API https://demo.bothan.io/documentation
#single values
curl -X POST -H "Content-Type: application/json" -d '{"time": "2017-03-12","value": 500}' "https://username:password@demo.bothan.io/metrics/replicate"
#multiple values
curl -X POST -H "Content-Type: application/json" -d '{"time": "2017-03-12","value": {"total": {"value1": 123,"value2": 213,"value4": 535}}}' "https://username:password@demo.bothan.io/metrics/replicate-multi-val"
#value with annual and ytd targets
curl -X POST -H "Content-Type: application/json" -d '{"time": "2017-03-12","value": {"actual": 1091000,"annual_target": 2862000,"ytd_target": 1368000}}' "https://username:password@demo.bothan.io/metrics/replcate-ytd-targets"
@quadrophobiac
quadrophobiac / AnonymousPrototypeInvocation.js
Last active December 15, 2015 20:57
node module patterns quandry for server
var Server = require('./../AnonymousPrototypeModule.js');
console.log("this server is a "+typeof Server); // returns this server is a function
console.log(Object.getOwnPropertyNames(Server)); // [ 'length', 'name', 'arguments', 'caller', 'prototype' ]
var server = new Server();
console.log("this invoked server is a "+typeof server); // returns this invoked server is a object
console.log(Object.getOwnPropertyNames(server)); // returns []
@quadrophobiac
quadrophobiac / instructions.md
Last active November 24, 2015 16:21
Atom Regexes for File Conversions
omit page numbers - regex that captures any number preceded and followed by a new line
Set up
  1. Download Atom
  2. Find in buffer (aka CMD+F or similar)
  3. toggle use regex option - should look like .*
  4. enter commands below, and leave the replace box blank

options: (\n\d+\n) # any amount of numbers wrapped in new lines, should remove page numbers

@quadrophobiac
quadrophobiac / application-view-resumable-code.js
Created September 23, 2015 15:05
Rails & Bootstrap Magic in CSvlint Alphas
var r = new Resumable({
// resumable initialised
});
$('#standard_files').addClass('hidden');
// Resumable.js isn't supported, fall back on a different method
if(!r.support) {
console.log("support error");
$('#standard_files').removeClass('hidden');
$('.resumable-error').show();
} else {
@quadrophobiac
quadrophobiac / validation.js
Created September 23, 2015 10:33
Promise Raising as Uncaught in Comma Chameleon
// line 54-86, feature-prebaked
// inclusion of printErrs is because type returns as undefined
function displayValidationMessages(validation) {
console.log(JSON.stringify(validation,null, 2));
var $messagePanel = $('#message-panel');
$messagePanel.html("<h4>Validation results <img src='" + validation.badges.png +"' /></h4>");
var resultsTemplate = _.template('<p><%= validation.errors.length %> errors, <%= validation.warnings.length %> warnings and <%= validation.info.length %> info messages:</p>')
$messagePanel.append(resultsTemplate({'validation': validation}));
//TODO the errorText function below is truncated and isn't doing what it should be doing
var printErrs = validation.errors[0];
@quadrophobiac
quadrophobiac / hot.js
Created September 17, 2015 10:59
Cosmetic Change to Handsontable in Comma Chameleon
var hot = new Handsontable(container, {
colHeaders: true,
- rowHeaders: true,
+ rowHeaders: function(index) {
+ if (index === 0){
+ return "Header";
+ } else {
+ return index;
+ }
+ },
@quadrophobiac
quadrophobiac / datapackage.js
Last active September 17, 2015 08:56
code written for Comma Chameleon in electron JS - inexplicable persistence of data
var exportdata = function() {
var window = BrowserWindow.getFocusedWindow();
datapackage = new BrowserWindow({width: 450, height: 600, 'always-on-top': true});
datapackage.loadUrl('file://' + __dirname + '/../comma-chameleon/views/datapackage.html');
datapackage.on('closed', function() {
datapackage = null;
});
@quadrophobiac
quadrophobiac / enumerator_pseudocode.rb
Last active September 13, 2015 19:26
Suitability of Lazy Enumeration in CSVlint
# ref - http://blog.honeybadger.io/using-lazy-enumerators-to-work-with-large-files-in-ruby/
# The Lazy Enumerator class contains a number of built in collection and mapping methods
# e.g. ```map, flat_map, select, reject, grep, zip, take, take_while, drop, drop_while, cycle```
# the basic way that lazy evaluation works with the above methods is like so
enum.lazy.select {|variable| (conditional_eval_of_variable) } # returns an array where the eval returns true
# in pseudo code fashion I would imagine it would proceed like this
CSVlintValidator.select { |validation| output(@ErrorCollector) if !validation.valid? } # returns object or array for the rows which raise messages
# validation.valid? could be rewritten in Csvlint::ErrorCollector to be errors.empty? && warnings.empty?
# ~ && info_messages.empty? or the output could only happen when an error arises, informing the user that there is already
# one error detected and do they wish to continue evaluating in 'lazy' fashion
@quadrophobiac
quadrophobiac / validate.rb
Created September 11, 2015 19:08
strange conditional logic in CSVLint
if type == :stray_quote && !wrapper.line.match(csv.row_sep)
# above evaluates to true && false
# however it is false only by placing bang against wrapper.line.match(csv.row_sep) which evals to either
# nil or MatchData - seems a strange way to order flow
# basically it want's whatever is matched against the row_sep (generated from the CSV.new of data inputted) to not match
# because if it matches then bang generates a false and only a stray_quote is logged
build_errors(:line_breaks, :structure)
# the tests that exist pass \r rather than \r\n when testing for line breaks
@quadrophobiac
quadrophobiac / csvlint_validation_exception_spec.rb
Created September 11, 2015 16:45
error catching for csvlint
context "error matching tests" do
it "checks for blank rows" do
# stream = StringIO.new('"","",') # this returns blank_rows
# stream = StringIO.new('"","",\r\n"","",\r\n') # this returns :whitespace
# stream = StringIO.new('"a",“b“,"c"""') # should return stray quotes but doesn't - there isn't a stray quote test in current code base
# stream = StringIO.new("\"a,\"b\",\"c\"\n") # returns unclosed quotes
validator = Csvlint::Validator.new(stream,"header" => false) # dialect options to avoid one liners being read as header
expect(validator.valid?).to eql(false)