/dpt/ - Daily Programming Thread

op.image.isAnime()

Previous thread:

Other urls found in this thread:

gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,options:(colouriseAsm:'0',compileOnChange:'0'),source:'#include int ec(bool x) { if(x) return -1; else std::cout << "Bla!!\n"; } void ex(bool x) { if(x) throw new std::exception; else std::cout << "Bla!!\n"; } int main(void) { bool x; std::cin >> x; ex(x); }'),l:'5',n:'1',o:'C++ source #1',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g62,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O3'),l:'5',n:'0',o:'#1 with x86-64 gcc 6.2',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
godbolt.org/g/qtz3IW
godbolt.org/g/XmtCrG
mediafire.com/folder/mcoahtucqx177/Programming_Books
stackoverflow.com/questions/16882489/why-does-scanf-get-stuck-in-an-infinite-loop-on-invalid-input
twitter.com/NSFWRedditVideo

first for GAS ALL FAGGOTS

Rust is the future C++ dead language it's official

This gay is faggot and he dont know how to c++.
I hope you get Parkinson's disease faggot.
Then i want to see you typing.

...

I wish you a stiff neck and arms so short that you cannot scratch yourself.

>And if it occurs for a small, trivial error - have you ever read from a socket, and there suddenly was no memory left, and you thought to yourself: "Now I need an exception to tell the caller function to give me some more memory additionally to what I already had!"? - then overloaded error handling is OK?
If you think that error occurs often enough that the constant overhead still beats the occasional cost of the exception then go for it, don't use an exception in that case.

>Do you have any idea how many trivial things can go wrong that don't fucking REQUIRE new/delete faggotry? OOM was one example.
>OOM
>trivial
That said, you can theoretically preallocate an exception although I don't think C++ supports it.

>Another would be "cannot find object in data set". Trivial stuff.
That one is tricky to quantify. It would be best to provide both or abstract over it somehow if your language is conducive to that.

>No. I have a better idea: learn how to fucking code
Coming from the dumbass that doesn't want to think about picking the right tool for the job, nah.

if( op.image.isAnime() == true )
reply("just stop posting anime pls. I'm tired of typing this out/n");

8th for python

I was actually done talking to you ... but you know what?

>gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,options:(colouriseAsm:'0',compileOnChange:'0'),source:'#include int ec(bool x) { if(x) return -1; else std::cout << "Bla!!\n"; } void ex(bool x) { if(x) throw new std::exception; else std::cout << "Bla!!\n"; } int main(void) { bool x; std::cin >> x; ex(x); }'),l:'5',n:'1',o:'C++ source #1',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g62,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O3'),l:'5',n:'0',o:'#1 with x86-64 gcc 6.2',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4

Compare ec with ex.
I rest my case, you are a gigantic faggot and you have no idea what you are talking about.

if( op.image.isAnime() ^ false == false ^ ( false == false)
){ reply( "just stop posting anime pls. I'm tired of typing this out/n"
);}
fixed for readability ^)))

bizzfuzz

The exception handlers aren't on the stack. Every function can have exception handlers associated with it, so what happens is, when an exception does occur, it repeatedly pops stack frames until it finds an exception handler.

How does it find the exception handlers without them being on the stack? It has a lookup table. It looks up each function it peeks on the callstack in this table to check if it has exception handlers associated with it at the current instruction pointer, and if so, runs that handler.

So the handlers themselves are in some part of memory that's rarely used unless you throw all the time, and gets referred to when exceptions do happen. So that means that when exceptions do happen, they have high cost (a lot of cold memory has to be loaded into the cache, the process of traversing the callstack is itself expensive, etc) - but this comes with the advantage that they're absolutely free when errors don't occur.

Keep in mind the actual implementation in practice depends on your compiler, so this is just an outline of how it can be done with zero cost.

But programming with error codes is so annoying.
For every function call, check did this thig return an error? Did that thing return an error? Did my dick return an error? And if an error occured you have to relay it up the call stack, and at every level in the calstack, more is this an error yet, is that an error yet.
I hate having to code like that. It's time consuming and ugly, and makes your code a lot harder to read because two thirds of your codebase is stupid error checking. ARGH!

>omits error handling for the error code version and doesn't even call it
It's the error handling that actually determines the cost of each option. Exceptions can be preallocated so the memory allocation cost is unnecessary.

Nice fair, unbiased example, you really showed me. Look, I'm not claiming that exceptions are always free, I'm claiming that sometimes they are the more efficient option than error codes. SOMETIMES. How is this a fucking problem to you?

>== false

Where do I learn about image manipulation, especially with python?
I want to learn how to manipulate pixels individually and do all kinds of weird stuff.
Where do I start?
Is python not a good language to manipulate images in? I can't find much about this. Just some basic "flip this image, crop blah blah" with PIL..

