Hacker News new | past | comments | ask | show | jobs | submit login

The only thing I have ever gone back and admired is when I wrote the following snippet of code:

  long time; // no see



Hehe, well if we're going here there are various go-to shell commands / filenames / hostnames I inevitably end up using at some point just for the wry smile:

    $ PONG=1.1.1.1; ping $PONG
    $ more cowbell
    $ cat dog | tee hee
And my favourite choice of empty file:

    $ touch me
Also I was fairly please years ago when I briefly re-aliased cd to something that could do "the right thing" (TM):

    $ cd ...
    $ cd ..../src/
etc..


"cd ..." etc. worked in 4DOS, an alternative (and extended) DOS shell: https://en.wikipedia.org/wiki/4DOS.


I think it was standard DOS, from maybe DOS 5 upwards?


I was thinking it worked in MS DOS after some point, but I was remembering more like Windows 95 era. I don't think it worked in MS DOS 6.x, because IIRC that's when I was using 4DOS. However, it doesn't work in Windows 10 CMD.EXE.


I wrote a generic bash function to spin up a mongodb instance called `mongo`. I couldn't resist adding

`echo "Mongo only pawn in game of life"`


You would get bonus points if you wrapped the mongodb process so that when it receives a SIGKILL it logs out "Mongo like candy!"


LOL - thanks for sharing this. Especially "$ more cowbell".

I am SO gonna steal that.

:-D


I came across this gem recently:

    catch (Exception up)
    {
        throw up;
    }
Truly genius code


  try
     ToastTheGenius;
  except
   On Glass: Exception do
     raise(Glass);
  end;


Or in Python:

  except Exception as the_roof:
      raise the_roof


I'm... going to have to use this. A lot.


I once came across a function that declared this:

    int ofTheJedi;
I was a bit confused until I got at the bottom of that function and saw this:

   return ofTheJedi;
That's when I recognized a coworker's style, haha


I once came across some code, written by a coworker, that consisted of deeply nested blocks. I added a comment that simply contained a URL:

  // http://photos3.meetupstatic.com/photos/event/4/b/c/2/600_436939394.jpeg
I don't know if anyone ever noticed this comment and followed the URL, but I hope they did and were amused. (The code was eventually refactored/rewritten, so the comment no longer exists in the codebase.)


Well, I followed the URL and was amused. So it wasn't a complete loss (even if I never did see the code). Thanks for sharing!


Remember timecube guy? Seen on a 16-bit DSP...

    struct timecube {
        uint16_t millisecond_of_minute;
        uint16_t minute_of_month;
        uint16_t month_and_year;
    };


That's clever. I might steal that at some point. Or combine into a millisecond_of_month on a 32 bit processor.

For people that don't play with bits often: Unsigned 16-bit integers have their max as 65,536. Storing data often wastes most of the bits, since a field that goes from 0-1000 doesn't fit in an 8-bit integer, and C doesn't have native integers between 8 and 16 bits long. (You can mask out relevant fields, but that's annoying.)

So there are 1000 * 60 = 60,000 milliseconds in a minute, which is an impressively good use of the space available. There are also a max of 60 * 24 * 31 = 44,640 minutes in a month, which is pretty good usage of the second value as well. The final 16 bits are probably 4 bits for month and 12 bits for the year, going up to 4096. Alternatively it could be using it as something like month_of_common_era to get it out to year 65536/12 = 5461.


It also cooperates with leap seconds, by counting faithfully up to 61,000 on such a minute.

IIRC, month and year was a 4-bit and 12-bit bitfield just as you describe.


This gem in a Flash frame (Actionscript)

    stop(); // hammer time


was there an actual hammer involved in the game at this point? I think then it would be great, most of these cute, funny bits of code are making me feel annoyed by proxy.


I wrote the following, completely innocently:

  return when.all(promises).yield(true);


Except for the return to happen when that's true, you'd need an await. At least in JS.


Not if it's returned by an async function. In JS, async functions automatically await promises that are returned.


That's not actually right. An async function will always return a promise, so if you return a promise directly it's indeed pretty much the same as if you return a promise that waits on that promise; it's the calling function that actually awaits on the returned promise.

The main difference would be error handling: if you have a catch block that returns a different value, returning the promise directly would actually throw in the calling function, whereas if you "return await", it's going to get caught in your catch block, resolving the promise to your own custom value.

Found a detailed explanation here: https://jakearchibald.com/2017/await-vs-return-vs-return-awa...


Every time I implement an action class, I make sure to make an empty parent class to subclass it from.

    class Action(Lawsuit): ...


Code puns, yay!

Mine:

    const makeEmptyPromise = () => Promise.resolve([]);


That's worth printing on a t-shirt. :)


But was this in C?


It was in Java...but I C where you are going with this.


Well, actually, the fact that it wasn't in C kinda makes it work even better, from one point of view. :-D




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: