/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/Reactive-Extensions/RxJS
tldp.org/LDP/abs/html/
mywiki.wooledge.org/BashGuide
git-scm.com/book/en/v2
twitter.com/NSFWRedditImage

Thank you for not posting animu

god bless anime
thank you for using an anime image

That's Lain faglord

I recently got an internship at a small webdev company, and as a project I have to build a website. I use PHP. It's easy but tedious as fuck. So this is gonna be my life now.

>being this new

First for g++ being part of the GNU Compiler Collection.

Can I have conditional replaces?
Let's say, given some /^([a-z])([a-z]).*/ pattern, I want to replace first group with [A-Z], and the second group with [z-a].

see

rip user

>First
>actually 6th
Good job, faggot.

Javascriptâ„¢ everyone!

What language/tool/etc

>sixth
ftfy

More like javashit, amirite

My own language.

CL-USER> (format t "~R~%" 83521983751973105132563)
eighty-three sextillion five hundred twenty-one quintillion nine hundred eighty-three quadrillion seven hundred fifty-one trillion nine hundred seventy-three billion one hundred five million one hundred thirty-two thousand five hundred sixty-three
NIL

There are many ways of doing this, including looping over the lines read by 'read'. The simplest is probably awk, but here's a version with sed:

echo 192.168.1.30 | sed "s/^\(.*\)\.[0-9]\+$/\1.1-\1.255/"

I still wouldn't do this with bash.

Lorem ipsum you must wait before posting a duplicate reply.

Perl

What is the best auto completion plugin for vim?

