Gotos aren't necessarily bad - for example when you have a large amount of nested loops and need to break out of a certain number of them.
Confess HN: Share your Immoral Hacks, Codes or Tweaks
31–40 of 70 posts
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#32Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#33Earlier quoted context omitted.
What you really want are continuations.
Pardon my presumed ignorance, but how is that?
(Loop exits, exceptions, returns from functions, etc. are all special cases of continuations.)
This is an improvement over something like Perl's "last LABEL" statement, because you can pass the continuation around and exit the loop from anywhere you desire.
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#34 // we don't even pretend to work on anything but i386 and LE arm
const unsigned char c[] = { 0x78, 0x56, 0x34, 0x12 };
assert(sizeof(int) == 4 && *((int*)c) == 0x12345678);Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#35I wanted to adapt someone's command-line-based program into a library, but it wasn't designed as such. The program was strewn with calls to exit(), and on encountering one of these I would just want to return to the function that called into the library rather than exiting the whole program. So I did a setjmp() prior to calling into it, and used the preprocessor to turn exit() into longjmp().
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#36Select ''||lvar_title||'' from tickets where ...
because I was to lazy to do it in the proper layer...
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#37I am writing PHP in Common Lisp, and my codebase is litered with the following: (defun make-record (&rest args) ; insert &allow-other-keys ;-) (let ((*db-auto-sync* t)) (object (make-instance 'record args))) (when object (update-records-from-instance object)))) Both the LET binding of db-auto-sync and the update-records call do the EXACT same thing. However, due to weirdness I don't grok quite yet, the calls to the d…
I've always wanted to do sort of the opposite... That is to say, I've always wanted to compile Scheme to PHP. I make the claim that PHP is the web's assembly language. Or, at least it's portable assembly language.
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#38"union select " 233455 ", " "usa"
"union select " 233455 ", " "canada"
Then puttied into my linux shell, opened emacs and added "create temporary table select 23456 as 'systemid', 'usa' as 'region'
Then pasted the entire csv of union selects. Did my joins, etc... Got the report out on time. I know now that I could have done it with an emacs macro, but just didn't have time to figure it out.
shudder
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#39Well, here's one that, erhm a friend of mine, did. dating has moved online, and the key to getting laid is basically to get as many contacts going as you can. It's like a funnel: The more you put in at the top the more comes out at the bottom. The problem of course is that all that initial contact and writing back and forth with potential subjects is somewhat timeconsuming. Enter the magic of webscraping and hacking.…
Re: Confess HN: Share your Immoral Hacks, Codes or Tweaks
#40I had just taught myself php and wrote a curl script with the classes I wanted, and the few timeslots I wanted, in order. After a brief struggle I finally realized I needed to hit port 443 instead of 80 and, voila, my initial class registration was complete. A few were full but it kept hammering the site every 10 seconds and over the next few hours I got emails whenever it successfully registered me with a class.
I actually thought about charging $5 to handle other students' registrations because they hated dragging out of bed at 8am and refreshing their browser for an hour. Somehow I decided the university wouldn't approve....