/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

github.com/PonderingGrower/rbackup
en.wikipedia.org/wiki/Pairing_function
quora.com/Why-does-mass-not-matter-when-an-object-is-free-falling
ti.com/tools-software/launchpads/overview.html
docs.rs/refraction/0.1.2/refraction/
wiki.dlang.org/GUI_Libraries
twitter.com/NSFWRedditImage

First for getters and setters are a code smell.

OHOHO new thread!
I read somewhere that lenses are bad practices in Haskell. Is that really true, gee?

learning scala

>What are you working on, Sup Forums?

Exploring the deepest, darkest corners of Racket. Advent of Code 2017.

Which Haskell? haskell.org or haskell-lang.org?

yes

delete your post right now

are the puzzles good?

those are different?

return to twitter pls fag

>those are different
he's meming you

I'm trying to hash an object based on its (x,y) coordinate (i.e. based on a location object).
But two objects, both with the same coordinates produce a different hash code with the hashCode() method.

What's the best way of hashing them? Overriding the hashCode() method and implementing my own based on their actual x,y coordinates? Or parsing the coordinates as a string and using the .hashCode() method on that?

I've given up on adventofcode in favour of improving my python-based backup utility and realeasing it on github. It's more interesting.

what are you even trying to say

Objects.hash

what is your github?

>are the puzzles good?
i would not say that. average at most.

why?

>why?
becase you replied to a random user instead of the OP
have you no shame

hmm. when friends talked about them it all seemed too similar to the algorithm puzzles of which i was already sick

Here's the backup tool.
github.com/PonderingGrower/rbackup

It's still unstable so a lot might change, but my goal is to release stable 0.1 before christmass.

OMG shitlord, pls delet that politically incorrect tweet out of true remorse right now, OR ELSE!

Reminder

i’ll take a look later

k

sorry.

en.wikipedia.org/wiki/Pairing_function

Thanks dude. If you see anything that needs improvement and you have any suggestions feel free to open an issue.

I should be merging unit tests branch soon, then I'll port my cli arguments form argparse to docopt.

Brainlet here with a brainlet queston for you, /sci/.

I made a createParticle function which returns an object with an applyForce method. When a force is applied to a particle it changes the velocity dependent on the mass of the particle like IRL.

It got me thinking, why doesn't gravity care about the mass of an object it accelerates IRL? The force of gravity accelerates all objects towards Earth at the same speed.

Because the force is proportional to the object's mass, which cancels into constant acceleration.

quora.com/Why-does-mass-not-matter-when-an-object-is-free-falling

you're doing MD simulations?

What does gravity have to do with ecstasy?

Just started learning C++ using Programming: Principles and Practice Using C++ (2nd Edition) by Stroustrup, wish me luck!!!

Suppose you have one rock and it falls to the ground at a certain rate. You get another identical rock. It also falls to the ground at the same rate. You you drop them from the same height at the same time. They reach the ground at the same time. You let them fall while they're in contact. Same thing. Now suppose you tape them together. Should they suddenly start falling twice as fast? Sounds pretty arbitrary to me.

Does arduino count?
I'm working on the code for pic related.
Basically an ultrasonic sensor mounted on two 180 axis. Will output distance data via serial port (SD Card) in the future to create a rough cloud point data set.

A C# script within unity will then smooth this out and create a 3D surface representation.

After that if I'm not bored, I'll mount the thing on a rover chassis and create a smart room navigation system. Where a drone rover will go in to an area, map it, figure out rooms/entryways, and will be able to autonomously navigate within in it.

Are you doing this for school?
That was pretty much what we did in our entire 3rd and part of the 4th semester of Automation and Embedded Systems.

ma = ΣF Newton's second law
ΣF = mg Assuming gravitation is the only force that applies. Similar statements would hold if it weren't
ma = mg
a = g QED

How does the Swiss knife map into that exactly? I already want to suck your dick for using one, but I just want to know.

No, been working on my game, got bored and realised I bought an arduino and a bunch of components 2 years ago. I'm using my only two shitty servos that I've found lying around.

How did your project go? If I'm successful, would love to go on to create my own mini lidar, I'd upgrade from servos to some precise tiny stepper motors (I'm guessing I'd need some kind of extra board to precisely control these)
And I could get pic related for moderately cheap (compared to an actual lidar)

Just a weight.

I use it for clipping cable ties. It weighs down the shitty lego frame the servos are mounted on. It was the heaviest/smallest thing I could find within reach.

Is is any good?
I only really have a background in Java and WebDev shit but I've been meaning to start on some C++

i believe it’s for programming novices, so you probably want another book

