/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

youtube.com/watch?v=kPRA0W1kECg
youtube.com/watch?v=DxY0jMJbk-8
twitter.com/SFWRedditImages

Hello World in Sup Forums text box.

Already got some answers but i'm just gonna repost this here:

Sup faggots, /jp/ here and i've got a question.

I want to translate a Japanese game into English but i have problems with the pointers in the text data files.
The pointers always point to the first letter of the sentence. I edit this in hexadecimal.
When i add or remove letters from the sentence, the sentences after it will change and the pointers do not match the first letter anymore.
Which programming language would be able to help me create a program which changes the pointers according to the position of the first letter?

Whatever they made the game in should help you. Specifically how they made the pointers and how the strings work. (Do they have to have the same length?)

I'm pretty sure he needs longer strings because otherwise it's a no brainer since if they're equal, they will work just as if, and if they're shorter, you just append a null byte after your text.

STRLEN
T
R
L
E
N

what wrong with it anyway?

How would you implement a Google type autocompletion/autocorrect thing in a standalone app?
Is there a library for this?

Something like that.
I know how the pointers work, would just be a pain in the arse to do manually

Depends what GUI library you're using, some of them provide such feature out of the box, otherwise you'd need some sort of a dictionary and fuzzy search then rendering the suggestions.

>Someone wrote shitty code in OOP so OOP itself must be bad
No

More like daily rulecuck thread amiright. Clean my shit janitorfaggot

every OOP codebase is shitty
Are you implying that everybody is shitty programmer?

Anyone worked here with Android embedded development? I'm looking to get a very custom solution built. Where can I find some good starting resources?

I guess null padding is the way to go then. Most likely your English sentences won't be able to get longer in bytes than the moonrunes.

Literally any scripting language.

Just write a program that parses the sentences, save somewhere the base pointer for the first sentence and the pointers addresses, and then compute the new values when you're done translating.

Also this, except it won't work when you'll try to add context information that is required in english but facultative in japanese.

yes, except myself

I want to learn how to write automated unit and integration tests properly, in Java. Any good tutorials and reading material you'd recommend?
Should I just go for the documentation of frameworks and tools like JUnit, Mockito, Powermock, etc?

>I want to learn how to BUZZWORDS and """testing""" in ENTERPRIZE LANGUAGE
are you sure though?

>vsnprintf is leaking memory again

That's wrong. standard library strlen() assumes that your chars are all 1 byte long, as it assumes that the first 0 byte will terminate the string. Anything that violates these assumptions will need a special library. If you're using strlen() on UTF-8 encoded text, for example, you should assume the result to be the amount of bytes and not the amount of chars. But that doesn't change much because UTF-8 is well designed, which is nice.

>write a piece of code in javascript using higher order functions and manipulate data in a pure stateless functional way and elegant recursive solutions
>performance is trash
>rewrite it "C-like" with only loops and plain functions
>runs literally 100 (one hundred) times faster

What are some memes you fell for, /dpt/?

I'm okay with simply going for the concepts and best practices, I just thought mentioning what I usually use could help.

>write automated unit and integration tests properly, in Java
Nothing can be done properly in Java. Just wing it. That's the entire reason Java exists.

High level programming languages have the issue that it's so easy to use inexpensive practices over expensive ones just because it looks better, when in reality the same can be done effortlessly without pointless language features much more efficiently.

The best example is the overused try: except: in python. It's at least 1000x less efficient than if-else and in most (if not all) cases it can be replaced by if-else effortlessly, just by knowing what to look for to avoid any error. Even adding if sanity_check(): goto fail in a few problematic places would be better.
The issue isn't the programming language, it's the shitty programming practices that it encourages.

post the code

i bet it's shit

>inexpensive practices over expensive ones
expensive practices over inexpensive ones, sorry.

he already said he's using javascript

the real issue is premature optimization of idiomatic code

>javashit
>functional
>recursive
The thing with FP is you can depends on referential transparency to do aggressive code transformation and optimization to make up for the supposed abstraction overhead. Mean while JS's FP implementation is just trash. I mean, what ``functional language'' aside doesn't even do TCO?
Well there are Scala and Clojure but that's JVM's fault.

