8 ms·
The only thing I have ever gone back and admired is when I wrote the following snippet of code: long time; // no see
by ejflick 6y ago
The only thing I have ever gone back and admired is when I wrote the following snippet of code:
long time; // no see
- yread 6y agoI came across this gem recently: catch (Exception up) { throw up; } Truly genius code
- ak39 6y agotry ToastTheGenius; except On Glass: Exception do raise(Glass); end;
- deleted 6y ago[deleted]
- ISO-morphism 6y agoOr in Python: except Exception as the_roof: raise the_roof
- cryptonector 6y agoI'm... going to have to use this. A lot.
- pbadenski 6y agoCode puns, yay! Mine: const makeEmptyPromise = () => Promise.resolve([]);
- declnz 6y agoHehe, 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..
- mkl 6y ago"cd ..." etc. worked in 4DOS, an alternative (and extended) DOS shell: https://en.wikipedia.org/wiki/4DOS https://en.wikipedia.org/wiki/4DOS.
- stevage 6y agoI think it was standard DOS, from maybe DOS 5 upwards?
- mkl 6y agoI 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.
- murph-almighty 6y agoI 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"`
- jkingsbery 6y agoYou would get bonus points if you wrapped the mongodb process so that when it receives a SIGKILL it logs out "Mongo like candy!"
- nocman 6y agoLOL - thanks for sharing this. Especially "$ more cowbell". I am SO gonna steal that. :-D
- mehrdadn 6y agoBut was this in C?
- ak39 6y agoThat's worth printing on a t-shirt. :)
- delta1 6y agoThis gem in a Flash frame (Actionscript) stop(); // hammer time
- bryanrasmussen 6y agowas 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.
- stevage 6y agoI wrote the following, completely innocently: return when.all(promises).yield(true);
- ohvirginia 6y agoExcept for the return to happen when that's true, you'd need an await. At least in JS.
- acarl005 6y agoNot if it's returned by an async function. In JS, async functions automatically await promises that are returned.
- deleted 6y ago[deleted]
- emilecantin 6y agoThat'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-await/ https://jakearchibald.com/2017/await-vs-return-vs-return-awa...
- emilecantin 6y agoI 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
- doodpants 6y agoI 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.)
- nocman 6y agoWell, 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!
- brandmeyer 6y agoRemember 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; };
- timerol 6y agoThat'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.
- brandmeyer 6y agoIt 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.
- scrollaway 6y agoEvery time I implement an action class, I make sure to make an empty parent class to subclass it from. class Action(Lawsuit): ...