i’d really like to get into this sort of thing

That one is mainly for people that are new to programming in general but it's not like you couldn't just quickly skim through the stuff you already know and only really work through the parts that you aren't so sure on.
It's written by one of the main guys behind C++ and is focused on teaching you the shit you will most frequently use when you are developing instead of pretending to give you some general overview of the language but not actually accomplishing much of anything. Its goal is to get you to a point where you can do simple stuff on your own and give you enough tools and base knowledge to where you can look up exactly what else you need instead of having to randomly shitpost on forums, begging for help.
It's probably one of the best books to get started on C++ with that I know of, I'd recommend it.

double roundOff = Math.round(a*100)/100;
Is this really the best way to round a value to 2DP in java?

>Polish-Japanese Institute of Information Technology
What an odd cultural mix. Did you have to learn Japanese while attending? Also, update your copyright footer. It still says 2016 even though its about to be 2018.

We did have Japanse culture/history classes during 1 year, but the language was optional. I did spend 2 years learning Japanese though, which isn't much. I haven't used it properly in ages though, so I'm rusty.

Also, thanks, I'll update it.

I'm trying to using cppunit tests, but and I do not know why. Anybody here have experience? Will post code snippets if there is.
Its due in 2 hours.

HELP

dumb frogposter i'm not helping you

>Frogposter
You deserve to fail.

Learn how to properly ask a question before you try to actually program anything.

but it always fails* and I do not know why.

I know C and Operating Systems pretty well, how do I get into embedded development?

that sounds interesting senpai
I wonder how unit tests are done in C++

warning: implicit declaration of function ‘gettid’ [-Wimplicit-function-declaration]

why? i have #include

This unit testing framework was a massive issue to install. It required the teacher to write a 40 page PDF installation guide. (The website has about 2 pages max, and its pretty awful)


Pls:
Fuck it, this is the code:
// ADSC bit handling
TEST(TEST_HAL, get_voltageCalledSetsAndWaitsForADSCtoClear)
{

//set_bit(&ADCSRA, ADSC);
//mock_set_bit(&ADCSRA, ADSC);
//This is always fails, I even tested it. The mock function is setup.
mock().expectOneCall("mock_set_bit").withPointerParameter("reg", &ADCSRA).withIntParameter("bit_no", ADSC);

mock().expectNCalls(5, "mock_read_bit").withPointerParameter("reg", &ADCSRA).withIntParameter("bit_no", ADSC).andReturnValue(_BV(ADSC));
mock().expectOneCall("mock_read_bit").withPointerParameter("reg", &ADCSRA).withIntParameter("bit_no", ADSC).andReturnValue(0);

hal_get_voltage(0);
}

Set bit function
void mock_set_bit(volatile uint8_t * reg, uint8_t bit_no)
{
// Production code function called
set_bit(reg, bit_no);
mock().actualCall("mock_set_bit").withPointerParameter("reg", (void *)reg).withIntParameter("bit_no", bit_no);
return;
}

setting up the function pointers:
static void _setup_register_access_functions()
{
_ra.read_register = &read_register;
_ra.read_bit = &mock_read_bit;
_ra.read_bits = &read_bits;
_ra.set_register = &set_register;
//_ra.set_bit = &set_bit;
_ra.set_bit = &mock_set_bit;
_ra.set_bits = &set_bits;
_ra.clear_register = &clear_register;
//_ra.clear_bit = &clear_bit;
_ra.clear_bit = &mock_clear_bit;
_ra.clear_bits = &clear_bits;
}

Unit test niggas, how would I unit test something like this:
pub fn from_url(url: &str) -> Result {
let resource = download_resource(url)?;
let item = parse_resource(&resource)?;
Ok(item)
}

fn download_resource(url: &str) -> Result {
let resource = api::get(url)?;
Ok(resource)
}

fn parse_resource(resource: &Resource) -> Result {
let name = resource.name()?;
let url = resource.url()?;
Ok(Item { name, url })
}

>man gettid
>NOTES
>Glibc does not provide a wrapper for this system call; call it using syscall(2).
Also, is there some reason pthread_self is not good enough for you?

Try contributing to Linux Kernel in small ways. Before you know it you'll be building full features. Once you have that in your CV any company will be happy to take you for any low-level coding.

I did a linux kernel module for my engineering thesis project and when I still had that in my CV companies that deal with embeded devices kept contacting me. Though that wasn't the career path I wanted.

No more frogs, I promise.


Failure

Something like this maybe?
#[cfg(test)]
mod tests {
#[test]
fn test_from_url() {
let url = "foo.bar";
let item = from_url(url).unwrap();
assert_eq!(item, Item { name: "Foo", url })
}
}