Good effect systems (monads, algebraic effects, continuation passing, etc.) make both look identical. In fact, you can completely abstract over whether it uses exceptions or codes underneath it all.

Smaller sized programs are able to better fit into the instruction cache. Larger programs that duplicate code more often will have to swap code in and out of cache more frequently, which destroys performance.

Probably best to search for a library and its tutorials, then if you can find python binding documentation.

What is going on in this video.

>animetards
>VR
>gay

Is there a way to keep track of how many times a recursive call happens in C without using a global variable?

The guy in the black shirt is standing in for the girl in the VR game.
Dollar for dollar, this is a much more cost efficient way to get your rocks off than to to fug a real girl.

Declare a static variable in the function, it keeps its value across calls. Increment it.

Why Python? Go with Rust! Much better performance!!!

And you can help me out with my image handling library!

If anyone's interested in why exception handlers are zero cost, check this out:

godbolt.org/g/qtz3IW

Specifically, the label after callcatch calls choose - the instructions themselves immediately return the result of choose even if it throws an exception. The handler itself is written to memory just afterward, and gets jumped to when an exception occurs.

How can I traverse a tree and record each value from the tree into an array in the order that it was traversed?

One of the functions didn't return what it was supposed to. Here's a better link.

godbolt.org/g/XmtCrG

Not that the actual assembly regarding the exception is different, but the program as a whole makes more sense.

By...doing exactly that? I don't know how to break it down any more.

What

you literally just described how to do it

How do I assign regex matches to a variable in bash?
Everything I'm finding is only used in an if/else configuration to basically print "yup, that matches!" or "no it doesnt", never actually doing anything with the found matches

>The handler itself is written to memory just afterward, and gets jumped to when an exception occurs.
That's a lot of bytes loaded into the instruction cache that are rarely exercised.

I can't figure out how to code it up in C.

int *preCheck(node *pre, int *arr, int i)
{
if(pre == NULL)
return arr;

arr[i] = pre->data;
i++;

preCheck(pre->left, arr, i);
preCheck(pre->right, arr, i);
}

What I've written isn't working.

You don't seem to understand passing by value vs. passing by reference (pointer).

Maybe you should stop posting anime and pick up a textbook

void *preCheck(node *pre, int *arr, int i)
{
arr[i] = pre->data;

preCheck(pre->left, arr, i + 1);
preCheck(pre->right, arr, i + 2);
}

mediafire.com/folder/mcoahtucqx177/Programming_Books

if [ "foo" = "foo" ]; then
echo "Dicks"
fi

>Syntax error: "fi" unexpected (expecting "then")

?????

Don't think bash supports '=', isn't it something like -eq ?

>[ "foo" = "foo" ]
Assignment?

Same problem
=. =~, ==, -eq all spit back the same "fi unexpected".

At very worst only 63 bytes will be placed in the instruction cache due to the size of cache lines in x86. And the handler itself in this case is less than 64 bytes anyway.

You can do both.

That's even worse; it has no base case and will just segfault. You just need to have a pointer to i, otherwise the indices will be wrong.

Works on my machine.

No offense, but why not Mega? And why not in a single archive?

Yeah I just ssh'd onto a different box and it worked without issue.
wtf

Okay. How about this.
Kindly kill yourself

Which one are you that I replied to?

...

rubyist@Overmind:~$ if [ "foo" = "foo" ]; then
> echo "dicks"
> fi
dicks
rubyist@Overmind:~$

Works for me.

What do you mean by have a pointer to i?

Works from the terminal for me too
What the actual fuck is going on, it just doesn't work from the damn .sh file

Why is it an int function? You're not returning anything worthwhile. If I was you I'd make the increment counter global and take it out of the method call. Working with increment counters inside recursive functions is asking for trouble.

Alright, why should I kill myself? I have a good career ahead of me, anime to watch, and traps to fap to.

Pretty sure this is right, but I haven't compiled it. Pass it a pointer to the value 0 for i initially. Also since you're modifying arr, I changed the return type to void.

void preCheck(node *pre, int *arr, int *i)
{
if(pre == NULL) return;

arr[*i] = pre->data;
++*i;

preCheck(pre->left, arr, i);
preCheck(pre->right, arr, i);
}

I need to return an integer array to compare it's values to an array with values from a different tree.

fuck off anime degenerate

>anime to watch, and traps to fap to.
exactly those reasons and that we are not here to do your homework.

rubyist@Overmind:~$ vim /tmp/foo.sh
rubyist@Overmind:~$ chmod +x /tmp/foo.sh
rubyist@Overmind:~$ cat /tmp/foo.sh
#!/usr/bin/env bash
if [ "foo" = "foo" ]; then
echo "dicks"
fi

rubyist@Overmind:~$ /tmp/foo.sh
dicks
rubyist@Overmind:~$

