/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

youmightnotneedjquery.com/
yarchive.net/comp/linux/typedefs.html
libcello.org/learn/a-fat-pointer-library
github.com/nlohmann/json
github.com/kgabis/parson
twitter.com/SFWRedditVideos

First for D

Employed Haskell programmer reporting in

how _is_ D? i've heard some good things but also very little.

D is dead. Nobody uses it.

How many hours should I realistically be putting into learning an OOP language to be successful in a CS degree

POO has nothing to do with computer science.

Pretty good if you don't mind it being completely GC free (yet). I find it much better to use over Java or C++

it's done but i'll publish it only when my dumb website is up.
which may take from half a year to never.

So guys I want to program a little bot to make alts for some japanese autism game. First thought would be that I have to sniff the packets sent and received by the actual game and then analyse what's in there so that I can make my bot send the correct commands and interpret the information the server sends. Thing is: I have no idea how I would go about doing the packet sniffing. Would wireshark or some other comparable tool work just fine? And if yes, anyone have some good site to read up on that stuff?

Of course if my thoughts are stupid I am open to a proper way to get the results I want.

Still working on WPF. It's a nice framework but I think I'll leave the project without much more technology features anymore, just content, it starts doing most of what need, barring some file saving I/O features that are basic technology.
Thinking of doing something multiplatform, for a family business site, it has to do basic things like promotion and booking of services.
I thought of going mobile platforms, but sad thing is the cesspit of the web is probably more optimal for that kind of thing.

Making an algorithm which calculates the root of a number using the babilonian method in python 3.
def babilonian(n):
guess = (n-0.5)/2
def method1(k,u):
h = k/u
u = (u+h)/2
print(u)
while guess**2 != n:
method1(n,guess)
return guess

print(babilonian(5))

The problem is after the first attempt of method1, it keeps returning the same number in a infinite loop.
What the fuck am i doing wrong?

I thought Pajeet was an authority on programming.

Seems really divided and lost on if it wants gc or no.
Chapels seems way better option.

So what you mean to say is that you work at a Wendy's, and program Haskell on the side?

Why go on the Internet and make things up?

Here's a good reference: youmightnotneedjquery.com/

while guess**2 != n

it's just a pattern matching problem if you have a wireshark equivalent api, read up on that business (finite automata)

(defun s(A)
(do((x 1(*(+ x(/ A x)).5))(n 100(1- n)))((zerop n)x)))

/*
* Some simple finite state machine implementations.
*/

/*
* Theoretically you could use the address of a state handler as its identity,
* however this is extremely cumbersome in C, as while you may compare function
* pointers for equality, you may not use them as switch expressions.
*/

enum state {
EVEN,
ODD
} fsm_a(enum state, int), fsm_b(enum state, int);

// Type A

enum state fsm_a(enum state st, int in)
{
switch (st) {
case EVEN:
return in ? ODD : EVEN;
case ODD:
return in ? EVEN : ODD;
}
}

// Type B

static enum state even(int in)
{
return in ? ODD : EVEN;
}

static enum state odd(int in)
{
return in ? EVEN : ODD;
}

enum state fsm_b(enum state st, int in)
{
#ifndef __GNUC__
static enum state (* const tbl[])(int) = {
#else
/*
* This ones for free :-) The GNU typeof extension can simplify
* unintuitive type declarations significantly.
*/
static const typeof(enum state (*)(int)) tbl[] = {
#endif
[EVEN] = even,
[ODD] = odd
};

return tbl[st](in);
}/code]
something i just whipped out earlier today re: implementation.

As a straight white male am I pretty much SOL for getting hired in tech now? Everywhere I look people are saying that H1Bs are taking over everything, and if it's not H1Bs, its diversity and gender quotas.
Are these just memes perpetuated by incompetence?

my heart sank when i saw the missing bracket as i had just pressed post

Pattern matching is not a problem.

My problem is that I have never done anything like packet sniffing. Or infact anything related to doing stuff to a running program to the outside (like trying to read the memory allocated by the program and just trying to make sense of the shit in there).

But I take that as "Yeah, wireshark works just fine"

Right, I know it's always true but it shouldn't be, method1 process the number once and returns the same number everytime

Also thanks for the trouble to give such an elaborate answer

well i'm drunk and extremely nice

>finite automata
what about infinite state automata?

