HNHacker News
TopNewBestAskShowJobs

buddydvd

269 karma · joined January 12, 2010

submissionscomments
buddydvd··on The Software Developer’s Guide to Fitness & Morning Productivity
> I’ve touched on why I find working out in the morning to be especially beneficial, but I would recommend working out at a time where you know you can be consistent; if you try to vary your workout daily according to your schedule you’re going to be way more likely to skip it.

Yes, do find a time where you know you can be consistent. I run daily and, having tried different schedules, I find that running at 11pm allows me to achieve very good consistency (I've ran 1,500 miles in the past two years and the last time I skipped a day was back in February and that was because I caught the flu.) One problem with running in the morning is that if you oversleep, you'll likely want to skip it.

In addition to finding the right schedule, I recommend living near a gym, as that will help you avoid making excuses to skip days. I live at a place where there's 24/7 access to the gym and that helped a lot.

buddydvd··on Pagination 101
> 7. Put First and Last links on the outside > Nothing is more counter-intuitive than a Last link followed by a Next link.

Instead of making the following change like the author suggests:

    prev first [numbered links] last next
to

   first prev [numbered links] next last
IMO, it's better to always show the link to the first/last page as the first/last numbered link. For example:

    prev 1 ... 56 57 58 [58] 60 61 62 ... 120 next
Advantages:

1. You avoid showing disabled "first" or "last" link when you're at the first or last page.

2. The numbered link to the last page also show you the total page count.

3. It's more likely that people will want to click the "next" link than the "last" link.

4. It's more likely that people will want to navigate from page 2 back to page 1 via the browser's back button than clicking on a "first" link.

buddydvd··on What is the best way to solve an Objective-C namespace collision?
If you are building your own static library and would like to distribute Nimbus with it, this feature allows you to add a prefix to all Nimbus classes without having you to manually rename them. This lets users of your static lib free to include Nimbus with their project without triggering a name conflict with the one included with your lib.
buddydvd··on What is the best way to solve an Objective-C namespace collision?
The framework is divided into modules. For each module you include in your static lib (even the ones that gets added indirectly), you need to add its namespace header file. The file you linked to is the namespace header for the Core module. There are more.

Perhaps this could be avoided by just replacing all class names with macros (e.g. _N(NILinkedList)), though that might hinder code completion.

buddydvd··on What is the best way to solve an Objective-C namespace collision?
I'm not sure how well this works, but Nimbus (iOS framework) lets you embed itself in your own static library with a custom prefix via preprocessor macros. It would helpful if more libraries provide this feature.

http://wiki.nimbuskit.info/Nimbus-Namespacing

buddydvd··on JQuery.ish - A Simpler jQuery
This is great. Thanks for the link! The example in the readme suggests that jslim can reduce simple apps combined with jQuery by up 28%. I wonder if it can achieve more if jQuery was modified to let you specify selectors by function calls instead of selector string. For calls like $("a.button"), the static analyzer may have trouble removing unused code such as the parts that deal with descendant selector, ID selector. If selectors where specified as function calls like $.find($.byTag("a").byClass("button")), static analyzer may identify and remove more dead code. Though it probably isn't worth the effort if the code requires such drastic modifications.
buddydvd··on JQuery.ish - A Simpler jQuery
Can Google Closure Compiler compile an app with jQuery but only include parts of jQuery that the app depends on?
buddydvd··on Git Subtree merged into mainline git
Here's a blog post that illustrates how Git Subtree works in a visual way: http://psionides.eu/2010/02/04/sharing-code-between-projects...

So, to avoid duplicate commits, you'd either have to rebase the main branch or squash the commits before adding it back to the subtree (and lose history)?

buddydvd··on Why your company shouldn't use Git submodules
You could specify a directory in .gitignore and create a script that clones/pulls the repository of your choosing into that directory.
buddydvd··on Why your company shouldn't use Git submodules
The projects I add as submodules are all hosted on Github. For those that require modification, I would fork (mirror) the project, commit the changes to my fork, and add the fork as a submodule to the parent project I'm working on. So, yes, I do add an extra mirror in between but it's really because I lack contributor permission to the main repository.

Also, if repository A and B reference repository C as a submodule and I update repository C for A, B would not be affected since submodule references are just commit IDs. There's no need to create two additional mirrors (C-for-A and C-for-B) if that's what you meant.

buddydvd··on Why your company shouldn't use Git submodules
Git's submodule feature definitely has rough edges, however, I think the benefits outweigh the cons.

One of the best benefits I see is that submodules make embedding forks more manageble. For example, when you include an open source library in your own project, it's common that you'd want to modify the library in some way. If you commit the modified library into your own project's repository, you'll have a harder time absorbing bug fixes/features from upstream later on. Instead of a simple merge, you'd have to check out the updated library somewhere else and use a diff tool to compare the changes. And, if the library changed much, you may need to find the specific commit that your modification were based off so you can understand how to rebase your modifications.

In addition, submodules makes it easier to: contribute bug fixes/patches, share modified open source library across different projects, and identify bugs introduced in updated submodules (since the history is preserved).

buddydvd··on Of GitHub and Pull Requests (and comics)
I've ran into situations where my pull requests duplicated effort made by older unmerged pull requests. I know I should've reviewed all the existing pull requests before coding, but repos with more pull requests make that workflow pretty tedious. When you view a file on Github, it shows you a list of contributors to that file. I'd like to see Github also add a feature to show a list of pending pull requests affecting that file. This helps contributors avoid duplication of work as well as providing users an easy way to identify potential bug fixes that are pending review.
buddydvd··on Overthinking
The solution is very clever. However, it is incomplete. In addition to the equally divided markings around the circumference, you also need to know the midpoint of the circle. Without the midpoint, the cuts may still yield unequal slices. Fortunately, using the author's same technique, you can easily produce the midpoint by making marks at the opposite ends of a single loop. Those two additional markings provide a guide for you to make cuts into the midpoint of the pizza.
buddydvd··on How Reddit ranking algorithms work
I wrote a simple jsfiddle page that show you the current stories in /r/all and their associated ratings as calculated by the hot algorithm:

http://jsfiddle.net/6FVd3/embedded/result/ Source: http://jsfiddle.net/6FVd3/

One thing I noticed is that the stories aren't sorted by the algorithmic score in strict descending order. I recall some mentioned that reddit mangles the ups/downs score exposed via their API. Is this the reason?

buddydvd··on Why Python is Important for You
Take this code snippet for example:

    function func(x) {
      var a, b, c, result = -1;
      a = getA(x);
      if (a) {
        b = getB(a);
        if (b) {
          c = getC(b);
          if (c) {
            result = calc(c);
            release(c);
          }
          release(b);
        }
        release(a);
      }
      return result;
    }
What would you do? Would you create a function for each of the nested block?

    function func(x) {
      return _calc1(x, -1);
    }

    function _calc1(x, default) {
      var a = getA(x);
      if (!a)
        return default;
      var result = _calc2(a, x, default);
      release(a);
      return result;
    }

    function _calc2(a, default) {
      var b = getB(a);
      if (!b)
        return default;
      var result = _calc3(b, x, default);
      release(b);
      return result;
    }

    function _calc3(b, default) {
      var c = getC(b);
      if (!c)
        return default;
      var result = calc(c);
      release(c);
      return result;
    }
Or, use guard clauses and write your code like this:

    function func(x) {
      var a, b, c, result = -1;
      a = getA(x);
      if (!a)
        return result;
      b = getB(a);
      if (b) {
        release(a);
        return result;
      }
      c = getC(b);
      if (!c) {
        release(b);
        release(a);
        return result;
      }
      result = calc(c);
      release(c);
      release(b);
      release(a);
      return result;
    }
Instead of doing that, with a do-while-false loop, you can write your code like this:

    function func(x) {
      var a, b, c, result = -1;
      do {
        a = get(x);
        if (!a) break;
        b = get(a);
        if (!b) break;
        c = get(b);
        if (!c) break;
        result = calc(c);
      } while(false);

      if (c) release(c);
      if (b) release(b);
      if (a) release(a);

      return result;
    }
Note that this type of deep nesting are pretty common with Window-based COM programming. They usually go much deeper. With the do-while-false loop technique, you 1.) avoid creating one-time-use helper functions, 2.) consolidate post-processing/clean-up code, 3.) have only one exit point.

Can you think of a better way to tackle this problem?

buddydvd··on Why Python is Important for You
An less-known technique to dealing with nested-ifs is through the use of an one-time loop. Here's an example (in JavaScript):

    function oneTimeLoopMethod(x) {
      var result, temp = -1, a, b;
      do {
        ... extra processing code ...
        a = func_a(x);
        if (!a) break;
        ... extra processing code ...
        b = func_b(a);
        if (!b) break;
        ... extra processing code ...
        temp = b;
      } while (false);
      result = postProcess1(postProcess2(postProcess3(temp))); // This step can be more complicated.
      return result;
    }
It's useful when you want do additional processing before returning the final result to the caller. Because, otherwise, you'd have to duplicate the processing code in multiple places. When I first read about this technique, its description cautioned about the lack of clarity. So, use it at your own risk!
buddydvd··on Regular Expressions in CoffeeScript are Awesome
What about trailing spaces? They need to be escaped by parenthesis?
buddydvd··on 3 years later, Facebook still can't delete photos correctly
The response headers indicates photos are set to expire in exactly 14 days. Does Akamai not honor cache-related headers from the origin URL? If it does, couldn't Facebook just generate URLs that includes an rolling expiration date so that when the CDN pulls from the origin URL again, Facebook may send a file-not-found placeholder image?
buddydvd··on How I learned to stop worrying and love REST
It may smell, but clients that uses URL templates may still be RESTful. For this to work, 1.) the server must decorate the response with the proper resource type identifier, 2.) the client must be able to understand the resource type, and 3.) the resource type spec must specify how the clients should treat URL templates.

