weblog.jamisbuck.org Archives - 07 October 2015, Wednesday

  • Buckblog: Changing the Channel

    weblog.jamisbuck.org 04 Oct '15, 2am

    Stuck? Try changing the channel. No, seriously. It’s like if you’re watching TV and you’re feeling uninspired by what you see, you change the channel. This doesn’t change the TV at all–you’re still staring at the same screen, in the same plastic chassis–but now you’re seeing something...

  • Generating Word Search Puzzles

    Buckblog: Generating Word Search Puzzles

    weblog.jamisbuck.org 26 Sep '15, 2pm

    My daughter (age 11) was writing an article this week for a local student newsletter , and had the idea to include a word search puzzle . After spending ten minutes looking online and being fairly disappointed in the quality of what we found, I decided to take a stab at writing a word...

  • Buckblog

    weblog.jamisbuck.org 19 Sep '15, 9pm

    Most of you will be familiar with “default scopes” in ActiveRecord, the feature that lets you apply conditions automatically to all queries on a given model. For example, suppose we have a system where a blog author can be deleted (perhaps to remove their access to the blog), while pr...

    1. Buckblog weblog.jamisbuck.org 19 Sep '15, 8pm
  • Buckblog

    weblog.jamisbuck.org 19 Sep '15, 8pm

    Most of you will be familiar with “default scopes” in ActiveRecord, the feature that lets you apply conditions automatically to all queries on a given model. For example, suppose we have a system where a blog author can be deleted (perhaps to remove their access to the blog), while pr...

    1. Buckblog weblog.jamisbuck.org 19 Sep '15, 9pm
  • Buckblog

    weblog.jamisbuck.org 13 Sep '15, 2am

    This leads to a quirky (but oh, so useful!) little thing about heredocs: syntactically, the first delimiter represents the entire heredoc . That is to say, if you want to invoke a method on the string, you attach the method invocation to the first delimiter, not the last! Like this:

  • I love how Ruby makes hashes and (arity-1) procs duck-type-compatible:


    weblog.jamisbuck.org 06 Sep '15, 3am

    A few years ago, I gave a presentation at Mountain West Ruby Conference entitled “It’s the Little Things” , in which I described “some of the littlest things that make Ruby big”. The point of the talk was really to highlight some of my favorite features of Ruby, and to emphasize that ...

  • Buckblog

    weblog.jamisbuck.org 29 Aug '15, 9pm

    I once challenged myself to write 1,000 words, every day, as an exercise to improve my writing. I kept at it for the better part of a year, and learned a lot. Most of the writing I did was journal-style freewriting, as well as some exercises from The 3 A.M. Epiphany by Brian Kiteley (...

  • Buckblog

    weblog.jamisbuck.org 05 Aug '15, 6pm

    When implementing certain kinds of algorithms, I often seem to find myself needing to move a token a given number of steps toward some location. In the “Back from the Klondike” puzzle described previously , for example, I needed to verify that a given path between two cells was valid,...

  • Sam Lloyd's "Back from the Klondike" puzzle is a fun one. Here's how I wrote a solver for it:


    weblog.jamisbuck.org 04 Aug '15, 10pm

    If you aren’t familiar with Dijkstra’s algorithm, here is a slightly simplified version in a nutshell. You start at some position (the root , here), and add it to a stack (frontier ). The algorithm then loops for as long as there are any cells in that stack. Each iteration looks at ea...

    1. Buckblog weblog.jamisbuck.org 05 Aug '15, 6pm
  • Buckblog

    weblog.jamisbuck.org 30 Jul '15, 10pm

    Honestly, converting the description into a BNF is usually the hardest part, but once you’ve got that, the rest of the parser flows very naturally. Each of the left-hand sides of those BNF definitions becomes a method, which recursively calls the appropriate methods corresponding to t...

  • Buckblog

    weblog.jamisbuck.org 23 Jul '15, 8pm

    I’m always surprised by the odds and ends that are tucked away inside a stock Ruby install. Recently, I was thinking about Rubygems and realized that since gem files are just tar files, and since Rubygems is cross-platform, that therefore Ruby must ship with some libraries for reading...

  • So, it's all real now. My author copies arrived!


    weblog.jamisbuck.org 08 Jul '15, 5pm

    The book is done! Well, and truly. The final milestone has been reached: Mazes for Programmers is now in print! Lookit, I’ve even got my author copies! It’s hard to believe this day has come. A huge “thank you” goes to everyone who read my maze articles and encouraged me, years ago, t...

  • Buckblog

    weblog.jamisbuck.org 17 Mar '15, 4pm

    I wish I could remember where, exactly, I first encountered this tip. It was on Hacker News some months back, and at the time I didn’t particularly need it. But when I started consulting last month, it suddenly came back to me, and I realized just how valuable it is. The problem is th...

  • Buckblog

    weblog.jamisbuck.org 22 Jan '15, 5pm

    Implementing Kruskal’s algorithm is straightforward, but for best results you need to find a very efficient way to join sets. If you do it like I illustrated above, assigning a set identifier to each cell, you’ll need to iterate on every merge, which will be expensive. Using trees to ...

  • You Should Totally Hire the Heck Out of Me -- -- looking for a remote team to join!

    Jamis Buck

    weblog.jamisbuck.org 20 Jan '15, 5pm

    You Should Totally Hire the Heck Out of Me. I'm Jamis Buck. Blog ~ Twitter ~ GitHub ~ Email I make things. Lots of things, in lots of ways. Some in software, some not. It's what I love to do. I helped make Ruby on Rails. I was a member of the core team from 2005–2007. I worked on lots...

  • Had an idea this morning for a variant on the recursive division algorithm. (I think a lot about mazes these days...)


    weblog.jamisbuck.org 15 Jan '15, 6pm

    This morning as I was getting ready for the day, I was thinking about the Recursive Division algorithm . (Maze algorithms are on my mind a lot these days.) It’s a neat algorithm, with some neat properties (like the ability to generate different sized “rooms” in a maze by controlling t...

  • Web services, Rails-style

    weblog.jamisbuck.org 12 Jul '14, 11pm

    Jamis, can this REST support (as well as ActionWebService::Client::XmlRpc as documented http://api.rubyonrails.com/classes/ActionWebService/Client/XmlRpc.html) be used for outbound client apps, such as allowing my Rails app to interact with other web services (like eBay, Amazon, Googl...

    1. OndeTrabalharCom ondetrabalhar.com.br 16 Jul '14, 7pm
  • Maze Generation: Wilson's algorithm

    weblog.jamisbuck.org 15 May '14, 10pm

    Then, we pick another unvisited cell at random and do a random walk until we encounter that first cell. Note that this random walk has a few constraints: although it can cross cells it has already walked (as long as they are not already in the maze), we don’t want to allow the final p...

  • RubyConf: Day Two

    weblog.jamisbuck.org 15 Mar '14, 10pm

    RubyConf: Day Two Posted by Jamis on October 02, 2004 @ 01:49 PM This morning started equally bleary-eyed. I just can’t seem to shake this jet lag. At any rate, I managed to shower and stumble downstairs for another exciting continental breakfast, followed by… Morning Panel Patrick Ma...

  • Inside Capistrano: the Gateway implementation

    weblog.jamisbuck.org 14 Jan '14, 6pm

    The gateway code is a bare 100 lines long, including comments. Basically, all it does is establish a connection to the gateway machine, and then for every connection established via the gateway, it forwards a port from the local host to the requested server. Then, it establishes a con...

  • Maze Generation: Prim's Algorithm

    weblog.jamisbuck.org 13 Jan '14, 12am

    The largest bit of implementing Prim’s algorithm (for me) seems to go toward managing the interactions with that frontier set. Maybe your experience will be different. You basically need two operations: mark a cell as “in” (which then marks the “out” neighbors as frontier cells), and ...

  • perils of programming while sick

    weblog.jamisbuck.org 04 Jan '14, 4am

    The perils of programming while sick Posted by Jamis on March 08, 2005 @ 01:29 PM So, I knew my turn was coming. My one-year-old daughter was quite sick about a week and a half ago, running a temperature of 106F. We even took her to the emergency room for that one, though her fever wa...

  • Unit vs. Functional vs. Integration

    weblog.jamisbuck.org 20 Oct '13, 2am

    Unit tests. Functional tests. Integration tests. Rails draws a lot of circles around your tests, and it does a good job (in general) of helping you know what kinds of tests belong in each, but there are still some gray areas (and areas that I think it categorizes incorrectly). For exa...

  • Maze Generation: More weave mazes

    weblog.jamisbuck.org 03 Oct '13, 5pm

    @Jamis Don’t be sorry! I wouldn’t be here if I didn’t like puzzlers. Why do you think the twisty mazes appeal to me? :-) I did wonder about doing something like what you describe, but it seemed likely to get complicated pretty quickly. But there does seem to be a reasonably simple sol...

  • Maze Generation: Aldous-Broder algorithm

    weblog.jamisbuck.org 27 Jul '13, 3pm

    The next maze algorithm I’m going to cover, the Aldous-Broder algorithm, is one of the simplest imaginable. It’s also one of the least efficient. In fact, it is so inefficient that you might wonder why anyone would even bother implementing it, let alone discovering it and having their...

  • Maze Generation: Recursive Backtracking

    weblog.jamisbuck.org 22 May '13, 11am

    Actually, once you understand this algorithm, I think the best place to go next would be to change it to a breadth-first traversal. The intuition here is that a maze is an undirected graph, and this algorithm constructs the maze by traversing that graph in depth-first order. This is d...

  • SwitchTower: Renamed

    weblog.jamisbuck.org 10 Apr '13, 12am

    Ryan, regarding "caving so soon and so fast," it wasn't a casual decision. We consulted an attorney, and their professional opinion was that we not fight it. True, we could have looked for a second opinion, but given that the prospect was not exactly sunny, it would have just been (IM...

  • Maze Generation: Algorithm Recap

    weblog.jamisbuck.org 08 Apr '13, 11pm

    (Hello Minecrafters! If you’re looking for random mazes you can build in Minecraft, you might be better served by this page I wrote . It’ll give you block-wise schematics for the maze, and will require less mental translation than the demos here. Just don’t use IE—it won’t work right ...

  • Nesting resources

    weblog.jamisbuck.org 03 Aug '12, 8pm

    I believe you are getting into why DHH said this will help you make better controllers. I am working on a e-book for modelling REST and resources in Rails. Right off the bat, you should be thinking about your use cases and the flow of your application. Jamis, didn’t you blog something...

  • Mining ActiveSupport: Object#returning

    weblog.jamisbuck.org 31 Jul '12, 9am

    If you’re into functional programming at all, you probably know right away what the K combinator is. For the rest of us, this article is helpful (if a bit on the academic side, but that’s about par for the course for most reading about functional topics). Basically, the K combinator i...