/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?
Previous thread:

Other urls found in this thread:

en.wikipedia.org/wiki/External_sorting
fbi.gov/submit-anonymous-tip
twitter.com/AnonBabble

first for sagiri a SHIT
elf best girl

Thank you for posting a cute anime girl.

>What are you working on, Sup Forums?
I have to do online programming test for as part of a screening process for a job I applied for.

what kind of job, lad?

learning nim

Looking at GTK+ for C and what it offers.

is nim the only language that offers arbitrary modification of the AST with metaprogramming right now?

dumb sagiriposters

The job application was actually really vague, but it's supposed to be at some R&D centre.

>GTK+
GTK
FTFY

GTK is shit. Unfortunately, basically every GUI library is shit.

No, actually D has been doing it since forever

who here legit doesn't use google at all for their programming activities

Is there a search engine thats completely independent from Google?

using anything other than longs or doubles at the start of your project is premature optimisation

I have a compilation to android problem.

any android wizard here who can help me?

No, D doesn't allow arbitrary AST modification. Show me an example where you replace if statements with an opposite condition, only if a variable named ``retard'' is declared in the else block, and only if the variable retard is not assigned to 7.

>What are you working on, Sup Forums?
I'm making a JS static analyzer.

I want it to be able to statically learn about control flow and data flow, kinda like IDA Pro does, but for Javascript.

I waste so much time on stupid mistakes that a proper compiler would catch in a real language, so I'm hoping to use the analyzer to replace a compiler.

Hopefully if I cache things properly it won't be too slow.

Lisp has been doing that for over 50 years.

why would you need a search engine for programming?

>kinda like IDA Pro does, but for Javascript.

my ``african american friend''. have a github i can follow so I can see when you have something ready? Have you considered adding dynamic analysis to provide comments in the static analysis, kind like funcap for ida?

Completely forgot about lisp for some reason. I absolutely love the homoiconicity concept, but unfortunately for my usual applications lisps lack the stuff I need (mostly just available libraries, performance and ``static typing'')

I whipped up a scaffolding script in an hour. It converts a js module into a file structure, replaces templated strings with stuff determined at runtime and offers event hooks before each file is created, before the file is filled, and after all that is done that can be used to run either js functions or shell scripts.

Unfortunately, the code still has to come from somewhere, so at this point I might have just made the file structure in the first place and let people change it by hand

best java ide?

Show me the nim example.
your wording is a little vague

>my ``african american friend''. have a github i can follow so I can see when you have something ready?
It's a bit early for that, I've been coding half-drunk non stop since yesterday, and I still haven't done a git init ..!

>Have you considered adding dynamic analysis to provide comments in the static analysis, kind like funcap for ida?
I'm not sure if I'll go that far, since I'm not really trying to do reverse engineering.

My goal is to have as much information as a compiler would have in a strongly typed language.
I have a small interpreter that statically tries to determine the value of objects, resolves imports/exports, and propagates Flow type annotations.

Size of an integer or floating type used is not really an optimization. It's typically a matter of correctness. Furthermore, the long data type should be almost never used, due to its inconsistency across platforms. One might think that it acts as a 32-bit type on 32-bit platforms and a 64-bit type on 64-bit platforms. But this does not happen at all on Windows, which makes up the lion's share of desktops. So it's a 32-bit integer on everything that's not a 64-bit Unix? If you need a 32-bit integer, use int or int32_t. If you need a 64-bit integer, use long long or int64_t. If you need an integer that is the size of a pointer, you probably want ptrdiff_t, or its unsigned variety, size_t.

stupid wojakposter

Looking up documentation.

>I still haven't done a git init
I always, *always* regret that. commit that shit NOW

I don't know nim. I just know its features. It's in my 'to learn' stack.

if whatever:
stuff
else:
retard = 5

becomes
if !whatever:
stuff
else:
retard = 5


if whatever:
stuff
else:
retard = 7

stays the same

if whatever:
stuff
else:
not_a_retard = 5

stays the same

I'm so fucking happy for anime picture.
Thanks for using anime picture!

good taste!

I dont know D well enough for that, but i see no reason why the fuck id want to do that anyway.

You'd want to do that because it's a very simple example that shows that D can do arbitrary AST modification, like you claimed in Seems you didn't get what I was talking about.

R-Rub..
..
S-Sensei... I am stuck on a problem. I have a f-file .. which contains 10 million unique 7 digit p-positive .... integer on each line. I-I need to sort this file using under 2 megabytes ...
...
PLEASE HELP ME SENSEI !!

I was not that user.

en.wikipedia.org/wiki/External_sorting

Whoops, sorry. Have a pup.

I-It needs to be in r-ram otherwise ....
....
i-it is too slow.

>under 2 MB

If only there was a system call that could read and write exactly this much data from a file...

With memory requirements that strict, you have no fucking choice.

