/sog/ - show off general

show off your programming skills.
-or-
Show off some code you have written that works.

Other urls found in this thread:

stackoverflow.com/questions/3700971/immutable-array-in-java
twitter.com/SFWRedditImages

r8 my boss AI interface Sup Forums

>Average C# toddler

...

wat is this?

...

...

show us some ingame screenshots

>thing.c
>156MB
I'm scared

If I told you, I'd have to kill you.

(More like it would expose my identity as a useless asshole that posts on Sup Forums)

That picture is painful. I'll never use a language with (((header files)))

but it's just a game user.

str = str[(len(str)-15):(len(str)-13)] + str[(len(str)-12):(len(str)-9)]
Only god can forgive my sins

>subtracting from string lengths

>using system.linq

currently creating a "catalog" string array for an in-game shop example.

HEre it is:
public class catalog {

public static void main(String[] args) {
String[] catalog = new String[10];
catalog [1] = "Landmine";
catalog [2] = "Bowie Knife";
catalog [3] = "";
catalog [4] = "";
catalog [5] = "";
catalog [6] = "";
catalog [7] = "";
catalog [8] = "";
catalog [9] = "";
catalog [10] = "";

}

}

post with dubs decides what will occupy 3-10.

language?

>swift.png
nvm lel

that's kilobytes you doofus

what the fuck
do you not know how to initialize arrays? or is your autism a "stylistic choice"

What's this for ? And how would it work for anything ?

>do you not know how to initialize arrays?
I do know how to initialize arays. Watch me do it right now:
String[] catalog = new String[10];

:^)

>is your autism a "stylistic choice"
i suppose you could say that ;^)

i think it looks great, user.

each level of my game has a boss, and each one's AI is different, but all of those AI's belongs to this interface (protocol in Swift)

I like everything about your setup... font, rendering, colors, and language. what is it?

please read the image name.

space shooter game

parsing strings always turns ugly

str = str[str.find("I love big")+11:str.rfind("cocks")]

thanks.
Here is the completed list:
String[] catalog = new String[10];
catalog [1] = "Landmine";
catalog [2] = "Bowie Knife";
catalog [3] = "Sticky Bomb";
catalog [4] = "Glock";
catalog [5] = "AK-47";
catalog [6] = "Bill Cosby";
catalog [7] = "Terminator";
catalog [8] = "Militant Autist";
catalog [9] = "Downie Debbie";
catalog [10] = "Pepe";

>156,280KB
>Roughly 156MB

I know you're baiting but it's 156KB

k = kilo = 1000
b = byte = 1
156,280b = 156kb

but it was 156,280 kilo bytes, not bytes.
therefore it was ~156 mega bytes
mega = 1000 kilo bytes

but it's not

oh...

Nothing says those are bytes, not kilobytes, and since virtually every system on the planet defaults to displaying kilobytes because of blocking, it makes sense to infer that it is 156,280 KILObytes, not bytes.

if you're basing your argument on sense, then does it make sense for source file some user made in his "crappy project" to be 156MB?

That's declaring an array, not initializing it. Initializing means setting all the values in the array to something.

Some of the codebases I've seen would lead me to believe that yes, it's reasonably probable for somebody that doesnt know what they're doing to create a 156MB source file.

It's in bytes, holy shit.

I don't get what's wrong with this picture.

t.not a programmer.

Imagine you want to buy a car for daily driving.
Imagine buying 7 cars, one for driving on monday, one for tuesday, wednesday, etc.

Does that sound stupid to you to you?

I see, so how would that whole piece of code be structured properly?
Could you show?

You wouldn't understand it even if I explained it.

What hinders you from explaining it properly?

purple whitey greeney color scheme, doh

As a starter you could have 2 string-string maps,
then writing everything like
this.Subtitle.UpdateLabel(subtitles[this.Witnessed], 1, 6f);
this.GameOverCause = causes[this.Witnessed];

I have a feeling theres more shitcode behind this though/

Yanderedev is storing stateful information as a string and he wrote the lose-condition checker to parse this string in the stupidest way possible.
>do this thing if teacher sees "weapon and blood and insanity"
>else do this thing if teacher sees ONLY "weapon and blood"
>else do this thing if teacher sees ONLY "blood and weapon"
>else do this thing if teacher sees ONLY "blood"

Look at what changes in each condition : only the number 0, 1, 2 in the argument of a function. So you could use a variable in the call of the function instead of that. Something like :

lightAttend.x,PixelShaderGetLightColor(cLightInfo,nNumLights)

Then, beware. Because how the conditions are depicted in the codes means that if nNumLights is 2, we want 0 and 1 to activate aswell. This can be made through an easy "for" loop that ranges from 0 to nNumLights.

In a nutshell, here, only take the code embedded in a "if" block, put it in a for loop that ranges from 0 to nNumLights, than use the indexation index to call the function

lightAttend.x,PixelShaderGetLightColor(i)

