/DPT/ - The Daily Programming Thread

What are you working on, Jow Forums

Previous Thread:

Attached: -g-animeC.png (2560x1440, 703K)

Other urls found in this thread:

codestepbystep.com/problem/list/ruby
github.com/OpenTTD/OpenTTD/blob/5a5944867dfeaa556ec78c23af4796adb28a6a9f/bin/ai/compat_0.7.nut
better-dpt-roll.github.io
twitter.com/SFWRedditImages

I'm trying to get my python workflow set up. I'm using IPython, and really like its quality-of-life improvements over the default python3 shell, but I do have one question.

Is it possible to remove the output of the %load command? Whenever I load a file, I need to press ENTER again, and then I can start typing commands.

Attached: Screen Shot 2019-04-02 at 10.57.22 AM.png (1358x724, 122K)

You don't use a code editor?

Third for fuck anime.

wasm is kill

What do you guys do if you're presented with something you just don't get? I'm in a class, have gotten assistance with the assignment multiple times, and even got an extension on its due date, but no matter what it just doesn't make sense. How do you guys go about handling shit like this?

Attached: woj.jpg (320x265, 24K)

Well, for some reason, emacs is really slow when using ipython, and I'm having other issues with the vanilla python interpreter.

Attached: Screen Shot 2019-04-02 at 11.19.15 AM.png (2054x342, 115K)

Still looking for Nim Full Course kind of video guide or something

why can't i get past the second question and print out the results in a readable format?

class Die:
def __init__(self):
pass

def DieNumber(self):
int(input("How many dice to roll?\n"))

def DieSides(self):
int(input("Which sided die to roll?\n"))

def __repr__(self):
pass

class Dice:
def __init__(self):
pass

dice = []
for dn in str(Die.DieNumber):
dice.append(Die.DieSides)

def DiceRoll(self):
roll = [Die.DieSides(self) for dn in str(Die.DieNumber)]

def __repr__(self):
pass


first_choice = Die()
first_choice.DieNumber()
first_choice.DieSides()
first_set = Dice()
first_set.DiceRoll()
print("You rolled {} {}-sided dice and got {}.\n".format(Die.DieNumber, Die.DieSides, Dice.DiceRoll))


second_choice = Die()
second_choice.DieNumber()
second_choice.DieSides()
second_set = Dice()
second_set.DiceRoll()
print("You rolled {} {}-sided dice and got {}.\n".format(Die.DieNumber, Die.DieSides, Dice.DiceRoll))

Nevermind. The python3 regular interpreter now works fine. I was trying to do something fancy, which ended up screwing the way the interpreter works. At least I have autocomplete with emacs now!

I'm gonna say something super unhelpful: Work Smarter, not Harder.
What is it that you're not getting? Are you asking the right questions when you're getting help, or is it more "I'm stuck... Please help me."
What are you getting stuck on?

That's not very nice, dude.

Why is \g/ so obsessed with C?🐸

because it is shit. just like how /a/ flips when anything gets popular.

libgen the book

C is extremely popular

Jow Forums's scale is not popularity, it's shit.

only one written in 2017

JavaScript rocks!

Attached: js-rocks.png (1000x494, 368K)

it's the one (NIA) still promoted by Andreas.

because all other languages have been delegated to the webdev general so we're stuck with C grandpas and Haskell sojboys

This picture is very cute!

Taking a "data structures" class that is literally just intro to CS repeated. Fuck me. What is a good book to learn the hard stuff? Preferably Python, Java or C++ based. I don't have time to meet with SICP or Hasklel...

The Cormen Algorithms book is pretty good.

You're completely right, but I honestly don't even know where to start. I kinda look at everything and just get a headache(I have a really bad case of stupid).

>I have a really bad case of stupid
Me too, but that's no excuse to give up.

There's this really interesting story from Khan Academy. They split fifth graders into two groups: Group A watch KA videos starting at a 5th grade level and Group B watched videos from the 1st-grade level. It turns out Group B actually improved a lot more than Group A did.
What I'm trying to get at is go to the most basic thing that doesn't make sense to you, and see what about it confuses you.
Is this for a course you're taking?

How may closing >s is acceptable in a declaration of an STL-based templated data structure variable

