NIH — Follow The Money

Screen Shot 2014-05-25 at 7.52.45 AM

I have some questions about how the NIH sees priorities:

Is it reasonable to spend 6x more on 174. smallpox (0 cases since 1980) than 226. CFS/ME? (1 million people, right now).

Or 141. anthrax — how many cases do you know, personally? Yes, with a few rooms full of specialized equipment and a half-dozen experts in various fields it can be weaponized. Otherwise, it’s “wool sorter’s disease,” and you have to catch it from a sheep. Most years, no one does.

For that matter, $72 million for 140. Adolescent Sexual Activity? What exactly are we accomplishing, there?

Posted in Uncategorized | Leave a comment

Rails 4 update: multiple file upload with HTML5 and Paperclip

Again, I am trying to make this the most understandable code, without any regard whatsoever for elegance. In a previous post I made a do-nothing uploader, just to get some feel for the whole HTML5 file upload process. I recommend that you also make one and play with it to get a good feel for what goes on.

This time, we’re actually going to upload, attach, and display files using Paperclip and Rails 4.

The Summit County Engineer keeps track of Road Records. A Road Record can have a bunch of attached files of varying formats, e.g. tif, pdf, jpg, and doc. There’s a bunch of fields about which road, which section, what kind of work, etc. These, you can ignore.

For this tutorial (and my app,) I’m going to call the attached files Road Record Assets.

For the most part, this is just typical Paperclip. Most of the non-typical work gets done in the road_records_controller, so let’s look at that first. (Rails 4: turn off protect_from_forgery for the add_assets function)

It just adds a new RoadRecordAsset for every file it gets. The fact that the file gets stored in /tmp/ for a bit gives you the chance to rename it, sanitize it, or whatever before it actually gets attached. Don’t forget to add the route:

The RoadRecord model is simplicity itself.

And the RoadRecordAsset model is nearly as simple.

Notice that you can do all the usual Paperclip magic, just as you’re used to.

All that’s left is the upload part, which is very similar to what was shown in the last post:

I scrounged all over the web for bits of this; hopefully, you won’t have to. Thanks to all those who posted demos, tuts, and gems!

Posted in Ruby on Rails, tutorial | Tagged , , | Leave a comment

Like Dad Used to Keep It

Dad was a big keeper of the boxes things came in.

Dad was a big keeper of the boxes things came in.

Every time I look at the transistor radio in my workshop, I think about my Dad. Well, not the radio, really, but the box. See all the wear and tear? That radio box is about 10 years old.

Dad’s been gone for a few years, now, but Dad would do that. He’d keep things in the original box until the box disintegrated. It’s a good idea for several reasons:

  • Labels the item
  • Preserves the instructions
  • You know where to get parts (if anything is actually repairable.)
  • It makes odd-shaped items fit neatly on the shelf and in drawers.

However, I don’t think any of those reasons are the real motivation. Maybe it goes back to when the container was a part of the product. Like, back when the boxes for tools looked nicer than the boxes for jewellery look now.

Even more than that was just Dad’s impulse to preserve, to keep things nice. Anyway, when I see that old box, I think Dad likes to see it, too.

Posted in Commentary | Tagged , , , | Leave a comment

Getting Away With Something

Sodom and Gomorrah - John Martin

Sodom and Gomorrah – John Martin

Then the Lord said, “How great is the outcry against the elitists and their government toadies. They cry out against the poor and say that they toil not, neither do they spin. I must go down and see who is Getting Away With Something.”

Abraham remained standing before the Lord. Then Abraham came near and said, “Will you indeed sweep away the deserving with the wicked? Suppose there are fifty within the Safety Net who couldn’t meet their medical bills; will you then sweep away the Safety Net from the fifty deserving who are in it? Far be it from you to do such a thing, to cut off the deserving with the wicked, so that the deserving fare as the wicked! Far be that from you! Shall not the Judge of all the earth do what is just?”

And the Lord said, “If I find fifty deserving within the Safety Net, I will leave the whole plutocracy in place for their sake.”

Abraham answered, “Let me take it upon myself to speak to the Lord, I who am but dust and ashes. Suppose five of the fifty deserving could have paid their medical bills, but now they have lost their jobs? Will you destroy the whole Safety Net for lack of five?” And he said, “I will not destroy it if I find forty-five there.”

Again he spoke to him, “Suppose forty are found there who owe on student loans for a degree that the elite value not?” He answered, “For the sake of forty I will not do it.”

Then he said, “Oh do not let the Lord be angry if I speak. Suppose thirty are found there who bore their children rather than abort them?” He answered, “I will not do it, if I find thirty there.”

He said, “Let me take it upon myself to speak to the Lord. Suppose twenty are found there who are working, but cannot earn a just wage?” He answered, “For the sake of twenty I will not destroy the Safety Net.”

Then he said, “Oh do not let the Lord be angry if I speak just once more. Suppose ten are found there whose retirement was taken to pay executive bonuses?” He answered, “For the sake of ten I will keep it in place.”

