/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: 1527734667639.jpg (369x333, 19K)

Other urls found in this thread:

godbolt.org/,
software.intel.com/en-us/articles/intel-sdm
gist.github.com/barosl/e0af4a92b2b8cabd05a7
curl.haxx.se/libcurl/c/CURLOPT_WRITEDATA.html
godbolt.org/g/pnvr9Y
open.buffer.com/buffer-distributed-team-how-we-work/
syscalls.kernelgrok.com/
twitter.com/NSFWRedditImage

It ended up being too long but it's basically this:

from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np


def generateWordcloud(text, maskFilename='logo_Jow Forums.png'):
mask = np.array(Image.open(maskFilename))

stopwords = set(STOPWORDS)

wordcloud = WordCloud(background_color="white", max_words=2000, mask=mask, stopwords=stopwords)
wordcloud.generate(text)

plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

generateWordcloud('foo bar baz test')

make a PR retards

>What are you working on?
A guide for learning C++, basically a collection of other resources (tutorials, talks, books, etc.) grouped into beginner/intermediate/advanced/avoid sections. I've seen several people asking where to start recently and thought I'd throw together stuff I've found useful.

nobody should learn C++ though
why mislead people?

I'm starting to like templates, why do I feel this is a bad thing?
template
void exec_func(Function func, Args... args)
{
int result = func(args...);
};

for me, it's camelCase

Attached: file.png (638x479, 95K)

I hate having to summarise what has been accomplished in my commit messages when I commit so infrequently that practically EVERYTHING has changed. But oh no, I can't just say "Everything has changed" because then some nerd reading my commit messages will shake his head and think poorly of me.

Because I'm the resident sepples shill. But seriously for no other reason than people want to learn it. That or objectively because there's enough complex C++ codebases that there's a demand for people who know the language well. Unless you like being a NEET in which case godspeed.

learn to squash, egghead

Someone link me to a place where I can learn enough of Assembly to write a bootloader pleeeeassse.

While templates are pretty useful, the syntax is very verbose and there exist languages with similar functionality that are much more elegant.

godbolt.org/, blockhead

Do a separate commit for each change.

UPPERCASE for global constants/enums/defines
PascalCase for structs/classes
snake_case for functions/methods/variables

What is squash?

Attached: egg.jpg (849x534, 56K)

Learning C, wedev stuff (playing with react and node), watching discrete math lectures on youtube, and doing a Udemy calc course.

Damn course jumps from basic slope formulas into regression lines without explaining what a regression line actually is.

Attached: nwahsbeware.png (720x715, 472K)

a git thing, ya nincompoop

>me when i compile

Attached: 1528493748763.jpg (800x722, 104K)

Pick an assembler(NASM is fairly popular), learn the syntax(i.e. read the docs),
software.intel.com/en-us/articles/intel-sdm

Good luck.

where's the /dpt/ gitlab group ya bunch of 4-eyes

>roll your own crypto
>opps don't understand maths
get outta here you lamebrain

Even if you have a phd in math, you're still not qualified to roll your own crypto.

variable_name
TypeName
function_name
But I just use the language style desu

RSA on paper is not that hard, elliptic curves on paper is not that hard
implementing them
get lost doofus

You can do that in C with generics.
variable_name;
funnam()
OBJECT_MACRO
FUNCTION_MACRO

>You can do that in C with generics.
care to give an example?

Turing-Church

>OOPs tards buttblasted

Attached: 1506067958830.jpg (600x599, 63K)

>take a bunch of points
>take a function y=kx + m
>for each point, calculate (y - (kx + m))^2
>sum this for all the points
>write this as a function, y = f(k, m), where y is the summed total error
>use the primitive functions to get the derivative for y = f(k, m)
>solve f'(k, m) = 0
>if there are multiple solutions, check them all to see which one is lowest
>you now have a regression line
Simply put, it's the best fit line. You can also get a good enough result with a ruler and pen and paper.

Attached: 1513075776626.png (682x330, 35K)

hahahahahhaa
the very state of /dpt/

sorry m8 you need to get back up to a middle school math education

>train-case
No, that's kebab-case

successful post my man
OOPsies in full retreat

Attached: church.jpg (256x256, 7K)

suicide

If you can't even figure that out, then there really is no hope for you.

Are apps back end any different from web back end?
Or as long as they use the HTTP protocol they are good to go in any project?

HTTP is a transfer protocol, it says nothing about the data it transfers.

what's the big deal about types

Confusion and dogma.

