/dpt/ - daily programming thread

Go edition

The game, not the meme

Old: What AI projects are you working on Sup Forums?

Other urls found in this thread:

open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
twitter.com/AnonBabble

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

Python

If you are SJW then python.
If you are Pajeet then go.
Otherwise you should learn proper language.

java

why do you say python? is it because go is still changing with every update?
i'd like a non-meme answer, ty anyway

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

no i know c, java and haskell (somewhat)

learn whatever the fuck you want you cuck

this image is a useful reference

>What AI projects are you working on Sup Forums?

I'm playing with metaheuristics. Wanna do my own "approximate Mona Liza with triangles" thing today.

>no i know c
user...

scanf() stops reading after a space. What's the best way to read a string with space?

fgets

Roll your own readln() function

>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.

take the pledge ranjet

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?

>It's to reverse a string
put the characters into a stack tbph lad

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.

nevermind, I can still use *String to get the adress of the original string

hm?
you're now breathing consciously
i dont agree with some parts of that pic

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?

Here's my working solution. If anyone has suggestions on how to make it shorter and less messy, or more efficient, let me know.

give me a sec

Do you have any specific thing you're interested in in mind? Go is nice for networking and multithreading for instance.

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

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

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

both are SHIT but out of those two options, definitely go

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

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]

>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

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?

how about
char string[100] = "this";
?

There's no guarantee on what the array would contain after the first \0 character

yes

fuck you mook why cant i post code

The rest of the buffer MIGHT be filled with '\0'.

does that even compile

I thought the rest of a string would always be filled up with \0 ?
pic related.

string contains 't', 'h', 'i', 's', '\0'
the rest of the array is guaranteed to be all zeroes
we're talking about strings, pay attention, moron

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????

this was for

>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

my solution
#include
#include
#include

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;
}

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.

>we're talking about strings

C strings aren't real strings. They are null terminated byte arrays.

>the rest of the array is guaranteed to be all zeroes
sauce?

STFU code monkey! Why are you allowed to talk about coding, you suck at it?

>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
the aggregate initialization rules

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);
}

>what are real strings?

pascal strings

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);

>talking C
>pascal strings
t. webshit

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;

>O(n) strlen
>to save a few bytes

>I don't know the size of my string
>I must O(n)
retard

>the aggregate initialization rules
What's that? Can you point it in the C89 standard?

>i must explicitly manage and pass around the size because reasons

>255 characters should be enough for any string

>255 characters should be enough for any string
I totally agree.

strings are for codemonkeys anyway

>too hard to keep track of size
css cuck

>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.

STFU, don't talk to me.

Wow, very rude and not nice at all.

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.

STFU, remove your trip

open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

6.7.8.21

>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

Not C89, not C.

>Not C89
correct
>not C.
wrong

D E P R E C A T E D

yea i was interested in learning about making a twitter bot, and some basic web apps

Huh, well you learn something every day.

here ya go

#include
#include
#include

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

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);
}

Python has neat libraries for that. Don't know about Go.

Check out Flask for web apps.

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).

>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

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

>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

>&buf[0]
what's with the useless verbosity? ex-java programmer?

yep

in java you would just pass buf

Actual boost error.

KiB or KB?

kB

>literally retarded

--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.

i want specify the adress of the first char in the buffer
i know "&buffer" would do the same

kill yourself idiot

java is pass by value only, there is no addressof operator

Gb