Please stay away from working on anything other than FizzBuzz so that the world of computing is a safer place for all of us.

>need to write a program that fetches some images from a website
>do it in python (requests, json, Beautiful Soup,...)
>takes a pain in the ass to write plus is slow as shit

>rewrite in bash using curl + sed+xargs+regex
>0.2 seconds

gotta love it boys

>working with immutable data structures and unnecessary abstraction that doesn't get optimized is slow
no shit sherlock

>Javascript
>C
Wow no shit

It's javascript, of course it's shit.
I don't have the first version anymore, as I've completely replaced it with the other.

If you're confident you can do a better job than me, write, in javascript, an automata that take an image (around 60x60) as input, and simulates a fluid as in pic. I let you decide the inner mechanics as long as it's semi-realistic.

A black pixel is empty.
A blue pixel is the fluid.
A yellow pixel generates one blue pixel beneath it on each step.
Anything else is a wall.

It should be able to simulate at least 1000 steps per second.

so that image is generated by reading from a file?

i prolly write it in C + SDL . it's not hard

just surround your code with a giant try catch block noob lmao

The goal is using a shit language with a shit paradigm the language wasn't designed to be using.

so, how are you exactly making that gif?

are you using any external lib to render anything?

Each step is written to a png file, when the program execution is done, I assemble the files with imagemagick.

Or you could make a webm with ffmpeg.

why not use JS + HTML5 to render in the browser?