Yeah. It's essentially babby's first programming, but for some reason the introductory language is Ruby(don't ask me why, I have no idea).

I like Ruby, so I can vouch for it, but something that helps students is force them to solve the problem without a computer, and then program the solution once they solve the problem with pseudocode.
Are you getting stuck on Ruby's syntax? Or is it a more general "I'm not sure how to approach this problem" situation?

Honestly I don't know. I want to say the latter, but I'm not certain.

3 then start using aliases

Well, I'm not sure how much more help I can be, but try doing some of the problems on this website:
codestepbystep.com/problem/list/ruby
There are other resources too. Don't be afraid of using another language to help you understand programming and then move on to Ruby.

Well, one issue is in this line:
for dn in str(Die.DieNumber):
dice.append(Die.DieSides)


Printing out what str(Die.DieNumber) is, I found out it's the string representation of the function. It's essentially calling Die.DieSides once per character in the string.

I then printed out the array of die, and got a *ton* of strings.
Make sure that you're using getter and setter methods in your classes correctly.

Attached: Screen Shot 2019-04-02 at 11.48.34 AM.png (2000x1344, 319K)

Well maybe describe what's wrong you massive faggot instead of wallowing in self-pity moaning "I don't understa-a-and!"

Here's an exercise: solve the problem in a pseudocode that will magically have instructions for anything you want. This should be trivial provided you understand what's being asked of you in the first place.
Then go about trying to break each instruction down. If you get stuck there, post some details here. If not, keep going. At some point you'll have detailed pseudocode directly translatable to a program, if you have that, that means you're just stuck on the syntax and that's easy.

why worst languages have best tools?

that show was trash

Crappy vector.

because you are deluded

i thought in python you didn't need to mess with set/getters. im not really sure what that would be in python. thought, when iw as able to get past the 2nd question, it printed everything out fine except for calling for the 0x0 value instead of a readable format. how would this be affected by what you're printing?

Working on my IRC client a bit. Added an API to my socket class for connecting to a hostname/port (rather than only supporting IPv4Address/port.) Turned out I had a bug in my DNS client where I would interpret all records as if they were A records. Having fun with programming, basically.

Attached: gsocket_connect.png (1440x900, 416K)

to put it basically, I need to take a .txt document that looks something like this:
"a;b;c"
"d;e;f"
and create a new .txt document with the above text
AND a new piece of text at the end of each line. Basically I want:
"a;b;c;3"
"d;e;f;6"
3 and 6 being determined by the 3rd piece of text(c is 3rd letter, f is 6th)
I need to be able to do this for as many lines as necessary, I need to do so using an array to store the text, using a split to divide the values based on ";", create and use a function that can calculate the new value based on the third existing one, loop as many times as needed for each line, and export all the data to the new .txt. I understand the pseudocode(mostly), but I'm at a loss for things like How do I divide the text properly, should I have just one array for the three-four characters on each line or should i have another array for each line as well, how do assign each word to a set place in the array, do I reset the array for each line or continue adding onto it, among other issues. Basically really easy stuff that I somehow can't wrap my head around.

How the fuck is one supposed to implement user permissions?

I'm developing a java + postgres employee management app, but cant' figure out what kind of pattern suits this best.

I plan on having 3 tables in the DB: users ---- roles ---- permissions. But how should I handle it within java? Am I meant to simply manually look for role name string when performing a permission check?

Attached: iu[1].jpg (431x431, 18K)

Had a database entity which could have multiple flags assigned to it and I figured I'd just save the flags as a bit mask in a single column, even had a minor hard-on for how space-efficient the whole thing was
Now I need to read all entities with only certain flags enabled and I just realized that saving them as a bitmask means I need to use bitwise operations inside my SELECTs
I am not a smart person

Attached: 1401126578487.jpg (192x220, 19K)

should note:
3 and 6 are determined by c and f being the 3rd and 6th letters of the alphabet, not 3rd and 6th in the document, so if it were "a;b;z" it'd need to output "a;b;z;26"
Also, I'm really confused as to what values should be defined in the initial class and what should be defined in the general program itself

>I am not a smart person
Join the club

Attached: 1514866463694.jpg (1920x1080, 573K)

On an assignment in a course unit I failed 3 times.

this may sound harsh but that code makes no sense
why are you getting input just to throw it away?
why are you declaring all these functions that don't do anything?
why are you printing functions?
where's the randomness?
and so on.
I suggest starting with something simpler, look up tutorials on classes etc.

I got some basic programming knowledge but I have no idea what to work on and how to improve my skills. Any tips?

Attached: 1552079213863.png (410x465, 20K)

Calculate the concrete permissions whenever the user logs in and cache them in memory, invalidate and recalculate them when the user changes roles or the role changes permissions, use the cache to check for permissions

>By convention, traits are always implemented as structs. Another convention is that the structs used to implement traits are known as trait classes.
Fucking sepplesers

How did you keep going? I haven't even technically failed this assignment yet and I still feel miserable. Being presented with something like this that I just don't understand regardless of the time or effort put in is incredibly demoralizing and results in compounded negative thoughts for me, resulting in me more or less shutting down within two to three hours.

Attached: 02f.jpg (655x527, 36K)

have you tried what I told you last time?
can you write a program that reads a file line by line?

do something you'd like to
If you got nothing to strive for, programming is the least of your problems at the time

I think part of the issue is just looking up ruby standard practice and what's in the library, but you do have some issues with actually understanding the pseudocode.
To get these out of the way:
>how do I divide the text properly
this entirely depends on the ruby standard library (I have never used ruby so I don't know). Look up on stackoverflow or something.
>should I have just one array or also store every line in another array
That depends on how you take input and provide output. Are you able to stream the files in and out? If so, you might be able to line by line. Your algorithm would then be:
string line = read_line_from_file();
string newline = do_processing_to_generate_the_line_with_the_extra_number_added(line);
append_line_to_file(newline);

Where read_line_from_file() and append_line_to_file(string) would be ruby library functions.
If you can't do this, then the other approach is to load the entire file into an array, then loop over the array calling do_processing_to_generate_the_line_with_the_extra_number_added() for every element, and then save the output. Here you could use a second array to store all the new lines, or you could try to modify the array of lines in place. Either way, again, this depends on what ruby offers you; read the official docs, search stackoverflow, etc.

Now, with code architectured like that, all you need to think about is your do_processing_to_generate_the_line_with_the_extra_number_added() function which takes a string and returns a string. The good thing here is that if you make this a pure function (with no side-effects), you won't have to worry about things like "do I reset the array for each line or not".

Try to go from here and see if you get stuck again.

This image has always bothered me, what the fuck language is that on the laptop? It's hard to read but it's not C.

Something Something

What's wrong with that? Other than traits in general sound retarded but I've never needed to touch them myself so I can't really comment on that

bool operator t1; }

Attached: 1540316307549.gif (245x222, 177K)

google would have told you it's R

I whipped this up just now, it seems to work
my_input_file = File.open("Project_6_Input.txt", "r")
input_line = my_input_file.gets
while(input_line = my_input_file.gets)
puts input_line
input_line = input_line.to_i + 1
end

this may sound harsh, but if i knew what i was doing, i wouldn't be asking for help.

I'm merely trying to make a set of dice that the user manipulates and rolls, which resets every time so the user must input each time.

>get input to throw away (again new set of dice)
>declaring functions that don't do anything (i don't get what you mean? i call die to be able to call the methods and then call dice to be able to call the list. this is what i think im doing, at least.)
>printing functions (to see if things are working the way i intend them to. (re: the 0x0 values instead of string format)
>randomness (im using list comprehension to grab a value randomly from a max value set by user)

Levels of permission should be prime numbers, and a user should have an int that's a product of every permission he has

Attached: 1499490884218.jpg (284x283, 24K)

Something something there are two kinds of people, those who intuitively understand programming and algorithms and are happy with it and those who struggle writing a fizzbuzz and seriously can't code.

I remember reading about a detailed study of CS students where freshment with zero programming experienced were asked to answer some questions relating to fundamental programming concepts, like variable assignment, and then were asked the same questions again after a term or two. Those who intuitively picked consistent answers first time around later gave correct answers the second time, those who had no idea what they were doing the first time around and selected at random still had no idea after taking the course on programming.

What's a regular expression that matches only the generals for Clover?

Should enums be typedefed?

The only things that should be typedefed are opaque handles.

pretty sure it's squirrel
github.com/OpenTTD/OpenTTD/blob/5a5944867dfeaa556ec78c23af4796adb28a6a9f/bin/ai/compat_0.7.nut

They're just integers. It's the same as #define.

Here I'll assume "gets" reads a line (and keeps track of where it is in the file) and "puts" appends a line (since like I said I don't know a lick of ruby).

