/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtube.com/watch?v=YQs6IC-vgmo
khronos.org/opengl/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C++/Win)
twitter.com/NSFWRedditVideo

Great, for some reason I the data types aren't compatible
#include
#include
#include
#include

template
class SimpleVector {
private:
size_t length{0}, capacity{0};
std::unique_ptr data{};

SimpleVector(SimpleVector* old, T new_elem) {
length = old->size() + 1;
capacity = old->size() * 2;
data = std::make_unique(capacity);
size_t i{0};
for (; i < length - 1; ++i) {
data.get()[i] = old[i]; // doesn't work
}
data.get()[i] = new_elem;
}

public:
SimpleVector() {}
SimpleVector(std::initializer_list&& ls) {
length = ls.size();

capacity = [ls](const size_t& n) {
// capacity must be bigger than or equal to the length
// if it can't fit the length, it'll try doubling the capacity
size_t cap{2};
while (n < cap) {
cap *= 2;
}
return cap;
}(ls.size());

// now create and copy the vector
data = std::make_unique(capacity);
size_t i{0};
for (auto&& elem : ls) {
data.get()[i] = elem;
i++;
}
}

T& operator[](size_t i) {
// TODO: i sanitization
return data.get()[i];
}

std::unique_ptr& get_data() { return data; }

T size() { return length; }

void push_back(T elem) {
if (length < capacity) {
data.get()[length] = capacity;
length++;
} else {
// okay so the vector is at its maximum capacity
// crate a new vector, with a bigger capacity
// initialize from the current vector, add the given elem

SimpleVector newVec(this, elem);
}
}
};

int main() {
SimpleVector v{51, 57, 15};
std::cout

So apparently there are 2 different languages, Nit and Nim. Nit is pretty alright, and it comes with OpenGL bindings in the std lib. Pascal based too

>Pascal based too
automatic trash

Jesus christ, how do people defend this garbage language?

>Pascal == trash
now this I got to hear. Please explain

Pascal is good

Because it always beats me in code golf

can anyone help with my shell scripting task?

How do I add a lib to my project (c++). I tried linking it in my ide but that broke some stuff.

What about something like putting the lib and header in my solution folder and using
#include "library.h"
#pragma comment(lib, "library.lib")

I want to learn R why does everyone hate on it? What's a good resource

i think there are some free courses in R. you could start at OMGenomics. they have some quick little tutorials

building an api in Go. I wanted to neck myself at first, but now it is starting to grow on me.

It's not too late

On a whim I decided to write a JavaScript module bundler (like webpack or browserify) in Go. So far I've got it successfully compiling a moderately complex react application, in roughly 2% of the time it takes webpack to do the same thing. I'm running babel via a JavaScript interpreter though, which is *by far* the slowest part. I've written a very basic JavaScript parser before, so I might take a crack at implementing the limited transforms from babel that I use in Go.

might be more useful

The type of old is a SimpleVector*. Thus, when you index into it, you get a SimpleVector. (The operator[](...) overload is never found). Try using old->data.get()[i] or old->operator[](i).

I took a different approach but got stuck for some other reason
#include
#include
#include
#include

template
class SimpleVector {
private:
size_t length{0}, capacity{0};
std::unique_ptr data{};

public:
SimpleVector() {}
SimpleVector(std::initializer_list&& ls) {
length = ls.size();

capacity = [](const size_t& n) {
// capacity must be bigger than or equal to the length
// if it can't fit the length, it'll try doubling the capacity
size_t cap{2};
while (n < cap) {
cap *= 2;
}
return cap;
}(ls.size());

// now create and copy the vector
data = std::make_unique(capacity);
size_t i{0};
for (auto&& elem : ls) {
data.get()[i] = elem;
i++;
}
}
size_t get_capacity() { return capacity; }

T& operator[](size_t i) { return data.get()[i]; }

T& at(size_t i) {
// TODO: i sanitization
return data.get()[i];
}

T size() { return length; }

void push_back(T elem) {
if (length < capacity) {
data.get()[length] = capacity;
length++;
} else {
// okay so the vector is at its maximum capacity
// crate a new vector, with a bigger(x2) capacity
// copy all the elements and make this point to the new vector

++length;
capacity = 2 * length;
auto new_data = std::make_unique(capacity);
size_t i;
for (i = 0; i < length - 1; ++i) {
new_data.get()[i] = data.get()[i];
}
new_data.get()[i] = elem;
&data = &new_data; // NOT ASSIGNABLE
}
}
};

int main() {
SimpleVector v{51, 57, 15};
std::cout

apparently no requests for homework. all sci does is mental masturbation. but ill give it a shot.

Does it have to be a shell script? I don't understand genetics but if you can explain what the input and what the output is, and how the data might be processed I might try

This code is better. (Your old code had a subtle bug since old was also this, so you overwrote your data pointer in the constructor with the error). Anyways, this line
&data = &new_data;

doesn't make any sense. &data is an rvalue (it's like the result of 1 + 1). Assigning a value to it doesn't make any sense.
Try
data = std::move(new_data);

(unique_ptr deletes its copy constructor since that would defeat its purpose).

the input is a code for a mammalian gene on the website uniprot. its a massive database of genetic data/sequences. this data is compared against other genetic data (multiple sequence alignemt). the results are made into a family tree. where the genes that are most similar to one another are closely related (e.g. a human related to a chimp, follwed closely by a goilla and an orangutang).

Ah, thanks that worked

Why are americans and canadians shitty at programming?

I wish I had a reason to use golang or Ocaml. Would be really fun to learn. I feel like I've best learned a language through employment

Does anyone have a link to the presentation explaining why C++ stl maps suck so badly?

I've been teaching myself HTML/CSS/JavaScript over the last month or so. Someone posted a list of beginner programming challenges here and I've just finished working through all of them with JavaScript. Now this might sound like a dumb question so pls no bully but what should I study in order to display database info on a web page? Is node.js better than PHP?

>>>/wdg/

Writing object oriented matlab code. Has polymorphism and everything.

How do /dpt/ use linked list in C ?
Do you make new functions for each type, do you use generic linked lists or do you do something else?

I don't use C, I use C++ with a modest sprinkling of templates.

>C
>Generics

>matlab
pig disgusting

youtube.com/watch?v=YQs6IC-vgmo

Best side for coding challenges?

dude void* lmao

There's no good options.

software fag is mad because his brain is too small and weak for real engineering languages

Can I get a little opengl help. Trying to follow
khronos.org/opengl/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C++/Win)
And Im stuck at the beginning. Compiler is saying CDC is an unidentified type.

