[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 18
File: K&R hime linked list copy.jpg (551 KB, 1280x1440) Image search: [Google]
K&R hime linked list copy.jpg
551 KB, 1280x1440
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 (204 KB, 440x574) Image search: [Google]
i got myself an anime!.jpg
204 KB, 440x574
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 (80 KB, 482x424) Image search: [Google]
1465700695183.jpg
80 KB, 482x424
>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 (99 KB, 630x655) Image search: [Google]
code bloat.jpg
99 KB, 630x655
>>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 (18 KB, 375x375) Image search: [Google]
spongegar.jpg
18 KB, 375x375
>>55118847
>hNot portable
>>
File: H E L L O W O R L D.png (22 KB, 564x482) Image search: [Google]
H E L L O W O R L D.png
22 KB, 564x482
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 (154 KB, 1181x515) Image search: [Google]
Untitled.jpg
154 KB, 1181x515
>>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 (2 KB, 96x96) Image search: [Google]
thumbs up.jpg
2 KB, 96x96
>>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 (194 KB, 1366x768) Image search: [Google]
zaaeazea.jpg
194 KB, 1366x768
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 (259 KB, 1284x980) Image search: [Google]
1458515256516.jpg
259 KB, 1284x980
>>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 (155 KB, 615x380) Image search: [Google]
disappointedotter.jpg
155 KB, 615x380
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 (2 KB, 512x86) Image search: [Google]
averaging 2 integers.png
2 KB, 512x86
Lesser languages blown the fuck out
>>
>>55122531
>damage control
>>
>>55122550
>poor
>>
File: le meem xd.png (3 KB, 259x119) Image search: [Google]
le meem xd.png
3 KB, 259x119
>>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 (9 KB, 378x509) Image search: [Google]
sub.png
9 KB, 378x509
>>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 (965 B, 185x45) Image search: [Google]
common_lisp_btfoing.png
965 B, 185x45
>>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 (937 B, 66x49) Image search: [Google]
wedemboys.png
937 B, 66x49
>>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 (7 KB, 300x300) Image search: [Google]
dao.gif
7 KB, 300x300
>>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?
Thread replies: 255
Thread images: 18

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.