/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1533440827829.png (810x698, 514K)

Other urls found in this thread:

raft.github.io/raft.pdf
web.stanford.edu/class/cs106b/homework/2/ngrams-spec.html
madprops.github.io/Snek/
open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1221r0.html
pastebin.com/CxEzVRkW
twitter.com/NSFWRedditImage

first for use C

An AI-powered programming language

third for turds

I want to become an enterprise meme developer: C#, Java, or Kotlin?

Attached: k-kawaii.png (1280x727, 1.05M)

C#

If you're serious, Java

C#. Java's too old and Kotlin's too young.

Nobody uses Kotlin
Java is gay, I'd only use it if you wanna transition into something not gay like scala later

java is very widely used, it's good to know. i have no personal experience with c#, but have heard it's also reasonably popular in enterprise environments.

kotlin is a meme, almost nobody uses it outside startups

How do I render a polygon in 3d space from an arbitrary position and angle?

the task was to write a function that checks if two strings of length n are the same

int same(char* s1, char* s2, int n) {
if(n==0) {
return (n==(s1[0]==s2[0]));
}
return n == ((s1[n]==s2[n]) + same(s1,s2,n-1));
}


is this good? I cant fail this class

Thank you, I will start learning C#.

Attached: resigned to my fate.png (364x364, 191K)

With a transform matrix. Traditionally they separate them into three transforms: World, View, and Projection, but they get aggregated into a single transform.

Well, user...
>I cant fail this class
Never mind, you're on your own.

you're thinking too hard.

What is Ruby good for?

Actually, it's not just tradition. Obviously, you have minimally a world matrix for each object, and a camera matrix. However, the camera matrix is split into a view matrix and a projection matrix, even though you're unlikely to mix and match them, because lighting is computed in view space.

just use node.js

That is an inappropriate use of recursion, especially because it's not tail-call.
You're being too "clever" for your own good.

Don't use recursion just because you can. It's bad.

Basically a better, actually readable perl.

I don't intend to learn Ruby. I just wanted to know if there is anything in particulat that is easier in Ruby.

Shit, didn't even think of that.
Thanks, all!

World/Camera separation makes sense from a logical/conceptual level. I'm just saying that mathematically, all you're doing is pushing points through a single transform matrix. In fact I'm more doing this to imply that you can, should, and WILL add on more and more transform matrices on top of those, not so much to suggest that you should re-invent the pipeline wheel.

>is this good?
nigga it doesnt even work
does your assignment require it to be done recursively? if so, here you go:
#include

#define MIN(x,y) ((x) < (y) ? (x) : (y))

int same(char* s1, char* s2, int n) {
if (n == 0)
return s1[n] == s2[n];
else
return MIN(same(s1, s2, n-1), s1[n] == s2[n]);
return 0;
}

int main() {
char *a = "Test";
char *b = "Test";
printf("%d\n", same(a, b, 4));
return 0;
}

I've always wondered, why do you need to do this?
Just subtract the camera position and call atan2 twice, then subtract the angles. Why is a matrix faster?

I just saw one of you faggots on stackoverflow. I feel violated.

Attached: Scared Satania.png (1000x1000, 223K)

You're missing the bigger issue, that he compares n to everything. Just remove n== and you get a working program.

Ok. Let's say that instead of shifting then rotating, you needed to shift, then rotate, then scale, then shift again, then rotate again, then shift and rotate again, then apply a projection using aperture / field-of-view logic. This is usually what you need in a 3D environment

Your way that's like 20 calculations per-vertex and it's hard to communicate an arbitrary list of these to the GPU who's doing all the work.
Using transforms, all you need to do is multiply a vector by a matrix.

who was it? name & shame
was it that Anonymous dude?

Because you can combine as many matrices as you want together ahead of time, and apply the transform efficiently later as a single operation. It doesn't matter how much shit you're doing; it's a single matrix multiplication.

Post it

Maybe he'd realize that if he didn't set up his program so counter-intuitively. Frankly, I didn't even try to understand the program because it's conceptually bad. Fix the conceptual bad before you fix the logic.

Matrix isn't faster, it just represents all the possible transformations you want to do with the camera like perspective, rotation, scaling, skew, etc

the function returns 1 if the both strings are identical else 0

where is the issue? it just works

But if you're only doing basic rendering, it would be equally fast?

yeah okay it works with the addition
still, don't write retarded code like that unless you're competing in the ioccc

Basic rendering? What I described is a pretty basic scenario: you have an object which has its own position, scale, and orientation inside a world which has its own position, scale, and orientation, seen by a camera, which has its own position, scale, and orientation, projected to a screen which has a field of view and clipping bounds.

That's about as basic as it gets in 3D.

Even 2D gets pretty complicated pretty quick. You need an orthogonal projection on top of a pan box on top of each object's orientation.

