old thread: What are you working on, Sup Forums?
/dpt/ - Daily Programming Thread
Other urls found in this thread:
github.com
en.wikipedia.org
my.mixtape.moe
twitter.com
Hello?
who decided to not allow function overloading in python -.-
also no implicit type conversion for concatenation wtf
I'm on opengl 2.1, but when I call functions like glGenVertexArrays and glGenFramebuffers, they return an identifier and not -1, even though these are opengl 3.0 features.
I tried loading up a 3.0 context and it wouldn't open.
Does my GPU have extensions?
Is this portable?
>implicit type conversion
hello brainlet
do you like doing self-evident busywork that the compiler should be capable of?
perhaps that makes you the brainlet, user
>not enjoying types
>implicit type conversions being safe
"no"
You are the only brainlet here, lad.
newfag here how to post source code?
when your friend asks for help on their Rust code
Right click -> Source code -> Post to Sup Forums.com
But I do enjoy types, I just don't rabidly attach myself to language design precepts.
Pretty much every compiler that exists makes some assumptions, arbitrarily deciding that it should never convert a type is hurting your productivity for no net benefit.
>&[u8]
...how do you get the address of a type? this isn't valid c
Brainlet calling other brainlet
Or just use a good language with a good type system so you never need to cast in the first place.
I'm open to that, what are some examples?
any decent functional language, take your pick.
Its not C
That's a byte slice.
How is that hurting my productivity? I would be more productive if I can trust that my code is free of numerous type related bugs (and thus rule them out while debugging, which is always a time sink), than to be granted the "freedom" to be momentarily implicit.
> ['Hello'] + "World" -> ['Hello', 'W', 'o', 'r', 'l', 'd'].
You monster
Concatenating string isnt usually what you want anyways. Format strings exist for a reason.
...
I DIDN'T FUCKING CHANGE X FOR Y IN THE FUCKING MIDTERM
IT'S THE FUCKING PROGRAMMING COURSE FUNDAMENTALS WITH LISP, FULL IDE, INTERNET AND TEACH PACKAGE, FIRST MIDTERM AND I STILL MANAGED TO FUCK IT UP
THE WHOLE EXAM WAS TO CREATE A FUCTION THAT CHECKS IF A POINT IS INSIDE OF RECTANGLE
AND I FUCKING FAILED IT
i haye myself
FUCK
DJDLSKEPGJFUDUSS
Did you not run tests?
wrote a shell script that works like windows slideshow for changing background choosing a random image, also copied it in order to change its resolution using feh
>muh safety
while true
do
find ~/Pictures/ -maxdepth 1 -type f -printf '%f\n' | sort -R | tail -1 | while read file; do
cp ~/Pictures/$file ~/Pictures/Wallpapers/randomBackground.png;
feh --bg-center ~/Pictures/$file
done
sleep 5s # Waits 5 sec
done
is it just mean but when you view the page source for this (the html) is that its one fucking line?
...
Guess you didnt run any unit tests
just drop out, become a girl and find yourself a sugar daddy to support your ass, since you already fail at everything else.
How do you fail at basic math?
can anyone help with a programming assignment for my class. im having some trouble with the while statement in it.
our teacher wants us to
Prompt the user to enter a sequence of numbers, ending with 'Q' to quit. (Use
the Scanner method hasNextDouble() to control your loop.)
Read the numbers, keeping a separate sum of negative and positive numbers.
this is what i have so far
double positiveSum = 0;
double negativeSum = 0;
double total;
System.out.print("enter numbers ending with q to quit");
userInput.hasNextDouble();
while( positiveSum > 0)
{
positiveSum = total +
after that im stuck
>the city of Lisplets
If i were you, i will blame it on Lisp.
Counting the parenthese usually fucked my brain.
Even on C
...
bruh if you cant do this easy shit how you gonna do hard shit
>java
I working on a building up a language from scratch.
Starting with a tiny stack machine implementation as c and pretending it's a real machine and all I have is a text editor.
I started with a program that translates hex into binary and translated it to binary by hand.
Now I'm using that as a base to add support for labels. After that I'll either write a traditional imperative language compiler, or maybe an interactive forth.
im thinking about dropping the class and taking it with a different teacher. this teacher doesnt go over shit in class and just expects us to know it all.
Good luck. Make sure to publish it somewhere,
otherwise it just a dead language
it's already on github, but i'm hesitant to post my account on Sup Forums, i think you'll understand.
This isn't like math where there's tons of different ways to do things and everything is ambiguous.
There's only one way to write java, and if you don't get it the first time you never will.
its not that i dont get it. if you wrote the program out i could tell you what it does. i just have trouble writing it all from scratch.
You afraid of a little forking my dude?
just drop out now
Sounds like you need more practice and not necessarily more instruction.
my account has my name with which you could find other personal information
well you can dump the repository into a cloud storage and share that.
only after u kill yourself first
:^D
i feel this way as well.
is it just me but when you view the page source for this (the html) is that its one fucking line?
pick related
nah you could still find it.
github.com
this repo partially inspired it, the original site is down but someone mirrored it on github
moot can't afford newlines
>i feel this way as well.
you're not even trying
i'd recommend turning the sleep time into a variable with a default of 5. That will prevent you from having to change the code if you want a different shuffle frequency.
use github or something
>8 pm
>boss calls
>wtf
>user we're in some shit, I need proof of concept on this shit we talked about yesterday by tomorrow morning
>pushittothelimit.mp3
What job is this?
the exciting world of front end api development, i'm just an entry level fuckboy though.
This.
If you're concatenating strings, you've already fucked up.
Dude I tutor that curriculum at my uni. If you wrote tests and the problem statement etc thats like 90% of the points. Actually writing the correct answer is nothing
wagie btfo
yep, hard lyf, sad lyf
fn to_hex(s: &[u8]) -> String {
s.into_iter()
.map(|b| format!("{:x}", b))
.fold(String::new(), |st, h| st + &h)
}
I'm making a chroma key program in c++ that needs an automatic threshold detector. I got the idea of incriminating the threshold, checking how many pixels are part of the foreground, and redoing it if the amount added is less than some value. This generally works, except the subject's size in the picture kinda fucks everything up. If it's too big then a lot of it will get added as background. Is there a better way to automate the amount of pixels that should be the foreground?
>incriminating
incrementing
t. spellcheck
im learning C++ as my first language and having fun
soup Sup Forums i have a problem
Below is an example of two line items:
Quantity: 2x Value: $9.99, which totals $19.98
Quantity: 3x Value: $9.99, totals $29.97
Grand total for the sale is $49.95
The user needs to be able to change the grand total to for example $49.99 and it should change the line values to make it equal.
My current naive method of doing this is multiplying every line by the same multiplier (49.99/49.95=1.0000800800...) which in this case rounds it up to 2x$10.00 + 3x$10.00 = $50. $0.01 off.
In this circumstance we can actually get it exact by adjusting it like 2x$10.01 and 3x$9.99
This isn't foolproof. If there is a single 5x$10.00 line it has to be $49.95 or $50 and there's no middle ground but I'm trying to get best effort.
Note the values do not necessarily have to both be identical this is just for example.
So after some experimenting I figured out that the greatest common divisor of two quantities is the minimum adjustment you can achieve in this fashion (please let me know if you can prove this is wrong)
e.g. since 7 and 9 have a GCD of 1 you can change 7x$1.00 + 19x$1.00 from $26 to $26.01 by making it 7x$0.92 + 19x$1.03. A pair of even numbers have a GCD of 2 so 4x$10 and 6x$10 can only get to $99.98 or $100.00, not $99.99.
So far in my implementation I do the multiply to get it close to what I want, look at the remainder difference between the multiplied amount and the desired amount and then look though all my quantities calculating GCDs and try and find a single row or two rows with a GCD that is divisible by the difference I need to adjust. Now that I have the best 2 rows I'm then at a loss how to elegantly figure out what the adjustments should be.
If I had two quantities like 9x$10 and 20x$10 = $290, how do I figure out that to get my additional 1c for $290.01 I need to adjust to 9x10.09 + 20x$9.96? Is there some freaky maths to find 10.09 and 9.96 without bruteforcing the shit out of it in nested loops?
Is this good code?
Why offer arbitrary discounts at all?
And if you're being serious just subtract (0.01 * cart->count), why the fuck would you put this in a loop?
no
Implicit type conversion is gay, a string concat operator might be a good idea but there aren't any characters left to use.
>>>print("foo" ! var)
?
>format!("{:x}", b)
Without fixed width you won't get the leading 0, meaning [1, 2, 0xff] will be "12ff". It would be
fn to_hex(s: &[u8]) -> String {
s.into_iter()
.map(|b| format!("{:0>2x}", b))
.collect::()
}
The existing structure basically calculates the sale total as qty x value of all the lines and i can't add an arbitrary reduction without it being specifically applied to a line. The quantity cannot be changed because it would impact stock levels. need to offer arbitrary discounts because that's basically what the feature is for, applying a distributed discount/markup across all the products to make the subtotalled section equal to a specific amount.
I'm writing a REST API in C++ from scratch. It's pretty comfy.
Just offer the total price as the price of each unit plus a "volume discount" subtraction or something.
I love this problem because I totally know why you'd need to do it, it seems super simple, yet there's no clear solution. This might help: if you write the number of pennies you discount (or increase the price of) each item as x, y, ..., the price of each item as a, b .., and the total discount in pennies as N, you have a linear diophantine equation. For example, in your example the equation is
2x + 3y = 4
en.wikipedia.org
As you point out, some cases dont have a solution. I'm not sure what to do except adjust N until you get a solution that works.
But if this isnt customer facing, just create an item worth 1 penny and charge them for it.
>sit with an error for almost 1 hour last night
>give up
>wake up this morning
>see what was wrong within first two minutes
Like wtf
Xir unsafe code is triggering me! Please learn to write idiomatic and safe Rust before you violate our safe space. I bet you're a CIS white male who writes C++.
fn to_hex(s: T) -> String where ::Item: std::fmt::LowerHex {
s.into_iter().map(|b| format!("{:0>2x}", b)).collect()
}
this is common btw
Actually, the original code is the most efficient one since it doesn't call format twice for every fucking byte(yeah, I checked the asm). It only needs a little cleanup to be readable:
pub fn to_hex(buf: &[u8]) -> String {
let mut res = String::with_capacity(buf.len()*2);
for byte in buf {
for &c in &[byte >> 4, byte & 0x0f] {
res.push(char::from(c + if c < 10 { b'0' } else { b'a' - 10 }));
}
}
res
}
It really is. It's happened to me lots of times. Sometimes you just need to take a step back from the problem and come back fresh.
There have been other times where I've been focused intensely on a problem late at night, go to bed, and then wake up like an hour earlier than normal with an idea for how to solve it.
Home work, haven't started. Due in 2 hours this was an extension have to program a website with 10 outcomes. So fucked
>Bitwise operations
>"Bytes"
>Not gender fluid
>for loops
>Function is not even generic
Remove Xirself.
(You)
> twice
Once*
pub fn to_hex + 'a,
R: ::std::iter::FromIterator,
{
buf.into_iter()
.flat_map(|c| vec![c / 16, c % 16])
.map(|c|char::from(c + if c < 10 { b'0' } else { b'a' - 10 }))
.collect()
}
thank you so much for this. i've finished work so i dont want to think about it much more but this gives me something to go on tomorrow! like you said it seems like something super simple but you just have no idea where to begin even googling it.
..
printf("%xull", (unsigned long long*)slice)
Good enough
printf("%xull", *((unsigned long long*)slice));
oops
That's not even close to being correct.
If I wanna make a function that consolidates multiple matrices together, would that be called "collapse" or "reduce"?
It's good enough on big endian systems.
No it's not. Not only does it violate strict aliasing, alignment requirements, and all that sort of shit, the format string is completely wrong.
Good!
Good enough for what, generating SIGSEGVs? It only kinda works if the slice is sizeof(long long) bytes long. But hey, I didn't expect anything less from a C-tard anyway.
Yes, good enough. As long as the remaining buffer is zero-filled, you're fine.
I made a messy python script to download images from Sup Forums threads.
my.mixtape.moe
That's not how it works, idiot.
Also, as I said: the format string is wrong. That's simply %x followed by a literal ull.
The correct format string is %llx.
munge_matrices()
Overload +.
Yes, it should be llx, sorry, I'm barely awake. If it doesn't fit your requirements, use strtoull or write a proper function. Still better than the rust """"solution""""