Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
This is more of a general UI/UX question: do users have a clue about right-click context menus these days? I know that 10-15 years ago the conventional wisdom was basically Do Not Use if you wanted your program to be remotely accessible because a significant portion of the (non-computer-savvy) user base just didn't understand why their mice had multiple buttons. Has that changed any?

I mean, obviously people who have a strong background in computers know about right-click context menus and multi-button mice; that's been a thing since the 80's at least. But I'm trying to design a UI for a fairly complicated program, and I feel like putting things behind context menus would basically end up "hiding" them and make them inaccessible. I mean, there's the secondary issue of figuring out how to notify the user "hey, you can right-click here" (which I also still need to figure out), but that's assuming the user knows how right-clicking works in the first place. How much can I assume of my user base?

For reference, said user base is largely composed of biology scientists and other scientific academics. I've learned that doesn't always mean as much tech-savviness as you'd like, though. Or rather, they're plenty savvy with their tech. I'd probably end up turning myself into some kind of lizard man if I tried to use their DNA profilers; they'd accidentally create Skynet if you handed them an IDE.

Adbot
ADBOT LOVES YOU

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

nielsm posted:

This isn't based off any research, but I'd say stick to the old wisdom, for new reasons: Context menus are okay, but never as the sole way to access a command. Make them shortcut menus for the most useful interactions on some UI object, but still allow the user to do the same thing in a more roundabout way.

Consider whether you might have users on a mostly-touch input system, those won't have a right click. Consider users with laptops with bad touchpads, using right click might not be comfortable there. Consider if some users prefer to use the software with only keyboard, keyboards don't have a RMB.

It's (almost) never wrong to put in a context menu, just make sure its content is relevant, not too irrelevant, and the menu itself is not unavoidable.

But it's probably still a bit of a power-user thing. The users I talk to daily tend to know what I mean by right-clicking, but don't always seem like it would be something they'd think of themselves.

Thanks for the advice. I guess my main worry is that my coworker keeps suggesting we just put things into a context menu that aren't super-vital but are nice to have (like extra customization for controls), and I worry that users are going to think our UI is clunky because they don't know how to make it fit their needs. On the other hand, trying to fit everything in so it's visible without context menus, without also making a horribly cluttered UI, is a very difficult problem. :shrug:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Jsor posted:

Why is an inverted index called "inverted"?

I had to look up what an inverted index is, but okay. Generally in mappings you map from some kind of "address" or key or whatever to the data that is associated with that key. In an inverted index you map from the data to the key instead. It's inverted because it's backwards (compared to the normal approach), which is what inverted means.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
On the other hand, as an abstraction you can think of the full path to a file being a key you can use to find that file. I've certainly had programs in the past where I mapped file paths to file objects.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Tea Bone posted:

I'm sure this must have a simple solution but I just can't seem to wrap my head around how to phrase the query.

I have a database for a booking system with columns 'start_date' and 'end_date' (stored as unix timestamps). On the front end of the software the user selects a month and the booked days in that month are pulled from the database. At the moment it looks like this "SELECT * from bookings where [1st of the month] <= start_date AND [last of month] >= end_date" Which kind of works but we get a problem if the booking crosses a month, for example if the start date is 30th of October and the end date is 2nd of November, if we're looking at November, obviously the start_date falls outside the query.

So the user wants to see all days in a given month that are booked, and you may have bookings that start before the month or end after it but still have booked days during it? You need to do a basic interval intersection test. You have two ranges: [A1, B1] is the month you're looking at, and [A2, B2] are the start and end dates of a given booking. The easiest way to do this kind of test is to check for the situations where the two intervals don't intersect, which are fairly easy to identify. If B2 < A1, then the booking ends before the month starts. If A2 > B1, then the booking starts after the month ends. Any other combination results in an intersection -- go ahead and imagine the possible arrangements of A2 and B2 with respect to A1 and B1. There aren't that many possibilities.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Honestly this isn't something that I think most people explicitly train in. It's just a matter of a) practice, b) working with well-written codebases (as an example), c) working with shittily-written codebases (as a counter-example), and d) getting advice from others (who hopefully know better than you do).

