/dpt/ - Daily Programming Thread

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

First for C++

Working on ur mom

Not too sure what I should be working on. I suddenly traded my free time for a job and classes.

first for PHP is C for the web

>combine_images
This must be your house then, user? I love it, great work.

contemplating my miserable existence.

for /F "tokens=1,2,3 delims=:" %%a in ('echo 12:34:56') do (
set /a s="%%a*3600 + %%b*60 + %%c"
echo %s%
)

if you really need to use batch

Anyone here experienced with MATLAB and image processing? I'm encountering some issues with what seems like a basic problem

i = 256x256 image
h = 3x3 filter
i_h = 258x258 filtered image

Now, given i_h and h, I want to numerically recover i. To do this seems simple enough, just divide the ffts, but I'm running into an issue.

First I got the fft of both
i_h_fft = fft2(i_h);
h_fft = fft2(h, 258, 258);

I then fixed a zero at (1,1) in h_fft by making it eps + eps*i.

Then to recover the image
i_orig = ifft2(i_h_fft ./ h_fft, 256, 256)

This truncation is fucking me up though, I end up with a massive complex expression that resembles the original image but isn't there.

Any ideas?

This reminds me of that one D screenshot that has its fizzbuzz logic in strings.
Why do languages do this? If the interpreting of the string is part of the compiler, why not just have it not be a string? Is this just so you can pass around arbitrary code? Aren't there better ways to do that? I don't know a lisp but isn't that kinda what ' does?

you won't find taylor

doesnt work

Writing a method of saving world data to disk for my minecraft clone. Just a very small bit left. Then I have to write a way to read it.

Nice paren colors.

what language is this

are you writing a Minecraft clone in Haskell, how are you doing the graphics?

you obviously have to replace the %% with % if you're using it directly in the command line, and not from a batch file, if you haven't done that

lots of parens means a lisp dialect. maybe Scheme

im running it from a .bat and it's not printing anything for %s%.

Is that hime?

Bingo

Sweet jesus not Haskell.

Right now it's mostly C and some Scheme. I'm writing the low level engine bits in C. I'm using SDL and OpenGL for graphics.

You can tell which procedures are written in C by whether the procedures use _'s.

So the best way to become good at programming is to practice obviously, but you would do this by completing harder and harder projects as you learn right?

What is your Topcoder rating Sup Forums?

I just broke 1800

huh, I'm looking for a project to do this summer and was considering some sort of game, though I'm a pussy so I'll do it in C++

I program in Ruby only

Generally, yes.
The hardest part is learning to compose code freely instead of sitting there for 10 minutes getting a headache because you're not used to thinking like a dumb computer.

I learned to get over it by doing all the challenges on codeeval, until they broke their C evaluator and now they won't let me overwrite the test input file before running the program anymore.

solved it
@ECHO OFF
echo echo Current File: "%~n1%~x1"

echo Start Time(HH:MM:SS)
set /p start=

echo End Time(HH:MM:SS)
set /p end=

>output.tmp (
echo %start% | sed s/:/*60+/g | bc
echo %end% | sed s/:/*60+/g | bc
)

why is recursion taught in schools when its not that efficient?

it's useful for algorithms operating on tree structures.
how is it inefficient?

It's not inefficient.

>keeping a server next to a heater
oh shit nigger what are you doing?!

-O2 optimization exists.

I am reading in this book that generally iterative functions are more efficient. The reason the book gave was that the function calls require a big overhead on most platforms. I just find it weird reading this when most of the time the professors taught me iterative then recursive functions.

I am just trying to study for coding exams and trying to learn stuff that I am not taught in the classroom. I guess I am just still looking at very simple programs that should not require complex calculations

it's useful in some cases like tree traversals and modifying trees. It's also useful as some people think better around recursion compared to iteration for some reason.

and recursion is only really fucking bad when it's a huge recursive loop which creates a fuck ton of stack calls.

Small tail recursion with -O2 optimization is condensed into iteration.

Iteration is more efficient only if you do cache optimization. Otherwise the time spent doing that function call is negligable as you'll be waiting on data to come in from memory.

That book is wrong. Iteration is 100% equivalent to recursion when optimized properly. For a given loop/recurrence, the work you do in an iteration is the exact same that you would do in a recursive call. The issue is that compilers aren't always great at optimizing recursion (which "by default" allocates a new stack frame), whereas with iteration everything is explicit and so the compiler has no say in it. Most of the time, a recurrence is easier to write then the equivalent loop, though, so if you have an optimizing compiler you should prefer it.

What makes you think this is impossible with pure batch?
@echo off
echo Start Time(HH:MM:SS)
set /p startTime=

echo End Time(HH:MM:SS)
set /p endTime=

for /F "tokens=1,2,3 delims=:" %%a in ('echo %startTime%') do set /a startSec="%%a*3600 + %%b*60 + %%c"
for /F "tokens=1,2,3 delims=:" %%a in ('echo %endTime%') do set /a endSec="%%a*3600 + %%b*60 + %%c"

set /a totalSec="%endSec%-%startSec%"
echo %totalSec%

Also, recursion in principle doesn't have to involve mutation (it will when compiled, of course), so it allows you to write pure code which is easier to reason about.

I keep running into the same error with that method

>HH:MM:SS
>1:00
>1:30

LOL

I just assumed it worked without needing 00:01:00.

my way works with just inputting 1:00 as 1 minute.

thanks for the help though

Rust or Sepples, anons?

For what?

an openGL IDE

You mean for OpenGL programming? Glium seems okay, and I'd choose Rust over C++ in general any day.

Writing an irc bot.
Not sure how to parse stuff.

int loop(bot_t *bot)
{
int k = 0;
char buf[513], (*message)[513] = malloc(513 * sizeof(char*));
char pong[64] = "PONG :";
const char *pass = "PASS bot1234\r\n";
const char *nick = "NICK mybot\r\n";
const char *user = "USER mybot 0 0 :mybot\r\n";

send(bot->sfd, pass, strlen(pass), 0);
send(bot->sfd, nick, strlen(nick), 0);
send(bot->sfd, user, strlen(user), 0);

int len = recv(boogiepop->sfd, buf, 512, 0);

for (int i = 0; len != 0; ++i)
{

for (int j = 0; j < 512; ++j)
if (buf[j] == '\r' && buf[j + 1] == '\n')
{
strncpy(message[k], buf, j + 1);
message[k][j + 2] = '\0';
printf("%s\n", message[k]);
++k;

if (k >= 512)
message = realloc(message, sizeof(message) + 513 * sizeof(char));
}
len = recv(bot->sfd, buf, 512, 0);
}

free(message);
return 0;
}


In this code I expect that message contains k separate lines of text which together makeup the bulk of data received hitherto.

But it mocks me.

It's late and I keep getting a seg fault when I run this. I feel like I'm fucking up something obvious. Pls help
#include
#include

struct node {
int data;
struct node *next;
};

struct node *makeNode(int data, struct node *n) {
if(n == NULL) {
n = (struct node *) malloc(sizeof(struct node));
n->data = data;
n->next = NULL;
}
else
n->next = makeNode(data, n->next);
return n;
}

int main() {
struct node *root;//, *a, *b, *c;

root = makeNode(5, root);

return 0;
}

I meant to put
int len = recv(bot->sfd, buf, 512, 0); on line 14.

You're using and comparing an uninitialized value.

compiled fine on arch no segfault user

may I ask what exactly you are trying to do their tho it's a pretty retarded way to do a linked list.

You need a list struct that holds the "head" node pointer and the depth of the list.
You need to initialize the head node with a pointer to NULL if you want your little makeNode function to actually work.

>applying for positions in software engineering or data engineer/scientist
>lots of entry level positions
>mfw so god damn many require 1-2 years of software work experience

I don't understand this shit how is it entry level if it still has work experience required?

The first thing you do in makeNode() is test if n == NULL, but root has not yet been initialized when you pass it in for n.
So struct node *root = NULL.
Not sure if that's the cause of the seg though.

Why are people still trying to use Batch when Powershell exists?

Seriously, if you wanted to convert a string in the format of HH:MM:SS to just seconds, it looks a lot cleaner in Powershell:

function convert_timestamp([String] $time)
{
$ary = $time.split(":")
$seconds = [Convert]::ToInt32($ary[2])
$seconds += [Convert]::ToInt32($ary[1]) * 60
$seconds += [Convert]::ToInt32($ary[0]) * 3600
$seconds
}

I mean granted, it's slightly more verbose, but is is insanely more intuitive. And this is available on every single Windows system since Windows 7 IIRC. (It might be in Vista, not sure, I don't know anyone who uses Vista).

not to mention, now I haven't looked to far into powershell but, the batch interpreter is terrible. It parses line by line (even parsing through comments) and there are cases where comments are parsed into the program!

Do not use cmd, ever. Not when POSH (and now BASH) exist as upgrades.

Using cmd.exe is like those old school unix guys you see who still use plain vi even though vim has been out forever and isn't as annoying or featurless.

the segment fault may be caused by this line:

n->next = makeNode(data, n->next);

since when you pass root it isn't initialized to NULL it could just jump to the else statement at which point it tries to access an unitialized struct leading to the segment fault.

*root = NULL;

will fix the problem.

fuck off, writing software is free. That's why there are so many pajeets who get sw jobs.

>electrical engineering positions 2-3 years experience minimum
>small scale interesting electrical projects are at least $50

Yup, this is what the problem was. Could have sworn that structs were automatically initialized to NULL if they were simply declared. Thanks senpai

>may I ask what exactly you are trying to do their tho it's a pretty retarded way to do a linked list.
lol yeah I haven't fucked with basic data structures in like two years, so I'm refreshing memory. I've also never implemented any in C so I'm getting acquainted with that. I realize the implementation is dumb, I was just trying to bang something out real quick.

>fuck off, writing software is free.

pajeet please I actually worked hard for a degree

just apply for it anyway

ok well I was just checking, I would try to write that linked list using a for loop first instead of starting with recursion to avoid problems like this

nice waste of money shit degree, and nothing to show for it.

btw after the malloc you need to check if the pointer has a value. Malloc can return NULL if your system can't return any memory from the heap.

so a simple if(!pointer){pritnf("out of memory"); return -1;}

should work to prevent a failed malloc from fucking your system up

Recursion is much sexier though

Yeah I was just typing up something quick and dirty without necessarily abiding by conventions

yeah I agree, but also it can be unwise in some situations.

to fuck over people without connections.

aka social retards

natural selection automatically filters out people who cannot even talk to someone face to face

its an unnecessary barrier thats fucks over far more people then those types.

I have multiple references from professors and 1 from my boss who I developed a website for.

I just lack work experience in shit other than class work and PHP.

just be a female, POC (no asians), or other surface-level minority and you can skip the line!

>what are you working on Sup Forums

My employer has tasked me with shilling Sup Forums with anti-Trump pro-Bernie stuff, and pro Hillary upvoting on r/politics.

Aside from that I'm meant to gain positive replies for Windows 10 threads in Sup Forums, and as much as possible keep threads that are positive for Windows 10 active for as long as possible. I have to log everything I do and submit it every four hours.

I hate my life

i'm curious about this apparent market for shilling. is there a site describing and brokering this work, or are you just making all this shit up?

It's to discourage people who don't think they can take the job. You apply for it and assert in a cover letter that you ARE material for the position. Don't be a pussy.

Hey guys r8 my code

public int findWinner(int userMove, int compMove){
if(userMove==ROCK&&compMove==PAPER||userMove==PAPER&&compMove==SCISSORS||userMove==SCISSORS&&compMove==ROCK){
this.CWins++;
return COMP_WINS;
}else if(compMove==ROCK&&userMove==PAPER||compMove==PAPER&&userMove==SCISSORS||compMove==SCISSORS&&userMove==ROCK){
this.UWins++;
return USER_WINS;
}
return TIE;
}

are cover letters still a necessity? I talked to some managers and they said they don't even look at them anymore and focus on the resume and interviews.

beautiful.

>focus on the resume
Let me translate that for you: look at the cover letter

>mfw I applied for jobs without a cover letter

OH FUCK

not him, but i've gone through resumes and done interviews a few times.

cover letters are useful if you don't match the profile they claim they're looking for. it's basically
>here's my resume oh here's this short explanation for why i'm applying even though on paper i look like a shitty candidate

it's not guaranteed to work, but it's guaranteed to work better than just submitting your resume without any explanation for why such a mis-match applied to the job in the first place.

what the fuck is a cover letter?
you have to write an essay along with your damn cv?

honestly if you're asking and not willing or able to look this shit up (e.g. googling your first line, pic related) then don't worry about it. it only makes a difference in marginal cases

also
>write an essay
google image search. should give you a sense for how long it should be. they're thinking about spending a lot of money to have you in the same workspace as them 5 days a week; everyone who's been in hiring wants as much signal to work with as possible.

Here's the trick. You need to show that you aren't afraid to take initiative and play by your own rules, but you also know your place and are humble. If you're having trouble finding a job, try cold emailing a cover letter (make it bomb as hell) and your resume to a hiring manager. Even if you're not super outgoing and self-assured the worst that can come out of this is that you send your information to someone who never reads it. The best is that you get a job, but oftentimes there lies compromise in having your documents passed to a different hiring manager by the one you spoke to. You got nothing to loseā€”carpe diem my boy.

>implying they don't redirect unsolicited resumes to /dev/null

Chances are if you get to the manager's internal email it's not gonna have any fluff protecting it. Think about those types of people, now. And to reiterate: what did you lose? Not much.

I have 20min

Can i use a scanner to scan what button the user presses instead of using if, dont ask why just help me find another way instead of if

int r;
if (JOptionPane.showConfirmDialog(null, "Do you want to take a risk?") == 0) {
r = Integer.parseInt(JOptionPane.showInputDialog("How much?"));
}

do you get penalties for spilling the beans in dpt?

I come up with shit tons of ideas when I'm swamped with schoolwork.

And then I'm dead for ideas when the summer starts and I have time to actually implement them.

You think he's serious?

Unification algorithm for Haskell
data Ty
= VarTy String
| ConTy String [Ty]
deriving(Show,Eq)

type Subst = [(String, Ty)]
type SubstResult = Either String Subst

substFail :: String -> SubstResult
substFail = Right

apply :: Subst -> Ty -> Ty
apply [] t = t
apply ((x1,t1):rest) (t@(VarTy x)) =
if x == x1 then
rest `apply` t1
else
rest `apply` t
apply s (ConTy c ts) =
ConTy c (map (s `apply`) ts)

unify :: Ty -> Ty -> SubstResult
unify (ConTy c1 xs) (ConTy c2 ys) =
if (c1 /= c2) then
substFail $ "Incompatible types: " ++ c1 ++ " and " ++ c2
else
foldM (uncurry . foldUnify) [] (zip xs ys)
where
foldUnify s t1 t2 = do
s'

Learning how to do automated smart contract testing. Protip: TestRPC is buggy, use geth instead as an RPC provider (even though you lose those sweet, sweet instamined blocks).

Also how to use MathJax.

Applied to an add through a Google add asking for data entry, work from home stuff. Ended up being shilling. While I can't tell you the company name a simple google search will show you how prevelant these companies are.

tldr
what is this supposed to do

you tell it to unify the type
a -> a
with the type
b -> Int
and it gives you a result saying to assign the 'a' and 'b' type variables to the Int type.
if you'd done
a -> a
and
Int -> Bool
it would give you an error because it wants either Int -> Int or Bool -> Bool

It's one of the central algorithms in what's called "hindley-milner type inference" which is really cool and not very many languages support a type system capable of it very well but the ones that do let the compiler decide the types for a variety of programs where you don't specify the types, while still checking to make sure they're valid.
it's p. cool. the algorithm works something like this:

we have some code that we want to know what the resulting type is. our code is
x + 1
since we have yet to figure out the type, for now we give it a "type variable", we will name this one 'a'. we say that
x + 1 :: a
meaning "x + 1 has type 'a'".
now we also don't know what the type of our variable x is either. we will give x a type variable, 'b'.
x :: b
now, thankfully we do know the type of (+), which is a function. it's type is
Int -> Int -> Int
(takes two integers as arguments, returns an integer).
by our hindley-milner algorithm, we create the following type for our "x + 1" code:
b -> Int -> a
because x :: b, 4 :: Int and (x + 1) :: a
we then call our 'unify' routine
b -> Int -> a
Int -> Int -> Int
it succeeds, assigning the Int type to both type variables a and b.
we have no inferred that x must have type Int and "x + 1" must have type Int as well

Please respond.

Text parsing is a complete pain in the ass in C, not worth using C under any circumstance for something like an IRC bot that not only does not need to be performant, but also whose bottleneck is mostly likely network latency, not CPU. You could probably write a 100 LOC Python script that does the same as you'll get in 1000 LOC spread across 5 files in C, without once having to worry about memory leaks or segmentation faults.

and I assume this is a type inference implementation in a custom language?

You could put type inference in any kind of language, preferably functional due to how the algo works. OCaml uses a type inference scheme closest to my code, as the algorithm was originally invented for the ML language. Haskell (what the code was written in) also uses type inference although their algorithm is going to be more complicated in order to handle type constraints, rank-n types, GADTs and all the other extension shenanigans in Haskell.

All the good ones do (Haskell, f#, ocaml, etc)
Only shit tier Scala has a retarded type inference

Writing an AI that plays a hexagonic version of 'dots and boxes' in java. It's only playing itself using opening moves and then minimax towards the end game.

I've finished but i'm scared it will fuck up somewhere as I have no other agents to test it against. Besides a random player and a semi-shit player (which are both far worse)..

Need your advice /dpt/.

I want to get into programming, but I'm looking for a programming language that requires little to none math, any suggestions?

>want to get into programming
>language that requires little to no math
but why

you can learn JavaScript if you wanna fit the hipster numale style I suppose