/dpt/ - Daily Programming Thread - Real Programmers Edition #13

What are you working on, Jow Forums?

Old thread:

Attached: Hamza Bendelladj.jpg (687x1105, 118K)

Other urls found in this thread:

godbolt.org/g/VcQwWs
youtu.be/Q7GKmznaqsQ?t=45m19s
www2.physics.umd.edu/~yakovenk/econophysics/animation.html
www2.physics.umd.edu/~yakovenk/papers/EPJB-17-723-2000.pdf
learncpp.com/cpp-tutorial/38-bitwise-operators/
twitter.com/AnonBabble

Just started trying to learn C++, coming from C#. I learned very quickly that structuring a program like a C# program ain't gonna fly in this language. I'm a bit confused as to what one of the warnings I'm getting means.

Warning: candidate expects 2 arguments, 0 provided
The warning itself isn't what's confusing, it's the context. This is a warning in the definition of a constructor, not at the actual call. What I have in code is
Space::Space(int width, int height)
{
do_something(width, height);
}
What did it mean by this? Using CodeLite btw.

that you arent constructing Space with two arguments.

Is Space derived from something? You need to call the super constructor through the initializer list.

I'm running into a situation where mvwprintw() is failing using ncurses.h with ERR. how do I tell what error happened? does ncurses set errno?

godbolt.org/g/VcQwWs
>fmtlib

what language can i learn to replace ParaSail now that it's officially dead?

What do I need to know to be prepared for interviews?

I'm mainly self taught (currently in uni) but have no idea what I'd be asked in an actual interview

b urself

How to optimize kruskal's algorithm was one I got asked a while ago for an internship

I think you have to use something like this
:code: class Space
{
public:
Space(const int &a, const int &b) : height(a), width(b) {}
int height;
int width;

};
:stopcode:

class Space
{
public:
Space(const int &a, const int &b) : height(a), width(b) {}
int height;
int width;

};

I'm a bit confused about some of that code.
1) In the constructor declaration;
: height(a), width(b){} is this setting the variables from the arguments passed, even if the type isn't derived? Space isn't derived from anything if it has to do with inheritance.

2) what's the implication by using & or not using it?

Sorry, been awhile since I went through class constructors.

to question 1, yes it is a constructor initializer list. it takes the arguments passed when you initialize the class and assigns them to the variables after the colon. so &a goes to height(a) and &b goes to width(b). idk why they do it this way, just how it is.

Second, using a reference keeps the variable being passed from being copied or manipulated during construction. You also need the const if you are passing literal values. ie
Space my_class(10, 10)

Is there any website or something similar where i can practice my programming skills? Stuff like challenges and whatnot.

New here, learning HTML5. Does anybody used Codecademy to learn programming languages? How was your experience?

hackerrank.com/dashboard

Lots of practice and competitions. the automated checking can be annoying at times but it is pretty good for just a shit ton of practice to do.

Why do I feel so much more uncomfortable writing C now than when I used to almost frequently?
I just want to do josephus' problem.
Like I feel like I am writing a bomb.

void initCircularList(struct node **head, struct node **end, int nodeNum){
*head = (node*) malloc(sizeof(node));
*head->data = 1;
*end = *head;

for(i = 2; i next = (struct node*) malloc(sizeof(struct node));
*end = *end->next;
*end->data = i;
}

*end->next = *head;
}

Attached: 1509378145322.jpg (425x408, 53K)

Never used code academy, I prefer books. I used the book in the pic. Pretty good overview.

Attached: index.jpg (220x276, 6K)

>forgot to declare i
fml

I got a job doing c# stuff

its easy and boring

Attached: 1499226880533.jpg (1100x516, 104K)

This is probably a stupid C# question, but how much of a performance difference would there be between

var query = Medications.Where(m => names.Contains(m.BrandName) || names.Contains(m.GenericName));


and

