/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1538758395100.jpg (1280x720, 778K)

Other urls found in this thread:

oocities.org/mc_introtocomputers/Instruction_Timing.PDF,
stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
stackoverflow.com/questions/20094394/why-do-we-cast-return-value-of-malloc?lq=1
thomas-cokelaer.info/blog/2011/10/malloc-and-casting/
youtube.com/watch?v=oQ7OhFKZZXo
en.wikipedia.org/wiki/Tree_(graph_theory)
math.stackexchange.com/questions/589717/introductory-books-as-preparation-to-read-voevodsky-homotopy-theory-hott-book
github.com/jozefg/learn-tt
cse.chalmers.se/research/group/logic/book/book.pdf
5ht.co/cat.pdf
catonmat.net/bash-one-liners-explained-part-three
twitter.com/NSFWRedditGif

Attached: 1494888806720.jpg (540x720, 86K)

INT 0x20 takes up to bytes (CD, 20), and according to oocities.org/mc_introtocomputers/Instruction_Timing.PDF, takes 51 cycles to execute, which on the original IBM PC which is running the i8088 @ 4.77MHz would take 10.7uS to execute?
Are my calculations correct?

Attached: ibmpc.jpg (640x425, 37K)

>c++ can declare names in the if statement
do people actually use this

Attached: 1469282654573.png (681x576, 290K)

The one feature of Rust seems to me that it can automatically insert calls to free() but are there otherwise any real reasons to use it?

Have you read your HoTT today?

Attached: 1528776152228.png (1700x1374, 1.1M)

it's occasionally useful
and it doesn't really hurt to be there

C++ has that lmao

types

Process that uses googles image net to flag naked pictures of women on Jow Forums, saves it to a database and hides the images when I'm browsing so I can use Jow Forums at work stress free

i am a dogger now
you are all beneath me

Attached: dogger.jpg (745x750, 49K)

Will you learn JavaScript with me? Trust me, it rocks!

Attached: ab6fdf3e76ffe3f3c39efa00101fb7ee.jpg (853x1280, 219K)

Go away evil dogger

Should be passing the size of the string tho
int count_words(const char* p)
{
int in_word = 0;
int count = 0;
while (1)
{
switch (*p)
{
case '\0':
return count + in_word;
case ' ':
if (in_word)
{
in_word = 0;
++count;
}
break;
default:
in_word = 1;
}
++p;
}
}

Sometimes. It's useful if you have an expression whose value is only used in the test and the body of the conditional (either or both branches). It's cleaner than introducing a block for just that variable.

how to get good at simd

std::function make_func() {
return [](auto foo) {
foo.mutate();
};
}

looks like the lambda takes Foo by reference right?
well youre fucking wrong and you get no warning

sepples is an amazing lang

auto doesn't deduce to references unless you explicitly tell it to
not sure what the actual rules are but i've run into it before

>doesn't return "count"
>while (1) instead of for(;;)
>input 65465164516451344332435245 words, return int

> Too many arguments (8/5) (too-many-arguments)
should I refactor?

should I typecast my malloc??

pass a structure as a parameter

no.
stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
stackoverflow.com/questions/20094394/why-do-we-cast-return-value-of-malloc?lq=1
thomas-cokelaer.info/blog/2011/10/malloc-and-casting/

What's the benefit to that? Aside from hiding the error message, obviously

benefit to what?

Is Perl a meme? Should I bother learning it and using it? Or if I'm given a choice I should use whatever else like Python?
>dupe post from old thread

passing a structure as the parameter. I previously had the arguments passed as a global dict (python) but I removed that when I refactored it previously

Attached: ll.png (1889x1135, 455K)

def myfunction(*args):
for x in args:
# Do stuff with specific argument here

First of all, it's not an error, just a linter message based on "agreed upon" stylistic choice, when you reach that argument count, at this point you should probably ask yourself, can the arguments not be grouped by type to make them more manageable, or perhaps the function tries to do too much of functionality at once and you should split it into separate smaller functions? You can just disable this pylint warning in pylintrc file under message control if you absolutely don't care about it.

Do you agree, /dpt/? I don't.

Attached: 1525451818174.jpg (850x400, 53K)

dumb nigger of course it doesn't
retard

Teaching OOP first is good, it teaches good habits which can be disregarded when you're l337 3nuff

Attached: 4ph1ye99lri21.jpg (759x627, 68K)

Perl is pretty neat for running other programs and dealing with their stdout
That task sucks in pretty much every other language IME

