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
Volguus
Mar 3, 2009
Hmm, that could work. To be honest though, rather than doing that, for my case and my usage so far, I'd rather inconvenience those 3 users. The Bar message would look ugly and scream "Bad decisions were made, now we live with regrets".
Declaring that a Bar is invalid when there are no Foos present is enough for me right now, as it makes sense from a business logic point as well. And when a single Foo is sent, then there are no Foos in the Bar.

Would gRPC solve this problem better? I've never used it (and I believe there aren't C embedded libraries for it, but i could be wrong there), but could one declare something like:
code:
Response processFoo(Foo foo);
and later on just come and say:
code:
Response processBar(Bar bar);
as a brand new method while leaving the old one intact?

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Worth noting that it wouldn't necessarily be a long-term thing - after enough time that you expect all clients to have updated (and/or you're willing to stop supporting the ones that haven't), you delete the backcompat logic and change the definition to:
code:

message Bar {
  repeated Foo foo = 3;
  reserved 1, 2;
}

It's not unusual to see reserved tag numbers from previous api versions - it's just an acknowledgment that apis change over time. If you get in the habit of making backwards-compatible api changes now when it's largely inconsequential, you'll find it easier to do later on when it's important to get right.

That said if you control all the code that calls this api, or you're willing to immediately break backwards compatibility (and can ensure that all clients are going to update), you totally can just start fresh.

Volguus
Mar 3, 2009

Jabor posted:

Worth noting that it wouldn't necessarily be a long-term thing - after enough time that you expect all clients to have updated (and/or you're willing to stop supporting the ones that haven't), you delete the backcompat logic and change the definition to:
code:
message Bar {
  repeated Foo foo = 3;
  reserved 1, 2;
}
It's not unusual to see reserved tag numbers from previous api versions - it's just an acknowledgment that apis change over time. If you get in the habit of making backwards-compatible api changes now when it's largely inconsequential, you'll find it easier to do later on when it's important to get right.

That said if you control all the code that calls this api, or you're willing to immediately break backwards compatibility (and can ensure that all clients are going to update), you totally can just start fresh.

Yes, that's good advice, thanks, I'll keep that in mind. While I do not control all the code that calls this API, and I wanted to not inconvenience those few clients ... theyr'e very few clients and they know they're testing my API (beta and all that) so I just may start fresh and tell them to change their stuff. 2 developers are chinese and one is indian, I have no idea how they're gonna react, but I can tell the business guy to just make it work.

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

Volguus posted:

Would gRPC solve this problem better? I've never used it (and I believe there aren't C embedded libraries for it, but i could be wrong there), but could one declare something like:
code:
Response processFoo(Foo foo);
and later on just come and say:
code:
Response processBar(Bar bar);
as a brand new method while leaving the old one intact?

That was my original suggestion: make a new API method with the desired signature, and delete the old method once people have had sufficient time to switch over.

...oh, was the reason you were having problems because you were just getting a binary blob on a socket and had to determine what its contents were at runtime? Yeah, gRPC would handle automatically dispatching to the appropriate server method depending on what proto you receive. At least, it does that for me in Python.

Volguus
Mar 3, 2009

TooMuchAbstraction posted:

That was my original suggestion: make a new API method with the desired signature, and delete the old method once people have had sufficient time to switch over.

...oh, was the reason you were having problems because you were just getting a binary blob on a socket and had to determine what its contents were at runtime? Yeah, gRPC would handle automatically dispatching to the appropriate server method depending on what proto you receive. At least, it does that for me in Python.

No, I am not using gRPC. One of the reasons is because I had to write an implementation in FreeRTOS on an ARC board using both lwip and bluetooth as communication mechanisms, and while looking around it didn't seem that gRPC and nanopb were working together. So, I abandoned the idea completely and I just read the message directly now.

The https://github.com/nanopb/nanopb/pull/248 pull though does gives me hope of this being implemented in the future, at which point (with a different endpoint than now, of course) i can probably provide a gRPC server.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Speaking of APIs:

Say I have an endpoint where users POST commands. My web application takes that command and ships it to a separate service, which will usually process it immediately but sometimes it will be slow.