First of all, you're skipping the first line: while loops first evaluate their condition, so you do "input_line = my_input_file.gets" twice in a row.

Secondly, is that puts only for debugging? Because if that's an attempt to write the actual output, you should know that you're outputting it before actually doing anything to the line. It should probably come afterwards.

But otherwise you're on the right track. Inside your while loop you now need to split the input_line, take the last element of the array, find the corresponding number, append it to the array, and then join up the array back into a string before outputting that new string. You should be able to google for each of these steps to get ideas on how to proceed.

/.*general$/ will match a lot, but many don't have "general" in their name so you'll have to hunt for the rest by hand
/\/\w{2-4}\// or something along those lines (untested, written off the top of my head) might be more thorough, but sometimes people omit the /xxx/ part from the subject

That's it, I think you're right. I never even heard of squirrel before.

then get that roll picture for projects or better-dpt-roll.github.io and do them by order/interest

Python and regular expressions are too comfy, lads

Attached: 1550614143633.png (749x865, 78K)

>get input to throw away (again new set of dice)
def DieNumber(self):
int(input("How many dice to roll?\n"))

this function asks the user for input. the input is then thrown away without ever being looked at
>declaring functions that don't do anything
__init__ and __repr__ don't do anything
this is not such an important point, just unnecessary
>printing functions
I can't see what kind of useful information you'd get by printing functions
>im using list comprehension to grab a value randomly from a max value set by user
that's not what list comprehensions do