Is there a way to get snprintf to emit strings that aren't null terminated?

>pass the size of the string
I assume the const char* thing does it in your example? Not familiar with that one yet so I have to use methods like strlen() or sizeof() which I don't like because they are clunky. Typically I just check for the null terminator since if its not there things will go to shit anyway hence my original question as why the second example worked.

I'm confused why the previous responses > and > say it segfaults on "" or count it as a word since there's the while(*p) that catches those cases. Testing reveals no problems in those situations. It is only with arrays that aren't initialized that things go awry which I think is normal?

I'm reading old book on ANSI C left by my dad, so either things have changed drastically over the years and I'm simply talking about different language, or some anons are memeing me.

>strings that aren't null terminated?

Attached: 127812b9f337a4421f683d25f9360e8b9b63ca3e4ebc5738c569bf85f6173e3c.jpg (625x468, 99K)

youtube.com/watch?v=oQ7OhFKZZXo

Yeah, just disregard the null character, you only get the pointer to the first element anyway, how many characters after that you consider valid is entirely up to you.

Strings in C must be null-terminated by definition.
If they aren't, they aren't strings at all.

I'm using an API that takes structs of {len, data}.
I know I could do this:
if (s.len = snprintf(s.data, "asdasd") >= maxlen)
CRITICAL("buffer size underestimated, oops");
s.len--;
api(s)

But it's extremely ugly.
Yeah, but it will write into a buffer and try to null-terminate it. If I give the true buffer length, the last character will be a null terminator. If I give it len+1, it's going to write into uninitialized memory.

How cool is it and what mathematical background should I have?

Then just copy-paste snprintf, rename it to whatever you want, remove the null termination bit and use that instead.

you could something like this
int len = 10;
char *str =

char backup = str[len];
str[len] = '\0';

/* something with str */
str[len] = backup;

> Then just copy-paste snprintf,
The *printf functions are huge. There's code paths for all of the different specifiers, as well as the field width, precision, length modifier and flags. And this will be wrapped up in abstractions so that the same code can be used for all of the printf family.

If you're using glibc, you can use fmemopen() or fopencookie() to fprintf() to a user-defined stream (FILE*) which writes to memory (similar to C++'s stringstream I/O). If you're stuck with portable C (and need full printf capabilities), you'll have to accept either the null terminator or a copy.

MUUHSHEEN LEARNING

why does this work with an input of any length?

is it just luck?

char s[1];
scanf("%s", &s);

dude BLOCKCHAIN lmao

>The *printf functions are huge.
So what? Just move them to a file and include it? Essentially the same as if you included stdio except less stuff.

I wonder what would've Minsky thought about modern """AI""" shitshow if he was in his prime today.

Why arent they null terminated?

It's just overriding memory it's not supposed to, consider the following:
char s[1];
int test = 12345;
scanf("%s", &s);
printf"("%d\n", test);


Then see what it prints out.

en.wikipedia.org/wiki/Tree_(graph_theory)

The term "tree" was coined in 1857 by the British mathematician Arthur Cayley

As a child, Cayley enjoyed solving complex maths problems for amusement. He entered Trinity College, Cambridge, where he excelled in Greek, French, German, and Italian, as well as mathematics. He worked as a lawyer for 14 years.

omg, so funny, never left the room xD

The fuck is that book?

bump

No, please no.
Not using glibc for release builds.

I don't have to do that, I can just decrease length by 1 because the API copies it internally. But I was wondering if there was a cleaner way. Maybe not.
Yeah, except for the part where everything breaks horribly.
That doesn't help, since it'd just be setting str[len] to uninitialized memory.

No, I want snprintf's emitted strings not to be null terminated. The inputs are all null terminated.

>it teaches good habits
In my OOP course in uni I learned a lot of good habits, and I learned a lot of really bad ones. I think I would have learned all of the good habits and fewer of the bad ones if it was a course about design in a functional language.

>still only on page 40
I've failed you again user

Attached: 1536507359614.png (1039x583, 750K)

Math proof, type theory and category theory.

math.stackexchange.com/questions/589717/introductory-books-as-preparation-to-read-voevodsky-homotopy-theory-hott-book

Today HoTT has too many problems for made computable version.

hentai

are there any good resources for type theory or category theory?

I watched a bunch of that polish guys videos and I know he has a book, but there didn't seem to be any exercises in it so it becomes suboptimal.

i'm writing a script that lists images of manga scans in folder and if the image's width is greater than it's height then split them in half but the below functions does not work correctly:
import os.path
from os import remove, listdir
from PIL import Image