You obviously can't fit 70 million digits in 2 megabytes of ram.

are you enjoying roleplaying as an autistic anime girl?

halp, how do i program my little sister to sit on lap ?
i was trying to find SPI interface but i can't find it anywhere, or maybe i'm searching in a wrong place?

B-B ... BAKA! IT IS POSSIBLE I KNOW IT IS .... s-sor .. ry ....

What about memory mapped I/O? I have a hunch it can lead to a much better solution than temporary files.

The downside is proper error handling involves signals, which is pure shit.

you need to use the rest api:

wget fbi.gov/submit-anonymous-tip

This right here.

You need a bare minimum of 24 bits (3 bytes) of data to store an arbitrary 7 digit number. To store all of your numbers, compressed, you would need 30 million bytes, or about 28.61 MiB. You clearly cannot store all of your numbers in memory at once, and therefore must use the filesystem.

Just started CS and loving it so far. I've always wanted to make a simple and ugly 3D game just for the hell of it and decided that I wanted to use LWJGL. Currently, the best stuff to be using seems to be LWJGL3, but most tutorials seem to revolve around older versions. Will these old tutorials still apply, or has the syntax changed enough where I will need to hunt down something specific to LWJGL3? If anyone has any other suggestions for 3D game graphics libraries for java besides LWJGL, I'd love to hear! Sorry for being the kid trying to make a game in this thread.

S-Sensei, I know that I can use less than 2MB!! ....
I-I will try and s-show you h-how I can sort...
...
`m-maybe sensei will n-notice me if I can solve the problem...`

Ahh ruby they're unique numbers, and there's 10 million of them which means every number from 0 to 9,999,999 is present just once.

How do you figure out how many decimal digits an N-bit number has?

How sorted is the data to begin with? Could you represent the number as very small deltas?

What range does it have? Can you normalize the data to save a bit of space?

How many duplicates are there? If there are many duplicates, you could first count the number of each unique number, then sort the unique array, then output for every number in the unique array however many occurrences you found in the first step.

So the solution is
for(int i = 0; i < 10000000; i++)
fprintf(file, "%i\n", i);

how about you use my dick slut
lets see you put on that angry face with my cock in pussy
filthy anime cumslut

log10(2^N)

i mean, i able to start console session. however REST is out of question, because "ifconfig" doesn't show any interfaces besides loopback

2 ^ 23 = 8,388,608
2 ^ 24 = 16,777,216

23 bits won't hold 10 million values.
24 bits will hold 10 million values.

>unique
Missed that part. In which case, you don't sort at all.

