/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1554683874599.jpg (1280x720, 462K)

Other urls found in this thread:

bitbucket.org/chromiumembedded/cef/src/master/
skia.org/
duktape.org/.
khronos.org/opengl/wiki/Data_Type_(GLSL)#Scalars)
khronos.org/opengl/wiki/GLSL_:_common_mistakes#glGetUniformLocation_and_glGetActiveUniform
geomalgorithms.com/a05-_intersect-1.html
comp.nus.edu.sg/~cs1101s/sicp/
comp.nus.edu.sg/~cs1101s/sicp/chapters/71
pastebin.com/rgrxtYkB
twitter.com/NSFWRedditGif

Thinking about certain exercise from csapp.

Trying to learn state management for Flutter development. BLoC pattern, to be more exact.

It's okay, user. Let me show you how it's done in JavaScript!

Attached: DoqID98UYAAJi5v.jpg orig.jpg (1126x1432, 198K)

thinking of user

Working through Programming Princiles and Practice using C++ by Stroustrup, and stuck (again) on one of the exercises.
Supposed to make a game bulls and cows, where you enter a 4 digit number, and the game comes up with a random one, and if you have the right digit in the right position it's a 'bull', and the right digit in the wrong position is a 'cow'. Each turn it tells you how many 'bulls' and ow many 'cows' you have. I have it mostly working, but I can't figure out how to have it only count non bulls as cows. Also it counts some 'cows' multiple times. Only think I can come up with is maybe making a vector of bools same size as my other vectors and marking a place out each time a 'bull' or 'cow' is found, but that seems overly complicated.
bool bulls_and_cows(vector guess, vector comp)
{
int bulls(0), cows(0);
for (int i=0; i

Anyone here has experience with compilers?

If I have a
NOT [expression]
and a
[expression] AND [expression]
rule

how do I force it to evaluate
NOT x AND y
as
(NOT x) AND y
and not
NOT (x AND y)

Specifically in bisonc++

You're looking for operator precedence.

I am isolating components of the Blink engine to create a standalone project.. Its a challenge but if I can get it done, the results will be amazing

is this what you're trying to achieve?
bitbucket.org/chromiumembedded/cef/src/master/

I was a doofus, NOT has to be at the bottom of the precedence list, not the top
I even had a college class about this, then again I got a D

Thanks for the answer anyway

Not really. I am trying to isolate the graphics portion of the canvas API in order to create a standalone framework which has the same Javacript API but it doesnt have all the blink baggage.. essentially I want to be able to make Javascript games with webgl or 2d canvas without having the entire Blink render process if that makes sense. My focus is getting it to run on mobile.

That sounds like a lot of effort, have you considered just using any of the lightweight frameworks like Love2D? Or even making one yourself with skia.org/ and duktape.org/.

I want to write a simple graphics editor (aka a meme editor) so I don't have to open Gimp every time I need to quickly edit some image.
It will be controlled by mousewheel, vi-like keyboard shortcuts and commands. So that most of it's interface don't require GUI elements except for the drawing canvas.
Can you recommend a good widget toolkit for that, anons? I feel like GTK and Qt are too much for this.
Or maybe I could just use something like imlib2, which is used by feh?

Attached: 1548951511566-g.jpg (400x400, 19K)

>It will be controlled by mousewheel, vi-like keyboard shortcuts and commands. So that most of it's interface don't require GUI elements except for the drawing canvas.
If you don't actually need fancy GUI widgets then do it low level with OpenGL.

Any OpenGL fags here? How come this doesn't work, I have this vertex shader:
#version 330 core

uniform vec2 position;

void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}


And this fragment shader:
#version 330 core

uniform vec4 color;
uniform float timer;

void main()
{
gl_FragColor = color;
}


When I do this:
GLuint attr_position = glGetUniformLocation(program, "position");
GLuint attr_color = glGetUniformLocation(program, "color");
GLuint attr_timer = glGetUniformLocation(program, "timer");


I always get -1 for the timer no matter what I try, whereas position and color always get the correct location. What gives?

Any anons want to stick their massive data into my large heap

It is and I know there are a ton of game engines already but there really isnt a solution to make JS games that run at native speeds in mobile. They all have the browser baggage which slows them down a lot especially if we are talking 3d. I want to make it into a React native component. Imagine how amazing it would be to create a JS game and then have it run natively on both IOS and Android. I would be churning out more shitty games than a Unity monkey ever could. Plus it would lend itself to things like being able to have one app that runs multiple games that you download from the network.

Do you know that the canvas API uses the Skia library under the hood?

Say I'm doing an exercise that involves writing several implementations of the same header file. This causes problems because now I've got multiple definitions of the same functions. I could use comments, of course, but that's a PITA and I know there's got to be a better way.

I'd want to use pre-processors and macros, right? I can't quite figure it out. I'm currently working in C, btw.

Attached: african-american-computer-genius-close-up-young-man-coding-his-gray-laptop-concept-mock-up-83722795. (1300x957, 109K)

You would just instantly segfault ;)