Integers are immutable in python, when you do `u = (u + h)/2`, `u` now references a new object, while guess remains how it was. to get around this return u from the internal function and set guess to that.

def method1(k,u):
h = k/u
u = (u+h)/2
print(u)
return u
while guess**2 != n:
guess = method1(n,guess)

You know method1 doesn't modify it's parameters? Python is call-by-value

def Babylonian(number):
if(number == 0):
return 0

g = number/2.0;
g2 = g + 1
while(g != g2):
n = number/ g;
g2 = g
g = (g + n)/2

return g

Python is pass by referene however the assignment operator always reassigns the label not the value.

you're joking but i was just today thinking what separates a "trivially looping" computation, i.e. detectable, such as for (;;) ;, from an undecidable one (susceptible to the halting problem)
is it just class in the chomsky hierarchy?

does anyone actually use anonymous classes in java?

inb4 >java

>that posting style
fuck off, plebbitor.

answer my question faggot

i don't talk to plebbitors, sorry.

I use them all the time, just because i'm associated with the Anonymous organization (Sup Forums hackers).

i do not forgive a class and i rarely forget one.

i didn't know you could be elitist about being the second worst

ur hardcore lol
I am the hacker who started the whole Anonymous thing

well, i was Heaven a couple years ago on Sup Forums

top that

Writing some gerneric json serializer in c++ - for this freaking old borland (embarcadero nowadays) compiler...

What are you doing? The algo is simpler than that.
def bab(n, v):
x = v
for i in range(0, n):
x = 0.5*(x + v/x)
return x

print(bab(10, 2))

I try to avoid them but there's a time and a place for everything.

Or with a convergence test:
def bab(v, e=0.001):
x = v
old_x = v + 2*e
while abs(old_x - x) > e:
old_x = x
x = 0.5*(x + v/x)
return x

print(bab(2))

Why?

Is there basic programming work available online somewhere? I'm willing to work for less than min wage--I just want to do some light development for a bit of pocket money. So far all I can find is Pajeets doing bad work for a dollar an hour, and if that's all that there is, I'm not interested. I'd appreciate any recommendations or advice.

.

Fiverr

c vector storing void pointers or storing items of block size?
typedef struct {
uint count;
uint size_reserved;
uint block_size;
char *data;
} vec;


typedef struct {
uint count;
uint size_reserved;
void **data;
} vec;

lol

>typedef

eh, leave the block delimiting to the memory allocator i.e. malloc of your choice

settle down linus

hehe

>Please don't introduce more typedefs. They only hide what the hell the thing is, which is actively _bad_ for structures, since passing a
structure by value etc is something that should never be done, for example.

yarchive.net/comp/linux/typedefs.html

just waiting for LIST to complete.

say I would add 1000 ints to vector.
I would have to call 1000 mallocs and store the pointers to vector.
Or I could have this one malloc for the vector memory and store the 1000 ints there.

freenode ended my suffering

Fat pointers.

libcello.org/learn/a-fat-pointer-library

sz = sz * growth_factor + 1
where growth_factor is either PHI or 2

Because legacy application and everything else is not enough

hell is real but at least you get paid

You may want to try json.hpp. github.com/nlohmann/json

>github.com/nlohmann/json
Thanks! very kind... but yeah, I don't even have C++11!!!

bitch, i'm the core contributor lmao

Then maybe wrap github.com/kgabis/parson in C++.

Hi, Theo.

thanks user
at last i truly see

What ur doing wrong is implementing babylonian method for square roots instead of the more general newtons method, faggot.

>github.com/kgabis/parson
Thanks, but in general the problem isn't the json handling - it's the nightmare of the runtime informations (RTTI) of the embarcadero rtl

Nice operating system

Is Lisp safe to use in medical equipment controllers?

What is a zeta swap?

i ama wb deve pls no bully :3

H1B is being killed by Trump

>Today on "question you don't want your medical equipment manufacturer asking on Sup Forums"

>medical equipment controllers
>critical systems?

basically, you have use a language that you can formally prove that its programs are correct.

sometimes you can't go without the latest and greatest

Would you write your own pacemaker in lisp?

>As a straight white male am I pretty much SOL for getting hired in tech now?
If you're not willing to make a sacrifice, yes. Comfy days of easy jobs are over. Now you need "people skills"

>Everywhere I look people are saying that H1Bs are taking over everything
Shit shops like Oracle, yes.

