/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

cplusplus.com/reference/bitset/bitset/
twitter.com/SFWRedditImages

>They store offsets from the stack pointer
Ah, cool, that's the part I was missing.

any neural net autists ITT?
how do i normalize many independent sequences? theyre all in a different range, and ranges may overlap between two sequences
should i normalize the data as if it were one sequence or each sequence independently?

A D fag posted a problem about finding common substrings between two.

Here is my solution in C
#include
#include
#include

int *lcommon(char *s, char *t) {
int strlen1 = strlen(s);
int strlen2 = strlen(t);
int len = (strlen1 < strlen2) ? strlen2 : strlen1;
int i, j, k;
int longest = 0;
int **ptr = (int **)malloc(2 * sizeof(int *));
static int *ret;
ret = (int *)malloc((len + 3) * sizeof(int));
for (i = 0; i < 2; i++)
ptr[i] = (int *)calloc(strlen2, sizeof(int));

ret[1] = -1;
for (i = 0; i < strlen1; i++) {
memcpy(ptr[0], ptr[1], strlen2 * sizeof(int));
for (j = 0; j < strlen2; j++) {
if (s[i] == t[j]) {
if (i == 0 || j == 0) {
ptr[1][j] = 1;
} else {
ptr[1][j] = ptr[0][j-1] + 1;
}
if (ptr[1][j] > longest) {
longest = ptr[1][j];
k = 1;
}
if (ptr[1][j] == longest) {
ret[k++] = i;
ret[k] = -1;
}
} else {
ptr[1][j] = 0;
}
}
}
for (i = 0; i < 2; i++)
free(ptr[i]);
free(ptr);
/* store the maximum length in ret[0] */
ret[0] = longest;
return ret;
}

int main(int argc, char *argv[]) {
int i, longest, *ret;

if (argc != 3) {
printf("usage: longest-common-substring string1 string2\n");
exit(1);
}

ret = lcommon(argv[1], argv[2]);
if ((longest = ret[0]) == 0) {
printf("There is no common substring\n");
exit(2);
}

i = 0;
while (ret[++i] != -1) {
printf("%.*s\n", longest, &argv[1][ret[i]-longest+1]);
}
free(ret);

exit(0);
}

reimplementing Redox in Haskell

Same, no I/O though.

Is there something like Write you a Haskell but finished?

Why do so few languages support bit arrays as part of their standard library?

I know that's implementation side but my ideal language (...implementation) would store and process arrays of booleans as bit arrays by default.

t. man with trillions of booleans to process all time who hates to run out of memory

Languages every programmer should study:

>C
>C++
>Rust
>Lisp/Scheme
>Prolog
>Haskell
>Idris

cplusplus.com/reference/bitset/bitset/

>C++
Everything you said except this.

Wow, that is some awful code.
#include
#include
#include

const char *lcs(const char *a, const char *b, size_t *out_len)
{
// +1 for the empty string column/row
size_t a_len = strlen(a) + 1, b_len = strlen(b) + 1;
size_t (*sol)[b_len] = calloc(a_len, sizeof *sol);

if (!sol)
exit(1);

// Coordinates to the best known solution
size_t max_x = 0, max_y = 0;

for (size_t i = 1; i < a_len; ++i) {
for (size_t j = 1; j < b_len; ++j) {
if (a[i - 1] == b[j - 1]) {
size_t len = sol[i - 1][j - 1] + 1;
sol[i][j] = len;

if (len > sol[max_x][max_y]) {
max_x = i;
max_y = j;
}
}
}
}

*out_len = sol[max_x][max_y];
const char *ret = a + max_x - sol[max_x][max_y];

free(sol);
return ret;
}

int main()
{
size_t len;
const char *s = lcs("123", "abc", &len);

printf("%.*s\n", (int)len, s);
}

C++ is THE example language to learn from though.

