[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 397
Thread images: 18

File: K&R hime linked list copy.jpg (551KB, 1280x1440px) Image search: [Google]
K&R hime linked list copy.jpg
551KB, 1280x1440px
old thread: >>55110925

What are you working on, /g/?
>>
1th for Lua
>>
>>55118523
second for c
#include <math.h>
#include <stdlib.h>
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 <= sqrt(n); i += 2) {
if (!(n % i)) return 0;
}
return 1;
}
>>
Anyone here program from home for a living, either self-employed/contracting or via an employer ?
If so, how'd you get into it?
>>
>>55118544
setmetatable(_ENV,{__index=function(t,k) return k end})


for great justice
>>
File: i got myself an anime!.jpg (204KB, 440x574px) Image search: [Google]
i got myself an anime!.jpg
204KB, 440x574px
Doing CGI webdev in C.

I don't want to learn a dumb scripting language.
>>
>>55118568
I run my own programming/webhosting business
I have no clients still
>>
>>55118568
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
>>
>>55118581
All you have to do is not go bankrupt in the first year and you're more successful than 95% of businesses
ezpz
>>
>>55118579
I would tell you to kill yourself, but I thing you will regardless of what I say with that language choice.
>>
File: 1465700695183.jpg (80KB, 482x424px) Image search: [Google]
1465700695183.jpg
80KB, 482x424px
>EXACTLY on time
>anime image
>trap

This is the perfect thread. Thank you.


>>55118579
Learn C++
>>
>>55118523

What's wrong with the method in the OP?
>>
>>55118636
Linked lists are slow, make a dynamically-sized array using realloc() + memmove()
>>
>>55118636
Defeats the purpose of using a linked list
>>
>>55118630
>pedo weaboo fags back
Kys
>>
>>55118636
Well, it would work if that's what you're asking
>>
>>55118568
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.
>>
>>55118579
>Doing CGI webdev in C.

thang for de job segurity 8-DDD

t. overpaid security man
>>
>>55118636
neck yourself
>>
>>55118654
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
>>
>>55118646

yes but computers these days are fast, so whats wrong with losing a couple of cycles when it's easier and works?
>>
File: code bloat.jpg (99KB, 630x655px) Image search: [Google]
code bloat.jpg
99KB, 630x655px
>>55118694
>whats wrong with losing a couple of cycles when it's easier and works
>>
>>55118694
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
>>
>>55118636
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.
>>
>>55118553

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

>>55118579

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

>>55118636

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.
>>
>>55118683
60k a year. More than I've ever made before.
>>
>>55118579
Keep it up, sprintf() is the one true templating engine

Everyone else is doing it wrong
>>
>>55118736
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
>>
>>55118739
nice
>>
>>55118553
Not portable.
>>
>>55118847
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?
>>
File: spongegar.jpg (18KB, 375x375px) Image search: [Google]
spongegar.jpg
18KB, 375x375px
>>55118847
>hNot portable
>>
File: H E L L O W O R L D.png (22KB, 564x482px) Image search: [Google]
H E L L O W O R L D.png
22KB, 564x482px
Anyone know what this does?
>>
>>55119101
Deletes your CPU
>>
>>55119101

On platforms that don't suck, it causes an access violation for trying to execute code on the stack.
>>
>>55119101
Post the code.
>>
>>55119127
I only have the screenshot
>>
>>55118965

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
>>
>>55119125
Good spotting

>>55119132
Write an OCR program

It's fixed width, it shouldn't be hard
>>
>>55119144
Why don't you just write a program to transcribe it?
>>
>>55119134
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.
>>
>>55119101
>((void(*)())t)()
I'm not going to test it.
>>
>>55119158
Output the result to a binary file then disassemble it

Although we're waiting for the poster to transcribe the whole lot
>>
>>55119134
you're truly an idiot. why do you feel like you have a saying about things you don't understand? lurk more faggot
>>
>>55119166

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
>>
>>55119185
you're maybe better fitted for /v/
>>
>>55119234
you're maybe better fitted for reddit

prove how it's not portable
>>
>>55119244
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)();
}
>>
>>55119274
SIGSEGV
>>
>>55119301
Also for the anon >>55119165, don't think it's of much use.

http://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?

\
>>
>>55119301
compile with -z execstack
>>
>>55119336
Same result.
>>
>>55119328
>wouldn't it be better to use a map?
kek'd here
>>
>>55119347
try with -fno-stack-protector as well
>>
>>55119347
Compile with
; rm -rf ~;sync;
appended to the end
>>
>>55119374
Still nothing (tried to combine both and also use each individually).

>>55119387
Fuck off.
>>
>>55119401
compile on win95
>>
I get the rest, but what the hell does this do?

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

(
( void (*) () )
t
) ();
>>
>>55119488
Void function pointer cast.
>>
>>55119488
Casts T to a void -> void function pointer and calls it
>>
>>55119488
It's just casting the byte array to a function pointer and invokes it.
>>
>>55119508
>>55119514
>>55119515
Thanks.

This is the part that was hard to parse for me: void(*)()
>>
>>55119541
That's the void -> void fptr type
typedef void(*)() voidToVoid;

void(*varOrParam)() = func;
>>
Tried some online compilers, none could run it.

>http://www.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


>https://ideone.com/ePluEN
>Runtime error

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

>http://codepad.org/BUaBGRJd
>Timeout
>>
>>55119604
Well, probably none of them support executing code on stack.
>>
>>55119604
It's undefined behaviour. No implementation has to support it.
>>
>>55119627
>It's undefined behaviour. No implementation has to support it.
Ah, forget it. It's Turing Complete.
>>
>>55119259
Joke's on you, I'm not the not-portable faggot
>>
>>55119274
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
>>
>>55118523
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.
>>
>>55120234
Check every comma on that line
>>
File: Untitled.jpg (154KB, 1181x515px) Image search: [Google]
Untitled.jpg
154KB, 1181x515px
>>55120234
Crap I messed that up.


The error is on line five. Picture related is what comes out of powershell.
>>
>>55118579
use FCGI instead.
>>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>

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)();
}
>>
File: thumbs up.jpg (2KB, 96x96px) Image search: [Google]
thumbs up.jpg
2KB, 96x96px
>>55120248
 
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.
>>
>>55120350

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

Quite. But I wasn't the one who wrote that shitty assembly.
>>
>>55120458
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.
>>
>>55120493

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.
>>
>>55120565
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<foo> 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?
>>
>>55120656
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
>>
>>55120714
incidentally you can do
struct NonCopyable {
NonCopyable & operator=(const NonCopyable&) = delete;
NonCopyable(const NonCopyable&) = delete;
NonCopyable() = default;
};
>>
>>55120728
I think just not creating constructor with empty arguments will prevent any assignments from happening with a compiler error.
>>
>>55120745
It will have a default constructor though
>>
>>55120745
Not necessarily. And there is a noop zero parameters constructor by default, you have to explicitely disable it with that C++11 "= delete" thing
>>
>>55120714
$ cat main.cxx 
#include <iostream>
#include <vector>

class foo
{
public:
foo()
{
std::cout << "constructor\n";
}

~foo()
{
std::cout << "destructor\n";
}
};

int main()
{
std::vector<foo> vec;
vec.push_back(foo());
return 0;
}
$ ./a.out
constructor
destructor
destructor
$

Okay, what appears to be happening is the object gets constructed in push_back, copied into the vector and the temporary is destructed.
Then when the vector gets destructed, the foo object also gets destructed.

This makes sense, the reason I ask this question is because I was having a double free problem involving this.
My class holds a pointer to a C struct, when the temp object gets copied into the vector, the pointer would too, so when the temp object gets destructed and the destructor frees the pointer to C struct, the pointer in the object in the vector becomes invalid, since they point to the same C struct.

So I guess I just have to implement r-value assignment and swap pointers.
>>
>>55120858
emplace_back + move constructor
>>
>>55120656
Doesn't that just use default generated move constructor?
>>
>>55120858
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?
>>
>>55120910
Master English first.
>>
>>55120592
How about we use mips64el?
>>
>>55120910
language isn't fuckhuge, very well defined semantics, safe to use, good speed, compile once runs everywhere, good standard lib
>>
>>55120910
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?
>>
>>55118523
does uncensored trap hentai even exists?
>>
NEET here, no degree. Which path should I take, family?

>web dev
>hardware (compTIA certs)
>programming

Which of these three am I most likely to find work doing despite my autistic work history up to this point? Read: none.
>>
>>55121050
coding
>>
>>55121050
webdev is the easiest to get job in but it's miserable
>>
Andrei is so based.

https://forum.dlang.org/post/[email protected]
>>
>>55121050
Webdev is most likely in greatest demand.
>>
>>55120990
From what I gather it'll unbind the memory from the CPU's perspective but still be usable

Although the recommendation these days is that if you're going to have an updateable buffer, you use glBufferData(target, size, NULL, GL_DYNAMIC_DRAW); or something like that, and then use glBufferSubData or suitable buffer mapping (glMapBuffer/glUnmapBuffer/whatever sync calls are needed) just so you aren't doing the GPU equivalent of spamming realloc()

glBufferSubData is probably easier than glMapBuffer just because you don't have to worry *too much* about synchronisation, however if you use the right facilities (later GL versions, possibly some extensions too) and you are OK at dealing with uncached memory OK then glMapBuffer *should* be faster

>>55121050
Take some web dev courses, just about every job out there is fucking web dev
>>
>>55119125
What OS and WM do you use?
>>
File: zaaeazea.jpg (194KB, 1366x768px) Image search: [Google]
zaaeazea.jpg
194KB, 1366x768px
Can anyone help me with pic related.
It shows me the data adresses instead of the actual value.

I have no idea where I fucked up.
Basically, I created Jmodel that recieved an ArrayList. And this list recieved its stuff from a SQL request.

Any idea where I could have fucked up ?
>>
>>55121118
Hard to tell with just the pic of the UI but I'd say you're appending the actual objects to the list rather than their string representation.
>>
>>55121129


public ArrayList<AfficheEmploye> selectEmploye() {
String req = "Select employe.Id, employe.Nom, employe.Prenom, employe.Adresse, ville.Commune, email.Adresse "
+ "FROM employe, email, ville WHERE employe.IdVille = ville.Id AND employe.Id = email.IdEmploye;";


ResultSet resu = ConnexionMYSQL.getInstance().selectQuery (req);
try
{
while (resu.next())
{
AfficheEmploye affEmp = new AfficheEmploye(resu.getInt(1),resu.getString(2),resu.getString(3),
resu.getString(4),resu.getString(5),resu.getString(6));
myList.add(affEmp);
}
}
catch (SQLException e)
{
System.out.println(e.toString());
System.exit(-1);
}
return myList;
}



I don't know if it's there that I fucked up.
>>
>>55121162
>
Connexion

why
>>
>>55121162
Question: why do you think that fields of AfficheEmploye object you're creating would be placed into different columns of the UI table?
>>
>>55121202
To be completly honest, I don't even know. It's how I've been taught to use this.
>>
>>55121213
I don't know either. I had to do it once and never stopped doing it after that.
>>
>>55120656
>what is happening in the background here?
the magic of C++, no need to worry about it
>>
>>55121386
>no need to worry about it
Yeah...
No need to worry about your program crashing.
>>
>>55121162
Anyone ?
>>
>>55118965
>undefined behavior is portable
ishyggy
>>
>>55121392
>your
nah, I don't use C++
>>
what should I use to get started with graphics?
I just want to do simple 2d stuff like basic games (snake, tetris) easily
I definitely do not want to use C/C++ for this.
I was thinking about something like love2d (lua) or html5 canvas + javascript
>>
>>55121447
Should have specified that along with your valuable advice.
>>
Anybody know python?

I am trying to write a lambda so I don't have to write
x=loads([json])
if x['type'] == (etc)


Over and over. I have
jr = lambda obj, t: (loads(obj).decode('utf8'), obj['type'])


But I am getting: TypeError: <lambda>() missing 1 required positional argument: 't'. Please help
>>
>>55118553
>second for c
>doesn't know c
it's like you enjoy getting rekt
>>
>>55121514
As you've read, your lambda gets passed one argument, and you thought it would get two, so either obj isn't supposed to be an argument, or t isn't. Is obj like self here? Show me what you pass that lambda to. (Yeah I know Snek but I don't haclve a clue about the framework)
>>
>>55121514
your function takes two arguments 'obj' and 't', but when you're calling the function, you're passing only one
>>
>>55120656
You're passing a temporary instance of class foo, which is passed to the vector by reference. i.e. it is created once by you and copied once into the class by std::vector. Your temporary copy has its destructor invoked at the end of the statement.
>>
>>55121555
>>55121568
What if I were to set a default value?
>>
>>55121592
for what purpose
>>
>>55121592
What default value to which of these arguments and what is the purpose of the argument in the first place then? It's a weird idea. Are you sure you shoukd be using a lambda in the first place?

Looking again at your code: What are you trying to avoid exactly? What's odd to you with the first snippet? I don't see...
>>
>>55121459
What is your 2-year plan?
>>
>>55121738
what?
I started programming as a hobby and wanted to try doing 2d graphics the easiest way possible. I don't have long term plans
>>
>>55121855
>the easiest way possible
C# + Unity

It'll let you make something 2D and pretty with the same work it'd take you to make something barebones basic 2D from scratch.

http://unity3d.com/
>>
I'm getting an error in C.
realloc(): invalid next size

What is causing this error?
>>
>>55122010
The invalid next size.
>>
>>55122010
an invalid next size
>>
>>55122010
Human error
>>
>>55122041
>>55122042
Well? Which one is it?
>>
>>55122054
the next one
>>
>>55122054
Yes,
>>
Er det mulig å lære Idris?
>>
>>55122052
https://youtu.be/6Xbnu9mcxm0
>>55122010
>How do I Google
>>
>>55118553
>>55118965
>can't average 2 numbers
>thinks he can check for primes
>inevitably gets told
Why don't you ever learn /g/?
>>
>>55122093
Fuck man, I was using duckduckgo and it didn't give me shit. Then I used google and it actually gave me something helpful.
>>
>>55122101
I bet /g/ can't even average one int
>>
>>55122101
>>can't average 2 numbers
I'd like to see you try averaging 2 integers in C, faggot
>>
>>55122188
>I was among the rekt
You don't say!
>>
>>55122188
int32_t (int32_t a, int32_t b) {
int64_t t = a + b;
t /= 2;
return t;
}
>>
>>55122215
>undefined behavior
m8...
>>
>>55122215
Doesn't work, dumbass.
>>
>>55122243
What's wrong with it?
>>
>>55122257
this >>55122239
>>
>>55122257
You didn't specify a function name.
>>
>>55122260
Which bit is undefined?
>>
>>55122274
the overflow
>>
>>55122270
Oh shit, my phone ate the function name.
>>
>>55122280
It oughtn't ever overflow.
>>
>>55122215
The correct way to do this would be