My first idea will be having my endpoint do this:

1) Ship command, start idling while listening to the service for 'processing complete!' notification
2) If the notification arrives within, let's say, 1000ms (maybe there's a standard header to let the user set the timeout?), return HTTP 200 with the outcome
3) If 1000ms pass without outcome, return HTTP 303 pointing to the /commandStatus/{commandId} endpoint where the user can check at his leisure for the outcome of his command

But then I thought, why not just always create the resource at the status endpoint and always return HTTP 303, even immediately

Are there advantages to either approach? Any aspects I haven't considered?

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
What's the advantage of the 303 redirect? How is it preferable to just having an HTTP POST that takes a long time? Especially if the user can know which requests will take a long time in advance, they can just configure the timeout on their request accordingly, right?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

NihilCredo posted:

Speaking of APIs:

Say I have an endpoint where users POST commands. My web application takes that command and ships it to a separate service, which will usually process it immediately but sometimes it will be slow.

My first idea will be having my endpoint do this:

1) Ship command, start idling while listening to the service for 'processing complete!' notification
2) If the notification arrives within, let's say, 1000ms (maybe there's a standard header to let the user set the timeout?), return HTTP 200 with the outcome
3) If 1000ms pass without outcome, return HTTP 303 pointing to the /commandStatus/{commandId} endpoint where the user can check at his leisure for the outcome of his command

But then I thought, why not just always create the resource at the status endpoint and always return HTTP 303, even immediately

Are there advantages to either approach? Any aspects I haven't considered?

If you're going to do a solution where you don't have a long-running POST request, I would always return an url or whatever for the client to check for results. Or you could do push notifications with websockets.

By always returning the url to check for results you simplify your code and your clients code. Neither has to branch based upon whether we're doing a real result or an async result...it's always an async result.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
How long is the request going to take? If it's on the order of seconds > 5 I'd suggest returning a 202 while the external request is outstanding is probably the preferred method.

Once data is returned, persist it and make the response available with a 200 the next time the same resource is requested.

Blinkz0rz fucked around with this message at 18:03 on Jan 23, 2018

Mr Shiny Pants
Nov 12, 2012

NihilCredo posted:

Speaking of APIs:

Say I have an endpoint where users POST commands. My web application takes that command and ships it to a separate service, which will usually process it immediately but sometimes it will be slow.

My first idea will be having my endpoint do this:

1) Ship command, start idling while listening to the service for 'processing complete!' notification
2) If the notification arrives within, let's say, 1000ms (maybe there's a standard header to let the user set the timeout?), return HTTP 200 with the outcome
3) If 1000ms pass without outcome, return HTTP 303 pointing to the /commandStatus/{commandId} endpoint where the user can check at his leisure for the outcome of his command

But then I thought, why not just always create the resource at the status endpoint and always return HTTP 303, even immediately

Are there advantages to either approach? Any aspects I haven't considered?

Like above mentioned, something is to be said about being consistent. So always returning a status that the client can check, even if the command has already completed, sounds wise.

It will also make it easier for the consumers of your API , there is just one flow in the program instead of branches that will need different logic.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

TooMuchAbstraction posted:

What's the advantage of the 303 redirect?

It seemed like the most appropriate response code to me.

https://httpstatuses.com/303 posted:

The server is redirecting the user agent to a different resource, as indicated by a URI in the Location header field, which is intended to provide an indirect response to the original request.

quote:

How is it preferable to just having an HTTP POST that takes a long time? Especially if the user can know which requests will take a long time in advance, they can just configure the timeout on their request accordingly, right?

I thought that having a slow-rear end POST would be bad UX? You'd have no idea if it's slow because it's actually working on it or because the web application just froze up somewhere, and you wouldn't have a confirmation that your command was actually received.

Thermopyle posted:

If you're going to do a solution where you don't have a long-running POST request, I would always return an url or whatever for the client to check for results. Or you could do push notifications with websockets.

By always returning the url to check for results you simplify your code and your clients code. Neither has to branch based upon whether we're doing a real result or an async result...it's always an async result.

