/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: hidamari_dpt_waifu2x_traps.png (1618x1308, 1.95M)

i implemented malloc using a pairing heap
right now it only allocates from a single mmap'd page but it allocates, deallocates and coalesces chunks fine
am I wasting my time or is this a good exercise for a novice

let us reflect upon the principles we learned from our last thread:
always prefer high level code over goto statements
traverse a shit
clojure > scala
javascript > python

What programming language should I learn?

Here are my Jow Forums credentials:
I successfully installed Arch twice, then gave up and stuck with graphic install Debian.
I onced successfully cracked a WEP wifi password, then completely forgot how to replicate my results.
I can generally ferret out an image from the source of a website that won't allow right-click-save-as.

Which is pitiful, but maybe one step above boomer-level knowledge.
I would prefer a language that is exhaustively documented and that leaves no room for intuition and assumes no standard set of programming knowhow.

just go kill you'reself

programming languages are tools, so tell us what you want to build or else learn some shell language like bash if you just want to do stuff on your computer

i mean did you learn anything

and Go > *

Attached: file.png (1280x720, 1.67M)

Attached: confused_pepe.png (420x420, 12K)

>trying to bait javascript haters
>not realizing that because everyone is a javascript hater, even people who use it, nobody takes these low tier baits seriously
amateur

It looks like you are genuinely acoustic. Learn C.

I want to build programmes. What programming language should I learn?

I know I used the word boomer in my post, but confusingly, I'm in my early twenties, so you don't need to be so defensive. I also made self-deprecating remarks, but confusingly, these were actually self-deprecating and indicated humility, not incompetence. Forget prgramming languages, human language is the real doozy!

java

I'm working on a rabbit breeding mini-game as part of a larger mini-game app package.

Attached: rabbit prototype.png (1080x1920, 188K)

so far I have a calculator, a stock market game, and a turn based combat game with level progression.

Attached: app images.png (3284x1940, 406K)

How the fuck do you even create a file in the current directory in a portable way in Java? All of the SO pajeets' answers start with "C://" garbage

copy path, open a file explorer, paste it and create the file from the folder.

connection error

dumb frogposter

call it nupets

Its called HareSplitting

Relative path

>gave up and stuck with graphic install Debian
>forgot how to replicate my results
>one step above boomer-level knowledge

Don't touch programming languages other than Python.

Do not make it portable but use GNU/Linux path instead of Windows.

>What are you working on, Jow Forums?
My retardation.

Windows would accept it as relative path KEK

implementing malloc is never time wasted

fell asleep earlier today, while I was sleeping I created a strongly typed functional programming language which compiles to wasm and got 500 upvotes on hacker news

import java.util.Scanner;
import java.math.BigInteger;

public class arashpiii
{
public static void main(String[] args)
{
var stdin = new Scanner(System.in);
int n;
inputEvaluationLoop:
while (true) {
try {
n = stdin.nextInt();
if (n < 1)
throw new Exception("Unacceptable integer.");
} catch (Exception e) {
System.err.printf("Invalid input: %s\n", e);
stdin.next();
continue;
}
break inputEvaluationLoop;
}
BigInteger result = BigInteger.valueOf(n);
for (int i = 2; i < n; result = result.multiply(BigInteger.valueOf(i++))) {
}
System.out.println(result);
}
}

Attached: 1532819403746.png (1890x1630, 725K)

#include
#include
#include
#include
#include
#include
#include

//We need the filesize in order to read and write out of the array correctly
size_t getSize(const char* filename) {
struct stat st;
stat(filename, &st);
return st.st_size;
}
//the in-place reversal, not allowed to use a second array.
//so we switch each front and back byte of the file around till we reach the middle
void reverseArray(char* mmappedData, int start, int end) {
int tmp;
while(start < end) {
tmp = mmappedData[start];
mmappedData[start] = mmappedData[end];
mmappedData[end] = tmp;
start++;
end--;
}
}
//MAIN PROCESS
int main(int argc, char** argv) {
size_t filesize = getSize(argv[1]);
//Open file
int fd = open(argv[1], O_RDWR);
//debugging with assert for any problems
assert(fd != -1);
//Execute mmap to a char array (basically a string)
char* mmappedData = mmap(NULL, filesize, PROT_WRITE, MAP_PRIVATE | MAP_POPULATE, fd, 0);
//If it cannot read it, tell us
assert(mmappedData != MAP_FAILED);
//attempt to reverse in-place
reverseArray(mmappedData, 0, filesize);
//print out the reversed string in stdout
write(0, mmappedData+1, filesize);
//write that changed mmapedData to a new output file
FILE *f = fopen("output.txt", "wb+");
fwrite(mmappedData, 1, filesize, f);
fclose(f);
//Cleanup memory mapped space
int rc = munmap(mmappedData, filesize);
//make sure there is nothing allocated after deallocation
assert(rc == 0);
//close the used file
close(fd);
return 0;
}