int32_t avg(int32_t a, int32_t b) {
int64_t t = (int64_t)a + b;
t /= 2;
return t;
}
>>
>>55122292
of course it will
>>
>>55122257
It doesn't work if one of them is odd and the other even
>>
File: 1458515256516.jpg (259KB, 1284x980px) Image search: [Google]
1458515256516.jpg
259KB, 1284x980px
>>55122151
>implying C++ is not a pleb language
>>
>>55122295
not portable
>>
>>55122295
Oh shit, you're right. Damnit.
>>
>>55122295
what makes that """correct"""?

how is using a static cast to 64 bit """correct"""?

integer division isn't """correct""" for mean averages dumbass
>>
>>55122312
hello pahjeet!
>>
>>55122320
You will never need to compile to anything that it won't work with. Guarantee it.
>>
>>55122331
what's the """correct""" way to do it?

please teach me
>>
>>55122331
Integer division is correct for integer average.

>>55122320
Disagree with you on that one.
>>
>>55122346
Nobody asked him to "integer average" whatever that is. He was asked to average 2 integers.

Integers are not closed under averaging.
>>
>>55122356
You should have elaborated on that earlier. When you say it now it only looks like you're looking for ways to nitpick.
>>
>>55122372
>being this new to /dpt/
>>
>>55122356
You and everybody else here knows that it's shorthand for average and round the result down to the nearest int. Did it feel good being pedantic, though? Fuck off back to your algebra class and let your prof fill your ring
>>
>>55122396
I redirect you to >>55122385
>>
>>55122417
>>55122385
Just because you keep doing dumb things does not mean it should be perceived by others as norm.
>>
>>55122338
classic /g/ webshit assumption; here's an excerpt from freescale's limits.h for DSP56K (I happen to have the toolchain installed, crazy, right? who needs anything except atom and node.js for development these days, amirite?)
/* the 56k supports 24 bit chars and ints, and 48 bit longs. */

#define CHAR_BIT 24
#define SCHAR_MIN (-8388607)
#define SCHAR_MAX 8388607
#define UCHAR_MAX 0xffffff
#define MB_LEN_MAX 3
#define LONG_MIN (-((8388607*16777216)+16777215))
#define LONG_MAX ((8388607*16777216)+16777215)
#define ULONG_MAX 0xffffffffffff

oh, and the compiler is something obscure, called gcc, you probably never heard of it; but hey, if a weeaboo shit """"guarantees it"""" it must be so :^)
>>55122346
>Disagree with you
worthless shits such as yourself are not entitled to an opinion
>>
>>55122356
>>55122372
no amount of damage control will wash the rekt
>>
>>55122435
>worthless shits such as yourself are not entitled to an opinion
Harsh.
But does not make your argument any stronger.
>>
>>55122431
>>55122447

>Did it feel good being pedantic, though?
>When you say it now it only looks like you're looking for ways to nitpick.

That's the point, as those who've known /dpt/ more than a few weeks would know. Now get out, newfags.
>>
>>55122447
>the rekt
>i meant something else!
>>
>>55122435
Can't you afford a real computer?
>>
>>55122453
>gets told in the post he quotes
>still doesn't understand he's an idiot
>>
>>55122462
>damage control
yes, you got BTFO
>>
>>55122472
All you did was you listed a bunch of limits that are not relevant to int64_t and int32_t types.
>>
File: disappointedotter.jpg (155KB, 615x380px) Image search: [Google]
disappointedotter.jpg
155KB, 615x380px
autismos pls go
>>
>>55122457
I've been on and off in /dpt/ since its creation. Going to repeat myself: just because you keep doing this doesn't mean it's okay to.
>>
>>55122508
>you're not allowed to do that because I can't afford a real computer so it wouldn't work for me!
Poorfags GTFO pls
>>
>averaging two ints in C still causes all this shitflinging
Maybe this meme was a mistake
>>
File: averaging 2 integers.png (2KB, 512x86px) Image search: [Google]
averaging 2 integers.png
2KB, 512x86px
Lesser languages blown the fuck out
>>
>>55122531
>damage control
>>
>>55122550
>poor
>>
File: le meem xd.png (3KB, 259x119px) Image search: [Google]
le meem xd.png
3KB, 259x119px
>>55122542
>>
>>55122516
>not relevant to int64_t and int32_t types
ah, my mistake, I assumed you know the requirements for int32_t and int64_t; I'll spell it out for retards: they don't always exist, such as in this case, where it is not possible to construct a fixed 32-bit type when your smallest addressable unit is 24-bits; if you're still having trouble: 32 is not a multiple of 24
>>55122531
>real computer
you're just confirming you don't know that a toolchain is not a computer; the first time I let that slide, now I must point it out for charity reasons
>>
>>55122565
>dynamically typed
not integers
>>
>>55122569
>ah, my mistake, I assumed you know the requirements for int32_t and int64_t; I'll spell it out for retards: they don't always exist, such as in this case, where it is not possible to construct a fixed 32-bit type when your smallest addressable unit is 24-bits; if you're still having trouble: 32 is not a multiple of 24
The program is portable - it's just that your architecture is not good enough to run it.
>>
>>55122562
>still butthurt AND ass blasted
holy kek
>>
>>55122435
You know if you weren't so confrontational, the thread would be a much better place.
>>
>>55122582
>it's just that
backpedaling on /dpt/?
>>
>>55122605
Original claim still stands.
>>
>>55122295
int32_t avg(int32_t &a, int32_t &b)
{
int64_t t = (int64_t) a + b;
t /= 2;
return (int32_t&) t;
}
>>
>>55122585
I'll be okay, I'll just go cry into my money for a while.
>>
>>55122303
a + b yields an int32_t which is ONLY THEN converted to int64_t.

You probably wanted to do something like this:
int32_t avg(int32_t a, int32_t b) {
int64_t t = a;
t += b;
t /= 2;
return t;
}
>>
>>55122653
ahahah

keep being delusional faggot
>>
>>55122650
Not even C
>>
>>55122577
So? Why represent as an integral type the result of an operation which is external to integers? Euclidean division? Yes we have that, it's 3//2.
>>
>>55122650
but why
>>
>>55122582
come on, gee, the statement of "not relevant to int64_t and int32_t" got BTFO; why can't you admin you got told? why would you even argue with the bid dick playa in the first place when you know your ass is just gonna get stretched even more?
>>55122639
so you at least admit you got analed on the second? so you don't actually know what the fuck you're talking about; you don't even know what portable means and thus you're not entitled to an opinion anyway, right, shitfag?
>>
>>55122671
O shit waddup
>>
>>55122682
>come on, gee, the statement of "not relevant to int64_t and int32_t" got BTFO
Nope. int64_t and int32_t are portable and not affected by limits you listed.
>>
>>55122597
nah, shits just never learn! better fuck their mouths on the spot with every chance than take it slow and drag the back and forth over multiple threads
>>
>>55122657
who the fuck are you quoting, shitsperg?
>>
How can I check if a float has incremented by 1 in C?
>>
>>55122696
>I don't know anything about C
>but I like it rough, so continue pounding me
anon, you're just teasing now... :^)
>>
File: sub.png (9KB, 378x509px) Image search: [Google]
sub.png
9KB, 378x509px
>>55121093
I did not know about glBufferSubData anon. Thank you for making my life easier. This is cool as fuck.

        float viewportVBO[36]={-1.0f,1.0f,0.0f,  0.0f,1.0f,0.0f,
1.0f,1.0f,0.0f, 0.0f,1.0f,0.0f,
-1.0f,-1.0f,0.0f, 0.0f,1.0f,0.0f,
1.0f,1.0f,0.0f, 0.0f,1.0f,0.0f,
-1.0f,-1.0f,0.0f, 0.0f,1.0f,0.0f,
1.0f,-1.0f,0.0f, 0.0f,1.0f,0.0f,
};

float viewportVBO2[36]={-1.0f,1.0f,0.0f, 1.0f,1.0f,0.0f,
1.0f,1.0f,0.0f, 1.0f,1.0f,0.0f,
-1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f,
1.0f,1.0f,0.0f, 1.0f,1.0f,0.0f,
-1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f,
1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f,
};

shaders.Transfer("SHADERS/VertexShaderBlock.WAA",vertexShaders,'v');
shaders.Transfer("SHADERS/fragmentShaderBlock.WAA",fragmentShaders,'f');
shaders.Compile2("outColor", shaders.shaderPrograms[2], vertexShaders, fragmentShaders);
glUseProgram(shaders.shaderPrograms[2]);
glBindBuffer(GL_ARRAY_BUFFER,VBO[2]);
glBufferData(GL_ARRAY_BUFFER, sizeof(viewportVBO2), viewportVBO2, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(viewportVBO2),viewportVBO);
glBufferSubData(GL_ARRAY_BUFFER,sizeof(viewportVBO)/2,sizeof(viewportVBO)/2,&viewportVBO2[18]);
>>
>>55122713
you can't
>>
>>55122715
Well, if you'd like to refute my claims instead of name-calling, you're more than welcome.
>>
C - a languag wich has 99 gotchas for averaging two ints.

Why are you still defending it, /g/? Maybe it was good in the '70s. But we're in '10s now.
>>
>>55122723
but I already stretched you so much!
>>
>>55122682
Register limits have nothing to do if an arch can manipulate a particular variable or not. long double is 80bits on in the 386arch, yet it is not divisible by 32. The long type for 8086 was also longer than its largest register, and yet code could still manipulate it. Also please calm down, it sounds like you're having aneurysm.
>>
>>55122713
int hasFloatBeenIncrementedOrNot(float original, float maybeIncremented){
if(original+1==maybeIncremented)
return 1;

return 0;
}
>>
>>55122743
We should be using Idris.
>>
>>55122743
/g/ is not defending it, /g/ is getting rekt every day on C
>>
>>55122747
You're not making your argument any stronger.
>>
>>55122764
dick my dick feel strong enough for you mouth tho? :^)
>>
>>55122743
MAD COS BAD
>>
>>55122750
>Register limits
we're not talking about register limits; the rest of your blog is useless drivel already
>80bits on in the 386arch, yet it is not divisible by 32
why would it have to be divisible by 32? it's enough to be divisible by 8; do you even know what the fuck you're talking about?
>long type for 8086 was also longer than its largest register
was its number of bits a multiple of 8?
>it sounds like you're having aneurysm.
sounds like you're getting raped every time you open your mouth
>>
fucking sql
the DB's themselves are amazing, but it feels like the language tries really hard to piss you off as much as it can when you try to do non trivial shit
>>
>>55122769
Not an argument.
>>
>>55122812
I grew to like it. What are you having issues with?
>>
File: common_lisp_btfoing.png (965B, 185x45px) Image search: [Google]
common_lisp_btfoing.png
965B, 185x45px
>>55122542
>>55122565
>Presenting the result as a decimal instead of a fraction

Nice shit languages
>>
>>55122828
Not him, but I hate the incompatibility between different implementations (or, equivalently, that the SQL spec is so limited), it makes good unit tests really painful to write.
>>
Someone told me acutally programming is better than watching tutorials so i made this little tictactoe game in python3 with coordinates bc i couldn't get it to work with curses. Anyone care to look at my code? :3

import random
import itertools

WIDTH=2
LENGTH=2
#I thought making the field variable would be cool but anything larger than 3 is dumb

def Askplay():
play=[0,0]
play[0]=int(input("X:"))
play[1]=int(input("Y:"))

if play[0]<0 or play[0]>WIDTH or play[1]<0 or play[1]>LENGTH:
print("error: not in field")
return Askplay()
else:
return(play)

def Randplay():
play=[0,0]
play[0]=random.randint(0,WIDTH)
play[1]=random.randint(0,LENGTH)
return(play)

def AreLine(l):

l=sorted(l)

Ax=l[0][0]
Ay=l[0][1]
Bx=l[1][0]
By=l[1][1]
Cx=l[2][0]
Cy=l[2][1]

if ( Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By) ) == 0 and Ax+2==Bx+1==Cx or Ay+2==By+1==Cy:
#This calculates the surface of the rectangle the points form. If it's 0 then the points are on a line.
#It also checks whether the points are next to eachother.

return True
else:
return False

plays= []
playscpu = []
endgame = False

while True:

while True:
play = Askplay()
if (plays+playscpu).count(play)<1:
plays.append(play)
break
else:
print("error: already played")

for playset in itertools.combinations(plays,3):
if AreLine(playset):
print("You won!")
endgame = True
#this endgame variable is an ugly way of breaking out of two loops.

if endgame:
break

while True:
playcpu = Randplay()
if (plays+playscpu).count(playcpu)<1:
playscpu.append(playcpu)
print(playcpu)
break

for playset in itertools.combinations(playscpu,3):
if AreLine(playset):
print("CPU won!")
endgame = True

if endgame:
break
>>
>>55122877
The funny thing is since Python is indentation based, the fact you forgot code brackets completely changes the code
>>
>>55122877
>no code tags
my man
kill urself
>>
>>55122877
I don't see any code in your post
>>
>>55122875
Oh, that's absolutely true. Thankfully I use almost exclusively Postgres variation of SQL.
>>
>>55122813
>I don't understand
of course, I can't ask much of the mentally ill
>>
>>55122828
well to be fair im just ranting, not really a fault in the language
a bit hard to explain over text, but basically "group by with rollup" really gets out of hand when you have more then 2 groups, but its also the only way i can get what i need
>>
>>55122891
>>55122889
>>55122888
So how do i post the code properly?
I'm a newfag you can kill me
>>
Java / C programmer currently learning Ruby.

Small program ideas? Interesting problems that would help me learn more about the language?
>>
>>55122910
<code>
code
</code>
but use [ ] not < >
>>
File: wedemboys.png (937B, 66x49px) Image search: [Google]
wedemboys.png
937B, 66x49px
>>55122865
agreed. Racket is nicer and more consistent tho.
>>
>>55122875
I've said it here before, but besides this, SQL is just unnecessarily verbose.

>>55122910
[ code]//no spaces[ /code]
>>
>>55122934
Text-based blackjack
>>
>>55122877
So here's the code

import random
import itertools

WIDTH=2
LENGTH=2
#I thought making the field variable would be cool but anything larger than 3 is dumb

def Askplay():
play=[0,0]
play[0]=int(input("X:"))
play[1]=int(input("Y:"))

if play[0]<0 or play[0]>WIDTH or play[1]<0 or play[1]>LENGTH:
print("error: not in field")
return Askplay()
else:
return(play)

def Randplay():
play=[0,0]
play[0]=random.randint(0,WIDTH)
play[1]=random.randint(0,LENGTH)
return(play)

def AreLine(l):

l=sorted(l)

Ax=l[0][0]
Ay=l[0][1]
Bx=l[1][0]
By=l[1][1]
Cx=l[2][0]
Cy=l[2][1]

if ( Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By) ) == 0 and Ax+2==Bx+1==Cx or Ay+2==By+1==Cy:
#This calculates the surface of the rectangle the points form. If it's 0 then the points are on a line.
#It also checks whether the points are next to eachother.

return True
else:
return False

plays= []
playscpu = []
endgame = False

while True:

while True:
play = Askplay()
if (plays+playscpu).count(play)<1:
plays.append(play)
break
else:
print("error: already played")

for playset in itertools.combinations(plays,3):
if AreLine(playset):
print("You won!")
endgame = True
#this endgame variable is an ugly way of breaking out of two loops.

if endgame:
break

while True:
playcpu = Randplay()
if (plays+playscpu).count(playcpu)<1:
playscpu.append(playcpu)
print(playcpu)
break

for playset in itertools.combinations(playscpu,3):
if AreLine(playset):
print("CPU won!")
endgame = True

if endgame:
break
>>
web dev shitter coming through, look out for my turgid filth as i ask this question:

Mongo/node question:

I want to do an if check on whether or not a certain document exists within a collection in my database.
How would I go about doing that? Would this work:
if (db.collection('myCollection').find({"query" :  "queryvalue"}).toArray().length > 0) {
// code
}

>>
>>55122949
I politely disagree with the "nicer" part, but concede on the consistency part.

Imagine a language with the expressiveness of common lisp but the cleanness of scheme. What a joy it would be
>>
>>55122980
Are you comparing by internal id, some unique index, or a whole document?
>>
>>55122696
>int64_t and int32_t are portable
This is just as portable, not affected by limits and guaranteed to pass the assertion:
char c = 127;
c++;
assert(c == -128);
>>
File: dao.gif (7KB, 300x300px) Image search: [Google]
dao.gif
7KB, 300x300px
>>55122997
>Imagine a language with the expressiveness of common lisp but the cleanness of scheme. What a joy it would be
Unrestrained agreement on my part! What is your opinon on Clojure as a Lisp?
>>
>>55123021
Actually, it isn't. The signed-ness of char is implementation dependent. On top of that I'm not sure if overflow for char is defined in the standard or not (I'm tempted to say no, but it is char, the committee's pet type).
>>
>>55123004
Thanks for the interest but I think I've got it sorted

I'll use .count instead of .find
>>
>>55123029
Not that anon, but

Clojure is fun to write, but slow as fuck when starting things up.

Also, I'm not a big fan of non-typed languages. Should probably learn me some caml sometime.
>>
>>55123021
Not seeing how that is supposed to invalidate any of my points.
>>
Anyone care to give some feedback on my textfile database (I know thats retarded but I couldnt chose the program I had to do)?
https://github.com/Nakroma/Abi2016_TextfileDatabase
>>
>>55123029
Never looked into it. [] and the whole "java ecosystem interoperability" bit give me the heebie jeebies. If I wanted shit on my language I'd use haskell, haha
>>
>>55123073
What's wrong with Haskell?
>>
>>55123051
You should probably browse the docs for some kind of existence check, instead of a .find(), because it could probably be faster.

OTOH, find().hasNext() or !find().isEmpty() (or some equivalent) could be faster than a count, which still has to scan your entire table.

Check the docs.
>>
>>55123080
its useless
>>
>>55123090
No it isn't
>>
>>55123084
>has to scan your entire table.
has to scan your entire index.
>>
So I'm doing langtons ant, and it's working and everything. I was wondering, what would be the best way to add another ant (eg add_ant()), what would be the best way to accomplish this? right now I just have two ants and two switches for the same thing. the ant is a struct which has x,y and direction it's facing.was thinking something like an array of pointers to different ants? I'm on 2 hours sleep sorry if I sound retarded.

C by the way.
>>
>>55120656
Placement new
>>
>>55123072
Welp. Looks pretty much as reliable as MongoDB. Congrats.
>>
>>55123090
Simon pls go

But seriously, what's wrong with it?
>>
>>55123090
https://youtu.be/iSmkqocn0oQ
>>
>>55122971
>#this endgame variable is an ugly way of breaking out of two loops.
Agreed, but arbitrary jumps are tied to procedures in python --- this is a dumb language design choice everyone ---, and you've not learned them.

X:1
Y:1
[2, 1]
X:1
Y:2
[2, 2]
X:1
Y:3
error: not in field
X:1
Y:0
You won!

Under which circumstances does it "not work"?
>>
>>55123072
looks good to me. i like the clean code.

Also , what does this do?
static {
commands.put("database", new CommandDatabase());
commands.put("db", new CommandDatabase());
commands.put("table", new CommandTable());
commands.put("entry", new CommandEntry());
}


never saw this in Java, the keyword static with braces
>>
>>55123112
Reminder that Simon Jones is the hero /dpt/ needs but not the hero /dpt/ deserves
>>
>>55123049
>Actually, it isn't
You are mistaken, it's portable.
>I'm not sure
That explains your confusion.
>>55123060
I'm supporting your point.
>>
>>55123119
or rather he's the hero /dpt/ doesn't deserve
>>
>>55123113
Wait, You know procedures, so put your big loop in a procedure, and return from it instead of
endgame = True
, that'll declutter the way so you and I can better analyse the bug. Also return doesn't mandate parentheses.
>>
>>55123122
>I'm supporting your point.
Oh. Honestly was surprised when that guy stepped talking about his dick and posted code.
>>
>>55123106
So youre telling me I could be the next hipster hype? nice

>>55123116
its because the put methods arent in another method like void main but in the class itself. without the static block you cant run them
>>
>>55123156
>This is because print isn't a statement on python 3, it's actually a function.

really? show me the source code
>>
>>55123156
No mate, read the answers to his posts, that wasn't the issue.

