Tag Archives: code

codespell: Prevents embarrassing code

Today is Pick on Kernel Developers’ Spelling Abilities Day.

2014-07-31-lv-c5551-codespell

As if they didn’t have enough work to do, along comes me and codespell to harass them about their spelling mistakes. :\

Spelling is sometimes important though, so a spellchecker specific to code is probably a good idea. And since I have no ability when it comes to creating software, I have to have something to complain about. O_o

codespell is neat stuff, and I don’t say that just because it has a lot of color in it. For one thing, you can step through a folder of code word-by-word, and codespell will give you the chance to correct things interactively.

2014-07-31-lv-c5551-codespell-corrx

Aside from that, codespell can write corrections directly into files, print a summary of the changes it suggested, and access custom dictionaries. There are quite a few other options, include one to — gasp! — strip out all that lovely color.

As I understand it, codespell’s main reference is part of the release, but is derived from Wikipedia’s page of common misspellings for machines (and-or technology).

If you really want to put codespell through its paces, I would suggest matching it head-to-head against something like aspell (or ispell or …). The difficulty in that, of course, is that aspell (or ispell or …) is likely to stumble over any portion of code that doesn’t look like a standard English (or other language) word. Which means codespell might end up saving you time.

And now for my regularly scheduled pity party, where I insist I would make much more use of codespell if I had a stick of programming ability. I’ll spare you that this time; if I had spent a tenth of the time learning to write software as I have moaning about my inability, I’d have come up with something vaguely usable by now. πŸ™„

cloc: Clock your code

Line-counting utilities are not a new thing for K.Mandla; there have been a few of these available for a while. codemetre comes to mind, as does sloccount. Even wc could fit in that category.

Here’s cloc:

2014-07-28-lv-c5551-cloc

cloc has a couple of features I like. For one, cloc can work straightaway on a compressed file. You don’t need to extract an archive before cloc does its thing; cloc will handle the decompression automatically. And if it runs into trouble, you can assert your biological superiority and tell it which decompresser to use.

cloc also has some built-in diff tools, which might not sound like a wonderful idea at first. What that means though, is that it can look for differences between versions of programs, and report on those. This might be useful if you have an axe to grind with a developer. 😑

And cloc carries a lot of filtering options, on everything from regex strings to specific programming languages to hidden Windows files. That might have saved me a little time when counting lines in the 3.15.6 kernel, above. 😐

The sad part of this little exposΓ© is that I have so very, very little coding ability that cloc (or for that matter, codemetre or sloccount) isn’t something I’ll likely use. Unless, of course, I’m counting lines of text in a smarmy blog. ^^’

wdiff, cwdiff and dwdiff: Since I mentioned it. …

I just mentioned colordiff, but left out one thing it can do: colorize the output of wdiff. And what is wdiff, you say?

2014-07-27-lv-c5551-wdiff-colordiff

That should give you an idea. wdiff works in the same way as diff, but at a word-by-word level. If you look closely in the upper half of that image, the differences in lines of text are offset with brackets and curly braces.

That may be enough for you, but you have to admit that the second half, where the output was piped through colordiff, is much easier to scan. The man page says you should add -n to wdiff before sending it through colordiff, but as you can see there, it worked fine in that example.

wdiff works well with colordiff, but you might prefer cwdiff, as opposed to piping things through one another.

2014-07-27-lv-c5551-cwdiff

cwdiff does much of what wdiff + colordiff offers, and simplifies the process quite a bit. There are a few added options too, including one to subtract the color from the output — meaning you get pretty much what wdiff had originally.

By default, cwdiff’s output is simplified somewhat from what wdiff creates, or what wdiff produces through colordiff. It’s not necessarily better, but it is a tiny bit … different. πŸ™„

dwdiff is the last on the list that I feel obligated to mention at this point. By now, you’ll probably feel like dwdiff doesn’t really do anything that wdiff, colordiff, cwdiff or even just diff could handle.