And I think the counter-examples are at least as important as the examples. Having to debug code written by someone who uses single-letter variable names (for things other than loop iterators/coordinates) is a great way to teach you how important descriptive variable names are. Having to manually trace where some library call comes from because the previous person abused namespaces / did "import *" / etc. will teach you how important proper namespacing is. Extending well-written code is obviously, vastly easier than extending badly-written code.

"Fortunately", if you ever get a job in software development, bad examples are extremely easy to come by...

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
I wouldn't make a PR for each individual one, but you could definitely try doing a bunch of them in a single PR. All they have to do to to accept your changes is click on one button, so it's not very hard for them. If they can't be arsed to do it then gently caress 'em.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Man, if one of my coworkers used code like that in real life I would punch them so hard.

I mean, code golf is a thing, sure, I just wouldn't want to see it used in an interview.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Rockybar posted:

code:
String compass = new String("COMPASS/n");

Dunno if this is just a typo or not, but your backslash is a frontslash here.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Hey, we're talking encryption and security! That's awesome. I want to implement a basic client/server API to allow our client programs to send notifications to the server. The only big trick here is that only authorized clients should be able to use this service, and the details of the information they're sending should be kept private (i.e. not sent in the clear).

First off, I'm happy to use existing solutions so long as they're secure and open-source compatible; any recommendations? Failing that, here's the sketch of my design:

Clients that are authorized are provided with a client ID and a client private key, which they plug into their versions of the program.

Server-side: we expose an HTTP server that accepts three types of requests:

1) HTTP GET request for the server's public key ("Key Request").

2) HTTP GET request to request an authentication challenge ("Challenge"). This request will return a random string encrypted with the client's public key.

3) HTTP POST request to send a new notification ("Notification"). This request contains the following information:

- The decrypted random string from a Challenge request (usable once only, and only within a short time window)
- JSON string describing the notification, encrypted with the server's public key

All requests also include the client ID; we can revoke client IDs/keys if necessary by updating a table on the server side. We can also update the server's public/private keys at any time since each interaction with the server should involve first getting the new key -- it's not embedded into the client program anywhere.

The notification process should be fairly obvious from this: request the server's public key, request a challenge token, decrypt the token with the client's private key, encrypt the notification data with the server's public key, send both to the server. The server verifies the token matches what it encrypted and that the client is authorized, and if so, decrypts the notification data and takes appropriate action based on what it finds there. As far as I can tell, the client's information should remain private so long as they keep their private key, well, private -- which is down to proper operational security on their computers and is not something I think I should be particularly worried about.

This seems fairly straightforward, but I'm worried that I'm the guy going "computer security is easy! :downs:" while walking off a cliff into oceans full of Screaming Eels. So, uh, sanity check please?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Okay, thanks for the advice guys! I'll need to read up on exactly how TLS works, so I know how to use the tool correctly, but that does sound preferable to a roll-your-own approach.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Rockybar posted:

I'm making a program that graphs based on input from an arduino. Currently all values and their timestamps are stored in an ArrayList, and then I use this code:

code:
for (int i = (TrackedPoints.size() - 1); i >= 0; i--) 
    	{

      point(centreX - (width/2) + TrackedPoints.get(i).getTime()*10, 
      		centreY + TrackedPoints.get(i).getTemp()-(height/2));
      		
      }
to draw a graph as a series of points from the array. However when it reaches about 1000 objects in the array (maybe a minute in) it starts lagging a lot. What is the best solution to reducing this? Currently I've thought of two options: merging multiple points in the array, so only a maximum of 600 or so are rendered (displaying the whole graph); or having the graph shift to the left as it goes along (and perhaps making a mode to switch between the two). Are either of these solutions acceptable? Or is there a better way to keep all my data displayed without having to resort to other ways of making it efficient? Just stopping the background update isn't really an option, as they'll be other things updating on screen, some I'd like in real time for instance.