Guffa, and of course he's an Assembly loving ancient gamer boomer turbowizard.
>I have used a lot of different languages over the years, like 6502 machine code, 68000 assembler, x86 assembler, Atari Basic, GFA Basic, Compis Pascal, Turbo Pascal, C, VB 6, VB.NET, C#.

Well, since everyone else is posting their solutions

int same(char *s1, char *s2) {
for (int n = 0;s1[n] || s2[n];) if (s1[n] != s2[n++]) return 0;
return 1;
}

Being able to combine a transformation hierarchy into one isn't a unique property of a matrix. You can do it with just x,y,z coordinates if your objects only need a position. The reason matrices are used is because they can represent several transformations at once (position, scale, rotation, perspective transformation, etc)

i saw that, friendo

Attached: 1529061672434.jpg (509x499, 123K)

Dial your sensor back a tad. I literally said that two posts down the chain and the post your replying is a direct response to a question of WHY you do it that way because requiring multiple transformations is a common scenario.

i realized my mistake while it was posting, pls forgive ;_;

:3

int strcmp(char* s1, char* s2)
{
while (*s1++ == *s2++);
return *s1 > *s2 - *s1 < *s2;
}

dumb but fast frogposter

STRCMP (const char *p1, const char *p2)
{
const unsigned char *s1 = (const unsigned char *) p1;
const unsigned char *s2 = (const unsigned char *) p2;
unsigned char c1, c2;
do
{
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0')
return c1 - c2;
}
while (c1 == c2);
return c1 - c2;
}

Give him this and you win all the things.
s(char*a,char*b){return*a?*a-*b?0:s(++a,++b):1;}

>b longer than a
>returns 1
dummy

The problem specified they're both length n, dipshit.

why are you so rude

>expecting consistency in C
dummy

This is the code your teacher wants to see:
int stringCompare( char* s1, char* s2, int len) {
for( int i=0; i < len; ++i) {
if( s1[i] != s2[i])
return false;
}
return true;
}

Analyze its simplicity and clarity and strive for it. Cut out the "clever coder" cancer before it takes root. It has been the ruin of greater coder than you.

I'm trying to do a sliding puzzle for a school project in assembly. Anybody know any good resources for MASM, specifically Mode 13h?

Rate my Haskell fizzbuzz.
(unsafe! (mutate! *turing-complete* true))
(mutate! *codegen* :haskell)