2014-07-27-lv-c5551-dwdiff

dwdiff also plucks out differences between words of files, and has a -c flag to inject color into the output. The distinguishing point between dwdiff and the others, as I see it, is its ability to set specific delimiters while searching.

I couldn’t think of a good case example for that, and I searched around in hopes of finding something to test it. Nothing handy appeared though, and most examples for dwdiff seemed to generate the same output as wdiff alone or cwdiff might get you.

So the final questions become academic: First, do you want colorized output (say yes! say yes!); and second, do you need control over specific delimiters when comparing files?

If you answer yes to the first, cwdiff might be the best tool, although you can get the same results from wdiff alone if you have colordiff available. If you answer yes to the second, you’ll most likely want dwdiff regardless of your preference for color.

And if neither of those questions is important … well, then you can probably get through the day with just the original diff tool. No shame in that. πŸ˜‰

colordiff: A difference in color

Remember my unnatural predilection for anything in color? You have to admit I’m right on this point. After all, which would you rather look at?

2014-07-27-lv-c5551-colordiff

At the top, diff. At the bottom, colordiff. The choice should be an easy one.

The man page describes colordiff as a perl wrapper for diff, and that’s very true. As a matter of fact, it’s so tightly wound around diff that if you ask for colordiff --help, you get the output from diff --help. πŸ˜• And I know there’s no difference because I used colordiff to show the difference between diff --help and colordiff --help, and there was no difference. See what I mean? ❓

2014-07-27-lv-c5551-colordiff-diff-diff

Clear as mud.

colordiff has its own rc file, installed by default at /etc/colordiff in the Arch version. I would advise you to copy that into .colordiffrc, and customize the colors there, but if you’re just one of those weirdos who runs a black-on-white terminal emulator, you’d do just as well to copy /etc/colordiff-lightbg into your .colordiffrc file instead.

That’s about all I can think about with colordiff. It stays very tight to the original tool while still giving you a small measure of customization, and that will probably keep you happy in your pursuit of differences. πŸ˜‰

howdoi: Because the Internet knows more than you

I picked howdoi as a complement to betty today, because in some ways, they both do similar things.

2014-07-21-6m47421-howdoi

Whereas betty would reply with set answers (provided she knew the questions πŸ™„ ), howdoi acts as a conduit between you and that vast cesspool in the sky, The Internet. Give howdoi a few key terms, and it will give back what it hopes is an answer to your conundrum.

howdoi is aimed mostly at coders, as I understand it, but as you can see, it will handle system admin or just bash issues too. I even asked it a question or two about vim, and I think it gave the right answer. It’s hard to tell with vim. 😐 I didn’t ask it for the weather in London. πŸ™„

If you tinker with howdoi for a few minutes, you’ll see what it’s doing: searching through StackOverflow, and replying with a best-case answer formatted for your screen. If you ask nicely (in other words, use the -a and/or the -c flags) it will prettify the result, and give a link to where it was found.

I can’t fault howdoi very much, since for the most part, it seems to give the right answers. On the other hand, as you can see above, it doesn’t really know what you’re asking — I don’t think that is the right command to add a user with bash. πŸ˜‰ So remember: It’s just handing down the wisdom of the unwashed masses, and hoping you will be pacified.

In that way, howdoi is really just a well-designed search utility for the console, like surfraw is and a few other tools do. I’d have to check to see how it’s designed, and whether it actually looks through more than just StackOverflow; I’ve only seen links to that site.

So in all, I can’t complain about howdoi the same way I do about betty. If you’re a coder and you sometimes find yourself fishing for snippets, howdoi is a short and quick tool that gives out just the right amount of info. On the other hand, be aware that while the Internet will always know more than you, what it knows isn’t necessarily something you want to learn.

P.S., Yes, there is an elvi for StackOverflow in surfraw. In case you were headed there next to check. …

