/dpt/ - daily programming thread

NoSQL edition
>2016
>using SQL
Nice job Pajeet

Old thread

Other urls found in this thread:

en.wikipedia.org/wiki/Linker_(computing)
pastebin.com/RgXc7Rz5
github.com/CRYTEK-CRYENGINE/CRYENGINE
twitter.com/NSFWRedditImage

first for my wife's son and his passion for OOP

satan's thread? satan's thread

>using a "database" that doesn't provide ACID

second for web scale

thank you for not posting a fag thread.

can someone tell me how to make a function that takes the area of rectangle and outputs it into main?

Working on using elaboration of implicit arguments, including sizes for termination/productivity checking, and universe levels during bidirectional type checking instead of having a complex, separate unification algorithm.

Signs you're a code monkey
>don't know fuzzy logic
>don't know about linear programming
>can't into convex optimization
>can't prove program is correct
>can't prove complexity of program
>doesn't know lisp, haskell and prolog
>thinks java is a perfectly acceptable language

signs you're a smug tard:

I can't believe we used to have those old databases that would never scale to my ten-thousand (!) customers a day

kill yourself retarded hasklel rust sperg

something is wrong with the case statements.
int computerchoice()
{
srand(time(0));
int compchoice = srand()2;

return compchoice;
}

int main()

