/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

'
codefights.com/challenge/WFRx6HvmG5KLABepG/comments/WADRsqgYMJAMnT7uk
twitter.com/NSFWRedditVideo

>tfw a video game taught you more about concurrency and threading than any professor could

>hi, my name is user
>I'm a virgin that has never accomplished anything
>I have an irrational obsession with Japanese children's cartoons
>I spend all my time posting about Japanese children's cartoons on an online programming discussion community

I created this neural network that applies the visual effect to the black and white picture.

Video is the learning process: each frame is the result of model's work after a step of training.

I trained it on just one pair of input/output images.

Any recommended json library for c++? I want write a bot that downloads json files and processes them.

Yeah, node.js has some C++ bindings :^)

javascript can do that a lot easier bud

http = require('http');
fs = require('fs');

port = 3000;
host = '127.0.0.1';

server = http.createServer( function(req, res) {

if (req.method == 'POST') {
console.log("Handling POST request...");
res.writeHead(200, {'Content-Type': 'text/html'});

var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
console.log("POST payload: " + body);
res.end( '' );
});
}

});

server.listen(port, host);
console.log('Listening at ' + host + ':' + port);

I'd suggest writing your own for practice. IRCC jsoncpp is easy to set up and use. Also it sounds like you want to make a simple networked program that does text manipulation, I'd suggest not using C++ at all ;) Unless you need the practice.

There are probably dozens of C++ JSON libraries: JSON is easy as fuck to implement.
Just grab one off of the JSON website.

currently getting destroyed by this:
codefights.com/challenge/WFRx6HvmG5KLABepG/comments/WADRsqgYMJAMnT7uk

This.

As much as newfags like to hate on Node.js, learning it made me 1000x more productive. Few languages can compare to its simultaneous power and lack of bullshit.

Maybe just use Golang instead of C++?

Here's some more pictures.

Qt is beautiful. It's probably too big for your small task, but using Qt with C++ is pure bliss.

Any modern language is just as powerful and is without bullshit.
Python, for example, has much, much more functionality available for it also.

I might as well try js. All I want to do do is a simple chan archiver that downloads threads, adds new posts to a db, marks deleted ones as deleted and updates message text of banned posts.
Getting practice would be nice, but I guess it would end up leaking memory all over the place after running constantly for a month.

Except python sucks at functional programming, but javascript is scheme dressed up as an imperative language. Also node is asynchronous and nonblocking.

Using a gui toolkit is always painful.

What? Why would you think this?

If I have a filename stored in a string and I am passing that variable to fopen() does the filename variable need quotation mark characters in its array?

Python has just the same capacity for functional programming as js.

Not really, python's lambdas are a lot less comfy than JS

Comfiness is not a measure of functional programming capacity.

Not even remotely. Functions are first class citizens in javascript. You can assign functions to variable just like you could with any other primitive data type. You can even instantiate functions as classes.

It's hard to appreciate the magnitude of the helpfulness of js's functional programming features without trying them yourself.

No

writing a gui for a scraper I wrote for my school in python

that little bar in the middle is draggable and the panels all scale (staying centered)
and the whole thing can be resized smoothly while keeping the ratios the same

Why are you telling this? Do you now know how it's the same in python or something?

Learning to actually program in C++. Tried in the past but never took it serious. This time I'm actually making my own shit using the concepts I'm learning rather than going through the motions or copying code.

What if there are spaces in the actual filesystem path to said file?

I'd say comfiness is all that matters.
You can implement psuedo-OOP in C, or try to implement optional types in C++ but it's going to suck compared to languages that integrate them first-class

No. You're not inside a shell or anything.
The kernel treats the filename EXACTLY as it is, byte for byte.

Comfiness means nothing. It's just a word you say when you have no actual argument.

C is bad of OOP because you have to write a lot of boilerplate code, not because it's not "comfy".

I've just never used a gui toolkit that was actually enjoyable.

Try Qt.

I've been putting off learning programming for 4 years now

and now after dabbling in some scripting languages, I finally feel motivated enough to dive in

What kind of shit did you program in your first year or two of learning?
What kind of shit programs do you write now?
when did you start contributing to other peoples projects n shit?
how often do you program shit from scratch that you actually utilize day to day at home?

Guido specifically wants to keep functional programming out of python, even though everything in node is based around functional programming. It makes for js that's really simple, short, and fun to write.

I have used Qt on linux projects.

