/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/raw/S1V67z2V
tutorialspoint.com/compile_c_online.php
ideone.com/ePluEN
codepad.remoteinterview.io/StartlingJoyfulBeatlesTemple
codepad.org/BUaBGRJd
twitter.com/SFWRedditImages

1th for Lua

second for c
#include
#include
int isPrime(int n) {
n = abs(n);
if (n < 4) return 1;
else if (!(n & 1)) return 0; // check for even

int i;
for (i = 3; i

Anyone here program from home for a living, either self-employed/contracting or via an employer ?
If so, how'd you get into it?

setmetatable(_ENV,{__index=function(t,k) return k end})


for great justice

Doing CGI webdev in C.

I don't want to learn a dumb scripting language.

I run my own programming/webhosting business
I have no clients still

Got a webdev job with Python/Django just by having a good portfolio (not even a degree)

Also trying to start running my own business

All you have to do is not go bankrupt in the first year and you're more successful than 95% of businesses
ezpz

I would tell you to kill yourself, but I thing you will regardless of what I say with that language choice.

>EXACTLY on time
>anime image
>trap

This is the perfect thread. Thank you.


Learn C++

What's wrong with the method in the OP?

Linked lists are slow, make a dynamically-sized array using realloc() + memmove()

Defeats the purpose of using a linked list

>pedo weaboo fags back
Kys

Well, it would work if that's what you're asking

I work as the sole developer for a startup. My house is my office and my conference room. I got lucky and met someone who was willing to take a chance on me despite my limited experience. It's a good thing i know what I'm doing.

>Doing CGI webdev in C.

thang for de job segurity 8-DDD

t. overpaid security man

neck yourself

do you actually get paid?
or is it like every other startup where you might get paid if it succeeds at some point in the future, or you get stock options or some shit

yes but computers these days are fast, so whats wrong with losing a couple of cycles when it's easier and works?

>whats wrong with losing a couple of cycles when it's easier and works

Computers these days are fast mostly because they cache well

Linked lists undo all that effort

This is reminding me of that time I ported a program I wrote from Python to C and it ran at about the same speed because I didn't implement hashing like I should have

Imagine if you made a copy of an array every time you wanted to delete something.
Now imagine if every item also required a malloc call.

isPrime(1) returns 1, when it should return 0. 1 and 0 are both considered not prime.

C is good for a lot of things, but I wouldn't use it for CGI web scripting

Incredibly inefficient. If you have some list A -> B -> C -> D, and you have a pointer to B after a search, deleting the element C would look like this:

c = B->next;
d = c->next;
free(c);
B->next = d;

No pointless copying and memory allocation.

60k a year. More than I've ever made before.

Keep it up, sprintf() is the one true templating engine

Everyone else is doing it wrong

you forgot to forget your trip
>isPrime(1) returns 1, when it should return 0. 1 and 0 are both considered not prime.
literally just one more if statement

nice

Not portable.

Yes it is.
Are you one of those idiots who thinks that bitwise operations on signed integers that don't involve the sign bit aren't portable?

>hNot portable

Anyone know what this does?

Deletes your CPU

On platforms that don't suck, it causes an access violation for trying to execute code on the stack.

Post the code.

I only have the screenshot

they're not you retard, maybe you should learn something about computers instead of harping shit you picked up from your youtube "how do I write python" videos

int main(int argc, char *argv[])
{
char t [313] = {
0xb8, 0x00, 0x00, 0x00, 0xb9, 0x1e, 0xab, 0x11, 0xca,
0xba, 0x95, 0x00, 0xfe, 0xff, 0x48, 0x0f, 0x88, 0x14, 0x01,

Ok I don't feel like transcribing more

Good spotting

Write an OCR program

It's fixed width, it shouldn't be hard

Why don't you just write a program to transcribe it?

The C standard only allows for 3 kinds of integer representations. Sign & Magnitude, One's compliment, and Two's complement.
They will all produce the same results for most bitwise operations, with the exception being shifts.

>((void(*)())t)()
I'm not going to test it.

Output the result to a binary file then disassemble it

Although we're waiting for the poster to transcribe the whole lot

you're truly an idiot. why do you feel like you have a saying about things you don't understand? lurk more faggot

you clearly don't understand shit, and just regurgitate what ever source you appear to think is 'reputable', like that midget fuck with his receptionist headset.

If you want to convince me show me some HARD PROOF

also
>you're

you're maybe better fitted for Sup Forums

you're maybe better fitted for reddit

prove how it's not portable

you're the one saying they're not portable faggot

caveat emptor

int main(int argc, char *argv[])
{
char t [313] = {
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x1e, 0xab, 0x11, 0xca,
0xba, 0x95, 0x00, 0xfe, 0xff, 0x48, 0x0f, 0x88, 0x14, 0x01,
0x00, 0x00, 0x30, 0x0a, 0xc1, 0xc1, 0x08, 0x42, 0xeb, 0xf1,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
0x76, 0xaf, 0x7d, 0xc7, 0x71, 0xea, 0x66, 0xc4, 0x6c,
0xa6, 0x75, 0xab, 0xb8, 0x85, 0x00, 0xfe, 0xff, 0x50,
0xb8, 0xe0, 0x1d, 0x40, 0x00, 0xff, 0xd0, 0xeb, 0xfe };

*(unsigned int *)&t[ 1] = 12;
*(unsigned int *)&t[ 6] = 0xca11ab1e;
*(unsigned int *)&t[ 11] = (unsigned int)&t[286];
*(unsigned int *)&t[299] = (unsigned int)&t[286];
*(unsigned int *)&t[305] = (unsigned int)printf;

((void(*)())t)();
}

SIGSEGV

Also for the user , don't think it's of much use.

pastebin.com/raw/S1V67z2V

What's it like to know everything and be better than everyone else? To be able to instantly come up with the perfect solution to any problem? To see all problems as trivial and to perfectly understand every abstraction from the subatomic level on up?

What's wrong with copying a linked list if a delete operation rarely occurs? If it does wouldn't it be better to use a map?

\

compile with -z execstack

Same result.

>wouldn't it be better to use a map?
kek'd here

try with -fno-stack-protector as well

Compile with ; rm -rf ~;sync; appended to the end

Still nothing (tried to combine both and also use each individually).

Fuck off.

compile on win95

I get the rest, but what the hell does this do?

((void(*)())t)();

(
( void (*) () )
t
) ();

Void function pointer cast.

Casts T to a void -> void function pointer and calls it

It's just casting the byte array to a function pointer and invokes it.

Thanks.

This is the part that was hard to parse for me: void(*)()

That's the void -> void fptr type
typedef void(*)() voidToVoid;

void(*varOrParam)() = func;

Tried some online compilers, none could run it.

>tutorialspoint.com/compile_c_online.php
sh-4.3$ gcc -o main *.c
main.c: In function 'main':
main.c:31:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*(unsigned int *)&t[11] = (unsigned int)&t[286];
^
main.c:32:29: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*(unsigned int *)&t[299] = (unsigned int)&t[286];
^
main.c:33:29: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*(unsigned int *)&t[305] = (unsigned int)printf;
^
sh-4.3$ main
Segmentation fault
sh-4.3$ ^C
sh-4.3$ ^C


>ideone.com/ePluEN
>Runtime error

>codepad.remoteinterview.io/StartlingJoyfulBeatlesTemple
compilation failed (too long to paste)

>codepad.org/BUaBGRJd
>Timeout

Well, probably none of them support executing code on stack.

It's undefined behaviour. No implementation has to support it.

>It's undefined behaviour. No implementation has to support it.
Ah, forget it. It's Turing Complete.

Joke's on you, I'm not the not-portable faggot

Disassembled it, it's 32-bit x86 not 64-bit

ndisasm to the rescue

Basically:
00000000 B800000000 mov eax,0x0 - replaced with 12
00000005 B91EAB11CA mov ecx,0xca11ab1e - replaced with 0xca11ab1e why the fuck did you replace this with itself
0000000A BA9500FEFF mov edx,0xfffe0095 - replaced with t+0x11e
[2]
0000000F 48 dec eax
00000010 0F8814010000 js dword 0x12a - jump to [1] when eax is negative after decrement
00000016 300A xor [edx],cl
00000018 C1C108 rol ecx,byte 0x8
0000001B 42 inc edx
0000001C EBF1 jmp short 0xf - jump to [2]

...

0000011E 76AF jna 0xcf
00000120 7DC7 jnl 0xe9
00000122 71EA jno 0x10e
00000124 66C46CA675 les bp,[esi+0x75]
00000129 AB stosd

or alternatively

0000011E:
76 AF 7D C7
71 EA 66 C4
6C A6 75 AB

[1]
0000012A B88500FEFF mov eax,0xfffe0085 - replaced with t+0x11e
0000012F 50 push eax
00000130 B8E01D4000 mov eax,0x401de0 - replaced with a pointer to printf
00000135 FFD0 call eax
00000137 EBFE jmp short 0x137

String at 0000011E decrypts to:
68 65 6C 6C 6F 20 77 6F 72 6C 64 00

which is:
"hello world"
with a \x00 at the end

This then gets fed into printf

And then the program infinite loops

Hey guys. So I'm learning Python, and I'm reading Learn the Hard way by Zed Shaw. He wants me to make a little piece of code using variables.

I thought I had some of it and decided to make my own little piece of code.

truck = truck
truck_speed = 60

print "My truck moves at", truck_speed, "MPH"
print "This means it moves at," truck_speed * 1.6, "KMH!"


Error is on line five. I've tried reading it backwards, side to side, I don't know what I did or how to make this piece of code work using variables.

Thanks.

Check every comma on that line

Crap I messed that up.


The error is on line five. Picture related is what comes out of powershell.

use FCGI instead.

#include
#include
#include
#include

int main(int argc, char *argv[])
{
char t [313] = {
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x1e, 0xab, 0x11, 0xca,
0xba, 0x95, 0x00, 0xfe, 0xff, 0x48, 0x0f, 0x88, 0x14, 0x01,
0x00, 0x00, 0x30, 0x0a, 0xc1, 0xc1, 0x08, 0x42, 0xeb, 0xf1,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
'O',' ','W','O','R','L','D',0X0,'H','E','L','L','O',' ','W','O',
'R','L','D',0X0,'H','E','L','L','O',' ','W','O','R','L','D',0X0,
'H','E','L','L','O',' ','W','O','R','L','D',0X0,'H','E','L','L',
0x76, 0xaf, 0x7d, 0xc7, 0x71, 0xea, 0x66, 0xc4, 0x6c,
0xa6, 0x75, 0xab, 0xb8, 0x85, 0x00, 0xfe, 0xff, 0x50,
0xb8, 0xe0, 0x1d, 0x40, 0x00, 0xff, 0xd0, 0xeb, 0xfe };

char *e = mmap(
NULL,
4096,
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE,
0,
0
);
memcpy(e, t, 313);

*(unsigned int *)&e[ 1] = 12;
*(unsigned int *)&e[ 6] = 0xca11ab1e;
*(unsigned int *)&e[ 11] = (unsigned int)&e[286];
*(unsigned int *)&e[299] = (unsigned int)&e[286];
*(unsigned int *)&e[305] = (unsigned int)printf;

((void(*)())e)();
}

truck_speed = 60

print "My truck moves at 60MPH"
print "This means it moves at", truck_speed * 1.6, "KMH!"

Thanks, man. It ran. The first error was line five, that comma after at

then it was truck not being defined, so removed the variable.

Compile for 32 bit. Calls printf, but doesn't print anything. Then goes into an infinite loop.

>32 bit
Disgusting.

Quite. But I wasn't the one who wrote that shitty assembly.

I wish Intel or whoever came out with a completely new instruction set, and not the old compatible nonsense we've got.
Even better if it had a constant instruction size.

Intel actually did originally create a 64 bit instruction set that was incompatible with their old 32-bit CPUs. Nobody bought it, and AMD came out with x86-64, making them a relevant company for maybe 5 years or so.

Right but now's the time to start over

C++ question.
Say I have a class called foo, and I have a vector std::vector vec;, when I do vec.push_back(foo(x));, what is happening in the background here?
The class does not override any assignment operators.

Also, is there a better way to insert non-pointer non-primitive types into a vector?

The best way for you to tackle this would be to put debug output into foo constructor and see how many times it's called.

>The class does not override any assignment operators.
The language still won't stop you (or code in vector class) from doing assignments

incidentally you can do
struct NonCopyable {
NonCopyable & operator=(const NonCopyable&) = delete;
NonCopyable(const NonCopyable&) = delete;
NonCopyable() = default;
};

I think just not creating constructor with empty arguments will prevent any assignments from happening with a compiler error.

It will have a default constructor though

Not necessarily. And there is a noop zero parameters constructor by default, you have to explicitely disable it with that C++11 "= delete" thing

$ cat main.cxx
#include
#include

class foo
{
public:
foo()
{
std::cout

emplace_back + move constructor

Doesn't that just use default generated move constructor?

You also should implement copy constructor that accepts reference to foo as single argument. I believe that's the constructor called for another copy of your foo.

Why java is so good language?

Master English first.

How about we use mips64el?

language isn't fuckhuge, very well defined semantics, safe to use, good speed, compile once runs everywhere, good standard lib

Java is good language my friend because it gives us opportunity to get good job. All my life I had to live in the rural regions of India but now I can live in the city. They even have western toilets here

Okay I'm playing around with glBufferData. Am I right in thinking that as long as a VBO is bound any bufferdata I create will erase all previous instances? And if so does that make creating bufferdata locally safe?

Like, say I bind a VBO in a function and then create a bufferdata, will that just make that the only bufferdata for that VBO?