You can draw the graph points to an image object, and just update that image object each time a new point is added. Then in your display code you just draw the image again. This kind of approach can also be used to do a shifting window (like your second option): just draw the image to itself, but offset by a bit, and the oldest points will disappear while new room opens up for new ones.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

JawnV6 posted:

Why is the fitness function affecting inputs like that? Shouldn't you have one set of "passengers" that each control scheme is expected to ferry around graded on the shortest time to complete all journeys?

You should have a large body of multiple different test scenarios, so that the control schemes can't overfit themselves to the test set.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Honestly probably the proper "real" fitness function would be based on the total time spent by passengers in waiting for the elevator to arrive. In my experience passengers don't care that much about stopping on floors that aren't their own once they're on the elevator, but they do care about the elevator taking forever to arrive. Probably you should additionally penalize very long wait times so you don't have some poor shmuck on the top floor waiting for hours. Something like "penalty = sum(time ^ 1.05 for time in all wait times)".

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Oh, you're trying to break the algorithm. Okay, that's different.

In that case I would expect you should base your penalty on how the algorithm compares to the best possible algorithm, which of course is "passenger does not have to wait to get on elevator; elevator takes passenger straight to destination with no stops." Everything beyond that is penalty, and a good algorithm should be able to recognize that you're repeatedly teleporting users to the top of the building so they can ride all the way down, and react appropriately.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

anatomi posted:

Hope this isn't veering too off-topic, but a friend of mine is writing an article about programming for children. She asked me if I knew anything about it, but I was stumped. Any of y'all know of some particularly decent programming courses and/or tools aimed at children?

I read a neat article once about a parent-child programming activity where the parents were the "computers" and they executed programs written by their children which included commands like turn left, walk forward 10 steps, duck, stand, etc. The children had to program their parents to navigate simple courses, and they started out with very basic commands and then gradually added more complexity like loops and subroutines.

Shame I can't find the article; it's a great idea.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Cryolite posted:

I'm asking a question but need help in figuring out where to start looking to figure it out on my own.

Suppose you have a very, very simple instruction set with 9 total instructions for a CPU that has 10 registers, and need to write a compiler to translate assembly for this CPU to x86. However, x86 only has 6 general purpose registers if you exclude ESP and EBP, or 8 with them I guess if you give up pushing/popping anything. I don't really know - the only assembly class I took was 6 years ago at a community college.

How does one translate instructions for a 10 register CPU to x86? Is there a general algorithm to do this kind of thing I can research? Or is it just cleverly juggling data around to and from memory as it's needed?

I'm not sure where to even start with designing something like this. This is a take home problem for an interview where I'm allowed to do as much research as I need to. The point isn't to actually build such a compiler but to communicate a possible design for one, but I'm not sure how to handle 10 registers on x86.

Well, you clearly aren't going to be able to do a 1:1 mapping of registers, so you're going to have to figure out some other approach. That will presumably involve mapping the fixed registers in your VVSISC (very very simple instruction set computing) to the currently-available registers in x86. You'll have to devise an algorithm that will allow you to figure out what registers you need over the course of some set of operations and do any necessary swapping if you need more registers than you have.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Here's a little puzzle/problem I'm hacking at (for work, not school, just to be clear). I have a program that displays grayscale images along with histograms of the pixel intensities in those images. A given image typically has two-byte intensities, so values from 0 through 65535 may be represented. In addition to the histogram, we show the user the min and max pixel intensities, as well as a configurable percentile (e.g. the 0.1th percentile intensity and the 99.9th percentile intensity).

We want to draw the histogram with reasonable screen fidelity; it typically takes up around 400-500 horizontal pixels on-screen, and we're using 256 bins in the histogram, which looks good enough. We generate the percentile intensities by linearly interpolating between bins in the histogram based on the sizes of the bins and how many elements are in them. And this all works fine.

