/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

drawy.io/
reddit.com/place?webview=true
youtube.com/watch?v=MZIv6WtSF9I
youtube.com/watch?v=qFl-Q21MzmQ
github.com/Sup
twitter.com/AnonBabble

First for Python!

Explain the desu girl pls
Asking for a friend

I made this:

drawy.io/

A collab drawing app. Just pushed it onto AWS today, very much an embryonic release. Feel free to try and break it.

nth for show me your TE

oops post my bait in the dead thread

studying math
>every CS student barely grasps highschool topics
>they even pull the "lol I hate math" shit
How can this be? It's so ugly and bizarre to me.

moot please stop

I bet canvas could have worked if he made it NSFW instead of trying to pander to normies

...

almost as good as reddit.com/place?webview=true

what is your browser and os?

learning ruby
[70] pry(main)> a
=> [1, 2, 3, 1, 2, 3]
[71] pry(main)> a | a
=> [1, 2, 3]
[72] pry(main)>

That's pretty neat

My guess is you used retarded font embedded icons.
>Anyone loading remote fonts ever on any OS or browser

>C++
youtube.com/watch?v=MZIv6WtSF9I

>python
youtube.com/watch?v=qFl-Q21MzmQ

>GNU-males STILL wasting their time with Vim instead of using a good IDE

How do I make myself enjoy programming again

Programming concepts homework.
>Create a loop that will out
put all the numbers less than 200 that are evenly
divisible by both 2 and 7.

The code I came up with does output the proper numbers and all so I'll get full credit either way but is this the most "efficient" way of doing this? So far all we just go to loops in C. Also no bully if this doesn't work, I've never used the code tag on Sup Forums before

{
int div = 0;
while (div < 200) {
div++;
if (div % 2 == 0 && div % 7 == 0)
printf("%i\n", div);
}
system("pause");
}

use python.

It's good.

I'm still not convinced why I should Rust over C. The only nice things I'm seeing are honestly the closure support (can be implemented in several fashions in C) and channel support (trivial to implement in C if needed though). The GC looks nice, but anyone that watches their heap usage and tests their code thoroughly and in a modular fashion can keep it bug free with good old malloc/free.

emacs is the best IDE

Just do it. Start somewhere, it doesn't have to be a big project.

Rust does a lot of nice things but "anyone who does X can do it in C" only works for so long before someone fucks it up. That's the real reason it exists, for those fuckups. Also concurrency is a breeze in the borrowing model, the rest of the everything is less easy because of it. Lifetimes are also kind of a pain to get used to.

It's a great language in its own right just too immature without diving deep into nightly.

>The GC

i have this problem too

i used to program all day long, now im too lazy

your teacher would suggest the 'for' loop instead of the while loop for this

>Also concurrency is a breeze in the borrowing model, the rest of the everything is less easy because of it.
Principled borrowing is important for more than just concurrency. It allows the compiler to optimize aggressively while preventing any kind of hazard. Like I said in the last thread, Rust is harder and faster than C without optimizations like restrict but it's far easier and only slightly slower than C with them.

{
for (int i; i < 200; i++) {
if (i % 2 == 0 && i % 7 == 0)
printf("%i\n", i);
}
system("pause");
}

>int i;
int i = 1;

Yeah, I'm just going to continue using Sublime. IDEs have uncomfortable, clunky interfaces, and Vim requires a bit of configuration.

Remove the system("pause"); part.

Also, consider using a for loop, instead of emulating a for loop with a while loop.

>I'm just going to continue using proprietary shitware because I can't be bothered to configure vim to fit my workflow
How is this justified?

>work in call centre
>my associates only copy paste the codes from google sarches
>no desire 2 multi-paradigm
>no interest in vedic maths
disapointed, my desis

>Remove the system("pause"); part.
his teacher might require it

>What are you working on, Sup Forums?
doing all the C++ "challenges" on hackerrank because I have nothing better to do with my time

It's a fractally-ironic meme created by an asexual namefig from [s4s].

I don't need a justification.

Gonna be honest, I'd fail a student if their code contained that garbage. The program MUST terminate, or it fucks with the grading script.

>hackerrank
what kind of 'challenges' are these? Simple stuff/Math Stuff/Actual exploit stuff/Reverse engineering?

they usually add system pause because cmd close when they run code and they cant see results.

We needed to use it just because of that

>implying refcounting isn't GC

Yeah she probably would prefer the for loop instead so I did the next question with that instead.
>Create a loop that will calculate the sum of the multiples of 8 that are between 100 and 500. Output the sum only.

