/dpt/ - Daily Programming Thread

Previous: What are you working on, Sup Forums?

Other urls found in this thread:

google.com/patents/US6007232?dq=6007232
better-dpt-roll.github.io/
lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html
godbolt.org/
twitter.com/NSFWRedditGif

>XKCD
I fucking hate you

literally nothing

I haven't accomplished anything in the last 3 months

other than smoke like so fucking much weed wow

That pic is so true. Here a medal for you.

I fucking dare you guys to average two ints in C

Pro tip: you can't

That one is old.

What do you call a function that takes some arguments and return a instance struct that has fields set according to the function arguments?

If you can't do it in C, what language can you do it in..?

A "constructor".

int average (const int x, const int y)
{
if ((x < 0) ^ (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}

I've decided that I want to become a developer at a quant hedge fund.

I have good python and SQL, but no real dev experience or a CS degree, so I've got a fucking mountain to climb.

I understand I'll need incredible C++ for it. What else do I need to focus on? I have some Java and C, so I don't see learning C++ as too much of a thing, but what else should I be focusing on?

I'll probably need a proper developer job between now and getting there, but this is more of a stretch goal.

I'll bite

(a + b)/2

can we please have a dedicated mod in /dpt/ that bans people for not posting anime in OP? especially XKCD

>anime image
>akarin
>const everywhere
o/

unsigned int average = (a / 2) + (b / 2) + (a & b & 1);

MyStruct s = MyStructConstructor("foo", 43);
Like this?

Connections. You wanna work at a hedge fund? You'll need connections more than a degree.

After that, data structures and algorithms.

>5 years to detect birds
Use a cognitive API.

HURR DURR SIGNED OVERFLOW IS UNDEFINED

What

Working on my terminal emulator, addingg macOS support because that seems the easy to do before Windows.

Working with cocoa in Rust is a huge pain in the ass, especially since I never worked with it before.

I would've told you but it's patented
google.com/patents/US6007232?dq=6007232

if (a+b) is greater than maxint then something terrible happens

Any good resources for learning algorithms? They're something that's missing from my skillset atm. Think we have a copy of Hacker's Delight at work, seem to remember that talking about it.

Got a few banker m8s who might be able to point me in the right direction, so I'll get something that way, in addition to randomly reaching out to people in the industry.

Any particular books etc. you'd recommend for those?

Languages that abstract data better?

Python can do it just fine

Nope, Check 4294967295 and 5000

Nope. Check -3 and 3.

lo = min(a,b);
hi = max(a,b);
return lo + (hi-lo)/2;

Ada

SICP

int _ret = a/2 + b/2;
if (a%2 == 1 && b%2 == 1) _ret += 1;

anyone has the updated programming challenge list?
otherwise give me some begineer projects in Java

Then don't do that

__float128 average(short int a, short int b)
{
__float128 c = (a/2)+(b/2);
return c;
}

In the C standard, overflow during signed integer operations is undefined.
If you two positive ints and get something larger than INT_MAX, or two negative ints and get something smaller than INT_MIN, that's undefined behaviour. Which means, as the old joke has it, the compiler can generate pretty much any machine code it sees fit, including one that makes demons fly out of your nose.

Cheers m8

better-dpt-roll.github.io/

>user is forcing https but doesn't have a redirect
Gay.

Use clarfai or something similar.

>reinventing the wheel

>google.com/patents/US6007232?dq=6007232
wew

what was that about https?

int lo = min(a, b);
int hi = max(a, b);
int answer;
for (int i = lo; i

If you navigate to the site without https, you get a 404.

That site should have a http binding that redirects to the https version, rather than 404'ing.

Any python-experts here?

I'm creating a django web-application. It is going to scrape the ever-living shit out of pixiv, danbooru, deviantart etc...

The question is, how do I proceed? I already came up with some efforts that were in my view, failures. I attempted to use celery to fetch each pixiv image/page, but that proved to be a mess because I'd have to put everything into redis, and everything has to be pickled or dilled, serialized.

I just don't know how to proceed.

Abstract primitives are fucking cancer, dude

https 404s for me. http is the only one that works

i can open the site but when i press roll nothing happens :(

I'm designing a YouTube archival system and I'm running into some trouble on storing information and files.

Let's say I have a video archive, which will have infomation about the video url, video file location, HTML page file location and archive parameters infomation. (I also plan to tracking channels and playlists with some other data structures.)

One approach I was thinking about is having a SQL database where each video archive could be an entry in a table. The information about the archive parameters, video url, video file path and HTML page file path could be stored in the columns. But I'm unsure if storing file paths is a good idea with this approach.

Another approach could be using XML files to store the archive parameter data and file path data.

What is a good approach to storing and managing information like this?

I've heard lambda calculus is good and helpful, but I don't immediately see how. Does it give any practical knowledge for anything but functional programming? What is it practically used for?

Is there a computer science equivalent?

>2017 - 0.08333
>not programming in cardboard and marbles
lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html

hi = INT_MAX
lo = INT_MIN

>total price: $240
absolutely disgusting.

a/2 + b/2 + (a%2 + b%2)/2

SQL

>file location
>html file location
Unless static pages are a must, you can use any server-side language and just use URLs like "/video/ID-NUMBER/download".
If you're concerned about using sequential row IDs, generate a unique alphanumeric ID and use that instead.

>xkcd
gtfo nigger

template
struct average
{
template
struct result_type
{
static constexpr int value = X;
static constexpr bool half = Half;
};
using result = result_type> 1), !!((A + B) & 1)>;
};

why does C++ with every next release look even more like a kludge on a kludge on a kludge?

...

1. Read SICP
2. don't not read SICP

How does godbolt.org/ knows which line produce each instructions set?

xkcd is fun

>stupidsepplesuseofstatickeyword somethingeverycompilerwilldetermine int value = X;
sepples is turning into java with a couple of very ill-considered features mimicked from functional languages

Because it is.

C++17 is designed to let compilers be backwards compatible with C++98. C++98 code needs to be able to be compiled on C++17 compilers, or else people get upset that they can't use stupid shitty code.

I mean, just imagine what it'd be like if you realize your code can't compile in the latest version of C++, so you need to be stuck on earlier versions until you port 50,000 lines of code that was originally designed to be ran on 90s era hardware.

That is so disgusting, but correct.

return 0.5f * (x&0xFF + y&0xFF);

ez ez

>overflows at compile time

i mean your choices are between wrapping calls to older languages (like Python wraps C/C++, just as they wrapped Fortran numerical calls) or supporting backwards compatibility in the language itself, in which case you either get no modern features, or your modern features have kludge syntax

there's this romantic notion that one day we'll rewrite shit in modern languages that unfortunately isn't realistic because it doesn't respect how much work has really gone into intrastructure. when you reimplement infrastructure you get garbage like Hadoop and Spark

in PyQT5, is there a convenient way to keep the UI bullshit away from the main program?

What is a good way to learn python ?
Codecadamt is not that good as far as I heard you guys.

((long long int)a + b)/2

Find a good course by a good university. CMU seems to have a good intro to programming course in Python.

(* camlavg.ml *)
open Num;;

let avg s1 s2 =
let n1 = num_of_string s1 in
let n2 = num_of_string s2 in
let avg = (n1 +/ n2) // Int 2 in
string_of_num (integer_num avg)
;;

let () = Callback.register "avg" avg;;

/* main.c */
#include

#include
#include
#include
#include

static value *closure_avg = NULL;

static char *argv[] = { "", NULL, };

extern void caml_main (char **);

int avg (int a, int b) {
char *ret;
char buff[200];
int reti;
CAMLparam0 ();
CAMLlocal3 (res, sa, sb);
if (closure_avg == NULL) {
caml_main (argv);
closure_avg = caml_named_value ("avg");
}
sprintf (buff, "%d", a);
sprintf (buff + 100, "%d", b);
sa = caml_copy_string (buff);
sb = caml_copy_string (buff + 100);
res = caml_callback2 (*closure_avg, sa, sb);
ret = String_val (res);
sscanf (ret, "%d", &reti);
CAMLreturnT (int, reti);
}

int main (int argc, char **argv) {
int a;
int b;
int c;
sscanf (argv[1], "%d", &a);
sscanf (argv[2], "%d", &b);
c = avg (a, b);
printf ("avg (%d, %d) == %d\n", a, b, c);
return 0;
}

# make.sh
#!/bin/sh -ex

ocamlopt -c camlavg.ml
ocamlopt -output-obj -o camlcode.o nums.cmxa camlavg.cmx
gcc -I$(ocamlopt -where) -c main.c
gcc -L$(ocamlopt -where) -o avg main.o camlcode.o -ldl -lnums -lm -lasmrun

Did someone hurt you when you were a kid?

declare
type Decimal is delta 0.1 range Float(Integer'First).. Float(Integer'Last);
A,B,C : Integer;
begin
C := Integer(Decimal(A)/2.0 + Decimal(B)/2.0);
end;

I'm using 'Think Python - How to Think Like a Computer Scientist' and it's good so far. If you don't like the sound of learning from a book you could always try YouTube, there must be more tutorials for Python than anything else at this point.

And when you let infrastructure sit around you get Heardbleed and Shellshock
Software is shit :=/

Are you implying that that won't happen with software that gets rewritten every 2 years?

There's even a greater chance of that happening 2bh

>DEVOTE EVERY ASPECT OF YOUR LIFE TO LEARNING MATH 24/7 FOR LIKE A YEAR
>ITS EASY TO GIT GUD IT JUST COSTS A FEW HUNDRED DOLLARS AND REQUIRES BEING COMPLETELY AUTISTIC
nobody actually takes this advice

Need a good word for a table name. The table describes files that have been posted, submitted.

The table describes files that are incoming, are received, and have yet to be processed to be entered into the system.

input_table

inbox

Well, a lot of modern tools and "software methodologies" would theoretically be less bug prone if you did it all over again.
I just think we need to move away from C.

t

Are you learning for the sake of learning, learning with the intention of seeking work, or learning to complete a project?

I got started due to option (3). It makes it a lot easier and enjoyable to self-teach if you have some endgame goal in mind.
If you're a fan of math, the daily Project Euler projects are a nice way to get it all going.

Why the fuck not just use libgmp instead of all this cs-undergrad-meme-tier bs

Now you have two problems

Both sensible suggestions, although it doesn't tell me what is in the table. file_inbox, file_input could work, but I'd like for the table name to also describe a single entry.

e.g there's a table named gallery_file, which tells you what you'll find in the table and also describes a single entry.

Why would you do that

What's wrong with xkcd?

The techniques are the same regardless of language or UI toolkit.

How much it costs (in terms of added complexity) depends upon the nature of the program.

Guess

#include
#include

int main(int argc, char* argv[])
{
int len = strlen(argv[1]);
int halflen = (len-1)/2+1;
for(int a = 0; a < halflen; a++)
{
if(!(argv[1][a] == ' ' | argv[1][len-1-a] == ' '))
{
if(!(argv[1][a] == argv[1][len-1-a]))
{
printf("No");
return 0;
}
}
}
printf("Yes");
return 0;
}

I got palindrome detector on the DPT roller. rate

Fucking tell already

Just move to C++, you'll like classes.

I think you're trying to skip spaces, but you will only skip spaces that are at the same distance relative to the start and end. The outer 'if' is redundant. If you want to skip spaces you'll need to track the offset from start and end of phrase separately, I think.

>[..] QT [..] convenient [..]
No.

What should i use then?

(int)(((int64_t)a+(int64_t)b)/(int64_t)2);

gtkmm

not him but the guy behind these comics is a massive faggot, he was "with her" and suck dicks all day long
just to name a few things

And if int is 64 or longer?

>Code monkeys will always code monkey.

>no functional programming
2/10
def palin(string):
if len(string)==1 or len(string)==0: return True
return palin(string[1:-1]) and string[0] == string[-1]