[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: 38
File: nature16961-f3.jpg (94 KB, 946x309) Image search: [Google]
nature16961-f3.jpg
94 KB, 946x309
Go edition

The game, not the meme

Old: >>54914382

What AI projects are you working on /g/?
>>
>>54927397
First for D
>>
should I learn python or go?
>>
big dick in da haus!
tripfags and """literate""" shits should tread lightly: got 2 copies of the latest draft and I ain't afraid of using 'em; think twice if you don't want to get slapped in the face with a fat dick
>>
>>54927460
Python
>>
>>54927460
If you are SJW then python.
If you are Pajeet then go.
Otherwise you should learn proper language.
>>
>>54927460
java
>>
>>54927514
why do you say python? is it because go is still changing with every update?
>>54927520
i'd like a non-meme answer, ty anyway
>>
>>54927550
Depends on your situation but because you specified no more info I assume you're new to programming and Python just has more tutorials and shit
>>
>>54927571
no i know c, java and haskell (somewhat)
>>
>>54927636
learn whatever the fuck you want you cuck
>>
File: programming powerlevels.jpg (473 KB, 1400x1341) Image search: [Google]
programming powerlevels.jpg
473 KB, 1400x1341
>>54927550
this image is a useful reference
>>
>>54927397
>What AI projects are you working on /g/?

I'm playing with metaheuristics. Wanna do my own "approximate Mona Liza with triangles" thing today.
>>
>>54927636
>no i know c
anon...
>>
scanf() stops reading after a space. What's the best way to read a string with space?
>>
>>54927700
fgets
>>
>>54927700
Roll your own readln() function
>>
>>54927665
>java
>bad

Who do you think you are you useless piece of shit weeaboo? You have never done anything more complex than a fizzbuzz and think 'hurr java is le enterprise for faggots XD this doesnt bother me im a neet'.

Go get a job, faggot.
>>
File: poo_pledge.jpg (25 KB, 800x196) Image search: [Google]
poo_pledge.jpg
25 KB, 800x196
>>54927766
take the pledge ranjet
>>
>>54927659
>>54927573
>>54927727
Got a new problem at the next task. It's to reverse a string, BUT the problem is, this task forces me to use [code}void wende(char String[])[/code] as function header.
That means I can't use the char* method to manipulate the string, right?
>>
downloading microsoft visual c++ express edition. what am i in for?
>>
>>54927861
>It's to reverse a string
put the characters into a stack tbph lad
>>
>>54927887
A buffer? That's what I plan. The problem is to get the manipulated buffer into the original string though. Since I need its adress for that.
>>
File: ss (2016-06-05 at 08.25.39).png (26 KB, 917x370) Image search: [Google]
ss (2016-06-05 at 08.25.39).png
26 KB, 917x370
>>54927887
>>54927904
nevermind, I can still use *String to get the adress of the original string
>>
>>54927695
hm?
>>54927656
you're now breathing consciously
>>54927665
i dont agree with some parts of that pic
>>
File: poo in loo.jpg (250 KB, 1343x1076) Image search: [Google]
poo in loo.jpg
250 KB, 1343x1076
>>54927848
designated shitting streets are reasonable
given their infrastructure
>>
Web developer wanting to learn more about systems programming.

Recently had to use USB and an ANT (the wireless protocol) receiver to build some heart rate monitoring interactive display for an event. Thankfully there were JS libraries on NPM that handled reading from USB and all the wireless frame data, then gave me a relatively simple API to work with. I'd have really struggled to figure out the USB stuff myself.

From what I understand it couldn't be done purely in the node runtime, so it used bindings with libusb. That's the kind of shit I need to learn to work with directly I guess. So is it time to pick up the K&R C book, or should I approach systems programming from a more modern approach, like maybe Rust?
>>
File: a.png (49 KB, 1074x587) Image search: [Google]
a.png
49 KB, 1074x587
>>54927929
>>54927861
Here's my working solution. If anyone has suggestions on how to make it shorter and less messy, or more efficient, let me know.
>>
>>54928089
give me a sec
>>
>>54927636
Do you have any specific thing you're interested in in mind? Go is nice for networking and multithreading for instance.
>>
>>54928089
why not just determine the string length, and then print it by character starting from the back and ending at 0? idk C so maybe that's a lot harder to do in C than i'm imagining since i'm a java pajeet
>>
>>54928161
Because strings contain an unknown amount of '\0' characters at the end, and I don't want to print it.
If you were to just reverse all the content, you'd turn
A B C D E \0 \0 \0 \0 \0 \0

to
\0 \0 \0 \0 \0 \0 E D C B A

If you then were to print that, it would stop at the first \0, so right at the beginning.
What I need is
E D C B A \0 \0 \0 \0 \0 \0
>>
>>54928229
ah i see. do you need to have the same number of \0s as the original in the reversed one? because if not you could just advance the counter if it reads in \0 without concatenating it to a new string and then print the new string. but if you need the same number then you're right you can't do it that way
>>
>>54927460
both are SHIT but out of those two options, definitely go
>>
>>54928378
I think at least the char right after the end of the text has to be a \0. I think it's better if all the remaining ones are \0 though.

The array has a fixed size, so that means the fields have to be filled with something. Best is if the result is as the last line in >>54928229
>>
>>54928229
You know how strlen works, right?
>>
So I'm practicing functional programming, or rather, trying to program functionally (maybe I'm not doing it right?). I'd like some feedback;
1. Is this code functional in style?
2. Is there a better way to format the line returns and white space to make this more readable?
3. Is this a good solution?
/*
Flattens an array whose elements may be primitives,
arrays or multi-dimensional arrays.
concat can take either primitives or arrays, which helps
make a short solution.
*/
Array.prototype.flatten = function () {

return (
list =>
list.some(e => typeof e === 'object') ?
list.flatten() : list
)
(
this.reduce(
(p, c) => p.concat(c), []
)
);

};