{
int sum = 0, i;
for (i = 100; i < 500; i++)
{
if (i % 8 == 0)
sum += i;
}
printf("%i\n", sum);
system("pause");
}


And I don't mean to use this thread as my homework checker so I'll stop at that.

My professor requires the system("pause"); and she hand grades everything.

Regardless of whether reference counting is GC or not you're not supposed to use reference counting much. You're supposed to use single ownership and borrowing as much as possible since it's the most efficient and easy to reason about.

Program is being run incorrectly. Either do "run without debugging" if you MUST use an IDE, or run it from a shell (the correct way to run a command line program).

You need to stop using system("pause") or cin.get() or any of that garbage that stops your program from terminating.

You really shouldn't be running your programs from the file manager in the first place though. Either use the command line, or an IDE with a console pauser built in as part of the run command. And even if you need it, system("pause") is a poor choice, since it's not portable. Better to do something like puts("Press ENTER to close.");
getchar();

Your professor is a moron and should be stripped of her PhD.

>Better to do something like
It's better to do nothing at all.

mostly algorithm challenges which can be solved in basically any language
there's no reversing or exploit challenges like hackthissite has

the language specific ones are basic introduction type problems for that language

this was in Visual Studio, 3 years ago
When you run program it just run it and close it (if it is working)
So we add pause or while(1) just to see results and then remove it.
That happens on some computers but on some cmd didnt close so they didnt need to add pause or while

I mean if you really need to run a character-mode program from the file manager, for whatever reason.

Weird, I would think Visual Studio 2008 would run the program within a console pauser (which can be implemented as simple as a batch script that's like
@echo off
%PROGRAMNAME%
pause

) and even Dev-C++ has that feature.

as i said, on some computers it worked nice bot on some it didnt so we needed to add that

there was one more command i thing getch() or something like that

system("pause") should never be used because it opens up an arbitrary execution vulnerability in your program. Slip a program named pause.exe into the same directory as the vulnerable program, and that program gets run in place of the ordinary pause command.

Friends don't let friends use system("pause");

How difficult would it be to program a bitcoin trading bot?

I imagine it would be simple, since I'm just automating buying and selling based off real-time data, but the most complex program I've ever made was a text-based calculator in Pascal.

Also, which language would be best for something like this?

>How difficult would it be to program a bitcoin trading bot?
very easy
but if bitcoin trading is anything like real forex trading, you can't make money doing it

I wrote a ray tracer in z80, anyone wanna see it?

Yeah

primes in ruby
[41] pry(main)> def prime p
[41] pry(main)* return false if p < 2 or p % 1 != 0
[41] pry(main)*
[41] pry(main)* 2.upto p - 1 do |x|
[41] pry(main)* return false if p % x == 0
[41] pry(main)* end
[41] pry(main)*
[41] pry(main)* true
[41] pry(main)* end


get the primes in the range of 1 to 20

[45] pry(main)> (1..20).to_a.select {|x| prime x}
=> [2, 3, 5, 7, 11, 13, 17, 19]
[46] pry(main)>

>not using nano

Is there any benefit in implementing your own data structures in C or should I just pick up a library and hope it's good?

Are there any good libraries for dynamically sized in-place kind of stuff (ie: lists, queues, etc)

>return false if p % x == 0
Why the fuck is there stupid special snowflake syntax like this?
These languages (Ruby, Python, etc.) are trying to be too "cute" by trying to read off like an English sentence.

just use c++

That is honestly the worst advice you could give to anyone under any circumstance.

>C++
No thanks.

kek

That's actually not the case on modern versions of Windows, since pause is a shell builtin, and as such has higher search precedence than even a file in the current directory.

Additionally, it's worth noting that the Unix command line is specifically designed to prevent this sort of attack, by only searching the current directory if you explicitly tell it to look there.

this is a reasonable post.

just spent an hour digging around the attic to find a serial cable so can into remote debugging like a real Sup Forumsentoomen.
finally found one, turns out there's a difference between male and female cables

...

>dynamically sized in-place
>lists
I think you are confused about some of the basics of data structures

I started working with rest api in java this past weekend, does anybody know how I could get access to the Sup Forums api so I can browse Sup Forums from the command line using api requests

add .json to the url
.json

github.com/Sup Forums/4chan-API