ceil(log10(1L

>im a dumb hs dropout
but are you a millionaire yet?

Yeah. Solution is But that method you showed to measure needed bits triggers me.

Just do cieling(log2(max_number)), or if your calculator is shit, cieling(ln(max_number)/ln 2)

no, but i'm depressed, afraid of social contact and full of pills.

and i put 20k$ i made from btc mining years ago in an etf, so maybe i can make a couple of bucks in the coming decades.

I'm working on a program that will generate, render, and display scientific statistics of futuristic starships for an TTRPG I'm a part of. It assembles components together in 3d space and uses a machine learning algorithm to determine which components and arrangements are optimal for one of several intended prepared (transport, combat, scouting, etc.)

kek

yeah and it sucks, its called yahoo

Help me Sup Forums. I need to use GLFW, as I want to learn how to use it. However I don't know an easier way to use 3rd party libraries. I'm using codelite ide, anyone wanna help with that?

>I need to use GLFW
why?

Or any third party library. That's the problem. I don't know how to properly utilize third party libraries.

I've spent the last hour trying to figure out what I'm doing wrong. I've copied the files properly, I've tried linking the files and the folder, yet its shitting out the same errors.

Please do not question the motive for why I need to use it, everyone who wants to learn C++ will eventually need to use thirdparty libraries. So I want to get into the business of using third party libraries.

why not openGL (simple) or SDL (harder) , Qt, SFML

what exactly are you trying to do?

Did you set compiller flags? ie
gcc main.c -lglfw -lGL -o bin

Not him but I prefer glfw over sfml.

>But that method you showed to measure needed bits triggers me.
Well it's really a bit of mental math anyways. I know 2^10 is roughly a thousand, 2^20 is roughly a million, 2^30 is roughly a billion, etc... Going from there, I know 3 more bits multiplies by 8, and 4 bits multiplies by 16. Since 10 is between 8 and 16, I round up and go with 4 bits. I could likely come up with the same method that you have, if I'm trying to do this for a bunch of numbers, but since I already knew the scale of numbers I'm dealing with off the top of my head, this was faster. My thought process goes, "it's on the scale of millions, so it's a little more than 20."

I'm learning bash for simple and personal automation. How do you go about organizing shell scripts? I have a file containing global variable declarations, another file to search the desktop for existing processes and their names/IDs, and a couple more that sources these two files to do some work.

SDL user. Fuck GLFW
sudo apt-get install libsdl2-dev libglew-dev


Include headers in this exact order:
#include
#include
#include
#include


And compile with
-lSDL2 -lGL -lGLEW

what went wrong?

are russian programmer the best»?

>Fuck GLFW
Why? GLFW is fine.
It gets you a window with an opengl context. None of this SDL drawing crap that you might not need.

>russian

That's what SDL does too. You don't have to do the 2d drawing crap if you don't want to since OpenGL does that better. SDL is MIT, not LGPL too so just statically link if you don't want your users to have all the drawing crap on their computer.

I've added this, I'm doing something wrong with the linking. Its not finding the

I have the include files in proper include folder, libglfw3.a in the library list.

I'm on windows too, either way, it main issue isn't GLFW, its how to setup third party libraries properly.

>You don't have to do the 2d drawing crap if you don't want to
So it's just useless library bloat.
>SDL is MIT, not LGPL
Oh, so you're a stupid BSD/micro cuck. Also, you should fucking learn the difference between the GPL and the LGPL.
>just statically link if you don't want your users to have all the drawing crap on their computer
What? That doesn't make any sense.

>I'm on windows too
I'm so sorry.

no seriously, what the fuck went wrong?

nothing. the program executed as written

so why the qwerty.png is still there?

-WhatIf

I know the difference idiot. You have to dynamically link against LGPL software if you're releasing proprietary software, whereas you simply cannot use GPL software.

And the 2d drawing crap isn't useless if you are interested in doing 2d drawing.

Honestly the only reason you'd care about there being some god forbid 2d drawing operations on there is if you were worried about the massive storage space of a handful of functions. So just statically link if you don't wanna distribute a couple extra functions. It's not hard.

oh ffs...this is so much like me. looking for some errors in the loops, syntax etc and missing the most obvious reason for it to not work as planned

anyway thanks for removing that massive brainfart bubble outta my head

Got it to work.

I was putting the include folder in the Linker options instead of in the Compiler options. Also had to make the library names into actual names instead of the full filepath names.

Glad I got this headache over with.

S-Sensei, I did it ... I-I did it! ...
p-please... notice .. me ... sensei ...
C-Can you t-teach me to be a better p-programmer ... n-n .. n-now?
#include
#include
#include

enum {
NINT = 10000000
};

void add_bit(unsigned char a[], int n)
{
int aindex = n / CHAR_BIT;
char bitnum = n % CHAR_BIT;
char bitindex = 1;
while (bitnum--)
bitindex *= 2;
a[aindex] |= bitindex;
}

int get_bit(unsigned char a[], int n)
{
int aindex = n / CHAR_BIT;
char bitnum = n % CHAR_BIT;
char bitindex = 1;
while (bitnum--)
bitindex *= 2;
return a[aindex] & bitindex;
}

int main(int argc, char *argv[])
{
unsigned char *a = calloc(NINT / CHAR_BIT + 1, sizeof(char));
FILE *inf = fopen("genints.n", "r");
FILE *outf;
int fint, i;

printf("Fetching ints\n");
while (fscanf(inf, "%d", &fint) != EOF){
printf("%d\n", fint);
add_bit(a, fint);
}
fclose(inf);

printf("Storing ints\n");
outf = fopen("sorted.n", "w");
for (i = 0; i < NINT; i++)
if (get_bit(a, i)) {
printf("%d\n", i);
fprintf(outf, "%d\n", i);
}
fclose(outf);

free(a);
return 0;
}

I-I even got it to use almost 1MB ....
.. ``baka, sensei will only notice me if I can be better`` ... s-sensei .....

So you're using a bitvector... not bad, but take a look to And again, I was already willing to teach you, but the problem was that you wouldn't tell me what you know thus far, and what all you want to be learning.

holy shit kill yourself

S-Sensei ... I don't u-undestand his code ...
P-Please explain i-it t-to me sensei ...

Woke up, middle of the night, covered in sweat and shivering. I'm making a program that makes my screen go batshit insane until I take my pills because apparently an alarm on both my phone and my pc is not autistic enough.

It wants your sempai D ruby. Time to culturally enrich him

You have a file with 10 million unique non-negative integers, all less than 10 million. It stands to reason that it contains the numbers 0 through 9,999,999. Therefore, you need not read from the file at all; just output the numbers in order.

If that's what he wants, I'm more responsive to the direct approach.

Why are you using those whiles instead of a single bitshift, considering you already bit fiddling?

N-No I-I don't ...
BAKA!
I-I only like R-Rubb...
。(⊙﹏⊙)。゚
S-Sensei is m-my teacher.
BAKA! I-I can tell you never had a teacher before because you a-are a BAKA!

I-I am j-just a beginner. S-sorry.. .. I-I will d-do better next time ....

Yeah nice but who's the gril in the pic?