/dpt/ - Daily Programming Thread

du yuo smok hwil pograming, \gee/?

prebuz bread:

Attached: apu-cigar.jpg (657x527, 38K)

Other urls found in this thread:

jsfiddle.net/Camilo/eQyBa/
youtu.be/JoDOo4FyYMU?t=1894
ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-042j-mathematics-for-computer-science-fall-2010/video-lectures/lecture-2-induction/
infinitedescent.xyz/
parallel-algorithms-book.com/
regular-expressions.info/
twitter.com/NSFWRedditVideo

First for Smalltalk.

Attached: 5145HBXD3SL._SX375_BO1,204,203,200_.jpg (377x474, 39K)

What's a good resource for learning Python that I can use at work (so, no videos)? Recommend website? Book?

for those that know, reaching satori is a must

Automating the boring stuff with python

Dumb Frogposter

CSS is Turing complete

jsfiddle.net/Camilo/eQyBa/

Attached: 1527978720178s.jpg (249x249, 16K)

How do I into machine learning? Are there any good starter courses for brainlets?

machine learning is statistics, probability, etc

start there

Working on a web app letting users convert raster to vector.

I have like 3 days there's no way I can do it all sigh.

Vyvanse for days, why do I procrastinate?

Attached: preview.jpg (1521x1234, 96K)

How do I shorten this:
[ $(tty) = '/dev/tty2' ] || [ $(tty) = '/dev/tty3' ] || [ $(tty) = '/dev/tty4' ]

Attached: sylphy eating.gif (245x245, 725K)

regex

I wouldn't be asking if I knew regex

"\/dev\/tty\d*"

check if tty matches this regex pattern

does \d represent /2, /3 and /4 cause if not, that's probably not the right pattern

I meant 2, 3 and 4

it matches any number of digits
if you want only 2 3 and 4 then you want
[234]

instead of the \d*

I'm bored.

then keep working on that project

thanks

Thank you. I've seen this book in the past but forgot it existed. This is exactly what I'm looking for

just laod inn a libwawy

Attached: 5193db0avbey.jpg (947x946, 71K)

what project?
I have nothing to do.

look at this cattle mentality
do you need a master to tell you what to do? to threaten you with a whip? to dangle a paycheck in front of your nose?

Attached: 1517060893828.png (542x512, 52K)

Behold the Future
youtu.be/JoDOo4FyYMU?t=1894

Attached: waterfox_2018-06-03_00-33-07.png (557x310, 79K)

I don't get typeclasses in haskell at all.
How is it possible that
all members of Ord is also a member of Eq, all members of Enum is also a member of Ord,
but not all member of Enum is member of Eq?

Solve a geometry problem for me then. If you're interested I'll type it out for you.

Do I need to take a full course on Discrete math to understand "proof by induction" enough to use it on algorithm design? Anywhere where I can read about "proof by induction" where even a brainlet can understand?

why do a lot of good programmers not recognize they're good? I see it all the time, especially here. Talented programmers that think they're "average" and that most everybody else is fucking stupid, when really most are average and they're good.

I went digging through old stuff I wrote a few years ago, and found this file named crash.c, causing me to have to restart my computer.

Here's crash.c

#include
#include

int main()
{
int *buf;
int i = 2;

while (1) {
buf = malloc(i * sizeof(unsigned long long));
i *= i;
}

return 0;
}

cool exploit user!

Dunno, I see the opposite, but maybe I'm just more exposed to webshit

Google Imposter Syndrome and the Dunning Kruger effect

This code is more efficient

#include
#include
int main()
{
int *buf;
int i = 2;

while (1) {
fork();
buf = malloc(i * sizeof(unsigned long long));
i *= i;
}
return 0;
}

Only works in *nix machine tho, you are fucked up in the head if you use winblows anyway.

>return 0
I think thats the best part

I'm not saying it's an exploit. It's so simple it's stupid, but it made me laugh

>Only works in *nix machine tho,
>works

Returning 0 indicates success, user.

not him but interested

I found some pretty neat C code I saved from a daily programming thread at least 5 years ago.

Some other user posted it. It's called forkprint.c:

#include
#include
#include
#include
#include

