/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/hmrten/wf
twitter.com/SFWRedditImages

Don't post threads before the bump limit, you fucking faggot.
Not even a single post.

That's how stupid image wars start.

How should I serialize basic structures in C? Like an array of pairs of int, for example. This will be running on multiple machines so it has to be portable, which is what I'm worried about.
Thanks.

>Like an array of pairs of int, for example
An array of length 2 arrays should work. Or is that not what you're looking for

>serialize

convert to text, problem solved

Just use JSON or some other serialisation format.
There are shitloads of libraries for this.

let's not be retarded here
let's not be extra retarded here

sir, are you pre-optimizing?
you shouldn't do that

but it's in C
it must be efficient

How is using serialisation format retarded?
You don't have any integer size, padding, or endianess issues that just dumping to a file has, it's human readable (if that's important to you), and every language is capable of accepting it.

that sounds like a personal problem

post your github

I'll never post code publicly

Fixed width types, ntoh(s|l) and hton(s|l) functions, and possibly __attribute__((packed)) are likely what you want.

With fixed width types (int32_t, uint8_t, etc...), you guarantee that no matter how alien the architecture or OS, you're all speaking the same language. A long is 32 bits on 32-bit Linux and 32-bit and 64-bit Windows, but 64 bits on 64-bit Linux, so don't use long, use int32_t when you mean to say you want it to be exactly 32 bits. Don't pass pointers around for any reason, though offsets are acceptable.

Network byte order is big endian. Doesn't matter that most machines are little endian these days, SPARC beat us to the punch and that's the way things will be until the end of time. Deal with it. The ntohs, ntohl, htons, and htonl functions convert to and from network (big endian) and host (big or little endian, doesn't matter) byte orders. The s and l parts of the names are short and long, but they mean exactly 16 bits and 32 bits respectively, unsigned.

If you need structs to maintain a specific alignment, __attribute__((packed)) is the compiler extension to do that. It's not technically standard C, but GCC and Clang support it, and no other compiler matters. Keep in mind that unaligned access is slow, so if you don't need to do so, it is best to just use a normal struct.

not good for portfolio?

right now I have a square grid of points

how do I arrange them in a buffer to get this effect?

right now I have a bug where the plane it is generating is acually like a thin strip normal to the plane I want

hi guys not coding today but rather planning build. i have 500 or so to build with. my last rig went down, only the mobo, but its been so long that i will need to buy a decent replacement to salvage the 1155 card and ddr3 ram. that or buy it all new ( mobo, cpu, ram ) and hope thats all i need. if i could do both machines, i would keep my old machine offline as storage or a nightly server for fun.

anyone here got some suggestions with a retailer or vendor to help me get both and stay under budget. i want to play mobas, ps2 emulator, ps1, possibly overwatch. i could do all of the prior with a mobo replacement, but what if it all goes out sooner than later given the sd that took out my mobo?

i can help with coding too if that helps.

>tfw shit the bed on my programming exam today

This has nothing to do with programming.
Post in /sqt/ or some PC builds threads if there is one going on.

don't care
I haven't had any trouble finding work without a portfolio

Finished modifying the theme for my jekyll blog, bls subscribe.
I'm learning SQL Server right now.
A-Are you going to employ me?

so how did you apply for your first programming job?

>ntoh(s|l) and hton(s|l)
It bothers me that there is no uint64_t version.
We're stuck with non (POSIX) standard functions if we want that.

Anybody doing advent of code?

advent of code is shit

I didn't, I did freelance programming
but if I had, I still wouldn't have included a public repo or way in my resume

...

I post only out of here. I didn't think anyone but the mods would pretend to care. anyway the ending part was about progamming.

you draw triangles from the pairs of vertices that are created by every two heights?

so one segment will have two heights in each direction and can make two triangles.

Is this the correct place to ask questions about UV mapping and diffuse maps in 3ds Max?

Hey it's the guy who got his laptop stolen. I was posting in the thread earlier.

numlist = []

for i in stringg:
numlist.append(i)

for i in numlist:
if i == '\n':
numlist.remove(i)
if i == ' ':
numlist.remove(i)

newlist = []
this = str()
count = 0
for i in numlist:
this += i
count += 1
if count == 2:
newlist.append(this)
count = 0
this = str()

x, y = 0, 20
array = []
while y < 420:
array.append(newlist[x:y])
x += 20
y += 20

a, b = 0, 0
while a < 20:
print(array[a][b])
a += 1


I found a computer at a university financial aide office to do euler problems. I'm kinda going insane though without my laptop and being homeelss ;-;

language?

make sure to get as much help as you can from your uni

I'll take that as a no.

top kek. i'm homeless neet user.

on my laptop i was building a bit torrent client but it got stolen at a homeless shelter. now i'm using online compiler to do euler.

no, the correct thread is agdg on /vg/

No offence, but if you're homeless shouldn't you be, uh, looking for a job? Maybe now's not the time to do Project Euler stuff.

>post vague question on a programming thread
>asked about language
>no

fuck off retard

I don't get why people get this whole idea of "home boards" or even "home threads". I'm not a massive proponent of tight moderation or "posting police", but just put your shit in the right place. This thread is about programming, not a chatroom for people who just happen to be programmers.
>anyway the ending part was about progamming
No it isn't. You just mentioned that you can help with "coding" which is completely tangential to your post, and is not a justification you posting in here.

Post in the right thread. You'll even get better answers that way.

grazie famiglia

well the thing is i did i applied to five jobs while i was on my library computer time.

you really are at the mercy of the employer.

Ah, well that sucks, best of luck I hope you find something soon.

How the fuck do I run a R script with input variable as an argument in Shiny AAAAAAAAAAAAAAAA

you could do this with a linked list over the original grid.

so if you always have a height, 0, you can create a boundary, perimeter, and build according to your segment length or make it all a little more general and include the possibility that more lengths will exist and create a composite system between the two sides that the segments are connecting to as if to create a "beaten path" between the two sides. when you have enough segments hold enough space in tact you can create shapes over them and manage the shapes as composite or whole. so it can happen to be that you create a sort of fractal out of nature. or a consistency. maybe a tendency.

the original shapes slowly "cast" over the larger shapes created by your segments and the rules that make em possible.

Started working on the peephole optimizer now.

This is an example for compiling a +
// + compiler macro
: +
lc-lit? if ` pop-lit ` #+ -d,x ;; then
` s+ ` +sp ;

Checks if the last word compiled was a literal, if so undo the code for a literal (and extract the literal value) then compile an add, imm32 instruction.

// code for regular plus:
+:
041623A: 48 03 03 add rax,qword ptr ds:[rbx]
041623D: 48 8D 5B 08 lea rbx,qword ptr ds:[rbx+8]
0416241: C3 ret

// code when compiling 1 + (or any literal + )
inc:
0416242: 48 05 01 00 00 00 add rax,1
0416248: C3 ret


That's gonna be the basic idea for other optimizations.
I will add more lc-XXX (last-compile?) words for testing if the previous word(s) was a dup, drop, etc and then the next word being compiled can look back and undo unnecessary stack effects, or do things like strength reduction.

i wish i was smarter like you

im not going to ask somewhere else so fuck off

I donĀ“t know where to post this, so I figured the programming thread should be my best option

>have to make an appointement for a subject which consists in making a bunch of drawings with a common theme and make a "portable museum"
>I thought it could be neat , and easy, to make a page with all my drawings in it and have a personalized qr code that leads to the page printed in a t-shirt so I have a "portable museum" without carry all my shit

Should I use 3rd party shit or can a almost 0 programming skills dude do a page to hold images by himself

should i clear some part up or were you being serious

What are you compiling?

being serious rn

I'm writing a x64 Forth compiler for Windows.

github.com/hmrten/wf

fucking madman

Jesus christ.
I don't know if I should be disgusted or impressed.

god damn it

float[] cube = {
-0.5f, 0.5f, 0.5f, // vertex[0]
0.5f, 0.5f, 0.5f, // vertex[1]
0.5f, -0.5f, 0.5f, // vertex[2]
-0.5f, -0.5f, 0.5f, // vertex[3]
-0.5f, 0.5f, -0.5f, // vertex[4]
0.5f, 0.5f, -0.5f, // vertex[5]
0.5f, -0.5f, -0.5f, // vertex[6]
-0.5f, -0.5f, -0.5f, // vertex[7]
};

What does this mean?

>all this work
>no stars
>no followers

life is suffering

Any good resources to learn http, web, networking etc?
I'm reading some perl web client book from 1997 so there's probably better resources out there.

Are you daft?
It's obviously the coordinates for a cube.

>networking
You're going to need to be more specific than that.
Networking is a quite a large field, although I suppose you mean TCP, IP and all that.

I don't know of any online resources, but they probably exist.
I learnt most of the shit I know about networking in university.

this is trivial stuff you just pick up whenever you need to do a project that uses it

And how does it fit here?
I'm having trouble trying to visualize how it fits together.

byte[] triangles = {
1, 0, 2, // front
3, 2, 0,
6, 4, 5, // back
4, 6, 7,
4, 7, 0, // left
7, 3, 0,
1, 2, 5, //right
2, 6, 5,
0, 1, 5, // top
0, 5, 4,
2, 3, 6, // bottom
3, 7, 6,
};

Neat.

do you expect us to tell you how a couple of arrays "fit together"?

Why would you write the compiler itself in assembly? Unless it's self-hosting and that's the compiled compiler..?

Don't really care about the whole 'github community' aspect, I don't intend to follow or star anyone else and I don't care if anyone follows/stars me, I just use it as a public cloud backup.

He should had renamed his project to: Name.js

I just want at least broad knowledge of common stuff so I don't sound like an idiot when someone talks about http requests, traffic routing, and ports.
I'd rather know it so I know when it's applicable.
How do people remember all the details of different protocols?

Anything I can improve on with this?

#include
#include

int numbers[] = { 34,64,45,12,
76,23,98,23,
12,43,76,12,
67,84,98,87,
39,12,87,21,
57,87,34,71 };

void find_a_number(const int set_number){

int arraysize = sizeof(numbers)/sizeof(int); // Calculate Array size
int accumulator=0;
size_t f=0;

for(f=0; f

I just made some OC for the thread images. Hope your happy.

>this image
>saved as PNG
>1.87 MB

apply yourself

My happy.

Case 0 and Default are identical.

>How do people remember all the details of different protocols?
there's not much to it
tcp if you want all packets in the right order
udp if you don't care about order and if you don't care that some packets can be dropped
http requests are even simpler, you can figure out everything you need to know in 5 minutes just by looking at a couple of them in your browser

>And how does it fit here?
Each 3 numbers describes a point in 3D space: a vertex.
The triangle array lists how each of the vertexes come together to draw a triangle. In 3D rendering, everything is drawn as a triangle, as they can be used to approximate any 3D shape.
Each line specifies a triangle, and each two triangles are drawing a face.

Yes. For one, your for loop goes out of the bounds of the array. Second, there's no need to create a temporary value. Third, f is an odd variable name for an index. Why not i? Fourth, arraysize and accumulator should be of type size_t. Fourth, you can improve the performance of your find_a_number by using a sentinel value. Finally, your brace usage in you case statements is retarded.

thanks, I wasn't sure if braces where needed for multiline statements in a case in C/C++ or pretty much any language since all of them have switch statements

That entire switch statement can be shortened to
printf("Found %d, %d time%s\n", set_number, accumulator, accumulator == 1 ? "" : "s");

>you can improve the performance of your find_a_number by using a sentinel value
how's that work

Compiler is being written in Forth.
Some of the asm is already unnecessary and could be rewritten, just haven't got to it yet, and I'm kind of figuring out what I need to expose as I go along.
One somewhat major thing missing is addressing system variables (code_here, data_here, etc), I'm working out how the code gen for them should be (probably gonna dedicate a register for them), I have the hardcoded HERE and XHERE words exposed to Forth (which drops data/code space pointers on the Forth stack), but that's just temporary.

Thanks. I can see how it works now.

In C, function variables are automatically zero, right?

would this call to memset be redundant?
struct triangle *triangle_new()
{
struct triangle *tri = malloc(sizeof(*tri));
memset(tri, 0, sizeof(*tri));
return tri;
}

My problem really stems from the way gl_triangles_strip works

right now I'm iterating through so that it skips at the edges and I get an extra line

also it has another problem (this is what I was originally on about):

...

printf("Found: %d. Occurrences: %d\n", set_number, accumulator);

shit nvm

tri is allocated from the heap, so it could contain garbage

but what about when accumulator equals 0? The last word needs to be plural in that situation

this is what it looks like with every other row with an added height

it should form V's like a height map, but they aren't connected

no, you need the memset

turn your adblock on

Since there is 11k+ solutions to day 1 my guess is that yes - someone is doing AoC.

But what if i want to know about all the celebrities who died without anyone even knowing?

I'm working on a mobile game, a 2D rogue-like. (The rest of what the game will be hasn't been decided yet).

I'm struggling with map generation.

>pic related
All the red sprites are highlighted because they are overlapping another sprite, this is something i'm trying to fix. Every tile should be on its own unique spot.

The problem is my algorithm for placing areas of tiles(sprites) isn't correctly spacing each area resulting in the overlaps.

Another question, what is the syntax for posting code? I'm assuming

(code here) ?

(guess I'll see if that works.)

TL;DR overlapping sprites in game because map generation algo is fucked, help >pic

In this case you could use calloc() which returns zero'd memory.

that explains

I got stuck on day 11, I don't know how to tackle that problem.
And it doesn't allow you to proceed further until you make all previous days, right?

>mfw

// place areas
for i = 1 to areas.length

tmpX = 0
tmpY = 0

if( areas[i].pos.x > 0 )

// find position pixels if area is right
tmpX = areaBounds - areas[0].sizeXPDiff
for i2 = areas.length to 1 step -1

if( areas[i].pos.x > areas[i2].pos.x and areas[i2].pos.x > 0 and areas[i].pos.y = areas[i2].pos.y )

tmpX = ( tmpX + areaBounds ) - ( areas[i].sizeXPDiff + areas[i2].sizeXPDiff )

endif

next i2

elseif( areas[i].pos.x < 0 )

// find position pixels if area is left
tmpX = -areaBounds + areas[i].sizeXPDiff
for i2 = areas.length to 1 step -1

if( areas[i].pos.x < areas[i2].pos.x and areas[i2].pos.x < 0 and areas[i].pos.y = areas[i2].pos.y )

tmpX = ( tmpX - areaBounds ) + ( areas[i].sizeXPDiff + areas[i2].sizeXPDiff )

endif

next i2

endif

if( areas[i].pos.y < 0)

// find position pixels if area is down
tmpY = areaBounds - areas[0].sizeYPDiff
for i2 = areas.length to 1 step -1

if( areas[i].pos.y < areas[i2].pos.y and areas[i2].pos.y < 0 and areas[i].pos.x = areas[i2].pos.x )

tmpY = ( tmpY + areaBounds ) - ( areas[i].sizeYPDiff + areas[i2].sizeYPDiff )

endif

next i2

elseif( areas[i].pos.y > 0 )

// find position pixels if areas is up
tmpY = -areaBounds + areas[i].sizeYPDiff
for i2 = areas.length to 1 step -1

if( areas[i].pos.y > areas[i2].pos.y and areas[i2].pos.y > 0 and areas[i].pos.x = areas[i2].pos.x )

tmpY = ( tmpY - areaBounds ) + ( areas[i].sizeYPDiff + areas[i2].sizeYPDiff )

endif

next i2

endif

areas[i].pos.pX = tmpX
areas[i].pos.pY = tmpY

next i


this is the problem area. My math must be wrong.

see:

I'm in the process of making a game