/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread

Other urls found in this thread:

news.ycombinator.com/item?id=16427807
ats-lang.github.io/DOCUMENT/INT2PROGINATS/PDF/main.pdf
youtu.be/4oDLMs11Exs
youtube.com/watch?v=rX0ItVEVjHc
en.wikipedia.org/wiki/Iterator
diva.3dvrm.com/manual/database_3d_representation.htm
internals.rust-lang.org/t/how-should-we-talk-about-mutability/1882/4
twitter.com/SFWRedditImages

rust is for pure girls (male)

Reminder that C is obsolete and GC is for script kiddies. Rust has solved memory management.

>Affine types

Remember that Rust can't even handle mutable trees.

Was thinking about making a program to export passwords from FF, but it keeps crashing when I call NSS_Init().

I'm trying to code a list on phyton that generates a grade for each of the elements of the list but the fucking IDE won't stop crashing each time I try to compile , I'm using PyCharm

can you just go die in a corner or something

news.ycombinator.com/item?id=16427807

Rust shills are mental illness, as OpenBSD nobody care about your autism manager.

Rust has absolutely no way of talking about shared mutable state. It just delimits where it can occur.

well that's your problem

Use jupyter notebooks or a text editor like sublime.

preferrably inside a virtual environment (venv)

stop arguing over C and rust
thanks

>Rust
You mean ATS.
ats-lang.github.io/DOCUMENT/INT2PROGINATS/PDF/main.pdf

I'm just learning Java.
How do I prompt a user to input an operator, such as "+" and "-" ? I'm attempting to make a calculator.
I use "char", right?

def addGrade(self):
gra = int (self.grade.text())
self.grades.append(gra)
self.grade.setText("")
print (f"Saved grades: " {self.grades}")

this is the code I'm using for a button that saves the grades, it crashes after I push it , don't know why

Circlejerking aside, there are certain languages that you need to know or you won't be taken seriously as a developer. If you don't know C++, you won't get hired at AAA game studios. If you don't know Java, you won't get hired at Amazon. If you don't know JavaScript, you won't get hired at a web shop, even one where they use something else like TypeScript instead of writing JavaScript directly.
Python is like this. Go is like this. Even PHP and Ruby are like this in some places. But there is no company in the world that would refuse to hire you because you lack experience with Haskell, Ocaml, Scheme, or Rust. That is what makes them meme languages.

>As we will explain below, the algorithm of Wang and Yu can be used to create files of arbitrary length that have identical MD5 hashes, and that differ only in 128 bytes somewhere in the middle of the file.
Fuck me, I knew MD5 was broken but I didn't think it was that broken.

Good luck pahjit

I doubt Jane Street would hire you without OCaml experience.

have you tried debugging? Or maybe just running the commands interactively in IPython (or jupyter)

>if you don't know [mediocre shitlang], you won't get hired at places with piles of [mediocre shitlang] code to maintain
Woah. Really makes you think. Now, don't you have some COBOL code to fix?

If you are master on algortihms and mathematics learn OCAML begins easy.

That's beside the point. JavaScript, Python, and Go are also easy to learn.

run the debugger, python doesn't compile it's interpreted, if it's crashing when you hit run you program is throwing an error.

>gra = int (self.grade.text())
this looks unsafe as fuck unless whatever your text() function is has some validator that forces it to be a number

Sure, most companies are using mainstream languages like you have listed. But many companies, particularly very large companies, have internal divisions or project teams working with languages like Haskell. You can bet that you would never get *those* jobs without significant experience in the languages they use. And you can also bet that they are well paid, and you'd be less likely to have a shitty manager breathing down your neck.

Brainlet and Python noob here.

import networkx as nx

G = nx.DiGraph()
nodes_lista = [
("A", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 3}),
("B", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 4}),
("C", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 2}),
("D", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 5}),
("E", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 1}),
("F", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 2}),
("G", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 4}),
("H", {"es": 0, "ls": 0, "ef": 0, "lf": 0, "dur": 3})
]

elist = [("A", "B"), ("A", "C"), ("B", "D"), ("C", "E"), ("C", "F"), ("D", "G"), ("E", "G"), ("G", "H"), ("F", "H")]

G.add_edges_from(elist)

can anyone help me define a forward() function to do the forward traverse on my graph? So that the traverse updates the values of edges attributes, (es, ls, ef, lf).
(similarly a backwards() function)

