weblog.jamisbuck.org Archives - 13 February 2016, Saturday

  • "Living With Your Eyes Open"

    Buckblog: Living with Your Eyes Open

    weblog.jamisbuck.org 06 Feb '16, 11pm

    6 February 2016 — The author shares some experiences in which learning came completely by surprise — 6-minute read A couple of years ago, I was struck by how much there was to learn. I tweeted this: The more I learn, the more I'm convinced that there's nothing that can't be learned. —...

  • Buckblog: Software Proverbs

    weblog.jamisbuck.org 30 Jan '16, 7pm

    When I was in Korea (20+ years ago), I picked up a little book called “속담백과”, which could maybe be translated as “The Proverb Encyclopedia”. It was a fun exploration of hundreds (thousands?) of Korean proverbs, all in Korean. I worked through a few pages of the book when I was in Kore...

  • Buckblog: Mazes in Swift

    weblog.jamisbuck.org 24 Jan '16, 2am

    I did it a bit differently this time. Instead of looking at existing code, I went a bit meta and instead read through The Official raywenderlich.com Swift Style Guide . I knew, going in, that a style guide was going to be a pretty opinionated document. For instance, if I were to read ...

  • Buckblog: A Pretty-Printer for SQL

    weblog.jamisbuck.org 16 Jan '16, 10pm

    Lately, I’ve been up to my elbows in enormous SQL queries. I can’t share the details, but suffice to say that it’s for a reporting app, and the SQL for these queries frequently run as much as 50,000 characters each. This happens because the queries are built up modularly, with each mo...

  • Don't Assume It's Difficult Until It Is

    Buckblog: Don't Assume It's Difficult until It Is

    weblog.jamisbuck.org 09 Jan '16, 9pm

    Does a task look like it might have some difficult or challenging bits? Don’t be too hasty in drawing that map. Your assumptions almost certainly have some gaping holes in them. About twenty years ago I returned home from a two-year stay in South Korea, where I had served as a mission...

  • This side-project has been so much fun to work on:

    Buckblog: Game Demonstration: Recover the Widgets

    weblog.jamisbuck.org 02 Jan '16, 8pm

    The THREE.js sample code I used to start experimenting (yay! a rotating cube!) used a field of view of 75 degrees. I continued using that for a while, but eventually found the slight fish-eye effect a bit disorienting. I went down to 45 degrees for a few iterations, but that turned ou...

  • Buckblog: Avoiding "Call Super" with Callbacks

    weblog.jamisbuck.org 19 Dec '15, 4pm

    is situation in which a superclass requires that subclasses invoke super when overriding a method. Martin Fowler is, I believe, among the first to have labelled this an anti-pattern (“minor code smell”, in his words), and he’s careful to point out the problem is not with the super cal...

  • Buckblog: Little Things: Introspecting Block Parameters

    weblog.jamisbuck.org 12 Dec '15, 9pm

    Since I don’t yet have permission from my client to share the actual code I wrote, I’ll demonstrate this esoteric little feature by monkeypatching Hash and adding a using method. The end result will let us access Hash keys that match the names of the parameters we pass to the block, l...

  • Buckblog: Integration API vs. Internal API

    weblog.jamisbuck.org 05 Dec '15, 5pm

    These typically manifest as callbacks. Webhooks are one form of this. GitHub, for instance, lets you specify a URL which will be sent information when some event occurs (like a commit). Parsers also use this technique, allowing you to supply a set of callbacks to be invoked at various...

  • Upsilon Mazes

    Buckblog: Upsilon Mazes

    weblog.jamisbuck.org 28 Nov '15, 9pm

    This article is adapted from material that I had originally written for my book, Mazes for Programmers @amazon | @b&n . It was intended to be the last section in chapter 8, “Exploring Other Grids”, following a discussion of hex and triangle grids. In order to trim the length of the bo...

  • Buckblog: Little Things: Refactoring with Hashes

    weblog.jamisbuck.org 22 Nov '15, 1am

    Right? And when I see a case statement being used simply to select between different values given some input, I find myself itching to rewrite it using a hash. Because, really, what is a hash, except a mapping that selects between different values, given some input?

  • Representing toroidal grids and mazes

    Buckblog: Representing a Toroidal Grid

    weblog.jamisbuck.org 22 Nov '15, 12am

    Toroidal grids share a lot with spherical grids (pg. 238 of my book), so some of this may sound very familiar if you’ve been through that. A spherical grid is basically a soup-can wrapper rolled so the east and west edges touch (and then with a bit of magic applied to the north and so...

  • Buckblog: The Dynamic Def

    weblog.jamisbuck.org 17 Oct '15, 8pm

    If you need justification for this, try a simple benchmark script. It turns out that using a nested def for memoization results in a memoized method that is about 30% faster…but honestly, that’s not saying much. Both techniques are pretty blazing fast. On my computer, 500k iterations ...

  • Buckblog: Bulk Inserts in ActiveRecord

    weblog.jamisbuck.org 10 Oct '15, 9pm

    Each item is added to the queue, and the whole is accumulated into a single insert at the end of the block. (For lots of rows, it might not actually be a single insert statement, though. Some backends, like SQLite, don’t like you to insert more than some number of rows at a time. For ...

  • Buckblog: Bulk Inserts in ActiveRecord

    weblog.jamisbuck.org 10 Oct '15, 8pm

    Each item is added to the queue, and the whole is accumulated into a single insert at the end of the block. (For lots of rows, it might not actually be a single insert statement, though. Some backends, like SQLite, don’t like you to insert more than some number of rows at a time. For ...

  • 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...

    Related:
    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...

    Related:
    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:

    Buckblog

    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:

    Buckblog

    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...

    Related:
    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!

    Buckblog

    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...