(type fizz-buzz Π :nat (:prog (Π :unit :str)))
(defn fizz-buzz (n)
#_(compiler (optimize *fn-body* :nat-opt :pmatch-opt))
`(λ (_)
(match ((mod ~n 3) (mod ~n 5))
(0 0) "FizzBuzz"
(0 _) "Fizz"
(_ 0) "Buzz"
:otherwise (show ~n))))

(type main Π (:prog (Π :nat :str)) (:io :unit))
(defn main (prog)
(do-io!
;; Base case - the program is a nop.
(when (nop? prog) (cons- prog `(io! (println :unit)))
(let (new-prog :infer-type)
;; Check if the compiler halts.
(if (halts? (compile prog))
(main (read (eval (compile `(map prog @[0..100])))))
;; If compilation doesn't halt, we optimize the code so that it halts on the next recursive call.
#_(compiler (optimize *if-else-branch* :recur-till-halt)))
(main (optimize prog :force-halt)))
(eval new-prog)))

(type prog Π :nat (:prog (Π :nat :str)))
(defn prog (n) (compile `(λ (_) (map (show ○ eval) (map fizz-buzz @[0..~n])))))

(io! (main (prog 100))) ;; => usual fizz-buzz, but guaranteed to halt.

Attached: 1555113059457.jpg (562x1000, 154K)

Web dev MVPs (see: devise, activeadmin, cancancan), rails in general
DB heavy applications
CLI programs, if the user has ruby installed (very likely, it comes with mac) you can get a lot of stuff done without anything 3rd party libs, but also there's things like nokogiri, mechanize, tty to get shit done that is non-trivial in other languages

>get shit done that is non-trivial in other languages
What is non-trivial in any non-crippled language that is trivial in Ruby?

#include

int strnsame(char *a, char *b, int n) {
if(!a && !b && n == 0) return 1;
if(!a || !b) return 0;

int len_a = strlen(a), len_b = strlen(b);
if(len_a != n || len_b != n) return 0;
return !strcmp(a, b);
}

Keep It Simple Stupid

int same(char *s1, char *s2, int n)
{
while (n --> 0)
if (*s1++ != *s2++)
return n;
return n;
}

Doing things with dates and times is incredibly easy and you write it in english like "2.days" or "Date.yesterday"
Running commands and capturing the outputs is literally just typing `ls`
I can't think many right now but if you try using ruby it's rare you need to go import libraries to handle things that in other languages need that.

I feel so stuck with javascript. Everything where I work runs on Node.js, and when I'm practicing algorithms I default to javascript since it's so easy to get set up.

How do I get out of this loop?

>How do I get out of this loop?
By using recursion.

>sudo apt-get install gcc

sorry grandpa, no one uses C++ or C anymore

Speak for yourself, pahjeet

don't call me pajeet i hate pajeet

Attached: anger.jpg (600x532, 42K)

Write in other languages in your spare time.

I write in C almost exclusively in both my personal projects and my employment.

oh, sorry ahmed

why not just do

int same(char* s1, char* s2, int n) {
return !n || s1[n] == s2[n] && same(s1,s2,n-1);
}

Not a tail call.

what programming language does ahmed use? Pascal maybe?

>her compiler doesn't convert every recursive call to a tail call

Where can I start to learn programming? codecademy and freecodecamp?

red wire, blue wire

find out what you want to make first.

I keep losing interest in programming because I feel like I'm not making any progress or learning anything new. Are there any good books or new things I should try to expand my understanding and try new things?

raft.github.io/raft.pdf

>Haskell
Are you sure?

>why not just do
Cause I'm not a Ctard.

In C++ this is just
bool is_same(std::string_view a, std::string_view b) {
return a == b;
}

Trying to learn common lisp by doing assignments from an intro CS Course.

web.stanford.edu/class/cs106b/homework/2/ngrams-spec.html
How do I read in a file one word at a time?

I read about this function, split-sequence,but it doesn't seem exist in SBCL.

Attached: Screen Shot 2019-04-14 at 10.40.32 PM.png (1120x570, 109K)

based

@70558490
do not ever post at me again

ok

Just made a simple snake game. It's a nice project to do in ~3 hours. madprops.github.io/Snek/

Attached: chrome_2019-04-14_23-31-53.jpg (1160x855, 141K)

protip: x264 encoding defaults to 25fps. ffmpeg will match the output fps to the input fps by default. If your input fps does not match the output fps you are going to have a bad time when trying to do rtmp.

rei@streamingserver:~$ cat code/run3.sh
#!/bin/bash
# Encodes camera stream with timestamp and sends to nginx for rtmp streaming

rm -f /tmp/latest.mp4

nc 192.168.11.222 9999 | \
ffmpeg \
-loglevel warning \
-probesize 10MB \
-r 30 \
-i - \
-vf drawtext="fontfile=Roboto-Bold.ttf: fontsize=12: box=1: [email protected]: boxborderw=5: [email protected]: x=10: y=10: text='Cam2 - %{localtime\:%D %T}'" \
-c:v libx264 -preset ultrafast -tune zerolatency \
-x264opts "qpmax=40:qpmin=20:min-keyint=25:keyint=250" \
-pix_fmt yuv420p -an \
-f flv -flvflags no_duration_filesize - \
| \
ffmpeg \
-loglevel info \
-f live_flv -i - \
-c copy -an \
-f flv rtmp://192.168.11.200:1935/dash/cam2 \
-c copy -an \
-f flv rtmp://192.168.11.200:1935/hls/cam2 \
-c copy -an \
'/tmp/latest.mp4'

how is that programming

Ah, good point, it's scripting. You aren't programming either, user.

Attached: 1506143372712.jpg (450x450, 40K)

Okay. I'm really confused now.
I'm using this library, "cl-ppcre" to split a line into words, but am running into an issue.

Essentially, if I do (ql:quickload "cl-ppcre") on the REPL, then all of my code compiles fine.
However, when I try to compile the file by using slime-compile-and-load-file, I get this error:

I just want to be able to compile my file out of the box.

Attached: Screen Shot 2019-04-14 at 11.19.43 PM.png (1874x534, 101K)

open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1221r0.html
C++ is getting a new feature called Parametric Expressions which are kind of like better macros that allow you to take parameters as values, unevaluated tokens, and even constrain them to be constexpr.
They are always inlined.

its not even scripting it's command line arguments

I should mention, that this is the file I'm compiling. Any and all help is appreciated:
pastebin.com/CxEzVRkW

great, more C++ features, can't wait to not use them

Give me a quick rundown on trading bots. My brother came to me with the idea and I though that it would be easily possible, the only thing slowing you down is how much money you have. All you have to do is set up the bot so that it buys when
x is lower than your initial and sells when x is y amount higher than
your initial. Most of the websites I'm
looking at have APIs that allow for buy/sell calls. Is making a trading bot as simple as it sounds or am I not getting something?

most trading has been done by bots for decades

>has she-bang
>is a bash script
Why are you so hostile. This is all a part of a DVR and home security system I am working on. What is a better thread to share in the progress on my programming project?

Attached: 1487550014410.gif (470x313, 1.36M)

I was able to QR encode some data and print it out... But how do I read the QR code?