It's been a couple of stressful weeks. We've all been working our socks off trying to do our bit, and in so doing, we might have neglected ourselves. From time to time, it's a good idea to remind ourselves how awesome we are. By we, I mean elite programmers.
My goals in awesome coding are 1) to produce feline-legible code 2) that produces results within the 12 hours or so of the day when we're napping and 3) is capable of making an educated guess if not. Two out of three is good enough to qualify as awesome.
Some examples coming up.
This one is a LoremIpsum generator in Java. It is guaranteed to be bug-free:
https://gist.github.com/3136492
Next up, inverse square root approximation in LOLCODE:
HAI
CAN HAZ STDIO?
OBTW
inverse_sqrt implementation
TLDR
HOW DUZ I INVSQRT YR NUM IT R A FLOAT
I HAZ A ITEMARATIONTIMEZ IT R 1 SRSLY BTW increase iteration times for accuracy
I HAZ A NUMHALF IT R NUM TIEMZ 0.5 IT R A FLOAT
I HAZ A OUTPUT IT R NUM
I HAZ A BITVAL IT R OWAIT TEH OUTPUT DEN MAEK DAT A LONG LAZERPOINTR DEN TEH DAT MKAY
SHIFZORZ BITVAL!!1
BITVAL R HAX5f3759df NERF BITVAL
OUTPUT R OWAIT TEH BITVAL DEN MAEK DAT A FLOAT LAZERPOINTR DEN TEH DAT MKAY
I HAZ A VAR IT R 0
IM IN YR LOOP UPPIN YR VAR!!1 TIL BOTH SAEM VAR AN ITEMARATIONTIMEZ
OUTPUT R OWAIT NUMHALF TIMEZ OUTPUT TIEMZ OUTPUT DEN 1.5 NERF DAT DEN OUTPUT TIEMZ DAT MKAY
IM OUTTA YR LOOP
FOUND YR OUTPUT
IF U SAY SO
KTHXBAI
Some selected stuffs from my LOLMAFF library.
HAI
CAN HAZ STDIO?
HOW DUZ I IZ_BOOMZ!!2 YR NUM IT R A INT
I HAZ A ANSWER IT R A INT
ANSWER R NUM PWNZ!!! AN OWAIT NUM ANDBITTEH OWAIT NUM NERF!!1 MKAY MKAY
FOUND YR BOTH SAEM ANSWER AN 0
IF U SAY SO
HOW DUZ I BUFF_BOOMZ!!2 YR NUM IT R A INT
BOTH SAEM NUM AN IZ_BOOMZ!!2 NUM
ORLY
YARLY
FOUND YR NUM
NOWAI
IZ NUM LIEK PWND!!2 OR BOTH SAEM NUM AN 2
ORLY
YARLY
FOUND YR 2
KTHX
KTHX
NERFZ X!!1
ORBITTEHZ X!!X SHIFZOR!!1
ORBITTEHZ X!!X SHIFZOR!!2
ORBITTEHZ X!!X SHIFZOR!!4
ORBITTEHZ X!!X SHIFZOR!!8
ORBITTEHZ X!!X SHIFZOR!!16
FOUND YR X
IF U SAY SO
HOW DUZ I NERF_BOOMZ!!2 YR NUM IT R A INT
BOTH SAEM NUM AN IZ_BOOMZ!!2 NUM
ORLY
YARLY
FOUND YR NUM
NOWAI
PWND!! NUM BY 2 OR BOTH SAEM NUM AN 2
ORLY
YARLY
FOUND YR 2
KTHX
KTHX
I HAZ A ANSWER IT R 1
I HAZ A LASTBOOM IT R 0
IM IN YR LOOP TIL LOLNO PWND!! ANSWER BY NUM
LASTBOOM R ANSWER
SHIFLOLZ ANSWER!!1
IM OUTTA YR LOOP
FOUND YR ANSWER
IF U SAY SO
HOW DUZ I ABS YR NUM
PWND!! NUM BY 0
ORLY
YARLY
FOUND YR NERF 0!!NUM
NOWAI
FOUND YR NUM
KTHX
IF U SAY SO
HOW DUZ I MOD INLINE YR NUM IT R A FLOAT AN YR PERIOD IT R A FLOAT
NUM R LEFTOVARZ NUM!!PERIOD
NUM BIGRLIEK 0
ORLY
YARLY
FOUND YR NUM
NOWAI
FOUND YR NUM BUFF!!PERIOD
KTHX
IF U SAY SO
HOW DUZ I CYCLIC_DIFF YR HI IT R A FLOAT
AN LO IT R A FLOAT
AN PERIOD IT R A FLOAT
AN WRAP IT R A TROOF
WRAP R WIN
ORLY
YARLY
HI R MOD HI!!PERIOD
LO R MOD LO!!PERIOD
KTHX
HI BIGRLIEK LO
ORLY
YARLY
FOUND YR NERF HI!!LO
NOWAI
FOUND YR NERF BUFF HI!!PERIOD!!LO
KTHX
IF U SAY SO
KTHXBAI
I guess you can count me out...I tend to skip Meudo code and dive right in. ;-)
Quote from: WanderingAries on September 18, 2012, 04:00:34 AM
I guess you can count me out...I tend to skip Meudo code and dive right in. ;-)
Hey, it's real code. Compiles smoothly with -w.
Also, awesome code is language-agnostic. ;D
Anonymized production code:
#include <cstdlib>
#include <cstdio>
#include "includethis.h"
using namespace std;
typedef int unused;
class FacingDirection : public Direction, public ISCDef
{
public:
inline FacingDirection operator++(unused)
{
if (mIsFacingNorth)
{
setIsFacingEast();
}
else if (mIsFacingEast)
{
setIsFacingSouth();
}
else if (mIsFacingSouth)
{
setIsFacingWest();
}
else if (mIsFacingWest)
{
setIsFacingNorth();
}
return *this;
}
FacingDirection operator++()
{
cerr << "Operation not supported.";
exit(1);
}
FacingDirection operator--(unused)
{
delete[] dirs;
dirs = NULL;
return *this;
}
FacingDirection operator--()
{
cerr << "Operation not supported.";
exit(1);
}
void setIsFacingNorth()
{
mIsFacingNorth = true;
mIsFacingEast = false;
mIsFacingSouth = false;
mIsFacingWest = false;
}
void setIsFacingEast()
{
mIsFacingNorth = false;
mIsFacingEast = true;
mIsFacingSouth = false;
mIsFacingWest = false;
}
void setIsFacingSouth()
{
mIsFacingNorth = false;
mIsFacingEast = false;
mIsFacingSouth = true;
mIsFacingWest = false;
}
void setIsFacingWest()
{
mIsFacingNorth = false;
mIsFacingEast = false;
mIsFacingSouth = false;
mIsFacingWest = true;
}
}
Won't lie, the most coding I've done was "Intro to Basic" back in high school. In said class, one of the activities was "Write a program for making a peanut butter and jelly sandwich", which I played masterfully. I wrote an intentional endless loop which ended up using the entire bag of bread and half a container of peanut butter before the teacher figured out I'd done it on purpose :D
I was probably the best programmer in the bunch. Admittedly, not because I was any good at it, but because everyone else in there was kinda dumb (but they were my friends, so I helped them out anyway :p)
Quote from: ROBOKiTTY on September 18, 2012, 06:05:28 AM
Anonymized production code:
I followed...most of that. :-p
function icanhazcheezburger($array) {
echo "I want a Cheeseburger with: ";
foreach ($array as $arr) {
echo "$arr[1] $arr[0], ";
}
}
echo icanhazcheezburger(array(array('Double Meat', ''), array('Tommato', 'No'), array('Ketchup', 'No'), array('Mustard', 'No'), array('Lettuce', 'Add'), array('Bacon', 'Add')));
I want a Cheeseburger with: Double Meat, No Tommato, No Ketchup, No Mustard, Add Lettuce, Add Bacon
This came about because I listed on my FB profile I could speak PHP, someone asked me to order a Cheeseburger, so I did.
This one is expressive, but seems to be missing that certain je ne sais quoi...
dtCurrentDate.mDateConvertFunc = function out(d) {
return (function (stD) {
if (!!~d)
{
return fn2(function (d) { return in(d) (fn3); } );
}
return fn3(function (d) { if (!!~d) throw d.getString("lc") + " is malformed or corrupted."; } );
});
};
I remember my BASIC days...
10 PRINT "NCSoft sucks..."
20 GOTO 10
30 PRINT "No wait... NCSoft rules!"
40 REM I'll remove 20 when they come to their senses.
↑ ↑ ↓ ↓ ← → ← → B A Select Start
Or the lesser known:
↑ ↓ ↑ ↓ ← → ← → ↑ → ↓ ← ↑ B
In the vein of the above, I present: IDDQD! Best code ever.
Because of a bug in my LOLCODE maintenance script, my cygwin was broken:
(https://images.weserv.nl/?url=euniana.kahlan.org%2Fcygwin-messedup.jpg)
Now writing a new LOLCODE script to repair the problem.
It's not uncommon that I need to manually unroll loops when tuning for performance. However, this can get tedious, especially when loops iterate more than a dozen times. The obvious solution is to expedite the process with a script.
I present you this BF (http://en.wikipedia.org/wiki/Brainfuck) routine. Supply a code snippet, and it will be automagically duplicated about 999 times. No moar manual code duplication.
+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+[->,----------]<[<]<<[>[>>[++++
+++++++.----------->]++++++++++++++++++++++++++++++++.--------------------------------<[<]<-]<->+++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++<]
http://ws.apache.org/xmlrpc/apidocs/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.html
Marvellous enterprise design, wouldn't you say?