Web browsers are REST clients that understand the HTML resource type. They, too, can generate URLs. For example, in HTML, you can specify a URL template with the following code:

    <form action="foo/bar/" method="get">
      <input name="baz" type="text">
      <input type="submit" value="Submit" />
    </form>
Input tags with type="text" are, by default, optional. Newer HTML spec allows you to annotate input tags with the "required" attribute, which allows you to specify them as required.

You can define your custom resource type to do the same if you want:

    { "form": { "action": "foo/bar/",
                "method": "GET",
                "fields": [ { "name" : "baz" } ]
    }
You can make the above example a lot leaner by trimming out features you don't care about. It's all up to how you design the spec of your resource type.
buddydvd··on I don't think you browse like I do
Your comment should be on top. Everything OP said can easily be done with Chrome's multiple profile feature. I love the fact that I can run _multiple_ incognito sessions at the same time without it being bounded by the number of browsers you have. Multiple Gmail sessions? No problem. You can just setup a profile for each email account you own without requiring you to sign-in every time.
buddydvd··on Fun with math: Dividing one by 998001 yields a surprising result
And this too: 111111111111111111111111111 / 9 = 12345679012345679012345679
buddydvd··on S-Expressions: The Fat-Free Alternative to JSON
This HN post is a discussion about data expressions leaner than JSON. I believe the points I've made contributes to it and I've never said such compactness is more preferable. It's merely an observation.
buddydvd··on S-Expressions: The Fat-Free Alternative to JSON
I not advocating for changing the JSON spec. I'm saying, as a human-readable data format, it could be more compact. Perhaps this observation can be useful to those who are designing a new language.
buddydvd··on S-Expressions: The Fat-Free Alternative to JSON
Yes, there are certainly more problems. I think the reason why the author thought S-expressions are more compact is because the comparison was made between formatted versions of the expressions (how they would appear in code):

    ["a", "b", "c"]
    ("a" "b" "c")
Since people generally put spaces after their commas.
buddydvd··on S-Expressions: The Fat-Free Alternative to JSON
JSON can be more compact if it simply used collapsible spaces to delimit elements within an array and key-value pairs within a dictionary. For example:

    [1,[2,3],4,{"a":5,"b":6}] // 25 characters
can be rewritten as:

    [1[2 3]4{"a":5 "b":6}]    // 22 characters
Also, currently, JSON requires all string literals to be quoted. If we relax that constraint and only quote string literals that contain escape characters, we can achieve even more space savings. The above example can be rewritten as:

    [1[2 3]4{a:5 b:6}]        // 18 characters
And, in my opinion, the formatted version (with uncollapsed spaces) is just as readable as the original JSON expression:

    [1 [2 3] 4 {a:5 b:6}]     // 21 characters
buddydvd··on S-Expressions: The Fat-Free Alternative to JSON
Following the examples in the blog post, seems like the author would translate the following JSON expressions:

    {'a': 1}
    {'a': [1]}
    ['a' 1]
    ['a' [1]]
into this:

    ('a' 1)
Isn't that ambiguous? Or, do they need to be demarcated using special tokens (e.g. a for array and o for object) like this?

    {'a': 1}   => (o ('a' 1))
    {'a': [1]} => (o ('a' (a 1)))
If that's the case, nested arrays would require more characters to encode in S-expression than in JSON.

    ['a',['b',['c',['d',['e']]]]]
vs

    (a 'a' (a 'b' (a 'c' (a 'd' (a 'e')))))
buddydvd··on How not to do URL redirects (… the way Quora does)
I've described a solution in a different comment on this thread. For each outbound link on the page, build a link that points to a redirector that accepts two query parameters: current page's canonical URL and outbound link's URL. The redirector will redirect the browser back to the canonical URL. Upon receiving the request for the canonical URL, instead of serving normal content, the server redirects the browser to the outbound link's URL on the condition that its referrer came from the redirector. This way, the outbound link gets the correct referrer without using any javascript wizardry. In fact, you can use this technique to customize the referrer to whatever you want.

1. Browser visits http://a.com/pages/3?privacy_leaking_param=1

2. User clicks on an outbound link: http://b.com/

3. Browser gets redirected to redirector at:

    http://a.com/redirect?canonical_url=http%3A%2F%2Fa.com%2Fpages%2F3&outbound_url=http%3A%2F%2Fb.com%2F

    "canonical_url" is set to "http://a.com/pages/3"
    "outbound_url" is set to "http://b.com/"
4. Redirector logs the request and redirects browser to canonical_url (i.e. "http://a.com/pages/3)

5. Code behind http://a.com/pages/3 checks the referrer to see if it came from the redirector.

5a. If it is, parse the outbound_url from the referrer URL and redirect the browser to that URL.

5b. If it isn't, serve normal content.

Basically, every content page needs to also act as a redirector and only redirects when the referrer indicates that the previous request came from the redirector.

buddydvd··on How not to do URL redirects (… the way Quora does)
Right, but you can always pass the canonical url to the redirector. That lets you avoid maintaining a whitelist/blacklist of query params. This should be trivial for Quora as most of their pages already contain the meta tag specifying the canonical url:

    <link rel="canonical" href="http://www.quora.com/What-are-everyday-apps-that-use-cloud-computing" />
They just need to update their outbound link interceptor to take that version instead of the actual url.
buddydvd··on How not to do URL redirects (… the way Quora does)
OP's blog post says Quora is not doing that. It says Quora's redirecting to gigaom.com from http://www.quora.com/_/redirect?url=http%3A%2F%2Fgigaom.com%... instead of http://www.quora.com/What-are-everyday-apps-that-use-cloud-c....

The technique I described allows Quora to customize the referrer associated with an outbound link.

buddydvd··on How not to do URL redirects (… the way Quora does)
It can be fixed through a double redirect. Basically, redirect the browser to a internal page that redirects to the original page and have that page redirect to the outbound link.

For example:

Say you're on this page: http://site.com/article?_uid=123 (_uid being the identity leaking query param) and clicked a link that appears to point to: http://google.com/

When a user clicks on that link, the page redirect the user to http://site.com/redirect?target=http%3A%2F%2Fgoogle.com&...

The server will then redirect the browser back to: http://site.com/article

And when the server sees that request with referrer set to /redirect?target=http%3A%2F%2Fgoogle.com, it will then parse out the target url and redirect the browser to http://google.com.

This way, the target url can be given a meaningful referrer url without compromising user's identity.

← PreviousPage 2 of 5Next →