not right side

The stereotype is the other way around, among pretty much everyone I know

Except it extends to most European countries as well

Get your shitty cuck software out of here.

>mathematical computing language that doesn't inline function calls
>function calls are very expensive
>tells people to use arrayfun anyway
>doesn't have a garbage collector but their alternative is total shit
>anonymous functions leak their entire surrounding workspace
>1-indexed matrices
>god-awful syntax
>proprietary and more expensive than your OS

just use numpy

few more

>anything but vectorized operations is unusably slow
>no such thing as pass by reference, you have to make "handle" classes which are basically retarded pointers to your matrices
>syntax errors are shit like "Expression or statement is incorrect"
>did I mention the fucking syntax
>no real module system, can't expose more than one function per file
>baits students with less expensive temporary college licenses just to trap them for the rest of their math career with triple the price

>come across cellular automata and game of life
>try to make it in lua
>Only managed to make the grids
>no fucking idea what to do next
I'm shit with tables and all that stuff. Apparently there are a lot of cellular automata made with lua already so I looked at one of the code and then it made some sense but not a whole lot.
I'm just too fucking dumb for programming.

comonads

simple codecademy exercise
not returning anything to the log, not even an error

const getSleepHours=(day)=>{
switch(day){
case 'monday':
return 8
case 'tuesday':
return 8
case 'wednesday':
return 8
case 'thursday':
return 8
case 'friday':
return 8
case 'saturday':
return 8
case 'sunday':
return 8
}//switch
}//function
const getActualSleepHours=()=>{
return getSleepHours('monday')+
getSleepHours('tuesday')+
getSleepHours('wednesday')+
getSleepHours('thursday')+
getSleepHours('friday')+
getSleepHours('saturday')+
getSleepHours('sunday');

}//function
const getIdealSleepHours=()=>{
let idealHours = 7;
return idealHours * 7;
}//function
const calculateSleepDebt=()=>{
let actualSleepHours=getActualSleepHours();
let idealSleepHours=getIdealSleepHours();
if (actualSleepHours===idealSleepHours) {
console.log('you did well');
}//if

if (actualSleepHours < idealSleepHours) {
console.log('you dun goofed son');
}//if
}//function


calculateSleepDebt();

pls give advice

what language is this?

javscript

shitscript

