/dpt/ - daily programming thread

Krapula editio

Vanha:

Other urls found in this thread:

youtube.com/watch?v=6Cw8cKQ6SN0
stackoverflow.com/questions/3001525/how-to-override-default-window-close-operation
stackoverflow.com/questions/3001525/how-to-override-default-window-close-operation)
github.com/django/django
github.com/git/git
github.com/p512/ads
twitter.com/NSFWRedditImage

first for
eiks joku muu vois välillä alottaa nää langat

...

Kannattaisiko poistaa sun suomi näkyy taas.

GOD DAMN FINNS
Get off this board

Are you even white?!

were as white as the snow and ice surrounding us and our ancient kingdom.
everlasting glory for mongolia!

DAILY PROGRAMMING CHALLENGE!

Post a function that averages an arbitrary number of integers without overflowing and returns an integer.

What should the integer return value be?

int, i'm pretty sure

int avg(int n, int *arr)
{
float result = 0.0f;
int i;
for (i = 0; i < n; i++)
result += (float) arr[i] / n;
return (int) result;
}

What do you mean?

val isZero : 'a -> Tot Bool
let isZero x = (x = 0)
val average : list (x:int { isZero x }) -> Tot int
let average _ = 0

possible incorrect syntax

what should I call my ocaml program?

it tells you if dates are matched by an s-expression.
made for recurring scheduling.

sex dating scheduler

iTrump

>karuselli
>karu selli
Reminds me of this.
youtube.com/watch?v=6Cw8cKQ6SN0
Pretty funny stuff.

He's asking what the function is supposed to return.
Most would assume the average of the array of integers. But you can't be sure.

Well it can't be the average, integers aren't closed under any form of averaging I know

>mastering swedish

First year course in C#. Can anyone help explain why my method only returns guessBool=False?

Method here: textuploader / 53zt5

Sorry about the url Sup Forums thinks its spam

Debug that shit lazy nigger.

#include
#include
#include

int avg(int n, int *arr)
{
float result = 0.0f;
int i;
for (i = 0; i < n; i++)
result += (float) arr[i] / n;
return (int) result;
}

int main() {
int arr[] = {INT_MAX-5, INT_MAX-5, INT_MAX-5};
printf("%d\n", avg(sizeof arr / sizeof *arr, arr));
}


$ gcc x.c -O0 -o x && ./x
-2147483648
$ gcc x.c -O2 -o x && ./x
2147483647


well done

>be writing javascript program
>run it
>suddenly fans go FULL BLAST

What the fuck.

Infinite loop, probably.