abbreviated version, logically identical assuming the if statements continue till n where n is the max value of nNumLights
for(int light = 0; light < nNumLights; light++)
{
PixelSha...(...(cLightInfo, nNumLights)
}

what's the point of this thread?
you can't 'show off' code like that.

that's like taking a paragraph from a novel and saying its a master piece. you don't know the context so how the fuck can you judge it.

then again everyone on Sup Forums is probably a retard that only pays attention to inane things like how pretty your font rendering is or what variable names you use

fucking stupid.

i made mistake, the inner scope should use the light variable obviously
could make the code shorter if order didnt matter

>he's never written a beautiful algorithm in his life
probably a javascript programmer

I see so basically his approach is simplistic and naive and could have been done properly which would reduce the amount of "code"?
This sounds reasonable if the number of lights increase, the loop will ease up of us.
But how will it be when the number of lights is more than the 0,1,2?
How would it be dealt if it was like 1000x or 10000x?

it's basically a long version of this
(though it should read Array[i], but you get the idea)

right so depending on what you limit was
you could cap it at 3 lights with
for(int light = 0; light < nNumLights && light < 3; light++)

Simplistic would be storing the state of a witness NPC with a bunch of flags.
Even a stupid, naive, and wasteful version of this would be something like
struct npc_witness { int weapon, blood, insanity; };
So now you can just toggle these values on or off without having to worry about the order they were encountered.
And once this npc encounters a corpse, it can just check which ones are flipped on to create the game over reason.

This is probably bait, but anyway. Arrays in Java are zero-based, retard

maybe catalog[0] is reserved for something special, GOSH

catalog[10] is out of range you nug

You really don't code ? You should look into it mate.

These kinds of codes are funny because they make no use of the automation power of a computer. It's like using a drill as a screwdriver.

>class is called catalog
>string array is called catalog

Well, maybe my choice of word wasn't right. What I meant with simplistic isn't "simplistic good" but simplistic as it "works but not the way one should ever do it".
I don't code because I know don't have the energy and will power to go through. But it's fun to watch these stuff and think about what went through their mind when doing this.

good detective work user. I did not catch that, that user deserves to be thrown out of this threads. WHERE ARE THE GAURDS!!!

why stop there
>lowercase class name
>manually assigning empty string to empty element
>not declaring your readonly array as readonly
>declaring your readonly array in entrypoint
>declaring anything at all in main()
>index out of bounds
nothing about this code is right

you cant declare it as "read" only, its in Java. That does not exist in java

Read only in Java would be final I think

t.not programmer

if (goingToCrash()) dont();

well fuck java then, can you make it final or at least give it a getter and no setter
actually you could set it to private because you wouldn't want anyone accessing that list anyway, you'd want a draw method or something

final does not work. Look at this:
stackoverflow.com/questions/3700971/immutable-array-in-java

I see, so the final statement allows it to be changed even through it's declaration states its final and not supposed to be changed.

oracle knows best
let everyone use sun's shitty language then sue the fuck out of them when they start making money off it

This is a part of xml I got on my final to which I had to write html with javascript

Fuck.
Wouldn't it be better to use XSLT?

C / asm code from crackme ctf I wrote.
void flagtaken(void)
{

DWORD high = 46;
DWORD low = 0;
DWORD tiny = 1;
DWORD tall = -1;
__asm
{
movd mm0, dword [high] ; mov ecx, 046

movd mm1, dword [low] ; mov eax, 0
movd mm2, dword [tiny] ; mov ebx, 1
movd mm4, dword [tall]

_loop:
movq mm3, mm2 ;mov edx, ebx
paddd mm3, mm1 ;add edx, eax
movq mm1, mm2 ;mov eax, ebx
movq mm2, mm3 ;mov ebx, edx
paddd mm0, mm4 ;add ecx, -1

movd ecx, mm0 ;jnz _loop

cmp ecx, 0
jnz _loop
;_exit:

movd ecx, mm2 ;mov ecx, ebx

; end of code to virtualize
cmp ecx, 2971215073 ; 46th fibonacci number
jnz bad
jmp good
bad:
push 0
call ExitProcess
good:
nop
}

printf("Good job, the flag is ");
char msg1[] = {0x38,0x3c,0x3e,0x20,0x31,0x34,0x2c,0x3a,0x78,0x00};
char msg2[] = {0xcc,0xdf,0xc7,0xc3,0xcc,0xdf,0xc7,0xc3,0x00};

decrypt_string(msg1, 0x55);
printf("%s",msg1);

decrypt_string(msg2, 0xaa);
printf("%s\r\n",msg2);
printf("Use this as the flag.");

system("pause");
}

It was not allowed. This is what the final product was supposed to look like :

>It was not allowed. This is what the final product was supposed to look like :

Damn that's harsh, luckily in real life you won't be restricted.

>luckily in real life you won't be restricted.

Lol, I am economist major
This was one optional course called
>Internet and mobile applications

And I am like, sweet, fianly something with Android

Nope
Nope
>Nope Nope Nope
xml, xslt, javascript, JASON and AJAX
:(

i would have dropped it on the first day. Didnt they give a syllabus of what your doing? you surely knew that there was going to be no android/ios after the first week.

It was like, you have 3 options from which to pick and you haveto pick one.
So I picked this one and stick with it.
Still better than the other options, trust me.

import facebook_killer
facebook_killer.run('0.0.0.0', 443)


And watch the $€£ flow in.
Who wants to invest in my start up?

I fucking hate programming. I suck at programming. Fuck you, momma's tech geniuses. I am surely enjoying my zero problem solving skills. At least I can google shit at stackoverflow.

t. normie pajeet

No, he's declared and initialised it in one line.

i don't code because i'm not a monkey

COBOL program to reduce fraction from a dat file.
IDENTIFICATION DIVISION.
PROGRAM-ID. FRAC-SIMP.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FRAC-FILE ASSIGN TO "FRACTIONS.DAT"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD FRAC-FILE.
01 FD-FRAC.
88 END-OF-FRACS VALUE IS HIGH-VALUES.
02 FD-NUM PIC 9(10).
02 FILLER PIC X VALUE SPACE.
02 FD-DEN PIC 9(10).

WORKING-STORAGE SECTION.
01 FRACTION.
02 NUM-RED PIC 9(10).
02 FILLER PIC X VALUE SPACE.
02 DEN-RED PIC 9(10).

01 A PIC 9(10).
01 B PIC 9(10).
01 WS-GCD PIC 9(10).

PROCEDURE DIVISION.
BEGIN.
OPEN INPUT FRAC-FILE
READ FRAC-FILE
AT END SET END-OF-FRACS TO TRUE
END-READ

PERFORM UNTIL END-OF-FRACS
CALL "GCD"
USING BY CONTENT FD-NUM, FD-DEN
RETURNING WS-GCD
END-CALL

DIVIDE FD-NUM BY WS-GCD GIVING NUM-RED
DIVIDE FD-DEN BY WS-GCD GIVING DEN-RED
DISPLAY FRACTION

READ FRAC-FILE
AT END SET END-OF-FRACS TO TRUE
END-READ
END-PERFORM
CLOSE FRAC-FILE

MOVE 12 TO A
MOVE 4 TO B
CALL "MULT2" USING BY CONTENT A, B RETURNING WS-GCD END-CALL
DISPLAY WS-GCD

STOP RUN.

Utils file containing the GCD subprogram
$set repository "update on"
IDENTIFICATION DIVISION.
PROGRAM-ID. GCD.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 TMP PIC 9(10).

LINKAGE SECTION.
01 NUM PIC 9(10).
01 DEN PIC 9(10).

PROCEDURE DIVISION USING NUM, DEN.
IF NUM < DEN THEN
MOVE DEN TO TMP
MOVE NUM TO DEN
MOVE TMP TO DEN
END-IF

PERFORM UNTIL DEN = 0
MOVE NUM TO TMP
MOVE DEN TO NUM
DIVIDE TMP BY DEN GIVING TMP REMAINDER DEN
END-PERFORM

EXIT PROGRAM GIVING NUM.
END PROGRAM GCD.


ignore the last call from the first file

Thats how you learn, by googling shit all the time, eventually you will come to a problem that you had ran in before and hopefully remember the solution without google.

I can't even begin to understand cobol. You're a trooper.

Would you like me to call lifeline for you.
You are so young user. Think about your family.

Everything is declared, first data then the procedures.

I'm okay, I'm writing COBOL at 23yo, I'm fully aware of the consequences.

C++ can't get modules fast enough.

final applies to the reference not the object you mong

where are these snibbets from

as a non-comp-sci student I did more programming for the semester long group subject than every other member of my group

one of them was tasked with extracting some data from a bunch of saved websites (uniform formatting) for analysis, and I found out on the last day that what he did was get the data from each page, and save each one to its own file in the same folder as the page
I had to write another quick script to extract data from his extracted data
he didnt even keep everything named in a consistent format, It almost would have been quicker to do the whole thing from scratch

>comparing strings
kek. Rate my solution

public string GetSubtitleText(WitnessState state)
{
const string reaction = "Teacher {0} Reaction";
const int maxWitnessStates = 6; // Can be retrieved dynamically, done here as const for convenience

for (int i = 0; i < maxWitnessStates; i++)
{
WitnessState check = (WitnessState) (1

You're using the [Flags] Attribute so I'd probably also use the
state.HasFlag( (WitnessState)(1

Oh and I almost forgot I'd likely also just use
Enum.GetName( typeof(WitnessState), state ) in the first place rather than the entire function.
Depends on the context though. For something that's updating this subtitle every frame you want to shy away from reflection and abstractions, but using it in general procedure code aids development and cuts down on bugs. Which is probably a lot of shitdevs problems. He always seems to use a thousand for loops when he shouldn't, and then complicated wasteful abstractions in tight loops.

The whole point of the function is to select only the most important reason, as there are multiple at the same time. using GetName will yield a list of values (if it's a [Flag]), when you only want the lowest one. Also I like to stay away from reflection if it's going to run on the render thread

>GetName will yield a list of values
I meant a list inside a string, like "Insanity, Weapon", not a literal List

I don't know if that's the purpose of the original function, considering he wrote it to understand multiple reasons.
For the purposes of finding the most "important" reason then your function is fantastic then.
Sticking away from reflection in general is usually a good idea. It's one of those tools to be used responsibly.