Really?
import std.stdio;
void main(string[] args){

string str1 = args[1];
string str2 = args[2];

string[ulong] largest;

for (int i = 0; i < str1.length; i++){
for (int j = 0; j < str2.length; j++){
if (str2[j] == str1[i]){
string current = ""~str1[i];
ulong current_largest_length = current.length;
for (int a = 1; (a+i < str1.length && a+j < str2.length); a++){
if(str2[a+j] == str1[a+i]){
current ~= str1[a+i];
}
}
largest[current.length] = current;
}
}
}
auto largest_key = largest.keys[0];
foreach(i; largest.keys){
if (i > largest_key){
largest_key = i;
}
}
writeln(largest[largest_key]); //I even got strings of different length
}
> ldc2 main.d ;and ./main cadfdce nadfica
adfc

Bjarne, hvorfor skapte du et så forferdelig programmeringsspråk?

Bjarne isnt responsible for C++ getting out of control.

kurwa :DDD

z-score

>adfc
That's the longest common subsequence, not the longest common substring.
They are different algorithms.

My program needs an API which is used with an HTML tag, which uses a URL as a source and runs a callback function.

But I've come across a scenario where I need that callback function to use the API for itself, and although possible to do it by having the callback function create script tags, it's messy and difficult.

Is there a neater way?

Ruby beginner question here. Is it better to use the .push method in ruby to combine arrays if they get to be very large? Are a few smaller arrays better than one big one for run time?

Something has gone very wrong here.
Posted about this yesterday
>program calls a console program, takes its output and places that output in a textbox
>program I'm using for testing is really simple, for(ieven I couldn't fuck that up
>add the data to a concurrentqueue
>every update I pull the count and place it in an array then write the array
>this is the data being written, it seems to come in fine though
fug

where can i get an xml file or whatever of current stock market?

use JSON with one of the websites you find on google

You're saying how to parse the XML file, not how to get it.
Well, you did say how to get it, but the day "just Google it" becomes an acceptable answer for anything is the day Bernie Sanders becomes president.

for real time data you have to pay someone to get it. or your bank or w/e might provide it for free for certain markets but they probably don't allow you to scrape it with automated tools

if i do this daily, do you think they will block me? also im pretty sure its against tos or something to atuomate this

how do i make this work in c#

public bool Regist(Client a, Date date, int i, int d)
{
Call c = new Call([here should be object im interacting with], a, i, d);

}

the call constructor takes 2 clients, but how do i get the caller client without making it an argument of the function?

i found MemberwiseClone() but it doesnt save changes on the original object. maybe this doesnt even make sense idk

What's a good project for when I'm drunk

Lisp interpreter

Unity
It's using Cg.

gpu register spilling maybe

1. The push method does not combine arrays, it appends an element at the end of one. If you call push with an array argument, it'll end up looking like this:
irb(main):001:0> a = [1,2]
=> [1, 2]
irb(main):002:0> a.push [3]
=> [1, 2, [3]]

The method you are looking for is concat, which would instead produce the value of [1,2,3]

2. Regarding runtime performance, if I remember correctly, Ruby's arrays are implemented like vectors. They have a length and a capacity, and the capacity doubles every time one tries to append elements beyond said capacity. A larger array should be able to push back more elements without requiring memory re-allocation, but it may also require more memory. It's been a while since I've looked at the Ruby source code though, so things might be a bit different...

You probably shouldn't be as concerned about performance for this, however. Keep different variables for different things. The point of Ruby is not necessarily to be a fast language, but to be a language you can enjoy. Putting all of your variables in one giant array does not make for well-maintainable code.

cool

Ruby: why Ruby?

help

this is not irc

Thanks for the information. I'm still learning and this is all very interesting and helpful to me. I will definitely keep the concat method in mind.

I know a guy who has been using it awhile, which helps because usually I can ask him questions and he doesn't mind helping me with it. The alternative would be trying to learn Java or C and having no one I know to help me. Also, it's my intention to transition into Rails someday if I can get Ruby down well enough.