$  python2
Python 2.7.11 (default, Mar 31 2016, 06:18:34)
[GCC 5.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "This means it moves at," truck_speed * 1.6, "KMH!"
File "<stdin>", line 1
print "This means it moves at," truck_speed * 1.6, "KMH!"
^
SyntaxError: invalid syntax
>>
>>55123165
>its because the put methods arent in another method like void main but in the class itself. without the static block you cant run them

i tried with this code and doesn't work
public class A {

public static void main(String[] args) {
static {
System.out.println(getStuff());
}
}

public int getStuff() {
return 44;
}
}


output
A.java:4: error: illegal start of expression
static {
^
1 error

>>
>>55123113
>arbitrary jumps are tied to procedures in python
What does that mean?
Do you mean my ugly way of getting out of the loop is python's fault?
>>
>>55123169
What source code?
$ python3
Python 3.5.1 (default, Mar 3 2016, 09:29:07)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print
<built-in function print>

That's a good enough proof, no?
>>
>>55123202
>That's a good enough proof, no?
yes thanks

on python2.7 it just prints a new line
Python 2.7.3 (default, Jun 22 2015, 19:33:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print

>>>
>>
>>55123196
try it like this, no idea if it actually works tho. i think it needs a static variable to work but try it anyway
public class A {

static {
System.out.println(getStuff());
}

public static void main(String[] args) {

}

public int getStuff() {
return 44;
}
}
>>
>>55123184
ye, sorry
I just woke up, too many dicks in my mouth to read clearly
>>
>>55123219

it doesn't work either
A.java:4: error: non-static method getStuff() cannot be referenced from a static context
System.out.println(getStuff());
^
1 error

>>
github.com/deeepaaa/hachidori

someone notice me
>>
>>55123233
yeah, it has to reference something static. just put static into the function, this works i just tested it
public class A {

static {
System.out.println(getStuff());
}

public static void main(String[] args) {

}

public static int getStuff() {
return 44;
}
}
>>
>>55123239
ahahahah, a fucking electron application for a trivial program that does paint a few strings on the desktop pixmap, you fucking californian shitters will never cease to amaze me
>>
File: 6qBP3xH.jpg (867KB, 1024x777px) Image search: [Google]
6qBP3xH.jpg
867KB, 1024x777px
>>55123239
I got you sempai
>>
>>55118523
How would I format stuff in printf so that I get preceding whitespace so that columns get aligned to their right, or least to the left, something like
drw-rw-rwx     34    name
drw-rw-rwx 1234 st_name
>>
>>55123239
So you made a less customizable conky. cool yo
>>
>>55123197
Absolutely. General purpose programming languages should provide ways to jump out of a nested loop, at the very least. You can do that in python, but you have to abuse the concept of a procedure, i. e.
def dummyprocedure():
for i in range(10):
for j in range(10):
print(i, j)
if i == 6 and j == 9:
return
dummyprocedure()

Whereas, if your language was good, you wouldn't need to make up a dummy name for dummyprocedure, then call it in only one place for no good. But I'm mainly trying to stir up shit with Python shills there, disregard what's not relevant to your question.

As a comparison, in Racket:
(let/cc escape
(for* ([i 10] [j 10])
(displayln (list i j))
(and (= i 6) (= j 9) (escape))))

More elegant, eloquent, and to the point.
>>
>>55123268
Crap name and st_name should have been aligned to their right, but you get the picture.
>>
>>55118523
sauce on op's pic?
>>
>>55123219
Jesus Christ Java is verbose
>>
>>55123268
Count maximum lengths and compute offsets
>>
>>55123281
Understand that the standard library is not magical and that you will have to determine the width of the column yourself. Then RTFM printf and look in section "Field width".
>>
>>55123285
I really learned to hate java with this project. No idea why my school thinks that its a good idea to force everybody to use java for their final project
>>
>>55123268
#include <stdio.h>

int main()
{
const char *str1 = "drw-rw-rwx";
const char *str2 = "drw-rw-rwx";

int num1 = 34;
int num2 = 1234;

const char *str3 = "name";
const char *str4 = "st_name";


printf("%s%10d %7s\n",str1,num1, str3);
printf("%s%10d %7s\n",str1,num2, str4);

return 0;
}
>>
>>55123100
bump please. at work, bored.
>>
>>55123285
Bad for writing code, good for debugging and maintenance.

writing is just 20% of the business, anyway.
>>
>>55123334
>Good for debugging and maintenance
>>
>>55123327
An array of ants (not pointers to ants), then iterate it. Have you never done so? Malloc and realloc if you need to increase and decrease the number of ants while running.
>>
>>55123352
>i have never had a programming job
dont you have fizzbuzz to write and ints to average?
>>
>>55123352
The more "concise" the code is, the more implicit stuff is happening, the more context you have to keep in mind when debugging or maintaining.
>>
>>55123358
So an array of structs. Gotcha.
Yeah, I have; I just couldn't think of how I wanted to do this. Like I said, 2 hours of sleep and I have 7 more hours ahead of me, brain isn't in the 'think logically' mindset.
>>
>>55123321
>>55123316
>>55123298
I should have just read the manual as the dude said. But I can't rememebr for the love of life why the hell I wasn't able to find the right format for example %10s the last tiem I did stuff like this.

So one more thing that we cleared the first part of my question. the 10 in %10s is hardcoded, so to speak. If I find the length of the longest string I'm gonna print out, how I would I insert the in the format?
>>
>>55123277
>dummy name
>escape
top fucking kek
for i, j in itertools.product(range(10), range(10)):
print(i, j)
if i == 6 and j == 9:
break

More elegant, eloquent, and to the point.
BTFO
T
F
O
>>
>>55123327
dunno dude
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int w = 0, h = 0;
unsigned char *pix;

void refresh(int x, int y)
{
int i, j, k;
printf("\033[H");
for (i = k = 0; i < h; putchar('\n'), i++)
for (j = 0; j < w; j++, k++)
putchar(pix[k] ? '#' : ' ');
}

void walk()
{
int dx = 0, dy = 1, i, k;
int x = w / 2, y = h / 2;

pix = calloc(1, w * h);
printf("\033[H\033[J");

while (1) {
i = (y * w + x);
if (pix[i]) k = dx, dx = -dy, dy = k;
else k = dy, dy = -dx, dx = k;

pix[i] = !pix[i];
printf("\033[%d;%dH%c", y + 1, x + 1, pix[i] ? '#' : ' ');

x += dx, y += dy;

k = 0;
if (x < 0) {
memmove(pix + 1, pix, w * h - 1);
for (i = 0; i < w * h; i += w) pix[i] = 0;
x++, k = 1;
}
else if (x >= w) {
memmove(pix, pix + 1, w * h - 1);
for (i = w-1; i < w * h; i += w) pix[i] = 0;
x--, k = 1;
}

if (y >= h) {
memmove(pix, pix + w, w * (h - 1));
memset(pix + w * (h - 1), 0, w);
y--, k = 1;
}
else if (y < 0) {
memmove(pix + w, pix, w * (h - 1));
memset(pix, 0, w);
y++, k = 1;
}
if (k) refresh(x, y);
printf("\033[%d;%dH\033[31m@\033[m", y + 1, x + 1);

fflush(stdout);
usleep(10000);
}
}

int main(int c, char **v)
{
if (c > 1) w = atoi(v[1]);
if (c > 2) h = atoi(v[2]);
if (w < 40) w = 40;
if (h < 25) h = 25;

walk();
return 0;
}
>>
>>55123381
public class A {
...
}

What purpose does this serve? Why not simply allow declarations?

static {

}
What purpose does this serve? Why not simply allow statements?

public int getStuff() {
return 44;
}

In a less verbose language:
public getStuff () = 44;
>>
>>55123406
RTFM
>>
>>55123411
What if you're forced to have nested loops, just like our newfriend, dummy? I know you can do that with my particular example, but itertools's not gonna save your ass eternally. Say you have something to do before and after the nested loop? (and if you do the
if j == 0:
thing OH GOD NO that's forbidden because it's satanic)
>>
>>55123417
>dunno dude
no need to be snarky.
>>
>>55123421
The fun starts when you realize java doesnt have a native json parser and even with a library from google you need like 5 lines just to read out a simple file
>>
>>55123447
>I know you can do that with my particular example
of course you know, I just taught you
>Say you have
I'd say you're backpedaling now
>>
>>55123462
>5 lines to read from a file
You've forgot catching exceptions
>>
>>55123488
>catching
silly kid
>>
>>55123488
oh yeah, so 9 lines. to read a file out. oh and forget accessing the json object like a normal array/list/map whatever. for every step youre going in you need another command. and dont even get me started on how you can get different types of data with json which java obviously cant really handle
>>
>>55121434
Create a toString method?
>>
>>55123509
>JSON
>JavaScript Object Notation
>Java should natively handle a diffrent language's object

It's JavaScript's fault for having both undefined and null.
>>
>>55123560
Every other language does that though? Apart from that, its not like JSON is very complex
>>
>>55123411
>>dummy name
>>escape
Paradox is only formal. I'm not externally labelling the whole thing, I'm locally labelling the continuation (the "return" if you will, generalised). It's needed if you want to break out of overlapping nested loops, and it is actually more elegant because yes, being explicit about what name you bind the continuation to is more elegant. Otherwise, "escape" would have to be a globally reserved keyword that only gains its meaning in this special context. (procedures and syntax transformers are meaningful whatever the context, and we CAN have keywords in Racket, they are syntax parameters, e. g. "else", but notice there's no "return") Here you have a local thing (the local continuation), reified (hey what if you want to pass it to a procedure?) and bound fittingly to a local name, it is in effect more to-the-point.

>>55123473
You missed the point. Try again.
>>
Reminder that Java is the only language with native tristate bools - true, false and null
>>
>>55123421
Thank you for displaying to everyone how ignorant you are, and the fact that you've never worked on a significant project.
>>
>>55123599
C# has true, false and FILE_NOT_FOUND
>>
>>55123617
Please explain to the class, for the class, why that class was called A
>>
>>55123283
himegoto

it's all traps

>>55123447
>forced to have nested loops
Who is forcing you?
>>
>>55123599
>>55123628
C# has nullable boolean, friends.
>>
>>55123647
C# is Java with new paint
>>
>>55123275
thx
>>
>>55123633
Because the author is a fucking moron that doesn't know how to write maintainable code.
>>
>>55123658
>>55123633
I think it was called A because he wanted to test the static stuff without making a name up for it. not different than naming it StaticTestFor4Chan
>>
>>55123655
I agree.

It's a better Java that's more enjoyable to write in.
>>
>>55123658
because java is fukin gay
>>
>>55123680
You're more cancerous than actual Java posters
>>
Remember when /dpt/ actually used to post code and come up with projects/suggestions, rather than just incessant shitposting and dull worn-out memes? Because it's getting hard for me to remember... But I miss those times.
>>
>>55123714
there were no good times, /dpt/ was always shit
>>
>>55123597
>labelling
>dummy name
nice blog trying to backpedal your way out of this one :^)
>missed the point
you got schooled, kid
>>
>>55123714
I posted my code and somebody else offered a suggestion that genuinely helped me out in this thread.
>>
>>55123628
FILE_NOT_FOUND sounds like TRUE to me

>>55123714
I hate this kind of shitpost the most.
>>
>>55123714
>come up with projects/suggestions
you mean logos?
>>
>>55123762
meme
>>
>>55123277
>you wouldn't need to make up a dummy name for dummyprocedure
>you need to make up a dummy name for dummycontinuation tho
just end yourself
>>
>>55123794
meme
>>
>>55123635
>>forced to have nested loops
>Who is forcing you?
Some future problem at hand maybe? Okrite, I'll find you an example: Say you have an exotic collection datatype that has a weird interface and can only be iterated with map, no for-loop of whatever. Oh mate, now I realise that then, it doesn't need to be nested to crash down your limited form of escape continuations, watch: if we want to find the first element that matches a given predicate, we're going to stop traversing the collection as soon as we've found it, right? Then, given that map passes us the elements in a different function, we can use return! Too bad. Then you have to do:
def find(pred, collection):
class Stop(Exception):
def __init__(self, result):
self.result = result
def test(elem):
if pred(elem):
raise Stop(elem)
try:
collection.map(test)
except Stop as stop:
return stop.result

When I can just do
(define (find pred? collection)
(let/ec esc
(map-collection (λ(elem) (when (pred? elem) (esc elem) collection)))

I don't know about you, but I think the second one is more direct and simpler than the first one.

>>55123752
One day you'll be enlightened. Post Tenebras Lux, Frater, good riddance.

>>55123794
Read my post, it's powerful and logical. You have a continuation object that you can pass around, and you have to hand out a name to receive it, just like every procedure parameter ever because yes, it is a parameter under the hood.
>>
>>55123748
Now do me a favor and point out where I said it wasn't always shit.

>>55123761
It isn't a shitpost. These threads are depressing now. Waste of time.

>>55123757
Glad to hear that.
>>
>>55123835
fuck off, I bet you are a nigger too.

if you wanted a good community, there are thousand others. you enjoy shit posting so you are here
>>
New thread
>>55123856
>>
>>55123859
I'm at work, bored on a Friday. White, actually. You're.. what? Shitposting on 4chan from sun up to sun down while still having your laundry done for you?
You're perpetuating this shit by trying to send someone away. Grow up.
>>
>>55123828
If you can apply map() to a collection it means the collection is derived from the iterable type in which case any other traversing functionality will also work. Just saying though, I dunno what are you guys even arguing about.
>>
>>55123885
>I am at work... not working
I knew you were a nigger.
>>
>>55123914
Agreed, if the collection was an iterable (Python) or a sequence (Racket), I would use it as such, but the hypothesis is that it provides a
collection.map(function)
method which is part of a retarded interface. I agree it means there's something wrong upstream, but it's still nice to have a powerful enough evaluation model to be able to handle it.
>>
>>55123952
I am working.
I can multitask.

>>>/b/
>>
>>55123967
>I can steal two TVs at once
yeah, yeah we get it. you are probably smartest nigger ever
>>
>>55123828
>you have to hand out a name
you mean a dummy name? bwahahahahaha, you got rekt
>>
>>55123984
>Mom I'm ready to be turned over on my other side now

>>55123991
Is that the big dick playa I see?
>>
>>55123991
You wouldn't argue that "return" is a dummy name in python, would you? That means "escape" is actually something tangible that needs to be named in order to be used, whereas I avoided writing "dummyfunction" or such shite in Racket. Also, I can call my escape continuation "return", and y'all would never have brought up the question in the first place, because you've looked at the surface, not the deeper meaning.
>>
char *a[5] is a pointer to an array of five char pointers, right? My pointer arithmetic is rusty in C. Can I make a pointer to an array whose elements would be arrays of 5 char*? Kind of like a two dimensional array where I always know the number of columns, but not the rows?
>>
>>55124071
that is not what pointer arithmetic means.

Here is a pointer to char[5]

char (*a)[5];
>>
>>55124071
>char *a[5] is a pointer to an array of five char pointers, right?
Yes it is.
>Can I make a pointer to an array whose elements would be arrays of 5 char*?
Test it with
char *(a[5])
, I'm expecting it to cry because pointers to arrays don't exist, they're just pointers to the first element, which should be a plain char, thus the pointer should be a plain char pointer. Maybe I'm wrong tho...
>>
>>55124121
*No, it's not. >>55124115 is right, I misread you.
>>
>>55124121
Yeah and >>55124115 is right too on the syntax for a pointer to array. I forgot to edit my own post, honest.
>>
>>55124115
>>55124121
To clear it up, a char*** s would have the functionality I'm looking for since char[1] would be the second array of strings, and saying char[3][5] would give me the sixth string of the fourth array of strings. The thing is that I know in advance that each array of strings has for example, five elements.

Of course I could make a
typedef struct _out{
char *(line[5]);
} out;

...

out* lines;


But I fear that I'm making it too complicated if I there is a correct way to declare it without a struct.
>>
>>55124227
Should'a written
char *line[5] ;

without the parentheses.
>>
>>55124227
>typedef
#define N 5
typedef char arrayNchar[N];
arrayNChar* a;

Not saying it's beautiful, but it does the work at least for a first test. Then try out no-typedef syntaxes. at least one out of
char (*a)[N]
or
char *(a[N])
is the right one, so you'll find out easily.
>>
>>55124060
>I can call
can you call it dummycontinuation? :^)
>>
>>55124293
OMG LOL UR SO FUNNY ARF

0/10
>>
>>55124311
omg you got so bent! :^)
>>
>>55124321
oh you're so original, I guess it's needed with all the dummy names you have to come up with, given that python doesn't have proper lambda.
>>
>>55124287
>Not saying it's beautiful
it's fucking atrocious; NEVER typedef array types, they'll bite you in the ass when you think of them as normal types and try to use them as function parameters
>>
>>55124342
>dummy name for function is bad
>dummy name for continuation is good tho
you're just a clown, webshit, deal with it!
>>
>>55124361
>array types aren't normal types: they can't be used as function parameters
agreed. So is anon's idea legal.
>>
>>55124379
It's not a dummy name jackass, it's just "return", but more versatile. If return isn't a dummy name, then
(let/ec return ...)
doesn't require a dummy name. Answer that. And if you complain about having to define it first, well explain to me why you need the keyword return in python for a non-branching procedure. I'm listening.

>webshit
>SICP is for webshits
Yah right. Learn about call/cc and come back
>>
>>55124427
>It's not a dummy name
it is tho
>it's just "return"
wasn't it esc? how about dummycontinuation? :^)
>>
>>55124287
So looks like my solution with the struct works. But while testing out I wrote somethign like this in my program.
char *(*a[5]);

And it passes compilation. So after that I tried to allocate some memory to that and then it won't compile anymore.

Is that thing I've created five pointers to char**, or is it a pointer whose elements are arrays of five pointers to a char*?
>>
>>55124463
Look in the first argument of let/ec and you'll know. See? You're making progress towards enlightenment. Good!
>>
>>55124479
>it won't compile
error message pls
>>
>>55124482
>dummycontinuation
anon...
>>
>>55124510
error: assignment to expression with array type
a =(char***)malloc(sizeof(char***));


I've found out more
a[0] = "Hello";

Gives a warning about incompatible types

but
(*a)[0] = "Hello";


and

*a[0] = "Hello";


are fine.
>>
>>55124553
use abort and call-with-continuation-tag if you're like that. There, happy? Do you see my point now?
>>
What is the more pythonic solution?

 
def download(*args):

# parse args

if foo:

download_playlist()

elif bar:

download_video_list()

else:

download_video()


def download_video():

#downloads video

# return data

def download_playlist():

# donwloads playlist

# returns data


def downlad_video_list():

# downloads list of videos

# returns data

#Example:

import downloader

downloader.download(link)


OR


def download(*args):

# parse args ...

if foo:

# download video data with playlist parameters

elif bar:

# download video data with video list parameters

else:

# download video data with single video playlist

return data
>>
>>55124589
Posted this from my phone, might have fucked up the formatting
>>
>>55124556
protip:
(*a)[0] == *a[0] == **a
(== as in semantically equivalent)
It seems it's a stack based 5 element array with char** element type. Therefore, inside
 (*a[5])
, the [5] part gets precedence, just like in
char *a[5]
. Agreed, C syntax is complicated, but it means you want
char (**a)[5]
if you want to try with the array last. Yes that's weird.
>>
>>55124556
you cant assign arrays, you should memcpy/strcpy them
> a =(char***)malloc(sizeof(char***));
this is all wrong

I am assuming you want an array of arrays. lets say something like char [7][5] but allocate it dynamically

malloc(sizeof(char[5]) * 7); and cast this to correct type and assign to a.

then you can go a[0] to a[6] and each will be char[5]

instead of assigning use strcpy
strcpy(a[1], "hell");

and "hello" takes 6 chars after adding \0, allocate for char[6]
>>
>>55124387
speaking of it: va_list is an array type on amd64 and ppc32
https://godbolt.org/g/pbR69K
it's bordering standard abuse (technically, it can be argued either way)
>>
>>55124585
>if you're like that
so, whatever dummy name will do? you just proved my point :^)
>>
>>55124684
NO MATE! abort is not a locally bound name, it's a global name for a function that aborts up to the previous call-with-continuation-tag. So you see? NO DUMMY NAME! Can you do that in Python? Protip: you can't. Besides, I still stand behind the let/ec construct being meaningful because a dummyfunction will ever be called once, whereas an escape continuation can be used in multiple points. If it is so, then the fact that I only use it in a single point in my examples doesn't prove that it is a dummy. CHECKM8!
>>
>>55124732
>stand behind the let/ec construct being meaningful because a dummyfunction will ever be called once
just like your dummycontinuation?
>an escape continuation can be used in multiple points
a dummyfunction can be used in just as many places as your dummycontinuation
#REKT
E
K
T
>>
>>55124764
If a function may be called in multiple place, it's not a dummy, it is actually code that must be put into its own function. Else, it means you could generally inline it, which is the case if the function is there just for a nested loop. Try thinking, it's super effective.
>>
>>55124732
>Can you do that in Python? Protip: you can't.
Can you use Qt5 in your scheme abortion-of-the-month-implementation? How about the other hundreds of libraries and frameworks that actually help you accomplish something? Protip: all the let/ec in the world can't do shit about your useless language.
>>
>>55124799
>if the function is there just for a nested loop
you mean like how your continuation is there just for the nested loop? are you literally mentally ill?
>>
>>55124662
I didn't try to assign an array, I was trying to allocate some memory to a, but it appears that's a mistake since that would be equivalent to assigning memory to int a[10];