>global
>ever
And he's not returning an int, he's supposedly returning the array for no reason. If he actually returned an int, he could return the counter.
int preCheck(node *pre, int *arr, int i) {
if(!pre) return i;
arr[i] = pre->data;
i = preCheck(pre->left, arr, i + 1);
return preCheck(pre->right, arr, i + 1);
}

>we are not here to do your homework.
What? I've been answering people's questions, not asking them.

>Using Qt when gtkmm exists

>draw a girl

>What? I've been answering people's questions, not asking them.
Then you're just making the problem worse by making them dependent on us

This. Also please stop posting, I can't add anything valuable to this thread.

not him, but unless they're flat out asking you to code up an entire assignment, I don't see what the problem is in asking for some help if you're stuck on something you did yourself.

What do you want to happen in this thread, then? No, this isn't a homework Q&A session. But if you can't ask questions (for any purpose) and neither can anyone else answer them, how are people supposed to learn?

>I can't add anything valuable to this thread.
Why is that my problem?

Forget your shebang?

How can I code a program that brings back my will to live?

I know C, Python and a bit of bash scripting.

Sorrryyy didn't meant to quote (you)

>What do you want to happen in this thread, then?
preferably arguements over == true

>how are people supposed to learn?
preferably they don't so I won't get replaced by pajeet trannies

Pretty noob here, learning C. My code stops working if I hit an invalid character, sending it into an infinite loop if I don't limit the loops to the array size. So if I input something like:

5 2 16 33 abc 10 5 EOF
it will hit the abc and scanf will return 0 forever never getting to the 10.

Shouldn't the scanf in the while statement move onto the next item in the input? Whether that be a number or EOF.

while( ((check = scanf("%i", ¤t)) != EOF) && (i < max_length) ){

if( check ){
if( items < max_length )
x[items++] = current;
else{
printf("Array is full, flushing excess data.\n");
while( (check = scanf("%i", ¤t)) != EOF )
;
}
}
else
printf("Invalid input, moving to next value.\n");

printf("%i\n", check);
i++;
}

When I'm in dark places sometimes I write girlfriend chatbots in python. It only goes so far user.. it only goes so far u_u

Do you think if we'd know the answer we'd still be here?

>Implying everyone asking help in this thread with a cute anime face is a pajeet
Oh gosh... I'm so manipulable... r--ree

Who is this trap

How many times do you retards want to ask the same fucking question? I had the same fucking question ten years ago, but unlike you pathetic lot I actually used google:

stackoverflow.com/questions/16882489/why-does-scanf-get-stuck-in-an-infinite-loop-on-invalid-input

Write a program with a small userbase that regularly commits and submits issues to the repository.

Write a program that program better than most pajeet.
>Capitalism fixed

Build an anti pahjeet wall.

I actually did google it, but I googled what I was trying to do rather than what was going wrong.

Anyway, thanks my man.

>tfw can't figure out how to return the selection from a single mysql column in php, instead of giving me errors it just returns the entire row
>tfw my getSchedule() function will break if the person's usename is \"Schedule":
>tfw can't be fucked to fix it

That's not hard. I had programs generating program code that I'd then insert in my actual program code.

The problem is that it takes a non-pajeet to actually program such programs and to actually understand them.

You forgot to mention all those SQL injections that you haven't even discovered yet.

Using gcc to compile my C programs on Windows.

How do I get it so when running the .exe on the cmd, it prints out the return value without using printf like it does for Python?

True that. It's not hard. The only reason nobody does that is because it's useless and uncreative... l-like ... most pajeets.

Lied and I feel bad about it. Good night folks

wat

Alright Sup Forums I need some help. I need to make c++ a program that draws a 2d shape's surface area with stars for example (a rectangle. input the length and width. 6 4. So the program outputs

******
******
******
******
. Where do I begin with the algorithm?

Na. For me, I stopped doing this because I found a way to statically initialize string objects in arrays without using strlen.

Nope pajeet. Post cuter anime girl and I might help you.

Loops.

allocate a 2d array of dimensions length and width, and then populate said array with stars.

Why? He's just supposed to print them out, not actually having such an object in memory.

What algorithm?

oh, true

I just had a flashback to an assignment where I had to make a chessboard and do stuff with it, so it's the first thing that came to mind.

Is there a way to replace the linux console by the pyhton one?

what why would it print out the return value lmao

Doing Project Euler questions with parameters in cmd.

I have a question

will SICP make me good compared to other learning materials in 2016?

Yes.
sudo nano /etc/passwd

find user:x:1000:1000:Name,,,:/home/user:/bin/zsh
and replace /bin/zsh with /usr/bin/python3

Dunno if it'll work tho

So print the return value, with print. There is a difference between "return" and "print". That is the point of "return" and not "print". If you would like to see a value outputted during execution of the program use a function provided to "output".