{
int player_choice = 0;

cout player_choice;

int comp_number = player_choice();

switch(player_choice);
{
case 0:

if (player_choice == 1)
cout

lmaoing at your life desu


sorry for shitposting

>break:

Working on a scrip that force me to clean my house by locking my screen.

7/10 if bait

Looks like you messed up the thread title OP.
It was meant to be "/wdg/ - Web Development General"

>mongoloid database
HA!

>implying only ruby artisans use databases

>Signs you're a useless CS student.

I don't understand why you said desu?

>>can't prove program is correct

If you are a functional programmer, your programs ARE the proofs. :^)

t b h (to be honest) is filtered to desu, autists like me use nigger speak ironically and mootykins filtered it because he's a meme

It's the jap filter

desu

user, what the fuck are you doing?

lemme enumerate the code so other people can show you some errors:
1 int computerchoice()
2 {
3 srand(time(0));
4 int compchoice = srand()2;
5
6 return compchoice;
7 }
8
9 int main()
10
11 {
12 int player_choice = 0;
13
14 cout player_choice;
16
17 int comp_number = player_choice();
18
19 switch(player_choice);
20 {
21 case 0:
22
23 if (player_choice == 1)
24 cout

Wait, it's still active? I thought it was removed a while ago, although I'm not an underage cringy teenage who uses niggerspeak (ironic shitposting is still shitposting).

Testing:
desu
senpai
baka

Oh it is, thank you Hiro.

nihongo ga wakanai?????? baka gaijin tbqh

lowercase cuck is not filtered any more

>line 12, you set player_choice as 0, and never modify it
He does, on line 15. But his code is so retarded I find it hard to believe he's not baiting.

what about uppercase KEK

oh, right, didn't see that.
but yeah, it's probably bait, and I fell for it

triangleArea width height = (width * height) / 2

Why is uppercase cuck filtered anyway? like what's the point?

fixed it
int computerchoice()
{

srand(time(0));
int compchoice = rand();2;

return compchoice;
}

int main()

{
int comp_number;
int player_choice = 0;

comp_number = computerchoice();

cout player_choice)

switch(player_choice)
{
case 0:

if (player_choice == 1)
cout

Just stop.

you're just not cut out for this bud

actually the third option doesn't work.

>int compchoice = rand();2;
>cout > player_choice)
>That entire switch block
>default:(player_choice != 1 || player_choice != 2 || player_choice != 3);

I have an extremely stupid question about c++, but I'm a total newfag learning and my brain cannot process this. Any help would be appreciated:

In simple-english, how do forward declarations work? I mean, sure it declares a function before using it so the compiler doesn't throw errors at you. But why and how do forward declarations make it possible to call a function from another file? You are declaring a function exists, sure, but you aren't really giving said function any body, so how does the program know what the function is supposed to do? Does the compiler see this declaration and then checks the entire code and files for said function?

en.wikipedia.org/wiki/Linker_(computing)

I'll assume you are a noob programmer, and that this is not bait.
you don't need those "if (player_choice == N)" checks, when you are already checking for that in the switch.

(defun rock-paper-scissors (player1 player2)
(labels ((rockp (hand)
(equal hand 'rock))
(scissorsp (hand)
(equal hand 'scissors))
(paperp (hand)
(equal hand 'paper)))
(cond ((equal player1 player2) 'tie)
((and (rockp player1) (scissorp player2)) 'player1-wins)
((and (paperp player1) (rockp player2)) 'player1-wins)
((and (scissorsp player1) (paperp player2)) 'player1-wins)
(t 'player2-wins))))

In new C/C++ programs, are there any good reasons to use Digraphs?

import rps
rps.run()

This is worse than his.

...

Sure, if your keyboard doesn't have the correct symbols.

Giving a shoutout to redis.

Redis is an in-memory key-value storage server typically used as a database and for caching and queuing.
It feels simple at first but its actually really powerful.

Think of it as a better memecached

- Very fast
- BSD License
- Supports things like strings, sets, lists, hashes, Pub/Sub, Transactions...
- Very easy to scale (easy to use clustering / data replication).
- Considered to be one of the cleanest C projects out there (code wise)
- Adopted by lots of companies & communities
- Commercial support
- Extendable with "modules" which are also written in C, like the 3rd party "password" module that allows you to store pw hashes.
- Lots of clients

I have used Redis as the backed for chat applications, machine-to-machine communications (my software and someone else's), background worker queuing (sidekiq: emails, transactions, ...) and also as general database.

I just realized its my favourite piece of software.

>memecached

redis (C) is best used on IBM (TM) machines. my company's revenue stream more than doubled after our switch to this system.

>memecached
I did not write this on purpose, fml im spending to much time here.

How can I make the numfactors function more efficient? I know there is a lots less stupid way to do it but I'm not seeing it. Project euler problem 12.

Ta

trianglenums = [sum [1..x] | x 500 = True
| otherwise = False
where numfactors = 2 * length [x | x

what is a good environment to code in python? sublime text? or is there a good framework with debugger, unit testing and shit

please avoid shitposting about how terrible python is and just answer the question

>more efficient?
By using OCaml.

PyCharm

thanks for that answer family it was very helpful

:^)

JFC user, stop abusing comprehensions and learn to write more succinctly (using point-free, not switching on a bool only to return the bool, etc.).

As for your problem, I think numfactors isn't the real issue. For one, you're trying to sum an infinite list in trianglenums - that's non-terminating.

Hiroshima is ridiculously bad at regex. For instance, many variations of /reddit/ are spamfiltered, but any punctuation after it is OK. Same with how only cuck in fullcaps or nocaps have filters, not any other caps.

>trianglenums = [sum [1..x] | x

thanks, trying it out

Hmm, maybe that's not it. I guess technically you're not ever summing an infinite list, only at the limit.

I think, still, your problem is in trianglenums. There's a much more efficient way to calculate the sums than that, not to mention that you can get an approximation (overestimated) of the square root at the same time.

both lowercase and uppercase cuck used to be filtered since moot's time with the ben garrison Sup Forums thing or whatever when cuck became a meme, then hiroshima nagasiki unfiltered 'cuck' on user's request in /qa/

But haskell is lazy so because I only ask for the first element in divisors it will only take enough from trianglenums to get the first one.

I know it works, it just takes about 5 seconds to run when I know it can be a lot faster cause my C version takes 0.6 seconds

In regards to me abusing list comprehensions, I know I use them a bit too much, but I'm not sure how better to do it.

Of course the numfactors should probably be written without a list comprehension I just can't think how.

Maybe I should read a bit more of the thing I was using to learn as I don't know that much yet but I wanted to do some actual programming to get used to the syntax and how it all works.

Is this better?

trianglenums = [x*(x+1) `div` 2 | x

The list comprehension in numfactors can be done with filter and trianglenums shouldn't be doing any list processing (other than producing an infinite sequence) in the first place.

trianglenums = [sum [1..x] | x

Here's an example of how much you can condense stuff:
-- don't actually continue using this, just get an approximate at the same time that you calculate the "triangle number"
isqrt = floor . sqrt . fromIntegral

over500factors n = 2 * length (filter isFactor [1..isqrt n]) > 500 where
isFactor x = n `mod` x == 0

The C cleanup attribute is pretty based

#include

void f(char **c)
{
puts(*c);
}

#define cleanup(f) __attribute__((cleanup(f)))

int main(void)
{
cleanup(f) char *c = "hello world";
}

Once i inject my dll in a process and get my code running, how can i find a specific imported function and hijack that so i can read its function arguments and then execute that function as it would have executed before?

>implement cellular automaton
>no idea what to do with it

What are some good things to do with wire world?

Can anyone post link to some decently written, serious, open source video game repo?
And by 'serious' I mean something definetly more profound than flappy birds.

That function is a lot better than mine, thanks.

What do you mean by get an approximate of a square root when you calculate the triangle number though?

That triangle number function is really cool, I would have never thought of that. How did you get the time to do that? I can't really tell if yours is faster than this one just by eye

Hey guys I really suck at error handling.

Does anyone have any helpful links that explain worthwhile patterns for handling errors and making sure things fail fast when I need them to?

I don't care about the programming language the articles/posts/whatever are written in

there are shitloads of free and/or open source games out there, user

I was tinkering with that the other day.

free_me(strf) char *buf = ...


Would be nice if these attributes were standardized.

But I got the impression that most of them are java or python entry level "penguin eating fish" amateur exercises. I'd like to see some decent code and good practices.

this overrides the print() function in python and works perfectly:
pastebin.com/RgXc7Rz5

But it doesn't work when I import it as a helper.py.
How can I import it without breaking functionality?

from helper import print doesn't work and neither does import helper / helper.print()

I prefer Go's "defer"

>inb4 defer existed before Go!!1
Go wasn't made to be original, quite the contrary. It takes some good things from many langs.

then google it: "FOSS games"

github.com/CRYTEK-CRYENGINE/CRYENGINE

n = x(x - 1)/2 = 0.5(x^2 - x)
n < 0.5x^2
n^0.5 < 0.5^0.5 * x

So your approximate square root can be (0.5^0.5 * x).

Though I'm sure that the normal square root is fast enough that the fewer iterations will more than compensate for it, now that I think about it.

>is casting too expensive in games?
>what about using 'new' or 'delete' instead of allocating memory?
>should I use stack everywhere I can?
>should I utilize binary operations everywhere I can?

if you're not writing games in assembly you're doing it wrong

It's 2016, none of those things are expensive unless you're doing it hundreds of thousands of times per second.

Who are you quoting?

test

Well, the part about heap memory is an issue because it can lead to fragmentation and bad cache usage. Though I'm assuming the question was really talking about something stupid like new vs. malloc which wouldn't make a difference.

did it work?

>fragmentation and bad cache usage
It's fine user.
Don't try to optimize shit until it shows up as a bottleneck in profiling.

retest

Redis actually serves a purpose (mongo does not, there is literally no use case for mongo where either redis or a relational database would be a better solution) but redis should not be used as a database like that. It's a key-value store, treat it as such.

>fragmentation and bad cache usage
memory fragmentation is really underrated, like my issues with google chrome grinding to a halt until i restart it is probably caused by memory fragmentation, you can't just teach a monkey to use malloc and free and expect to get optimal performance

yes

mongos use case is hey i dont wanna think about modeling data

ive used it to get up and running then eventually projected from it

i agree with your point though. i have no clue why its so popular

how much disk space would it take to create and store 99.99% of the tripcodes?

how are secure tripcodes more secure than plain tripcodes? is there some secret sauce on the server that salts the tripcode and if the secret sauce gets known it's easy to bruteforce secure tripcodes too?

It's not hard to optimize for that. That's mostly a question of what data structure you use.

11x92^1018 bytes

pretty much
the old secure tripcode salt was literally just appending "LOLOLOLOLOL" to the end of the password string

>11x92^1018 bytes
there are no (known) attacks on the algorithm? what's the algorithm? I have no idea, t-b-h