gist.github.com/barosl/e0af4a92b2b8cabd05a7
Function overloading at least. For function pointers, we have void function pointers, putting the fun in function pointers!

>if it walks like a duck it's probably a duck idk just see what happens

Oh, that's pretty interesting, thanks!
Okay kid

Function overloading is not the same as templates.

that's what you have the macro for

libcurl - is there an option to specify the directory I want a file saved in? I don't want to have to override callbacks and handle opening, writing and closing a file manually. That's just stupid.

Attached: V2zuWYQE_400x400.jpg (399x399, 16K)

That's is neat, didn't know about _Generic, but how would you deal with something like, functions that return int, but have different number of parameters, without relying on UB?

Nvm found it
curl.haxx.se/libcurl/c/CURLOPT_WRITEDATA.html

Open a FILE handle wherever you want the file to go.
Set it as CURLOPT_WRITEDATA.
Then the default curl write callback will write to that file.

At that point you need to manually instantiate templates.
If you use static for templates instantiated in this way, you will get horrifically bloated code.
If you use inline for templates, you'll need to collect all possible instantiations into a single implementation file or you run the risk of generating linker errors.
Without C++ vague linkage, there's no point trying to imitate template stuff in C.

variadic macros and variadic functions I guess.

def foo():
bang = 1
return {'baz': bang}

def bar():
bang = 1
buzz = 2
return {'baz': bang, 'fizz': buzz}


Is there any harm in combining these two, even if some functions will only use the 'baz' value in the dict?

>variadic macros and variadic functions I guess.
Not very familiar with those, sadly, but if I remember correctly, variadic functions are notorious for their overhead, or at least that's what I heard.
But yeah, gotta familiarize myself with those.

reposting in fresh bread

I'd like accounts of self-hosted VCS, specifically Mercurial, but the /hsg/ is too dead to answer:

Attached: d90.png (861x484, 686K)

Thanks friend.

Attached: 1519901182220.jpg (303x326, 20K)

>zero overhead property implementation(add operator overloads as needed)
godbolt.org/g/pnvr9Y

Your move, C#.

>open.buffer.com/buffer-distributed-team-how-we-work/
>all these macbooks
How the fuck do people do develop on such underpowered tiny machines?
They can't even upgrade the ram.

#include
#include

template
std::function operator,(Receiver receiver, Retval(*fun)(Receiver, Args...))
{
return [&](Args ...args) -> Retval { return fun(receiver, args...); };
}

struct intbox
{
int x;
};