var b = [0, [1], 2, [3], [4, [[5]], [6] ] ];

console.log(b.flatten()); // [0, 1, 2, 3, 4, 5, 6]
>>
>>54928229
>strings contain an unknown amount of '\0' characters at the end
no, strings have exactly one '\0', it's in the definition of the string
>>
File: Quorthon_-_Young.jpg (113 KB, 661x768) Image search: [Google]
Quorthon_-_Young.jpg
113 KB, 661x768
If I want to make a Python script intended to run on servers, occasionally polling a website, is it acceptable just to use a while-loop and a sleep statement?
>>
>>54928518
how about
char string[100] = "this";

?
>>
>>54928541
There's no guarantee on what the array would contain after the first \0 character
>>
>>54928530
yes
>>
fuck you mook why cant i post code
>>
>>54928518

The rest of the buffer MIGHT be filled with '\0'.
>>
>>54928541
does that even compile
>>
File: ss (2016-06-05 at 09.08.05).png (20 KB, 1287x413) Image search: [Google]
ss (2016-06-05 at 09.08.05).png
20 KB, 1287x413
>>54928541
>>54928634
I thought the rest of a string would always be filled up with \0 ?
pic related.
>>
>>54928541
string contains 't', 'h', 'i', 's', '\0'
>>54928585
the rest of the array is guaranteed to be all zeroes
>>54928626
we're talking about strings, pay attention, moron
>>
File: fuckingmook.png (2 KB, 492x46) Image search: [Google]
fuckingmook.png
2 KB, 492x46
I have my code injected in a process. I want to copy a function thats imported in the process, before i modify it. Im able to get the function address by doing pic related.

But how do i get the size of the function to be able to copy it?

ps:Why couldnt i post this in code tags????
>>
>>54928643
this was for >>54928585
>>
>>54928715
>before i modify it
>how do i get the size of the function to be able to copy it
have you thought this through? why do you need to copy more than you modify? if you only modify the first 100 bytes, backup the first 100 bytes
>>
>>54928089
my solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void str_rev(char *base)
{
int len = strlen(base);
while((base+len)>=base)
{
putchar(*(base+len));
len--;
}
putchar('\n');
}

