/dpt/ - daily programming thread

Interviews edition

Old:

Other urls found in this thread:

github.com/tomaka/vulkano
gitlab.com/CollectiveTyranny/DMUX
youtube.com/watch?v=ame2PH67gnk
lel.ed.ac.uk/~gpullum/loopsnoop.html
youtu.be/A__8Y8I3hNo
lmgtfy.com/?q=kernel32.dll!WriteConsole
twitter.com/NSFWRedditVideo

Does std::next wrap around if it hits the end of something?

Too early edition

TOO EARLY

Nope.

UH OH, Sup Forums!

You've been visited by the BAD CODE BOOGEYMAN! You will leave this thread unharmed only if you post something you coded recently and the boogeyman sees there's no bad code in it!

C'mon, you guys don't have anything to fear, right?

Continued adventurers of the chip8 emulator.. Looking at Vulkano as a potential for graphics github.com/tomaka/vulkano

True story this has taken so long because I only work on it for about 15 - 30 minutes a day..

main = print "God bless you immunity cat"

Sorry bro, immunity cat is protecting me

Am I safe?
int x = 0;

there's no need to be rude

nice try but immunity cat is ALWAYS with me.

But I wasn't trying to be rude. :(

std::copy(std::begin(uartData), std::end(uartData), std::back_inserter(resultData))

Immunity cat guards the dpt..

mov ax, 1

3D rendering computed fractals

std::copy(
std::begin(uartData),
std::end(uartData),
std::back_inserter(resultData)
)

Only use powers / multiples / divisors of 12 when you're generating the fractals. It'll provide interesting results.

>tfw all the videos in my BGM playlist were flagged by Youtube
>no more rare pc-98 tracks to program to

The real project generates a random function from a
list of functions and generates the images. The 3D part is a thing I was working on to export the data to OBJ.

{
using namespace std;
copy(begin(uartData), end(uartData), back_inserter(resultData));
};

In C, how do I make scanf accept n number of inputs?

For example, if I wanted it to accept 5 integers, I would simply write

scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);

The idea is, for an array of size n, I should be able to make scanf accept n numbers of input, all to be deposited into the array.

int arr[5];

for (int i = 0; i < 5; ++i)
scanf("%d", &arr[i]);

Is this good or bad code, mr. boogeyman?