Yeah, that was my thinking basically.

I've only glanced at websockets before, and mentally filed them away in a folder labelled 'try this if the calls grow numerous enough to make the client lag'.

Blinkz0rz posted:

How long is the request going to take? If it's on the order of seconds > 5 I'd suggest returning a 202 while the external request is outstanding is probably the preferred method.

Once data is returned, persist it and make the response available with a 200 the next time the same resource is requested.

These are POST RPC commands that result in changes to the system, and the user provides a unique UUID for each command, so not really applicable. I'll keep this suggestion in mind though in case I ever end up with a GET resource request that takes forever.

redleader
Aug 18, 2005

Engage according to operational parameters
The convention seems to be to return 202 with a Location for the actual resource. You can return 303 from the 'queue job' endpoint once your job has finished and the resource is available.

Pollyanna
Mar 5, 2005

Milk's on them.


What's the best way to work with tabular data and data analysis without relying on a database like SQLite or a big ol' framework like Rails? I had an interview question today that in retrospect would have been much more easily answered by using SQL, except working with tab-separated values in a file. The problem was basically a couple of tables and some questions that amounted to AVG, MAX, etc. in SQL along with some join trickery and grouping, but I opted for a brute force Ruby method since that's what I'm most comfortable answering questions like those 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
Can't sqlite be backed by a flat file? So you can say "here, have this CSV, now I want to do SELECT foo, bar FROM my_file.csv WHERE foo > 10".

spiritual bypass
Feb 19, 2008

Grimey Drawer
Loading to in-memory SQLite is usually pretty quick, but there's also this Python thing if you really don't want to do that: https://pythonhosted.org/querycsv/

Nippashish
Nov 2, 2005

Let me see you dance!

Pollyanna posted:

What's the best way to work with tabular data and data analysis without relying on a database like SQLite or a big ol' framework like Rails?

My goto for things like this is "use python and load it in pandas". After that its just sql by different syntax.

Pollyanna
Mar 5, 2005

Milk's on them.


I don't think I've ever loaded tab-separated values into SQLite before. Maybe SQL really is the best option here...my solution ultimately worked, but I think I beefed it due to how long it took. If it had been a take-home, then I would have been calmer and been more open to exploring the SQL option instead of feeling pressured to brute-force it in Ruby. Oh well, next time.

Mr. Apollo
Nov 8, 2000

Not programming per se but does anyone have any recommended reading material for dealing with Bluetooth beacons (iBeacon, Eddystone, etc.). I’m looking for stuff like best practices, figuring out how many you need to cover a space to act as an indoor positioning system (I’m guessing it depends on how accurate you want it to be), security, management, stuff like that.

Everything I’ve come across so far is just a marketing pitch for products or services.

downout
Jul 6, 2009

Mr. Apollo posted:

Not programming per se but does anyone have any recommended reading material for dealing with Bluetooth beacons (iBeacon, Eddystone, etc.). I’m looking for stuff like best practices, figuring out how many you need to cover a space to act as an indoor positioning system (I’m guessing it depends on how accurate you want it to be), security, management, stuff like that.

Everything I’ve come across so far is just a marketing pitch for products or services.

I can't help you but your av is pretty sweet.

Edit: to ask a question ->

Does anyone have suggestions for an application that would provide forms that can provide validation (formio style) and allow users to go back and reference entries and edit them? Basically an easily modifiable/editable validation grid?

downout fucked around with this message at 06:04 on Jan 27, 2018

Volguus
Mar 3, 2009

downout posted:

I can't help you but your av is pretty sweet.

Edit: to ask a question ->

Does anyone have suggestions for an application that would provide forms that can provide validation (formio style) and allow users to go back and reference entries and edit them? Basically an easily modifiable/editable validation grid?

First time I've heard about form.io. Looking at their page ... what is it exactly that they're providing here? A form designer? They call it "application"? Whose application? Where is it hosted? Where's the database? Who sees the data? How ... what? It looks extremely confusing.

downout
Jul 6, 2009

Volguus posted:

First time I've heard about form.io. Looking at their page ... what is it exactly that they're providing here? A form designer? They call it "application"? Whose application? Where is it hosted? Where's the database? Who sees the data? How ... what? It looks extremely confusing.

Formio is a drag-n-drop form builder tool. Each section on the form can be customized with validation rules and conditional functionality based on previous sections or entries. If you get the free account, then you can see all the tools including the data which is just records of form entries. Each record is displayed in a grid. When you edit the entry it takes you back to the form with the fields filled with the entries details. The forms can be embedded in an external sites page (Hubspot style) with custom css to change the visual.

I think they provide an API to access the records from external sources, and a lot of other stuff I haven't explored yet.

So I need pretty much that, but a way to allow entry users to view their entries and edit them. Formio is pretty close, but I'm trying to explore options.

Jaded Burnout
Jul 10, 2004


What's the state of system languages these days? Is Go still bad because generics? Is Rust still for weirdos? Did JBlow release his language yet?

Educate a poor Ruby dev please.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Jaded Burnout posted:

What's the state of system languages these days? Is Go still bad because generics? Is Rust still for weirdos? Did JBlow release his language yet?

Educate a poor Ruby dev please.

C++ still going strong.

Don’t think Blow has released his language, but I think he’s still making YT vids of its development.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Rust seems to be staying mostly cool and good.

Jaded Burnout
Jul 10, 2004


leper khan posted:

C++ still going strong.

I did scoop a handful of C++ and it seemed like an acquired taste.

taqueso posted:

Rust seems to be staying mostly cool and good.

What do you feel makes it cool and/or good?

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Jaded Burnout posted:

What do you feel makes it cool and/or good?

I guess I'll start with the bad - It forces you to define how the data is allowed to be accessed and who owns the data, which can be easy if you aren't doing anything special, and a bit tricky if you are. This is the hardest part of learning the language, or at least it has been difficult for me. However, forcing you to define that ensures you can only access the data in a safe manner. It allows you to write code at a C level (or C++) while maintaining safety. And you get modern abstractions and language features. It is incredibly liberating to know the C-type footguns I'm used to dealing with aren't things I need to worry about.

The abstractions are chosen to fit nicely at a lowish level and tend to be very lightweight. Heavyweight abstractions are provided by libraries. The interface system makes a lot of sense and is easy to reason about. The people making the language are responsive and really seem to be trying to make a good, useful language based on real-world user feedback. The tooling is excellent. The docs are excellent. The community is excellent.

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you
Recently visited a friend who had that Amazon Alexa thing and had one of those hacker seizures where a million ideas appear out of nowhere. Does the Alexa thing and similar products use a common API for its NLP stuff that I can go read up on and try hacking with or is it all proprietary where you need to pay to hack and to already have bought one of their things beforehand?

One such crazy idea was to do a Reboot-style "Glitch! Command line!" and perform bang searches on DuckDuckGo or whatever, then reroute the results to a screen of my choice. Could use voice commands to search for legislation on Thomas and display the text on TV or tablet... or to an !endic search on DuckDuckGo to translate a word to Korean.

Love Stole the Day fucked around with this message at 22:18 on Jan 31, 2018

The Fool
Oct 16, 2003


Love Stole the Day posted:

Recently visited a friend who had that Amazon Alexa thing and had one of those hacker seizures where a million ideas appear out of nowhere. Does the Alexa thing and similar products use a common API for its NLP stuff that I can go read up on and try hacking with or is it all proprietary where you need to pay to hack and to already have bought one of their things beforehand?

One such crazy idea was to do a Reboot-style "Glitch! Command line!" and perform bang searches on DuckDuckGo or whatever, then reroute the results to a screen of my choice. Could use voice commands to search for legislation on Thomas and display the text on TV or tablet... or to an !endic search on DuckDuckGo to translate a word to Korean.

Start here: https://developer.amazon.com/alexa-skills-kit

e: all of your ideas sound possible, but you will likely just be using an alexa skill to forward the command to a rPi and doing the heavy lifting there.

The Fool fucked around with this message at 22:29 on Jan 31, 2018

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'm using an HTML canvas with a Javascript script for visualization of the output of a procedural map generator. However, for some reason I only can have one map in a given file. Can anyone tell me why this HTML doesn't draw anything on the second canvas?