Attached: 1528156971140.gif (540x603, 188K)

That's why I was hinting at Love2D, it's written in C, is really performant and works just fine on mobile if you build it targetting the mobile platforms. You can also link it with LuaJIT which will yield you great performance (many tasks will be even faster than you'd get from JS + V8 from Chrome).
As far as the question goes, I know that Canvas uses the Blink renderer which in turn is based on Skia so I'd assume the answer is yes.

Nevermind, I figured it out.

#define Switch
#ifndef Switch

...

#endif

Python friends, is Click the best option for developing a complex CLI?
I like the ability to specify file existence checks through a path, but would be even happier if I could verify file extension at the same time.
Is that possible (solely through Click)?

Should it be a GLfloat?

Sweet! That's just what I need, thanks fren!

Attached: 1500861326882.jpg (1000x800, 301K)

Nah, it's not the type of the variable, it just returns the index of the variable in the shader layout, so I should be getting 0, 1, 2, but instead I get 0, 1, -1. I read you can manually specify layout locations in the shader and then just refer to those but it seems counterproductive because then you have magic numbers that you have to keep in sync between your shader and your C code - which is already achieved by retrieving the uniform locations.

Trying to get into NASM and Assembly:
;Why is this legal:
mov eax, Variable
;But not
mov Variable, eax
mov al, eax

I should have been more clear. I meant the type of timer, does it have to be a GLfloat to get the program to properly pick it up?

No, GLfloat is just a typedef for the C API, in GLSL it's just float (khronos.org/opengl/wiki/Data_Type_(GLSL)#Scalars)

khronos.org/opengl/wiki/GLSL_:_common_mistakes#glGetUniformLocation_and_glGetActiveUniform

My negro, thanks a bunch, that must be it, gonna use the timer in the shader somewhere to test it out. Thanks a bunch.

reminder to read a lot of books

hot

I'm new to Linux in general. There's a firmware for a certain device that I need to build using make. Is there a way to check if the code is valid without rebuilding everything when I change just two lines of code? Up until a few hours ago I could just do make and it would do a quick build, now it just says "all is up to date" and I need to run make --B in order to get it to build, but it takes a few minutes

What's the point of a java backend when I could just use PHP?

If you're making changes to a .h file you'll have to do an entire rebuild every time, if to .c files then you should be able to only rebuild the relevant parts.

????

?

I mean java servlets. I could do all of this server-side stuff in PHP/JavaScript.

What's the point of a java backend when every nonmeme company backend is written in C++?

>C++
>webdev
doubt

declaring the position attrib AS uniform makes Not much sense. what are you trying to so?

> A very weird bug in the GUI that's causing 2 items from JComboBox to merge together
> Spent half an hour figuring out what's wrong
> Runs the program in Debug mode
> Works perfectly
> Runs it again
> Works perfectly

What in the world

Attached: Warehouse.png (264x225, 4K)

Big amount of backends is written in C++, i.e. facebook, amazon, google.

Facebook uses php

And I think Google uses Python

My next project is I’m going to turn TFL into something resembling actual maths. Is having an if on the end bad? It’s not something you see in normal langs but it’s how mathers do it.
f(x) = 0 if x < -5

Attached: B48C79BB-0E5C-4850-8E6C-B7AFD9A30F3E.jpg (837x360, 24K)

some kind of build caching fuck up?

Trying to learn some OpenGL basics but it's pretty confusing. What should I use instead? I've seen it being used as attribute rather than uniform but I don't get the difference.

Attached: 40CABB95-E9F0-46B5-950D-BDD6C6ADFE04.jpg (604x453, 45K)

The changes are to a .c file

Go for it bro

Then you shouldn't have to rebuild the entire source base. Not sure what's happening, is your clock set properly? I remember having an issue with CMake where it wouldn't pick up changes and I had to also force rebuild when my system clock was fucked. I know this is a bit anecdotal but I can't think of anything else.

It's true though.

Attached: Dw_YStdV4AAC0Nl.jpg (189x200, 6K)

google declaring vars as attribute or in and how to upload vertex data to your gpu

But the position here isn't meant to be the vertex data but where it's supposed to be translated to on the screen. I figured it'd be easier than the projection matrix fuckery.

I'm at my wit's end here. I need an algorithm to check if the green line crosses between the blue circles (or vice-versa). I've tried every damn thing I could think of. I checked the angles, if one is between the other(this breaks when the angle crosses over 180°), I tried a line that goes to a point to the other and checks if it crosses (this one breaks when the line is vertical: a->inf), I've tried changing coordinate systems to a rotated one to avoid that and that one is just plain wrong. Why is something so simple so complicated?

Attached: untitled10.png (560x420, 8K)

This makes sense, but the specific file I'm editing shows as having its last edit done right now, which is when I changed something and saved it. What date/time does make check against?

doesnt matter. Uniforms are constant for the whole render pass. you need attributes for each Vertex Position

You need to find intersection between a line and a segment?

I'll read up more, it's still super confusing, I don't even understand VAOs at all, some people just say "just do it and don't think about it lmao", and some explain it in the most convoluted way.

Yes. Without bugs, preferably. I've made a few that work almost well, but break down depending on the angle or the position of the points.

geomalgorithms.com/a05-_intersect-1.html

computational geometry is a qt tbqh

#pragma once
if you bad

Hehe. Try first to understand how Vertex Buffer objects work and dont mix them up with Vertex Array objects

There was an "all" file inside the build folder, once I deleted it make stopped saying "all is up to date". What the hell?

>doing the make pong meme

Attached: 40a59cfdf7670c5ab0c7b5babbfdec53.png (139x333, 138K)

convert the circles to equations and then solve for intersections?

Oh, no, the circles are just endpoints. I'm trying right now. Not looking too good at the moment, I'm rechecking to see if everything is correct, but I'm losing hope right now. It's looking like this:
function s = inter2(Po, P1, Qo, Q1)
U = P1-Po;
V = Q1-Qo;
Ut = U; Ut(1)=-Ut(1);
Vt = V; Vt(1)=-Vt(1);
if(dot(Ut,V)==0)
s = 0;
else
W = Po-Qo;
sx = (-dot(Vt,W)/dot(Vt,U));
s = (sx>0) && (sx

Attached: untitled11.png (560x420, 8K)

C question. Using tcsetpgrp works fine for bringing processes to the foreground in my homemade shell. All process except tui ones like Vim, nano, man. Any idea why? On my phone rn so sadly can't provide code

>this breaks when the angle crosses over 180°
how do you calculate the angle, do you use arctan?
if so try sign(y)*arccos(x/sqrt(x^2+y^2))

Need help with Prolog here.
I'm trying to write a simple parser like this
prog_head --> [program], id, ['('], [input], [','], [output], [')'], [';'].
id --> [a]|[b]|[c].

This only returns true if id is either a, b or c. How do I make it so that any string that starts with alphabetic character is accepted?

Because Variable is a symbol, and "mov eax, Variable" actually transfers the address of Variable into eax, not its value. On the other hand, you can't transfer the contents of eax into a symbol, that would be like doing "42 = a;" in C.

I want to read SICP because I'm really getting into software composition but don't want to read a book written in Scheme. Would reading this Javascript version basically be the same thing?

comp.nus.edu.sg/~cs1101s/sicp/

It's supposed to be a direct adaptation.

Attached: 142F2CAF-FD50-4D7B-A7D7-0984CEC4A8E0.png (168x168, 11K)

Ut = U; Ut(1)=-Ut(1);
I don't really remember matlab, but isn't it just making a vector (Ux, -Uy)? The orthogonal vector to U is (-Uy, Ux), coordinates are swapped.

I used atan2(delta_y, delta_x), I'll try yours. The problem I had was that when the upper limit for the arc was at 180° and the lower limit was at the third quadrant, then this second limit would give me a negative angle, and the function I was using would not know the angle was in fact just near each other. I though I had solved this using
(pi - abs(abs(a1 - a2) - pi)) > (pi - abs(abs(a1 - b) - pi));

(found it on the internet), and it seemed to work well enough for some angles I made up by hand, but didn't work very well, I guess. It has the tendency to flag angles that are just near each other, for some reason. If not for that, it would be the best one I've tried yet. Unfortunately, since it flags every angle that are a near miss, it's completely useless. Pic related.

Attached: untitled12.png (560x420, 8K)

Toughest course i ever did was on comp. geometry. No programming, just math and proofs. Was hard as fuck

you can google any geometric intersection and find the formula and write that as code verbatim and it will work
why do you need to ask for help

comp.nus.edu.sg/~cs1101s/sicp/chapters/71
It looks kind of the same, seems to be missing chapter 5 though.

You are completely right. I somehow misread one the site you linked. I thought it was (-Ux, Uy). Still not right, although the flags are all in the same quadrant now. Unless I fucked up somewhere else again (too)?
function s = inter2(Po, P1, Qo, Q1)
U = P1-Po;
V = Q1-Qo;
Ut = [-U(2); U(1)];
Vt = [-V(2); V(1)];
if(dot(Ut,V)==0)
s = 0;
else
W = Po-Qo;
sx = (-dot(Vt,W)/dot(Vt,U))
s = (sx>0) && (sx

Attached: untitled13.png (560x420, 8K)

I don't know if you're checking the right parameter for being in [0;1]. sx is the one for the line segment between the circles, right?

It seems so. Working much better now, but also suffering from near misses like . Pic related.
function t = inter2(Po, P1, Qo, Q1)
U = P1-Po;
V = Q1-Qo;
Ut = [-U(2); U(1)];
Vt = [-V(2); V(1)];
if(dot(Ut,V)==0)
s = 0;
else
W = Po-Qo;
t1 = (-dot(Ut,W)/dot(Ut,V));
t = (t1>0) && (t1

Attached: untitled14.png (560x420, 9K)

Update: there was a minus there that shouldn't be. Working perfectly now. Post bitcoin wallet for me to send meme rewards.

Plot the resulting intersection point. Also, maybe where you plotted your circles might be inaccurate.

Oh, okay then. I'm actually not the user who linked the site to you.

Oh, man, this is so beautiful. I've been trying to fix this piece of shit code since sunday. Now I just gotta make it not take fucking 5 minutes to run on 50 elements so I can run it on the real thing with 14000 elements. Things are looking bright! Thanks for the anons who helped!

Attached: untitled15.png (560x420, 41K)

Is there a book that I can read cover to cover to learn c++? The problem is that I'm not a beginner and I don't really want a book that goes into explaining every programming concept in detail.
I don't have a specific goal other than learning the language itself so I want a book were it has cool examples and maybe exercises.
I find reference books useless since google is a thing but I don't mind having info if it is in a format where I can ignore what I'm already very familiar with.

>The problem I had was that when the upper limit for the arc was at 180° and the lower limit was at the third quadrant
that's exactly what this specific function fixes.

Check this out. Check this out and cry of joy! I'll even pretend I didn't see that misflagged nigger #36 there so I can keep living my life without danger of suicide.

It's probably a mistake on another part of the code though.

Attached: untitled16.png (855x607, 83K)

a tour of c++ works well enough

A trivial optimization (that you might already be doing) is that an edge "behind" the current edge is always invisible.

If I know JS well enough and am comfortable using Node, is there any use in learning Bash?

Attached: b77.jpg (788x656, 25K)

Does your shell interpret JS?

This will teach you most of the language.

Attached: EE67E077-EA69-4B5F-82E1-40F629822514.jpg (220x271, 17K)

pastebin.com/rgrxtYkB

Not POSIX compliant but hopefully someone finds this useful. It works best with a hotkey. It took forever to figure out how to get the latest URL from Firefox's history eloquently so I said fuck it and just read the cache files.

Yes, it was the first thing I implemented. I'll now try to cut down the time by taking advantage that elements that are seen by other can themselves see the other element (symmetric matrix). Then there are some other things I can do, but my matlab isn't as good as my python or C.

If I can only ignore the nigger #36 I'll be able to sleep peacefully tonight.

Attached: untitled17.png (915x684, 92K)

i'm writing a python script that looks for duplicate files by checking their md5 hashes. it kind of works but it doesn't return same hashes for duplicate files so i can't detect them.
from os import walk, path
from hashlib import md5

def get_files_and_md5(folder):
# creates a dictionary of files (key) and md5 hash (value)
file_list = [path.join(r,file) for r,d,f in walk(folder) for file in f]

hashes = {}
for file in file_list:
hashes[file] = md5(file.encode('utf-8')) # not sure why you encode

return hashes

def compare_hashes(hashes):
# compares each hash with each other and return list of duplicates

duplicates = []
for key_1 in hashes:
original_hash = hashes[key_1].hexdigest() # compare this to every other hash

for key_n in hashes:
n_hash = hashes[key_n].hexdigest() # hash to be compared
if original_hash == n_hash and not key_1 == key_n:
duplicates.append(key_n)

return duplicates
python docs don't seem to mention that md5() takes filename into account to calculate hash. do i have to strip file of all metadata or something?

Attached: 8dcb9184-44ea-40a8-c0b8-c2d382fb619a.png (2400x3200, 1.85M)

My shell can launch JS interpreter.