/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: haskell tiddies.png (1075x1518, 1.76M)

Other urls found in this thread:

github.com/electron/electron
gitlab.com/spacegeneral/moonrabbit-os
en.wikipedia.org/wiki/Learning_to_rank
twitter.com/NSFWRedditGif

i don't know my dude, down the rabbit hole i go
BFD (GNU Binutils) 2.29 assertion fail /build/mingw-w64-binutils/src/binutils-2.29/bfd/cofflink.c:265

Thank you for using a programming-related non-trap anime image.

Thank you for not using a trap image.

nth for Nim!

Thinking about picking up SICP.
But im not sure if I want to do that,my c skills are probably not up to par.

making a python script to make a visualization for an algorithm

According to CTCI hash tables are the most common data structure used in interviews but there's many ways to sort/search through one. What would be the most efficient and quickest algorithm to do this? BST or is that overkill?

Attached: 1514694727315.png (645x729, 82K)

nobody cares
nobody cares

What kind of hash tables are you talking about? The hash table I learned about puts keys into buckets according to a hash function.

stop

Attached: plsnobully.png (710x384, 192K)

Why do programming languages insist on making these super clever and magical string types that end up being useless for most purposes?
>let's call it "string"
>it holds bytes
>it is handled as utf-8 text
>except when it's not
>it cannot be split into incorrect parts
>except when it can be
>it is checked to be correct
>except when it's not
Why can't they just make separate types for character encodings and use byte array for unformatted data?

In CTCI examples they're just using a java hashmap. So just normal ones I guess.

Nitpicking here: you don't implement a hash table with a BST. Hash tables and BSTs are both implementations of the dictionary (map, associative array, etc.) abstract data type. If they ask for a hash table, they want a hash table, although there are still variations corresponding to different collision resolution methods.

no one cares

uses scheme not C retard

>but there's many ways to sort/search through one
Loop through the array backing the hash table.

Why not just have a string type for strings and a byte array type for arrays of bytes? Wouldn't that make the most sense?

I like how Rust does it. Shoot me for that, but they're very clear that [u8] (resp. Vec) is for unformatted data and that str (resp. String) is for UTF-8 encoded strings, and the latter has checks in place to prevent you from e.g. splitting in the middle of a code point.

Is it really that simple? Assume it's already sorted then O(n) is fine?

Searching a hash table is O(1). Just hash the key and go to the slot. I don't think there's a notion of sorting a hash table either. The hash function can be replaced then all keys in the table must be hashed again.

a forum/blog/chat engine for node.js

> I don't think there's a notion of sorting a hash table either.
Oh cool I didn't know that. So basically what said as well. Thanks!

coding outside. i can't see shit because everything is themed dark.

Really? I guess I'll have to put aside the memes and actually look into this language.

nobody?


cares

What memes?

Hash tables are generally not in sorted order.
When user says searching is O(1) he means looking up one key.
If you need to iterate through all the entries or get list of entries they will not be in any specific order, unless the specific implementation does some extra stuff to guarantee that.

>op asks what you're working on
>haha le nobody cares XD *le epic troll face*

Hmmm shouldn't you be working on something instead of being rude user?

Attached: joe-gato-gallery-impractical-jokers-tru-tv-325.jpg (325x400, 64K)

lookup is *expected* O(1). it's not a general time complexity, but one for a specific class of random inputs.

yes... perfectly uniform hash functions are hard to come by

On plain old C I have an if statement that I want to keep simple
Is it possible to write something like:
if input != '1', '2', '3', '4' '5'{}
is this allowed or do i have to type it differently?
The thing is that input is a char variable.

Attached: 1306913541634.jpg (185x301, 12K)

What does this line do in Python?

attractions_for_destinations = attractions[destination_index].append(attractions)

gcc has an extension for it in switch statements

Well, it really depends. For that example, since all those characters are contiguous in ASCII, you can use input < '1' || input > '5' as your condition.

It's just an array of arrays, so you're adding an element to attractions[index] but I don't think append returns anything so it most likely assigns None to the variable.

In general, though, no, you'd have to write it as input != '1' && input != '2' && input != '3' && ....

Hmm I see now, and know what to do

Attached: 1416113994078.png (512x323, 19K)

>go through someone's code
>variable is named 'cum_reward'

Attached: 1475236991066.jpg (237x213, 12K)

I graduated a year ago and after neeting it up for a year I'm ready to be a good little wagie
Issue is I haven't written a single line of code in a year and I need to brush up my skills.
What are some good resources to get started and actually learn good practices, build a portfolio and learn life life shit instead of the usual tutorials that start with "this dog is an object..." I already know all the fundamentals and basics, just want a challenging project that guides me through real world work scenarios

Attached: 1523504662597.jpg (600x481, 44K)

dumb frogposter

Idiota postador de rãs

Attached: 1505546396485.png (865x1645, 1.26M)

u r doomed ha ha ha

>be CTO of WD
>have to loop over N colors...
>use if statement to reset counter to 0
what the actual fuck?

hmm
undefined reference to `__stack_chk_fail'

find an open source project and try to contribute 1 line of code that is not grammar errors.

A whole year? What the fuck did you do? Watch chuunibyou and jerk your little dick off?

>think you're clever for using mod
>the compiler optimizes both to the same thing
>if 0 actually has clearer intent in the code
I don't see anything wrong with it

What is a non-shit way to make a nice Desktop GUI in Python? I've made a super autistic tkinter gui plenty of times before but it seems fucking impossible to make them look like they aren't tkinter. Is Kivy a meme?

Comes from libc apparently. What are your linker arguments?

bunch of memes, everyone disregard this picture

I've only ever used tkinter and it sucked.
Are there QT bindings for python?

well the problem is that I couldn't compile with the default LDFLAGS because Arch adds some shitty -z flag that's not recognized, so I saw another library doing unset LDFLAGS but I guess it worked for them because they're building a dynamic library whereas I'm trying to make a static one and it needs the standard shit and I'm going to assume unset LDFLAGS wipes the linker flags completely and not just the custom ones

>he wants to write a desktop application with a scripting language

I have no problem motivating myself to work on a project when it's something that interests me, but how the fuck do you motivate yourself to learn more core CS concepts to make yourself a better programmer so you can build more and more interesting projects?

I KNOW that learning all these various forms of bullshit esoteric trees and data structures will come in handy eventually, but how do you motivate to study that stuff?

Attached: 1546365024482.png (419x398, 191K)

github.com/electron/electron

Can anyone redpill me on firecode.io?

Attached: C6Wx8_jXQAAgDyy.jpg (528x960, 40K)

It is a frontend for several well-used data processing/analysis scripts so that autists at work don't have to figure out which script does what.

Are you suggesting I write the GUI in a different language to the functionality?

Winter vacations! Which means I can come back to my ongoing osdev pet project...
Mostly bugfixes / security enhancements, but I also ported a nifty (pic related) NES emulator.
I also implemented some UX improvements, such as adding syntax highlight where needed and adding proper management of "keyup" events (the previous implementation was just a stub)

Attached: screen.png (1024x797, 33K)

The trick is to find esoteric data structures interesting.

Attached: 1520943284544.png (787x796, 151K)

Looks great. How do I get into hobby OS development? I built a small compiler to x64 so I at least know some assembly, but I haven't done anything with OS outside of one course in college.

That's amazing! Are you making it open source?

gitlab.com/spacegeneral/moonrabbit-os

neat

Thanks user.
I got into hobby osdev a couple of years ago, following a blog about kernel development in rust.
I ultimately found out that rust wasn't my calling, so one year later I started over in C (the osdev wiki has nice tutorials for starting out). I have been working on it intermittently for about one year as of November 2018.
This cunning user already found it, all open source.

introduction to algorithms is a fucking trash book for learning by yourself

>esoteric trees and data structures
what do you consider esoteric?

>esoteric data structures
Like what?

i'm creating a grading system to determine the best quality item in a set of items. there are several quantifiable factors that I've identified but i have no idea where to start on how each factor would impact the grade i assign an item. what should i do when a factor is desirable? add? or do i multiply by like 1.1? is there a word that describes what i'm trying to do.

Attached: 0-aggretsukojpg.jpg (940x488, 39K)

hahahaha oh man

if a method throws an exception on certain argument values, should i check that those arguments are in range before the call, or catch the exception on error?

multiplication is best for non-alike attributes e.g. for a computer, RAM speed, RAM capacity, SSD capacity, CPU clock speed.

Addition should be used for alike attributes, e.g. 1TB hard drive + 1TB hard drive = 2TB hard drive

Divide for non-desirable things e.g. screen response time, weight of your girlfriend, litres of piss in jugs on your desk

you should try to make sure that the exception doesn't throw, i.e. sanitize earlier. if that isn't possible (i/o, for instance), you'll have to work with the exception.

>esoteric data structures
wat

search for applications of those data structures and incorporate whichever suit your hobby/passion projects.

nice, user. just starred it. I was working on a little embedded RTOS a while back but it's kind of gone to the wayside- I want to try out an interactive desktop OS eventually, though, so I might use yours as a kind of reference.

I'm thinking of just papers/implementations that have specific features/tradeoffs or improvements/extensions of popular structures, e.g. custom tries, sketches, cache policies etc.
For a general one, maybe something like Gomury-Hu trees would be fairly unknown to most devs?

catching before the call will be faster if you already know your arguments can have invalid values, HOWEVER

It might be less lines of code to catch the error if it is well defined.

thanks i'll try that.

Attached: aggretsuko.jpg (3791x2130, 1.53M)

It's an entry level lisp textbook

I have simple set up of a binary tree in C
struct tnode {
int value;
struct tnode* left;
struct tnode* right;
};

struct tnode* nalloc() {
return (struct tnode*) malloc(sizeof(struct tnode));
}
Now to extend this so I can have multiple children I think I should do this?

struct tnode {
int value;
int num_children;
struct tnode** children;
};

struct tnode* nalloc(int num_children) {
return (struct tnode*) malloc(num_children * sizeof(struct tnode));
}

In a higher level language I would use an array of child nodes, but in C an array size should be known at compile time so instead I use a pointer of poiinters. Does this seem correct and idiomatic?

Attached: 1532030970399.png (822x822, 678K)

Woops code blocks got combined, the second half is my attempt to extend to multiple child node support.
struct tnode {
int value;
int num_children;
struct tnode** children;
};

struct tnode* nalloc(int num_children) {
return (struct tnode*) malloc(num_children * sizeof(struct tnode));
}

I just realized my malloc is wrong. I think this is correct
struct tnode* nalloc(int num_children) {
return (struct tnode*) malloc((num_children+1) * sizeof(struct tnode));
}

What are you asking?

The binary version works, and I want to support different number of children per node.
Wanted to check if using double pointer to store these as a sort of list makes sense and if when allocating a new node should I also allocate space for the children?
In hindsight I think no, I should allocate the child "list" separately. I don't know.

If I understand correctly just rescale your quantities to a value between 0 and 1, then multiply that by whatever you think it's worth.

// thing.a is worth 30% of ranking
// thing.b is worth 70% of ranking

rank = (thing.a / max(thing.a)) * 0.3;
rank += (thing.b / max(thing.b)) * 0.7;

Then sort by the rank.

The word you want is scaling.

There are a few ways to do what you want which have different consequences.
Multiplying grades can be dangerous, because it has a much larger effect on high scoring items (1 * 3 = 3, 3 * 3 = 9, delta goes from 2 to 6).

Adding a fixed value can correct for when the median is below some passing grade. This is usually what teachers use to bump up a class mark.

en.wikipedia.org/wiki/Learning_to_rank

To solve this you can just normalise values beforehand. Obviously this requires either a well-known expected range or all of the data before you rank.

that IDE recommend me to program in java in linux

I only skimmed it, but the way you are doing it seems fine.
If this is for some application, I might reconsider if its worth using a general tree, as you can encode any general tree as a binary tree.

Okay, my concern is I tried to be smart and allocate a node with a known number of children but counting them but then I realized I'm not allocating enough for children of those nodes.
Would it make more sense to allocate for just sizeof the struct then assign another malloc function for the children list or something? I feel retarded.
I'll write out function to add data to tree and see where it breaks I guess.

Are there any good resources for networking projects and solutions?

I wrote a simple peer-to-peer system in haskell a few weeks ago, but I can't help but feel its a bit hacked together.

You shouldn't need to allocate enough for the children of those nodes. Your array is just an array of addresses, each address will need to be set to point to a newly allocated node elsewhere.

Don't trust what IDEs recommend you. Do not kill your family, user.

For your own projects do you just use a bunch of libraries or implement data structures yourself? i know the conventional wisdom is to not reinvent the wheel but i just want to do things a certain way without learning a library.

Attached: IMG_5884.jpg (2272x1704, 1.28M)

I'm looking for a way to start at the top left cell and iterate through each row and column on a square grid, and pretty much end up with a filled in circle

Does anyone know a good method to do so?

crud pic related

Attached: algorithm.png (298x295, 110K)

just compare the distance to the centre of the circle to the radius

That makes sense. Each node should be allocates on it's own.
Hypothetically if you knew the final tree size could allocate it all in one go, or would that then require you to have to manually lay the nodes out in the allocated block of memory.