tag:blogger.com,1999:blog-305474332024-03-13T15:51:29.940-04:00Bucky BitsProgramming and rants for the "Developmentally Disabled."Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.comBlogger43125tag:blogger.com,1999:blog-30547433.post-17085311828185318112020-07-17T12:27:00.000-04:002020-07-17T12:30:35.857-04:00The Importance of Whitespace to ReadabilityCode is hard. One way to make it easier is to make it pretty. Even simple, short code can become difficult to reason about if it's all scrunched together:
That code is pretty simple, but difficult to reason about. The interspersed debug logging adds a lot of noise and detracts from overall legibility. Just spacing it out helps a lot:
What else can we do? The first declaration of ret is Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-32610013200510076262019-01-20T08:39:00.000-05:002019-01-20T08:39:09.272-05:00Snowflake Sociology"Snowflake" isn't a term I enjoy using: it's derogatory, demeaning, and can be used as a dismissive approach to ideas we don't like. Until you're snowflaked, it's an easy thing to not like.
I was finally snowflaked awhile back. I sat on it for some time, but given today's general political and conversational climate, I wanted to discuss the experience. Someone asked a Stack Overflow question I Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-86459689371393533152019-01-20T08:27:00.001-05:002019-01-20T08:27:06.365-05:00Back yet again!As part of a blogging/writing blitz I'm back on this platform as well as others.
I'll be blogging here, as well as one of the bloggers at the Maker's End Blog, discussing a wide variety of topics, generally related to technology, but occasionally stretching far afield into general Making, society, crafting, and so on.
A few of the upcoming topics will include:
* JavaScript
* Embedded Systems
*Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-31266194489018111892017-10-20T15:20:00.000-04:002017-10-20T15:20:01.006-04:00Cura 3 on OS X Crashes on StartupThis one was easy to fix, although I'm not sure what the consequences will be.
On startup the new version of Cura would start to open (evidenced by Activity Monitor process) then close. I decided to delete my existing Cura app data since (a) need to recalibrate the printer anyway, (b) getting an additional new printer anyway, and (c) didn't know what else to try.
Navigate to ~/Library/Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com1tag:blogger.com,1999:blog-30547433.post-57786980332690247672015-08-11T16:09:00.000-04:002015-08-11T16:09:01.735-04:00Pirate StackLAMP? MEAN? No, mateys, PIRATE STACK!
(A)RRR(GH): React, Relay, RethinkDB.
The stack is mine. I win the internet.
Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-45223385025679634982015-08-05T17:05:00.002-04:002015-08-05T17:05:40.262-04:00Styling Atom Editor UI ElementsI'm in the process of switching to Atom as my daily text editor (from Sublime Text 3) and needed to have my UI element font much smaller. Doing this in Atom is blissfully easy, just edit your styles.less file and you're done. The trick is understanding which elements you want to style.
Most elements I needed re-sized are easy:
The styles.less is accessible directly in your $HOME/.atom Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-4005600698184585752015-07-17T15:14:00.003-04:002015-07-17T15:16:24.427-04:00Best JEE Interview Ever LIVES AGAIN!!!Transcription
The audio in all its glory.
Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-58078298017267782612015-06-06T22:22:00.000-04:002015-06-08T14:28:49.290-04:00CoffeeScript IIFEsImmediately-Invoked Function Expressions are an easy way to hide your variables, preventing collisions with your code or the code of others. In JavaScript you'll see the following a lot:
In CoffeeScript the syntax can be the same; enclose the function in parens, and put parens after it to call it. It's ugly, though:
CoffeeScript has the do keyword, though, and it provides a cleaner way to Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-71783991354361962252015-04-30T10:57:00.000-04:002015-04-30T10:57:06.428-04:00Easy Halloween Sound Hack, Part OneMy aunt and uncle set up a "Haunted Forest" every year, where they take area kids through a section of their woods with groomed trails and various scary things. This year I'm helping "up the ante" with sound, lighting, and robotics (pneumatic and/or otherwise depending on time). I'll cover various means of tech-ing up the fear.
The first hack is pretty straight-forward, the only possible glitch Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-92224663942860923362015-04-26T17:57:00.000-04:002015-04-26T17:57:38.641-04:00Electric Imp + OLED + ... Squirrel?The Electric Imp came out before the days of essentially-free ESP WiFi modules. It was designed to be embedded into devices, provide a WiFi interface, and some basic cloud connectivity. It's a bit of an odd duck: it's initialized by blinking lights, e.g., seizure-inducing screen flashes from your phone. This is a pretty unique way to get things set up, and it works great.
I had a few of these Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-8869716293843263592013-04-19T09:54:00.001-04:002013-04-19T10:00:31.509-04:00Remapping a Control key to Windows / Super Under Ubuntu 12.04My old ThinkPad keyboard rocks: it has a trackpad and a trackpointer, types nicely, has a palm rest, and is generally awesome. It does not, however, have a Windows button: this makes using it under... well, anything... difficult.
I'm currently developing with a company-bought Ubuntu laptop after having used OS X for the last three years almost exclusively. Like Windows and OS X, it pretty much Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-61046151991955140582013-03-12T13:05:00.000-04:002013-03-12T13:05:29.363-04:00sftp "Received message too long" on OS XToday I started receiving the following error when I tried to sftp to my localhost, both from the command line and from the Ruby Net:SFTP library:
$ sftp ftpuser@localhost
Password:
Received message too long 1399157792
Trivial digging revealed that ftpuser's .bashrc script was writing to stdout, which apparently is enough to confuse sftp all 'round. I modified the command it was running to Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-84465719118008986102013-03-12T08:10:00.001-04:002013-03-12T13:06:08.667-04:00Tied to the Web LayerStruts 2 claims that "actions can be POJOs". Developers find out pretty quickly that not extending ActionSupport means you lose some Struts 2 functionality (primarily I18N and validation).
One source of confusion is what "POJO" means. POJOs don't mean you don't extend a base class. POJOs are classes not directly tied to unrelated libraries, specifications, etc. For example, Struts 1 actionsDave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-14131812960100661252013-03-04T18:15:00.000-05:002013-03-04T18:18:00.463-05:00"Unknown error" while signing in to Apple App StoreI was unable to log in to the Apple App Store while trying to update Xcode on my MBP.
Here's an Apple discussion thread regarding possible solutions.
What ended up working was signing out, clicking "Store -> Create New Account", accepting the Terms and Conditions, then canceling out of new account creation and signing in again.
While deleting the network interface plist, cookies, etc. was Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com27tag:blogger.com,1999:blog-30547433.post-76307582390829762282012-08-23T19:57:00.000-04:002012-08-23T19:57:09.794-04:00A JRuby, Rails, RSpec, Spork, and an error walk in to a bar...I was running a specific rspec over and over during a tight development cycle. The way our system was set up it was taking 30+ sec to run a single spec file, which made running them onerous.
We had Spork running at one point, but it wasn't working for me, with a "undefined method 'flush' for nil:NilClass" error (and a couple of others depending on the incantation):
After upgrading Spork (weDave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com1tag:blogger.com,1999:blog-30547433.post-18423875072838637162012-08-08T21:56:00.001-04:002012-08-08T22:06:52.989-04:00RSpec Error With Implicit SubjectEver write a trivial spec like this:
And get something totally baffling back, like this?
Backstory: Refactoring some pre-written classes to use metaprogramming to create some methods and values. I wanted specs in place before starting the metaprogramming to avoid breaking things.
In retrospect, I should have figured this out sooner. In my defense, I love the Olympics and was distracted. The Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-53301595479655803002011-11-12T10:20:00.001-05:002011-11-13T13:09:31.533-05:00Testing singletons while avoiding their constructorsSingletons are evil, and here's why.
Fair enough. Yet they exist, and they're not intrinsically evil--just misused. Can we mock enough to make testing them feasible? Yep, and here's a Contrived Exampleâ„¢ that shows how (and why we might want to).
"Embedded" singletons or utility classes can make testing is problematic. Injected singletons are different; then it's an issue of Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com2tag:blogger.com,1999:blog-30547433.post-55285975529957153792011-11-10T22:07:00.001-05:002011-11-10T22:20:13.229-05:00A trip to the Rake-track.(Because it's like "racetrack", and it makes Rake tasks faster, and... oh, never mind.)
Tired of waiting for Ruby to spin up just so you can run a "routes" command, or your latest "db:migrate"?
Use rake-sh and start up a rake console for running tasks without the initial spin up. It'll take a "rake routes" from four seconds down to under a second. Rake task completion? Naturally. Use "t" for Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-58605061323039553862011-09-15T22:07:00.001-04:002011-09-25T15:46:59.535-04:00Rails 3 Custom Validator Quandary -- Solution Step OneRemember when I had a Rails 3 custom validator quandary? My bottom-line question was "how should I access a specific error condition, cleanly, in both an action, and a template?" I sketched a few solutions, ranging from checking for a specific error message to providing a function that indicates if the error has occurred.
For now, I want simple boolean methods on the model to encapsulate the Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-38243871125380426042011-09-06T23:02:00.000-04:002011-10-27T09:51:52.914-04:00Simple Ajax property toggle in Rails 3.0Entry-level overview of one way to add trivial Ajax functionality to a Rails 3.0 app, originally written for a specific audience. The repository is on github.
Let's say we have an Article model with an "approved" flag. We need to be able to toggle this flag. Normal scaffolding would have us view the article, click a checkbox, and submit. We'll keep that functionality, but add a simple Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com4tag:blogger.com,1999:blog-30547433.post-14768217170045397242011-09-05T20:15:00.000-04:002011-09-05T20:19:55.018-04:00Example app test failures from authlogic user sessionsThis question on stackoverflow led me to believe that if I actually ran rake test that my example app's tests would fail--and they did, with the same error. (Why I wasn't running tests from the beginning? Meh!) The tests throw up wads of stack trace, headed with this:
SQLException: no such table: user_sessions: DELETE FROM "user_sessions" WHERE 1=1
What's causing this error? We created our userDave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-55634571130112150202011-09-05T12:24:00.000-04:002011-12-24T13:09:27.931-05:00TextMate, rvm, ActiveSupport outside of Rails, "require"s from current directory, all together now!I'm prototyping some calendar/date stuff for a Rails app in standalone scripts, and want access to both normal Rails things (in this case, ActiveSupport's date math, like Date.today - 3.days) and my own classes within the prototyping directory. I'd like to continue using TextMate's "Run" command to run the current buffer as a Ruby script, since it's convenient. I'm using rvm; my prototyping Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-84324454250396169412011-09-05T06:00:00.000-04:002011-09-05T09:57:30.016-04:00Using email or nickname to log in using authlogic and Rails 3
This is a continuation of my first authlogic/Rails 3 post.
Authlogic users have both "login" and "email" properties by default. I wanted to allow users to log in via their email address or nickname. I tackled this in two steps. First, switch to logging in using the "email" property. Second, create a "nickname" property, and allow users to log in with either one. (Yes, I actually wanted to call Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-54290534882183587642011-09-04T20:32:00.000-04:002011-09-05T18:34:32.227-04:00Rails 3 + authlogic explorationsI've started a simple Rails 3 + authlogic example project on github, mostly for myself to experiment with. Right now it's basically a copy of this post's implementation (and unfinished at that), but I'll be expanding it over the next few days in various ways.
As it stands, the "application" (I use the term loosely) consists of a home page (root path) requiring login, and login/logout actions. Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com0tag:blogger.com,1999:blog-30547433.post-17515904591190740572011-08-29T01:23:00.000-04:002011-08-29T01:23:53.416-04:00Associating has_many relationships in Rails 3 using checkboxes(Not checkboxes, in my case, but a checkbox example is easy, and more common.)
Originally I thought I needed accepts_nested_attributes_for, but that seems to be mostly for when we're creating the related objects, which I'm not--I need to save relationships to existing objects.
My example (github) uses a simple product/category relationship. We need to get a product's categories, we Dave Newtonhttp://www.blogger.com/profile/13420113088393527059noreply@blogger.com4