/* Extend the buffer in sb by at least len bytes.
* Note len should include the space required for the NUL terminator */
static void sbuf_extendby(sbuf_t *sb, int len) {
len += sb->NUL;
if (len buflen) return;
if (!sb->buflen) sb->buflen=64; //min size (to alleviate fragmentation)
while (len > sb->buflen) sb->buflen *= 2;
char* buf = realloc(sb->buf, sb->buflen);
if (!buf) abort(); //out of mem
sb->buf = buf;
}

Im confused by this line
while (len > sb->buflen) sb->buflen *= 2;

Would this not potentially increase the buffer's size by way too fucking much, or?

You want to increase size exponentially so that you have fewer reallocations as it gets larger.

i remember reading somewher that pthread_self() and gettid(); would return different values but im not sure anymore

im trying to implement file lock across threads but i guess i need to use thread mutex or some shit, i was trying to do it with fcntl() only

meant to quote you

Go for it. Get a cheap chinese arduino, components are like a dollar each. Wires are basically free.

I should've made my question more clear. How do I make the api::get() not do any external I/O during unit testing? Should I make a stub api implementation? How would I do something like that in Rust?

On the topic of racket, Typed racket just got some cool features like refinement types. It's now possible to write formally checked code in Racket.

TI makes some pretty cool shit

ti.com/tools-software/launchpads/overview.html

Thanks

ah, thanks

how does user choose which area of the kernel to contribute to?

>making GUI
>having to handle IO and other tasks without blocking
What is preferred way to do this?
I'm using tkinter, right now I have a lazy image loader that will make a thread and poll a queue for the response but I feel like this won't scale and isn't very clean.
Should I write an event loop for fetching things?

working on python and ai, anyone suggest some good ai and python training from top to bottom

i have scikit

#[cfg(test)]
mod test_api as api;

#[cfg(not(test))]
mod api;

Something like this, maybe

If a new object is passed to a method as an argument, is it immediately deleted when the method returns, or does the garbage collector still need to remove it?
i.e.
foo(new bar(a,b));

ai can mean a lot of things. what do you want to do? andrew ng’s mooc is standard—he uses octave/matlab but it shouldn’t be difficult to translate to numpy

a smart enough interpreter can do escape analysis. But no guarantees.

Huh, apparently there's an equivalent of the Lens library in Rust: docs.rs/refraction/0.1.2/refraction/

The type signatures are still quite crazy, but less so than in Haskell. I guess having multi parameter typeclasses and type families in the language by default does simplify a lot of API's.

this is bait, right?

What even is the use case for Lenses?

That's exactly what I was looking for. Thanks user. Now I can make an Api trait and a production and test Api.

This is unintelligible garbage, why would anyone willingly subject themselves to this.

He wants an ai gf that he can talk to. He wants Her.

What should I learn?
Nim, D, Rust, Go or something else?

I really hate that she wasn't a blank slate from the star. Really killed any immersion along with it being the voice of scarjo

>poll
You should never poll except in RT/embed world.

Common Lisp

take off go.
try all three and see which one you like the least.
Nim is pretty good, but still very new, and lacks a lot of tools.
D basically has two modes, just werks GC where things are as easy as python, and C 2.0 with a lot of quality of life stuff. But you lose some of D's niceties as well.
Rust is polarizing, i personally hated it, bu it has loads of support so there's that.

Anybody ever worked on Rockbox here?
I have a good level in C, I'd like to contribute but I don't know where to start.

hate the least*

Perhaps I used the wrong word.
I have a queue and when I need to go get an image I spawn a thread and register a callback to check the queue every 0.1 seconds. When my threads gets the resource it puts it in the queue.

Elaborate why I should learn Common Lisp

I'm looking to build cross platform desktop application.
I already installed nim and tried using it's GTK wrapper but I'm having trouble with it.
D probably has the biggest support in that regard right?

Nevermind, reqwest doesn't allow mocking. FUCK!

No

It'd be between D and Rust.
D has bindings to most mainstream GUI stuff as well as a few small native ones.
wiki.dlang.org/GUI_Libraries

C

Damn nigga, good luck. I use rockbox on my xDuoo X3

...

If I wanted to put things from an ArrayList into another data structure that'll be sorted, what should I use?
Would a treemap be useful? Or would iterating through this to get the values be inefficient?

>Using getters and setters
>Using OO
Remember kids, OOP is POO

Guess I'm gonna try out Rust first then, since it seems to be growing quicker.
Thanks