/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

strawpoll.me/11767105
insecure.org/stf/smashstack.html
intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf
collinoswalt.com/11
collinoswalt.com/feed/
linkToYourSiteAnd/article
tracker.archlinux.org:6969/announce'
myredditnudes.com/
twitter.com/SFWRedditVideos

Please don't use an anime picture next time. This is a tech related discussion board

on an anime-based image board

Please don't post a non programming related post here. This is a programming discussion thread.

Okay is the guy that knows torch here still, am I retarded or why I can't just assign values to random table indices in lua?? If i do table[i] = 1 then it complains about the index being nil

It's not anime and she's holding K&R, which is tech-related... I don't get why people complain on Sup Forums about anime. Sup Forums has always had its roots in anime.

>he uses int
Why are you using importable code user?

This is a Isle of Man basketwork board, faggot.

'cause I want my code to be imported?

post the last code you wrote

post a screen shot if you want

Rajesh?

> then it complains about the index being nil

it means that `i` isn't assigned. Make sure i has a value other than nil.

>tfw to smart to learn haskell

table[{1}] = 1

It's dumb, but there aren't true arrays in lua, only dicts, so you must use its syntax.

Anybody in here able to figure out this compile error. game is my struct games is my array of structs, time_of_day is a string in the struct.

its a pointer to a struct, use ->
games->time_of_day[2]

christ dude

Ah, never mind, I am retarded haha, I went from a for i blah,blah loop to repeat until

>indexing a table with another table

I'm pretty sure that's not what he was asking...

haha

tfw i never have to ask these questions because intellisense makes it clear for me.

tfw I never have to ask these questions because I'm not dumb

Use a fucking struct pointer if you have that many state variables to keep track of.

>tfw i never have to ask these questions because i write error free code

tfw i never have to ask these questions because i don't program

tfw i never have to ask these questions because i code in PHP

>tfw i never have to ask these questions because i code on PCP

I don' wanna

>given a dll with no documentation
>has a parameter just called block_size.
>different values for block_size make it run at consistently different speeds for the same return value
is there a way to find the best block size without brute forcing the value for block_size? the method is taking roughly 300,000ms to run...

Is 1.5 seconds for generating 1 mil random 6-digit unique(in a set) ticket strings good performance for java or should that be able to be done in nanoseconds?

I get ~ 3 - 4 seconds for 2 mil

I'm doing multithreading in Java.

I start and join threads like this:
for(int i = 1; i

I'm supposed to do stack smashing for my homework in C, but this example code I found doesn't work.
This is supposed to skip the instruction x=1 but it won't.

File Edit Options Buffers Tools C Help
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
int *ret;

ret = buffer1 + 12;
(*ret) += 8;
}

void main() {
int x;

x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}


and the assembly instructions
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000400561 : push %rbp
0x0000000000400562 : mov %rsp,%rbp
0x0000000000400565 : sub $0x10,%rsp
0x0000000000400569 : movl $0x0,-0x4(%rbp)
0x0000000000400570 : mov $0x3,%edx
0x0000000000400575 : mov $0x2,%esi
0x000000000040057a : mov $0x1,%edi
0x000000000040057f : callq 0x400536
0x0000000000400584 : movl $0x1,-0x4(%rbp)
0x000000000040058b : mov -0x4(%rbp),%eax
0x000000000040058e : mov %eax,%esi
0x0000000000400590 : mov $0x400640,%edi
0x0000000000400595 : mov $0x0,%eax
0x000000000040059a : callq 0x400410
0x000000000040059f : nop
0x00000000004005a0 : leaveq
0x00000000004005a1 : retq
End of assembler dump.
(gdb)

>
Run the threads in different CPUs and it'll print more parallel.

C++, long double
(1.18973e+4932 + 1.18973e+4932) / 2 gives inf instead of
1.18973e+4932
what do?

I'm a dunce so I don't know if you're joking. If not how?

Half joke. It's what you want, but I don't know if Java can do that.

strawpoll.me/11767105
Alright, last repost, it seems Sup Forums is pretty conclusively in favor of C as the language of choice for the up and coming debutante. Thank you very much for participating in this incredibly important survey

Is function() using the right return type?

Yes. This looks approximately like what its supposed to.

How do I print out a description of a class or object in Java?
Can't seem to find the answer anywhere.

So wait, what's considered a good error for StochasticGradient?

lol nvm fixed it

How do you expect main() to work with whatever function produces if the retrun type of function is void?

Because im trying to manipulate the stack frame to overwrite the return address pasr x=1 and dont care about returning data.

getClass().getName()

?

Like, I just want to know where the number comes from and what it's supposed to represent

I waited like a couple of minutes and now it's printing randomly. I don't understand threads at all. I'm just going to assume it's working properly.