def parse_images(path):
images = listdir(path)
print(f"files: {len(images)}")
i = 1
for image in images:
print(f"{i} processed...")
i = i + 1
image = os.path.join(path, image)
dimensions = Image.open(image).size
if not dimensions[0] > dimensions[1]:
images.remove(os.path.basename(image))
return images

parse_images(path_to_folder) #contains 8 image files
this is the output:
files: 8
1 processed...
2 processed...
3 processed...
4 processed...
5 processed...
6 processed...
it only iterates through 6 files. is there something obviously wrong with this function (apart from it being written in python)?

Attached: sample_50e836cd5640b5cc94d8fb2bb864f73a_waifu2x_art_noise1_scale_tta_1.png (1700x1190, 950K)

github.com/jozefg/learn-tt
Type Theory
cse.chalmers.se/research/group/logic/book/book.pdf
Cat Theory
5ht.co/cat.pdf

h-help me solve these?
the first are equal cause bases dont matter
n! is bigger than 2^n
What about the last?

Attached: 2019-04-14 21_14_19-.png (432x85, 5K)

No. snprintf() must always terminate its string according to spec, even if it has to discard characters to do so.
If you want to do unwise shenanigans, you need to copy the bytes from the string after printing (or do other similar magic).

thanks senpai

Currently reading The Science of Programming
>Expected: General theories and mathematics that go into computer science
>Got: Boolean math proofs and Calculus.

sqrt(n^5) = n^(5/2)

rewrite sqrt(n^5) = n^(5/2) = n^2.5
Does that help? How would you compare n^2 * log n, n^2.5?

I got no idea if logn is bigger or less than that .5 difference

Attached: 1544005112891.jpg (460x687, 31K)

Start with i = 0 and move the i = i + 1 to the bottom of the loop.

because it enters the if-clause inside the for loop, removes the images then you only end up with 6 images in the directory.

Initially you have 8, but then after that if you end up with 6

Put it in a graphing calculator.

n^2.5 = n^2*sqrt(n)
log(10000) = 9.21
sqrt(10000) = 100


How this relates to asymptotic complexity, I actually don't know.

i is just for debugging. i don't think it did anything.
oh shit, you're right. i'm just gonna add items i want to remove to some blacklist and then remove them from original list. thx mate

Attached: 4e3.png (659x609, 221K)

> is there something obviously wrong with this function
You're modifying the list while iterating over it. Don't do that; iterators tend to be written on the assumption that the thing being iterated over won't change during the iteration. Make a copy, e.g.
> for image in images[:]:
Or construct a list of valid images by starting with an empty list and appending each valid image, rather than removing invalid images from the original list.

1. log10(n)=(1/ln(10))*ln(n) => O(log10(n))=O(ln(n))
2. O(n!)>O(2^n). Should be self-evident.
3. O(n^2*log(n))

at least you make progress

log grows slower than any polynomial

What do '' mean in linux terminal?
I know that '>' is for providing some info to stdout, but what is '

Attached: hms.jpg (1920x1080, 77K)

catonmat.net/bash-one-liners-explained-part-three

>For any k>0
>let k be an integer/real ?

thanks!

Attached: smh.jpg (640x480, 37K)

If your whole program is in callbacks, how do you handle errors? Just critically fail whenever any underlying error of any kind is encountered?

Oh no, I figured out the answer: more callbacks.
Man, this is going to be fun.

My CS course barely covered networking at all, but had shit tonnes of agile and scrum nonsense. I feel kinda scammed.

write an error handling monad. in javascript these are called "waterfall functions"

still going for a bit

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

How would I implement that in C?

use console.log() and troubleshoot yourself, nigger

The latter will prove far more useful in the industry. You scammed yourself by not taking it seriously.

Networking has already been "solved." 99% of the time it's just going to be plug-and-play from your product's perspective.

>if the image's width is greater than it's height then split them in half
Split them vertically?

Is it not obvious?

why would you care about networking? somebody else has already written code to do that nonsense.

It's in C, I don't have no console.log. I mean more generally.
I shoot of an HTTP request. The database fails inside a callback. Now what? I can just critically fail, but is there a nicer way?

Apparently, error callbacks, but is there something better?

Is a shorter strlen possible?
int strlen(char*s){int i=~0;while(s[++i]);return i;}

Callbacks can return error codes, can't they?

In ANSI C int return type is implied.

Yes. Just store the length of the string rather than using null-terminated strings.

nice code tags nerd