You have a condition printing for === and . You can see by doing the math you're getting 8 when it wants 7 per day, which is the > case.

const getSleepHours= day =>{
switch(day){
case 'monday':
return 8
case 'tuesday':
return 8
case 'wednesday':
return 8
case 'thursday':
return 8
case 'friday':
return 8
case 'saturday':
return 8
case 'sunday':
return 8
}//switch
}//function
const getActualSleepHours=()=>{
return getSleepHours('monday')+
getSleepHours('tuesday')+
getSleepHours('wednesday')+
getSleepHours('thursday')+
getSleepHours('friday')+
getSleepHours('saturday')+
getSleepHours('sunday');

}//function
const getIdealSleepHours=()=>{
let idealHours = 7;
return idealHours * 7;
}//function
const calculateSleepDebt=()=>{
let actualSleepHours=getActualSleepHours();
let idealSleepHours=getIdealSleepHours();
if (actualSleepHours===idealSleepHours) {
console.log('you did well');
}//if

if (actualSleepHours < idealSleepHours) {
console.log('you dun goofed son');
}//if
if (actualSleepHours > idealSleepHours){
console.log('LAZY FUCK');
}
}//function


calculateSleepDebt();


yep

is trolling, I just wrote another one to try Lua again after all these years. See if you can make sense of it maybe

mkBoard = function(M,N)
local b = {}
for i=1,N do
b[i] = {}
for j=1,M do
b[i][j] = false
end
end
return b
end

printBoard = function(b)
for i=1, #b do
local c = {}
for j=1, #b[i] do
c[j] = b[i][j] and '#' or '.'
end
print(table.concat(c))
end
end

putGlider = function(b)
b[1][3] = true
b[2][4] = true
b[3][4] = true
b[3][3] = true
b[3][2] = true
end
neighbors = function(b, i, j)
local n = 0

for dx = -1, 1 do
for dy = -1, 1 do
bad = dx==0 and dy==0
bad = bad or i+dy#b
bad = bad or j+dx#b[i+dy]
if not bad and b[i+dy][j+dx] then
n = n + 1
end
end
end
return n
end
step = function(b)
local s = {}
for i=1, #b do
s[i] = {}
for j=1, #b[i] do
local ns = neighbors(b, i, j)
s[i][j] = ns==3 or b[i][j] and ns==2
end
end
return s
end
board = mkBoard(10,5)
putGlider(board)
printBoard(board)
for i=1, 5 do
board = step(board)
print(i)
printBoard(board)
end

Ask me whatever questions you want. The implementation would be a lot smaller and simpler if lua had a basic standard library of table processing/functional style operations...

>local ns = neighbors(b, i, j)
>... ns==3 or b[i][j] and ns==2
c o m o n a d s

cokleisli coarrows of moderate misfortune

should've said cofortune

Perhaps. I liked the alliteration in "moderate misfortune"

Hi i'm here to determine if i am a coe monkey or not.

For a computer science assignment we were supposed to program instruction by instruction every single movement of a maze runner instance from a starting point to an end point through a maze (Inefficient i know, but this is an introductory course). To save time and reduce bloating I wrote the following:
import os
import MazeRunner
from MazeRunner import *

mr = MazeRunner("maze1505369241.7894154.csv")

#Automatic navigation. Decided to use multiple functions because
#the original suggested method was too bloated.
#New and improved method:
def mUp(a):
for i in range(a):
mr.moveUp()

def mDn(a):
for i in range(a):
mr.moveDown()

def mRt(a):
for i in range(a):
mr.moveRight()

def mLt(a):
for i in range(a):
mr.moveLeft()

def autoNav():
mRt(6)
mUp(2)
mLt(6)
mUp(4)
mRt(2)
mUp(4)
for i in range(2):
mRt(2)
mDn(2)
mRt(4)
mDn(6)
mRt(6)
mUp(6)
mRt(2)
mUp(4)
for i in range(2):
mLt(2)
mUp(2)
mRt(2)
mUp(2)
print("Maze is finished: ", mr.isFinished())


Please rate it.

>template type parameter deduction fails
>no idea why
I hate C++ sometimes

>data.get()[length] = capacity;
what

rename your function
>mUp
wtf is that
why not
>moveUp

also why not:
def move(direction,step):
# move block in here

what's the scenario? post code

GAY

So, I'm tutoring a kid who wanted help on Java programming, but basically I aint teaching him shit because all he really needed was someone to push him to study.