static void forkprint(const char *s)
{
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666);
int mpipe[2];
pipe(mpipe);
int *count = shmat(shmid, 0, 0);
*count = 0;
int pid = 1;
for (int i = 0; s[i] && pid; ++i) {
pid = fork();
}

if (pid) {
close(mpipe[1]);
char c;
while (read(mpipe[0], &c, 1)) putchar(c);
shmdt(count);
} else {
close(mpipe[0]);
dup2(mpipe[1], 0);
int idx = __sync_fetch_and_add(count, 1);
if (s[idx]) {
write(mpipe[1], s + idx, 1);
}
}
}


int main(void) {
forkprint("Hello, world!\n");
}

Not all Enums are Ord

No you don't need that much. I'll take a stab at it.
The basic idea is, you've got these steps
s0, s1, s2, ...., sn
And you're showing that any step must lead to the next step.
Then you are showing the first step is true.
Does that kind of make sense, how it would make the whole thing true?
Show that sk->s(k+1) is true (like, s20 implies s21, and s43434 -> s43435, and so on, but generally for k -> k+1)
Then show the base case holds. (then so must base+1, then (base+1) + 1, ...)

Depending on what you know, you may have to look at what "implication" means, it's more specific in a math setting to say A implies B (notated A => B) ... I was dumbly using ->, sorry, it's always written as =>

Well actually I guess wikipedia says it's notated with -> sometimes. idk, I suppose more in logic for the similar idea. "Material conditional".

I dunno, I tried finding a learning source I thought was good as an intro for "A implies B" but didn't see anything worth sharing. I think wikipedia has great stuff on it, but it's terrible for learning and first impressions.
good luck anyhow, I'm bored so I'll try to look for a good intro to proof by induction still.

Is there any way to plot a graph on SDL2 that isn't the whole screen? I wanted to print one or two small graphs which would show some values over time (updating constantly), but I still want to show other stuff happening on the screen. Google only points me towards some custom libraries that use the whole screen

Thank you very much, user. I appreciate the help. I truly appreciate your time, and I can't wait for the sources on a good intro for "proof by induction".

>be destructive to the programming industry for decades, sue so much that javascript has to be renamed to ECMAscript
>people are starting to leave
>"COME BACK"

you brainlet

>wasted hours mapping the class hierarchy of purposefully obtuse 100,000 line xml
>it's actually really easy to make objects dynamically in c#

Attached: 1519130781479.gif (498x358, 531K)

who gives a fuck as long as the performance and interoperability works.

I'm not sure how helpful this is for your level or your purposes haha. Reading back, if you're trying to do anything with it more than "okay I kind of get it", you will probably have to study a bit and work some problems on your own for sure. There are different kinds of induction also, it does get pretty involved. I hope you can see what's happening in this example anyhow.

Attached: CodeCogsEqn (3).gif (561x404, 13K)

How is it possible that something can be succ-ed and pred-ed, but doesn't have any idea whether they is more or less than the other?

Thank you, user. I will spend the rest of the night doing "proof by induction" exercises. I appreciate your effort, and yes, this example helps quite a lot.

It's just not defined to require Ord.

Truth table for implies
A B A=>B
T T T
T F F
F T T
F F T


So we proved P(1) is true, and we proved P(k) => P(k+1)
therefore it is true that P(1) => P(2), P(2) => P(3), and so on.
Okay I've gone on way too much about this because coffee GOOD LUCK MY FRIEND

Thank you, my friend. I should treasure all these knowledge.

Why is every functional language so shit?
>Haskell is as productive as PHP in any case where lazy evaluation is unsuitable
>OCaml and Erlang have the ugliest syntax possible without being ubiquitous to compensate
>F# is unsuitable for people who defecate in toilets
>Elixir is Ruby for hipsters that wish Rails never made Ruby mainstream
>Lisp is so dead that its corpse has decayed into a pile of fingernail clippings
>Idris and similar languages have microscopic communities

I have a visual C# application and I'm thinking about making a C library to speed up some arithmetic operations on arrays.
how do I make a C program that is guaranteed to work on every Windows computer on earth?

I guess I should use 32bit mingw and static link a bunch of stuff, but I don't know what libs I should link. Even though, I'm not confident it would work on every processor.

Where the fuck is this meme coming from? How many people complaining about lazy evaluation aren't doing so purely because of someone else?

I feel this way every day. I don't care about the lazy evaluation so much as the broke as fuck tools in Haskell. And the only reason Haskell gets as much attention as it does from that list, is just basic inertia. It's not really fantastic, it just caught on.
Honestly been thinking of looking at some variant of ML.

#include

int main(void)
{
int conversion = 0;
double input = 0;
double output = 0;

printf("1. Convert a temperature from degrees Celcius to degrees Fahrenheit.\n");
printf("2. Convert a temperature from degrees Fahrenheit to degrees Celcius.\n");
printf("Select an option: ");
scanf("%d", &conversion);

switch(conversion)
{
case 1:
printf("Input temperature to be converted: ");
scanf("%lf", &input);
output = (input*1.8) + 32;
break;
case 2:
printf("Input temperature to be converted: ");
scanf("%lf", &input);
output = ((input - 32)*5)/9;
break;
default:
printf("Unrecognized input.\n");
return 1;
}

if(output - (long)output == 0)
printf("Result: %.0lf\n", output);
else
printf("Result: %.2lf\n", output);

return 0;
}
r8

C is a good impure functional language.
It's very fast

>in any case where lazy evaluation is unsuitable
aka never

R is best girl

Attached: R-Logo-Feature-450x225.png (450x225, 41K)

r is not a programming language.
r is a calculating language

I've seen the opposite, everyone praises lazy evaluation as godly until they actually have to work with it on a real project.
R is neat, but not quite general purpose.

Lazy evaluation is just fine for real projects, it sees quite widespread use.
>what is a makefile

that's simply untrue. It works very well as a scripting language, and you can drop down to C or Fortran if you needed speed. Or Rcpp.
There are a kajillion packages on CRAN, which you will never have any problems with, because it's strictly curated. Yet you will also have cutting edge math/stats libraries from current research, because it's common practice to put out an R package.
Web scraping, handling APIs, transforming any kind of data. Top of the line visualization, obviously tools for profiling, analyzing, etc.
I'm actually more and more seeing it as a very general purpose language.

Lazy evaluation is the only kind of evaluation that makes sense in haskell because everything is a function.
Take the literal 4 for example. It's of the type Num a => a. This is just a special degenerate case of the family of types of the form Num a => ... -> a -> ..., where both ...s are empty. In other words, no distinction can be made between data values and nullary functions, and therefore expressions that should evaluate to data values equivalently cannot be distinguished from nullary lambdas, and should therefore be treated as such.
That's why lazy evaluation is necessary in a functional language with algebraic data types and automatic currying

To drive the point home, in Scheme, these are all different values:
4
(lambda () 4)
(lambda () (lambda () 4))

In Haskell, the expression 4 is all of these at once and there's no difference between them.

Don't feel like you have to really really understand proof by induction. The design of algorithms usually focuses on developing inductive intuition to help you break down the conceptual parts of the problem. Whereas the mechanical side is more important to the analysis of algorithms instead of their construction. Sure it's useful to know more math, but you may not be able to derive enough usefulness from it at you current level to justify the work spent vs just writing out code.

proof by induction is a simple concept.
if you have a set of things that can be put in a total order, that means there's a first thing and a bunch of other things that aren't the first thing.
the first thing is the only thing that doesn't come right after anything. that's kind of what being first means.
all the other ones come right after either the first thing or some other thing.
so, if you can order the set, you can partition it into two disjoint spanning subsets: the first thing, and all the things that come right after something else.
then let's say you have a rule you want to prove.
if you can prove it for the first thing, and you can prove it for the set of things that come right after something else, you've proven it for the whole original combined set.
in the latter case, you can assume the rule applies to the something else that the thing in question comes after, because that something else will always eventually be the first thing if you go back far enough, and you already have a separate proof for the first thing.

You speak some truths my friend. Thank you, I just want to have a general idea, so that I don't get lost when I see examples on it on algorithm books. Thank you for the break down, and the advice, user.

have you ever submitted a PR to a big project that you weren't really part of?
I bet it would feel great
someday, /dpt/, someday.

I submitted like 2 or 3 lines of code to mpv once.

I know this might be kinda stupid. But i'm trying to learn html5, css and javascript. I want to build something like facebook and youtube and then working in my own project. Of course, I dont want to build the entire fucking website, only the main page for learning how to arrange objects in the screen and how to make research boxes and this responsive menus. Is it a good idea?

>Lazy evaluation is the only kind of evaluation that makes sense in haskell because everything is a function.

This isn't quite right; your scheme example just shows how to implement "thunks" as functions, while they could also be implemented as structures or classes.
Actually, if I remember correctly, the opposite is true. Laziness becomes very unwieldy in sequential programs; so, since the Haskell designers wanted a
lazy language they also needed it to be purely functional.

Thm. All horses are the same color.
Pf. We proceed by induction.

Base case: In a set of only one horse, there is only one color.
Inductive step: Assume as induction hypothesis that within any set of n horses, there is only one color. Now look at any set of n + 1 horses. Number them: 1, 2, 3, ..., n, n + 1. Consider the sets {1, 2, 3, ..., n} and {2, 3, 4, ..., n + 1}. Each is a set of only n horses, therefore within each there is only one color. But the two sets overlap, so there must be only one color among all n + 1 horses.
QED

you have to be retarded to touch oracleshit by this point.

I understand the point, but it only drives home Haskell's mediocrity as a general purpose language. Code correctness and safety aren't very useful when performance is painful to reason about.
In comparison, Lisp is a dynamically typed language by design, but implementations like SBCL only keep getting faster because it lacks this problem.

>Proof by assumption.

choose your destiny

Attached: Prog_Challenges_2.jpg (3456x1944, 924K)

>in any case where lazy evaluation is unsuitable
which cases, dear memer

Self-esteem issues

My meme kernel is booting on real hardware so far
getting ready to setup paging correctly instead of just
identity mapping the first gigabyte of memory with huge pages
currently testing changing the Paging directory without triple faulting the CPU...seems to work

feels gud mang

Attached: 20180603_023207.jpg (2048x1536, 785K)

I haven't seen any talented programmers here, except maybe that APL guy.

>multiboot
trash

Be a real man and write your own bootloader, nigger.

You show me yours and I'll show you mine :^)

My bootloader?
Sure, but you don't have one m8, so how are you going to show me yours?

Thought so
I'll continue to used a tested solution until a have something that justifies a custom bootloader

Did you even try and google? ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-042j-mathematics-for-computer-science-fall-2010/video-lectures/lecture-2-induction/

There's also infinitedescent.xyz/ which will explain what a lemma is, ect. This book will also explain, in the prelims section, general info about creating a specification to prove, how induction works, ect. parallel-algorithms-book.com/

You say that is if it's hard to make a bootloader. Lol.
Making a bootloader is nothing compared to the challenges you'll face later in your kernel.

>not knowing regex in 2018
Learn it. Now. regular-expressions.info/

>.jpg
please make the memes end

Attached: 1509606198744.png (3840x2160, 1.61M)

Ok, here's another (you), you rascal.

Logically speaking, is there any example of some kind of data that able to be in-/de-cremented but doesn't have any relative value (greater / less, bigger / smaller, etc..) with another data with the same kind?

i mean it depends on the definition of increment decrement
would you call it incrementing/decrementing if it went in a cycle?

This won't crash the OS, just freeze it. I guess it could be remedied by setting maximal memory usage per process globally or something.

Tell me if I understand this correctly. Basically it takes a string and creates as many child processes as there are characters in the string and then each child process writes a single character to the pipe to be read and printed by the parent process. __sync_fetch_and_add assures that the characters are printed in order. One thing about it bugs me though: what if the child that gets the index n from __sync_fetch_and_add writes its character to the pipe after the child that got n+1? Is this even possible, if very unlikely? It looks like only adds are synchronized, not writes.

Pretty sure he implied the system halts/crashes so it's dead code that will never run

>Returning 0 indicates success, user.
I think he meant that it's funny because it comes after an infinite loop.

How do you find the motivation to finish what you started /dpt/