Thanks a lot for any ideas.

>embedded market
Im a freshman in EE and embedded is one of the master level courses here. Iv been thinking about how to structure my studies so is embedded actually a good option for longterm monetarywise? It is interesting based off few courses.

I wonder how it stands up to RF related fields

Forgot to mention, I am supposed to implement the whole Critical Path Method.
I'm following this video:
>youtu.be/4oDLMs11Exs

hello underage
by prompt you mean tell?
just print "Enter + or -: " before calling the input method

>If you don't know C++, you won't get hired at AAA game studios.
youtube.com/watch?v=rX0ItVEVjHc
Cppcon talk by a guy who practically doesn't use C++ outside of in name. Just the list of things he brought up as things they don't use:
Exceptions
Templates
Iostream
Multiple inheritance
Operator overloading (with exceptions)
RTTI
STL
Virtual

And note. This was in 2014, so that's with regards to C++11.
I don't think this guy 'knows' C++ in any real way. He was asked what he's looking forward to in C++14 and he didn't even know, at the Cppcon conference. It was pretty funny.

But it's also true that he also said that they use ~70% C++ across all tools and the engine. So maybe this is a narrow view and he's thinking about the experts at the company and they have large chunks of 'actual' C++.
Maybe 'knowing C++' means something completely different than what general C++ knowers would think of it.
>Java
>Amazon
Really? Hadn't heard of that one.
>But there is no company in the world that would refuse to hire you because you lack experience with Haskell, Ocaml, Scheme, or Rust.
For Ocaml I'm certain there's companies that absolutely require it. Same with Scheme. But these are probably maintenance/extension jobs. Like with Cobol.
Rust is too new for this to be judged like this. If you want to look at commercial failures there's plenty of them.

Don't ask Sup Forums, ask industry.

he's asking about how to receive the correct values from the input prompt, don't be rude if you have no clue

This is what I have.


import java.util.Scanner;

public class Testprogram

{
public static void main (String[] args)
{
double userValue;
double userValue2;
double addition;
double subtraction;
double multiplication;
double division;
double percent;

Scanner keyboard = new Scanner(System.in);

System.out.println("Please enter a number.");
userValue = keyboard.nextDouble();
System.out.println("Please enter a second number.");
userValue2 = keyboard.nextDouble();


if (userValue2 == 0)
{
System.out.println("Can not divide by zero.");
System.out.println("Enter a number other than zero and run again");
}
else

{
addition = userValue + userValue2;
System.out.println(userValue + " + " + userValue2 + " = " + addition );
subtraction = userValue - userValue2;
System.out.println(userValue + " - " + userValue2 + " = " + subtraction );
multiplication = userValue * userValue2;
System.out.println(userValue + " * " + userValue2 + " = " + multiplication );
division = userValue / userValue2;
System.out.println(userValue + " / " + userValue2 + " = " + division );
percent = userValue * userValue2 * .1;
System.out.println(userValue + " % " + userValue2 + " = " + percent );



}

}
}


Instead of having to hard code the operators myself, I want to have the user input their values and their operator and then have the program compute their problem. I think I have it figured out though.

I mean, the syntax is bollocks, the standard library is unreadable, the error messages are even worse, there is no documentation on anything, what little there is is high-level, formal treatises...
Honestly, I wish the chink could gather more people to solve these issues, instead of answering questions, piecemeal, in mailing lists.

code tags are a thing, read the sticky
use a switch and have the input(the operator) be the condition
and just keep it as a char

Yes what you want is
char userOperator = keyboard.next().charAt(0);
That swallows the entire string they input and gives you back the first (0th) character. Which is the operator if they put it there.
You can then do
switch (userOperator) {
case '+':
addition = userValue + userValue2;
System.out.println(userValue + " + " + userValue2 + " = " + addition );
break;
case '-':
subtraction = userValue - userValue2;
System.out.println(userValue + " + " + userValue2 + " = " + subtraction );
break;
case '*':
multiplication = userValue * userValue2;
System.out.println(userValue + " * " + userValue2 + " = " + multiplication );
break;
default:
System.out.println("Invalid operator"); //This happens if it isn't +, - or *
break;
}

why does it say it's the wrong version when clearly it's seems to be the right version?

>entire string they input
No sorry. The next token.

how does an iterator make a linked list more efficient?

