/dpt/ Daily Programming Thread

previously

Attached: 1525664156583.png (3033x2200, 2.03M)

Other urls found in this thread:

dangermouse.net/esoteric/ook.html
pastebin.com/t1tUnRgE
stackoverflow.com/questions/4851234/difference-between-int-and-int-in-c
twitter.com/SFWRedditImages

Fuck off with your shitty reddit memes.

haskell!

Attached: karen haskell.png (1280x719, 818K)

Should IDLE suggest dot oparators?

What's the best python IDE that lets you write custom themes and lets you switch between versions of python easily?

Attached: 1524947792421.jpg (385x387, 17K)

>python
lol

Attached: 1503621091771.gif (540x540, 1.1M)

Where are pybooga and haskuuga?
Consider this an issue.

that pseudo meme doesn't make any sense and is a disgrace to the /dpt/ memers of the old days.

None of these grugs make sense.

Python is already extinct and Haskell has yet to be invented. Haskell is like space age while they're all stone age languages.

I was surprised ponylang exists, 2bh

this, especially since bronies don't have the right to exist

>haskell
>space age
Nothing important has ever been built in Haskell. Haskell is like a modern art piece that no one really enjoys but tries to appreciate because of how smart they feel to be associated with it.

good op image user
add haskell
make it an anime girl
it'll shut them up

Is there any anime equivalent of grugs?

You mean nothing that contributes to the capo-commie feminist matriarch techno system

>tfw HAXE and I can target whatever the fuck I want with a single codebase

Attached: 603.jpg (245x193, 16K)

What's the idiomatic way to do this in python?

