Thursday, September 8, 2016

pantsuit! a ui library for the clinton campaign

Medium piece on Pantsuit: The Hillary Clinton UI pattern library.I hadn't heard much about SMACSS (Scalable and Modular Architecture for CSS - reminds me of the Blues Brothers' nemesis SCMODS - State County Municipal Offender Data System) and ITCSS (Inverted Triangle CSS)

In some ways it ends up looking like the "bad version" of Hungarian Notation, with CSS class prefixes ".c-", ".t-" etc used to indicate "component-based", "theme-based", etc. Also some good stuff on inclusivity.

Wednesday, September 7, 2016

the tenth anniversary of the facebook news feed

Facebook’s News Feed Turns 10. Quote:
At first, people hated it. But much as they complained, Facebook’s data logs suggested they came around quickly. The News Feed caused more people to spend more time on Facebook, a trend that picked up speed during the years that followed. Meanwhile, nearly every other social web service, from Twitter to Instagram to Pinterest, adopted the format.
I always thought Facebook followed Twitter, but I guess Twitter was still in the phase of primarily using being an SMS-based notifier in 2006. I wrote about the power of the stream a few years ago (curious I didn't talk about RSS, though that's never been a huge player.) The ability to assemble a page from a bunch of people likely to write stuff you find interesting generally overwhelms the old individual blogosphere, and in fact only the most diverse news websites seem able to maintain an audience to their separate front page.

FB's curation seems unique to me; I think that is the most underappreciated feature of the site. It's much maligned. On other sites, like Twitter, users protest loudly whenever that service fiddles with its traditional "posts from everyone I'm subscribed to, in the order things were posted" model and the service backs down more often than not. On FB, people also pine for a simpler model, but their cries are generally unheeded.  I think most users don't realize what a fire hose an unfiltered set of posts from all their "friends" would be.

Actually, for me Twitter suffers from the same fire hose effect, and so I pay less attention to it. (Also, the 140 limit used to seem cute and pithy, but now feels so confining.) I tried using Twitter lists to get a more limited subset of posts, but those listss are oddly downplayed in main Twitter web UI. And anyway, it fails pretty hard in Zacho Holman's Don't Give Your Users S**t Work kind of way; having to keep up to date groupings of all your contacts is laborious.

Tuesday, September 6, 2016

react 101

For grins I fired up React, went through its nice tutorial.

I'm trying to think about what I feel about it. It feels nice and clean relative to some other things, and I dig that it's a library and not a framework; it does what it does very well. On the other hand, I'm not always convinced what it does is worth doing, namely, it seems like a lot of engineers really hate working directly on the DOM. But, I think I haven't dug far enough to get into React's sweet spot, and many people like it a lot better when they combine it with its Flux implementation "Redux".