l

fucking shills who suck big black cocks admit it , what a bunch of faggots

and here's some code
switch(keyboard.next().charAt(0))
{
case "+":
addition = userValue + userValue2;
System.out.println(userValue + " + " + userValue2 + " = " + addition );
case "-":
//and so on
}

I see no reason why it would if you haven't changed the underlying representation.

apparently it makes insert or get O(1), im confused on iterators in general. I have to use it for my data structures project

An iterator into a linked list is roughly a pointer to a node. If you just have an index i into a list, it requires i operations just to get to the node you want to work with. If you're e.g. iterating through the list front to back, it's much faster to use an iterator, "remembering" where you were from the last iteration, than to index from the beginning each iteration.

I'm no CS guy, but I guess that makes sense? If it has a list of pointers to each element then it doesn't have to traverse the list itself to get or ass.

Thanks, anons.

I think you're very confused on iterators.
en.wikipedia.org/wiki/Iterator
In short it's just a way to say 'next' or 'previous' more abstractly.
>If it has a list of pointers to each element
Well an iterator could have this. But it's certainly a special case. To create this iterator for a linked list you would have to traverse the entire linked list.
You'll also be storing all the pointers. So it's starting to look less like a linked list and more like a vector/dynamic array of pointers pointing to elements of a linked list.

And yes that would be more efficient a lot of the time. But if you wanted this I don't think you wanted a linked list in the first place. Sounds more appropriate to use something like the C++ deque (I don't know what the general name is, refer to pic). I'm not sure if C++ deque is defined to be this or if it's just the common implementation.

>So it's starting to look less like a linked list
Sorry, iterator instead of linked list.

I asked this before in autistic way but here goes it:
I want to avoid having two key-value hash collections O(1) that are the reverse of each other and iterating everytime is not a proper solution.
e.g:
fcollection[x] =y;
scollection[y] = x;

Another way to think of an iterator is that it's like an index that lets you get the element in constant time, but you can also increment it. For a doubly linked list, you'd also be able to decrement it. For an array list, it's indeed the same as an index because lookup is already constant, so you can also do arbitrary arithmetic on it. For tree or graph structures, indices are not just integers, but iterators are still very basic and support operations that let you move along edges.

I want to add that I can't do this either:
y.key = x;

>an iterator is like an index that lets you get the element in constant time
If all you want is the next element.
I don't find this helpful to anyone.
Iterators alone have nothing to do with constant time.

You want a bi-directional map.

No, the current element. And I disagree, iterators have everything to do with constant time operations. Every iterator provides constant time access to its current element. Singly linked list iterators provide constant time access to the next node. Doubly linked list iterators provide constant time access to the previous and next nodes. And so on. Any non-constant time operation can be derived from the primitive operations of the iterator.

could someone tell me what's wrong with this diffuse shader? i know it's terrible but

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(binding = 1) uniform modelUniform {
mat4 model;
mat4 normalMat;
} mu;

layout(binding = 3) uniform Light {
vec3 position;
vec3 intensities;
} light;

layout(location = 0) in vec3 fragNormal;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 2) in vec3 fragVert;

layout(location = 0) out vec4 outColor;

layout(binding = 2) uniform sampler2D texSampler;

void main() {
vec3 normal = normalize(vec3(mu.normalMat * vec4(fragNormal, 1)));
vec3 fragPosition = vec3(mu.model * vec4(fragVert, 1));
vec3 surfaceToLight = light.position - fragPosition;
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal));
brightness = clamp(brightness, 0.0, 1.0);
vec4 surfaceColor = texture(texSampler, fragTexCoord);
outColor = vec4(brightness * light.intensities * surfaceColor.rgb, surfaceColor.a);
}


pic related. it's missing the blue colours.
I've checked my uniforms I know they're correct.

Matlab is the most powerful language. Prove me wrong

pro tip
[spoiler]you can't[/spoiler]

Probably you have no blue light. Or maybe your texture loading is wrong.

texture loading worked fine before I changed the fragment shader
light.intensities is (1, 1, 1)- should have blue light.

So that is what it is called! Thanks but the implementation is either O(n) for iterating over values of one collection or just two collections like I am doing that double the size of the program.

What was the original fragment shader? Is that the only thing you changed? Do you know for sure that the shader gets (1,1,1) for the light colour (to check, just output vec4(light.intensities, 1) or something)?