No idea what you're trying to accomplish.

>tfw have computer science degree from a reputable university
>tfw can't find a job
>tfw fell for the computer science meme

It's the most comfy scripting language out there. Really great for string and array processing

What about Scheme?

What's this about strtok not being thread safe?

strtok has static internal which means you get different results on each call.

there's a huge shortage of competent programmers, all you need is to know programming and not be an overly autistic freak

This is probably just someone being a comedian but out of curiosity is it because you wont accept below a certain pay for a job? Like do you feel you wont earn enough or your skills are too high for what they want to pay? Because as someone without a degree and looking from the outside in there seems to be tons and tons of programming jobs available all over the damn place but they just don't pay well enough to fill the positions, resulting in the demand for programmers being high.

I'm not implying you are like ungrateful, I know that you have to make x amount of dollars just to get by and you can't work for peanuts and just hope for advancement or making a connection, but what's the deal? Are they literally not calling you back or getting back to you?

strtok_s

Scheme can be alright, although I'm not as familiar with the standard library. Also, it doesn't really have great syntax for function composition. By comparison, since most things in Ruby are done with methods, rather than naked functions (which are really just methods on the main object), I can compose functions by means of chaining methods. I also can take advantage of the fact that parentheses are optional for regular functions. If I wanted to call f(g(x)), it's really just f g x.

