/dpt/ - Daily Programming Thread

Previous Thread: Next Thread: What are you working on, Sup Forums?

Other urls found in this thread:

github.com/kostya/benchmarks
en.wikipedia.org/wiki/Generics_in_Java#Generic_class_definitions
github.com/golang/go/issues/12488
github.com/golang/proposal/blob/master/design/13073-code-of-conduct.md
stackoverflow.com/questions/16137108/python-error-importing-curses-not-sure-why
gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
twitter.com/NSFWRedditGif

What is Sup Forums thoughts about Mechatronics Engineering

>write a program that when run outputs its source code

here is my solution

post yours!
#include

int main()
{
FILE *fptr = fopen(__FILE__, "r");

char c = fgetc(fptr);
while (c != EOF) {
printf ("%c", c);
c = fgetc(fptr);
}
puts("");

fclose(fptr);
return 0;
}

I'm working on a tool that will create, edit, and audit wargame armies.

Sup Forums is my anime club

Reccomend me some good series

Opening the .c file for reading is cheating and not a real quine.

Kill yourself

himegoto
kuragehime
shounen maid
henneko
gochiusa
yuyushiki

Is this the future of programming?

Syntax of Ruby and performance of C

github.com/kostya/benchmarks

I'm not gay tho

>GC
>performance of C
nope.

Sekaiichi Hatsukoi
Kono Danshi, Ningyo Hiroimashita
Fuyu no Semi
Uraboku
Ai no Kusabi
Yami no Matsuei
Honoo no Mirage
Monochrome Factor
Kirepapa
Haru wo Daite Ita
Sukisho
Gakuen Heaven
Okane ga Nai

I've written some small applications in Winforms C# that uses XML to store configuration settings. I know it's wrong but I also use the XML as a small database at times.
What's the best way to replace the XML without relying on something overkill like SQL DB?

...

You could write it yourself

shit list

sure, bisexual :^)

ini-style config file, write the parser yourself.

i just googled gay anime don't tell me you actually watch that shit like an ANIME FAN ON PROM NIGHT

This database will never exceed 10k 'primary keys', but the XML is getting all fuck'd up with some special characters for some reason.
Anyway, I wanted something pre-made at least, but I will look into writing it myself, thanks.

>Syntax of Ruby
That is not a good thing.

Repostan

look up soft body physics if you want to simulate tits

what is that bar code?

Posted a question in /sqt/, but I'll link it here as well since it's programming-related:

something like
int e[3][] = { { 1, 1, 0}, { -1, 1, 0}, { 1, -1, 0}, { -1, -1, 0}, { 1, 0, 1}, { -1, 0, 1}, { 1, 0, -1}, { -1, 0, -1}, { 0, 1, 1}, { 0, -1, 1}, { 0, 1, -1}, { 0, -1, -1}};

just a stupid array declaration, google that shit

Who is this cum chum?
Also thinking of reverse engineering ARM firmware and embedded OS's in the SoC's

I'm stuck at something.

here's the idea in C++
template< class T>
void function(params)
{
T.getSomething();
T.doSomethingElse();
}


the class is supposed to have 2 static functions, getSomething(), doSomethingElse()
in C++ i'd call it with function(params)
haven't tried if it works.

how do i make somehting like that in java.

Alright, I was thinking I'd have to do like a pointer or some shit. Pretty stupid looking back on it.

inheritance

but i want to keep that particular function seperate from the data structure.
Is there no way to do this without inheritance?

I need to get the stat values from player and pass them to Input_check but I have no clue how to do this in Python can anyone help?

class Input_check(object):
stats

def input_checker(self, x):
if x == "s" or x == "S":
print("Health:%d\nAttack:%d\nDeffense:%d\n" % self.stats)

class Player(object):
player_name = "Edwin"
player_attack = 10
player_deffense = 10
player_health = 10

pretty sure you can't in Java

well thanks for answering me. i guess i'll pick up some design pattern for this

well, this isnt about programming but to start messing with my programming projects, i need to find some good free proxys( dont say : pay some proxy or vpn with bitcoins or someshit like that cuz its the first thing that comes to every1s mind) ,so if you have some with the format: protocol ip port, it would be really nice ;)

public abstract class Faggot {
public Faggot() { }

private static void getSomething() { }

private static void doSomethingElse() { }
}


If getSomething or doSomethingElse are going to return something, replace the "void"s with the return type (ex: "int")

what is the point of putting a retarded amount of parentheses in macros?

linux kernel's version
#define list_entry(ptr, type, memb) \
(type *) ((char *) (ptr) - (unsigned long) &((type *) 0)->memb)


my version
#define list_entry(ptr, type, memb) \
((type *)((char*)(ptr)-(unsigned long)(&((type *)0)->memb)))

am I missing something?
was the linux dev just ignorant of operator precedence rules?

wait shit,

my version is the top one

Under Player:
ic = Input_check()
ic.stats = (player_name, player_attack, player_defense, player_health)
ic.input_checker("s")


That is the easiest way to do it based on the code you have now, but it isn't very proper.

Am I missing something? Why isn't link related sufficient? en.wikipedia.org/wiki/Generics_in_Java#Generic_class_definitions

Java can't assume the type being parametrised supports those operations

Why are you writing like a retard?

>cuz
You ain't my cuz, nigga.

"waaah, setting the GOPATH env var is hard!"

github.com/golang/go/issues/12488

The person asking about this is probably new to programming. The design and question should give that away.

Mvc or Mvvm would help here.. But it's kinda hard to find a beginner friendly resource to explain for this person.

A simple image viewer because I was sick of bloated shit.