So the video bios is below the motherboard bios in memory right? if I boot my computer with only integrated graphics, the video bios will be mapped to the integrated graphics hardware. But if I put a dedicated graphics card in there and boot the video bios will be mapped to that dedicated card.
How does that work? aren't those mappings physically built into the motherboard? I know that PCI devices are assignment dynamically so I guess my real question is, how does the motherboard dynamically change mappings like that?
Does the mobo have an internal read-write table of mappings that it uses to lookup devices from addresses? if so, I'd like to know what techniques and algorithms a motherboard would use to achieve the lowest overhead for looking up a mapping so I can implement it in my virtual machine.

Don't think of threads as running in parallel, but rather running independent of each other. The order and time they run is up to the operating system to do with as it wishes. You can control them better with semaphores and telling the scheduler a threads priority and it's dispatching domain.

>How does that work? aren't those mappings physically built into the motherboard? I know that PCI devices are assignment dynamically so I guess my real question is, how does the motherboard dynamically change mappings like that?
>Does the mobo have an internal read-write table of mappings that it uses to lookup devices from addresses?
The system address map is setup by the chipset/memory controller which can be controlled by special registers.

I really don't get what it's supposed to do. You're trying to access the 12th element of a 5byte charater array?

I get the error "non-static method getClass() cannot be referenced from a static concept".

What do?
Sorry 'bout this.

Do you happen to know any resources I can use to learn more about this system address map?

Damn. I just realized how slow Python is.

I just tried the same thing and got 2.7 seconds for 100 thousand.

You'll never beat my one liner, though :)))))
n=["".join(random.choice(string.digits) for _ in range(6)) for __ in range(100000)]

try splitting the source into chunks, so each thread can work on one chunk at a time and then print in order.

Just use YourClassNameHere.class instead of getClass()

where are the imported modules random and string?

that's not one line

insecure.org/stf/smashstack.html

I am attempting to use a bug in C to overwrite the memory address which stores where the CPU should jump to in the code after it finishes running function.

You can take a look at the spec for some particular memory controller like:
intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf

In particular Chapter 3 and 4 which describes the register configuration and how the address map is setup.

n=["".join(__import__('random').choice(__import__('string').digits) for _ in range(6)) for __ in range(100000)]

I could have just made it easier by making my own choice function in that same line. But fuck you

I need to return these values / send these values into another class.

Is there an easy way to do this without doing it individually?

move that stuff out of the code and into data files instead
it'll save you a lot of pain later on

Trying to graph in MATLAB.

Let's say I need to graph several vectors that represent a trajectory. These trajectories are all the same, except the only difference is some constants, which are changed through a "for" loop. At the end of the loop, I graph the trajectories on the same graph.

My question is: How would I write it such that I can get a legend for each of the trajectory? Like "Trajectory 1", "Trajectory 2", "Trajectory 3" instead of "data1", "data2", and "data3"?

Here's my code so far:
%CONSTANTS
C_ARRAY = [3000, 2775, 2545];
N_ARRAY = [3.0, 2.8, 2.6];

g = 0:.05:1 %"g is a parmeter that ranges between 0 and 1"

%TRAJECTORIES

for index = 1:3

n = N_ARRAY(index);
C = C_ARRAY(index);

t = (.1*C) * ( (g.^(n-1) / n-1) + (g.^(n+1) / n+1));
x = (.2*C^2) * ( ((g.^(2*n-1)) / (2*n-1) ) + (g.^(2*n+1) / (2*n+1)) );
y = (.1*C^2) * ( ((g.^(2*n-2)) / (2*n-2) ) - (g.^(2*n+2) / (2*n+2) ) );

hold on;
plot(x, y);
ylabel('Vertical Displacement');
xlabel('Horizontal Displacement');
legend('' + index);
end

one less char than you
n=["".join(__import__('random').choice(__import__('string').digits) for _ in range(6)) for a in range(100000)]

Not a good habit though.

There could be an a defined out of scope that you're overwriting.

one
less
char
than
you

Huh, I thought I was the only lady of good upbringing on /dpt/

I had posted:

collinoswalt.com/11

Another user asked me to create an RSS feed

I just finished it

Here you go, anons:

collinoswalt.com/feed/

That's 32 bit code, you appear to be compiling for 64 bit which uses a different calling convention and typically different frame setup.
It also depends on what kind of compiler flags you use.
Don't expect examples with hardcoded numbers like that to just work on your system, you have to check the disassembly, calculate the correct offsets and use those.
You want buffer1 + X where X = (buffer1 - rsp_on_entry).
Then ret's gonna have to be a long (64 bits), and the amount you need to skip depends on how big the x = 1 compiled to (probably bigger than 8 bytes on 64 bit -O0 builds).