>and if it's not H1Bs, its diversity and gender quotas.
Given the same skillset etc, a recruiter will forward female CVs/resumes ahead of yours, and the company reviewing will generally prefer those over you as well. If you know what you're talking about you're already going to sound better than 90% of applicants.

>Are these just memes perpetuated by incompetence?
Yes.

>dynamically typed
sure. just don't use it on anyone but yourself.

> EXAM REQUIRES PROGRAMMING ON PAPER

CUT MY LIFE IN TO PIECES

i'm not a fucking cripple so no. but I would write in Haskell

yeah no, it's far too lucrative for us economy even for a populist protectionist to kill
you _want_ the smart, educated foreigners to jump ship as the years 0 to college graduation are sunk cost

>that formatting
Stupid redditor. Return to your website.

if you can't write simple programs even on toilet paper, you aren't worth shit

Stupid monkey, return to your mudhut

yup, redditor confirmed. deport yourself back to your shithole

index cards and a ballpoint pen fo' life

>you aren't worth shit
Was that not clear by his blatant redditry?

why do you support hirojewki

because it's a plebbitor.

rate
typedef struct {
uint count;
uint size;
uint block;
char *data;
} vec;


static inline void vec_new(vec *v, uint s)
{
v->count = 0;
v->size = 16;
v->block = s;
v->data = malloc(s * 16);
}


static inline void *vec_get(vec *v, uint n)
{
return (void*)(v->data + (n * v->block));
}

static inline void *vec_add_one(vec *v)
{
if(v->count == v->size) {
size_t tmp = v->size < 1024 ? v->size * v->size : v->size * 2;
char *d = malloc(tmp * v->block);
memcpy(d, v->data, v->size * v->block);
v->size = tmp;
free(v->data);
v->data = d;
}
void *p = v->data + (v->count * v->block);
v->count++;
return p;
}


#define vec_add(v, val) ({ typeof(val) *p = vec_add_one((v)); *p = (val); p; })


int main()
{
vec v;
vec_new(&v, sizeof(int));
for(int n = 0; n < 100; n++)
vec_add_one(&v, n);

int sum = 0;
for(int n = 0; n < v.count; n++)
sum += *(int*)(vec_get(&v, n));

free(v.data);
return 0;
}

I was filling out enough captchas for it to be worth it

>write a generic function that draws any star polygon
I managed to do this

from turtle import *

def star(aretes, couleur) :
color(couleur)
if aretes % 2 : x = 180
else : x = 360
for i in range(aretes) :
forward(200)
left(180-(x/aretes))

# ex : star(8, "red")

exitonclick()


But I feel it's not elegant at all somehow

disregard the float precision

Mostly learning scala on Coursera if that counts, the Martin Odersky's course. Not bad.

One issue is that it really assumes you're using some kind of IDE. Thankfully intellij seems a bit less of abomination than eclipse and even comes with vim mode.

Use Ada.

fixed
#include
#include
#include

typedef unsigned int uint;

struct vec {
uint count;
uint size;
uint block;
char *data;
} ;


void vec_new(struct vec *v, uint s)
{
v->count = 0;
v->size = 16;
v->block = s;
v->data = malloc(s * 16);
}


void *vec_get(struct vec *v, uint n)
{
return (void*)(v->data + (n * v->block));
}

void *vec_add_one(struct vec *v)
{
if (v->count == v->size) {
size_t tmp = v->size < 1024 ? v->size * v->size : v->size * 2;
char *d = malloc(tmp * v->block);
memcpy(d, v->data, v->size * v->block);
v->size = tmp;
free(v->data);
v->data = d;
}
void *p = v->data + (v->count * v->block);
v->count++;
return p;
}


#define vec_add(v, val) ({ typeof(val) *p = vec_add_one((v)); *p = (val); p; })


int main()
{
int n;
struct vec v;
vec_new(&v, sizeof(int));
for (n = 0; n < 100; n++) {
vec_add(&v, n);
}

int sum = 0;
for (n = 0; n < v.count; n++) {
sum += *(int*)(vec_get(&v, n));
}

free(v.data);
return 0;
}

>typedef unsigned int uint;
I hate fags who do shit like this.
You don't need your own special snowflake integer types.

has anyone here actually fucking read norvig cover to cover?

its 1000 fucking pages aiming to serve as a complete introduction to AI, but when i told my prof i hadnt read it, i only attended lectures and skimmed relevant chapters for revision he looked at me like i was taking the piss.