It just
1) show images in an absolutely clean GUI and is able to (decently) scale them
2) show a folder view with decent looking thumbnails of the current directory

I wasn't really in the mood of doing it so the result is a shitty ~160 lines python script where the 90% of the lines are actually a call for some PyQt function/class.. but well, for sure it's pretty light and does the work.

because pre-processor macros perform text-replacement before the code is compiled

A macro is just a straight text substitution.
example
Consider the macro replacement using this macro:
#define SQR(x) (x*x)

Using b+5 as the argument, SQR(b+5) will become:
(b+5*b+5), or (3+5*3+5).

Now remember your operator precedence rules: * before +.
So this is evaluated as: (3+15+5), or 23.

The second version of the macro:
#define SQR(x) ((x) * (x))


Is correct, because you're using the parens to sheild your macro arguments from the effects of operator precedence.

The thing to remember here is that you should get in the habit of always shielding any arguments in your macros, using parens

top kek

github.com/golang/proposal/blob/master/design/13073-code-of-conduct.md

I knew about the argument shielding, but I now realize that if I am to use a macro like a function that returns something, I need to parenthesize the whole thing so I can use it in an expression.

>falling for the cpp meme
Why does everyone code in C++ in these shit threads??

templates > macro abuse

Went through the python course in codeacademy, now I want to learn how to use curses to create a GUI in CLI.

This is happening. Help?

stackoverflow.com/questions/16137108/python-error-importing-curses-not-sure-why

rename your file

thanks dude

It worked, thanks.

thanks, that did it

wow thanks

There's a difference?

we did réddit!

print open(__file__, 'r').read()

((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))


This counts because using google is what programmers do.

>This counts because using google is what programmers do.
?

#!/bin/cat

rate my quine:

(λx.xx)(λx.xx)

>when a process eats all the memory linux will evoke a "reaper" to kill him and sacrifice his child to prevent freezing

Why so violent?

why is this allowed?
why aren't multi-statement expressions described in K&R?
printf("max: %d\n", ({int x = 3; int y = 4; x > y ? x : y;}));

Programmers like to have fun.

It's a GNU addon.

non-standard extension i believe

oh

It should be in the language 2bh
it's like a lambda expression

If you want usable lambdas, use C++.

no, C++ is gross

x: for (goto x; goto x; goto x);

Never will be, it has some problems with C++.
gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

t. pleb

a.c: In function 'main':
a.c:2:10: error: expected expression before 'goto'
x: for (goto x; goto x; goto x);
^~~~
a.c:2:18: error: expected expression before 'goto'
x: for (goto x; goto x; goto x);
^~~~
a.c:2:26: error: expected expression before 'goto'
x: for (goto x; goto x; goto x);

I'm trying to write a function that does hexadecimal addition, but when I run the program, the for loop doesn't seem to be running... In other words: Where did I fuck up?

void addTwoVectors(std::vector vector1, std::vector vector2, std::vector result)
{

int max = vector1.size();
if(vector2.size() > vector1.size())
{
max = vector2.size();
vector1.push_back(0); //Makes both vectors the same size;
}
result.resize(max+1, 0); // Makes sure adition goes correctly by not caring about what result was previously

for(int i = 0; i < max; i++)
{
short a = vector1[i];
short b = vector2[i];

short temp = a+b;

result[i] += temp;

if(result[i] > 0xFF)
{ //If the result of the addition is > 255, then shift bits and
//Add num-255 to the ith term and num/255 to the (i+1)th term
result[i] = result[i] & 0xFF;
result[i+1]= ((result[i] >> 8) & 0xFF);
}
std::cout

and this is why C++ is gross

C++ should adapt to C and not the other way around

I just googled "rosetta code quine"

Your compiler is broken

Use a debugger.

about to add the in-app store for users to buy rare pepes

Wow, clang is even worse.
a.c:2:10: error: expected expression
x: for (goto x; goto x; goto x);
^
a.c:2:18: error: expected expression
x: for (goto x; goto x; goto x);
^
a.c:2:26: error: expected expression
x: for (goto x; goto x; goto x);
^
a.c:2:26: error: expected ')'
a.c:2:9: note: to match this '('
x: for (goto x; goto x; goto x);
^
4 errors generated.

I've tried using breakpoints in XCode, but it doesn't really help me get any more information... All I know from the breakpoints is that XCode realizes that there's a for-loop there, and just doesn't run it...

Try reading the variables when in a breakpoint. Or why use breakpoints at all, just step into the function.

How do I interact with a database in C?
Do I have to manually compose SQL query strings and then pass them to some black box function, or is it much more intuitive than that?

#include

fucking brutal, based linus

Best resource for learning ARM?

Alright... Found the error, apparently I wasn't passing vectors by reference, which is why the for-loop wasn't running... Thank you, though! Looking at the variables was surprisingly helpful!

Where did you get that byte type?

Help me anons, I'm no c programmer, I'm trying to understand this code to port it to another lang. What is going in this line?
count = *((unsigned short *) (in+inptr));
in is a char * and inptr is an int
Go to the character at in[inptr] dereference it and cast as unsigned short? Looks just weird and the castings confuse me

Depends on the library you use.

pointers were a mistake

Yeah, you pretty much nailed it

some expression (in+inptr) getting casted to (unsigned short *) and assigning what that points to, to count.

>inptr is an int
but it says "ptr"

this is how computers actually work you better learn pointer arithmetic and fast, if you don't know already then I can't show you, C is the one true language all others are just immitators, OOP and webdev give me a headache how can anyone understand that garbage pointer arithmetic is easy and simple to understand go take an abstract algebra course fucking kids these days I miss my 486 when programming meant something C is so easy make programming great again

What's a good book for learning abstract algebra?