Anyway, I decided to practice what I had studied with a simple helper toy (I'm rearranging the physical folder layout for the domains I host on my server, a lot of fiddly bits to keep track of)... to get there I decided to recreate the classic Angular "hey you synch up a text input and its display with no code!!!".   Here's a fiddle I spun off their Hello World that does that.

var Angularish = React.createClass({
getInitialState: function(){
    return { site:'foo' };
  },
  updateSite: function(e){
  this.setState({ site : e.target.value});
  },
  render: function() {
    return <div><input value={this.state.site} onChange={this.updateSite} /> {this.state.site}</div>;
  }
});

ReactDOM.render(
  <Angularish />,
  document.getElementById('container')
);

I dig that React is very event based; I think a lot of other toolkits rely too much on shared memory and watches and you never know when anything is happening. On the other hand, like all these toolkits it's so very finicky with the syntaxes it introduces; the JSX bit (the little html/XML tag like thing) had to be a properly closed tag (even singletons, in the xhtml sense), a tag value has to be either a string or an {expression} and not a mix, etc, and I had to learn you can't just modify this.state directly.

(for my personal future reference here's the https://jsfiddle.net/sfh7ydpw/1/ I made with more detailed steps for the refactoring; I guess revealing the old and new folder structure isn't much of a security risk.)

2018 UPDATE

Guess it's too much to hope that 1 1/2 year old code would still work.
Here's the updated fiddle: https://jsfiddle.net/69z2wepo/171740/
class Angularish extends React.Component {
constructor(props){
  super(props);
    this.updateSite = this.updateSite.bind(this);
    this.state =  { site:'foo' };
  };
  updateSite(e){
  this.setState({ site : e.target.value});
  };
  render() {
    return <div><input value={this.state.site} onChange={this.updateSite} /> {this.state.site}</div>;
  }
};

ReactDOM.render(
  <Angularish />,
  document.getElementById('container')
);
That's closer to the example presented in https://reactjs.org/docs/lifting-state-up.html
That seems like a surprisingly large amount of shitty boilerplate, tho... this.updateSite = this.updateSite.bind(this); is sort of uncool.

build your own bot

In the "to get to, someday, when I get a good idea" - How To Make a Twitter Bot in Under an Hour

Monday, September 5, 2016

the power of Sass

When doing basic website and web application stuff, my instinct has been to always keep things as "close to the metal" as possible. Basic html5, CSS, and javascript (especially flavored with a bit of JQuery and/or Handlebars) is pretty expressive - it's not like someone in 1994 saying everything should be in assembly language. In this view, it's terrific to have fewer layers to dig through when things don't act as expected.

A smart friend and ex-coworker of mine, Marco Morales, once mentioned that he really liked CSS preprocessors. I asked if he could put his finger on why - I wish I could remember how he put it, but my paraphrase is that he found that it let him speak semantically vs syntactically; he could more readily express his intentions in code.

Currently I'm doing a mini-project in Sass to get a feel for it. Skimming through the intro page gives an idea of what it offers. Variables are kind of a no brainer, for color definitions alone (and font families and the like). Nesting is my second favorite; it feels elegant to have the layout of the stylesheet mirror the structure of the DOM (though you have to be careful to think in terms of reuse, you can kind of get over-specific if you're not careful.)

Also, even if you're not using gulp or grunt, you can easily set up a watch to autotranslate your .scss into .scss - and you get a ".map" file to boot, which lets Chrome point you at the rule in the .scss file directly. The latter behavior removes one of my strongest reservations; when you're poking around in the DOM inspector, you don't want to have to manually/mentally unwind the raw CSS back to the actual code you wrote.

BONUS SASS MIXIN:
The <nobr> tag was an early "find" of mine, to make sure a string of text was kept on the same line. Of course, that kind of non-semantic instruction belongs in CSS, not markup...

@mixin nobr() {
    white-space: nowrap;
}

gets the job done, and then a CSS class can say

@include nobr;

Maybe it's not much more convenient than remembering white-space: nowrap; but to a grizzled web veteran such as myself, it's more concise.

Friday, September 2, 2016

note to self: lodash assign();

It wasn't clear to me what the advantage of
_.assign($rootScope.creative, { somejson: ‘map'} );
was vs
$rootScope.creative = { somejson: ‘map’};

What's going on in the first case is actually a merge; useful if $rootScope.creative already existed with some keys, somejson would be a new key in it. (or any old value of somejson would be replaced with 'map')

Learn something new every day! Some days, two things!

Tuesday, August 30, 2016

note to self: node, nvm...

Note to self, when I'm running functional tests (for our Angular 1.X app suite) and see an error like
const builder = require('./builder');
^^^^^
SyntaxError: Use of const in strict mode.


I'm probably on the wrong node version. "nvm" is what controls that, and hopefully by using "nvm alias default X.X.X" I shouldn't see this again.

(bonus... looking into how to test validators that reject or resolve the defereds from a $q defer()

promise = creativeCreateService.validators.impressionTracker3('http://foobar.com');
expect(this.unwrapPromise(promise)).toBeTruthy();

promise = creativeCreateService.validators.impressionTracker3('https://foobar.com');
expect(this.unwrapPromise(promise)).toBeTruthy();

promise = creativeCreateService.validators.impressionTracker3(_.repeat('A',20));
expect(this.unwrapPromiseRejection(promise)).toBe('Impression tracker must start with http:// or https:// if provided');

the code that supports it is:
    self.unwrapPromise = function unwrapPromise(promise) {
        var value;
        promise.then(function (result) {
            value = result;
        });
        self.$digest();
        return value;
    };

    self.unwrapPromiseRejection = function unwrapPromiseRejection(promise) {
        var value;
        promise.catch(function (error) {
            value = error;
        });
        self.$digest();
        return value;
    };

 )