But the user can "zoom in" on the histogram, changing the top end of the X-axis from 2^16 to 2^10, 2^8, etc., and we need to maintain that visual fidelity when drawing the histogram. That means allocating fewer intensities to each bin in the histogram as you zoom in (we recalculate the histograms when you zoom). But if we keep the same number of bins in the histogram while shrinking the size of each bin, then we lose the ability to track the full range of intensities represented in the image. That is, we may end up with a histogram that "stops" at a pixel intensity of, say, 1023, and every pixel that is brighter than that just can't be tracked.

We can still find the absolute brightest and dimmest pixel (since we have to iterate over all pixels to generate the histogram, and they can just be specially tracked). But in order to figure out the Nth-percentile stats, as far as I can tell you need to know what the distribution of intensities is, and that requires a full histogram. Can you think of a way to derive the intensity of the Nth percentile pixel in an image without generating a histogram that spans the entirety of the dataset?

In practice, we're likely just going to decree "okay, all our histograms have 4096 bins instead of 256" and accept that they may get a little "chunky"-looking if you zoom in all the way. Or as you zoom in the number of bins in the calculated histogram increases; either way. But I'm curious if someone can come up with an elegant solution that avoids having to calculate histograms with potentially huge numbers of bins. Eventually we may want to support 32-bit images, for example, and it'd be nice if we didn't have to generate a 4-billion-bin histogram just so it still looks nice when you zoom in.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

fritz posted:

Keep a copy of the pixels sorted by intensity and then as you zoom in on the histogram that tells you the bounds of a window into the sorted intensity array?

This is potentially even worse than "have a histogram with bin size of 1 and bin count equal to the maximum allowed value" because the number of pixels in the image is potentially unbounded. Plus it requires a sort operation. I should have said this originally, but we expect to be continuously replacing the image being viewed as the camera takes new images, so there's not a lot of value in keeping a reference data structure lying around.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Yeah, the two-histogram approach looks like the way to go. And to be honest my main complaint against the 65536-bucket approach is just that it's inelegant. Resource-wise we're not particularly constrained, though if we tried to go to 32-bit images and have a 4-billion-bucket histogram then we would probably run into problems.

Thanks for the advice, everyone! That P-Squared thing looks interesting, assuming I can muster the brainpower to understand it. It's been awhile since I regularly read academic texts...

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

fritz posted:

How big are your images anyway? Unless you're something like https://en.wikipedia.org/wiki/Gigapxl_Project a 2**32 histogram is going to have basically "all" of its bins empty. (from a 16 megapixel image, at most 1 in 256 buckets will have any count at all)

Yeah, 10MP is pretty standard for images right now, and while it will probably grow some I don't see it exceeding 100 MP in the next couple of decades.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
If you are stuck with OpenAL, the library has methods to convert those error codes into error strings which should help you figure out what's going wrong. Something like AL_getErrorString() or something.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

ufarn posted:

Having two big screens by sheer hardware instead of deluding yourself into thinking that you can totally do the same by splitting up the screen (which doesn't work with full-screen apps and videos at all) is so amazing.

It also makes it really obvious when you use a program that doesn't anticipate that you might have multiple displays. And, y'know, if you're writing your own GUI, then it'll help you fix issues related to having multiple displays.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
You know what this subforum needs? A thread for developers to bitch about what they've been doing lately.

For example, I spent a day and a half tracking down a memory leak. Totally my fault, I wasn't doing my bookkeeping properly. But it didn't help that for some reason during the first day of investigations, the memory leak only showed up when I wasn't running the profiler. :psyduck:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

JawnV6 posted:

There's the Coding Horrors thread where you can own up to your crimes and describe your heisenbugs when observability tools affect outcomes.

Ahh, excellent. Unfortunately I have no idea what was going on with the profiler; it started behaving itself the next day and the root bug was deterministic so :shrug:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Bob Morales posted:

I kind of get it from Ruby or Javascript but I just don't grasp the 'how' or 'why'

I have some bit of throwaway logic that I need to apply in bulk (for example, a sorting routine) but I don't want to make a fully-fledged function. Or I have a bit of logic that needs to fire when some piece of GUI is interacted with (e.g. a button is clicked), and I want the logic to be close to the GUI setup code. Those are the two use cases I run into most often, but there's plenty more. Start thinking of functions as interchangeable objects in their own right (functions as first-class objects) and you'll probably start using lambdas more often. Unfortunately, many languages don't actually let you treat functions as objects. :argh:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Slanderer posted:

I'm currently dealing with a large data set from an experiment, and I'm looking to an alternative to Labview for viewing it. Basically, I have 30 test devices logging 200 points of data every minute, which is streamed to a set of PCs controlling the test and saved as CSV files (1 file per device per day). I'm looking for a better way to visualize and analyze the data, but I don't know the first thing about this stuff. I know that I want to be able to inspect certain signals from one device over months and zoom down to the scales of minutes, and also compare multiple devices at the same time (while keeping in mind that each unit will timestamp it's own data set individually, either the plotter needs to be ok with arbitrary floating point scales or I need to correct the timebase on each device's data and account for clock drift and stuff). I also need to be able to go right from the graph to the data (for instance, to check the state of various control and status registers at a certain point in the graph).

Can anyone point me in a direction for stuff to read about visualizing and analyzing Not-Big- Data?

My inclination would be to write some kind of script where you'd tell it what devices and what time range you care about, then it would spit out a single CSV file containing the relevant data. Then you load that CSV in Excel or another spreadsheet program (or in Matlab) and use it to generate graphs. The script wouldn't need to be very complicated since it's just mapping your "what device and what time range" input into a list of files and then merging those files together. If you wanted to be a bit fancier you could learn to use Matplotlib in Python; then you wouldn't need the intermediary CSV file.

The important thing is this case is to have an approach that's smarter than "I'll load the entire dataset and then select out the parts that are relevant". Your 30 test devices are probably generating, what, 50-100MB of data per day all told? (It's bigger than strictly speaking necessary, since the numbers are stored as text rather than binary, but that's fine). Loading several months' worth of data is still entirely in the range of what modern computers are capable of, but it'd slow things down especially if you don't have a solid-state drive.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

fritz posted:

Why not just dump the data into a SQL db? surely both matlab and excel support populating things from queries.

Because then I have to maintain the CSV files and the database and have to coordinate interchange between the database and the analysis tools. Absolutely this would be a good idea if I expected to be doing this on a large scale, but I got the impression that Slanderer is in an academic environment where a) simplicity is valuable (every addition to the toolchain is one more thing for the next hapless grad student to have to maintain), and b) there's not really a need for large-scale.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
matplotlib (a Python graphing library) supports zoomable graphs. Could be worth taking a look. You'll also need to use numpy as the input to matplotlib; you can load CSVs directly into numpy. numpy also has good decimation, concatenation, etc. operations.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
And your performance should start decreasing once you've taken more than 2 shots or so... :v:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

lord funk posted:

If I have eight chars in an array vec, but the value represented is actually 55.0 (float). How to I get the float 55.0 out?

Is there some particular reason why you're doing manual bit twiddling instead of using your language's number parsing functions? Your method is going to break as soon as you try to read an actual float rather than an integer as you're doing now. Recommend you instead construct a string from your chars and pass that to the appropriate library method depending on language (e.g. in Java it'd be Double.parseDouble(str)).

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

JawnV6 posted:

He's edited in a solution, the printf was just to show what value was in x, and fritz solved the right problem the right way. How did you read an array with values 0, 92, 66, 0 as being ascii characters that represented "55.0"?

Sorry, my bad: I saw "char" and leapt to thinking about strings instead of remembering that it's another term for "byte". It's Friday and I'm, evidently, more tired than I'd realized.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Leandros posted:

1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice.

What kind of optimization are you doing that a single addition is an unacceptable speed penalty? Have you actually determined that this addition is slowing you down unacceptably? People are lousy at optimizing code unless they have a lot of experience at it.

quote:

2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed? :ohdear:

Your problem is elsewhere in your code. You are almost certainly doing a bad access into your array of arrays somewhere. The RNG is probably not related to the cause; the reason it's nondeterministic is because the initial state of memory is different each time you run the program. You need to run your program inside of a memory access analyzer which keeps track of what parts of the program are valid accesses and which are not. MSVC has a built-in debugger that can help with this; since you aren't using it, though, you might look into valgrind. Or just check all the places where you're doing memory accesses; you done hosed up in one of them at least.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Sergeant_Crunch posted:

The error. "d" should read "CIS" in both spots and hours in the case of CIS hours should read 100. My guess is that it's taking the d at the end of invalid, but I'm not sure why.

What is the type of the variable "major"? What kind of information are you trying to store in that variable?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Illusive gently caress Man posted:

At one point I thought I knew C++ but I was just writing C with half baked classes.

At one time C++ was just C with half-baked classes, so hey, you're just forty-odd years behind the times! :eng101:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Jsor posted:

How can you easily scrub/apply backspace characters? I was doing some stuff with Keras and piping the output to a file. When I ran cat on the file, it appeared fine, but when I tried to parse the file the program panicked on a bunch of junk. Eventually I opened the file in an editor and discovered that the logging file had actually grabbed the backspace characters it uses to update progress as raw characters. Despite cat displaying properly `cat file1 > file2` still wrote the raw character buffer.

My "solution" ended up being to cat the files, copy the terminal output, and then paste that into a new file, but that was only tractable because the files after backspaces were relatively small and there were only six of them.

Edit: Obviously I can write my own script that reads files in character by character and shortens the buffer whenever it encounters \u{8}, but I figure there has to be an out-of-the-box way to do this.

Total shot in the dark, but maybe `cat file | sed "s/ctrl-Vctrl-H//"` would do the trick? Where "ctrl-Vctrl-H" is replaced by actually pressing ctrl-V followed by ctrl-H. That should be the backspace character.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

ExcessBLarg! posted:

Laws are weird like that. Implied warranties might not apply to software at all. Or they might not apply to software that is not sold. Or they might apply, but with damages limited to the cost of sale, which is zero. Or they might not apply because the disclaimer says they don't. Or they might still apply because the law precludes disclaimers, and so we're all screwed anyways.

This is why lazy evaluation is bad, mkay? :v:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Bob Morales posted:

What the gently caress is a 'factory'? I know the Java joke is ObjectFactoryFactoryBeanFactory() but what is it?

Factories are objects that make other objects. Generally this is relevant when there are things you can't do in the constructor for an object that need to be done before the object can be interacted with. For example, if your program requires different objects that do not have owner/creator relationships to be aware of each other, you can't establish that awareness in an object constructor -- that's known as "leaking "this" in constructor", and can be problematic e.g. if another thread attempts to interact with the object while its constructor is still executing. So instead the factory makes the object, and then once its constructor is done (and it is therefore safe to interact with) establishes relationships between the new object and any other object.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

ExcessBLarg! posted:

You can "just build" something. However, since Java lacks keyword arguments, the Builder pattern avoids having to have constructors with many arguments, or having to pass in a "config" object. It's solving a different problem than the lack of global-scope methods.

Builders also make it a lot more pleasant to create large numbers of similar objects, especially if they're immutable and can thus share internal state. You fill in the bulk of the builder with the stuff that's identical across all objects you're creating, then you tweak the few things that are different, create an object, tweak again, create another object, etc.

Adbot
ADBOT LOVES YOU

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Agrikk posted:

I would like to identify a regex string that will eliminate the nested double quotes from within the text string, without stripping the double quotes in a "good" string. Or is there a better way of making the strings consistent?

Jesus Christ, no. You want to bind your parameters into a query, and let your query library handle escaping quotes, etc. for you. In general, if you are generating a query by inserting variables into strings, You Are What Is Wrong With Databases.

A proper query gen should look something like this:
code:
dbConn.execute("INSERT INTO MyTable VALUES (?, ?, ?, ?)", param1, param2, param3, param4)
Obviously varying depending on the specifics of the language and DB you're working with, but if your database doesn't support bound variables (I'm not even aware of any that lack this feature) then you need to ditch it and use something that does.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply