/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

yegor256.com/2017/02/21/say-no-to-google-recruiters.html
redsymbol.net/articles/unofficial-bash-strict-mode/
twitter.com/SFWRedditVideos

first for pascal

>cpp at all
Get a load of this fag.

Third for C is a miracle of this universe.

*Rust

That would be anime.

Really really really basic 3D question. I have
* a 3D position, P
* a direction vector, D
* a length, L

I want to calculate P', which I define as the result of moving P, L units, in direction D.

Imagine I want to draw a line showing a triangle's normal for debugging reasons. (This isn't exactly what I'm doing, but it's analogous.) P is the centre of the triangle, D is the normal, and L is an arbitrary number.

I think I can do this by creating a full-on 4x4 transformation matrix out of the required rotation specified by D and a translation specified by L, and multiplying P by this matrix. That really seems like overkill, though- surely there's a simpler/faster way to determine P'x, P'y, and P'z given Px, Py, Pz, D, and L?

_Dude, it's just P + L * Dn, where Dn is normalized D, i.e. D * 1/|D|.

Thanks. I feel like that should probably have been obvious to me... I'm very new to 3D work.

if you don't dress like this you aren't a real programmer

...

NP, that's what normalized vectors are for: representing a direction in a way that's easy to apply.

> And instead of JS, we'd be stuck with C++. Not an improvement.

HN at its finest.

That's correct though.
As shit as JS is, C++ is definitely worse.

if you don't wear a lab coat you aren't a real programmer.

If I shouldn't have learned c++, what should I have learned?

C, I suppose.

JS

I've been learning web development on the side of my current job and college, and, as projects, have made websites for local restaurants that have no/very bad websites. I'm not hoping to make much money on these, but, what would be best for approaching these businesses and presenting what I've made to sell to them? Any other advice regarding this?

If I'm writing a script in python that I'll put in my path should I just remove the .py?

hey mate that's pretty cool

how much do you get paid for making the restaurant sites?

use squarespace and tell nobody that you're using squarespace

Oh, what I meant is that I've been making these websites for local businesses without their knowledge, as a sort of exercise material. I haven't even approached them yet.

I was just wondering how much I ought to ask for, and how to approach it.

useful tip of the day:
you can find the address of your code by calling a pop instruction:
call .a
.a: pop eax
; now eax contains the address of the previous instruction

>find the address of your code
Why would that be useful?

Why do I feel like shit all the time, I feel like I have constant cold, anyone else experience this?

If you're going to do that in C, make sure to push it again or else everything will break.

go to the doctor and tell him this

which linux distro should i get to run in virtualbox for the purpose of learning c?

Gentoo. I'm serious.

writing position-independent code

could you further explain pls daddy

Are you me?

it doesn't matter

d e p r e s s i o n

...