good. now try to split the line, and print the parts individually
also I'm not sure what input_line = input_line.to_i + 1 is for, doesn't seem to do anything.

>he asks, in one of those generals

You're right, it doesn't. I thought it might be needed to make sure the program knows to move forward past the first line, but I was mistaken. I will likely need something similar for the program to know to split and transfer past the first line, though.

me neither, I just googled some of the code in the picture and then looked up what the hell a .nut extension is

// Like this?
typedef struct { ... } stuff;
// Or like this?
typedef struct { ... } *stuff;

Thanks, I will do my best!

Attached: ChiyomaruHeart.png (1227x1228, 2.19M)

I basically take financial risks until I get better at it. Problem is when dealing with lecturers who either force you to do a task a certain way or give harsh penalties if your code does not compile fast enough.

Although I am curious, why does it need while(input_line = my_input_file.gets)? It clearly does need it, as it doesn't work without it, but why doesn't simply puts input_line work? am I missing something obvious?

FLOOOOOEEEEENS
pic related

Attached: Screenshot_Clover_20190402-152734.png (1080x1920, 116K)

gets takes care of that, it will always return a new line when you call it, so your input_line get's a new line for every iteration.

you're still missing the point about how i don't know what im doing; your post doesn't help me much. ive already pointed out how i don't know how to make the results of the roll readable, so telling me that repr isnt necessary doesn't help me, as ive already gathered that from pointing out how the results are printed in the 0x0 value thing instead of a readable format. (which again, i thought repr did but i still don't know and have tried for way too long to figure this out) ive tried multiple ways of doing this and with the ocean of information out there, finding the right island is actually very hard to do.

how would you write this out then? ive already made shitty iterations of this project but im trying to do things in a more concise and clean manner instead of spaghetts. is there any source of information that cleanly explains what im trying to do without using retarded examples that actually confuse the reader instead of helping?

this basically means "while there is still data left to process, read one line from the file and assign it to input_line for processing". in the next iteration, it assigns a new line to input_line, and so on

More like
// handle.h
typedef struct handle *Handle;

void handle_foo(Handle);
void handle_bar(Handle);
void handle_baz(Handle);
// handle.c
struct handle
{
// impl
};

my 20 minute nap turned into a 3 hour one again

Attached: 1550509123815.jpg (942x890, 108K)

>..., and recursion is to functional languages as TV is to American pop culture: inseparable)
Based Scott bringing the heat

It's called depression, user

>defining structs in *.c
This actually works?
Will any separate file just need to #include the header to see this?

It's called being a lazy faggot

Depression is not real
t. Someone who has been "depressed" for 15 years

there's a lot of python dice rolling examples out there, pick one and try to understand how it works (ask here if necessary) and see if you can adapt it. start with making the user input a number of sides instead of having it always be 6, then try adding more dice.

Yeah, it's called forward declaration. You'll only be able to manipulate the struct through non-dereferenceable pointers unless you're in the .c file though. That's why it's called "opaque".

Any opinions on Codesignal?

A friend recommended it to me, and it's pretty fun, but I have never heard of it before

>he thinks his ""depression"" was the same thing as people actually suffering from major depression
How to spot a normalfaggot

every example has __repr__ which is why i used it in the first place...

Am I the only one who thinks objects and classes are bullshit? I'm having to learn Java for a class, and this """"organization""""" into objs and classes in BlueJ seems like such time wasting bullshit. I wish I could just use C instead.

Sorry about that, I think I need glasses but I have no optometrist money.

Huh, The more you know.
Thanks, user!

C++ is best of both worlds

could you post an example?
the ones I'm finding don't use it