>Rust has solved memory management.
By rejecting programs that hurt its fee-fees?
>WAAAAAAH YOU'RE CREATING MULTIPLE MUTABLE REFERENCES WAAAAAAAAAAAHHHH THAT'S TOO HARD FOR ME WAAAAAAAAAAAAAAHHHHHHH WHAT ARE ATOMICS?
Rust is for retards.

Well since you've scoured the entire web now. I should suggest you write a perfect hash generator that finds hashes that collides each of your value pairs.
It won't be feasible to do dynamically but at least it's something right?

Convince me to learn RUST anons.
and stop learn javascript

I checked the uniforms with renderDoc. light.intensities is definitely (1,1,1)
the original fragment shader was just outColor = texture(texSampler, fragTexCoord);
i'll check it now for you though, just to be 100% sure

thanks for the help btw

>WAAAAAAAAAAAAAAHHHHHHH WHAT ARE ATOMICS?
Atomic operations work on any reference. Unfortunately, "unique" was called "mutable" and "shared" was called "immutable" when that's not always the case case.

what's in light.intensities? My guess is that it's {val,val,0} coming in, and masks the blue color.

>unfortunately
Why would they do that? Sounds like a blunder you hotfix frankly.

Are there any database guis that can also visualize databases like this: diva.3dvrm.com/manual/database_3d_representation.htm but also let you edit the data on the fly?

I'm trying to replace a bloated excel sheet at our job that basically stores

name|number|anothernumber|one of 4 variables|comments
name|number|anothernumber|one of 4 variables|comments
name|number|anothernumber|one of 4 variables|comments
etc about 120 times to represent physical items we carry in storage
our excel sheet has little popup windows to log in and update status and saves logs of who updated what and when. Its also used for filtering based on variables and printing a quick rundown of what needs to be done that day.
Anything open source / not too expensive that could do this? I have some lunix admin / webdev / server experience but im retarded when it comes to programming outside of excel cells.

So far I've looked into:
old DOS item management software
all open source IT item management software (typically client/server type)
all IBM products
emacs / orgmode
github with issues as "items" and labels as statuses
all git based IT software (atlassian etc)
microsoft products
open source products
etc

I'm just about ready to give up and pay someone to write it in C or something because of how specific it is, im suprised nothing on the web seems to fit the niche

Basically, the only thing in the shader itself that's suspect is light.intensities * surfaceColor.rgb. So somewhere in the process of uploading the uniform and texture, blue is getting lost. Maybe some undefined behaviour somehow causing RenderDoc to say you have the right thing but the results not matching? Throw me a bone here, try outputting just light.intensities.

Yes, OpenGL can really be this finicky and unpredictable.

welp you guys were right, just didn't read properly in renderdoc. thanks
I'll never say "i checked my uniforms" again

output of outColor = vec4(light.intensities, 1)

There you go. Personally, I tend to stay away from tools like RenderDoc and prefer to do debugging right in the shader. It's a lot harder to misinterpret the results!

you want what is called an inventory management system. search for that and see what comes up.

thanks

yeah ive looked at those as well, the problem is they all look like pic related with all these useless variables, our software needs to be as simple as possible so that other people could use it effortlessly
all those programs that show up when you search that have hardcoded variables that are specific to store / warehouse scenarios and we dont need any of that, and most of them you cant modify or if you can it would be too much work and time wasted

internals.rust-lang.org/t/how-should-we-talk-about-mutability/1882/4
The language team prefers to lie first and correct the record later. They don't even have to change the language, it's purely a documentation and diagnostic issue. "&mut" really does imply mutation, whereas "&" doesn't explicitly forbid it.

>uses Indian address in example
You can't make it up.

Yup, that's what they look like.

You get that, or you get unreliable bullshit.

Maybe write a django application :^^)

rust is just javascript with annoying seatbelts
you dont wear seatbelts do you user

Wearing seatbelts is important.
Just not when you're out of the car.

Does anybody have that copypasta of programming job interviewees where the guy compares a fizzbuzz to asking a potential piano player to point to the piano in the room?

That might be it actually. No way I can make hash collisions but I can do something like this:
spCollection.push_pair(x, y);

Where spCollection uses a small size hash function for both x and y used for:
x hash -> y
spCollection.getValue(x);
y hash -> x
spCollection.getKey(y);