var query = Medications.Where(m => names.Contains(m.BrandName);
query.AddRange(Medications.Where(m => names.Contains(m.GenericName));


Am I saving one loop through the collection by doing it the first way?

I ask because I need to query the same list for different things and it's unclear if it's worth the hassle of trying to figure out a way to "buffer" all the queries into one big search instead of several ones.

pic unrelated.

Attached: fuck me eyes.png (994x560, 618K)

>*head->data = 1
you probably want (*head)->data = 1 or head[0]->data

gz fren

dumb frogposter

Yea shit I forgot -> has higher precedence, I thought they were the same

Attached: 1524475822867-b.jpg (252x200, 9K)

Using flutter to make an app. Was going well until I had to load in a ton of thumbnails. Now one of my widgets refuses to load.

Going to see if it can be solved using isolates, but my hopes aren't up.

stupid frogposter

Is there any benefit to learn python? I learned C/C++ first and it feels like I am learning a language written by someone with down syndrome.

Attached: 1510885396288.gif (500x281, 996K)

Association for Computing Machinery is $19 for a student for a year and gives you access to Safari Books Online (has tons of books, online trainings, videos and shit), Skillsoft (for IT people I guess, mainly videos with a few books) and Science Direct which has science books. Also I hear it looks good on a resume, IDK about that though, I haven't tried. It's helped me out because I'm really fucking bored this summer.
Just a bit of a protip for anyone who's a student and doesn't like pirating (or is too lazy to).
Anyway, on topic, I'm messing around with a cryptocurrency price guesser.

no python is an anti-language that gives you brainletitis.

I've played for acm in games of broomball.

>hackerrank.com/dashboard
thanks, will check out

yeah it's nice to write a script here and there or setup some kind of quit flask api thing. Theres really not much to learn if you come from another language lol

So what should be used instead of Python? Haskell?

if you like python syntax, nim.
if you want FP, Idris.

Trying to get a job. I miss working.

Attached: tables.png (2560x1320, 286K)

Who's the Cupcakke of the programming world?

Employed Haskell programmer reporting in

Attached: 1483073157801.jpg (1280x720, 110K)

Are you making embedded stuff for fax machines?

Attached: 1531141627731-c.png (510x690, 402K)

I'll keep powering through then.

Attached: 1514162516428.jpg (1270x1006, 163K)

It's weird, the company covers a lot of communication stuff, but I was mostly tasked on fax-software. It was used in weird ways, as a standalone sender/recorder, as a gateway between different communication standards (both analog and digital devices), and probably a few other kinds of software.

>thinking I'd do all that shit by hand
Work smarter not harder.

Attached: generator.png (2560x1440, 373K)

>Fax!

Attached: hqdefault.jpg (480x360, 16K)

This looks comfy.

Attached: 1528550414616-c.png (900x900, 277K)

yes

That was an earlier version of the code.

Attached: 2.png (2537x1242, 173K)

youtu.be/Q7GKmznaqsQ?t=45m19s
I'm quickly verifying this Jordan Memerson's claim about muh Pareto distribution.

As he claims, everybody starts with the same amount
People go around and "trade with everyone"
import numpy as np
import matplotlib.pyplot as plt
import random

nb_agents = 100
initial_money = 10
agents = initial_money * np.ones(nb_agents)
time = 0
fig,ax = plt.subplots()
plt.subplot(2,1,1)
while (agents.max() < nb_agents * initial_money): # until someone ends up with all the money
for i in range(nb_agents - 1): #Make everyone trade with everyone else
for j in range(i + 1,nb_agents):
if (agents[i] > 0 and agents[j] > 0): # Check both agents are still in the game
head_or_tail = random.choice([1,-1]) # if so, one agent gains $1 and the other loses it
agents[i] = agents[i] + head_or_tail
agents[j] = agents[j] - head_or_tail

plt.clf()
plt.subplot(2,1,1)
plt.plot(sorted(agents))
plt.subplot(2,1,2)
plt.hist(agents)
plt.pause(0.0001)
if (time < 10): #slower framerate display at the beginning
plt.pause(0.2)
elif (time < 100):
plt.pause(0.05)
if (time < 100):
time = time + 1
random.shuffle(agents) # Shuffle agents to randomize next step trading order


But this is nothing like what he shows.
I guess in his example, "everyone trades with everyone" but in a random manner maybe?
Anyway, no mention of the Pareto distribution in the original paper whatsoever
www2.physics.umd.edu/~yakovenk/econophysics/animation.html
www2.physics.umd.edu/~yakovenk/papers/EPJB-17-723-2000.pdf

Attached: memerson.jpg (1920x1080, 135K)

>company was working on 4-core 8-thread/core fax server

>they hand me a T1 card and say "we want to output data on this without using Freeswitch"
>mfw

Attached: Ai+wont+take+over+the+world+with+guns+and+explosions+_1fbc46360a7dd4daf0379167bce9de43.jpg (273x273, 37K)

>without using Freeswitch
but why?
Are they an in-house software only company or something?

I guess my mistake was to plot at every trading cycle rather than at every trade.

Damn, plotting in python is S L O W !!

Babysitting a bunch of government workers who shouldn't be this bad at development/security. Pretending I'm improving things.

Freeswitch may have been introducing excess latency for the specific application.

Additionally, these data lines were dedicated lines (1:1 with machine), so we didn't need intermediate routing/call handling structures, and the company is old enough they *have* pretty much the entire thing FreeSwitch could otherwise do for us (all the data setup/modulation stuff).

>library isn't compiling
>dig around trying to figure out what the fuck the error messages even implied, literally nothing to help online
>single update on gcc 5 update page: semantics are changed from C89 to C99, this syntax doesn't work anymore, compile with C89 or use this other flag if you need to

Attached: 1489098957846.png (575x446, 169K)

>it's another trying to look at your code for the first time after a break episode

Attached: 1526038832746.jpg (1252x1252, 111K)

How does one even begin writing software for embedded machines?

>comment out everything in chunks
>compile one at a time to refresh
ezpz

dumb frogposter

interesting, your job sounds like a nice mix between hectic and comfy. Besides having to use C that is.

lrn2comment

My code submissions were scrutinized (usually).

Attached: structs.png (1414x1106, 106K)

>having to use C
Any opportunity to use C is a privilege.

>multiline comments
>on a single line

any particular reason for this senpai?

perhaps he's stuck with ANSI C

You can clearly see // comments here and there

>be me
>for the first time ever have a real use case to build a mobile app (no experience w java or Obj-C)
>app is minimal really a mapmatching algorithm with a dash cam implementation run locally, so hitting sensor APIs and collecting video and map context.
>come to the conclusion learning and implementing a rather complex alg. in a new language would be much harder than doing the UI in a non-platform language. After all the UI is video preview with some text overlay.
>look into cross compiling either python or go to android
>try kivy, 3 days later hello world still doesn't build, tried everything ubuntu vm, read through probably 100s of github issues nothing, compiling x86 arch just shits the bed every fuckin time
>Look into writing that core alg. as a network daemon in go using gRPC, as thats something rather minimal that could be compiled into a java library.
>test a minimal implementation of a small library utilzing that would effectively be just my dependencies in go
>test library compiles
>"cool guess I'll build the location daemon then"
>build the daemon, compile the daemon, find that the structs are skull fucked due to unsigned integers / more abstract structs being omitted
>find out if a type isn't supported it just fails silently
>fuck it, fuck phones, fuck everything.

Why are phones just so shitty to develop for was it limitations at the time permeating through today? Gatekeeping development for some advantageous reason? I mean I understand why apple would do this I guess, and understand the need or desire for APIs to be locked down, but still.

oh, i'm a moron then.

its ok, you tried.

Any embedded machine will have "priority" tools. For Arduino/non-operating-system machines, you usually have a pile of libraries and/or tools which compile code to a binary, and you load the code file which properly initializes stuff. I believe often there's two softwares, the priority tool for coding, and the priority tool for loading, but for open-source or other platforms you work with their environment, and if the makers are jerkbags you can be SOL on different operating systems (our hardware lead worked on XP because many compilers we rarely used only worked last on XP).

For "operating system" types, it's not different from normal stuff. We worked cross-platform, on a ridiculous number of hardware configs, and with a well-defined behavior usually (fax, modems, telephony is all standardized), so C and not-using-libraries-unless-needed was best for performance and style reasons.

Hectic doesn't begin to describe half the shit I was doing.
>we need better backups, our current system kind of sucks
>slap together shit out of FreeNAS and rsnapshot which can ssh into a machine, load an SHA256 key into a newly generated user, set up the backup scheme, edit /etc/sudoers and other stuff to have a delta-based backup system where you can traverse each temporal backup as a normal directory while still only taking the size of the deltas to store

>debugging
>we have an issue, here's how it presents, here's where it might be
>go at it
FFFFFFFFFFF

>we have our config file, a grid-based text file thousands of lines long and 300 configurations wide
>I want some more information from it

>we have an auto-compiler for the Linux build server
>there's an unused windows server, go do it for windows

I honestly liked it, but they had... issues paying me on time, so I had to leave.

The codebase was ridiculously structured and big. // were filtered out if the code was sent to customers (a lot of other stuff happened too, like ifdef falses were entirely removed). /* */ were kept for customers. There was another comment style, which I think was multi-line comments that were pruned from customer releases.

It took me a day to get kivy compiling and everything. I just used their vm and had to mess around to get it to work. I think you still need to sign it though to get an app on the store. It's not something you can do in Java?

>trips into quads
clearly your experience speaks for itself. I nkew you had a good reason. sounds like a hassle.

>writing your own options file parser for Perl
Better, it can be used to set default values and refer to previously addressed data in the options file. Works with arrays and hashes, and is parsed like perl-text so it's consistent.

Attached: wew.png (1235x744, 55K)

How do you guys figure out what to work on after you have the basics of coding done? I know how to code, but all the things that I want to work on seem lightyears away from my current skill level.

Attached: 1528981621697-c.jpg (540x936, 154K)

just do them.
that's what i did.
people who waste their time on "beginner projects" seldom escape them or waste way too much time thinking they're "not ready" over and over.

Thats the first log trace I was getting, and it would also be like 15 minutes into the build. I looked everywhere for similar issues which did exist I'm tending to believe it has something to do with ssl certs in virtual box from what I've read but I have no idea. Its super annoying to debug though because there is almost nothing to change other than your environment, and it takes 15 mins to find out if it worked.

I couldn't get compiled to an apk for x86, all I wanted to do is see how easy the APIs are to use and kivy seemed pretty vetted. It could be done in android, but that would require learning it.


I also have quite of bit of libraries I've built for vector-tiles, mbtiles, and a ton of other stuff that I don't know if it exists in OS java. Thats the main reason I'm apprehensive because I have I'm using a lot of relatively new formats. I'm sure some libraries exist but its you know at least 50-100 hours from 0 java experience to where I need to be. This does have a real-time constraint as well so if I do things in a shit way it will matter.

Attached: Screen Shot 2018-07-30 at 12.22.49 AM.png (1674x656, 181K)

>How do you guys figure out what to work on after you have the basics of coding done?
Find someone who will tell you what to do and pay you to do it.

/wdg/ failed me so I figured I'd ask here.

How would I go about making this whole thing into a function that creates new controllable timers?


var seconds = 0;
var interval;
//when you want the timer to stop
var endTime = 55;

function checkTimer() {
if (seconds == endTime) {
restartPause();

}};

//reset timer
function restart() {
pause();
seconds = 0; interval = setInterval(function() {console.log(seconds); seconds++; checkTimer()}, 1000);
};

//pause timer
function pause() {
clearInterval(interval);
};

//play timer
function start() {
pause();
interval = setInterval(function() {console.log(seconds); seconds++; checkTimer()}, 1000);
};

//Restart and Pause, for when the video ends
function restartPause() {
restart();
pause();
};

function timeChange(n) {
seconds = n;
}

Say I wanted to make a bunch of timers like so


var myTimer = new timer();
var anotherTimer = new timer();
var thirdTimer = new timer();

Any help?

you're going about it wrong lad.
checkTimer,restart,pause,start,restartpause,timechange, all need to take a timer.

Install VS Code or VSCommunity.
but really if you're set on sepples, and on windows you may as well pirate the latest VS.
else the above two are on linux.
But you should also keep at C because it's gonna kick your ass even harder.

I'm a fucking idiot and I'll never be good
Why am I even bothering to try to learn how to be a good programmer.

Attached: 7bf6a8bc092cf2be51adda90554ec1da.jpg (500x681, 70K)

C++ is gonna kill your ass even harder and you should really understand the basics in C first*

i've been trying to learn since the age of 10

i am now 20 and i still can't do it lmao

Got my shit together just now and did it finally
Had to reason about it on pen and paper.
I realized that the steps thing wasn't actually clear to me.

The number you're given is actually the nth person in the circle to kill, so you skip n - 1 people and to get to the person you gotta kill you gotta do n - 1 steps... But I need to get to the person before, so i = 1; i < steps - 1 which looks awful I guess
What should I name the parameter instead of steps? I'd like giving it something meaningful and avoid any gay single letter name.


void josephus(struct node *head, int steps){
int i;
struct node *cycle = head, *toKill;

while(cycle->next != cycle){
for(i = 1; i < steps - 1; i++){
cycle = cycle->next;
}

toKill = cycle->next;
cycle->next = toKill->next;
cycle = toKill->next;
printf("%d killed.\n", toKill->data);
free(toKill);
}

printf("%d survives.\n", cycle->data);
free(cycle);
}

i was considering coming back to it later, as making the jump from babby's first python book to C feels like a mountain of difficulty t b h

what are the basics of c? i mean, i understand the babby stuff like arrays and loops, and a tiny bit of pointers
but C looks like it has a lot more low-level "basics" than i feel at i'm a level to deal with

C++ is about 9000lb of extra bullshit layered on top of C to make it "more accessible and extensible"
And if you understand exactly what you're doing, it's great
But if you don't, it's a fucking hellish nightmare that you can't ever escape, and every time you try to figure out a way to do "common simple task X" you will run through 82 different extremely overcomplicated, overengineered solutions, and you'll hate life.

Start with C.

>what are the basics of c?
everything in a c book besides maybe advanced macro autism.
bit stuff isn't that hard, even though you'll only be using it for bitmasking.
learncpp.com/cpp-tutorial/38-bitwise-operators/ may explain it better.
but you absolutely need to comprehend malloc,free, and memory management even though sepples deprecates free. because you'll need to understand destructors when coming to sepples.

also why does llvm even bother shipping windows binaries if there's no standard library that comes with it?

Felt the same way that you did for a while. Tried several times to learn it. I just ended up finding something that I wanted to do with programming and forced myself to learn everything I needed to do it.

The trick is don't keep jumping around only half completing things. See it all the way through even if it sucks.

It gets better. After I got through the Bullshit of C++, I understand what is going on at least half the time.

Attached: Ckya blyat anime edition.jpg (768x768, 88K)

comments, easy to understand function names and variables, rationale behind every function. if it is a monolithic function (usually because there is no part that could be used elsewhere), divide it into blocks and place comments there as if you were documenting a function.

In case your wondering it would be something like this without the vector and nicer looking. Its use case is relatively simple people in who work at the DOT where everything is off there datasets and MPs have no idea where they are in the field. Often times they use printouts of pdf maps, because lack of service.

Attached: ddc.webm (576x432, 2.84M)

How would you do this in Python?
Its lists aren't circular

Your code is slow because you're using nasty python for loops.
You are using numpy, try and reformulate your logic into something using np.array's and it will run faster than a native python for ().
Also you'd get faster results if you don't run your plot code every single iteration of that while loop, instead execute the while loop then plot it once at the end. And yeah no shit plotting will be slow if you pause.
And looks like you have written an O(n^2) algo anyway so it's gonna suck regardless.

Just trying to learn php in 2018.

the cover is pretty.

>but you absolutely need to comprehend malloc,free, and memory management
tfw I have no knowledge about memory management beside knowing recursive functions go on the stack, malloc space is allocated on the heap. And heap and stack are just words for me.

Any C++ wizards here?
I have a class that requires some processing to construct, but I'll know the exact instances I want at compile time.
Can I somehow use constexpr to do this processing at compile time? I'm too much of a brainlet to work out how.

Look at the C second edition book. I got up to chapter 6 before I stopped doing exercises, and switched to Perl because I was working mostly on interacting with the operating system and deciphering/editing text and some other stuff.

I have a lot more experience cross-platform, but I've gone C->Perl->llibraries/complicated includes/etc->makefiles (present). I'll get to more complicated object-orientation, but I'll always prefer to program in low-level brutality.

Attached: HONK.png (1333x1357, 154K)

>you'd get faster results if you don't run your plot code every single iteration
That's the goal, I want to display the evolution of what is happening,
I'm not against using vectorized code for fun, but it's rather spaghetti to make sure everyone plays with everyone else only once each loop without nested for loops.
The problem is n^2 by nature, how can I escape from it?

>That's the goal, I want to display the evolution of what is happening,
Save your data as you go along, then plot it all at the end.
Make a big array and store the state after each iteration, then do the plotting animation stuff last.

I feel like theres a very simple solution for what I'm trying to make, but I am just not aware of it.
I play online dnd with some friends and I wanted to make a script to take in player names and initiative roles and sort them in a neat list for my DM, but I cannot for the life of me figure out how to do that.
sorting a list of numbers is nothing, but keeping a character name string tied to each while sorting the numbers is somehow confusing as fuck to me.
I'm using python for clarity.

Attached: 1458960263596.png (142x173, 45K)

Why is that a good idea? The bottleneck is the animation frame rate.