wgetpaste: A healthy collection of features

I have a link to the home page for wgetpaste, but it gives me nothing but a 404. Perhaps it has moved.

2014-06-25-6m47421-wgetpaste-01 2014-06-25-6m47421-wgetpaste-02

Ordinarily I’d look to the Debian repositories for a backup source package, but it’s not in Debian. So this time, Arch saves the day. πŸ˜‰

wgetpaste uploads text to pastebin-ish services, much like curlpaste or elmer or others. Judging by the -S flag, wgetpaste supports about five or six upload hosts, but I’ll be honest and admit I didn’t try all of them.

As far as code languages, you have your choice of about 180 that wgetpaste claims to support — and no, I didn’t check all of those either. Some of them I never even heard of. 😯

But as you can see, a quick default run through wgetpaste sent my test file out into the wild blue yonder, and it arrived safely and intact at bpaste.net, the default host.

There are a couple of other options worth mentioning. wgetpaste can use tee to show you what it’s sending out. It can also interface with the X clipboard, like uppity does. And it has an option to send a URL to tinyurl.com, kind of like surl does.

So I suppose, if you wanted some of the functions of other tools, or features of other text-paste tools, wgetpaste might be a good choice.

uppity: Not the last, nor the least, pastebin-ish upload tool

Just by virtue of alphabetical order, uppity is arriving near the end of a long list of pastebin-ish upload tools.

I’ll try to give it the same measure of attention that its competitors received, even if I am beginning to wonder why there are so many of these tools, and if there is a requirement somewhere for CS majors to write a program to upload a code snippet to the Internet.

2014-06-12-6m47421-uppity

uppity, in conjunction with dpaste.com, worked fine for me, and I was able to apply a description to the short text file I uploaded. uppity supports quite a few different services, and there’s always the chance that it will fall out of favor with one or more of them. But uppity cleared the first hurdle — do what you promise — without incident.

kmandla@kl-mkc96: ~/temp$ head output.txt
001,Fanny Moreno,902 Kennel Ln,Indianapolis,IN,46206,(317) 901-6298,77,7299714f
002,Geraldine Adams,479 Flanty Terr,Burlington,NC,27215,(919) 114-2613,67,4f77e31d
003,Mario Meyer,482 Shalton Dr,Auburn,NY,13021,(315) 918-2187,77,8ffaf55c
004,Clare Flynn,676 Dorwin Rd,Addison,IL,60101,(708) 811-9115,41,1fc9ade7
005,Refugio Mcfadden,603 Plymth Terr,Akron,OH,44309,(216) 277-6958,56,0027b74b
006,Chance Mcclure,279 West Street Terr,Akron,OH,44309,(216) 759-8910,69,d17459d3
007,Wilma House,854 Burnet Dr,Appleton,WI,54911,(414) 872-1644,56,f21e179c
008,Charity Newman,770 Rider Blvd,Detroit,MI,48233,(313) 167-2599,47,fb3f7ce2
009,Chester Ross,337 Genesse Blvd,Seattle,WA,98109,(206) 987-2809,85,22cfce3c
010,Preston Higgins,729 Limetree Ln,Orange,NJ,07051,(201) 377-8402,61,cfa29694

kmandla@kl-mkc96: ~/temp$ uppity -s dpaste.com -d "Sample address database." output.txt
Uploading output.txt: 100%
http://dpaste.com/1GJ7FD5

The variety of features available between services is probably what accounts for some of uppity’s options; there are specific flags for language (code language, not spoken language πŸ˜‰ ), expiration, description and nickname, to name the majority. It will also mash together separate files into one whopping upload, if you ask nicely.

uppity also makes a point of listing the languages supported for each service with the -L flag, so if you’re looking for one that will enhance a specific block of code, that might be useful to you.

And I also see, but didn’t test, features specific to a graphical environment, to including reading from the X clipboard and writing to X’s primary selection buffer, both of which need xclip installed to make use of.

