klenwell information services : SpecialCocktailNapkin

online cocktail napkin

links and notes for later organization

Rubocop with Minitest

# lib/tasks/test.rake

require 'rubocop/rake_task'

# Add additional test suite definitions to the default test task here
namespace :test do
  desc 'Run RuboCop on all ruby source directories'
  RuboCop::RakeTask.new(:rubocop) do |task|
    task.patterns = ['lib/**/*.rb', 'app/**/*.rb', 'test/**/*.rb']

    # Abort on failures (fix your code first)
    task.fail_on_error = false

Rake::Task[:test].enhance ['test:rubocop']

JSHint with Minitest

# lib/tasks/jshint.rake

desc "jshint"
task :jshint do
  puts "# Running jshint:"
  puts `jshint app/assets/javascripts/*`
  raise "jshint did not run successfully" if ($?.exitstatus != 0)
  puts "No errors found.\n\n"

Rake::Task[:test].enhance [:jshint]

Rails Styling


Wikka Formatter

 *  https://gist.github.com/klenwell/d8e0555986f6c4639c51
 *  formatters/wikka_to_html.php

class WikkaToHtmlFormatter {

    public __construct($wikka) {
        $this->wikka = $wikka;

    public function to_xhtml($wikka_markup) {
        $wikka_markup = $this->normalize_line_breaks($wikka_markup);
        $xhtml = $this->wwml_to_xhtml($wikka_markup);
        $xhtml = $this->snip_last_br_tag($xhtml);
        $xhtml = $this->close_open_tags($xhtml);
        $xhtml = $this->enhance_xhtml($xhtml);
        $xhtml = $this->inject_actions($xhtml);
        return $xhtml;

    private function normalize_line_breaks($wikka_markup) {}
    private function wwml_to_xhtml($wikka_markup) {}
    private function snip_last_br_tag($xhtml) {}
    private function close_open_tags($xhtml) {}
    private function enhance_xhtml($xhtml) {}
    private function inject_actions($xhtml) {}

 *  handlers/api/api.php
 *  http://localhost:3000/wikka.php?wakka=FormattingRules/api

$test_markup = $this->page['body'];

// Old formatter: formatters/wakka.php
$expected = $this->Format($test_markup, 'wakka', 'page');

// New formatter: formatters/wikka_to_html.php
$formatter = new WikkaToHtmlFormatter($this);
$xhtml = $formatter->to_xhtml($test_markup);

if ( $xhtml === $expected ) {
    die('new formatter passed');
else {
    print '<h4>Failed</h4>';
    print '<hr />';
    printf('<h2>New Formatter</h2><pre>%s</pre>',
    die('new formatter failed');

On Long Hours and Productivity

Comment on article that got flagged on HN:

> Studies shown if you lower your daily work hours from 20 to 8 and work 5 days instead of 6, your productivity increases!

#1 reaffirms something I strongly believe (whether on the basis of personal experience, something I've read before, or mere wishful thinking, I don't recall). It is a sensible constraint that came to mind in reading all the Amazon horror stories.

While reading that New York Times article I checked out the link to their 14 sacred principles. The funny thing was that I agreed with most of them. They were all ideas that occurred to me over the course of my career working independently, with small companies, and especially now in corp.

The one thing that was missing, I felt, was a Rule #15: Never work more than 8 hours a day.

Without it, it's no surprise you end up with the sort of dystopian workplace documented in the Times article and all over Reddit and HN here.

But then I suppose, as has been pointed before, long work hours are more about cultural signaling and penny-wise-pound-foolish accounting than really improving productivity.



Wikka Refactor

Bundle, Rake, and rbenv

See http://benscheirman.com/2013/12/using-rbenv-in-cron-jobs/

Rails DOM Test with Nokogiri

Because assert_select kinda sucks sometimes:
	# Collect rows and shift off header row. I'm using Nokogiri instead of css_select
	# because I need to drill down to text node, which css_select makes hard if not
	# impossible. Better element identifiers in template could have probably avoided this.
	page = Nokogiri::HTML(@response.body)
	transaction_rows = page.css("table#transactions tr")

Unpublished Comment


I was hoping her model would get past the obvious shortcomings she glosses citing Yelp review at the end. I don't think Bernard Mandeville's poem is going to get us there.

The Righteous Society model sounds a lot like what we got on the Internet right now. See China's Human Search Engine for examples of this model in action:

I'm all for heroic efforts to spread justice. It's just that the old-fashioned techniques, marching in the streets, maybe even throwing a trash can through a shop window, seem like more measured approaches than a lot of what I seen come from the internet.

Interview Portfolio

Google Drive

Wikka Before and After

Before: wikka.php
After: wikka.php

Python with Jenkins


Quick Temp Rails Controller

# app/controllers/temps_controller.rb
# Add to routes.rb:
#   resources :accounts, only: [:index]
class TempsController < ApplicationController

  # GET /
  def index
	render html: 'hello world', layout: "application"


Comments [Hide comments/form]
There are no comments.