|
title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com |
FOR ENTERTAINMENT PURPOSES ONLY!!! Back-up your data and, when you bike, always wear white. |
| Friday, October 14, 2016 | |
|
Let's talk HTML Fragments in your clipboard when coding on Windows. I've created what's arguably the best Markdown editor on Win10 (if I do say so myself), and wanted it to be more intelligent when I was pasting content that comes from web browsers. That is, in the original version of MarkUpDown, if you copied the text I've got highlighted, below, from DaringFireball...
... and you pasted it into MarkUpDown as a quotation (Ctrl-Shift-V), you'd get unstyled text, like this...
I mean, that's okay-ish. Unfortunately, you'd have to go put in an additional line after each line so that it's not all scrunched into one paragraph. And you lose that Gruber was block-quoting Mossberg. And you lose that "they stop trying" was originally in italics. That stinks. Isn't Markdown really supposed to be shorthand for html? Can't we handle pasting html better than that? Yes, yes we can... TL;DRGo pull the HtmlFragmentHelper, a working, in-progress library for turning HTML Fragment strings into view models with these properties...
There are also several convenience methods to help you get, say, the top- and second-level domains for the HTML Fragment's source URL ( Here's an example:
Read how to use it here. Get it from GitHub, though the only file you really need is here. And here's a quick article on how to get code back into the clipboard as html, which I'm not doing. HTML Fragment FormatWant to paste clipboard HTML as HTML? Enter Microsoft's HTML clipboard format. Instead of using the standard code to read the clipboard's contents, like this...
... now you use this...
But when you look at the contents of
What comes back isn't a string with html source, but an "HTML Fragment" formatted string that looks like this: HTML Fragment from Edge
Wow. No, really, wow. That surprised me. I was using Edge this time instead of Chrome, and whoa. Edge includes the entire page's header. That said, that's really not a horrible idea. We have really good context for this fragment, and if we wanted the original CSS, for example, we know where to get it.
HTML Fragment from ChromeBut let's take a look at where I initially started, with Chrome.
See the difference? Chrome's fragment initially looks much more focused, but also provides much less information about the code's original context. Worse, Chrome's puts all the CSS information inline, and repeating each CSS property inside of each pasted html element makes the source a long ways away from DRY. And that out-of-context, inline CSS is lossily translated, which will cause us some rendering problems that we'll see and discuss in a bit. Original SourceNow Edge's fragment isn't perfect. Here's the original html of that snippet straight from the server...
Look how clean the original is! Why can't we just get that? Chrome's CSS injections and line flattening makes for a much less human readable snippet. Edge is close, but still weird. Take another look. For some reason, Edge's fragment makes every tag uppercase like it's 1998. It also trashes Gruber's original (and thoughtful) whitespace. Also yuck. I mean, Gruber's using Markdown to write Daring Fireball. In a perfect world, I'd take that clipboard's html and turn it back into Markdown when it's pasted into MarkUpDown. How do we get this original source? Start and End FragmentThe important thing to catch is that the HTML Fragment format almost always includes a full html doc with html and body tags after the Though Chrome immediately dives into your selected text (the "true" html fragment) immediately after the If you ignore context like this, though, it's an easy enough feat to take the string and parse out the "true fragment's" html by splitting the entire HTML Fragment string on
When we parse out that html and insert it into our Markdown from Chrome, however, we get some, um, interesting results.
I'm going to wrap these pastes in Edge Parsed Code
Though you should remember that the original source has been smeared together, losing its newlines, and all the tags are strangely capitalized, the source looks pretty nice. It's plain, and adopts the local styling for the most part, but the most important markup is still there -- the blockquote, the italics, links if they'd been included, etc. Chrome Parsed Code
Um, ew. Wha' happen'd? Unfortunately, even though Daring Fireball's entire page has the same styles applied, this inline kludge Chrome performs puts it only in each, in this case, Let's look at all the overhead we have for each
And here's what we have from Chrome's Dev Tools' "Computed" style tab:
But note that that's essentially all from one css file, as properties from user agent stylesheets are simply the browser's defaults:
If you'd like, we can compare the fragment's CSS vs. the stylesheet. Spoiler: It's a mess. Not a lot of matching. Click here to see. Ugly. The bottom line is that With HtmlFragmentHelper, I have a couple of choices. One is to strip all inline styles out, or at least some subset of styling. If I want to maintain as much of the original as possible, I might just blast anything that injects colors into the html, like Or I could normalize the CSS and optionally (via a property on I think I'm going to do the former, though it's not in there as of this writing. That Chrome paste looks horrible as is, though. If only there was an easier way... HTML Fragment from FirefoxThere are certainly other applications that create HTML Clipboard values. I ran into LibreOffice's when using Calc, their spreadsheet app, and its html clipboard doesn't include Start and EndFragment tags. Wonderful, folks, wonderful. But isn't there one glaring omission I might want to add here? You know, I think there is at least one... For fun, let's take a look at Firefox's fragment too. Firefox isn't as popular as it used to be, but it's probably worth taking a look. (Remember that this is all on Windows, and Safari is dead enough by now that I'm not going to bother with v5.)
Oh, so beautiful. Same whitespace as the original, with the added bonus (?) that the final paragraph is also text wrapped. No crazy inline CSS attempted. No header overhead or 1998-style HTML TAGS. You could argue that Chrome is better because it has that inline CSS (yuck!) or Edge because it has the full page headers, but honestly, we're only one step farther away from what Edge gave us. We have the URL here. If we have network access to get CSS, we have network access to read the header and figure out where the CSS lives ourselves. Don't overcomplicate things. Beautiful. Good looking code continues to look good when pasted inline with Markdown. Firefox Parsed CodeAnd Firefox's snippet is just as nice when pasted.
I miss Firefox. Labels: c#, howto, html, long, markdown, markupdown, microsoft, tutorial posted by ruffin at 10/14/2016 11:46:00 AM |
|
| 0 comments | |
| Thursday, October 13, 2016 | |
|
From daringfireball.net:
Exactly right. I've had it do the same thing when I ask Siri to give me directions home, usually because I want to know if there's enough traffic to go an alternate route, and I get the same, "Who are you?!" complaint. But if I open Maps, "Home" is usually the first location listed. QA sucks at Apple. I'm no longer politely questioning it. Spend ten million (he said figuratively) and get the best QA staff in the business, and make sure there's no silo making QAing app interactions an issue. If Maps borks like this, the QA team "for Maps" has to be able to hold Siri and Contacts (or whatever else) accountable. No software ships until this blocking bug is fixed. Good QA will think of and try these sorts of pretty obvious, yet creative, use (not edge, simply "use") cases before you ship. Pitiful. Seriously pitiful. posted by ruffin at 10/13/2016 02:38:00 PM |
|
| 0 comments | |
| Wednesday, October 12, 2016 | |
|
From FiveThirtyEight.com
I'm slowly starting to see what it feels like to be lumped into a demographic. Between this, "locker room talk", and "mansplaining", I'd really like us to find a less socially coercive version of the concept of "gentlemen" that we could use to split the monolithic "men" into at least two groups. Or whatever term you want. I'm probably a little biased here. "Unconventionally sensitive XYs." Whatever. Let's look at Nate Silver's numbers:
For heaven's sake, Nate, there are three polls with men voting for Clinton ahead of Trump. Overall, it's a five point swing average. I guess that means Trump 40% and Clinton 35% or therebouts, with 25% undecided or 3rd partied, just to throw a dart at the wall. That means 7/8th as many men are voting for Clinton as Trump according to Silver's numbers. That's a crudload of XYs. Further, it'd be in spite of 40% of women voting for a major party voting for Trump. (I'm trying to stay reasonably impartial in my presentation here, but wow. Just wow.) In other words, If Trump loses the election, it's not because men voted for him. It's not because women voted against him. It's because the country voted against him, and he lost. And vice versa if Clinton loses. If you wanted to say what Silver tried with more skill, it'd be to say, "If Trump loses the election, it's because his lead with men was larger than Clinton's lead with women." Stop normalizing me, dang it. Every American without two X chromosomes isn't voting for Trump, and, strangely enough, everyone with isn't voting for Clinton. Labels: gruber, Other Stuff, politics posted by ruffin at 10/12/2016 05:43:00 PM |
|
| 0 comments | |
| Tuesday, October 11, 2016 | |
|
From Microsoft's How to: Verify that Strings Are in Valid Email Format
Oh please, heavens, say it isn't so.
EDIT: Some decent advice:
And then from the linked post, "How now to validate email":
As I mentioned on SO...
Just fwiw, I'm also checking for a length of at least one before and after the last
posted by ruffin at 10/11/2016 02:40:00 PM |
|
| 0 comments | |
| Friday, September 23, 2016 | |
|
"At Least 500 Million Yahoo Accounts Hacked in Late 2014" via Macrumors.
Does this surprise anyone at this point? You know, I think if I had a huge cloud company with hundreds of millions of users, I'd consider having at least three sets of teams writing at least the fascade of the software -- the server-side controller methods -- so I could rotate from one to another every sprint or so to throw off would-be hackers. As soon as they made progress hacking one, it'd be replaced by Team 2. By the time we got back around to Team 1, they'd have iterated once or twice, and the hackers would have to, if not start over, pivot. Or maybe any user would have an X% chance of bringing up Team 1, Y% 2, Z% 3 each time they started a session. I'd likely do the same for the users' data, splitting them into into several different databases, and maybe rotating users back and forth. Several different architectures using several different databases, all pitching to a consistent UI and user experience. If you interface well, it's no problem. I realize there are obvious downsides. Maybe Team 2 has a horrible design, and it's easily cracked. That is, I'm in some sense three times as likely to get hacked as before, even if it's a much smaller set of users that's compromised. But even more importantly would seem to be to sniff your network traffic like heck to see when 500 million sets of birthdays had left the network. Bizarre. Ultimately, though, RMS (hrm, apparently not Stallman) is on point: If it's on a computer, in a network, given enough time, it'll eventually be free to anyone else on that network. Networked zeroes and ones want to be free. Labels: encryption, free, rms, security, yahoo posted by ruffin at 9/23/2016 12:19:00 PM |
|
| 0 comments | |
| Wednesday, September 21, 2016 | |
|
From DaringFireball:
I mean, I get the point that each is iconically designed, generally, but, um... Put another way, Andy Warhol would've only included one of those in his pop-art series (mais quelle ironie, non?) posted by ruffin at 9/21/2016 08:38:00 AM |
|
| 0 comments | |
| Monday, September 19, 2016 | |
They had me up until that poorly translated line. (Okay, no, no they didn't. But it was a hilarious/horrible ending. If you're going to pay to robocall tons of people, you might as well translate your threat properly first.) posted by ruffin at 9/19/2016 01:06:00 PM |
|
| 0 comments | |
|
|
All posts can be accessed here: Just the last year o' posts: |
|||||||||||||||||||||
| ||||||||||||||||||||||
|
|
|
|