#define/**/install/**/0[x]=045;p(j);p(k);for(;;){++l;m++;++q;r++;
#define gentoo if((l-44)){p(l);p(l);break;}}m|=3;q^=27;p(m); \
r+=6;t>>=2;t+=7;p(t);p(q);p(m);p(r);p(l) ;p(s); t++;p(t) ;p(10);}
#define/**/i/**Sup Forums*Sup Forums Sup Forums /c/ /d/ /e/ /f/ Sup Forums /gif/ /h/ /hr/*/
#define/**/c/* */char/*/k/ /m/ /o/ /p/ /r/ /s/ /t/ /u/ Sup Forums /vg/*/
#define/**/Anonymous/**/1[x] b-1;i Thu b;j+=4;k++;i a=// /vr/ /w/
#define/* *Sup Forums* */=0144/* /wg/ /i/ /ic/ /r9k/ /s4s/ /cm/ /hm/ */
c x[2];i j b,No b,k b,l b,m b,q b,r b,s b,t b;main(){ //lgbt/ /y/
#define p(o) printf(x, o) //3/ /aco/ /adv/ /an/ /asp/ /biz/ /cgl/


Anonymous 07/07/16*(Thu)*11;25;11*No*55458155;

install gentoo

I'm pre-ordering a binary tree in java and returning the String result of the pre-order. My methods are traversing the tree properly but it is deleting my string, so that the end result when printed out is only the root node in my tree.
public String preOrder() {
String answer = "";
return preOrderHelper(root, answer);

}

private String preOrderHelper(Node root, String answer){
if(root == null){
return answer;
}
answer = answer + root.key + " ";
preOrderHelper(root.left, answer);
preOrderHelper(root.right, answer);
return answer;
}

what the fug

Okay I think I worded my question wrongly..

Basically, I have a pointer to an array passed to a function. The size of the array is not fixed. I have to write a scanf that accepts input based on the size of that array, and write those inputs to the array itself.

Your solution would work if the array size is fixed, but unfortunately my case isn't.

Indescriptive name. What the hell does x mean? It's not even something standard, like i or j in loops, or n as size of something, or T in generics/templates, or e in range-based for loops, et cetera et cetera.

Don't compile that, it releases mustard gas!

>there are no possible situations where x can be a reasonable variable name

Oh, then just use malloc, and realloc to get as much memory as you need for the input.

use an struct that has a pointer to the array and the size of the array.

This will work:
answer = preOrderHelper(root.left, answer);
answer = preOrderHelper(root.right, answer);
Since you seem to want to do things to a traversed tree, why not write one function to turn your tree into a pre-order list and another function to turn a list into a string?
private List preOrder(Node root) { ... }
private String toString(List) { ... }

toString(preOrder(root));

Do I have to use those right now? Because the point is, I'm currently following this course, and it hasn't touched on malloc or struct right now.

static PyObject* decode(PyObject* self, PyObject* args)
{
Py_buffer buffer;
PyObject* retval;
char* decoded;
char ch;
size_t i = 0, j = 0;

if (!PyArg_ParseTuple(args, "y*", &buffer)) return NULL;
if ((decoded = (char*) PyMem_Malloc(buffer.len)) == NULL) return PyErr_NoMemory();

for (i = 0, ch = ((char*)buffer.buf)[i]; i < buffer.len; ch = ((char*)buffer.buf)[++i])
{
if (0x0A == ch || 0x0D == ch) continue;

if (0x3D == ch)
ch = ((char*)buffer.buf)[++i] - 106;
else
ch -= 42;

decoded[j++] = ch;
}

retval = PyBytes_FromStringAndSize(decoded, j);
PyMem_Free(decoded);
return retval;
}


Boogeyman is going to fuck my shit up

You can't unspecify the size of the array in its declaration if it has zero elements, and then pass it to a function. How does the code look like?

So you're problem is you have an array and dont know the size? That should be easy to figure out.

you should have told us that you are a noob. just use a fixed length array, keep track of the number of inputs in a variable and do something like

should I study pre calculus/calculus in order to be a good programmer? I am learning via sicp now, but I have some free time as well, so maybe it will be helpful to start learning precalculus right now?

What's 'pre-calculus'?

This is a python script to remove any leading non-alphabetical characters in a directory.

I don't know why it would be of use to anyone but me but here you go:


import os


stop = False


def isalpha(x):

"""Returns true if character passed in is alphabetical"""


if x in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":

return True

else:

return False


for filename in os.listdir("."):

num = -1

for c in filename:

if stop:

stop = False

break

num += 1

if isalpha(c):

os.rename(filename, filename[num:])

num = 0

stop = True

Wow thank you user. I also didn't think of doing it the second way.

What's with that excessive whitespace, user.

Okay somehow the following code


while (i

The python effect. You make whitespace mandatory and suddenly it's everywhere.

I don't know what you mean by precalculus, but analysis and, while we're at it, abstract algebra with linear algebra put your brain in the right place (only for it to be blown away in differential geometry and logic afterwards, lol).

But honestly, I didn't use them at all in my work. Still, mathematics really help with your thinking and, in my opinion, it's worth it just for that.

Had a script that combined data read-in and processing in the same loop and it was a fucking mess, and then this morning in the shower I realized it wouldn't actually be that much memory to hold the whole data input file in memory, and I wouldn't kill myself on file read times anymore. It also makes the data processing so much easier too.

Actually I don't normally write code like that, so I don't even know, ha.

What happens if I don't put return 0 at the end of a simple function? Is it implementation based? I assume it's something that the user wouldn't see since there are no compile or runtime errors.

Also, should I kill myself if I make stupid mistakes like leaving the final character of a line outside of a comment so that I end up getting a compile error?

>hat happens if I don't put return 0 at the end of a simple function? Is it implementation based? I assume it's something that the user wouldn't see since there are no compile or runtime errors.
0 is returned implictly if you omit it in main() as I assume is what you meant to ask.

>Also, should I kill myself if I make stupid mistakes like leaving the final character of a line outside of a comment so that I end up getting a compile error?
Happens to everyone.

ey /g im willing to get serious into something this summer but haven't picked a project yet.

Thinking about django and get into back-end.

Here is what I meant, I was referring to the inspace function.

#include
#include

int inspace (int deg);

int main (void)
{
int num_sp =5;
char c;

printf("Input and press ENTER when done\n");
for(c =getchar(); c ; c = getchar())
{
if(c != '\t' && c != '\n')
putchar(c);
if(c == '\t')
inspace(num_sp);
if(c == '\n') {
putchar(c);
break;
}
}
return 0;

}

int inspace (int deg)
{

int j;

for(j = 0; j < deg; ++j)
putchar(' ');
j = 0;

// return 0;
}

We got the vehicle physics going with Bullet Physics which is awesome, and a GUI (See the top left widget) and are working on the HUD and networking. I am also doing some refracting of the code. We also got some new assets, this project is getting interesting :^) Here is our repo for anyone interested:
gitlab.com/CollectiveTyranny/DMUX

From the C Standard:

(C99, 6.9.1p12) "If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."

The main function is an exception to this rule as if the } is reached in main it is equivalent as if there was a return 0; statement.

Thank you very much user. I will do my own research from now on instead of bugging you guys.

Worst part? I actually did code this recently

#include

