/dpt/ - Daily Programming Thread

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

Attached: 1561171425694.jpg (1536x2116, 367K)

Other urls found in this thread:

automatetheboringstuff.com/
twitter.com/AnonBabble

first for anime

my wife renge is so cute

Attached: d91m8hd-e6f443c0-23c3-4d68-9147-4461b2620453.png (753x720, 442K)

An ncurses Xresources browser and swapper in cpp

find_if(vec.begin(), vec.end(), not1(fun_ptr(Cond)))
So simple and elegant

Attached: 1563977063936.png (952x767, 700K)

>What are you working on, Jow Forums?
Pic relateded

Attached: space.png (1282x752, 12K)

find (not . cond) vec

What's the cleanest way to search in two entries and append founds to list? I'm doing this rn but idk feels like could be better
try:
if (re.search(string, thread['com']) and thread not in foundt):
foundt.append(thread)
except KeyError:
pass
try:
if (re.search(string, thread['sub']) and thread not in foundt):
foundt.append(thread)
except KeyError:
continue

To the user who asked if I was that furry porn game, those are free assets to test rendering. I will not be making anything furry related >:[

Recommend me a manga with a software dev setting. I've caught up with new game and I want to add something else to my pull list.

I posted this over in /sqt/ and might get a better answer here

I hacked together a Bash script to scrape entire mangas from mangadex.org. Obviously, this should only be for purposes that would not violate copyright.

#!/bin/bash
set -e

# Written by Anonymous on 2019-07-31
# This is free and unencumbered software released into the public domain.

chapter_vals="$(egrep -o '"[0-9]+">[^

Attached: 04.jpg (960x1363, 310K)

SE

And now it's obsolete because of ranges.

>What are you working on, Jow Forums?
I'm trying to complete generic coding interview questions in my own lisp ripoff language.
{!!oneline}

{! set of primes to use as a base case !}
{list:base_primes;2;3;5;7;11;}
{list:sieve_primes;}
{set:primes;sieve_primes;}

{func:sieve;

{! test if goal is larger than number of base primes !}
{set:base_test;
{?gt:{ta[0]};{#pow:{base_primes[-1]};2;};}
;}
{when:{base_test};
{! find primes up to sqrt first before calculating goal !}
{set:primes;base_primes;}
{sieve:{#pow:{ta[0]};0.5;};}
{set:primes;sieve_primes;}
;}

{! create a list of all numbers under this goal !}
{list:all_nums;}
{loop:i;0,{ta[0]};{push:all_nums;{i};};}

{! iterate over current set of primes, remove all multiples of prime except prime itself !}
{loop:iter;values;{primes};
{loop:i;{#mul:{iter};2;},{all_nums[]},{iter};
{set:all_nums[{i}];POP;}
;}
;}

{! copy leftover primes back into sieve primes !}
{list:sieve_primes;}
{loop:i;2,{all_nums[]};
{set:iter;{all_nums[{i}]};}
{when:{?ne:{iter};POP;};
{push:sieve_primes;{iter};}
;}
;}

{! if this is a recursion case, those primes will then be used
! to calculate the primes of the calling case, until the final goal
! is reached
!}

{! return value is sieve_primes !}
;}

{set:sum;0;}
{sieve:2000000;}
{loop:iter;values;sieve_primes;
{#iadd:sum;{iter};}
;}
{sum}

>C#
if (true){
int x = -1;
}
int x = 1; //compiler error

I don't know what's going on but it looks like a good time.

I just realized that I would be much more inclined to use Lisp if its syntax looked more like C.

Started working on the C++ codebase at work and feeling very confused about pic related. I'm an intern and only done Java before.
>Variable get passed to function as pointer
>Function changes the actual variable in memory
>Function returns success or fail to say whether it worked
>The return value is not the variable I wanted to change despite that being the explicit purpose of the function
>Return value gives no indication of what actually happened inside the function
>"Dude just trust me lol it worked"
This completely bewilders me. I've always been taught that a function should return what I want to set the variable to. Am I wrong for finding this misleading?

I also mimicked the code style they use which I find to be incredibly autistic. Who is wrong here?

Attached: image000000_03.png (443x321, 7K)

>>> im = Image.open("ok.jpg")
>>> im.getpixel(0,0)
Traceback (most recent call last):
File "", line 1, in
TypeError: getpixel() takes exactly 2 arguments (3 given)
Am I missing something? How is (0, 0) 3 arguments?

The language itself sucks ass but that's why it's fun to try and complete challenges using it.

>I've always been taught that a function should return what I want to set the variable to.
???????????????????

the object instance is the third (technically the first), fyi the function expects a tuple not two coords

I'm so excited to do something fun in Haskell!

What you gonna do, user?

Anyone use jUnit5? I'm confused as to what JUnit Jupiter is meant to do.

im.getpixel(0, 0) # is equivalent to im.getpixel(im, 0, 0)

im.getpixel([0, 0]) # or
im.getpixel((0, 0))

This works the same way in Java too, maybe you'll like Haskell

This is common practice in C++ and especially C, yes. In C, the return value is often used for an error code which you can test with a conditional (by convention 0 = success)

thank you

Literal retard here. How do I get started with Haskell?

Is it technically im.getpixel(im, tuple) or Image.getpixel(im, tuple)?

second

How does javascript work without a main function? Does it just go line by line?

she is autistic right?

CLI frontend for pleroma's API

I'm refactoring my minimal modern c++ code to be "modern" so I can put it on my resume and claim I know modern c++.

read Real World Haskell
that's it

yes

No she is cute

So i understand &_input1 is an address to the data’s location. Like 0x0001.

How does _input1=‘abc’; work?

How does just doing _input1 = ‘abc’ changes the

all autistic girls are cute

What you're looking at there is a C++ reference. They're like pointers, but they work implicitly.
int x = 0;
int *p = &x;
*p = 1;
is equivalent to
int x = 0;
int &r = x;
r = 1;

This is true. I had a crush on this girl, and then I realized that she's probably on the spectrum.

Why the retardation?

Can’t you just get values from function and then assign? Because it’s fast?

it depends

Imagine you have a 1kb class and you're passing it to a function as a value. This means you copy 1kb of memory (that is if the function isnt inlined), which is obviously really bad. A pointer (which is effectively what a reference is, for short) is much smaller.

Please stop calling stuff you dont understand retarded. You are making a fool of yourself.

anyone good with sed ?

I got a file with data, sometimes empy
field1;field2;;;;;field7
field1;field2;;;;field6;

And I want to do something like this :
sed 's/;;/;\\N;/g' file.csv > new_file.csv

But sadly, it adds the \n every 2 empty fields. What would be a good way to do it ?

>Kotlin JS
>Kotlin for Android
>Kotlin Native
>Kotlin JVM
>no API parity for this shitfest
>still adding annotations to support more Java crap with every new version
>still depends on java's library and its shit design because that's what makes it popular
>clojure also relies on jcl even for exceptions
>scala is still an abomination
what a failure. fuck the jvm '''ecosystem''' where everything dies if it's not literally java or something worse.

Attached: imgs_touch.png (1231x774, 286K)

It’s 2020-1. Don’t fuck yourself with a 45yo command and use python.

so how you do that in python ?

what do you want to do? you only posted something you don't want

based

Attached: IMG_20190731_102453.jpg (4048x3036, 2.49M)

What do you want to do?


data = []
with open(‘file.txt’, ‘r’) as f:
for line in f:
data.append(line.split(‘;’))

# do what you want with the data

with open('new.csv', 'a') as f:
for line in data:
f.write(‘,’.join(line))
f.write(‘\n’)

>I've always been taught that a function should return what I want to set the variable to.
See #1 in pic related
>This works the same way in Java too
It doesn't though, right? I could do #2 in pic related but that is limited to that specific class. How could I change stringy in a completely different class?
Fug, guess I better get used to it then
>tfw want to do embedded programming

Attached: image000000_04.png (439x583, 16K)

I'm stuck in some test where I have to make a 7x7 matrix automatically filled with random numbers between 1 and 99.
The catch is that no number inside the matrix can repeat itself. I don't just mean on different fields but like in the entire matrix. So a row that looks like 1 2 3 1 would be invalid.

I have no fucking clue how to do this. I've spent like 6 hours just thinking about this step and trying 1000 solutions.

that this :
field1;field2;;;;;field7
field1;field2;;;;field6;


be this :
field1;field2;\n;\n;\n;\n;field7
field1;field2;\n;\n;\n;field6;\n

sed ':l s/;;/;\\n;/; s/;$/;\\n/; t l'

the second s is for the case of a ; at the end of the line

Quit posting this garbage. No one cares.

What? Just treat it is an array of 49 elements. Simple selection sort.

use a set

For functions where you have no need of an error code you can definitely return it by value, and in some cases it's more efficient.
However when you must return both an error code and the "real" value you should prefer to return the error code directly and update the "real" value through a pointer or reference.

Sometimes it's better to use jumps.

wtf

import random

x = random.sample(range(1, 100), 49)

[x[7*i:7*(i + 1)] for i in range(7)]

Could he do ;[;\0] for the search part? I have a feeling it can be replaced in one go, but I'm used to perl regex, not sed/awk/etc

what does that do?
I thought about using a lookahead assertion, but sed doesn't have those.

It would look for a null terminating character, but that'd be... pretty dangerous to modify since a dumb algorithm wouldn't necessarily replace it with another null at the end.

I don't think a look-ahead would work because an ending semicolon has nothing to look ahead.

The two-liner is easiest to understand I guess. I'm sure there's a way to do it in one line.

ah never mind I misunderstood,
you can do it in one go
sed ':l;s/;\(;\|$\)/;\\n\1/;tl' test.txt

it didn't work with \0, I think that's a backreference

>What are you working on, Jow Forums?
I am building a CPU in VHDL. Pic related
We did about 50% of that two semesters ago in uni, but now i am starting from scratch just to get back into VHDL. Will see how far I get.

pic related. Instruction set coming

Attached: datapath.png (2006x1372, 134K)

Attached: instructionset.png (1620x1758, 285K)

String in Java are weird, but otherwise everything non-primitive is passed by reference, and will be modified

Do you need a $ in front of the \1 in the second part? I assume you mean to replace it with the capture group found in the search

Please post Nenecchi reading the C book. This is important!

no, sed doesn't need a $ for back references. I guess that's how they do it in perl?
It is meant to be replaced with the capture group

Nice. Got an FPGA to load it onto?

Pretty sure she only reads a C++ book.

Poor soul.

Attached: 1545605857084.jpg (1280x720, 110K)

fixed size instructions?
how would you do subroutines? wheeler jumps?

Ye, some chink spartan-6 board. Will try to get it working on that and depending on how far i get i will buy myself a proper dev board. Artix 7 or something ... will see.

Is this javacript?
If so why don't you create an array of 1 -99
Then math.random choose one and at the same time splice it out of the array and decrement the value you are multipling random by 1.

I am very dumb with regex, would a kind user tell me how do I get the 1040 and 151 from this string?
bb9468f5ca5cc8a69d33db4f117d88bacce0f4b0-714873-1040-151-

Yes. I haven't thought much about it yet. My prof designed this CPU and I think he is pretty good and this shit should work out somehow. Not sure yet.
Dream would be to write my own compiler for this shit and bootstrap it or something lol.

it's all german, sorry.

I - Memory Instructions
II - Load and Store instructions
III - Arithmetic, Logic, Shift, Compare

Attached: instructionset2.png (1728x2088, 346K)

Okay, neat.

use strict;
use warnings;

my $string_in = "aaa;;;;bbbb;";
my $string_out = $string_in;

while ( $string_out =~ s/;(;|$)/;X$1/ ) {
print "${string_out}\n";
}

$string_out = $string_in;
print "Resetting: ${string_out}\n";
$string_out =~ s/;(;|$)/;X$1/g;
print "All at once: ${string_out}\n";

exit;

PS: I might translate all of this someday. He said I can make it open source, but I should link to his page then. SHould do a blog about it

Bad use-case for regex.

s.split('-')[-3:-1]

/(\w+)-/g
group 3 is 1040
group 4 is 151

I have zero experience coding. From lurking I have learned C is the base of all languages. So C I will try to learn. Any recommendation on resources I can use to help me teach myself?

programming job is so tiresome

Attached: 1537274056860.png (1022x731, 643K)

nvm, mine won't work. This would: /(\w+)-(\w+)-$/

That's smarter, but would it reserve memory for the groups you don't want?

I would assume that the memory overhead of compiling and executing a regex far exceeds that of allocating a few extra strings.

that worked out-of-the-box in python
that is exactly what I needed

man, regex is really weird, how did you learn it?

Don't do this,
Start from the top and work your way down, if you start with C your going to be essentially useless in the job market.
Python or JavaScript. Start there.

that's alright, I speak german
If you want subroutines you'll probably want some good way to save the current pc before jumping, and a way to jump to an address contained in a register (which you'd also need for indirect jumps in general). You could achieve the same effect with the instructions you have now, but it's going to involve some self modifying code, but that might be fun to do in the compiler.

Learn python
automatetheboringstuff.com/

Thanks, I'll keep that in mind.

>From lurking I have learned C is the base of all languages
Not quite. Learn x86 assembly.

What's the most efficient way to write code to approximate a double integral?
Assume the function given is an array of points, and you draw straight lines between the points.

Can you do it in 10 lines?

Attached: 1510137269509.jpg (1200x1171, 372K)

Pshh he needs to start with Boolean Mathmatics first.

There’s a good coding train video about regex

post an example input/output

I worked at a place which used C and Perl scripts. We did a lot of manual editing of files, because the company optimized a lot of its stuff for embedded/not embedded use (and other things - variables would explicitly not get allocated if they weren't used in a build for example, instead of relying on the compiler for optimization). Worse sometime scripts would be made on one OS but ran on another, so a lot of my lines search for \n or \r\n explicitly and replace it exactly.