/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

docs.julialang.org/en/stable/manual/methods/
opengroup.org/onlinepubs/000095399/functions/stat.html
pubs.opengroup.org/onlinepubs/9699919799/functions/access.html
youtube.com/watch?v=-AoHGJ1g9aM
twitter.com/NSFWRedditVideo

...

/dpt/ has been really awful lately

is this correct for activity selection?
select(A): # A is sorted by finish time
dummy = Item(-1, -1)
activities = [dummy]
for i in A:
if A[-1].finish < i.start: A.append(i)
activities.remove(dummy)
return activities

for (int j = i*i, k = 0; j < SIZE; j=(i*i)+(i*(k++)))
{
a[j] = 0;
}


If I wanted to index through the char array called 'a' with pointers instead, how would I do that?
char *jp = a;
for (int j = i*i, k = 0; j < SIZE; j=(i*i)+(i*(k++)))
{
jp += j
*jp = 0;
}

Doesn't work. And I think it might be because my pointer and array are char, whereas j is an int?

++++++++++[>++++++++++++++++.>++++++++++[>++++++++.>++++++++++[>++++
+.>++++++++++[>+++++++++++++++.>++++++++++[>++++++++++++++++.>++++++++++
[>+++++.>++++++++++[>++++++++++++++++.>++++++++++[>+++++.>++++++++++
[>++++++++++++.>++++++++++[>++++++++++++++++.>++++++++++[>++++++++++
+++.>++++++++++[>+++++++++++++.>++++++++++[>++++++++++++.>++++++++++[>++
+++++++++++++++.>++++++++++[>++++++++.>++++++++++[>+++++.>++++++++++
[>++++++++++++.>++++++++++[>+++++++++++++++.>++++++++++[>+++++++++++
+++++.>++++++++++[>+++++++++++++++.>++++++++++[>+++++++++++.>++++++++++[
>++++++++++++.>++++++++++[>++++++++++++++++++.>++++++++++[>+++++++++
+++++++++.>++++++++++[>+++++++++++++++++.>++++++++++[>+++++.>++++++++++[
>+++++++++++++++.>++++++++++[>++++++++++++++++.>++++++++++[>+++++.>+
+++++++++[>+++++++++++++++++.>++++++++++[>++++++++++++++.>++++++++++[>++
+++++++++.>++++++++++[>+++++.>++++++++++[>+++++++++++++++++.>+++++++
+++[>+++++++++++.>++++++++++[>++++++++++++++++.>++++++++++[>+++++++++++<
-]>++++++.>++++++++++[>+++++.>++++++++++[>++++++++++++++++++.>++++++++++
[>++++++++++++++++.>++++++++++[>+++++++++++.>++++++++++[>+++++++++++
++.>++++++++++[>++++++++++++++++++.>++++++++++[>++++++++++++++++.>++++++
++++[>+++++++++++++.>++++++++++[>+++++++++++.>

Julia is the most wonderful language in the world.

Explain, please.

I'm gonna have a quiz-like interview with questions from maths/CS. What kind of questions should I expect for the CS part?

I was thinking stuff like explaining OOP concepts (encapsulation, inheritance, polymorphism), explaining sorting algorithms (insert/selection/merge/quick sort), search algorithms like binary search, maybe some questions about linked lists? Graphs/trees (DFS/BFS/Prim/Djikstra/Kruskal)... What else?

Note that it's a quiz done through video chat, no blackboard so no actual coding

i was *going* to make a cool NES debugger for fceux. i messed with the language for a bit and it's such a fucking mess. fuck lua

: fn 0 1 rot 0 do swap over + loop drop ;

depends if it's a major company or a minor one. if it's minor, it's more likely to focus on practical things than algorithms. if it's a major company, it will likely be all just very difficult algorithm questions

>Julia
Whos Julia?

Anyone know how to poll hardware activity/noise in Python? Kinda how /dev/random is seeded, except I don't want to deplete /dev/random nor use a cipher on the polled data.

>just very difficult algorithm questions
But like what?

How to invert all prime numbers under 2 million.

It is a dynamic language with none of the disadvantages that most of the popular languages have.

* It is faster than most statically typed languages if written with performance in mind, and predicting what the emitted assembly code will be is relatively easy if you stick to procedural code.

* Its type system isn't shit, and it has top-tier parametric polymorphism despite being dynamic. Abstract types subtyping and multiple dispatch solves the expression problem. Another user showed in the previous thread how it can trivially express concepts like GADT's that are normally considered the domain of Haskell.

* You can do fun stuff like define unboxed bits types and implement basic operations on them that call inline assembly instructions. User-implemented fundamental types like Int are just as good as the built-in ones.

* It has proper common-lisp like macros without giving up the "having syntax" thing. The language itself is programmable and this allows very powerful metaprogramming.

* It has the best interop with other languages that I've ever seen. I can call C,Fortran, Java, Python, R and lots of others trivially, almost as easily as calling a built in function. Among the best glue languages that I've seen, ever.

It's awesome because it is both high and low level. It has tons of very high level features and allows for some very terse and expressive scripts, but at the same time it can do some very low-level stuff as well.

Are there any resources where I can find questions of this nature?

Isn't that just 1/p? So literally just write a sieve, which is trivial.

How the fuck i'm supposed to use keys like this

func(params)
{
//
}

If I have shit like this
func(params, func(params){
//
})

i'm actually looking for an easier book than introduction to algorithms myself. ITA is so dense. back when i was doing literally nothing for 2 weeks i progressed fast but now that i have a full time internship and i do it in my weekends and spare time not so much.

a problem i encountered in an interview was to find the number of groups in a 2-d matrix of 0s and 1's. if a 1 is touching, including diagonally, another 1 that's part of the same group.

the solution i came up with a year or so late is to make a table of all the elements and their group number. a bit too late but idk why i didn't think of it then. i tried to do it without using any additional data storage

>dynamic language
What is this supposed to mean?

>statically typed
Do you mean compile-time type checking?

Does it have things like classes? Sum types?

What is this supposed to mean?

I think he's asking how to put the brackets or something stupid like that

How are you expected to deal with errors when dealing with internet? Lets say I accept a connection from a client, they request some kind of procedure, and then part of the way through we get disconnected. Is it normal to just drop everything and have the client handle it by starting over, or should there be some kind of volatile but not fragile state that is maintained on the server, like a session ID so that things can be resumed/restarted at a more granular level.

Are there any good references on designing internet protocols and implementing them well?

Pretty sure that protocols like TLS handle things like that.

It's dynamically typed and runs on a JIT compiled interpreter with an LLVM backend. The JIT compiler does something unique though, in that it infers static types for you and replaces dynamic dispatch with static dispatch whenever it can, which is pretty much everywhere in idiomatic code. So you typically end up with zero cost abstractions.

So basically, you have the extra flexibility of a dynamically typed language, but any expression which is well-typed does not pay a performance penalty for dynamic typing because the compiler can unbox everything. And you have a very expressive type system to boot which supports some very powerful yet structured function overloading.

>Are there any good references on designing internet protocols
>literally asking this question on the fucking internet
retard isn't a strong enough word

py2exe

is py2exe reliable?

I have python script with numpy and scipy + tkinter as gui, now I have to make standalone exe for windows 64bit users.

any opinions on this?

Is it going to work or I will save more time by rewriting it from the scratch in c#?

you're the retard

Statefulness is generally considered bad. Have them start over, unless you have some easy way to resume where you left off (e.g. what byte to start at in a file transfer).

Also, the type system is built on a somewhat unique CLOS-like multiple dispatch and sum types in a way that sort of generalizes classes and ADT's.

Methods can dispatch on several arguments, not just the first, so they are not grouped by class. Instead, you have a notion of abstract data types that define sort-of inheritence-like subtyping hierarchies, though to prevent ambiguities it doesn't let you inherit fields, it only inherits default implementations of methods.

>dynamically typed
How can it be something which does not exist?

>runs on a JIT compiled interpreter with an LLVM backend
This seems like an implementation detail, not a language one.

So, is it something like message-passing? Are objects just functions in that language?

this depends on what you mean. Look at common website IAM, which is typically handled via session cookies that the browser and server maintain such that if I leave the site and come back (within a certain amount of time), I do not have to go through the entire login process again.

A different example would be how TCP works, where packets are numbered sequentially and a "session" is an exchange of packets from one side to the other where the other is aware of the entire "state", e.g. the total size of data being transmitted, and the progress of that transmission, and dropped packets can be re-sent at the request of the receiving end

TLS / SSL I can't remember if there is some extra state maintained such that the browser doesn't have to fully re-negogiate the secure connection after a disconnect, but I suppose it would be a possbility

really it comes down to what your protocol is and how you want to design it.
I tend to agree with this user

I don't know what you're asking.
x := func(params){
...
};
func(params, x);


I will look into it for use but also for education, I didn't realize TLS could be used without encryption. In my particular case none of the data will be sensitive. In practice I'd love to use a de-facto standard that just handles state for me behind my application instead of designing that API myself, but I am also curious about how it's done right.

Can you elaborate? I can't learn what I'm doing wrong if you don't tell me. If you know there are a lot of resources, I'd appreciate you linking me to one because I obviously am requesting them, this is because I can't find them.

The resources I come across when looking for network programming are either too basic (hello world for sockets) or beyond the desired scope (demonstrating concepts on top of other protocols, not how to design your own).

This is kind of what I'm looking for, I guess the points where resuming would be possible and beneficial will be obvious when writing a reference implementation. Keep state out of mind as much as possible during the protocol design, but see about doing ad-hoc state where it'd be convenient. Although the way I'm thinking I'd have some wildcard optional "extension" field where something like state handles would be used, is something like this appropriate or bad?

I don't have any experience with py2exe, but I would think like most interpreted-to-binary converters it just packages all the source files along with an interpreter into a single executable.

given the fact he followed it up with talking about static typing, one would assume he meant dynamically typed language
>read the rest of your post
ah i thought you were being a pedant

>>read the rest of your post
>ah i thought you were being a pedant
What is this supposed to mean?

just bought the algorithm design manual. what am i in for

I appreciate the input, the different OSI layers and data encapsulation methods are what throw me for a loop. I'm trying to find out where to best implement what kind of error handling. Like you mentioned with TCP I don't have to worry about ordering, and I'm made aware when something goes wrong which is nice, so there's no concern there, if I were to use something like UDP, I'd have to think about all that myself. But even on top of these things I'm trying to best figure out what and where to make my own "reliability" features, designing a protocol seems easy if you just assume everything will always work, but then when implementing it you have to consider all the point where things can fail, trying to strike a sane level of grace in regards to network failure is what I'm trying to learn now, if that makes sense.

I'm getting the impression that it's something I should think about less, instead I should just bail out early on failure and start again. Assume reliability is there and don't try to add it myself since that's more the realm of other OSI levels. Does that sound sane?

Right, methods are just functions. But they can be very polymorphic and dispatch based on runtime type information ( docs.julialang.org/en/stable/manual/methods/ ).

i thought you were pointing out a saying a language is dynamic doesn't make much sense, and not that you were genuinely ignorant

>i thought you were pointing out a saying a language is dynamic doesn't make much sense
And I was.

>and not that you were genuinely ignorant
Explain

Who-care-th for C and death to functional languages.

oh

stop being pedantic then

No

kys cuck

>kys
Sure, let's do it together :3

>cuck
I can't be a cuck if I never had a girlfriend.

I've known how to program for a while and have helped others by making scripts for them or things like that.

But how am I supposed to come up with a project to work on myself? I have the creativity of the color grey.

what's your goal? are you an undergraduate looking for experience for getting internships? ask your professors if you could help them with their research in any way

General anxiety is hampering my concentration.

I got stressed by reading this post.

I'm a youngfag who just graduated from high school and community college. I still have a little over a month before I move into "real" college.

In the meantime, is it possible to build my profile/portfolio somehow by working on personal projects?

acquire a light form of alcoholism

Is there a way in C to check if I have the permissions to open a file without actually needing to open it?
This is on Linux, by the way.

Idk, check out POSIX and Linux system calls. There wouldn't be a portable way of doing it using the C standard library, since the standard doesn't even assume the existence of directories.

Yes opengroup.org/onlinepubs/000095399/functions/stat.html and pubs.opengroup.org/onlinepubs/9699919799/functions/access.html

can someone explain why

SDL_Rect rect = SDL_Rect(0, 10, 10, 10);

is allowed?

I come from C# and Java, so trying to understand that.

I get this, but on the spot it might be cheeky

How long does it take to get good at very low level reverse engineering and programming?

Like this guy working on getting Linux running on PS4
youtube.com/watch?v=-AoHGJ1g9aM

Cut out sugar and caffeine COMPLETELY. Not even 1 pico gram of either for at least 2 days.

It isn't.

I'm using POSIX file I/O.

>access
Oh right. I didn't realise that did permission checks; I thought that just checks if it exists.
I actually need an effective uid check, so I guess I'll have to use the non-standard eaccess.

It works on my code.

if you're already admitted into college develop your skills before you get in. after you're in there, keep your ear to the ground for students doing things like app development or websites. try not to be a total shut in, right? if you're one of the most proficient people, other students will be more willing to work with you than if you're less proficient than the average person. in the meantime i'd recommend just building a foundation and doing self study

books i'd recommend:
- grokking algorithms (i never read it, hear its good for newbies). introduction to algorithms is what your algorithm class will likely use and it's hard as shit (i read it)
- dive deep into python3. not good for anything more than learning python, but python's a good scripting language
- K&R C. some knowledge that transfers over to an operating systems class
- SICP. knowledge that transfers over to programming in general and to year 3/4 programming classes that will likely include scheme at least sometimes
- D is for Digital. this is actually a really enjoyable book, it's a bit like taking 2 big steps back and taking a scenic look at the expanse that is computer science. not a difficult read at all. i really like this book

Working != allowed/api legal, it's only syntactically legal, which means it's probably not guaranteed to work reliably forever, it heavily depends on what you're doing, maybe it works on accident, maybe packing or a compiler optimisation will break it. In this specific case I don't know (SDL), but you said you're coming from managed languages where saftey is more or less guaranteed, that's not the case in unmanaged languages.

What's the proper C++ way to write:

SDL_Rect rect = new SDL_Rect(0,0,0,0);

Obviously I mean without using new or a pointer.

yes.
I gave the website session example as an example of how state / reliability that was built independent of any protocol e.g. TCP / HTTP / TLS, and it is something web developers implemented for website IAM and as a convenience we are essentially getting some kind of state management on the server side, if that makes sense.

I don't know what your protocol is doing, and it is ultimately up to you to design it how you want but honestly the complexity behind this kind of server-side state management (client has to know something about it too) may outweigh the benefits

Again I'm not familiar with SDL but I'm going to make the assumption that you don't.

You want a rectangle, so what you need to do is decide where you're going to use it, if you're going to use it inside the local scope you can just declare one, set values on it, use it, and then it will go away. Remember though that when you declare it the memory isn't initialized, it's going to be garbage, so it's best to just get one returned that has the 0 values for everything.

But if you want to use it outside of the local scope you're going to have to allocate memory for it on the heap and remember to free it later. SDL is a C library so you should probably use C syntax for it.

SDL_Rect rect = SDL_Rect{0,0,0,0}; will give you a 0 initialized rect on the stack to use in the scope you're in, alternatively you'll have to allocate space for it.

SDL_Rect rect = malloc(sizeof (SDL_Rect));
doThingWithRect(Rect);
free(rect);


If you're using a C++ compiler though you'd either have to cast the malloc return to an SDL Rect or you could probably use C++ keywords new and delete depending on your preference.

What specifically are you trying to do and why do you want to avoid a pointer to a rect?

I'd assume if you say you can just malloc something that you're not doing any type of memory management scheme.
Just my 2 cents.

thanks for the books user

what if I use the rectangle inside an object?
will the rect be on scope as long as the object is alive?

If your object has storage for a rect and you assign a rect to that member, then it will have the same scope as the object. obj.rect = SDL_Rect{0,0,0,0};

Depending on what you're doing though and how you do it, you might be better of just allocating it on the heap and storing a reference to it, it's faster to copy references around than whole types. For instance if you're passing the parent object around a lot, you should probably just store a reference to the rect on the object and delete it when you're done with it, otherwise when passing the object by value, you'll be copying that rect into the function local scope every time, unless of course you're passing a reference to the parent object. I'm sorry if that's confusing, without knowing your level of understanding of memory, plus what your intentions are, I can't explain that well.

Haskell faggot here.
Can someone explain why zipWith . uncurry has type (a -> b1 -> b -> c) -> [(a, b1)] -> [b] -> [c]? I'm trying to wrap my head around composition but I'm dumb as fuck

I'm just making pong bro.

I just discovered python zip()

it feels so good

kek

console.log('Hello, world!');
// coding is so much fun and easy :DDDD

The tricky thing is that there's a lot of ways to implement pong and they can be wildly different, some ways are more "correct" than others. Graphics is/are one of the few places people really care about performance, so stuff like allocation and referencing are usually very specific and tight. More over going from something like C# and Java to C++ means learning all about memory management which is a whole beast of its own, it's something you will have to learn as its a core part of unmanaged languages.

I don't mean any offense in my statements if that's what you think, I'm just trying to better understand your situation so that I can give more helpful advice. Intent is another big one, you could be doing this for education in where you'd want to make pong as efficient as possible to learn how it's done, or if you're just doing it for assignment you can be like "who cares how slow it is".

I just want to make a pong clone so I can make later breakout, then maybe tetris, then make a small 2D real game, and work out until I make cave story.

Neat, I wish you luck and hope you have fun with it along the way. Jumping back though, is there anything you're still unsure of that I might be able to explain?

memory management is my biggest problem right now.

you know, pointer shit.

like I have a rect that is in the stack, but the SDL_Fill takes a pointer, how do I combine both?

You can use the "Address-of" operator (&) on a variable even if it's in the stack.

int x = 3;
int *p = &x;
// p == &x
functionThatTakesApointerToInt(&x);
//this works the same
functionThatTakesApointerToInt(p);

Use the address-of operator '&' to create a pointer to the object.

>like I have a rect that is in the stack, but the SDL_Fill takes a pointer, how do I combine both?
The unary & operator takes a name (or a reference in C++, which is not exactly quite the same thing, but close enough) and converts it to a pointer. Say if your rectangle is called r, then a pointer to it is called &r.

thanks.

got some invalid use of incomplete type error (sdl_window)

any help?

In the library, SDL_Window is only ever handled by pointers. I'd suggest keeping it that way in your code; you should never be manually dereferencing an SDL_Window* or using a stack-allocated SDL_Window. Changing your code to only ever use SDL_Window*, and never SDL_Window, should fix it.

You're trying to use a type (sdl_window) before it was defined, if that's a standard SDL type then you probably forgot to include the header it's define in, if that's one of your types then you need to declare it yourself somewhere before(in literal/lexical scope) you reference it, typically in a header of your own.

zipWith . uncurry (a -> b1 -> b -> c) =
zipWith ((a, b1) -> b -> c)

wait, is SDL_Window diferent than a SDL_Surface, in the sense I shouldn't blit to the window but to the SDL_Surface instead?

window->format
I don't know where you read you could do this, but the error you're getting suggests it's deprecated. When you apply the -> operator to a pointer and a field name, it dereferences the pointer to produce the value of the field. However, you can't dereference a pointer to an incomplete type (SDL_Window), because your code doesn't know the size, alignment, or layout of the value it would have to produce.

>wait, is SDL_Window diferent than a SDL_Surface, in the sense I shouldn't blit to the window but to the SDL_Surface instead?
Yes. SDL_Window and SDL_Surface are different types. Indeed you cannot blit directly to an SDL_Window. However, if I recall, there should be some function you can call to obtain the window's surface.

that makes sense, I'm retarded then.

Is this accurate?

Yes, that is an accurate depiction of what the kind of faggot who would dress like that thinks.

Learning!

Go is so damn easy/nice to use.

I don't understand where the b1 comes from, could you explain it a bit more?

>the kind of faggot
Screw you.
Reminder that there's literally nothing wrong with sucking cock / not being masc and it's mean and inaccurate to conflate that sort of lifestyle with holding unpopular or objectively incorrect opinions.

imagine thinking python is a functional language