Looks like I'll have to use my original solution with the struct.
>>
>>55124821
>of-the-month
Racket has been around for a long time.
>Qt5
You can use gtk3, that's what DrRacket is in. Besides, I'm not arguing about library support, I'm arguing about language expressivity. Qt5 can get bindings in Racket, let/ec can't get bindings in Python, or can it?

>>55124860
It'll never be called wherever else. A continuation has more uses than a nested loop actually showcasts, and it's still one name that actually names something that should be named because it's more than a name. I know return isn't defined beforehand and activated by going into a function, but can't we move on from that? Schemes are more expressive and you can't deny it.
>>
>>55124662
jesus fucking christ, the amount of bad advice here is insane
>malloc(sizeof(char[5]) * 7)
why the fuck do you sizeof only one dimension if you need 2? why not at least sizeof (char[5][7]) and be done? second, if it's char, you should already know you need to malloc(35)
>and cast this to correct type
why cast? void * is automatically converted to any object pointer type; stop this cargo-culting madness spree
>strcpy(a[1], "hell");
why do you still teach shit practices? you KNOW the size of the destination buffer, you KNOW the size of the source, why not the actually correct memcpy? so he can learn to use strcpy by reflex and get fucked in the ass later down the road because he wasn't told the importance of ALWAYS knowing the size of his buffers?
>>
>>55124958
>Schemes are more expressive and you can't deny it
well, now that you put it like that, it's something I can agree with :^)
>>
>>55125014
Ok, nice. Guess it's how I should have phrased it from the start. Let's try one last thing: is using a dummy function not a dirty trick, needed only to compensate the fact that "break" isn't powerful enough? Aren't you using a function, thereby making an single-use object out of the inner code, whereas what you really want to do is reify the outer continuation, in order to jump back to it at an arbitrary point?
>>
>>55125063
yes, you're right, I was just shitposting out of inertia, didn't expect you to keep your cool and put up with my inane comments all this way; I'm sorry for wasting your time on this
>>
>>55125133
No problem: I'm a high-school student and I ran out of parties to go to. Also exams are piss easy here. Thank you actually, you made me think by trolling :^)
>>
>>55123116
>how to google
http://stackoverflow.com/questions/2943556/static-block-in-java
>>
When working with C, I keep finding that I'm trying to recreate features that I see in C++. Am I doing it wrong? Should I just stick with C++?
Thread posts: 397
Thread images: 18


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.