I dunno. I applied for so many jobs and I only got one interview and the pajeet asked me if I could reverse a string in bash (which I couldn't do). I failed the interview.

>f g x
>not f (g x)

literally retarded

Both are valid in Ruby. Similarly, a b c d e is equivalent to a(b(c(d(e)))), or scheme's (a (b (c (d e)))), or F#'s a

>not forg(x)

>Rust
Everything you said except this.

Well I'm sorry sir and or madam. I wish you luck when you snag another interview which I'm sure you will. You might even find a place that cares more about interest and drive over per-existing skills, but that's kind of rare. Try to keep your chin up friend.

>Both are valid in Ruby
THEY'RE COMPLETELY DIFFERENT

Thank you user. Where do you live where there is a shortage of programmers?

Rust is pretty nice

>not fag(x)

>last pic

lol nope, nice try.

Where did you find these

That's the closest to 2D you'll get

nice gap vs full rub was what i was commenting on.

first two are damn close, last is not.

i thought projections were the closest you get to 2d

Not where I live. I live in Appalachia and looking to leave because this place is dying fast.

I would suggest any place like a big city that has lots of companies and individuals looking for programming skills. Also, where there are lots of people there is more of a chance to find startups or things that could use you, or be in the same boat and willing to work with you on a project.

Basically, I think the ideal way to go would be move to just outside a city where it will be much cheaper, but close enough you can commute to work or find an apartment if you do land a job or find some work to do.

However, I would think programming you could do from home in many instances. Also, have you tried freelancing or helping with open source projects to make some friend/connections?

what do you think about java Sup Forums?

>all you need is to know programming and not be an overly autistic freak
Theres a difference?

Fuck off, you hillbilly freak!

>You'll never get a dragon mommy gf
why even live?

WHERE DID YOU FIND THESE?
shit

Okay, thank you again user.

Go to tumblr and search for lucoa cosplays

Disgusting.

>tumblr
What are you doing

So I'm unemployed, but have a CS degree with a good GPA and all that. But I don't want to work for a big company, or any company really. All I want to do is make my own games, which is feasible, but not when you have no other income. Friends/family are pressuring me to get an SE job so I can eventually work for Amazon or the like, but I fucking hate the thought of doing that. I'd rather get 20K a year making my own games than 100K+ working at a top tech company.

Is there a position I could hold that's low-stress and low-effort that can keep me afloat while working on my own projects? I don't want to get tied into being a software dev my whole life just because it's what I'm qualified to do.

No
Move out

Could you apply for a part time position somewhere doing part time development or something? Like you'd work half as much, and make around 50k a year, and have time left over for games and stuff.

Like I imagine there is something like that where a company only wants someone doing small programs or touch-ups on things rather than a full time person. In fact, wouldn't it be cheaper for them to not support someone full time with benefits and shit and just contract people for short amounts part time?

I think my cum tastes sweet

you're being very short sighted.

you should put in at least a few years making 100k+. save and invest it. you can always spend more time later doing your own thing, but the time to prove your worth, and earn money, is now not later. it's very hard to go into the industry if you don't have the right experience form the get go.

Don't listen to this guy. If you want to do your own thing just do it. Doing X because your family/friends told you to is possibility the worst thing you can base your decisions on.

If you want to pursue your own decisions, then go for it. Just own your own decisions and don't blame others if you fail later down the road.

That being said, you can work part time somewhere and earn just enough to still claim benefits. That should give you more than enough free time to do your own projects.

kek I work as a line cook 3 days a week and the rest 4 days is enough to get my programming going. Pays my bills just enough.

if you're confident you can live of 20k you'd only have to work for ~9 years making 100k and saving 50k of that every year, investing in index funds, to never have to work again for the rest of your life.

after 9 years you could be effectively financially independent, 30 years old, and free to do all the programming for yourself you want.

9 years is a long time to do something you dislike even if it brings in good money. I worked at an IB when I was in college for an internship. They paid me 8k per month for those 6 months. Every single day I wake up and I wanted to shoot my brains out.

if you want to shoot your brains out every day then yeah, that's a terrible job.

but there are plenty of good paying coding jobs that are, at worst, tolerable that can be used as a vehicle to financial independence in a relatively short amount of time if you're diligent and keep your eye on the price.

Rust is a fad. Everyone who shills it is either an attention whore or a hysterical worrywart. Hype for "safety" is completely unwarranted. On the list of reasons your software is insecure, being written in C is at the very bottom.

>Security concern is a hype
gee I wonder who sponsored this post

All coding jobs are the same. So long as you can tolerate coding it is fine. What makes it good or not is the working environment, company culture and team members. But that user talks as if he hates the idea of coding as a job. So yeah he is going to want to shoot his brains out if you ask him to code for 9 years doing something he doesn't want to do. Also depending on the type of company you work for, it might make working on side coding projects restrictive or downright nonviable.

Say I am writing a program in C that reads in a (unknown length) file, splits the file into 4 equally sized chunks, and throws the 4 chunks into child processes to sum, and return back to the parent.

I've gotten all the fork and pipe business, but I was wondering if there was any way to do this without reading the file into a huge array initially? Essentially what I'm doing is this:

1. Read file, each line into an element in an array (resizing as needed, and counting how many elements)
2. Split array into 4 arrays, pass each subarray into the child process via pipe
3. Sum as usual
4. have each child return their sum
5. have the parent sum the sums
6. show user

Would there be a way to directly read 1/4 of an unknown file size into the child processes?

It's for an assignment that requires me to demonstrate knowledge of forks + pipes, so that part cannot change.

nice trips fag

>It's for an assignment
Not doing your homework

thx
I already technically did it but I was just wondering if there was a more effective way since I never use C

You could always start with 4 arrays and round-robin the lines you read if order doesn't matter.

Nice strawman, Schlomo.
>no goyim use our """"safe"""" language

Your epic Sup Forums memes are not working and we already know you and your co workers post in Sup Forums

The CIA has more day 0 exploits for C than they do for Rust.

Is there any point in using a dynamically typed language that isn't a lisp?

Catering to retards

I'll give that a shot and see if it affects performance much, thank you.

But user, half of all people have above median intelligence.

If more people start using Rust, do you think that would change, or stay the same? Are the even interested in putting in the time with so few developers using Rust?

Have you audited the rust compiler?
>b-but you d-didn't audit gcc
Not an argument.