/dpt/ - daily programming thread

juhannus editio

vanha:

Other urls found in this thread:

linuxnix.com/linuxunix-shell-ps1-prompt-explained-in-detail/
codefights.com/
cryptopals.com/sets/6/challenges/48
github.com/expeditiousRubyist/Memesnake/blob/master/Makefile
twitter.com/SFWRedditGifs

first for game development with Unity in Javascript

second for game development in malbolge

third for shut the fuck up or I'll rape your sorry asses

third for gdg. what games are you making /g?

Guy on the left has a boner.

i've seen people do this. assigning NULL after freeing the object. is it correct?


int *r;

r = (int*) malloc(sizeof(int) * N);

free(r);

r = NULL; // why this?

you should never cast malloc
and RTFM

Give me a hard algorithmic problem.
I am bored.
I will even do your homework for free if its hard enough.

>why this?
the same reason you cast malloc: cargo-culting

Write a program that parses past /dpt/s and creates a rating system based on negative replies that specific posts get, then when fed a post's content, it will give you a shitpost rating.

Assigning NULL after free is a safety mechanism to keep yourself from accidentally using a pointer you just freed. If you were to later malloc a block that happened to correspond to the same address, the result could be some rather undesirable behavior.

That said, if you know you don't use the pointer afterwards (i.e. you free at the end of a function), there's no point in nulling it.

So currently I have a wget script that downloads a bunch of files. How can I redirect all the files that it downloads to another folder? I'd like to keep the filenames it produces.

-P prefix
--directory-prefix=prefix
Set directory prefix to prefix. The directory prefix is the
directory where all other files and sub-directories will be
saved to, i.e. the top of the retrieval tree. The default
is . (the current directory).

I tried that and it did not work. Now I noticed that I had a typo in the folder name. Thanks user.

Can anyone recommend some resources for learning Mathematica? I'm fairly competent in C, C++, Java, but I have no idea what this shit is.
Like, I just have to write simple stuff that takes the average, does Fibonacci up to a number n, but all the youtube videos I see people just type in "table, graph" and it's all automatic. Like how do I write a function/method?

I'm about halfway through Dive into Python right now, and it's a really good book, but what are some good beginner/intermediary projects to put my skills to the test.

Oh no still doesn't work. This is how it looks like atm:

wget -q -O - $1 | sed "s/>/>\n/g" | grep "eThum" | cut -d ' ' -f 3 | sed -e "s/href=\"/http:/g;s/.$//" | wget -p $1 -q -i -

The small p at the end is actually a P. So that's not the problem.

From my introductory programming class:
>In this problem you will be creating a game that you play against the computer. Make a class named GuessingGame - when executed, this program should randomly generate a secret integer from 1 to 100, and then instruct the user to try to guess what it is. After each guess the program will tell them if they are too high, too low, or if they got it right - and if they got it right it will congratulate them, tell them how many guesses it took them, and offer to either play again or exit
the program.
>Make a program that reads in text file of fractions with the format:
8/4
2/3
4/6
and so on. Then have the program reduce all the fractions, and find how many instances of each fraction there are. Do not print the same fraction to the screen twice.

I don't know, boring stuff like that. You should just program what you think is cool, otherwise I don't think it'll be very fun for you.

>Can't even greentext.
I don't think I'm gonna make it.

Try to create something that you can use to back-up a folder. It has to know which files/folders it should copy, so you don't get duplicates. How you do that is up to you.

projecteuler.

I am screwing around in python and sending files to myself.
What the hell does socket.recv() return when there is no more data to recv()?

>you should never cast malloc

On the contrary, you should always. Malloc returns void pointers, which should be casted.

There is literally no advantage to casting void pointers.
C guarantees that void pointers will be converted to other pointers automatically, and vice versa.

Still looking for ways to mess with arc files. The ones i'm trying to extract keep giving me an error

It's blocking, so it'll just sit there until it either receives something or the connection is closed, in which case it'll return an empty string.

suomi perkele :D

Ok that makes sense.
Thanks

Air traffic monitoring with APL

>see oracle posted a position for students at my university to apply to
>posting made by Thomas Lott, "Diversity Recruiting Programs Manager"
this happens every time

Post the posting

"niggers and koders only"

I want you to post the posting so I can talk to him myself and grill him about it

the job description and such was bog standard if that's what you're asking about

I need you to post it itself so I can apply to it with a bunch of lies and ask him if he like the grape koolaid and fried chicken when he answers. Just need plausible deniability. Also Here's mr Thomas Lott in da fresh

Given a simple linear 2D PDE, return a graph of its characteristic.

don't bully the minorities in tech user

int main(void)
{
printf("Testing the code tag, hope this shit works\n");
return 0;
}

If you free the memory block r points to and later try to access it via r, that'll be an error -- which of course shouldn't be an issue if you know what you're doing... but I guess assigning NULL to r is a way of allowing to at least test, later on, whether r points somewhere or not.

You should only free pointers if you're going to reuse them immediately or at the end of the function.

Also, I already tested this.
Free'd pointers return NULL automatically.

>Free'd pointers return NULL automatically

How? Is free() a language construct thing rather than a normal function? I mean, the pointer sure does return NULL after being free'd, but how does this happen since the pointer is passed by value? Is it not a compiler thing rather than a language standard thing?

I mean "is it a compiler thing", not "is it not".

>Free'd pointers return NULL automatically.
No they don't. Idiot.

what font is that , Scott?

So, when they do, it really is an implementation-dependent thing rather than a part of the language standard, huh.

Terminus.
Also, who gives a shit if you know my first name?

I dunno, all I know is I can allocate an array of linked list pointers as buckets for my hashmap and if the bucket is empty, I simply free the whole bucket and it doesn't screw up because those pointers become NULL pointers.