>What are you working on, Sup Forums?
delimiter $$
create procedure register_user(in pname varchar(64), in pemail varchar(64), in ppass varchar(64),
out response varchar(128), out userid bigint unsigned) begin
declare user_exists boolean;
declare salt varchar(64);
select count(*) into user_exists from user where email = pemail;
if char_length(ppass) < 3 then set response = 'password too short';
elseif user_exists = 1 then set response = 'email already registered';
else set response = 'ok';
set salt = substring(sha2(rand(), 512) from 1 for 64);
insert into user (name, email, pass_salt, pass_hash, signup_verification_code)
values (pname, pemail, salt, sha2(concat(ppass, salt)),
substring(sha2(rand(), 512) from 1 for 6));
select max(id) into userid from user;
end if;
select response, userid;
end $$
create procedure verify_user(in userid bigint unsigned, in pvcode char(8),
out response varchar(128)) begin
declare user_exists boolean;
declare user_verified boolean;
declare vcode char(8);
select count(*), signup_verification_code, verified
into user_exists, vcode, user_verified from user where id = userid;
if user_exists = 0 then set response = 'user does not exist';
elseif user_verified = 1 then set response = 'user already verified';
elseif vcode pvcode then set response = 'wrong verification code';
else set response = 'ok';
update users set verified = 1 where id = userid;
end if;
select response;
end $$

i don't actually know how mysql works, please be gentle

it's not that they're trying to be "too" cute in reading like English, it's that they're designed to be read like English. Different languages have different goals and problem domains and use cases. How is this hard for you?

it would be better to just do (!(div % 14)) since anything cleanly divided by both 2 and 7 is divisible cleanly by 14

use Rust

Want to do SICP and practice emacs. What's the best Lisp/Scheme to use? MIT/GNU Scheme? Guile? Don't say Racket.

How does Rust make me enjoy programming again?

There is no point, and it usually just hides the important information behind a lot of stupid fluff.
Consider the python "ternary statement"
if_true if cond else if_false
The fucking important part, the condition, is hidden in the middle of that sentence and would be much easier to accidentally miss when reading over code.

If you think that's bad, just wait until I finish my compiled language designed to be written on cellphones using speech recognition. I call it "English."

Let there be a kind of thing called a point and let it be defined thus:
Let a point have integers called x and y.
Thus concludes the definition of the kind of thing called a point.
Let there be points called p and q.
Let the x of p be 0.
Let the y of p be 1.
Let the x of q be 1.
Let the y of q be 0.
Let there be an integer function called distance, in points called a and b, and let it be defined thus:
Let there be an integer called x distance, and let it be defined as the x of a minus the x of b.
Let there be an integer called y distance, and let it be defined as the y of a minus the y of b.
Let this function simplify to the square root of the sum of the square of x distance and the square of y distance.
Thus concludes the definition of the integer function called distance.
Report the distance of p and q.

do you really speak like that

No. Of course I don't.
That's the best part.

>speech recognition programming
wew lad, it is interesting tho

Looks like COBOL.

I was actually kidding, I'm not working on this.

Though, having said that, it might not be a bad idea if it could be done better than this. If it's friendly enough, a programming language that can be read aloud without loss of information -- and can therefore be written via speech recognition -- could revolutionize the nature of programming as a discipline. Imagine, people could be programmers and still actually go outside.

>I was actually kidding, I'm not working on this.
You can't imagine how I'm mad when actually good ideas, released on April 1, happen to be jokes.

Are you from a country like germany, where anybody can start studying cs without any entrance test? If so, probably morons who did not know what to do yet and "liked computers" a.k.a. Photoshop Philipp or Sup Forums. Bet they become fewer in the higher semesters

Rust's error handling is confusing.

How so?

>what is the human memory
The only thing that will revolutionize programming is convenient AR.

Like your phone being the host and turning a surface or two into a projected screen and (magically) have a projected keyboard with feedback and the feel of switches. Or people will just get implants to pair.

oh my god it's april 1 I didn't even realize
don't worry though, I'll probably still do this at some point now that I've got my mind set on it, it'll just be a lot less needlessly verbose than what I've got here

that would also be cool

Why couldn't it just use the simple try-catch model

Its still the 31st in relevant land

>Imagine, people could be programmers and still actually go outside.
I can't imagine how you would program on the go, to be honest.

...

Because try/catch isn't very simple. It can be a control flow nightmare, which is important to avoid when you have RAII and not garbage collection. Not that Rust doesn't have your standard exceptions, they're just called panics and you're generally not supposed to catch them because then you don't have strange control flow.

What's it doing here? Converting it to a set and doing a set union with itself?

haha holy shit i tried doing all the logic for a game in stored procedures once, never again, dude never again

C++ has try-catch

>laptop keyboard

what's g++ -c doing?