Python does FP bad because you can only have a single expression in a lambda, scoping is all fucked up for nested functions (well, JS has fucked up scoping rules until the ES6. jesus is lexical scoping really that difficult to get right? it's been around since scheme..), and Python doesn't and will never implement automatic tail calls.

Confines is another way of saying boilerplate. You can't
var myFunction = function() {...}

or do any of the awesome stuff from lexical closures in python.

Where is the programming board? What's going on?!!

*comfiness

I fucking hate posting from mobile.

Is there an extant file line counting function in C, or do I have to write my own?

I know it's a common tutorial topic, so searching line count C is really unproductive.

Been learning Python a series of months now. Enjoying it intensely. Programming is one of the most rewarding things.

Been writing scripts - flashcard tools, small file sorters, codewars challenges, stuff like book recommendation listers.

Some of it is now dry and easy.
Looking for some good project recommendations. Something accessible.
Recommend please

The best way to learn is just to program. Been picking this up fast. I use programming to accelerate my skills. The best thing I've made is an "impediment tracker" that helps me even-out irregularities.

How feasible would it be to, instead of having a full-on compiler, have a programming language be described by a bunch of assembly language macros in the standard library that get all pasted together before you run your program? Like the way your code is compiled would be overrideable by the programmer because basic operations like addition and loops are just defined as inline assembly macros .

It would probably have to look kind of like lisp, though.

>you can only have a single expression in a lambda,
That looks really horrible. I found more reasons to like Perl today. Perl's lambdas work just like javascript's.

then don't. your contributions won't be missed

Tensorflow. Maybe their MNIST tutorials.

>being this butthurt that python is being supplanted by newer, better platforms
Lol, I love it.

make me a software that hooks my operating system and intercepts mouse clicks
and then it only allows clicks through that are at least 20ms apart
because my gay ass mouse clicks twice almost every time I click once

>Is there an extant file line counting function in C
No
>do I have to write my own?
Yes. However it's REALLY trivial.
int c, lines = 0;
while ((c = fgetc(some_file)) != EOF)
if (c == '\n')
++lines;

He's not the person you're arguing with. I am. I do concede. Having just one operation per lambda is unacceptable. I'm new to python and am extremely impressed with what can be done with neural network libraries, which mostly seem to be developed on python. I never actually used lambdas in python - I usually use Perl and its lambdas are the same as in javascript, so I just assumed python can;t be worse.

can someone give me an example of the use of lambdas?
to me they seem like anti-patterns in that they go against the concept of writing reusable code once and in only one place

Something like this probably:

((call/cc call/cc) (call/cc call/cc))

If you know you don't use this code anywhere else, why not write it in a place where it logically is supposed to be happening instead of somewhere far away? Why give it a name if it does not need one since it's only referred to once?

why write it in the form of a function at all if the only place you use it is within another function?
why not just write the code in a scope in that function?

Because it's not called at all during function execution - it's called later, as a callback for example. It belongs to function because it is directly related to what the function is doing and uses its local variables.

ok. That's what I did.
I just didn't want to re-implement something that was already written.

I personally don't use callbacks, but if I did I'd certainly want the callback to be its own function for ease of debugging and refactoring and for code clarity
is there any other use of lambdas besides that?

try tis-100 for a real dose of autism.
Also, how far are you in spacechem?
I think I gave up half way through the last set of challenges.

How do I, using Haskell Platform & Atom+HaskellIDE, install packages globally in a way that will automatically work with GHC & autocomplete

You say for clarity but putting pieces of code that do related things away from each other hampers clarity. And whatever misconceptions you have about difficulty of debugging lambdas are false.
The other use I know of is binding data and code together. You can create a function that would output identifiers - first time you call it, it outputs 1; the second time - 2, etc - and if you create another instance of this function it would have its own counter.

Holy shit I FUCKING HATE Dbus.

>Need my systemd service to send desktop notifications
>Set DISPLAY to :0 in unit file
>Set user to the user my X server is running under in unit file
>Still no notifications visible, because lol dbus.
Yet it works fucking fine in my shell.

Fucking HELL, this shit is pissing me off! how do I get my daemon to connect to the existing fucking dbus whateverthefuck under my user?

Wouldn't that result in some really, really nasty side effects?

I'm writing a program that needs to access some files in /dev/ (/dev/input/event* specifically). I'm currently using the setguid bit on my executable to allow my program to access them, but is there a better way I can be doing this?
Whenever I try to run my program with the setguid bit on through valgrind, it seems to show a whole bunch of leaks that my program isn't responsible for.

Can't you just change permissions for files you're accessing?

No, I just want to be able to install packages

Actually I should clarifiy, the notifications ARE present, but because it's under a different dbus connection, it spins up a whole new dunst instance! (wtf dbus) and crashes BOTH instances.
Honestly I have no idea how dbus works or why it fucking exists, but I just want this shit to use the EXISTING fucking dunst instance when sending notifications.
Why do these ABSOLUTE FUCKTARDS HAVE TO MAKE EVERYTHING COMPLICATED AND BROKEN.
There is LITERALLY NO NEED FOR DBUS TO EXIST.

You should be more careful what you wish for.

Changing shit in /dev isn't really a good idea, as udev or whatever manages it all.
Also, if I ever want to distribute my program, it really isn't something I could expect other people to do, as changing those files in particular allows malicious programs to keylog you.

/tech

I just want to know how to fucking install packages so that I can actually fucking use them

Well, if you do need root, then setguid is the way to do it. You can write another tiny program that would access your files, setguid just it and use IPC to communicate with your main program. You'll also limit the amount of code that runs as root, making your program less likely to be a security hole.

How bad of an idea is this union
typedef union
{
uint32_t u32;
uint16_t u16[2];
uint8_t u8[4];
float f;
char hex[4];
char str[5];
} U32;


Im reading a binary file into a string. I want an 4 byte word from the string but its null terminated so its 5 bytes total. Hence char[5];
Also, is a string is just a null terminated char array. Why in the world cant I convert a string to a char array.

You'll probably have to elaborate on what your inputs are, what you want to achieve, and what you mean by being unable to convert string to char array if you want someone to provide a good response to you.

I'm only setguid'ing myself to the 'input' group, so the security implications aren't too massive.
I realise now I could just add myself to the input group, but it's still not really sure if it's a requirement I want my program to have.

>How bad of an idea is this union
It adds endian issues to your code.

Stop using anime images

yeah Ive already noticed the endian issue. I play to only use big endian so the uint8_t are probably going to be unused.
what elaboration about my inputs do you need. Its 4 bytes from a binary file in a string.

Well, your 4 bytes from a binary can contain bytes that have value that are not printable characters which means you should not be printing them which meas your null terminator useless.

You can convert string to char array in C.

I never said I was printing them nor that the null pointer was needed. Its just there. Do you know of a way to get a substring of length 4 without the null pointer. strings copy function seems promising but vs2015 is telling me its unsafe.

Trying out some console style output on my chip8 emulator in rust.. Only one question how the fuck does one clear the console screen in a way that is compatible on both windows and linux in rust?

char x[]="abcdefgh";
char y[]="nmpqzxuw";
*((int *)y)=*((int *)x);
// y should be "abcdzxuw" now // if sizeof(int)=4 that is

//alternatively,
memcpy(y,x,4);

I've got the sdl implementation working. I just think the ascii style output looks cooler. I'm thinking that a ncurses style library that has windows / linux support would be ideal.

That violates the strict aliasing rule, idiot.

>the way i do the same thing is better because arbitrary rules!

>check if user is running linux or windows
>if linux then A
>if windows then B
is usually how you do it.
Either that, or you're using a library that does that for you.
I suggest running this check once on startup and keeping that as a global final var.

#if _WIN32
windows clear
#else
linux clear
#endif


oh, right
rust doesn't have preprocessor
fucking el-oh-el

The strict aliasing rule isn't some self imposed shit: your program contains undefined behaviour.
Maybe you should actually learn something about the language before you try to argue about it.

Anyone care to point me in the right directions to learn various programming languages? I don't mean like all languages together, I mean like a good place to learn X language and such, languages you know. I want to start programming and making apps/software but I'm currently stuck in a rut, just have Eclipse open and nothing going on. Know the basic Javascript/Visual Basic/Android/etc.

I could do that.. it'd be a pain in the ass though to accomplish so little. I mean I don't feel like writing a small c library + rust bindings for this trivial task. It looks like the answer will be using pancurses.

unfortunately it has to be a string Im working with initially. Im returning the file as a string from a function.
Fortunately after turning off the compiler warning about string copy, it does exactly what I want I need.
Im still a little annoyed but the endian default and I need to make sure that there are no issues with signed and unsigned since I cant use an unsigned char.

This is a very bad practice in C as any system is able to define _WIN32.

Files that compile only on one system and you define the same functions in them. This is what you should do in any language.

>This is a very bad practice in C as any system is able to define _WIN32.
So? It's in the reserved namespace.
No platform is retarded/trolly enough to claim that it's a platform that it doesn't support.

It's not about claiming something, it's that they have the right to do it, and only a retard would use something like that to check for a system.

what do you suggest instead?

>it's that they have the right to do it
Again, no platform that expects to be taken seriously will masquerade as another platform.
There are all sorts of nasty shit that a platform could do to you that they "have the right to do".
>only a retard would use something like that to check for a system
Do you have a better proposal?

Did you not read my post above?

>Again, no platform that expects to be taken seriously will masquerade as another platform.
Again, they do not claim to be another platform. They could as well consider anything that starts with _ and an uppercase as defined.

>There are all sorts of nasty shit that a platform could do to you that they "have the right to do".
And if you do not really need a feature that may cause this kind of thing, you should not use it, especially when better ways exist.


>Do you have a better proposal?
Did nobody read my post above?

Both methods I listed always works as advertised in practice. Your theoretical knowledge is worthless in relation to the topic at hand.

>Files that compile only on one system and you define the same functions in them. This is what you should do in any language.
that would result in code duplication. I would trust my compilers to properly define things thank you.

>that would result in code duplication
No, not at all.

>in practice
>My undefined behaviour "works"
You clearly don't know jack shit about what 'undefined behaviour' entails.
If you write programs which rely on undefined behaviour, you have failed as a programmer and should kill yourself.