It really is a nice font, looks like the font used when you login without a GUI.

calm down Scott

That's most likely a compiler "optimization", so to speak, I don't think you should count on that.

can you post your $PS1 please?

I want to be friends with Scott, since my previous friend named Scott moved away. The position is available

Not the quoted user, but what is the $PS1?

A nigger with a non-nigger name. Interesting.

see linuxnix.com/linuxunix-shell-ps1-prompt-explained-in-detail/

its the prompt in the terminal

local sep=$'\xC2\xBB' # UTF-8 U+00BB
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
cyan=$(tput setaf 5)
bold=$(tput bold)
reset=$(tput sgr0)

PS1="\[$green\]\u@\h\[$reset\] \[$blue$bold\]$sep\[$reset\] \[$yellow\]\W\[$reset\] \[$blue$bold\]$sep\[$reset\] \[$green\]\$\[$reset\] "

thanks bruh

Trying to make a function which when the user reaches page 1 and tries to turn the page further, rather than crashing my app (by trying to get page[-1]) it will reset the page number to the last page of the book (i.e. so the pages loop)

This is just a basic version.

let Pages:[String] = ["001", "002", "003"]


Pages[1]

var currentPage:Int = 1


func test() {if currentPage == 0{
var currentPage = 3
} else {
var currentPage2 = currentPage
currentPage = (currentPage2 - 1)

}
}


Is this a valid method of creating a loop of pages?

faggots

FAGGOTS

ew.

codefights.com/

var currentPage = 3
} else {
var currentPage2 = currentPage
currentPage = (currentPage2 - 1)


Replace with:

var currentPage = Pages.count()
} else {
currentPage--;


Alternatively Pages.length or whatever your language calls it, and currentPage = currentPage - 1;

What language is this anyway?

I just noticed currentPage is already declared so

var currentPage = Pages.count();

Should be just

currentPage = Pages.count();

I know your last name too, Scott :^)

I'm so lonely.

#include

int main(int argc, char *argv[])
{
int i = 0;
printf("Content-type:text/plain\n\n");
printf("Hello, you are learning C!!\n");
printf("Number of arguments to the main function: %d\n", argc);
for(i = 0; i < argc; i++)
{
printf("argument number %d is %s\n", i, argv[i]);
}
return 0;
}


Where in manjaro can I run this so it can run from a browser. i.e. here is the public_html/cgi-bin directory in manjaro. in opensuse it's /srv/www/cgi-bin
and in ubuntu it's /usr/lib/cgi-bin

>using the smiley with a carat nose

install lighttpd
add mod_cgi to your lighttpd.conf

Does that man on the left have an erection?

JS in Unity has some cleaner syntax for things like coroutines but I still prefer C#.

And screw people who give "ew"s. Sure there are better 3D engines and maybe Unity encourages some less than great habits for its target demo of newbies but as a tool it is quite capable for quickly prototyping behavior.

If you haven't tried it in a while you should, it had quickly gone from cheap 3rd party software to powerful well documented software.

Unreal for any serious project though.

t. Near no-code

Someone give me a homework problem.

Well spotted

I have a full set of first year CS labs from Pearson but they aren't programming-centric. Stuff like turing machines and simple encryption etc

you use this to debug double free.

normally you wouldn't know which line causes it, by setting that pointer to null you will get a segv on the second free.

given a palindrome, find the next palindrome

e.g. 303 -> 313

I'll take it.

Thank you. I will post a solution shortly.

here
Thank you, by the way.

Question from previous thread:

I was shitposting. :^)

I'm about to release an asset. I fucking hate Unity's serialization, but their asset store seems more promising.

>using the smiley with a carat nose

cryptopals.com/sets/6/challenges/48

>not dick riding my caret nose into the sunset
:^(

My wife's son is taking his first programming course in school. What supplementary material can I get him to challenge him? He's often bored in school and I figure this course will be no different.

Making stuff.

I think I may have done something amazing /dpt/

My job does a lot of programming, but the whole office is confined to choosing between Groovy, Jython, or Nashorn (basically JS with Java methods). This is because we're writing scripts inside a crappy java environment and don't have access to the server itself

I don't like Java, and most of my coworkers don't like it either, so tonight I wrote a script in Nashorn that just lets them run almost any executable single file from a URL (input doesn't work but doesn't need to, node and rare languages don't either but there's no way around that)

you invented cgi?

cgwhat

I fucking hate make.
I do not want to type out seperate identical targets for every source file which only differ in target name and file name.
I want to get a list of source files dynamically, loop through them and turn them into object files, and then call the final target to link to all together.
How can I do this? Google is fucking useless.

And don't tell me to use some build system like GNU autotools or cmake please, I'm not that suicidal.

Also, I need parallelism, so don't tell me to just do gcc *.c etc etc

Studying for 2 back-to-back phone interviews early next week. Wish me luck.

I kinda want to buy a Sup Forums pass. These captchas are getting annoying and I have no friends.

>I do not want to type out seperate identical targets for every source file which only differ in target name and file name.

Then don't. Use Make wildcards. Use my Makefile from my Memesnake program as a reference:

github.com/expeditiousRubyist/Memesnake/blob/master/Makefile

Use Cmake or Scons or any number of make alternatives. The only time I use Make directly is when I'm doing some small test programs that I would otherwise compile by hand.

Studying for my exams so that I can then study for this test I have to do for a graduate program.

We'll get them jobs lad.

What's wrong with Cmake?

Bloated and unnecessary, I'm not writing a firefox clone here.

It's an ugly, overcomplicated son of a bitch.

Does anyone know how to have a soundcloud widget play music in a backgrounded tab?