int main(void)
{
char buf[20] = "cuck\0";
printf("%s\n", buf);
str_rev(&buf[0]);
return 0;
}
>>
>>54928795
This prints the reversed string to the console, right?
This works well, but I should have elaborated that the task is to modify the string to its reverse, not to print the reverse of the string.
so that str_rev(buf); causes buf to now contain the reverse of itself.
str_rev(buf);
printf("%s, buf);

should then be able to print the reverse.
>>
>>54928704
>we're talking about strings

C strings aren't real strings. They are null terminated byte arrays.
>>
>>54928704
>the rest of the array is guaranteed to be all zeroes
sauce?
>>
>>54928887
STFU code monkey! Why are you allowed to talk about coding, you suck at it?
>>
>>54928887
>aren't real strings
what are real strings? js strings? ruby strings?
shut the fuck up, you idiot, the standard defines what a string is; if you don't know, fuck off
>>54928911
the aggregate initialization rules
>>
>>54928934
static void
conn_mod_write_sendq(rb_fde_t *fd, void *data)
{
conn_t *conn = data;
const char *err;
int retlen;

if(IsDead(conn))
return;

while((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0)
conn->mod_out += retlen;

if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
{
if(retlen == 0)
close_conn(conn, WAIT_PLAIN, "%s", remote_closed);
err = strerror(errno);
close_conn(conn, WAIT_PLAIN, "Write error: %s", err);
return;
}

if(rb_rawbuf_length(conn->modbuf_out) > 0)
rb_setselect(conn->mod_fd, RB_SELECT_WRITE, conn_mod_write_sendq, conn);
else
rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL);

if(IsCork(conn) && rb_rawbuf_length(conn->modbuf_out) == 0)
{
ClearCork(conn);
conn_plain_read_cb(conn->plain_fd, conn);
}
}

static void
conn_mod_write(conn_t * conn, void *data, size_t len)
{
if(IsDead(conn)) /* no point in queueing to a dead man */
return;
rb_rawbuf_append(conn->modbuf_out, data, len);
}
>>
>>54929003
>what are real strings?

pascal strings
>>
>>54928934
    struct ConfItem *aconf;
char *p;
int para = 1;

aconf = make_conf();
aconf->port = 0;

if(parv[0][0] == 'K')
aconf->user = rb_strdup(parv[para++]);

aconf->host = rb_strdup(parv[para++]);
aconf->info.oper = operhash_add(parv[para++]);

switch (parv[0][0])
{
case 'K':
aconf->status = CONF_KILL;
break;

case 'D':
aconf->status = CONF_DLINE;
break;

case 'X':
aconf->status = CONF_XLINE;
break;

case 'R':
if(IsChannelName(aconf->host))
aconf->status = CONF_RESV_CHANNEL;
else
aconf->status = CONF_RESV_NICK;

break;
}

if((p = strchr(parv[para], '|')))
{
*p++ = '\0';
aconf->spasswd = rb_strdup(p);
}

aconf->passwd = rb_strdup(parv[para]);

rb_dlinkAddAlloc(aconf, &bandb_pending);
>>
>>54929026
>talking C
>pascal strings
t. webshit
>>
>>54929048
    struct rb_sockaddr_storage daddr;
struct ConfItem *kconf = NULL;
int aftype;
const char *p;

aftype = parse_netmask(aconf->host, &daddr, NULL);

if(aftype != HM_HOST)
{
#ifdef RB_IPV6
if(aftype == HM_IPV6)
aftype = AF_INET6;
else
#endif
aftype = AF_INET;

kconf = find_conf_by_address(aconf->host, NULL, NULL, (struct sockaddr *)&daddr,
CONF_KILL, aftype, aconf->user, NULL);
}
else
kconf = find_conf_by_address(aconf->host, NULL, NULL, NULL, CONF_KILL, 0, aconf->user, NULL);

if(kconf && ((kconf->flags & CONF_FLAGS_TEMPORARY) == 0))
return 0;

for(p = aconf->user; *p; p++)
{
if(!IsUserChar(*p) && !IsKWildChar(*p))
return 0;
}

for(p = aconf->host; *p; p++)
{
if(!IsHostChar(*p) && !IsKWildChar(*p))
return 0;
}

return 1;
>>
>>54929048
>O(n) strlen
>to save a few bytes
>>
>>54929080
>I don't know the size of my string
>I must O(n)
retard
>>
>>54929003
>the aggregate initialization rules
What's that? Can you point it in the C89 standard?
>>
>>54929098
>i must explicitly manage and pass around the size because reasons
>>
>>54929080
>255 characters should be enough for any string
>>
>>54929134
>255 characters should be enough for any string
I totally agree.
>>
strings are for codemonkeys anyway
>>
>>54929129
>too hard to keep track of size
css cuck
>>
>>54929127
>Can you point it in the C89 standard?

I'm interested, too. Being that I'm wrong, I actually want to see what the standard says.
>>
>>54929186
STFU, don't talk to me.
>>
>>54929212

Wow, very rude and not nice at all.
>>
>>54928784
I think i have to, i dont want backup of it, but i want to have the original function still available for me.

My goal is to do stuff with the arguments before the function processes it. I plan to do this by:
- making a copy of the function
- modify the original function so it immediately jumps to somewhere where i do my thing with the function arguments
- then call the copied function to process the modified arguments
- and return, by doing this i return to the main process where the original function was called from

I hope thats clear.
>>
>>54929221
STFU, remove your trip
>>
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

6.7.8.21
>>
>>54929127
>>54929186
>in the C89 standard?
who cares about C89? we're talking about C
in the C standard, the relevant entry is paragraph 21 of 6.7.9
>>
>>54929272
Not C89, not C.
>>
>>54929307
>Not C89
correct
>not C.
wrong
>>
>>54929307
D E P R E C A T E D
>>
>>54928156
yea i was interested in learning about making a twitter bot, and some basic web apps
>>
>>54929266

Huh, well you learn something every day.
>>
>>54928886
here ya go

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void str_rev(char *base)
{
int i, n;
n=strlen(base);
char buffer[n];
memcpy(&buffer[0], base, n);
i=0;
while(n--)
{
*(base+i) = buffer[n];
i++;
}
}

int main(void)
{
char buf[20] = "cuck\0";
str_rev(&buf[0]);
printf("%s\n", buf);
return 0;
}


could probably be improved on, i only program as a hobby
>>
>>54928089
I'm the pointer fag from previous thread.
I think you can do it shorter like this:
void revert(char* c){
int i = strlen(c);
int x = 0;
char buffer[i];
for(--i; i>=0; --i) //note first --i
buffer[x++] = *(c+i);
buffer[x] = '\0';

strcpy(c,buffer);
}
>>
>>54929321
Python has neat libraries for that. Don't know about Go.

Check out Flask for web apps.
>>
>>54929250
Just save the address after your inserted jump to modded code and have your modded function return there.

Getting the 'size of a function' is not trivial (sometimes not even well defined, think a block with multiple ret instructions with branches jumping to different ones), you can try some heuristic searches for common prologue/epilogue code, but it's not foolproof since depending on which registers were used it will look different (especially if frame pointers are optimized away).
>>
>>54929307
>I choose to be an obsolete retard
>I don't even know the obsolete standard guarantees the same thing as the actual standard
you're basically shit
>>
>>54928530
Or cut out both and just put it in a cronjob
>>
matlab
>> (@() 2 + 2)()
ERROR ERROR ERROR


octave
>> (@() 2 + 2)()
4


fucking pajeets at mathworks can't even parse things correctly
>>
>>54929250
>then call the copied function to process the modified arguments
you can't simply do that; the function can have instructions with relative addressing (ie. it matters where the function actually is loaded and executed relative to the rest of the code in the module)
either use a pre-made api hooking/detouring/trampoline library or prepare to implement somewhat half of a disassembler on your own
>>
>>54929348
>&buf[0]
what's with the useless verbosity? ex-java programmer?
>>
>>54929565
yep
>>
>>54929565
>>54929588
in java you would just pass buf
>>
File: help.png (211 KB, 1022x1580) Image search: [Google]
help.png
211 KB, 1022x1580
Actual boost error.
>>
KiB or KB?
>>
>>54929613
kB
>>
>>54929595
>literally retarded
>>
File: ss (2016-06-05 at 09.56.17).png (67 KB, 1071x853) Image search: [Google]
ss (2016-06-05 at 09.56.17).png
67 KB, 1071x853
>>54929349
--i is because of the \0, right?
Looks good and game me some insight, thanks

Just finished a basic array sorting algorithm. It's probably not very efficient on huge arrays, but I like that it worked on the first attempt. Also made use of the pointers I learned earlier, so thanks again.
>>
>>54929595
i want specify the adress of the first char in the buffer
i know "&buffer" would do the same
>>
>>54929631
kill yourself idiot

java is pass by value only, there is no addressof operator
>>
>>54929613
Gb
>>
>>54929641
Just buf is enough.
>>
>>54929641
>specify the adress of the first char
yes, it's just buf, no need for & and [0]
>>
>>54929661
>>54929680
alright ill keep that in mind for njext time
>>
>>54929649
>let me actually prove I'm retarded
we already knew
>>
How do we get more women involved in coding?
>>
>>54929698
>projecting this hard
kys
>>
>>54929717
weak bait
>>
>>54929603
Your point being?
>>
>>54929603
and yet the worst part was your username being "Cyberpunk" and your project being called Nara2D

I can already tell it is some degenerate anime-enabling stuff

Errors pertaining to templated classes do suck though
>>
>>54929349
>buffer[x] = '\0';
undefined behavior
>>
>>54929867
explain yourself or fuck off
>>
>>54929892
there's no buffer[x], obviously
>>
>>54929918
there is
>>
>>54929944
where? buffer only has space for x elements, you fucking shit stain
>>
>>54929961
the for loop dies before x can be incremented
>>
>>54929987
>provably retarded
>>
>>54929987
Think the simplest case when strlen(c) == 1, tell me the value of x after the loop?
>>
>>54929918
>>54929867
fuck you're right.
Sould be buffer[i + 1]

That's second time today I fucked that up :) But it's been years since I had to deal with c strings. Thanks.

>>54929634
Nah it's simply because array is 0 based. So having strlen = 9 we want to copy chars from 8 to 0.
>>
>>54930064
Why are you even using an extra buffer?
Just do it in-place.
>>
>>54928084
>directly I guess. So is it time to pick up the K&R C book, or should I approach systems programming from a more modern approach, like maybe Rust?

C is easier than Rust, I'd start with it.
>>
No Hime no code.
>>
>>54930093
Elaborate please?
Right after I swap 1st char of the string with the last one I'm losing its value for further iteration.
So intermediate temp storage is necessary.
>>
File: ss (2016-06-05 at 10.27.32).png (63 KB, 1105x701) Image search: [Google]
ss (2016-06-05 at 10.27.32).png
63 KB, 1105x701
>make pi approximator through brute-forcing rand() numbers many times
>more instances often get it further away from pi instead of closer

Is this because the numbers C generates are not random enough? Or is this just how randomness works? one million attempts still only get 3.1 right.
I'm supposed to use the monthe-carlo-method, which is to generate random points in in a coordinate system between (0,0) and (1,1), then check whether they're inside of a unit circle centered at (0,0). The ratio between in-circle to in-square points is then pi/4.

Should I try a different seed every now and then to make it more random, or will that not make a difference?
>>
>>54930133
void strrev(char *s, size_t n)
{
if (!n) return;
char *t = s + n - 1;
while (s < t) {
char c = *s;
*s = *t, *t = c;
++s, --t;
}
}
>>
>>54930187
when trying 10million numbers a few times, it seems that it always approximates 3.16. Target is 3.141.
Any idea on how to improve it?
>>
>>54930187
rand % 1000 is not uniformly random.
See https://stackoverflow.com/questions/1340729/how-do-you-generate-a-random-double-uniformly-distributed-between-0-and-1-from-c
>>
>>54930187
I think the issue is x = rand() % 1000. This does not give equal probability of producing every number between 0 and 9999. By the pigeon-hole principle, lower values of x are less likely, explaining why you're getting slightly larger values of pi than expected.

Consider switching to a language that has proper support for random number generation, like C++.
>>
>>54930187
lol
>>
>>54930187
C's rand() is garbage.
>>
>>54930199
There you have me, changing both sides at once. NIce.
Examples like that reminds me the beauty of raw pointers.
>>
>>54930262
TIL
https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
>>
File: ss (2016-06-05 at 10.40.53).png (63 KB, 1092x653) Image search: [Google]
ss (2016-06-05 at 10.40.53).png
63 KB, 1092x653
>>54930262
Thanks, this made me realise that RAND_MAX exists.
Dividing the rand() result by RAND_MAX resulted in a properly random number, pic related. It's 2^16/2 or so, 32768.

>>54930325
yes, %1000 was the mistake, because the highest result is 32768, which means that the first 768 possibilities of 1000 have a 1/32 higher chance to appear than the rest, if I'm correct.

>>54930345
?
>>54930370
It seems to be alright now, I get 5 digits of pi correct after 10million samples.
>>
>>54930370
i agree.

when i want to use a random number i use a prime modulus multiplicative linear congruential pseudo random number generator
>>
>>54930325
*more likely.
>>
>>54930262
depends what's the implementation of rand
>>
>>54930187
open Num;;

let is_valid x y = if x *. x +. y *. y <= 1.0 then Int 1 else Int 0;;

let delta_time = 0.5;;

let rec loop time count success =
let count = succ count in
let success =
success +/ is_valid (Random.float 1.0) (Random.float 1.0) in
let time =
if Sys.time () > time then
let approx_pi = float_of_num (Int 4 */ success // Int count) in
Printf.printf
"%d\t%F\t(%F, %F)"
count approx_pi (cos approx_pi) (sin approx_pi);
print_newline ();
time +. delta_time
else
time in
loop time count success
;;

let main () =
Random.self_init ();
loop (Sys.time ()) 0 (Int 0)
;;

let () = main ();;


Works for me.
>>
>>54929359
Okay now i get it.

I patch the function to jump to my own function, there i patch it back to original after i messed around with the arguments, and jump to the original function.

But when that happens next time the function is called it will not be patched and wont jump to my function. How to fix that?


>>54929526
Right, thanks for the pointers
>>
File: 09fig09.gif (41 KB, 425x502) Image search: [Google]
09fig09.gif
41 KB, 425x502
why are gotos "bad"?

do you use in your code or have seen in production code?
>>
>>54930504
>why are gotos "bad"?
They ain't bad. When they are used instead of evil break there are good.
>>
>>54930511
why is break evil?
>>
>>54930524
Because you change the way you're doing your loop and it can become a fucking mess. Break is just a sill hidden goto.
>>
>>54930446
I only know some C, but didn't you forget to get the square root of x2+y2 ?
>>
>>54930537
>Break is just a sill hidden goto.
Then, if goto is good how break that is a goto bad?
All flow control statements are sunctatic sugar for gotos..
>>
>>54930589
It would change nothing.
>>
>>54930615
Break can change if you change the context. Goto will not change.
>>
>>54927545
this
>>
>>54930448
>Okay now i get it.
>I patch the function to jump to my own function, there i patch it back to original after i messed around with the arguments, and jump to the original function.
>But when that happens next time the function is called it will not be patched and wont jump to my function. How to fix that?
You don't patch the original function back, what you do is save whatever bytes was overwritten by the insertion of the jump, and then just before you return to original function you execute those saved instructions (just like how you have to restore any registers or flags you potentially changed by your detour function)
Then you leave the added jump always in the original function.
>>
>>54930624
Why? Does it still work? What's your result?
>>
>>54930730
sqrt(x*x + y*y) < 1

square both sides:

sqrt(x*x + y*y) * sqrt(x*x + y*y) < 1*1 =

x*x + y*y < 1
>>
>>54930370
this but it should still work somewhat decently enough as long as his algorithm is correct
>>
>>54930794
Right,
x2+y2 is not the same as sqrt(x2+y2)

But they are both below 1 when x2+y2 < 1.
Thanks.
>>
File: pi-approx.webm (1 MB, 964x580) Image search: [Google]
pi-approx.webm
1 MB, 964x580
>>54930730
Compile and run my program.
>>
Goto is dangerous. Consider transferring control non-locally with longjmp, instead.
>>
>>54930881
I'm on windows.
>>
I laugh at all of the circlejerk mathematics that goes on in computer science.
"Q(p) is a function where q is the stability of the system, and p is a random variable we pulled out of our ass. As p increases, Q increases, but we don't have an actual mathematical relation; we just say it this way because fuck you."
Fuck everything about those impractical cunts.
>>
>>54930886
Ho the baby OS. But my program is portable. It works on Windows too.
>>
can arrays be implemented in a language that only has a 'define' and lambdas
y/no?
>>
>>54930881
printf("%f\n", 22/7.0f);

that was hard
>>
I really wish I could focus on one programming topic without getting the sudden urge to start learning something else
>>
File: babys first c.jpg (16 KB, 260x341) Image search: [Google]
babys first c.jpg
16 KB, 260x341
I took two classes in Java at my school, and am now learning C for fun. Everything is weird.
Should I read pic related to bring me up to speed, or is there a better resource?
If it means anything, I don't consider myself a good programmer, nor am I wizard at Java.
>>
>>54931182
same
>>
>>54931205
I usually recommend C Programming: A Modern Approach since it's more beginner-oriented.
>>
>>54930881
God I hate that stupid algorithm to approximate π. It's not a good example for an algorithm to approximate pi, nor for integration, nor for monte carlo approaches.
>>
>>54927397
Hey I have a problem I'm having trouble trying to solve.

I'm making a calculator in Python, but I want this calculator be able to support multiple operations and arguments.

So for example, someone calls it like this:
>Calc(5 * 3 * 1 + 5)
and it returns
>20

Now the problem I'm having is that unlike a normal function, I have no idea how many arguments will be passed. It could be 3, it could be 4, it could be 10. I have no idea. So I'm not sure how to define the function.

And even then, I'm not sure exactly how I would compute the arithmetic.

I'm a newfag at programming, so I'm not sure if this is over my head or not, but this is really throwing me off.

Any ideas? Maybe I'm just overlooking something. Could I somehow put all the arguments received from the function in a list? And then compute shit from it? I'd need to preserve the order of operations too.
>>
>>54931307
read about variadic arguments/kwargs
>>
>>54930665
oh ok

Thank you for your help!
>>
So how are complex C programs (like le games) actually structured? They don't have objects so I don't really understand.
>>
>>54931425
they use structs as objects and headers as interfaces
>>
>>54931461
Where can I find an example?
>>
>>54931401
Alrighty. Thanks.
>>
>>54931472
https://github.com/id-Software/Quake-III-Arena
>>
>>54931472
https://github.com/GNOME/gtk/tree/master/gtk

this is more of an "extreme" example where they've gone pretty much full OOP
>>
>>54930916
Lambda is all you need to express any computation.
>>
>>54930916
Untyped lambda calculus is turing complete
>>
Haskell will defend this

{-# LANGUAGE TemplateHaskell, OverloadedStrings, OverloadedLists, GADTs #-}
{-# LANGUAGE MonadComprehensions, ParallelListComp, TransformListComp, RecursiveDo #-}
{-# LANGUAGE UnicodeSyntax, LambdaCase, MultiWayIf #-}
{-# LANGUAGE BangPatterns, ViewPatterns, PatternSynonyms, TupleSections #-}
{-# LANGUAGE RankNTypes, TypeFamilies, MultiParamTypeClasses, ExistentialQuantification #-}
{-# LANGUAGE DeriveFunctor, DeriveGeneric, DeriveFoldable, DeriveTraversable, DeriveTraversable #-}
>>
>>54930665
>>54931421

How do i make sure i dont split an instruction when overwriting the original functions bytes?

say i have this originally:
776A021E | 6A 1C | some instructions: push 1C
776A0220 | 68 00 BB 62 77 | some instructions: push ntdll.7762BB00

but i overwrite it with a jump to my function:
776A021E | E9 12 34 56 78 | jmp myfunction
776A0223 | 62 77 | some junk because of the overwrite
>>
>>54931425
>C programs
>don't have objects
sure they do
object
region of data storage in the execution environment, the contents of which can represent values
>>
>>54931639
see >>54929526
>prepare to implement somewhat half of a disassembler on your own
>>
>>54931658
i give up

Well i hope the function im trying to patch have the right amount of instruction so i dont have to deal with that.

Maybe easier to check if there 5 bytes free before the function to do a long jump to my function, so i can do a short jump to the long jump in 2 bytes

jesus fuck
>>
>>54931425
I usually just define structs instead of classes like
typedef struct {
/* ... */
} class_t;

and then associated methods as
void class_method ( class_t *object, ... )
{
/* ... */
}

You should also implement a destuctor for convenience. It's getting pretty messy pretty quickly, so you should definitely sort things into different header files. Having at least some consistent naming scheme is also obligatory.
>>
>>54931783
If you're gonna do that just use C++
>>
>>54931822

A lot of people do that.
>>
>>54931879
And most of them use C++
>>
>>54931939

Not really, no. That's a common C technique.
>>
>>54931960
If you're doing that in C you're retarded
>>
>>54931822
this
>>
>>54931205
personally I like Kochan - Programming in C
>>
>>54931822
That is basically the absolute standard form for C programs that are just somewhat complex. You see that everywhere and I guess everybody who's programmed in C for a little while will end up with similar kind of structure.
>>
>>54932090
You honestly should be programming in C++ because it has better syntax for this stuff

You're literally writing the C code C++ code could be directly translated to, plus C++ gives you scoping in terms of namespaces & member functions, and templating (which macros don't compare to)
>>
>>54931989

You're right, I'm a Cruz Missile now.
>>
>>54932114
Really makes you think #ShillForHill
>>
File: 1460751987629.jpg (34 KB, 1280x720) Image search: [Google]
1460751987629.jpg
34 KB, 1280x720
>>54932114
Wow, nice non-argument. really makes you think
>>
>>54932156

Why reply to a non-argument with an argument? A non-argument suits a non-argument just fine.
>>
>>54932172
Not an argument.
>>
>>54932172
>>54932113
>>
>>54932190

But what if the programmer doesn't want to use C++?
>>
>>54932202
>>should be programming in C++
>>should
>>
>>54932113
I have my reasons to use C instead of C++, so no thanks. Not everything ends up in that scheme I may have to add, of course there will be many methods that are not strictly associated with a single class. It's just how your code structure is usually organised in the end, if you want it or not.
>>
>>54932237
What are those reasons?
>>
File: [tilting increases].png (27 KB, 500x500) Image search: [Google]
[tilting increases].png
27 KB, 500x500
>>54932237
>I have my reasons to use C instead of C++, so no thanks.
>>
>>54932257
Dumbass
>>
>>54932257
>I have my reasons to use C instead of C++, so no thanks.
>>
File: linus.jpg (51 KB, 425x445) Image search: [Google]
linus.jpg
51 KB, 425x445
>>54932209
C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.
>>
>>54932323
Fuck off linus, if you want to keep C++ programmers out then just don't fucking hire them you idiot
>>
>>54932323
Linus Torvalds is retarded and incompetant
>>
>>54932381
*sigh*
>>
>>54932323
>derp
>>
industry professionals generally choose C++ over C for anything that isn't OS/driver/embedded dev
>>
is visual studio c++ some weird bizzaro world version of C++? i had a class that used C++ last fall but this auto generated stuff looks alien to me
>>
>>54932780
Not really. Has different semantics for dependent lookup of types
>>
If I have a string in Python that is 5+5, how would I make it actually print the calculation? I've tried converting it to int but it just throws
>ValueError: invalid literal for int() with base 10: '5+5'
>>
In git, is it possible to ignore all files that match the names of files in some other arbitrary directory?
>>
>>54932841
Parser monad
>>
>>54932868
wat
>>
>>54932841
You tokenize the string then apply operators and operands based on the token precedence and type.
>>
>>54932824
was using C#
>>
>>54932964
C# isn't anything like C++
>>
Trying to teach myself Java and came across this odd exercise in my book:

>write a Java program that reads in a file and outputs the file as modified by the #include statements

So how do I go about implementing a preprocessor in Java? I'm not even really sure I even understand the exercise. I assume that I read an input file looking for #include and insert its content into the output file by using recursion?
>>
>>54932969
really?
>>
>>54932983
Have the Java program call gcc -E on the input file
>>
Should I learn java or python?
>>
>>54933019
java java java

say no to python

python - not even once
>>
>>54933019
python's a meme so java
>>
File: when the D hits you.jpg (23 KB, 512x512) Image search: [Google]
when the D hits you.jpg
23 KB, 512x512
>>54933019
http://tour.dlang.org/
>>
>>54932983
import re

data = ''
with open('file', 'r') as h:
data = h.readall()

def cb(m):
with open(m.group(1), 'r') as h:
return h.readall()

data = re.sub(r'#include <(\S+)>', cb, data, flags, flags=re.DOTALL)
with open('file', 'w+') as h:
h.write(data)
>>
Does anyone here is good at programming challenges?

i am struggling trying to understand a problem of network flow....
>>
>>54933055
feature-checklist whore
>>
>>54933166
Apologize
>>
File: say my name.jpg (6 KB, 299x168) Image search: [Google]
say my name.jpg
6 KB, 299x168
>>54933184
Say my name
>>
>>54933202
Hal
>>
>>54932995
It's more like Java
>>
File: screenshot1.png (1 MB, 1280x800) Image search: [Google]
screenshot1.png
1 MB, 1280x800
Yo guys I'm working on a Chrome plugin.

Beat Finder - find and identify any song playing in your browser.

Basically Shazam as a plugin in your browser
>>
>>54933254
i was memeing. obviously i know that C# isn't like C++ if i realized my mistake and posted about it here to explain why nothing looked familiar
>>
File: howitworks.gif (1 MB, 386x670) Image search: [Google]
howitworks.gif
1 MB, 386x670
>>54933274
>>
>>54933334
cool
>>
>>54933371

Its open source yo

https://github.com/Shrekie
>>
>>54933388
even more cool

shame i don't use chrome
>>
>>54932780
THere's something like CLR C++ that is indeed a weird bizzaro version of C++

>>54933012
or just cpp ?
>>
File: ishygddt.jpg (23 KB, 600x600) Image search: [Google]
ishygddt.jpg
23 KB, 600x600
>>54933388
>believes in the open source meme
>>
>>54933443
well it landed me a deal with acrcloud lol
>>
File: 1424327986446.png (34 KB, 809x808) Image search: [Google]
1424327986446.png
34 KB, 809x808
>make app
>release it
>look at bug reports and reviews
>"My 10 year old sister could write a better app than this piece of shit"
>>
>>54933467
Did you have a degree?
>>
>>54933558
well it means your app is shit or does nothing important
>>
File: 1456937598273.jpg (43 KB, 390x400) Image search: [Google]
1456937598273.jpg
43 KB, 390x400
>>54933558

>release second Chrome extension ever
>It gets some recognition

feels great

https://chrome.google.com/webstore/detail/beat-finder/ndenpgejcjbklgdhdhimhdbfbcnbknpg
>>
>>54933558
My 10 year old sister could write a better blog post than this piece of shit
>>
>>54933558
git gud feggot
>>
>>54933571
>webdev
>>
>>54933558
next time spend more time testing it yourself
>>
>>54933561
No I am self taught, 21 now. Began at 14 reading Java books.
>>
>>54933571
how does it work though?

how do you detect the songs and identify them?
>>
>>54933599
That's fucking great m8
>>
>>54933601

I made an article, acrcloud were cool enough to post it

https://www.acrcloud.com/blog/how-to-make-a-chrome-music-finder-extension
>>
>>54927397
>AI
hahaha, fuck off with your AI fad
>>
>>54933571
>smug ass faggot picture for his linkedin
>>
>>54933648
im just a fucking nerd lol
>>
>>54933648
says the NEET

kek
Thread replies: 255
Thread images: 38

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.