how does one make a rss feed?

Shouldn't it be something like

legend(strcat('Trajectory ', num2str(index));

How do I figure out (buffer1 - rsp_on_entry)?

I made it with a php file

basic rss takes the xml form:



My Rss channel title
Description of rss feed
Programming


Item 1
linkToYourSiteAnd/article
Description 1
Mon, Sep 23 2016 14:37:01 EST

And just use php to generate that. Make sure to send the Content-Type: text/xml; charset=utf-8 header with it so the browser knows it's XML

cheers!

Does this perversion work?
#include
void stack_smash(void)
{
enum { ASSIGN_INSTR = 7 };
void *r;
r = &r + 2 ;
*(char **)r += ASSIGN_INSTR;
}

int main(void)
{
int x;
x = 1;
printf("%d\n", x);
stack_smash();
x = 2;
printf("%d\n", x);
}

You really should use a newer version of GCC.
It gives much more helpful error messages, especially for beginners.

nice man

Replacing an old bundy clock lunch bell system at a warehouse with raspberry pi's, speaker systems, html5 Audio() and configurable times from a simple admin interface.

no
use clang, gcc is utter shit, they only reason they added those in gcc is because clang did it first and they suddenly had to compete.

No it couldn't. a is local to the list comprehension

>they added those in gcc is because clang did it first and they suddenly had to compete
So? How is competition not good?
Clang used to have way better error messages, so GCC stepped up their game.
Now that is no longer an advantage that Clang has over GCC.

You're going to have to give a real reason as to why GCC is "utter shit".

my gcc gives a different error lel

void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
long *ret;

ret = (long *)(buffer1 + 0x18);
(*ret) += 7;
}

void main() {
int x;

x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}

I got this to work with:
gcc -fno-stack-protector

(my gcc had -fstack-protector on by default which adds code to prevent this kind of exploit)

Mind helping a C++ beginner?

I need to make an IF statement that checks 3600 equations (X[i][j - Y[i][j] < 0,001) are simultaneously true.

How the hell do i write it with FOR loops? Im mostly in doubt if i need to use a && condition in the middle of the for, or if the for checks for everything.

>4.7.3
>Copyright (C) 2012
Jesus christ. They're made so many changes since then.
That's why I can't stand using distros on my main computer that has ancient packages.

>tfw to smart to understand racket

If they all need to be true just check for the first false condition and break there, otherwise if the loop finishes you can safely know all conditions held.

How can I become proficient in Ruby on Rails in a week? I have exp. with a few other languages/frameworks already so this shouldn't be a huge issue but what are the best books/guides/tutorials for Ruby?

Beat my autism, Sup Forums.

I made a program that tells me which album to listen to by spacing them out perfectly so as to create the maximum gap between albums from the same artist.

Each artist has its own interval. The hard part is figuring out how to populate a list that takes into account each artist's interval and the fact that spots will be taken by other albums.

Here is a snippet of a final list (Xiu Xiu and Animal Collective are repeated; Xiu Xiu has more albums and, so, appears closer together than AC):

Animal Collective/Strawberry Jam
American Football/American Football
Neutral Milk Hotel/On Avery Island
Xiu Xiu/Always
The Tuss/Rushup Edge
Sufjan Stevens/Carrie & Lowell
Aphex Twin/Drukqs
Meshuggah/Catch Thirtythree
Death Grips/The Powers That B/Jenny Death
The Caretaker/An Empty Bliss Beyond this World
Gorillaz/Demon Days
Xiu Xiu/Covers
Animal Collective/Prospect Hummer

Loop through the equations and keep a flag. If any of them aren't true all of them aren't simultaneously true so you can break.
>Im mostly in doubt if i need to use a && condition in the middle of the for, or if the for checks for everything.
Lost me. Write out what you're thinking.

just be yourself!

you just need to demo how to smash a stack?
also please use "set disassembly-flavor intel" in gdb, at&t style is fucking retarded

If you want to become proficient at something you don't read a book, you do a project, make something, you dumb MIT nigger.

Build something and Google what you don't know

I don't understand.
Explain yourself.

url = 'tracker.archlinux.org:6969/announce'
values = {'hash_id': urlhash, 'peer_id': 'ABCDEFGHIJKLMNOPQRST',
'port': 6881, 'downloaded': 0,
'event': 'stopped'}
print(type(urlhash))
sendto = requests.get(url, params=values, timeout=None)


i can't get a response back from trackers. i can't figure out what i'm doing wrong?

You want to listen to every album that you have, right? Well listening to every album by an artist and then moving to the next artist would get boring. So this spaces them out perfectly so that you never listen to the same artist too often (close together).

Before it segfaults, which it does, it prints a 1 and a 2. So, no...

I can post a whole generated list if you want.

do it.