Not able to upload code onto arduino mega

So the main processor seems OK, the few flashes are from the boot loader. What does your operating system think about the board? I'm not a Mac user so don't know how to check.

What is the chip closest to the USB port? A square one with legs at all sides or a rectangular one with legs at two sides. The former would be a 8U2 or 16U2, the latter a CH340 or FTDI232. For the 16U2, 8U2 and (probably) the FTDI, you can run the loopback test; see Loop-Back Test Instructions; the loopback test will fail with the CH340 so is not conclusive.