/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: HAPPENING.png (690x764, 415K)

Other urls found in this thread:

youtu.be/BWvSSsKCiAw?t=952
yegor256.com/2018/11/13/bigotry.html
en.wikipedia.org/wiki/IEEE_754
pastebin.com/nGZvVBXw
pastebin.com/2c08UWHS
plugins.jetbrains.com/plugin/10804-doki-doki-literature-club-theme
twitter.com/NSFWRedditVideo

I don't even remotely understand or care about this image, but I appreciate the non-anime programming for retards thread.

based op

Nice grammar, tard.

Workin on some perl for class

Yes it's terrible

Attached: perlscr.png (1600x900, 128K)

What class?

Assange is a hacker who has contributed to postgresql, netbsd, ... he may be prosecuted for high treason towards the united states of america.

#define FREADW(buf, cnt, file) (fread((buf), (cnt), 1, (file)) == (cnt))

Good or bad?

A general scripting course

We're taught bash, python, and then perl

Macros are always a bad idea. Is there a reason you can't use a function for this?

"Upon successful completion, fread() shall return the number of elements successfully read which is less than nitems only if a read error or end-of-file is encountered."

>can't read
literally nothing wrong with it you brainlet
also ^ not writing a story here mate? it's literally a shitpost on Jow Forums you fruitcake; no one follows proPER grammer or spelling or literally gives two fucks About that shit except for autistic fags like yourself;!;:?

get ass-mad freak,

Attached: autistic helmet.png (640x404, 307K)

yeah, think about what would happen if FREADW(..., ++a, ...)

Well, is there such a function?
Right. Do you mean I should change it to this?
#define FREADW(buf, cnt, file) (!(fread((buf), (cnt), 1, (file)) < (cnt)))

That's not an intended use case, so who cares.

Make it a function instead. I don't see the point in making it a macro. If your optimizing compiler doesn't optimize away the wrapping call you should focus on getting a new optimizing compiler before doing things like this.

This is of course ignoring the possibility that you're working on some ancient platform with no real support. I say a macro is better than trying to build optimizations into ancient compilers.
A function would sort this too. Of course you could also rewrite your macro to capture the cnt value once.

trying to learn some erlang. It's my first fp language beyond scheme in SICP course

Are functions like this an abominations that should be purged and rewritten or is it ok in a functional world, it's just me not getting used to it?
divLine([Xfirst|Xtail],
[YFirst,YSecond|YTail]) ->
divLine(Xtail, [YSecond|YTail], [(YFirst - YSecond) / Xfirst]).
divLine([Xfirst|Xtail],
[YFirst,YSecond|YTail],
Result) ->
divLine(Xtail, [YSecond|YTail], [(YFirst - YSecond) / Xfirst|Result]);
divLine(_,_,Result) -> Result.
[\code]

I insulted your grammar because "I appreciate the non-anime programming for retards thread" doesn't mean what you wanted it to mean.
You're calling yourself a retard, lmao.

cnt = fread(buf, max_cnt, 1, file);

if (0 > ferror(file))
perror("Could not read file");

I'm watching this talk:
youtu.be/BWvSSsKCiAw?t=952
But right here (15:50) I'm confused. What's surprising about this? Seems completely obvious to me. I don't understand what the expected behavior would be in case we didn't expect an ambiguity in referencing string here.
Is this a slide bug?
#include
namespace name {
using namespace std;
struct string{}; //this can be before or after the using
}
using namespace name;
void moo(){
name::string ns;
std::string ss;
string as; //ambiguous
}


I'm thinking this is something people could be confused about more and it fits better with his motivation. So I'm wondering if there's some depth I'm missing in the example or if Titus has some _very_ low standards for C++ programmers.

Attached: file.png (880x410, 191K)

I fully understand what I posted you dumb shit.

You did but every native reading it understood it differently.

not really, sounds like you got it to me.

Is he an American? If not, how can he be prosecuted for high treason? That's like prosecuting an enemy soldier for treason because he shot one of your guys.

But I want to know if I'm at EOF or not.

Show me the code /dpt/.

Attached: quote-talk-is-cheap-show-me-the-code-linus-torvalds-45-66-13.jpg (850x400, 36K)

>w

Attached: 1471290086830.png (196x208, 20K)

I keep rewriting the same shit

Attached: Screenshot from 2018-11-17 04-42-41.png (3840x2160, 593K)

I don't think the US government cares how they justify an unlawful arrest and ruling as long as ignorant masses buy it.

int feof(FILE *stream);

The feof() function shall return non-zero if and only if the end-of-file indicator is set for stream.

Yeah, that seems like a good solution.
13 enum filetype
14 { SCRAPE,
15 TORRENT,
16 UNKNOWN
17 };
18
19 enum filetype what_type(FILE* in)
20 {
21 # define CNT 8
22 enum filetype rc = UNKNOWN;
23 char buf[CNT];
24 fread(buf, CNT, 1, in);
25 if (!(feof(in) || ferror(in)))
26 { if (!memcmp(buf, "d5:files", CNT))
27 rc = SCRAPE;
28 else if (!memcmp(buf, "d4:infod", CNT))
29 rc = TORRENT;
30 }
31 return rc;
32 # undef CNT
33 // "d4:infod5:files";
34 // "d5:files";
35 }
36
37 void fast_forward(FILE* in, enum filetype type)
38 { // there's a small "header" -- this skips over it to get to the repeating part
39 int offset;
40 switch(type)
41 { case SCRAPE:
42 offset = 0;
43 break;
44 case TORRENT:
45 offset = 7;
46 break;
47 default:
48 assert(0);
49 }
50 fseek(in, offset, SEEK_CUR);
51 }

for a second i thought hiro added line numbers
fuck you

Attached: 1483601820443.png (720x720, 357K)

static void extract_initramfs() {
printk("Extracting initramfs... ");
auto *p = kmap(u32(bootinfo.initramfs), bootinfo.initramfs_size, 0);

vfs_mount("ramfs", {}, "a:/");
String path;

tar_foreach(p, [&path](const TarHeader &hdr, const u8 *buf) {
auto size = string_to_uint_octal(hdr.size).value();

path = "a:/";
path += Str(hdr.name, strlen(hdr.name));

if (path.back() == '/') { // This is a directory, create it.
assert(vfs_mkdir(path) == 0);
}
else { // Otherwise this is a file, create it and copy it over.
auto file = vfs_open(path, O_CREATE | O_TRUNCATE).value();
assert(file->write(buf, 0, size) == isize(size));
}
});

kunmap(p, bootinfo.initramfs_size, KUNMAP_FREE);
printk("Done\n");
}

I kept watching.
The ADL segment in this talk is TERRIFYING. That C++ is used in any context of any significant importance is ridiculous.
Stop now. Please.

yegor256.com/2018/11/13/bigotry.html

If I have a set of data points for the velocity and acceleration of an object in an elliptical orbit, how do I find the position of the object at any given time? Assuming at time t = 0, the object is at one of the vertices of the ellipse.

iterating is the only reliable way

Employed Haskell programmer reporting in

Attached: 1474325315193.jpg (636x616, 43K)

give me your job

Attached: deadly loli.jpg (300x222, 9K)

The hard part is the direction. I don't know by how much the object rotates with each step. I know pretty much everything else about the ellipse, though (circumference, semi-major axis, focal length, etc.).

Why larp on an online Bruneian tofu fermenting imageboard?

>Do you agree with these guys? Most probably, just like me, you don’t.
assertion failure

Is there a combined web interface for Git that includes a wiki with the ability to attach files to pages? It should support multiple users

is rust really hard?

No it's just annoying

Not really. More depends on what type you are.
M? Rust is for you.
S? C++ is for you.

Basically it is a less than stellar language with a strict static analysis. But any good static analysis tool for C or C++ can do the same thing as Rust. The only difference is Rust refuses to compile if it deems something is unsafe. A strict static analysis tool will show errors but it isn't tied to the compiler.

M? S?

oh i got it sadomasochism

Attached: 1516991410072.jpg (1280x720, 400K)

Lisp is the most powerful programming language.

no user
you are

I made this horrible mess, just for you.

Attached: file.png (586x417, 49K)

guys what is the best way to measure similarity between two images? I have a program that compares images of typed out letters 0 to 9 to a different font 0-9, I split up each letter into 9 regions and save the black/white pixel ratio for each region and calculate the euclidean distance for it. but basically its shit and guesses almost every letter incorrectly so I'm assuming I need more things to compare but what else even is there to compare?

spectral clustering using features learned from a deep net

doesn't work though.
installed on greasemonkey btw

Odd. What does it write in the console?

is it because i'm using greasemonkey instead of tampermonkey?

Attached: 3333.png (663x243, 14K)

I would guess so but I want it to work for both.

Attached: carsales-2014-01-14.png (1216x647, 55K)

>made by cpp programmer who can't code in rust

>made by rust programmer who can't code in cpp

Can openGL do this?

Attached: _.webm (640x360, 2.36M)

Do what? Render 3D objects?
Yeah of course.

Anyone know perl?

How do I pass arguments, and then pipe in a text file?

For instance I'm trying to count the frequency of words in a text file.

If my text file is "foo bar foo foo bar"

Then I would do

./myfile.pl foo bar < input.txt

foo: 3
bar: 2


I know how to read from ARGV I'm just wondering how I pipe a file in and read from it off of argv

inf bottles of beer on the wall!
inf bottles of beer!
Take one down, pass it around
inf bottles of beer on the wall!

Attached: 1476811327277.jpg (640x480, 38K)

>performing operations on special cases
if you, you know, wanted to perform operations on something it would probably be best if it wasn't a special case

In what way is inf a special case.

It's too hard AND too easy, simultaneously

0 bottles of beer on the wall!
0 bottles of beer!
Take one down, pass it around
18446744073709551615 bottles of beer on the wall!

>String
>strlen
why can't you decide on one

en.wikipedia.org/wiki/IEEE_754 because infinity is returned as a value in boundary cases in the same contexts as NaN, and that operations on infinity are specifically well defined because people apparently don't want their computations to grind to a halt by an exception just because they ran out of precision and wound up naturally dividing by 0

all these programming language wars, what about DB wars?
Let's start with natural vs surrogate keys. My teacher seems fond of surrogate keys, he said that if you're using more than 2 PKs then better to use ID surrogate key or else other tables will have many FKs and it will be annoying and costly to join tables where you need to compare many FKs instead of just one. But it seems to me this gives more drawbacks that benefits.

You can't do INSERT x ON DUPLICATE KEY UPDATE but with natural PKs you can. Also when inserting into a table that has a surrogate FK it seems I need to do a fucking select to find that the correct FK value is.

>Example
I have tables of artists, albums and songs. If I had natural keys I could easily detect a duplicate during INSERT album
because the PK would be artist's name and album's name. With surrogate keys I can't.
Also doing an INSERT of a new song requires me to do a select just to get the correct album ID that was auto-generated from autoincrement.
Enlighten me DB engineers

Because name is defined like this: char name[100];
And I have an overload on String constructor and operators that takes an array of chars with static size to avoid a strlen (because the compiler for some reason rarely decides to optimize strlen out. Beyond me).
So I'd end up concatenating some chars, a null terminator, and a bunch of junk to the string and since String doesn't give a single shit about null terminators shit will hit the fan. I just tried it now and it kernel panicked trying to access a bad optional (duh, because it couldn't find the name).
So I have to call strlen explicitly and wrap it up in a string view and then concatenate that. It's still zero cost besides the strlen.

In my OS I stay away from null terminators in general and use sized strings, even in the syscall interface. I always use Str for string parameters/refs and String for owned strings. I only have bare minimum support for null terminators because unfortunately you can't get completely away from them because lmao fuck you t. C. But I'd still prefer to pretend they don't exist in most places and pretend statically sized char arrays don't have a null terminator anywhere but the end. Anywhere where that isn't true I can explicitly take the length, and that's very rare.
I didn't design the tar spec and it uses null terminators, so oh well.

Who said anything about computers?

You mean ω.

pastebin.com/nGZvVBXw
This works for greasemonkey. Couldn't get the function include to work. And I don't know where my functions end up in greasemonkey. I added a toggle to the tampermonkey version.
pastebin.com/2c08UWHS

Attached: file.png (497x247, 20K)

>implying it makes sense to underflow to 0 in the first place

I would suspect it's because it can cause issues down the line.
For instance, say you insert an artist "System Of A Down", and then add some albums for it. Then you realize it should be spelled "System of a Down". Now you need to change all those referencing that key, which potentially creates issues.
Also, there might be performance issues with strings - it's a mixed bag depending on which database you have.
>If I had natural keys I could easily detect a duplicate during INSERT album
because the PK would be artist's name and album's name. With surrogate keys I can't.
Add a UNIQUE constraint in the table on album_name and artist_name.
>Also doing an INSERT of a new song requires me to do a select just to get the correct album ID that was auto-generated from autoincrement.
Yes, just use a subquery.
INSERT INTO songs (artist, album, song_name) (SELECT id FROM artists WHERE artist_name = :artist), (SELECT id FROM albums WHERE artist_name = :artist AND song_name = :song), :song;

DBfags get out
Not programming.

What is a good programming language to learn if you want a job fast (as in a junior position).
I only have the following: general IT certification from school (4 year course with everything from basic computer stuff to servers and networking), CompTIA A+ and Network+ and HTML5/CSS3.
I was considering python since there is a lot of demand for it over here, JavaScript and PHP is in high demand as well.

C++

>Add a UNIQUE constraint in the table on album_name and artist_name.
I cannot put an album's name as unique because different artists might have same album name.
Is there a way to make the pair (album_name, artist_name) unique?

No job listings for C++ unfortunately.

Yes.
UNIQUE (album_name, artist_name);

Haskell
300k starting
Any woman you want

*woman (male)

How expensive is making a new thread relative to the cost of any other syscall?

Don't you need to be a wizard with math for Haskell ?

No.

HANG. HIM. HIGH.

any linux expert here?

Attached: yuru_yuri_render_pack_by_ganesa221-d79ijbr.png (800x716, 345K)

*python*
class Name(object):
def __init__(self, name):
self.name = name

what is the fucking difference between "class Name(object)" and "class Name()"?

fuck spaces

liar

object will be the superclass in that case. Probably not what you wanted. () are not required if you have no superclass.

Nothing near me unfortunately.

how to make 2d mutableListOf in kotlin?

What do you think about Agile and SCRUM?

plugins.jetbrains.com/plugin/10804-doki-doki-literature-club-theme

Attached: 0.png (1440x900, 402K)