It should take the file in, and return the file in reverse. However, when it prints the result to the file, it is garbage corruption. Anyone know what is the solution to this?
Can I just intercept the write() to write that into a file?

>java
>var
Yooo, what?

It's a Java 10 thing

got caught writing a lisp at work today

Then you woke up?

Give me a good reason why I shouldn't use this.
>pic related

Attached: rust-logo.png (512x512, 84K)

It has yet to get a C++11 kind of update

slow compile times
low usage hence less support than C++
lack of tried and tested libraries

import java.util.Scanner;
import java.math.BigInteger;

public class arashpiii {
public static void main(String[] args) {
var stdin = new Scanner(System.in);
int n;
while (stdin.hasNextInt()) {
n = stdin.nextInt();
if (n > 1) {
break;
} else {
System.err.printf("Invalid input: Unacceptable integer.");
stdin.next();
}
}
BigInteger result = BigInteger.valueOf(n);

for (int i = 2; i < n; i) {
result.multiply(BigInteger.valueOf(i));
}
System.out.println(result);
}
}

It's ok if you are just learning, but damn that is some shit code.
If this is just some exercise to learn exceptions or whatever fine, but please never use exceptions like this for flow control in real code. And try and avoid break/continue as much as possible - following the flow control of your while loop is real hard because of them.
Also it's pretty awful style to do calculations like that in the header of a for loop, makes it really hard to follow. i++/++i are a minefield where it's easy to introduce subtle bugs due to the order of evaluation/addition.

what books should I read to have the same level
as a formally trained software eng./compsci grad ?

You aren't catching InputMismatchException, senpai!

Can't be thrown due to stdin.hasNextInt() in the header of the while loop.

>for (int i = 2; i < n; i) {
should have been
>for (int i = 2; i < n; i++) {

But is that really handling the error? It's basically going to do weird shit if user inputs a string or char or something.

What does that mean?

a massive update

C++ has received a large scope update that basically polished and improved the language by a big factor as a whole, it was the C++11 standard. I assume he means that once Rust is a bit more mature it should also receive such an overhaul to bring it into usable state.

Yeah good point, it will.
Best would be
while (true) {
if (stdin.hasNextInt()) {
n = stdin.nextInt();
if (n > 1) {
break;
} else {
System.err.printf("Invalid input: Unacceptable integer.");
stdin.next();
}
}
}

Sepples c++ wizards, what is a better way to do this
std::map my_map{{'A', 'Z'}, {'B', 'X'}, {'D', 'O'}};
for (auto cc: my_map) {
my_map.insert({cc.second, cc.first});
}

It feels wrong because I'm adding new elements to the map as I iterate through, but in practice it works? Is there a better way to achieve this - or another data structure?
I need a map, but one where I can serach by key OR value.

try boost.bimap?

It's too small to justify boost, I was hoping for something in the stdlib, but it's not important.
I've had a really hard time using boost before, I'm hoping that with the switch to CMake it will get easier to utilize.

if you don't care about efficiency (you probably don't if you're using std::map, it's just terrible) then you can just make a thin wrapper over two std::maps

That's completely fine.

Yeah efficiency is a total non-issue.

I end up iterating over twice as many elements as necessary, but it does seem to work with no problems.

What's Jow Forums opinion on PerVersomething's Bitwise stream about making language for fpga and other fun stuff?

Generally what's your favorite fpga related streamers?

Why are native compilers so fucking slow?

>classname is lowercase

Attached: banter stops.png (500x611, 176K)

did you consider that the file might be corrupted already

I have an application that when it crashes, offers a save dialog to save the work.
If i attach a debugger to this application, how can i force it to crash?

>caring about such a trivial thing when the code is written by an autist who unironically uses labeled breaks

Attached: 4aITRJ7.jpg (515x1037, 87K)

it's not trivial >:(

kill yourself and go back where you came from.

no u

Hey guys, gather round. Let's all engage in a mental exercise that I swear will improve our lives.


Alright let's all start by closing our eyes and imagining. Imagine you, but you're not yourself anymore. You are 30 now, you are also overweight and american, you work a boring repetitve job and you use anime, discord and imageboards as a surrogate social life. I want you to imagine the only fleeting joys you get in this life is the dopamine rush you experience when there is a new loli doujin uploaded to sadpanda. That and spending money on frivolous commodoties that don't improve your life (but you don't know this, you are afterall an american).


Now this is the part where we are healing. You picture this man, I want you to put yourself in his shoes. He has lost his self-awareness long ago, he cannot help himself anymore. But you are not like him. I want you to feel disgusted at yourself. Now, I want you to channel this loathing that you are feeling towards your real life, every decision you make, every step you take, remember this man, and remember you do not want to be like him.