The beauty in that, as I see it, is uploading your code snippet, then immediately pasting the link from the selection buffer, without the added step of opening a browser or highlighting the displayed text.

I like uppity for doing the job and having the forethought to add a few time-saving shortcuts. As it is, I rarely need a pastebin-ish service, but when the time comes I’ll make a point of hunting down uppity again, and giving it the chance to impress again.

tig: The dream application

I have to give high marks to tig, a text-mode interface for git, even if I may never, ever, in this life or the next, have the chance to really put it to use.

2014-05-26-jk7h5f1-tig-01 2014-05-26-jk7h5f1-tig-02

That’s just lovely. Color everywhere. Line-drawn characters showing connections between revisions. Breakout panels for examining code in detail. Line-by-line color coordination for easy viewing. Intuitive controls. Left-and-right panning, as well as scrolling. Onboard help screens. One-key jump to $EDITOR. The list goes on.

tig is like my dream application. It’s as if someone read through every post I’d made for the past eight years and distilled it into one program.

And the irony is, I will probably never get to the point where I could use it. 😦

No matter. This is definitely worthy of a coveted K.Mandla gold star: ⭐ Enjoy. πŸ˜‰

sloccount and sloc2html.py: Because size does matter

I’m not a coder, and I try whenever possible to repeat that, at the top of my lungs.

There are some coder’s tools that I think are nifty though. Way back in the C section we had codemetre, for checking the length and breadth of your efforts, and comparing that with the number of commented lines.

In a similar vein, here’s sloccount, which goes a step further by counting out lines of types of code, summing them across an entire project, and showing some basic analysis.

2014-04-28-6m47421-sloccount

And that’s what you get if you point it at the source for the 3.14.2 kernel. πŸ˜‰

sloccount is nifty by itself, no doubt about it. If you’re willing to make a small leap toward the graphical, sloc2html.py will — as you might expect — convert the results of sloccount into something browser-oriented.

2014-04-28-6m47421-sloc2html

This is where things start to break down, because the home page for sloccount also hosts a touched-up version of sloc2html.py, but the link to the actual python program is dead. I scraped around the internets and I think I found a reasonable facsimile thereof, here. I have no way of knowing if that’s the right one though. πŸ˜•

The problem is that, as with so many python programs I encounter, it seems that advances in python proper spawn errors in sloc2html.py, the least of which seemed to occur with Arch’s python2 in charge. What you see above is what sloc2html.py could write out, before it crashed and burned.

I think you get an idea of what it should be doing though, from the screenshot. If you are a pythonian, you might be able to get it going with version 3+, with a little effort. I lack the requisite skills for that.

Which is what I mentioned at the start of this post. Clever, aren’t I? πŸ˜‰

ppt, bcd and morse: Dit dit, daw daw

One more out of bsd-games, because … well, just because. And this is a three-fer. Here’s ppt first.

2014-03-10-lv-r1fz6-ppt

If you’ve been in the computer game for a while you’ll recognize a strip of paper tape, cleverly rendered in ASCII characters. ppt will translate to image and back, as you can see in the screenshot above.

Now bcd.

2014-03-10-lv-r1fz6-bcd

Keeping with the 1960s-70s computer motif, bcd translates — only, I might add — from text to an ASCII rendition of a punch card. Anybody here remember punch cards, besides me? Anyone? Anyone … ? πŸ˜•

Last but not least: morse.

2014-03-10-lv-r1fz6-morse

By now you probably have an idea of what morse will do, if logic follows in this post. As you can see, morse will use the “dit-daw” notation, or better, the dot-dash notation. And like ppt, it will convert back and forth between its product and the original string.

So … aside from nostalgia, what use are any of these, K.Mandla?

Well, again, you’re the best judge of that. I suppose if you need some sort of bland cryptographic effort, it could work that way. After that … I’m out of ideas. πŸ˜‰