Why is the compiler giving me that error?
import std.stdio;
import std.algorithm;
//take an array, sort it and reverse it
void main(){
write("Enter the number of values you want to store: ");
int len;
readf(" %s", &len);
int[len] ins; //

allergies, lack of sunlight exposure

say you have a function you want multiple copies of at runtime
each function has its own local data located nearby, at a fixed offset from your code
so you find the address of your code, add the offset and now you have a pointer to the local data structure

use D's equivalent of malloc instead

alright

can somebody recommend a linux crash course? i've never used it before.

D doesn't support VLA's
Use
int[] ins = new int[len];

unless you need it on the stack for some reason

Ubuntu MATE

Explain this to a CS101 class as their first day on arrays

I don't understand, what do you want me to explain exactly?

>using a stack at all

I HAVE ONE WORD FOR YOU
STATIC ALLOCATION OF PROCEDURE ACTIVATION RECORDS
THREAD OVER

Any good books for cracking? hacking software and exploits

when you want to do something, google how to do it. like if you're in the console and need to switch directories, google how to do that. the command "man ___" will bring up the manual page for ___ if one exists. i've used linux for 2 years and just today i learned xdg-open opens the gui file viewer for a directory. e.g. xdg-open . to open the current directory, because . is the current directory. it's a lot of fun, using linux. you get more productive as you keep using it

not but arbitary size arrays are not allowed to be stored on the stack, as all variables stored on the stack are on predeterminied offsets from the base pointer, The only place you are allowed to store variable length arrays is on the heap, to do this you initialise an int array of a length on the heap, and then store a pointer to it on the stack.

myfun x = reverse $ sort x

this can be just
myfun = reverse . sort because of currying

just have the stack reform itself at double the size when it hits max capacity and someone tries to push to it

you mean because of eta reduction

myfun x = (reverse . sort) x
myfun = reverse . sort

λ> import Data.List
λ> let myfun = reverse . sort
λ> let x = [2, 5, 3, 2, 1, 7, 4, 3, 8, 4, 5]
λ> myfun x

:20:7:
Couldn't match type `Integer' with `()'
Expected type: [()]
Actual type: [Integer]
In the first argument of `myfun', namely `x'
In the expression: myfun x
In an equation for `it': it = myfun x
λ>

You can't grow a stack variable, but it definitely can be of arbitrary size

Really, it could just be
ins.sort().reverse();

in D

what does static keyword mean in programming?

works on my machine
Prelude Data.List> wew = reverse . sort
Prelude Data.List> wew [1,2,3]
[3,2,1]
Prelude Data.List> wew [1,2,3,4,5,65,23,234,242,24,23,42,64]
[242,234,65,64,42,24,23,23,5,4,3,2,1]

Whatever the language wants it to mean

usually, static environment (vs. dynamic environment).

Google it

$"static {lang}"

Are partition tables and file systems on x86 computers always stored in little-endian byte order?

>he doesn't have the based "secondary stack"

what took me an hour to set up on windows has taken me a grand total of 2 minutes to set up in ubunto because i could just apt-get install all the c libraries i needed

why can't windows have apt-get install

>why can't windows have apt-get install
It does.

is left-shifting a signed integer ok as long as it doesn't overflow arithmetically?

this is not ok:
int foo = INT_MIN;
int bar = foo

>Bit shifting a number

if i multiply a signed int by a power of 2 will the compiler optimize it into a bitshift on relevant architectures?

yes, as long as you multiply by a const value

cool thanks

Sure.

Script to rename file with random Sup Forums filename.
#!/usr/bin/env python
import os, sys, random

if len(sys.argv) != 2:
sys.exit("usage: 4chrename file")
old = sys.argv[1]
dir_path = os.getcwd() + os.sep
if not os.path.isfile(dir_path + old):
sys.exit("not a file")
i = old.find(".")
ext = old[i:] if i != -1 else ""
start = 1401427584643
end = 1487817132668
new = "{}{}".format(random.randint(start, end), ext)
while os.path.exists(dir_path + new):
new = "{}{}".format(random.randint(start, end), ext)
os.rename(dir_path + old, dir_path + new)
print "{} -> {}".format(old, new)

i installed mingw so i can compile for windows from linux, how do i add libraries to mingw?

git

I want /prog/ back on Sup Forums.

c++ 11 = patrician

c99 is ok too

allow me to interject for a moment

>The C language is my shepherd; I shall not want.
>He makes me lie down in reading manuals. He leads me beside mature libraries.
>He restores my stdout. He leads me in PATHs of POSIX for his name's sake.

>Even though I walk through the valley of the shadow of bloat,
>I will fear no C++, for you are with me; your structs and your unions, they comfort me.
>You prepare a triple dereference and increment before me in the presence of Rust fanboys;
>you anoint my head with pointers; my stack overflows.

>Surely malloc and goto shall follow me all the days of my life,
>and I shall dwell in the house of the Embedded forever.

zedshaw 781 days ago [-]

Well this if fun folks, but frankly, you all have proven just how conservative programmers are. My chapter advocating something as "revolutionary" as including the lengths of strings when you process them has received more hate mail than anything I've written. And I'm the guy who gets death threats because I don't like Ruby.

If you are reading this and saying, "This guy's wrong about including the lengths of strings!" Then I ask: Why are you using any modern language? Nearly every language in use today include the lengths of strings and backing buffers in their string implementation, and you all use it and appreciate it, but when I advocate it suddenly it is heresy and deserving of vitriol.

I personally don't care what you all think, which I know insults your pride at being the smartest people in the room, but until you are willing to admit that your hatred of that chapter is based entirely on nostalgia and not on the merits of my fairly simple claim that K&R (or any) C code is error prone, then you are not going to advance the state of the art any further than the 1970s.

This is what makes me sad about computing today. You are all desperately clinging to the notion that you are radical free thinking futurists while you desperately cling to reverence for the past and are incredibly resistant to any change. If something as simple as a thought experiment to look objectively at how things are done and try something better makes you angry, then you are not free thinking futurists.

Anyway, enjoy your day folks. I'm going to go do some painting.

Me programming! Which way shall I fly
Infinite wrath and infinite despair?
Which way I fly is /prog/; myself am /prog/;
And in the lowest /dpt/ a lower /dpt/,
Still threat'ning to devour me, opens wide,
To which the Sup Forums I shitpost in seems a heaven.

>LANGUAGE-IMPOSED ALIGNMENT OF SOURCE CODE TO PREDEFINED SPATIAL BOUNDARIES

He's right, Forth and Pascal had it right back in the 1970's.

so how do i get python to open a webpage ? in my calculator program i want it open to a youtube video when the user inputs something wrong

> yegor256.com/2017/02/21/say-no-to-google-recruiters.html
> expert in object oriented design
> doesn't know how to traverse a binary tree

really fires up your neurons

help this nigga out i guess

Write me a c# program with a method that counts the letters in a word

string.Length

oh shit, cool

nvm i figured it out

what was the answer

import webbrowser
webbrowser.open("insert url")

no indentation needed for the second line

any bash options i should enable when writing scripts besides the ones here?

redsymbol.net/articles/unofficial-bash-strict-mode/

Too late

hmm its returning a boolean for me... Python 2 or 3?

You fucking whore

remember when i said that linux was great

i take that back, i'll just use mingw

ONE WORD
THE FORCED INDENTATION OF CODE
THREAD OVER

nevermind, just realized you have to add http:// first

That was VIP quality!

Run mingw on Linux, test with Wine.