animeVim (yup, that's its name...)

Sure you can.

Thanks.

bumoing question

if im just a neet who works by himself, is svn or git better?

So is Rust like C with some FP mixed in?

when people explain the differences between python and java why do they always mention that java is statically typed? it sounds like a much bigger deal than it actually is. it doesnt even fucking matter.

just my noob opinion

not at all

How do I get better at math?

Should I just go through all the math subjects on Khan Academy or will that be too basic?

I want to start doing speed math competitions so I can think faster and then start doing coding competitions.

>I want to start doing speed math competitions so I can think faster and then start doing coding competitions.

you can be an excellent mathematician with shitty mental calculation skills

>just my noob opinion
At least you know that.

As with all programming you should only learn what you need.
Khan is good up to and including pre-calc.
After that I would use textbooks.
Textbooks offer more in depth demonstration and proofs which are necessary for conceptualization and conceptualization is necessary for application.
You don't really need calculus unless you expect physics problems.

Found an alternative using arrays:
file=list.txt
IFS='.'
while read -r aaa bbb ccc ddd
do
printf "%s" $aaa
printf "."
printf "%s" $bbb
printf "."
printf "%s" $ccc
printf ".1-"
printf "%s" $aaa
printf "."
printf "%s" $bbb
printf "."
printf "%s" $ccc
printf ".255"
printf "\n"
done < "$file"
read


It just werks.

Please don't do that. Literally copy and paste this code into your terminal:
cat MY_FILENAME_HERE | sed "s/^\(.*\)\.[0-9]\+\$/\1.1-\1.255/"

thanks again.

The issue is resolved, but now I'm trying to use arrays just for the sake of it and found a problem:
file=list.txt
IFS='.'
while read -r a b c d
array=("$a" "$b" "$c" "$d")
do
printf ${array[0]}
printf "."
printf ${array[1]}
printf "."
printf ${array[2]}
printf ".1-"
printf ${array[0]}
printf "."
printf ${array[1]}
printf "."
printf ${array[2]}
printf ".255"
printf "\n"
done < "$file"
read


It works in the beginning but when the list ends it just loops forever (pic related). How comes?

How about this - github.com/Reactive-Extensions/RxJS

#include

class fizzbuzz {

public:
fizzbuzz ();
fizzbuzz (const fizzbuzz &other);
fizzbuzz &operator = (const fizzbuzz &other);

private:
int _value;

};

inline fizzbuzz::fizzbuzz () : _value (0) {}

inline fizzbuzz::fizzbuzz (const fizzbuzz &other) {
_value = other._value + 1;
}

inline fizzbuzz & fizzbuzz::operator = (const fizzbuzz &other) {
_value = other._value;
if (_value % 15 == 0) {
std::cout

(cont)
It's still looping but I made a small revision here:
file=list.txt
IFS='.'
while read -r a b c d
array=("$a" "$b" "$c")
do
printf "%s." "${array[@]}"
printf "1-"
printf "%s." "${array[@]}"
printf "255"
printf "\n"
done < "$file"
read


Any ideas what's causing the loop?

what's the most anime language?

The most cancerous language? C++.

Any good sites to learn web/software development independently from? I'm trying to get back into programming after putting it aside because of muh studies which was kind of a stupid decision.

I've farted about with C++ and Lua before stopping, but I'm looking for more structured learning. I'm sure I have to pick up C/C++, HTML, CSS etc.

No bully pls

Common Lisp and C

@58691914
hello rddit

No worries. Here are the two best resources for bash scripting that I've found:

tldp.org/LDP/abs/html/
mywiki.wooledge.org/BashGuide

I would warn you not to attempt too much in shell; I find it to be unreliable and generally quite risky.

This post is hate speech.

I dunno, I just read books.
Also, check /wdg/, it has resouces about web development.

Try it without using the 'read' on the very last line.

To be honest, I would avoid using arrays in bash. They are messy and dangerous. If you need aggregate data types, you should probably switch to a full-blown programming language.

just copy folders for new versions

Rust

@58691914
That would be an anti-anime language
Why?
And is there any particular reason why it's common lisp and not any other lisp?

>I would avoid using arrays in bash
Indeed, it's still broken even after removing read, I was just playing around with what I learned anyway, what I needed the most was accomplished with the sed script from before.
I'm planning on learning more Perl since I made some stuff in the past with it, so it's the most familiar language for me at the moment.

Well i currently just 7zip the dir and stick on another drive & a flashdrive. But i feel like i should learn """proper""" src control

What are you doing? It could be made a hell of a lot easier probably.

You can loop over lines in a file by using
for l in $(cat $filename); do
#shit
done


And for the print formatting you should be using sed (use group capture).

I am on exercise 1-20 on K&R C, but I literally have no idea what I am supposed to do. I thought I was just supposed to replace tabs with spaces equal to tablength, so I just used the standard tablength of 8, and wrote this:
#include

#define TABLENGTH 6

main(){
int c, i;

while((c = getchar()) != EOF){
if(c == '\t'){
for(i = 0; i

>But i feel like i should learn
no you really shouldn't

>What are you doing?
I've a list of IP addresses and I'm converting it to ranges, like:
>192.168.1.69 (b4)
>192.168.1.1-192.168.1.255 (after)

Like you mentioned there's a way with sec, which user posted here: but I still wanted to try using an array, though looks like bash is kinda slippery with this.

>sec
sed*

Do you not know how tabs work? They align text on the next column that is a multiple of 8. You can't just turn a tab into 8 spaces.

I would expand on my earlier post by saying that any time you need string processing beyond a sed one-liner, you should again use a full-blown programming language.

While I've done a lot of shell scripting in the past, I've come to regard shell languages with fear and suspicion. Often, the few extra characters you have to type if using Python, Perl or Ruby are well worth it in reliability and, honestly, sanity.

I want to learn code but I have to chose between JS, Java and swift.
What does /dpt/ recommend?

The \t character is variable length. It pads the string to the multiple of where the tab would go. You have to keep track of the characters read in and pad TABLENGTH-chars_read_in

As a first? Java. Cross-plat and not JS (shit). Make sure you learn Java 8 patterns after you learn the basics.

The programming community should collectively refuse to use JavaScript, to force better working conditions from employers.

git-scm.com/book/en/v2

Also here's how I would do it with a while loop:
while read -r ip; do
echo ${ip%.*}.1-${ip%.*}.255
done < "$MY_FILENAME_HERE"

However, this will only work in some shells (tested in bash), whereas the sed version only requires that you have the right type of sed installed.

>patterns
You could just use a not-shit language that doesn't need 'patterns'

>The programming community should collectively refuse to use JavaScript, to force better working conditions from employers.
The programming community should collectively refuse to use Windows, to force better working conditions from employers.
>FTFY

>Python, Perl or Ruby
Those are all shit languages and you should feel bad for using them.

In fact, I've just noticed that those string substitutions are pure bashisms, so I really wouldn't expect this snippet to work in anything but bash.

Cute

"patterns" is a generic term you retard. I mean learn the functional-esque shit they added, not just the bog-standard procedural/OOP stuff.

>Those are all shit languages
Yeah, well, that's just, like, your opinion, man.
>and you should feel bad for using them.
I don't use them.

I'm not a good bet for this kind of shitposting, have a go with someone else.

They're objectively shit, they retard development and have poor performance, there's literally no reason to ever use them.

Yeah, well, that's just, like, your opinion, man.

new standards dont happen with protests. they happen with one person or group showing off a shiny new replacement & then people follow

I didn't know you could do that.
Someone suggested a similar thing in last thread: I couldn't find a way to make it repeat so I didn't continue in that direction.

We've had lots of shiny replacements, but we're still stuck with fucking JavaScript.

>Yeah, well, that's just, like, your opinion, man.

Scripting languages aren't indented to have C-like performance and they have their niches, which don't require hard real-time responce.

what's the best way to pick a pivot for sorts?

That was me. I also alluded to the while loop solution here: I generally do not use awk because jumping from shell (a DSL with problems) to awk (another DSL with problems) is avoiding the issue. The sensible solution is to switch to a general programming language.

Yeah, well, that's just, like, your opinion, man.

what does he want to do even? :3
echo "192.168.44.59" | awk -F "." '{for(i=1; i

He just wants to do this: But we've solved it and are just talking about the different approaches to the problem.

...

more like sjws with cucks mixed in

Let me guess, you have some "alternative facts".

oh.. like this?

$ echo "192.168.44.59" | sed 's/\(^.*\.\).*$/\11-\1255/g'
192.168.44.1-192.168.44.255

Daily Reminder: if you took a class on C in university and this wasn't the textbook you used then you went to a shit school.

Lua and Julia are possible solutions. I'd also make a case for Common Lisp.

Forth is probably not 'easy for retards to use' due to being concatenative.

>Let me guess, you have some "alternative facts".
I'm not sure what part of my post you're replying to. But If you're the bad troll, I'm happy to report that that's just, like, your opinion, man.

See I would agree that this is the sanest solution.

>what does he want to do even?
Converting an IP list to ranges.
There're 3 working solutions at this moment.
Using sed:
cat MY_FILENAME_HERE | sed "s/^\(.*\)\.[0-9]\+\$/\1.1-\1.255/"

Only bash:
while read -r ip; do
echo ${ip%.*}.1-${ip%.*}.255
done < "$MY_FILENAME_HERE"


And my shitty bash without sed:
file=list.txt
IFS='.'
while read -r a b c d
do
printf "%s" $a
printf "."
printf "%s" $b
printf "."
printf "%s" $c
printf ".1-"
printf "%s" $a
printf "."
printf "%s" $b
printf "."
printf "%s" $c
printf ".255"
printf "\n"
done < "$file"
read

They all work, except mine is bloat.
I tried to redo with an array, which failed (causes a loop):
file=list.txt
IFS='.'
while read -r a b c d
array=("$a" "$b" "$c")
do
printf "%s." "${array[@]}"
printf "1-"
printf "%s." "${array[@]}"
printf "255"
printf "\n"
done < "$file"
read

>learning C
nice meme

>going to a school where you weren't just expected to know C already
topmost kek

Actually, yours isn't necessarily bloat, since you can convert all those 'printf's into one 'printf' (or 'echo'). The reason I wouldn't recommend doing it is just that you messing with the IFS.

I'll take a C pls

Shit JS senpai. That can be made a lot clearer with async/await.

>Learning C from books

made anudda version for you

$ echo "192.168.44.59" | awk -F "." '{printf("%s.%s.%s.0-%s.%s.%s.255\n", $1, $2, $3, $1, $2, $3)}'
192.168.44.0-192.168.44.255

this