nielsm
Jun 1, 2009



I'm not sure exactly why it fails, but if I wrap each canvas in a block element (like <p>) it displays all of them correctly.

https://jsfiddle.net/cec2x4xp/

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
Interesting, I wonder why that happens? Excellent to have a workaround though, so thank you very much!

Volguus
Mar 3, 2009

TooMuchAbstraction posted:

I'm using an HTML canvas with a Javascript script for visualization of the output of a procedural map generator. However, for some reason I only can have one map in a given file. Can anyone tell me why this HTML doesn't draw anything on the second canvas?

This:
code:
<canvas id="2" width="82" height="62" stroke="black"/>
should become this:
code:
<canvas id="2" width="82" height="62" stroke="black">
</canvas>
everywhere.

nielsm
Jun 1, 2009



That's a good point, <canvas /> is only valid as open + close if you're actually in XML mode. In standard HTML mode the / is just a stray character the parser ignores for 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
Aha, that'd do it. So I guess in my original setup, the parser was opening a canvas, then leaving it open until the end of document. That'd explain why it wouldn't let me open a second canvas.

shovelbum
Oct 21, 2010

Fun Shoe
Is MUMPS still used outside of Epic? Like did everyone who works in this language learn it there?

csammis
Aug 26, 2003

Mental Institution
I've never heard about it outside the context of Epic, and I worked in and around healthcare EMR vendors for several years. Doesn't mean it's not out there though. I'd be surprised if there weren't ex-Epic employees going around offering consulting services in and about MUMPS.

School of How
Jul 6, 2013

quite frankly I don't believe this talk about the market
Imagine there is a slot machine. The cost to pull the handle is $15. The slot machine only has 3 results, you get either prize #1 worth $13, prize #2 worth $20, or prize #3 which is worth $100. The machine needs to be designed to assign prizes based on a probability that the machine can be operated profitably. In order for the machine to be profitable, prize #1 must be the most common, and prize #3 must be the least common prize. How can I calculate the probability of each prize in order to maintain break even? Is there such a formula I can plug the prize values into to get each probability? Maybe this is more of a math problem than a computer problem, but I need some python code that calculates this probability.

nielsm
Jun 1, 2009



As the machine owner, you get a profit of $2 for every time prize #1 is won, a loss of $5 when prize #2 is won, and a loss of $85 when prize #3 is won. If there were just prizes #1 and #2, how would you calculate how many times you need to produce result #1 to make up for one result #2 ? Try writing it as an equation to solve.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

School of How posted:

Imagine there is a slot machine. The cost to pull the handle is $15. The slot machine only has 3 results, you get either prize #1 worth $13, prize #2 worth $20, or prize #3 which is worth $100. The machine needs to be designed to assign prizes based on a probability that the machine can be operated profitably. In order for the machine to be profitable, prize #1 must be the most common, and prize #3 must be the least common prize. How can I calculate the probability of each prize in order to maintain break even? Is there such a formula I can plug the prize values into to get each probability? Maybe this is more of a math problem than a computer problem, but I need some python code that calculates this probability.

There's an infinite number of different probabilities that will satisfy this. The general case of what you're looking would be something like this:

Given a set of prizes in ascending order of value: n0, n1, ..., nn, find probabilities p0, p1, ..., pi, where the sum of all pn is in the range [0, 1] and pn < pn-1 for all n, such that p0n0 + p1n1 + ... + pini = b, where b is the size of the bet. Since all pn are unknown, there's no single solution to this equation.

In your particular case, one example solution that breaks even would be that $13 happens with probability 40%, $20 happens with probability 20%, and $100 happens with probability 5.8%. To calculate this I just made up some probabilities for prize 1 and 2, and then solved for p in the following equation to find the break-even probability for prize 3: 13*0.4 + 20*0.2 + 100*p = 15. Another solution would be 50%, 15% and 5.5%.

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



LOOK I AM A TURTLE posted:

Another solution would be 50%, 15% and 5.5%.

What happens the remaining 29.5% of the time?

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