/dpt/ - Daily Programming Thread

Death to Linked Lists Edition

Old:

Other urls found in this thread:

hackage.haskell.org/package/array
hackage.haskell.org/package/vector
java.net/projects/glassfish-samples/sources/svn/content/trunk/ws/javaee7/websocket/tictactoe/docs/index.html
twitter.com/NSFWRedditImage

>well I don't care about cache utilization since it isn't important for my Java CRUD application
>well I don't care about data structures or algorithms since it isn't important for my Rails app
>I'll just import a library, I don't need to understand this!
>who cares if it runs slow? muh moore's law will make my O(2^n) algorithm fast in a few weeks I think...
>wow calculus totally wrecked me xD
>I just want to make games and websites, why do I need this theory crap??
>why does some incompetent Pajeet take my job and work for $500/month? :((((

still depends on the usage, your graph only shows inserts, you either you don't understand data structures or you are trolling, either way sage...

>4+ posts before the bump limit

For fucks sakes look at the fucking post count before you post you fucking retard i hate you
thanks for your time

You don't understand CPU caches

You could write a linked list using a vector for allocation & small integer offsets (like a byte) rather than pointers

If the links aren't too distant it might be reasonable on a cpu

>sorting a 300k element list
Just throw it all on the a heap and pop them off

buf.append(String.format(
"#EXT-X-STREAM-INF:BANDWIDTH=%d\n127.0.0.1:" + getListeningPort()
+ "/%d/%d.m3u8", variant.bitrate, randomValue, count--));

what the fug

What would happen if a cosmic ray flipped a few null terminators in a critical system running C code?

Would the program crash?

nth for C#

>Doesn't write cosmic intervention error handling into all his programs

Tourist.

That's why they don't use strings, infinite loop and pointers.

What's the best language to be a 1337haxor with

Python.

>he doesn't add redundancy to his program
>he adds redundancy to his program

>anime image

Nothing would happen - cosmic rays are not in the C standard

I'm a TA and I saw this shit the other day in a 2nd year CS homework i was grading.

typedef double inches;
typedef double meters;

inches length1;
meters length2;
// ...
length1 = length2;

Rude people go to hell!

Show me on the Microdoll where the big mean bullies insulted you

I know this might be more of a /biz/ question but what's the minimum level of math required to get into algorithmic trading? Calc III, differential equations + Bayesian stats?

I'm just a lowly CS pleb so I've never taken a real analysis class, how useful would that be?

SHART

I've rarely found that I need a linked list, i.e. inserting/removing from one end or the other is not sufficient.

>>I'll just import a library, I don't need to understand this!
Tfw guilty of this and I keep getting burnt for it. I'll never learn.

I've rarely found that I need a linked list, i.e. inserting/removing from one end or the other is not sufficient.

AFAIK it's quite math heavy so you will definitely need more than those very basic courses

Is C++ primer the best book/source to start learning c++? I have a pretty good background in programming.

>I have a pretty good background in programming.
You don't need a book

really makes you think

if you dont know c++ you dont have a pretty good background in programming

I'd just Google whatever I need when I need something. Do you know C? Then just do that.

>linked lists in Java
This makes me want to die. Why the fuck do they have to teach linked lists in Java when there's literally no upside to them? Why don't they teach fucking Lisp? Fuck "industry standards" we don't need any more code monkeys, we need programmers who can understand Lisp

I only know Ocaml

really made me think
hmmmm
/dpt/'s advice is sometimes solid, why not ask

Nice meme faggot

But that's a complicated data structure and only useful if you're inserting TONS of elems. There are indeed some use cases, e.g. allocation buffers, and the main upside to doing that is that pointers to within the array are not invalidated on resize. But for a large majority of dynamic lists you should be using vectors. Besides, vectors are easy as fuck in both C and C++, and exists in the core library of virtually every other language.
The only exceptions are Lisp and Haskell.

Well my advice is if you already know how to program a book isn't necessary to learn C++.

Excuse me?

Why

don't "excuse" me you fuckin nerd

kys

I think a minimum chars post threshold would definitely cut back a lot of the shitposting.

...

why doesn't this shit compile, you fucking nerds

#include

int maine()
{
printf("Hello world!\n");

return 0;
}

>int maine
>maine

Posts are limited to about 2000 characters

Figure it out

>This much of a bait

it's because you are a moron.

try this:

int mayne ()
{
printf("Hello, world!\n");
return 1;
}

Not max chars, I mean like every post has to be atleast 16 characters excluding backlinks

It should compile just fine. Linking might fail, though :^)

making a jpg exif remover
any constructive criticism? this is my first real project so dont be rood pls
#include
#include
#include

int main(int argc, char*argv[])
{
FILE* file;
char* file_bin;
long f_len;
if(argv[1] != NULL)
{
file = fopen(argv[1], "rb");
fseek(file,0,SEEK_END);
f_len = ftell(file);
rewind(file);
file_bin = (char*)malloc((f_len+1)*sizeof(char));
fread(file_bin,f_len,1,file);
fclose(file);

if((uint8_t)file_bin[0] == 0xff && (uint8_t)file_bin[1] == 0xd8 && (uint8_t)file_bin[2] == 0xff && (uint8_t)file_bin[3] == 0xe0 )
{
printf("Image is valid JPEG\n");
for(int i = 0;i

Fix those nested if statements my dude

The if statements cause me worry. Nothing should have that many levels of indentation.

if((uint8_t)file_bin[i] == 0x45)
{
if((uint8_t)file_bin[i+1] == 0x78)
{
if((uint8_t)file_bin[i+2] == 0x69)
{
if((uint8_t)file_bin[i+3] == 0x66)
{


in haskell this is just
all $ zipWith (==) (drop i file_bin) [ 0x45, 0x78, 0x69, 0x66 ]

if((uint8_t)file_bin[0] == 0xff && (uint8_t)file_bin[1] == 0xd8 && (uint8_t)file_bin[2] == 0xff && (uint8_t)file_bin[3] == 0xe0 )

// replace with

if (memcmp(file_bin, "\xff\xd8\xff\xe0", 4) != 0)

// and

if((uint8_t)file_bin[i] == 0x45)
{
if((uint8_t)file_bin[i+1] == 0x78)
{
if((uint8_t)file_bin[i+2] == 0x69)
{
if((uint8_t)file_bin[i+3] == 0x66)

// replace with

if (memcmp(filebin + i, "Exif", 4) == 0)

fixed
#include
#include
#include

//Don't remove first 21 bytes (File header?)
//24 - 27 is EXIF Tag
int main(int argc, char*argv[])
{
FILE* file;
char* file_bin;
long f_len;
if(argv[1] != NULL)
{
file = fopen(argv[1], "rb");
fseek(file,0,SEEK_END);
f_len = ftell(file);
rewind(file);
file_bin = (char*)malloc((f_len+1)*sizeof(char));
fread(file_bin,f_len,1,file);
fclose(file);
/*
for(int i = 0;i < f_len;i++)
{
printf("%x ", file_bin[i]);
printf("%x ", (uint8_t)file_bin[2]);
}
*/

if((uint8_t)file_bin[0] == 0xff && (uint8_t)file_bin[1] == 0xd8 && (uint8_t)file_bin[2] == 0xff && (uint8_t)file_bin[3] == 0xe0 )
{
printf("Image is valid JPEG\n");
for(int i = 0;i

Why not:
if((uint32_t)file_bin[i] == 0x45786966) {
printf("Image has EXIF data\n");
break;
}

?

"main" was the worst choice for entry point.

try adding
#define maine main

hahaha kys

#include
#include
#include

int main(int argc, char **argv)
{
FILE* file;
char* file_bin;
long f_len;
if(argv[1]) {
file = fopen(argv[1], "rb");
fseek(file,0,SEEK_END);
f_len = ftell(file);
rewind(file);
file_bin = (char*)malloc((f_len+1)*sizeof(char));
fread(file_bin,f_len,1,file);
fclose(file);

if((uint8_t)file_bin[0] == 0xff &&
(uint8_t)file_bin[1] == 0xd8 &&
(uint8_t)file_bin[2] == 0xff &&
(uint8_t)file_bin[3] == 0xe0 ) {
puts("Image is valid JPEG");
for(int i = 0;i

Because type punning is bad, your code depends on the endianess of the target system, and you did it incorrectly.

STFU

Literally what would be a better option, and give me an actually valuable argument about why

still not working:
#define maine main
int mayne ()
{
printf("Hello, world!\n");
return 1;
}

>OSGTP
>valuable argument
wew wew wew

The Haskell standard literary specifies an Array module.
hackage.haskell.org/package/array
hackage.haskell.org/package/vector

no no no, its
char* maen()
{
printf("Hello, world!\n");
return 1;
}

tard

Pick a function at random

Thanks for posting so I didn't have to.

#include
#include
#include
#include

int main(void) {

int n, i;
char *charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#&/()=?";
srand(time(NULL) * strlen(charset));
printf("Length: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {

int r = rand() % strlen(charset);
printf("%c", charset[r]);

}
printf("\n");
}

tell me why i suck

rand() is garbage no matter what you seed it with

because you call strlen too many times

I thought that argument only applied to cryptography.
What should I use instead?

>main doesn't return anything
fired

use xorshift

uint64_t xorshift(uint64_t *state)
{
uint64_t x = *state;
x ^= x >> 12;
x ^= x > 27;
*state = x;
return x * UINT64_C(2685821657736338717);
}

What kind of algorithms did Sean Murray use to make No Man's Sky?

and what language?

What's this a drunkposting program?

STFU

>What kind of algorithms did Sean Murray use to make No Man's Sky?
rand() from C
>and what language?
Java

bubble sort, sieve of eratosthenes

Standard ML

C99 allows that

Genetic algorithms in Malbolge

>uint8_t
Unportable

>FILE*
You should instead write type *var.

Also, learn to use &&

>C99
Yes and coprophagy is a thing too.

You need to use size_t for r.

Anyone have a programming challenge for someone who's literally just learned the basic of Python?

Check if two words are anagram of each other

a program that outputs its onwn source code

Generate random names

how hard is it to learn xlib? how long?
i really want to make my own tiling wm

Too long, it'd be easier to wrap SDL2 or somethnig

My job is basically 4 or 5 sorting algorithms and a few basic scripts but irl

import collections

def anagram(s1, s2):
if collections.Counter(s1) == collections.Counter(s2):
return True
return False

I'm the opposite.
> working as code monkey on the side
> image recognition in Python
> source images are in HSV colorspace but when I load them they're interpreted as BGR
> look up BGR to HSV conversion on Wikipedia
> implement it
> could have just used a function in an image processing library I was importing anyway
Did the same for calculating mean, median and standard deviation of lists of values. Wasted so much time.

SOMEBODY SEND HELP
I'm trying to run this
java.net/projects/glassfish-samples/sources/svn/content/trunk/ws/javaee7/websocket/tictactoe/docs/index.html

On intelliJ idea

the first error was the JavaFX dependency, i had to delete it because i'm using jdk 1.8 so that fixed it

When i run the maven build i get another error in the client

Exception in Application start method: Handshake response not received.

> org.glassfish.samples.tictactoe.client.TicTacToeClient.startGame(TicTacToeClient.java:150)
> org.glassfish.samples.tictactoe.client.TicTacToeClient.start(TicTacToeClient.java:117)

>container.connectToServer(LocalEndpoint.class, null, new URI(SERVER));
and SERVER is
>private String SERVER = "ws://localhost:8080/tictactoeserver/endpoint";

inb4
>Glassfish

Is zipWith just a fold that takes two functions instead of one?

design your own relational database software in python

Honestly, if you do manual cache prefetching and don't allocate any memory then they give great performance when used in memory blocks inside memory pools to mark memory. I can't really think of a replacement.

Like:

struct MemoryNode
{
MemoryNode* next;
uint8_t flag;
};

do you think, xmonad uses xlib and its only 1200 LOC
surely there can't be many uses of the xlib, just some general useful functions

def anagram(s1, s2):
return sorted(s1) == sorted(s2)