x is small and under my control but y is fucking heavy and I get it using a shitty API(otherwise I'd add y.key)
Basically ~8-12 bytes extra for every pair(I have dozens but that shouldn't affect the program like having the two collections)
Thanks for your help!

but rust see more friendly, right?

Reminder that if you don't use Rust, you are incompetent. Naziboo ideology is not an excuse. If you can't put up with not insulting trans people, don't bother getting out of your basement and showing up for a job interview.

>his supposedly "safe" "systems" language doesn't even have temporal types

rust : for objects instead of =, its javascript

I'm working on my mpd client. It already supports autistic ricing via scripts (scheme) and format strings, but the UI layout isn't customizable at all. So I'm building a generic ncurses widget library that will be able to load UI definitions (as SEXPRs) at run time.

I don't understand what you're suggesting. Sounds just like the original idea to me.
I'm curious now.

Python question:

I have the following code, it works fine:

file = open('config.json', 'r')
user_config = json.loads(file.read())
is_sound_desired = user_config["Audio"]["On"]

I want to wrap my configuration in a class so I can add some simple read/write get/set functions. So the above becomes:

config_manager = ConfigurationManager('config.json')
is_sound_desired = config_manager.get_config(["Audio"]["On"])
# Also a setter
config_manager.set_config(["Audio"]["On"], is_sound_desired)

I don't know what to put in get/set so that this works. Any help or more Python idiomatic ways to do this?

Not a python expert but if you create def __getitem__(self, key): ...
You can do
config_manager["Audio"]["On"]
To access values in a managed way (return default when value is missing for instance) and
config_manager["Audio"]["On"] = is_sound_desired
To set values.
You can overload __setattr__ i believe to get control over the behavior when you assign.

I don't think you could put the [][] as arguments to functions in python.

If you're going to know exactly what fields are going to be in your configuration, what you probably want is an audio field in the config manager, so you can do something like:
if config_manager.audio:
do_audio()


The proposed syntax for getting you wrote is a little wonky, not sure if typo or you're not sure how Python works. If you do want a getter that gets arbitrary fields, you'd probably want to just keep the JSON parsed into a dict as a field inside your manager, pass a string into get_config, and have it just look it up in the dict.

Work sucked today. I work for the government and we have a big database that tracks people who have committed fraud. A long time ago they hired some pajeet to maintain the software for it. She's been maintaining it solo for years, but they brought me on to assist her. I'm quickly discovering that the whole thing is fucked. So many people wrongly marked for fraud and so many fraudsters shown as having a clean record.

I'm also slowly learning that the support staff (a team of 8 people) is supposed to help with resolving issues like someone fat-fingering a name or address and other one offs like that. Instead, 95% of the issues they've been resolving have nothing to do with any of that. It's all been issues caused by software bugs. And because they were software bugs and the data associations aren't correct; they have to redo much of that work. Think about this for a second. One fat, curry stinking, poor excuse of a "software engineer" has screwed up years worth of data, potentially fucked thousands of out jobs because they wrongly show up as fraudsters, and had a team of 8 people whose main job it was to try to do damage control, which in the end, wound up not being effective.

We had a meeting about it today. She was in the room so nobody really blamed her directly. Instead, everyone just pretended it is a tough engineering problem to solve and that there isn't really an ideal solution. It was not a hard problem to solve at all. Any idiot who spent more than 2 minutes running SQL queries could see whether the software was putting out sane data or not. But now, it's an almost impossible problem to solve because the original sources of data no longer exist because our system is supposed to be the official archive. The frustrating part is that management shows no indication of letting her go. She'll likely keep her job.

I'm rewriting systemd in Rust.

please don't tell me that's the US government
I wouldn't be surprised though

Good thing I'll never use either.

I'm new to Python. But the config file is huge and writing out all of that if x.audio do_audio boilerplate would be huge and unmaintainable.

I want a single get/set that allows me to access anything, even new config items.

I'm going to look into this, but I've notice some meta tags missing as I'm deploying on an embedded system missing many libs. For example __subclasses__ was unavailable.

>implying your story is real
>implying you wouldn't have done even worse

Why is really simple stuff left undone in compilers when a new standard rolls out? I've seen this stuff happen before in C++11/14 and I never been able to figure this out...

Because writing a compiler takes time.

I want to write a c compiler for the fuck of it. Any good resources?