int main() {
int i;

for (i = 1; i

>tfw I just remembered I have immunity cat protection
>tfw I keep falling for shitty b8

You're like the retard in my plant that programs in C# once a year. He makes enough whitespace around functions to make sure only one is visible on the screen at any given time.

A while loop would work better here.

while( c = getchar() != '\n' ) {
if( c == '\t' ) {
inspace(num_sp);
} else {
putchar(c);
}
}

Here's an immunity cat for everyone else

while( (c = getchar()) != '\n' )

Right, missed that.

Literally just made an educational video about fixing syntax errors, am I boned or left-alone?

I love parenthesis so much

Yeah I know it's messy. I designate a time in my day where I go back to "old" code and make it more "effecient". Thanks anyway.

Show us the video user, we'll be the judge of that.

here you go

youtube.com/watch?v=ame2PH67gnk

print "FUCK OFF BOOGEYMAN!"


t. started Python last night.

lel.ed.ac.uk/~gpullum/loopsnoop.html

>printf("FizzBuzz\n");
boogieman rapes you to death

What's wrong with that? I tested it and it seemed fine.

Please enlighten me oh wise user

Using an old branch of python? The boogeyman will be after you for sure, user.

You're using the print formatted function without the use of formatting.

puts/fputs would do

Not user, but I state to the boogeyman:

"When the majority of the Python code that you use on your corporate system is running Python 3, I'll switch"

That'll keep him off for about ten years

You already have statements that will print the components of the word.
Think about it.

That's not technically wrong though; it can be used like that. I'll take your suggestion, but the boogeyman will have to satisfy his savage desires off of some other poor user.

Plus, that immunity cat...

How do i into python lads?

Just go to the documentation, and try things out.

Codeacademy is a nice gentle start if you're clueless.

Not programming related but this is the only relevant thread I could find, SQT hasn't been helpful

You don't need any books to develop a hand cipher.
Just make some modifications to ROT13.

You can give a function the return type "void" which means that it doesn't return anything.

void inspace (int deg) {
int i;
for (i = 0; i < deg; ++i)
putchar(' ');
/* nothing left or required to do. */
}

>mfw when this compiles

>hey look, I'm an insufferable prick!
1) It's more consistent if you use only printf
2) It's easy to add formatted arguments if you need to
3) puts is confusing because it automatically inserts the newline; people reading the source might not know that without looking at the docs
4) GCC always turns printf("...\n") into puts("...")
You literally have no excuse for being such a shit head.

>in the year of our lord C99+17
>space between identifier and opening paren
>two-spaces for indentation
>not putting variable declaration in the initialization expression of the for loop
>prefix increment
>omitting braces around a control structure
>putchar
>multiline comment notation used for a single-line comment
ritchie is spinning in his grave rn

runs too ;)

I'm not clueless, just a new language.

I actually did the code academy course when I was first getting into programming, but now I have to properly learn it for work

I think this is a good idea, read quite a lot of the documentation and also some introductory book on safari, but it doesn't help

I am trying out some basic control flow like

If arg do this
Elif do that

And it just keeps quitting on me, with no stack trace or anything

I must be doing something incredibly stupid but I don't know what

Learn Python the Hard Way

>>space between identifier and opening paren
>>two-spaces for indentation
It's cause I hand-typed it into the code tags.

>>not putting variable declaration in the initialization expression of the for loop
It's a habit because I used to compile without -std=c99. It doesn't make any semantic difference and I think it looks better

>>prefix increment
Literally no semantic difference, a C++ habit.

>>omitting braces around a control structure
Not a significant enough body for it to be worth it

>>putchar
Just regurgitating what the other poster used. He doesn't know you're supposed to use
printf("%*s", n, "");

>>multiline comment notation used for a single-line comment
All my comments are multiline, unless they're used to block-out code. It's consistent that way.


Also
>giving this much shit about 5 lines of code
You must be a complete shithead in real life.

Anything but this book.

Haskell is shit.

youtu.be/A__8Y8I3hNo

I'm using pip to manage dependencies on a per project basis, isolating environments. In order to deploy, my project must be inside of a docker container, which loads the environment into a simulated operating system. Docker must be run in a linux distribution - so I use vagrant to deploy a virtualbox vm, wrapping the docker containers into a linux based operating system.

Version control. Dependency control. Environment control. OS control. Everything is monitored and kept under control. Code has changed. The age of deterrence has become the age of control... All in the name of averting catastrophe from . And he who controls the code... controls history. Code has changed. When the computer is under total control... Code becomes routine.

DOES ANYONE HAVE A WIN10 MACHINE HERE?

If so, could you kindly check what syscall code kernel32.dll!WriteConsoleA is?

shoulda used docker

lmgtfy.com/?q=kernel32.dll!WriteConsole

>what does SMB stand for?
How the FUCK would I know? More importantly, why?!

>Do you know what DNS means?
Why are you asking me what Domain Name Systems MEANS instead ow what it DOES?

>what does the PAM abbreviation mean?
Why the fuck is me knowing that Pluggable Authentication Modules stands for PAM would be relevant to me being a developer?

I feel like I'm taking crazy pills!

Why is so bad? It was recommended to me by a teacher back at uni

Maybe a coordinate reference ? Maybe the next line has an "y" variable ?