The two angels came to the plutocracy in the evening, and Lot was in a place of honor within the plutocracy. When Lot saw them, he rose to meet them, and bowed down with his face to the ground. He said, “Please, my lords, let me treat you as equals, even though you cannot prove that you are deserving.” They said, “No; we will spend the night in this town square.”

But he urged them strongly; so they turned aside to him and entered his house; and he made them a feast, and baked unleavened bread, and they ate.

But before they lay down, the men of the plutocracy, both the elite and their toadies, all the people to the last man, surrounded the house; and they called to Lot, “Where are the men who came to you tonight? Bring them out to us, so that we bring them into the plutocracy. We wish to make unto them loans instead of Free Stuff, that they may become indentured servants unto us.”

Lot went out of the door to the men, shut the door after him, and said, “I beg you, my brothers, do not act so wickedly. Look, I have two daughters who have not yet entered the plutocracy; let me bring them out to you. The younger will be an unpaid intern unto you; and the elder will hew wood for 30 hours and draw water for another 30 so that even the Safety Net avail her not. Only do nothing to these men, for they have nothing to yield up to you.”

But they replied, “Stand back!” And they said, “This fellow came here from outside, and his charity is given freely to those who cannot prove they deserve it! Now we will deal worse with you than with them.” Then they pressed hard against the man Lot, and threatened him with foreclosure.

But the men inside Lot’s house reached out their hands and brought Lot into the house with them, and shut the door. And they smote the men who were at the door of the house, both small and great, so that they were unable to find who actually held the mortgage on Lot’s house. The first waved papers that shew him as the owner of Lot’s house, but another had papers that shew the first had failed to file other papers, and there was great confusion.

Then the men said to Lot, “Have you anyone else here? Sons-in-law, sons, daughters, or anyone you have in the plutocracy — bring them out of it. For we are about to destroy this plutocracy, because the outcry against its people has become great before the Lord, and the Lord has sent us to destroy it.”  So Lot went out and said to his sons-in-law, who were to marry his daughters, “Up, get divested now; for the Lord is about to destroy this plutocracy.”

But his sons-in-law said, “Are you jesting? It has always been this way. What would take its place? Within six months, all the shekels will be right back in the same purses.”

When the light dawned, the angels urged Lot, saying, “Get out, or else you will lose everything in the downturn.” But he lingered; so, the Lord being merciful to him, the men bought him out and left him outside the plutocracy. Likewise, they bought out his wife and daughters from their financials and credit default swaps. When they had bought them all out, they said, “Just forget this whole plutocracy; do not look back or try to save any part of it; flee to the hills, or else your substance will be consumed.”

And Lot said to them, “Oh, no, my lords; your servant has found favor with you, and I am glad to get away with something; but I cannot just shut down completely, for fear the downturn will overtake me and I will go broke. Look, that Zoar co-op is easy enough to invest in, and it is a little one. Let me put my investments there — is it not a little one? — and my assets will be saved!” They said to him, “Very well, I grant you this favor too, and will not overthrow the co-op of which you have spoken. Hurry, invest there, for I can do nothing until you are fully vested there.” Therefore the co-op was called Zoar. The light had fully dawned on the earth when Lot became fully vested in Zoar.

Then the Lord rained on the elitists and their servile government sulfur and fire out of heaven; and he overthrew that plutocracy, and all that elite, and every transaction that they corrupted. But Lot’s wife, behind him, couldn’t resist selling short on the downturn, and she became a pillar of salt.

Abraham went early in the morning to the place where he had stood before the Lord; and he looked down where the elitists and their servile governments had been and toward all the land of the plutocracy and saw the smoke of them going up like the smoke of a furnace.

So it was that, when God destroyed the elitists and their government toadies, God remembered Abraham, and sent Lot out of the midst of the downturn, when he overthrew the plutocracy in which Lot had invested, because Lot had showed mercy to those who had not proven that they deserved it.

Whenever the safety net is discussed, even among Christians, the conversation always gets around to welfare cheats, if it doesn’t start there. Well, of course there are some, but what of it?

  1. God doesn’t limit His charity to the deserving, so we can’t, either. As G. K. Chesterton points out, if someone deserves a benefit, that it is a demand on us for justice rather than an opportunity for us to show charity.
  2. God seems to set great value on preserving even very imperfect things. He doesn’t burn down the city to exterminate some rats; nor plough up the wheat to kill the tares. Helping truly needy people, even if they were in the minority, takes precedence over preventing abusers from Getting Away With Something.
  3. God does not give money and power to certain people because they possess some superior wisdom or morality. The cost of one rich tax dodger, one unearned government subsidy, or one no-bid defence contract can easily exceed the cost of all  welfare programs put together, but the discussion almost never turns to the sins of the wealthy and powerful.
Posted in Commentary | Leave a comment

Meaningful Pagination

Why “Meaningful?”

Well, if your results are ordered by last name, which page do you click to see “Phillips” ?