[code
for (int i = 1000; i < 100000000; i*=10)
[/code]

I couldn't see a way to do it with range(). Ofc i can do it easily by manually setting the vars but i'm sure there's a nice way to do it.

>when meme is done wrong

Attached: wow anon.jpg (884x574, 78K)

I ended up making my own range replacement when I needed something like that:
def crange(init, cond, step):
i = init
while cond(i):
yield i
i = step(i)

for i in crange(1000, lambda x: x < 100000000, lambda x: x*10)
...

I'd use a generator comprehension:
for i in (10**x for x in range(3, 8)):

Use range inside whatever Python's base 10 log function is

in python, "for" iterates over any iterable object until it hits a StopIteration exception.

You can create a generator function which is iterable

def my_gen():
n = 1000
while(n < 100000000):
yield n
n *= 10

for n in my_gen():
print(n)

thanks lads

I'm writing a server program that communicates with clients via TCP sockets.
Is there a simple way of testing possible failure modes of clients? I want to see how the program holds up against inconsistent connections or abusive clients without yanking the Ethernet cable or anything similarly barbaric.

Attached: F2676491-01.jpg (429x444, 12K)

Most operating systems will have a way to simulate bad network conditions.
Also, you should try fuzzing your program.

most like hasklel amirite?

In the following posts there will be code which is from Freifunk Radio's github page. It takes some GPS inputs, then calculates a fresnel zone, and generates all of the GPS points you would need to render it as a 3D polygon in Google Earth. Can someone port it from PHP to Java?

1 of 2.


function makeFresnelPolygons($from, $to, $freq, $steps_in_circles) {

// How many degrees is a meter?
$lat_meter = 1 / ( CIRCUMFERENCE_OF_EARTH / 360 );
$lon_meter = (1 / cos(deg2rad($from['lat']))) * $lat_meter;

$distance = distance($from, $to);
$bearing = bearing($from, $to);
$wavelen = SPEED_OF_LIGHT / $freq; // Speed of light


// $steps_in_path is an array of values between 0 (at $from) and 1 (at $to)
// These are the distances where new polygons are started to show elipse

// First we do that at some fixed fractions of path
$steps_in_path = array(0,0.25,0.4);

// Then we add some steps set in meters because that looks better at
// the ends of the beam
foreach (array(0.3,1,2,4,7,10,20,40,70,100) as $meters) {
// calculate fraction of path
$steps_in_path[] = $meters / $distance;
}

// Add the reverse of these steps on other side of beam
$temp = $steps_in_path;
foreach ($temp as $step) {
$steps_in_path[] = 1 - $step;
}

// Sort and remove duplicates
sort($steps_in_path, SORT_NUMERIC);
$steps_in_path = array_unique($steps_in_path);

// Fill array $rings with arrays that each hold a ring of points surrounding the beam
foreach ($steps_in_path as $step) {

$centerpoint['lat'] = $from['lat'] + ( ($to['lat'] - $from['lat']) * $step );
$centerpoint['lon'] = $from['lon'] + ( ($to['lon'] - $from['lon']) * $step );
$centerpoint['alt'] = $from['alt'] + ( ($to['alt'] - $from['alt']) * $step );

2 of 2


// Fresnel radius calculation
$d1 = $distance * $step;
$d2 = $distance - $d1;
$radius = sqrt( ($wavelen * $d1 * $d2) / $distance );

// Bearing of line perpendicular to bearing of line of sight.
$ring_bearing = $bearing + 90 % 360;

unset ($ring); // clear rings

for ($n=0; $n

easymode: just give me some tips and advice on how to store the new points in the arrays in the same way they are doing in the PHP code.

I have spent the past 48 hours straight working on this, and almost have the java port working. problem is i'm outputting the same values for each polygon (which is an ArrayList of Polygon objects, and polygons are made of PolygonPoint objects). It's coming out in the wrong order, and also you'll notice they're all the same value.

[Polygon{
point1='138.845472,-34.504806,179.0 ',
point2='138.845472,-34.504806,179.0 ',
point3='179.0,138.845472,-34.504806 ',
point4='179.0,138.845472,-34.504806 ',
point5='138.845472,-34.504806,179.0 '},

Polygon{
point1='179.0,138.845472,-34.504806 ',
point2='179.0,138.845472,-34.504806 ',
point3='-34.504806,179.0,138.845472 ',
point4='-34.504806,179.0,138.845472 ',
point5='179.0,138.845472,-34.504806 '},

Polygon{
point1='-34.504806,179.0,138.845472 ',
point2='-34.504806,179.0,138.845472 ',
point3='138.845472,-34.504806,179.0 ',
point4='138.845472,-34.504806,179.0 ',
point5='-34.504806,179.0,138.845472 '},

Polygon{
point1='138.845472,-34.504806,179.0 ',
point2='138.845472,-34.504806,179.0 ',
point3='179.0,138.845472,-34.504806 ',
point4='179.0,138.845472,-34.504806 ',
point5='138.845472,-34.504806,179.0 '},

Attached: linux command sheet.png (1280x800, 325K)

>I have an algorithm that's about 1000x faster than the state of the art for a particular task.
>simple linear improvement

No because the ordering can sometimes be meaningful — for example, structs that shadow a byte buffer — so there's no safe, general way to reorder members. On higher-than-base optimization levels all bets are off though.

>{ a, ++a, ++a }
You're using the pre-increment operator. a is incremented twice before the constructor is called. Use a++ to return the original value after increment, which will give 15,16,17.

i got my json strucks into the template, but how do i get this into the template? When writing localhost:8080 this one comes up outside the rest

Attached: idkimstupid.png (545x149, 8K)

I have been using go at work for 10 months and still find it comfy and breddy noice. It's not perfect at all but I like it. What does dpt think of it?

It's shit and you have shit taste
desu

Attached: 1462333020059.png (554x463, 389K)

excuse me, but why are you using elseif? you could just go with else, unless I'm missingo ut on something here

missing out on something*

Both Go and you are equally retarded. No wonder you go along so nice.

Why is lisp a jew?

Attached: coincidence-lisp.png (466x225, 27K)

lisp "sex-prs" are directly linked to feminism and the sexual revolution
it's a fact, google it

I made Pong in WPF and it runs like ass. Where do I find original Pong code to copy/emulate/steal? Will it work on modern monitors?

Attached: Pong.png (750x450, 30K)

Guide on how to quickly draw things in wpf:
1)Get a window handle
2)Draw on it with dirextx/opengl/gdi whatever

What should we take it to mean when we say that we've learned a particular algorithm or data structure? E.g., I'm taking a course on Introduction to Algorithms. What does it mean to say that "I know merge sort / quick sort / red-black trees" ? Should I be able to sit down and in short order reproduce such an algorithm? Or rather just that I'm familiar at a higher level with how the algorithms work, their time/space complexity, their applications, etc?

How does one create a programming language?

You should be able to understand how they work. Given enough time, you should be able to derive a particular implementation of them if you don't already have it memorized.

The second is more important and also gives you the knowledge necessary to write one yourself. Anyone can copy-paste and doing it from memory doesn't make it any more useful. You need to know the when, why and how to be of actual value to a company.

fuck you

You design one, like this: dangermouse.net/esoteric/ook.html
Then you write a compiler for it to make it usable. The compiler can be written in any language.

Who /nim/ here?

what sort of language do you want to create?
try writing an interpreter for the lambda calculus
start with just printing and reduction, then parsing, then maybe a REPL
I recommend Haskell, it's really good for writing interpreters

I have 2 bytes FF FF (in bit and not in hex) and I want to transform them into a signed short (-> -1).
I use:
short byteToShort(std::ifstream& file) {
char c1 = (file >> c1, c1);
char c2 = (file >> c2, c2);
return int(c2

Attached: 1525537190034.jpg (624x351, 65K)

>tfw no gtk API documentation yet

Attached: index.png (210x240, 5K)

Your int is 32 bits, and your cast doesn't sign extend. Include stdint.h and cast to int16_t

ok found the mistake. it was just me being retarded

You didn't account for endianness user!

>gtk

Attached: 797d85010dffd9e9362f6a01894bdede.png (473x488, 188K)

>anything but gtk
enjoy your web app / qt sepples shit

I have two problems with my program, not sure why. First is that it has a segfault at the end of the program, for some reason it goes back to the top of the main when it hits return 0, no idea why the fuck it's doing that. Second when I put std::cout, the compiler says I cout isn't a part of std.

#include
#include
#include
#include "game.h"
#include "mancala.h"
using namespace main_savitch_14;

int main ()
{
mancala m1;
m1.display_status();

return 0;
std::cout

>random actually returned 0.00000000
holy shit that was an annoying bug to find that kept messing up my weighted choice

this has to be bait

Attached: sweetie.jpg (680x680, 66K)

Please tell me it's something ridiculously simple that is easy to fix, I can't take this anymore.

Sounds like you want sublime or atom with an integrated terminal + pyenv

check out a hello world in c++

nice blog basedboy

Goddamit I'm retarded, never mind about the cout. Fuck me. Okay, why is this thing looping back to the beginning of the

why the fuck did (S O Y B O Y) auto correct to basedboy, the fuck nigger

main?

as for that, the issue has to be in mancala (more specifically in display_status) because your main is completely fine

because I am that based c:

Attached: 2afeb7ef7f8f267a2bd84169d5b1c5a2cadf378579b5a33a33a4452a84f806e4.png (694x1050, 483K)

It gets out of the dislplay_status just fine though, see?

Attached: Screenshot (41).png (1920x1080, 42K)

idk what you're doing in there but main is 100% not causing it to print a million times
usually it's runaway recursive calls or loops that do this so check for something like that?

>calls people "basedboys"
>post from a smartphone

the nerve of these autists

Is there a simple way do weighted shuffling in c++.

there is std::discrete_distribution which can do an kind of random I want.

How can I do something like
std::shuffle(std::begin(a), std::end(a), generator(std::discrete_distribution));

And even if it was in the mancala.cc, I've made it as rock stupid as I possible could, it's just two loops in each other.
void mancala::display_status()const
{
//Top Border
for(int j = 0; j

You didn't include , so you can't use std::cout. Also, what are those "mancala.h" and "game.h" files? If you want us to debug your code, provide the full source.

>no Objective C

>no Forth

Okay, can do.

pastebin.com/t1tUnRgE

>int data[];
C-style arrays in C++ are fixed-size, you have to actually specify it like this:
int data[14];
Your definition is ill-formed and it shouldn't even compile. See: stackoverflow.com/questions/4851234/difference-between-int-and-int-in-c . But I suppose your compiler is permissive and treats it as a pointer. It's not initialized, so it could have any value. When you access the indexes of data you're actually writing to memory god-knows-where.

if(i==0 || 7)

Isn't this always true?

Why do you think it would be?

Yes, he probably meant:
if(i == 0 || i == 7)

yup

even mathematically you would have typed i in {0,7}

Crap. I'll fix that, thanks for pointing it out.

Also, while I'm here is there anyway to get those escape codes to actually print colors on windows command line?

Because == has higher precedence than ||, so it's equivalent to
if((i == 0) || 7)
Any non-zero value, including 7, is true in C++. So this always evaluates to true. On a side note, even if the order of evaluation was:
if(i == (0 || 7))
it wouldn't work because || can only return true or false.

I think ANSI escape codes work on Windows 10 console. You'll have to use conio.h otherwise. Or better yet, use a library that abstracts over native interfaces and works both on UNIX and Windows.

Okay, cool, thanks a bunch.

hello everyone,

i want to convert a string to a byte array, the string has delimiters so it should be split at every delimiters position. also i need to add 0x to the array
String mystring = "ab:cd:ef:gh";
for (int i = 0; i < sizeof(mystring); i++) {
??magic happens??
}

bytearray = {0xAB, 0xCD, 0xEF, 0xGH}


someone here that can help me out?

What language is this supposed to be?

can one of you faggots please explain how a bash fork bomb works to me? (Pic Related)

So the function is declared and called.

Then the function recursively calls itself ONCE. When it returns (it never does) it will pipe its output to the second function call. So my question is because the first function call never returns, how the fuck does the second get called?

Attached: 1523781771624.png (3200x1800, 55K)

Does /dpt/ have a recommended anime list?

Lain

Pycharm

fuck I love Elixir so much sorry if I am gay

>Then the function recursively calls itself ONCE. When it returns (it never does) it will pipe its output to the second function call. So my question is because the first function call never returns, how the fuck does the second get called?
Functions in Bash don't work like this. Both on them are launched concurrently and input from the first is fed to the other as soon as OS deems that there's enough of it (depends on buffering, etc.). It works like a normal pipeline. Try to think of them as commands instead of functions. tee doesn't wait until the command that feeds to it finishes executing, does it?

Yes, actually. I watched the top one from that list and it was really good. I can't remember the name, but it's about a young user who enabled a filter to hide all posts with the word "anime" in them from all /dpt/ threads and lived happily ever after.
god i hate this fucking thread.

Attached: 1501261486937.png (1440x1080, 1.44M)

Sounds like you could have taken a life lesson from that anime.

No, I love getting butthurt about words I don't like and I love showing my sore ass to everyone even more! Just. look at my glorious sore ass!

What do I read that will teach me how to program and problem solve through computation and not "how to java"?