I have somewhat simple SQL server 2012 question, but cba to post on StackOverflow. I've googled quite a lot but didn't find any real help.


Example table
ID | TYPE | VALUE
---------------------------------------------
1 | A | foo
1 | B | bar
1 | C | baz
2 | A | foo
2 | B | NULL
2 | C | baz

Example output
ID | TYPE | VALUE
--------------------------------------------
1 | A | foo
1 | B | bar
2 | A | foo
2 | B | baz

I only want to output TYPE A and B values, but I want to replace all TYPE B null values with their corresponding TYPE C value. Plz help.

Writing a system that allows me to rename files to "Tag" them in Ruby. Nothing fancy at all, just having the user input what "tag" the image falls under, and builds a list of tags that the user can use later.

I'm planning on doing a sort of auto-complete feature, but I have one question: How would I make it such that
1) When I press TAB, it doesn't print out the tab character, but it displays some output while keeping whatever input I have already there
2) Do what emacs does when you autocomplete. By this I mean, when you press TAB, it shows you some matches, but if you keep typing, the auto-complete minibuffer goes away

In any case, I'm going to try to implement several add-ons that will make it easier for me to tag my images.

gay blog post

Attached: yamero.jpg (197x200, 6K)

check out GNU readline, I think there's a ruby module for it

he's a pol-baiting canadian/yuopeen
just ignore and report.

>please never use exceptions like this for flow control in real code.
Wouldn't unhandled exceptions be a bad thing

I love asm.

making anything neat or just learning?

Yeah sure you should handle your exceptions.
Even better to write code that can't throw exceptions in the first place.
ABsolutely don't do what that guy did and use custom exceptions as control flow for trivial things that could just as easily be solved with an if statement. If you want ints >= 1, use in an if statement, don't throw new Exception() --> catch --> continue to achieve the same thing. That's retarded.

I'm doing a 16 bit OS.

Oh, ok then! What kind of programs? The best general purpose language at this point is probably javascript (and HTML / CSS for UI), as it is supported everywhere and you can build applications for any platform with it.

have a github/lab?
i love os dev.

You must learn C and Assembler and all girls will be your.

why does the query itself have to do that? just select a,b,c and programmatically map each row so that c is discarded and b is set to c if it was null

>have a github/lab?
No, git is too difficult for me. In this moment I write a downloader of OS.

>git is too difficult for me.
Give VS Code a try with gitlab.
makes it extremely simple and VSC has a nice git UI built in.

Thanks.
>gitlab
Is there a difference with the github?

every language supports first class continuations because that's what fork() is

the only major thing is free private repos.
and better control of who can read/write your repo.
Haven't used github myself but gitlab just works so i don't have to think about it.

There's a /sqt/ for that
Go there.
Leave my /dpt/ alone!!!!!

This is just really small simplified part of my SQL procedure. I'd have to change a lot of other logic as well to be able to handle this in code.

Thank you very much for your full answer!

Attached: Ёжик_в_костюме_Копатыча.jpg (291x307, 81K)

no problem ivan.

I am Ajnur.

Attached: maxresdefault.jpg (1280x720, 75K)

Have an assignment with image processing/manipulations in C++.
Have done all the manipulations.
Have to:
"crop the image according to the image dimensions you set (either with the mouse, or manually by setting top-left, bottom-right pixel values)."

Ask if I can use OpenCV for this, told no you've got to do it in C++.


OpenCV is C++ though.
I'm not really sure where to begin with this problem.
What do?

Ok so what is the output of this step supposed to be exactly? You probably group by ID, can you show me what you it would look like if, hypothetically, you only wanted to select A and B?

is the image format specified? I guess you're forbidden from using already existing libraries
first try to crop .pbm, then move to .bmp
it's simple

Help.
I code in C and I have a problem (medium size, not too big, not too small). For user input, a buffer of type char input [1024] is often made. But the input can be less and then the bytes will be wasted. How can you deal with this? Linked lists?

It would just simple select statement like

SELECT
[ID],
[TYPE],
[VALUE]
FROM myTable
WHERE [TYPE] IN ('A','B')

Don't worry about it. You won't overflow your stack with a kilobyte.

One single .ppm file

I have set it up to start cropping but it only does it from a certain point on the y axis, I can't get it to crop from the middle of the x axis.

Thank you. I will hedonistically spend bytes.

Attached: хуйпидорговно.png (160x160, 25K)

if I remember correctly ppm is just a bunch of pixels' RGB values and a small header?

Yes.

I've been thinking that it is still a major pain in the ass to share files with other people - even when you are on the same network. It think it could make sense to make a minimal program with no dependencies that would just be given a folder as arguments, and serve files from that folder via HTTP.
What do you think?

read the image to an array[WIDTH][HEIGHT]
process it column by column or row by row, however you like it

>array[WIDTH][HEIGHT]
I. WANT. TO. EAT