<<Page 1, 2, 3 . . . < 15, 16, 17 > . . . 32, 33 >>

Go on, guess!

Wouldn’t this be easier?

<< Appleby, Brown, Busskirk . . . < Lundy, Numps, Psederton > . . . Wycliffe, Zetos >>

See?  With proper page labels you can find the page in a couple of clicks.

Page numbers only make sense when there is no natural order to the results. A true search (returning results in “relevance” order, say) is forced to use page numbers, because the results don’t have any consistent labels. However, there’s no excuse for making users guess which page number is the “P’s” when we’re filtering and sorting a “Last Name” column.

It’s normal to have some kind of default ordering, so that should be used to label the pages. If we’re talking about people, family name is a good default order. There is a demo at, and the default order is family_name.

However, we could use “Supervisor.” If you click the “Supervisor” link in the first table of search terms, you’ll see that the results are paginated by supervisor’s name. (Hover over “Pick Page” in the brown pagination menu.)


Whatever we use, the pages should be labeled with the value of that field for the first record on the page.

Here’s One Way To Do Meaningful Pagination

Use whatever paginator you like. Kaminari is fine.

We’ll need to know which field the results are sorted by (there’s a little extra code to put the sorted field on the left if it’s an optional field, but that’s another tutorial):

Then we can get the contents of the first record on each page.

It’s simpler just to use the same page length and select the first field on each page.

So, the controller looks like this:

Then, it’s just a matter of creating the navigation display.

The view calls for the pagination navigation display if there is more than one page of results

There’s a little helper method:

which calls the actual pagination navigation partial:

And, finally, style it all:

There! It’s a bit of work, but it really makes user life easier.

Posted in Information, Ruby on Rails, tutorial | Leave a comment

Rails, Ransack, and Associations The Easy Way

Ransack (neé Metasearch) is brilliant at providing ad hoc table searches for users, but  handling all the possible ActiveRecord associations can require workarounds. However, it is bonehead simple to use with a single table. So, we’re going to give it one.

Views are Read-only Tables

A lot of the problems posted on StackOverflow happen when we use associated table fields. An employee has_one section, and we want to filter/sort by the section name. That kind of thing.

I find it’s simpler to avoid the whole issue. I have a demo running at The Employees Search (the landing page) uses results from four different tables, one used twice with an alias, and from another view. It ought to be a nightmare, but it’s actually simple, because it’s using a single virtual table (a Postgresql view.)

There are some other features implemented in the demo, but they’re for future tutorials. You can ignore them, for now.

I wouldn’t use a view for editing, but we only need to show/sort/filter. The view joins any associated tables and makes their columns look and act like native columns in a table.
A view will play nicely with Ransack, because it looks to Rails just like a single table.

How nice it is to get a table with all the columns renamed, all the text concatenation done, all the columns from associated tables sortable and filterable — yum! Null handling is another nice feature: nulls can be shown as “NULL” or “Inactive” or whatever you like, or left as nil values.

Creating/Editing a view in PostGreSQL:

I like to name my views “fil_whatever” (filter), and columns from joined tables as “whatever_disp” if several tables have columns with the same name. For example, if the “sections” and “divisions” tables both have a ‘title’ column, I’d rename them to section_disp and division_disp. I usually include the ‘whatever_id’ columns as well, so that my associations work, although I seldom use them.

That sql will produce a virtual table in PostGreSQL. The view can be used as though it were a table in its own right:

Gives results like:


So, we have pulled four tables and another view and an alias into one do-it-all table. However, as far as Rails is concerned, it is just another table, except:

  1. It doesn’t show up in your schema.rb
  2. You need to add a couple of lines to the model to let Rails find the table.

Here’s the controller:

and here’s the view:

There you have it. For my money, that’s a lot easier than fiddling :joins, :includes, scopes, etc. in Rails. YMMV, of course.

Posted in Information, Ruby on Rails, tutorial | Tagged , , , | Leave a comment

Camera Stabilizer? Who knows?


I had a request a while back: to create a camera stabilizer like this one. The challenge: it needed to be simpler to make.


I took that to mean more assembly of stock parts, and less drilling, heating, stretching, etc. I came up with this design, which meets the criteria, and actually shaves a bit off the cost.

It uses a Female Thread – Rod End Bearing ($3.08), a piece of threaded rod ($0.56), a 1′ piece of about anything, and some common nuts, bolts, and washers. It ought to be under $10, easy.

The rod end provides freedom of rotation in roll, pitch, and yaw, and the bar with the stack of washers at the ends provides inertia for stabilization.

I think.

You see, I have never used a Steadicam. I’ve never even seen one used, come to that. I tried it, and my results were distinctly better than hand-held, but what does that mean?

So, to test it, I am looking for someone who knows what’s supposed to happen! If it gets an upcheck, then I’ll feel comfortable publishing the full instructions, price list, and sources.

If you are willing to be a guinea pig, let me know.

Posted in NewProducts | Leave a comment