Anyone use mathematica?
I want to take a list, square every item in the list and print it.
someList = {1, 3, 5, 7, 9}
sqList[a_] :=
For[i = 1, i

>For[i = 1, i calling the C/LISP modified while loop "for"
Put it in the fucking garbage.

Why does Sup Forums hate C++?

Because it's verbose and complex shit bolted on top of C.

C++ is an abomination that should have dropped C backwards compatibility 30 years ago.

It's pretty cool desu. I still prefer C tho.

Why does Sup Forums hate R?

R is very powerful and useful, but also gross.
(see also Java, C++)

It's ugly, bloated and the niche it fills (gotta-go-fast with some high level features) becomes less relevant all the time.

>In fact, my ideal when I started on C++ was "Algol68 with Classes" rather than "C with Classes." However, the list of solid reasons against basing my work on type-safe Algol68 [Woodward, 1974] was long and painful. So, perfect type safety is an ideal that C++ as a language can only approximate.

Is writing an api wrapper a good first project? The API has a bunch of wrappers already (just in languages I don't want to use)

A project with a useful result is always a good project.

Can I override the Close (X) button of a Window in WPF? I think the button calls the Close() method of that window, but I want to call ShutDown() to close the application and therefore all the windows spawned, not only one window.

>write website for remote file management
>drop project because fuck html and css
>write client server application instead
>fuck writing 2 applications
REEEEEEEE
I think I'll go back to my initial plan and go for a website.

stackoverflow.com/questions/3001525/how-to-override-default-window-close-operation

t. your friendly google proxy
this never gets old

Yeh, I searched for it, and saw that solution but at first didn't worked because he was trying to override a public method to a private, therefore that method wasn't showing in the IDE.
I susbcribed to the Window.Closing event and that worked. (stackoverflow.com/questions/3001525/how-to-override-default-window-close-operation)
ty senpai.

What is /dpt/'s opinion on singletons?

Great when you only need 1.
Not so great when you don't.
Little point in structuring your code around them

Inflexible. Dependency injection is much better.

What is the best option for sanitizing data in perl?

I mean for protecting against XSS for example

Regex could be an option.

I was hoping that wouldn't be the answer..

(I'm bad at regex)

Check out this, I readed it when I was a webdev.

if i have an int x, would it be faster to do x = ~x + 1 than x*= -1 ?

Mostly useless in my experience.

It's a way to use global state "without" using it

If so, then the compiler will probably optimize it anyway and it will be less readable if you write it the first way.

check the assembly yourself.

thanks I will check it out did you find it helpful for untainting also?

52. postaus suomalaiselle kulttuurille ja perus Sup Forums käyttäjälle

>did you find it helpful for untainting also?
I don't do Perl, so I can't know if it's useful for that.

Here's a checklist:
1. I have written both versions
2. I have looked at the disassembly
3. I have profiled the code
4. I have considered if the difference is worth it
After going through these steps you will know what to do.

Is it true crossdressing gives godtier programming abilities?

those being equivalent is implementation defined

can you guys help me with coding something? I'm practicing for an exam and I'm having trouble with a part of my code. the language is java and it has to do with queues.

True, I can confirm. I do not crossdress and I can't write fizzbuzz.

Post it.

Well at least there are no faggots SJW that like Rust in Sup Forums

>mfw using gradle
i was positively surprised
now they just need to extend it for a bunch of other languages

how do you get past dependency paranoia
like, i know there are millions of great libraries out there but im scared that my build process will turn to shit

english is my second language so bear with me.

basically the user needs to input a word or sentence and the program needs to check if it's a palindrome or not.
I have to use a single linked queue. it enqueues at the end and dequeues from the beginning of the list.

the part I don't understand how to do is this: I have to check if the word (or sentence) is a palindrome using dequeue.

should I make two different queues, one normal and one flipped and then compare them with dequeue? or can I directly check. I'm pretty sure I can't do it that way because it's single linked, but maybe I'm missing something.

What Python GUI framework would you advise me to use ?

>fuck html and css
Ah, I see. You guys rip on webdevs because you're actually too dumb to even understand html/css.

STOP. This is premature optimization and one of the worst things you can do to your project. Just use whichever displays your intent better (the second one) and move on to more important things.

Write to the screen directly.

I like rust, it's a great language

Found the autist

What ?

what's the correct way to handle errors in C that might happen in some function or procedure? should I just return an error code and check for it in the main method?

Yeah pretty much, I remember creating a bunch of small functions validators, each returned a non-zero if there was an error. And finally I wrapped all the function into one.
You might wanna return an object which contains the functions that raised an error if you need to know that.

>which contains the name functions*

For someone who only knows Turing (it's taught as a course in my school) what programming language would you recommend as a next step, C, C++, C#, Java, something else? I'd prefer for whichever language to have pretty extensive documentation that is actually understandable for a beginner. Thank you all in advance.

I don't hate it mane. Concepts are the shit.

what the fuck is Turing

>actually understandable for a beginner
>extensive documentation

python 3

How do I make the jump from regular C programming to Data Structures programming?

I don't know about nodes and structures and lists and trees and shit.

>Data Structures programming
lol

lists are super ez.
BSTs are super ez
balanced BSTs are not as easy.

there's no magic involved, just read some sample implementations and understand them.

Whats good /gee/

I think I've come to realize that programming a series of small scripts will not greatly progress programming ability, and ability gained from programming these scripts will taper off into a plateau over time

In this case I define a script as anything

Turing is a Turing complete language developed by holtsoft, it's incredibly basic.

>lists are super ez.
>BSTs are super ez

I feel very dumb now.

Maybe check out an open source project.
github.com/django/django
github.com/git/git
git://git.musicpd.org/master/mpd.git
[...]

Eh, everyone has to start somewhere.
If you want I can write some basic implementations of lists and BSTs for you to work through.

Take your input, save it as a string.
Take that's string's length, save it as an int.
Half that int and round down.
Walk across your string and enqueue that many char.
You can start at the front or the back, it doesn't matter.
Then walk across the string in the /other/ direction.
As you go, dequeue and compare it.
If it matches until the queue is empty (or maybe just reusue the ½length), it's a palindrome.

So,
>take input
>prepare ½length
>loop where you enqueue
>loop where you dequeue
>return something

Yeah that would be cool.
I just need to study for an exam and like I said I only know "regular" programming. I'm not even good with pointers.

avg :: (Integral a) => [a] -> a
avg [] = 0
avg xs = fromIntegral((sum xs)) `div` fromIntegral((length xs))

I'm currently working on my xscreensaver replacement.

Improving the saver API and Rust implementation to take into account all the various issues that screen lockers had in the past.

In the end it should be even simpler to write screen savers in any language than it is with xscreensaver, and they'll even be more customizable.

Wonder if jwz will ever write a rant about me.

Cool, I'll probably take an hour or two and release it here: github.com/p512/ads

This () assumes some things about your problem.
Frankly, you were /really/ vague about it.

If you do it with literally a single queue and a two chars things get messy.
The easiest solution would be to use a bookened. EOF/EOT/NUL/whatever. A char value you know you won't see.
Actually, how do you know when the input is finished? Just use whatever it terminates with?

So you take a char of input, save it in your a char, enqueue the char, then check if the char is the termination char.
This enqueues the termination char as well, but that's fine, because you'll use it as your bookend.
Then do this shit, but in Java instead of fugly psuedo-code.
loop (is char1 not the bookend?)
input -> char1
char1 -> enqueue
dequeue -> char1
loop (true) //we just return at some point
is char1 your bookend? //inputs of even length
(yes) you're done! it's a palidrome
// there's no (else) case, we just keep going
enqueue -> char1
dequeue -> char2
is char2 your bookend?
(yes) enqueue -> char2
dequeue -> char2
is char2 your bookend again? //inputs of odd length
(yes) you're done! it's a palindrome
(else) are char1 and char2 the same value?
(yes) dequeue -> char1
back to the start of the loop
(else) you're done! it's not a palindrome
(else) char2 -> char1

return 3;

that's clever, thank you. I'm trying to type it out now.

how would you do it then?

uh, you can also do x = -x; If there are no optimizations involved, I believe it would be fastest. and the most clear

no stop

I'm trying to scrape a site but I'm exceeding the amount of request. I've started sleeping my in between requests up to 3 seconds but I'm still getting hit with the too many requests. Am I just going to have to keep sleeping longer and longer until I get under their limit? It's already becoming deathly slow.

>any ideas would be much appreciated

Well for starters, if you are going to cast to float, you should at least use a bigger one. 32 bit floats can hold 23 bit integers. 64 bit floats (doubles) can hold 52 bit integers.

sleep longer

make a virus, infect a hundred PCs, scrape with them too

Figures. Apparently you can use tor and request different IPs which could be useful. But I'm lazy and would rather sleep longer.