void println(intbox x)
{
std::cout

That's why you use a recursive macro to generate it.

Why is mercurial better than git?

It's not.

I don't get it either, I walk around in a special powered armor just so I can carry one of these like a backpack (I SSH into it with a Thinkpad ofc.)

Attached: ubuntu-mainframe.jpg (620x808, 144K)

I'm not qualified to say it's better, but it is definitely easier to use.

I don't see how this solves the linkage problem.

Because you will inevitably use them for all kinds of shit they dont belong to.

Probably true, I'm a C programmer, and never really wanted templates, but looking at examples, I'm starting to get intrigued, but you're right, it would probably end in disaster.

Are you seriously competing with C# as a sepples faggot?
How far the mighty have fallen

how print "hello world" in assembly.

The mighty have fallen?
Last time I checked, the mighty is still the backbone of your (required)runtime.

>std::function
LOL try again

Depends,
on your OS, assembler and CPU(and implicitly, your architecture)

how do Linux (Arch), NASM, i5, unknown architecture cuz im stupid.

Rust/D/Nim doesn't need a C++ runtime. It's just sad that you suffer from an inferiority complex when it comes to C# for some weird reason.

Finished my dithering algorithm!

Overall, pretty proud of it!
The dream is to make some photoshop-lite application that exhibits different versions of different algorithms.

On an unrelated note, how do I find what the bottleneck of my program is?

If I run my program on a 24 MB image, my algorithm (which is essentially just storing data, in a vector, then a palette of colors, then a map from palette to data) occupies around 2GB of memory according to my IDE.

I use the following type of map, but was considering using pointers to vectors instead.
typedef std::vector DVector; //Linear algebra vector
std::map KMap; //Mapping from centroid to data vector


I also know that a kd-tree would be a *lot* faster than a simple map because then lookup for a color would be O(log N), but I'm just concerned about memory atm.

I might also learn about parallelizing my code to see if it runs in real time.

Attached: AESTHETIC DITEHRED CYCLOPS.png (1280x1706, 2.58M)

brainlet here, what does this accomplish?

Tries to emulate UFCS in C++

>Rust/D/Nim(transpiled C)
Who ever mention those?

You said `your` required runtime. I use those three languages.

>your
Referring to C#, sorry if I wasn't entirely specific about that

How to achieve dithering on random images?

>Linux
eax = sys_write (4)
ebx = file descriptor (1 for stdout)
ecx = address to where your char/byte array is
edc = length of your string
int 0x80

syscalls.kernelgrok.com/

>edc
fuck, edx, that is.

how the fuck does a dithering algorithm that operates on a 24MB image end up using 2GB of memory...

>according to my IDE
which is?

I don't really make a special case for random vs non-random images, but I'd assume it does it badly.

Attached is a comparison of the algorithm with a range of colors

Yeah, that's what I want to know as well...
It just doesn't make sense to me. I'll post my code once I'm done with tests and have a bit more free time, but my hunch is that I'm doing a lot of unnecessary copying and reallocating with the map

XCode

Attached: Untitled-1.png (1500x1343, 367K)

I don't say what I see

2GB? How?
2GB/3 colors = 680M
sqrt(680M) = 26000

Is your image 26000x26000 px big? If not, you're going wrong there.

If you have such a small space as 3 channels, you can just use a regular array lookup (16.7 MB, but consider using Morton numbers and seeing if less suffices)

section .data
msg: db `hello world\n\0`
msg_len: equ $-msg

section .text
global _start

_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, msg_len
syscall
; write(1, msg, msg_len)

mov rax, 60
mov rdi, 0
syscall
; exit(0)

>2GB/3 colors
Forgetting about alpha, but yeah, still...

Dont get me wrong templates are a fucking godsend when you need them
Its just then you want to template everything
And then you end up with horrifying templated chains of templates because you templated one class and lost your fucking mind

Considering rolling my own algorithm to solve something, for fun and learning, even though there probably are better solutions available. Thoughts on this?

It's an image from /wsg/, so the dimensions are approximately 1200 x 1900.
The image attached was by far the largest memory hog

>alpha
>dithering

Fuck

Attached: Screen Shot 2018-06-08 at 4.22.28 PM.png (522x782, 92K)

I don't see why it is necessary to do dynamic memory management at all...

Whatre some good sepples compiler tricks to squeeze every drop of performance out?
Im building a program that ultimately isnt complex in structure, but it is PAINFULLY performance sensitive. Every 100ms I can knock off really really counts.

Right now the bottleneck seems to be how Im pulling in data. It takes about 20ms for libcurl to pull in the data file and about 33ms to read it out of memory into a usable format.
Are there any better libraries than libcurl for this? Its already multithreaded and I have workers reading it out of memory when libcurl is done asynchronously but its still not fast enough.
I tried the multihandle option with curl and it ended up being slower.

You better be pre-allocating your blocks

Ditch the sepples garbage and rewrite it in C.

Do heap snapshots. You almost undoubtedly have a fat memory leak or youre passing copies of datasets around instead of pointing to a single item

My bad, shouldn't even have responded, all I've ever handled is RGBA8.

I mean at least the way I have my algorithm set up, here's how I do the mapping from palette colors to data:
void
K_Means::clearMap()
{
KMap.clear();
}

void
K_Means::createMap()
{
//ASSUMPTION: InitGuesses / centroidVec is nonempty
//ASSUMPTION: KMap is empty
assert(KMap.size() == 0);
//Iterate through centroid vector and create an empty vector at each step
for(int cInd = 0; cInd < K_VAL; cInd++)
{
DVector centroid = centroidVec[ cInd ];
KMap[ centroid ] = std::vector();
}
}

void
K_Means::loadDataIntoMap()
{
const int64_t N_ELEMS = dataVec.size();
//Iterate through the data vector
for(int dataInd = 0; dataInd < N_ELEMS; dataInd++)
{
//Get closest centroid and place into map
DVector closestCenter = getClosestCentroid(dataVec[ dataInd ]);
KMap[ closestCenter ].push_back(dataVec[ dataInd ]);
}
}


Honestly, this is probably what Im' doing wrong... I'll learn how to do heap snapshots and report back eventually

From a non-user's perspective, it seems to gather more data about your project, said data is easier to navigate (altho this depends on GUI I suppose) and the commands aren't a Byzantine mess. Looking at the Wikipedo comparison table, Mercurial uses Python instead of Perl, and Git doesn't let you change file names, what the hell

>//ASSUMPTION
Is this a guide to "how not to get your code merged"?