Recent submissions

Comment · 10 years ago
Comment · 11 years ago
Unfortunately that won't work as expected, you'll need something ugly like:

  Array.apply(null, Array(26)).map((_, index) => String.fromCharCode(65 + index))
Comment · 11 years ago
I find it useful to have `unary` and `apply` around:

  [1,2,3].map(unary(User))
  [[1,2],[3,4],[5,6]].map(apply(User))
Comment · 12 years ago
In dynamic languages I don't see the need to create a Monad interface. I'd create classes/objects and simply use instances of those objects. As long as they conform to the desired interface, and you can check their relationships, then it should work; and use monkey-patching if necessary, embracing the dynamic nature of the language. I don't think it is possible to fully translate Haskell examples without the types, but you can adapt the ideas to other languages and get very similar functionality, in JavaScript for example:

    class Maybe {
      constructor(value) {
        if (value != null) {
          return new Just(value)
        }
        return new Nothing()
      }
      bind(f) {
        if (this instanceof Just) {
          return f(this.value)
        }
        return new Nothing()
      }
    }

    class Just extends Maybe {
      constructor(value) {
        this.value = value
      }
      toString() {
        return `<Just ${this.value}>`
      }
    }

    class Nothing extends Maybe {
      constructor() {
        this.value = null
      }
      toString() {
        return '<Nothing>'
      }
    }

    var result = Maybe(2).bind(x => {
      return Maybe(3).bind(y => {
        return Maybe(x + y)
      })
    })

    console.log(result.toString()) // <Just 5>
Comment · 12 years ago
Comment · 12 years ago
I was a Photoshop user for a long time, but haven't looked back since I moved to Linux full time a few years back. The challenge was to use libre software for everything and reduce my business' expenses. It's been 4 years since then and I don't miss Photoshop. I realized in the process the I was terribly misusing it. It was my goto tool for everything, from web design, to photo retouch, to vector, icons...

I have a background in 3D & VFX but my work today is mostly web development, and opensource software covers all my needs. MyPaint for free drawing like brainstorming, illustrations, and blueprints. Inkscape for vector graphics like icons, logos, layouts, mockups. Darktable for simple photo editing. GIMP for heavy photo retouch, and well, it's still my goto tool for those quick screenshots, image cropping jobs. And Blender for 3D work of course. I hardly do print, but when I do I use Inkscape, HTML and CSS.

TLDR; Photoshop isn't the best for every task. There are free software alternatives for everything. Using them all together provides me with all that I need, so I no longer miss Photoshop.

Comment · 12 years ago
Comment · 12 years ago
Comment · 12 years ago
I agree. I think music and sports consciously impact your code as well. Skills with a mix of creativity and endurance are going to affect the way you think about problems, in general.
Comment · 12 years ago
Then Windows Update: "Your computer will restart in 10 minutes". Postpone 4 hours. Glad I'm on Ubuntu 99% of the time nowadays.
Comment · 12 years ago
Comment · 12 years ago
"You might not need jQuery" -- But you have to cope with ugly syntax, browser compatibility hacks, and disconnected pieces of code. By the time you re-factor all of this, make it user friendly and lower the cognitive load, you're already re-inventing the wheel by building your own jQuery replacement, with the parts that you need.

The beauty of jQuery is working with the DOM as collections. I don't see how it's better to have all these helpers like `nextSibling`, `matches`, or `filter` thrown in the global scope or having to remember is this a real array? jQuery already built solutions for these common problems and exposes a nice API.

If all I need is querying the DOM and I don't have to support IE8 then I may consider using vanilla JavaScript, or building my own simple jQuery-esque library. But you'd start with some structure, and expose your own API. I re-invented the DOM wheel many times, and from my experience, although the code is smaller, I end up going back to jQuery because it covers some edge case or provides something else I need, like AJAX, or nice events, etc.

But building your own DOM library is a good educational challenge. Querying the DOM is all about collections, and if you don't need IE8 then you can use all the ES5 arrays methods, like map and filter. It all boils down to four functions to work with collections: toArray, unique, flatten and query. And four functions to work with the DOM: compose, join, dot, loop. See here for an example http://jsbin.com/EgIkega/1/edit. The article is more about techniques to build your own jQuery-like library; I wouldn't use "el.nextElementSibling || nextElementSibling(el)" when I can use "$(el).next()". C'mon!

Conclusion, you are probably going to use jQuery anyway.

Comment · 12 years ago
In LiveScript there's a := operator. From the docs -- "However, unlike CoffeeScript, you must use := to modify variables in upper scopes" -- I find LiveScript overall a better alternative to CoffeeScript. If you're into CS for the sugar, then you'll love LS.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton