/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Computers_and_Intractability
mega.nz/#!RYNGlYII!eUWr59vyx9QI1IpsI3Pp_QMJsYkP0Op26fPHIrtPNPU
github.com/klipperoo/pyircbot
my.mixtape.moe/iwuacs.pdf
en.wikipedia.org/wiki/Tidy_data)
json.net/
twitter.com/NSFWRedditGif

First for C

What would be an approved unharmful library for making GUIs?

third for help

Ncurses

>listening to the output of some sort of shit tier parser

can't wait for the day computers are fast enough to make the benefits of programming in C and C++ unreasonable in relation to the productivity of other languages.

I can't advance into my JS course if I don't get an OK,sorry if my code is bad

I need some help on a project I'm working on.
A console application where multiple users can access it. Users are saved in a txt file, all data from one user in separate lines. Now, how do I make the data in the file as an array? Example
ID: 1|name: poo|money: 400
ID: 2|name: loo|money: 100
etc...
I want to make switching between users possible using a global variable, so that when an user switches, it will read only from the index with that same variable, but only specific elements.
Is it possible without making a db?

Reposting because I need help.

It is already in many cases.

>computers get faster and faster
>programs get slower and slower thanks to worse techs
Yeah good luck with that Pajeet

That makes no god damn sense.
Why not use a fast computer AND a fast language? You get even quicker that way.

Make a parser for your txt.
Or use CSV.

Benefits of programming big complexes in fast languages are covered by the time of programming big complexes in slow language.

Having fast computers but slow software is like driving a lambo in NYC.

Just read the file into memory?

It's probably just complaining because you're missing a space between the sentences in your string.

>implying fast computers matter at all

what I wanted to say is that computers would be so fast you'd reach a point that it wouldn't really make a difference for tasks that you don't actually need all that power.
i don't know if a point like that will ever exist though, desu.

What does N state for?

Boring UI stuff's

>desu
Kill urself

it's autoreplace

...

Artists of the past were classy.

That still means that you're a stupid fag who wrote the shit which was replaced, which is even worse.

Can you explain more in depth?
How?

Let me explain a bit more, can I make an array out of the txt file for each field(ID, name, money), so size of 3, then read only the values they have? If let's say I would be user with ID 1, my name would be poo and somewhere I would have only 400 displayed(money)

it's actually two different people.

encoding quality too high, I could almost make out some of the text

>That webm
>~720p, ~20 seconds
>293KB
You could stand to up the bitrate a bit.

> Can you explain more in depth?
CSV means comma-separated values, which is a portable format for tables.

en.wikipedia.org/wiki/Computers_and_Intractability

I like this book DESU.

It's not a secret user.

How would you know?

I asked about big N

>can I make an array out of the txt file for each field(ID, name, money), so size of 3, then read only the values they have
Yes. This is serialisation/deserialisation, which is an extremely common thing for people to do.
The other user is mentioning CSV, which a very simple serialisation format to implement yourself, but being somewhat primitive. It should be fine for your needs, though.

Building a visualization tool for gene expression. Need some proper css for colors and labels, but quite pleased so far.

mega.nz/#!RYNGlYII!eUWr59vyx9QI1IpsI3Pp_QMJsYkP0Op26fPHIrtPNPU

ty.

I used | instead of commas, it would be the same, right? Can you post some example code as to how you would make the txt file into an array?

>looks like sleepCheck isnt returning
>no return outside of the if/else
GEEE....
spoonfeeding pajeets time
var sleepCheck = function(numHours){
if(numHours < 8) {
return "Get some more shut eye!";
}
return "You're getting plenty of sleep! Maybe even too much!"
}

>bitrate for plain colors with well defined borders
-crf 30 would have shat out a better webm at the same size.

i am one of them.. and the other isn't me?

lostboi.exe

Can someone test this Python code for me and tell me why it won't run? I'm new to Python.

import glob
global_creations = glob.glob("*")
for creation in global_creations:
with open(creation,"w") as c:
c.write("startup")

What's the error user ?

been working on a python ircbot

github.com/klipperoo/pyircbot

could anyone look over the code?

Mmm. i run the command. not see a difference.ffmpeg -i inputfile.txt.mp4 -crf 30 /tmp/ui.webm

It's saying I need root permissions but I'm already running as root.

it overwrites all files in the directory with "startup" including itself
add a print global_creations on line 3 to see what files its about to write to

Mmmm. do this as a normal user, and tell me if work.

mkdir -p /tmp/h/
cd /tmp/h
touch {a,b,c,d,e,f}
#open python/ipython/ptpython, whatever you like, then run your code

This is true in the vast majority of cases already.

Oh. BTW, the script don't have to be in the same folder of the files.

How did you guys become good programmers?

There are algorithms with higher complexities than exponential. You don't use 'em very often as they usually blow up in your hands when given real input data.

Create programs that do useful things.

>How did you guys become good programmers?
Practice.

Shit loads of practice.

Did you think there was another way?

We are not human's, we are alien's from "AREA 51". Do you see the animation movie Aliens vs Monster's. I'm the jelly guy.

alright what kind of useful programs?

>it would be the same, right
Sure.
>Can you post some example code as to how you would make the txt file into an array?
I don't know what language you're using, but here is a simple memesnek solution:
def read_file(filename):
array = {}
f = open(filename, "r")

for index, line in enumerate(f):
array[index] = line.strip().split("|")

return array

config = read_file("input")
print(config[1][2])
And the input:
abc|123|qwe
xcg|xra|24
So this should print 24.
I don't really know python that well, and it could probably be done more concisely, but hopefully this will give you the general idea about what you need to do.
You can also add all sorts of other fancy shit, such as a "header" line at the top which gives each column a name and ensure that each row has the same number of columns, but that's up to you.

By learning how to problem solve.
A programming language is just a means to an end to describe logic to a computer so it does what you want, which is almost always a specialized math problem.

how do you learn to problem solve when you suck at math?

I cleaned up a PDF on the book C Progamming: a modern approach. The only pdf I could find of that book was photocopied so I cleaned it up so it's more readable.
my.mixtape.moe/iwuacs.pdf

It's not the same as math, but uses the same logic. You can learn by practice a lot

Get a job and make programs that help the company.

By practicing solving problems.
I started out doing those dumb hackerrank challenges.
My first fizzbuzz attempt took me all afternoon because I didn't understand modulo.

Why are you learning C in 2017? Seriously, lean Rust and then a higher level language like Dart or C# through .NET Core.

Mmm. I think we have someone that try make sense of he's life.
my current job is develop software to compute messy data into tidydata (en.wikipedia.org/wiki/Tidy_data) to make decisions and see results in a hierarchy way

Epic memes, bro!
Do you mind if I save them?

I'm using C# , and I will have the user input all fields manually. What if the input is different though, like in my original post? An array of size 3, but each index has 2 elements (in above example, index 0 would have "ID:" as first element, "1" as second, but both on the same index).
I know you can do that with functions, can you do it with txt files?

Because C is used and Rust isn't.

>.NET Core

I don't use a language if I can't see the source code, you fucking monkey.

I like nuklear for c

I'm studying vector and matrix algebra fundamentals because I wanna sink my teeth into openGL again.

I burnt out the first time because I didn't understand what a dot product was, among other things.

I already gave you a somewhat general solution to get you started. Just modify shit to suit your needs. I'm not going to hand-hold you and straight-up do your homework for you.
A programmer needs to be able to think through shit and work it out for themselves, and not just copy-paste code from other people.

json.net/

Install the NuGet package:
Install-Package Newtonsoft.Json

Use the package in your header:
using Newtonsoft.Json;

User class to store information in-program:
class User
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Money { get; set; }

public User()
{

}
public User(int id, string name, decimal money)
{
Id = id;
Name = name;
Money = money;
}
}

Usage:
var muhUsers = new List();

// using the default constructor
muhUsers.Add(new User
{
Id = 1,
Name = "Poo",
Money = 300
});

// or using your own constructor
muhUsers.Add(new User(2, "Loo", 400));

// write the list of Users as a Json file
File.WriteAllText(@"C:\temp\muhUsers.json", JsonConvert.SerializeObject(muhUsers));

Now I can also read the data by deserializing it from the file:
var muhUsers = JsonConvert.DeserializeObject(File.ReadAllText(@"C:\temp\muhUsers.json"));

foreach(var user in muhUsers)
{
Console.WriteLine($"User #{user.Id} is named {user.Name} and has {user.Money.ToString("C")}");
}

Thanks for the help, but that wasn't what I was looking for. You could just look through the string if it contains "ID:", then read the value from that index, but that seems inefficient, I was wondering if there's another way.

Any way to do it without the package, but get the same result?

>Header-only project
>22k lines
Good job bloating compile times.

compile time is the appropriate place to sacrifice time.

The ideal would be to have efficient implementations and use less power so that devices that run on battery last longer. That is why C and low level optimization is (still) the future.

>Any way to do it without the package, but get the same result?
Yes, you stupid faggot, but it's disgusting and I can only assume this is homework and your prof doesn't allow other libraries.

So, assuming you still use a class:
var muhUsers = new List();
var filePath = @"C:\temp\muhUsers.txt";

// using the default constructor
muhUsers.Add(new User
{
Id = 1,
Name = "Poo",
Money = 300
});

// or using your own constructor
muhUsers.Add(new User(2, "Loo", 400));

File.WriteAllText(filePath, string.Join(Environment.NewLine, muhUsers.Select(user => $"{user.Id}|{user.Name}|{user.Money}")));

// to retrieve...

var muhUsersFromFile = File.ReadAllLines(filePath).Select(x =>
{
var ln = x.Split('|');
var id = int.Parse(ln[0]);
var name = ln[1];
var money = decimal.Parse(ln[2]);

return new User(id, name, money);
});

muhUsersFromFile.ToList().ForEach(user => WriteLine($"User #{user.Id} is named {user.Name} and has {user.Money.ToString("C")}"));

It's for an elderly home, they'd like something to store their games and bets, but I don't want it to be bloated and I want it to be simple to use.
Thanks though.

>literally doing his homework for him and not explaining how to do it properly

This is why people can't code

>tfw no geriatrics to impress with 20 lines of code

web programming and GUI programming is superior to any other types of programming because you can actually physically see your results right away