What can I do to still teach him some usefull skills?
Already started helping him working with git

the best way to learn any language is to use the language.
lay out some basic problems or programs for him to perform.
he could just sit there and think of his own, but thats what you're for.

do this, camel case is horrible

Best Python book?

Learn Python The Hard Way

see

get him started on some projects. you guys can go over what he’s done and look for things to improve. just grab some tasks from course websites

Why don't more languages have language servers? Surely it's much better for the actual compiler to tell an IDE things like the type of an expression, possible autocompletions, etc. than for the IDE to guess?

I'm writing a P2P app in C++
It goes through Tor, every node has its own .onion hidden service address.
Every node uses the same port, so I can't run them all on the same os.

I tried binding them to different ports on localhost, and then pointing the different onion addresses with the same port to the various local ports, but the result is that Tor relays the messages to a random node.

I could use VMs but for quick testing during development this would be such a major pain in the ass
What should I do, Sup Forums? Is there a more convenient solution?

> Why don't more languages have language servers?
Because they aren't popular enough for someone to spend time on implementing one? Besides, is language server even useful outside VSCode?

Create virtual network interfaces. Each has its own network stack, so they can have the same port with different IP addresses.

Look up for dummy interfaces.

How do I get the games method to not return null?

for(int z = 0;z < 16;z++){
games.add(new Game(team.get(x),team.get(y)));
frame.standingsArea.append(team.get(x).getName()+" VS "+ team.get(y).getName()+"\n");
if(games.get(z).result(team.get(x),team.get(y))==0)
frame.standingsArea.append(team.get(x).getName()+" Wins!"+ "\n");
if(games.get(z).result(team.get(x),team.get(y))==1)
frame.standingsArea.append(team.get(y).getName()+" Wins!"+ "\n");
if(games.get(z).result(team.get(x),team.get(y))==3)
frame.standingsArea.append("Tie!"+ "\n");

frame.standingsArea.append("--------------------------------------------"+"\n");
x++;
y--;
}

*/
package game;
import java.util.Random;

public class Game {
int rand1;
int rand2;
Team team1;
Team team2;

Game(Team team1, Team team2){
this.team1 =team1;
this.team2 =team2;

}

public int result(Team team1, Team team2){
Random rand = new Random();
rand1= rand.nextInt(10)+1;
rand2 = rand.nextInt(10)+1;

if(team1.getStr()*rand1 > team2.getStr()*rand2)
return 0;
if(team1.getStr()*rand1 < team2.getStr()*rand2)
return 1;
else
return 2;

}

}

I meant game class and result method

In all seriousness though, some of my coworkers and bosses seem to think matlab is the hottest shit since sliced bread.It would all be python if I had my way.

dumb frogposter

>python
what a retard

Post the full code nigga. This is unreadable gibberish.

Why can't I do I do
n.times do print "repeated string"
instead of
n.times {print "repeated string"
}

in Ruby?

i forgot to add end, sry

Yes, it's useful in emacs, vim, atom, eclipse, intellij, ...

Why aren't you learning Mill assembly yet?

santaclaus.jpg

>meme images

go back to réddit retard

>Why aren't you learning Mill assembly yet?
why would i?

i better things to waste my time

>why would I buy bitcoin lol???
t. in 2009

I'd rather learn Elder Futhark.

>implying i don't have bitcoin already

lmao

Is that how you afford your NEET life? Because if you don't then you clearly didn't buy enough.

Exactly my idea. I'm basically helping him improve the tasks he has to do for school, but he learns best by just programming.
He understands most concepts, I'm just there for free money basically

>implying i'm NEET

bitch you're making a lot of assumptions

What's getStr doing? maybe team2's getStr returnes something non positive?

>bought bitcoin in 2009
>has to work in 2017
cool story

n.times do
print "repeated string"
end

autonav doesn't is a misleading name, call it manualnav instead

What's a good file format for configuration files? rc files don't support arrays and nested data structures. I'm leaning towards JSON for its library support but I'm open to suggestions.

>JSON
enjoy no comments

JSON

XML

TOML

>YAML
>superset of JSON

and it allows comments.

Prof requires that we write all instructions out. No input durring runtime.

I don't see how implementing it the way you suggest would reduce it, as there would still be a need for input, and therefore either user would have to write it all out in shell (which is 1. very inconvenient, and 2. not allowed), or i would have to write more lines of code to call upon the function in another function, in other words i would have to bloat what i already wrote. In both instances i would be doing myself no favors.