sorta like
window.requestAnimFrame = (
function(callback) {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();

Just do what the fuck you want.

I'm taking a course in neural networks. I wana see if I can train a neural network to detect clickbait.

artificial neural networks, you mean

>that code
kek, gotta love """standards"""

I mean yeah i'm not taking a premed course. I just figured that within the context of the thread it was fine to leave out the word 'artificial'

you were mistaken

that window's thing is to give support to firefox, opera, safari, chrome, etc..

i think there isn't another way of doing it?

That's because you have autism.

t. retard who can't figure out context

>implying implications

...

that's what I'm talking about, idiots cannot agree on a standard way to do something and instead every vendor implements their own and people end up writing shitty nigger hacks like that

would you like to have only one Operating System for every computer?

Vendor prefixes are only required for backwards compatibility with older versions of the browsers, you don't need to use them anymore really.

are you perhaps mentally challenged?
there's a thing that's called a standard, it defines the API, but instead, browser vendors break the standard, and create their own function names that do not adhere to the standard, I'm not sure how your analogy makes any sense whatsoever in this context

good to know

>are you perhaps mentally challenged?
probably. don't even know anymore

>tfw getting 900 euro for a programming job in yurop

can i live in my car and shower at the gym to save money?

Where in europe? Depending on which country (and city) it's either decent amount of money or fucking nothing.

what shit tier country do you live in? i get 600€ per day here in germany

Portugal

>i get 600€ per day
god help me. there are people here who get 600€ per month,

what do you do? work as a programmer?

C++ IS THE GOD OF ALL LANGUAGES PROVE ME WRONG FAGGOTS

Employed idris programmer

kek

freelancer programmer

this is before taxes of course

why not working in a company?

wouldn't you earn more?

i guess i get your point. you have more liberty

>I wana see if I can train a neural network to detect clickbait.
Easier just to blacklist known clickbait domain names.

>decided to accept the challenge and try it on C++
>in the end, can't stop watching the gif while doing nothing

i like wasting time with sorting algorithms

youtube.com/watch?v=kPRA0W1kECg

working in a company is trading money for safety. i need to look for a new client every few weeks when i'm done with one project. but sometimes i just sit on my money and NEET for a few weeks. i like it

>Essential Skills :-
>DSP
>C
>C++
>Assembler

>Desirable Skills :-
>Matlab
>Simulink

But the challenging thing here is about doing it in functional-style javascript, not C++.

Typed languages are too easy.

blue board

Help me /dpt/, I'm about to tear my hair out. Trying to do some C.

if (guess[0] == 'm' && guess[1] == 'o' && guess[2] == 'a') {
puts("\nGETTING MOA BY MANUAL COMPARISON\n");
printf("strcmp returning: %d\n", strcmp(guess, "moa"));
}

Output:
GETTING MOA BY MANUAL COMPARISON

strcmp returning: 1

Context: I'm looping over all three-letter words (the above snippet is inside a triple-nested for loop). I use a char array called "alphabet" containing all the lowercase letters (I know I could just increment chars, but an array is more general, as it allows arbitrary alphabets if I want to do that in the future).

The function this is in literally has the three nested for loops, a strcmp to check if the words matches a known goal (in this case "moa"), and if it matches it it returns it (otherwise it returns an error value).

I'm calling this function multiple times (once per line for an input file), and the first time ALWAYS gives the above wtf. Starting with the second line (i.e. second time the function gets called), everything works as expected.

I'm at my wit's end. What could possibly do this?

lol i had that when i graduated

web dev?

The problem is that you're using C

check the value of guess[3], it's probably not '\0'. Maybe a newline or something.

strcmp looks for an exact match of the two strings from start to finish.

Are design patterns important? Why can't I just create a custom one based on every custom problem?

VR, interactive media. mostly Unity at the moment

i don't get that image
my gf says that all the time and I see absolutely no problems iwth it

you should look up the definition of "pattern"

strcmp checks more than the first three characters

post more of the code

>Why can't I just create a custom one based on every custom problem?
Uh. That's exactly what you should do.
Design Patterns are good solutions to _known_ problems. If it's a new problem, create a new solution. Don't abuse design patterns lest they get in your way.

Guess is a char[3], so there is no guess[3]

And it works perfectly the next time I call the function

Once I get back home, in 20 minutes

There's your issue then, it has no null byte while the "moa" argument probably has it added to it at compile time. Make it a char[4] with a null byte forced at guess[4] and try again?

php > all

What's the time complexity of sorting an array of strings? Is it still n log n?
var foo = ['yes', 'no', 'maybe', 'i don\'t know', 'can you', 'repeat the question'];


For sorting such an array, is it only necessary to look at the first character the vast majority of the time, and sort relative to that character? We'd only need to check successive characters to resolve cases where the strings being compared both start with the same letter, which wouldn't happen all that often or to such a degree that each individual comparison would become non-constant time.

Is that right?

No.
Use a real programming language.

I don't understand why it would work later, but I'll try it anyway

Design patterns are like generalizations of custom shit that you will write.
I think it's more about learning the terms to communicate with others and understand things quicker.

Which are your favorite programming penguins to program with?

youtube.com/watch?v=DxY0jMJbk-8

I think those birds should live in their natural habitat.

that shit ain't right

so should programmers

...

The string literal "moa" is stored in memory as the letters m o a followed by a null byte, so it's a total of 4 bytes. This null byte marks the end of the string, that strcmp and other standard string functions rely on to know when to stop processing.

You can test that by doing

char s[] = "moa";
printf("%ld\n", sizeof(s));


It will print the size in bytes of s.

strcmp will reach that last character, and see that there's a null byte at the end of string pointed by its second argument, but may or may not see a null byte following the "guess" pointer, as it will check outside of the storage specified by your pointer, which is undefined behavior.

The guess variable has 3 bytes in memory:
{'m', 'o', 'a'}
The argument has 4 bytes in memory:
{'m', 'o', 'a', '\0'}

strcmp returned one, what probably happened is:
strcmp looks for the first different byte. It scans 'm' on both, scans 'o' on both, scans 'a' on both, sees that the '\0' ends the second argument but random garbage is on the first argument. The next byte is probably a '\0' at random, if not it would keep going until it found one or it segfaulted.

so it sees:
first argument: {'m', 'o', 'a', random byte, '\0'}
second argument: {'m', 'o', 'a', '\0'}
It returned one because the string has one byte more than the other.