Skip to content

Instantly share code, notes, and snippets.

@quadrophobiac
quadrophobiac / index.html
Created August 26, 2015 18:59
Electron.js main | renderer concern separation: Menu & Dialog as Edge Case - badly separated
<body>
<div id="container" class="container">
walla walla glub glub
</div>
</body>
@pikesley: @pezholio I'm aware this may not arise in the time remaining on the internship period, but if you do decide to write a gem for something-something-ODI could you alert us?
Sam [3:25 PM]
I can show you build-a-gem-101 in like an hour
Sam [3:25 PM]
Up to and including putting it through travis and publishing to rubygems
stephenfortune [3:25 PM]
I'd love to see the travis part, but I'm interested in being a fly on the wall to the rationale of creation which was discussed earlier
@quadrophobiac
quadrophobiac / gist:f5e9f8a22de3f6dde48e
Created September 1, 2015 13:34
reasoning through CSV file upload refactoring
To clarify if non-blocking fashion means making the CSV parsing CPU bound rather than IO Bound, and to check what refactoring is desired (I had previously moved the parse_csv methods to a separate file, not sure if this is required or not, and if it is required it will require rewriting a lot of tests)
stephenfortune [2:13 PM]
I think that the existing code already has the CSV parsing as CPU bound but it would be helpful to clarify
James Smith [2:14 PM]
in my mind it’s more that no matter how the parsing is bound (CPU or IO), you can’t tell what it’s doing halfway through - and that’s what we need to be able to do.
James Smith [2:14 PM]
if that makes sense. And if it is in fact correct. Might not be
@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)
@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 / 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 / gist:32fc608b5e8a8c23b0d8
Last active September 14, 2015 15:07
emulating production node environment for csvlint-chef
git clone https://github.com/theodi/chef-csvlint.git
cd chef-csvlint/
rbenv local 2.1.6
gem install bundler -v 1.10.5
bundle exec kitchen converge
to sanity check your local env
which ruby # should return /Users/$USERNAME/.rbenv/shims/ruby
which gem # should return /Users/$USERNAME/.rbenv/shims/gem
ruby -v # returns ruby version
@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 / 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 / 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];