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
Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
Alright database people I need some advice. Our factory is using some complicated MAC address state machine to keep track of which MAC addresses are assigned to which unit and it's become a big error prone headache.

What would be a good solution to maintain a database of currently assigned MAC addresses and to generate new ones across multiple work stations?

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


Popete posted:

Alright database people I need some advice. Our factory is using some complicated MAC address state machine to keep track of which MAC addresses are assigned to which unit and it's become a big error prone headache.

What would be a good solution to maintain a database of currently assigned MAC addresses and to generate new ones across multiple work stations?

How much development are you willing to do? Can you cloud host it, or does it need to be on prem? What languages are you familiar with?

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer

The Fool posted:

How much development are you willing to do? Can you cloud host it, or does it need to be on prem? What languages are you familiar with?

Probably don't want to spend a lot of time working on this. The factory asked us software developers for suggestions on an implementation and one of us may get assigned to this but probably for no more than a week.

I'm an embedded software developer so I spend %90 of my time working in C, but I've worked a decent amount in Java and more recently Python. I'm unfamiliar with SQL but I'm sure someone else here has more familiarity. This would be hosted on our work servers ideally and the factory desktops (Windows) that would be used to assign a MAC address could pull from it.

The Fool
Oct 16, 2003


My first thought would be to roll a django site with sqlite, using django's auto-generated admin site as a template for the basic ui.

tracecomplete
Feb 26, 2017

Centralized data store with guaranteed atomicity. A Redis with an incrementing key would probably be enough, but you might want to be a little more elaborate.

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
Thanks, those are both good suggestions and I'll dig into them further. Would there be a way to guarantee uniqueness in the database? We want to avoid accidentally assigning the same MAC address to two units.

The Fool
Oct 16, 2003


Super easy with Django to set a constraint: https://docs.djangoproject.com/en/dev/ref/models/fields/#unique

Splinter
Jul 4, 2003
Cowabunga!
What's the recommended way to implement an action on a resource when designing an API? For example, I want to have an action that will delete (or alternatively, set end_date to now()) the resource, as well as create a new resource that is identical to the specified resource except with start_date set to now(). My first inclination is to have the API end point be something like POST to /{userId}/resourceType/{resourceId}/theAction. I know this isn't really RESTful, but it seems simpler than trying to do this in a strictly RESTful manner.

Also, another API design question: when dealing with a fetching data for a specific user, is it best to include the userID in the API endpoint, or to infer the user from the authentication?

Slimy Hog
Apr 22, 2008

Splinter posted:

What's the recommended way to implement an action on a resource when designing an API? For example, I want to have an action that will delete (or alternatively, set end_date to now()) the resource, as well as create a new resource that is identical to the specified resource except with start_date set to now(). My first inclination is to have the API end point be something like POST to /{userId}/resourceType/{resourceId}/theAction. I know this isn't really RESTful, but it seems simpler than trying to do this in a strictly RESTful manner.

Also, another API design question: when dealing with a fetching data for a specific user, is it best to include the userID in the API endpoint, or to infer the user from the authentication?

EDIT: I can't read.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Splinter posted:

What's the recommended way to implement an action on a resource when designing an API? For example, I want to have an action that will delete (or alternatively, set end_date to now()) the resource, as well as create a new resource that is identical to the specified resource except with start_date set to now(). My first inclination is to have the API end point be something like POST to /{userId}/resourceType/{resourceId}/theAction. I know this isn't really RESTful, but it seems simpler than trying to do this in a strictly RESTful manner.

Also, another API design question: when dealing with a fetching data for a specific user, is it best to include the userID in the API endpoint, or to infer the user from the authentication?

I wouldn’t worry about it being fully “RESTful” so much as “can I document this and does it meet design requirements?”

You need to determine how exactly the API will be used. If a user is only ever going to get user information about themselves, then you can infer the user from whatever auth method you’re assuming. More typically you’d have the option to get information about any given user provided you have the authority to do so, which can be useful if you need to get multiple users in a programmatic way. This assumes you have some endpoint to get all userIDs, either in total or to some specific group.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Splinter posted:

What's the recommended way to implement an action on a resource when designing an API? For example, I want to have an action that will delete (or alternatively, set end_date to now()) the resource, as well as create a new resource that is identical to the specified resource except with start_date set to now(). My first inclination is to have the API end point be something like POST to /{userId}/resourceType/{resourceId}/theAction. I know this isn't really RESTful, but it seems simpler than trying to do this in a strictly RESTful manner.

Also, another API design question: when dealing with a fetching data for a specific user, is it best to include the userID in the API endpoint, or to infer the user from the authentication?

You’ll probably get a different answer from everyone, so here’s mine!

1. Use POST because your request isn’t idempotent.
2. Put the user ID in the endpoint. If you want to have a variation in the endpoint that means "do thing for the currently-logged-in user", that’s ok too.

Jose Valasquez
Apr 8, 2005

Splinter posted:

What's the recommended way to implement an action on a resource when designing an API? For example, I want to have an action that will delete (or alternatively, set end_date to now()) the resource, as well as create a new resource that is identical to the specified resource except with start_date set to now(). My first inclination is to have the API end point be something like POST to /{userId}/resourceType/{resourceId}/theAction. I know this isn't really RESTful, but it seems simpler than trying to do this in a strictly RESTful manner.

Also, another API design question: when dealing with a fetching data for a specific user, is it best to include the userID in the API endpoint, or to infer the user from the authentication?

We do these as /{userId}/resourceType/{resourceId}:theAction to make it clear that "theAction" is a custom method (as opposed to normal CRUD operation) rather than a subresource

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
The standard way to satisfy the "everything must be a resource" nazi ideology when faced with a complex but atomic action, is to take the verb you would use to describe the action and try to turn it into a plural noun. In your case it sounds like you're effectively replacing the old element, so the best resource nazi name might be POST /{userId}/resourceType/{resourceId}/replacements. POST /{userId}/resourceType/{resourceId}/restarts is another option. Because English is the way it is you often just end up with a verb with an -s on the end.

However, trying really hard to make everything "RESTful" in that manner is basically just a waste of brain power. What's important is choosing a name for the action that feels intuitive, and where you don't feel the urge to replace the name every time you look at it. I like the sound of the ":action" suffix approach, although I've never used it myself.

Dominoes
Sep 20, 2007

Hey dudes. I've been working on a proj and the past few commits are down a rabbit hole I can't wake myself out of. Want to revert a few commits without losing everything.

History shows that entering terminal commands from the first StackOverflow article I find results in bad things happening if Git is involved. Git is a dark art. Probably need to get the current code in a sep branch. This is a collaborate proj with a few other users, but no one else has modified any commits since what I'm reverting to. What's the word?

edit: Solved. Copy+Pasted raw text from Github into current files.

Dominoes fucked around with this message at 06:35 on Jan 20, 2019

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'

Dominoes posted:

Hey dudes. I've been working on a proj and the past few commits are down a rabbit hole I can't wake myself out of. Want to revert a few commits without losing everything.

History shows that entering terminal commands from the first StackOverflow article I find results in bad things happening if Git is involved. Git is a dark art. Probably need to get the current code in a sep branch. This is a collaborate proj with a few other users, but no one else has modified any commits since what I'm reverting to. What's the word?

edit: Solved. Copy+Pasted raw text from Github into current files.

First rule of git is make all changes in branches.

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

dupersaurus posted:

First rule of git is make all changes in branches.

Correct. You should have a local master branch that only contains code you're happy with. Each new thing you start work on should start by pulling from the remote to the master branch, then creating a new local "feature branch". Work in the local branch until you're happy with it, then make a pull request from that branch to the remote. Once the pull gets accepted you can pull it into your master from the remote, and delete your local feature branch.

Your described situation can happen even with the above though, if you get partway into your feature branch and then muck it up. In which case you can just check out a second feature branch from the first one (causing them to both have both the good and bad changes), then revert the bad changes in one of them (or reset its HEAD to be before the bad commits, if they're the most recent commits).

Dominoes
Sep 20, 2007

Much apprec. I've never done a collaborative proj before, but that makes sense as the best way to do it now. Would also make it easier to deal with my worry that if I don't commit/push often enough, it'll break someone else's WIP they haven't yet submitted a PR for.

nielsm
Jun 1, 2009



If you've made some changes on master you wanted to have on a branch, what you can do is mark the current head of master as that branch, then point master back at the previous "good" commit.

yippee cahier
Mar 28, 2005

Dominoes posted:

Much apprec. I've never done a collaborative proj before, but that makes sense as the best way to do it now. Would also make it easier to deal with my worry that if I don't commit/push often enough, it'll break someone else's WIP they haven't yet submitted a PR for.

A certain amount of this will happen anyways, so it's probably a good idea to come up with some interfaces you can use as boundaries with your fellow developers so you don't step on each other's toes.

LongSack
Jan 17, 2003

I didn’t see a separate thread on ansible, so posting this here.

We are being tasked with automating something using ansible and python (don’t ask)

My first thought is to replace a current n-step process for producing firewall rule dumps with hit counts.

So, I have an ansible playbook using the asa_command module which connects to each firewall and executes the following commands:

term pager 0
show access-list | i x.x.x.x\x20

where x.x.x.x is the IP address, and the trailing “\x20” is a space to make sure that searches for 192.168.1.10 don’t also pick up 192.168.1.100-109

This works, and when I run the playbook with the -vvvv option, I can see the results.

My problem is, how do I get the output(s) from the command(s) into a state where I can then use the output in a python script to parse the rules and produce an excel spreadsheet. I know how to do the excel part in python, I just need to know how I can get the output from ansible in a way that python can use it. The results of the commands are stored in a variable called stdout_lines

TIA

The Fool
Oct 16, 2003


Would a callback plugin work?

https://docs.ansible.com/ansible/latest/plugins/callback.html

LongSack
Jan 17, 2003


Quite probably! Thanks!

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Can anyone suggest a way I can open .dbc files?

I think they are FoxPro 6 files but I'm not sure and I don't have access to a MSDN subscription to download this ancient application. Does anyone know of another way to look at the data inside?

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

It was a long time ago, but I was able to get something going with python and a free trial of some paid ODBC deal. It was annoying IIRC.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Agrikk posted:

Can anyone suggest a way I can open .dbc files?

I think they are FoxPro 6 files but I'm not sure and I don't have access to a MSDN subscription to download this ancient application. Does anyone know of another way to look at the data inside?

Maybe try LibreOffice? Some googling around indicates Base can do stuff with DBF files, but that may just be table structure, not sure if that or Calc can do the DBC. This of course would be on an application basis and not programmatically.

If you have .NET it looks like there's an OLEBD driver for it so you could do a simple harness CRUD/extract:
https://social.msdn.microsoft.com/F...m=csharpgeneral

Farchanter
Jun 15, 2008
I have a Java project that will be populating an object by cherry-picking the needed pieces of data from a few existing REST services. Is there a preferred design pattern to go about doing this?

fankey
Aug 31, 2001

Due to poor life choices I am trying to implement CSS styling to a windows WPF based application. Most of it's pretty straightforward but I'm having a hard time wrapping my head around how CSS gradients ( both linear and gradient ) are implemented. For example, it appears as though CSS premultipled alpha for gradients when compared to SVG or WPF.

This CSS code
code:
<style>
div {
  width: 400px;
  height: 140px;
  position: absolute;
}
.g {
  background : green;
}
.l {
  background: linear-gradient(to right, red, rgba(255,255,255,0));
}
</style>

<div class="g"></div>
<div class="l"></div>

produces this


while similar SVG or WPF code
code:
<svg height="150" width="400">
  <defs>
    <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
      <stop offset="0%" style="stop-color:red;" />
      <stop offset="100%" style="stop-color:rgba(255,255,255,0)" />
    </linearGradient>
  </defs>
  <rect width="400" height="150" fill="green" />
  <rect width="400" height="150" fill="url(#grad1)" />
</svg>
gets

I'm thinking that I'm going to need to generate my own gradients to match CSS but the CSS specs I've looked at don't give enough detail to really implement anything. The Chromium source contains how they generate gradients but without any context of that code I wasn't able to make much sense of it. Does anyone know a good reference or straight forward source in any language for CSS gradient implementations? I can probably get the premult alpha linear gradients working but the radial gradients definitely get crazy when compared to what's available in most graphics frameworks.

necrotic
Aug 2, 2005
I owe my brother big time for this!
This SO post seems to answer the question. Basically CSS handles transparency in gradients differently (better) than SVG. As for the gradient calculation its just linear RGB interpolation for both.

Can you not layer and have the gradient go cleanly from red to green by itself?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I believe CSS colors are specified in sRGB space. try converting to linear, blending, and then converting back to sRGB.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Suspicious Dish posted:

I believe CSS colors are specified in sRGB space. try converting to linear, blending, and then converting back to sRGB.

Isn't that browser specific? I haven't touched gradients in a while but when I did I seem to remember having to roll one way for IE and another for Chrome/FF

Kind of irrelevant to OP I guess because they're doing WPF but still curious.

hooah
Feb 6, 2006
WTF?
I'd like to write something to automate scanning in CD album liner notes and turning them into PDFs. I'm most familiar with Java, but also have experience with Python, Javascript, and Matlab. I tried the scanning library from Asprise, but it couldn't get any capabilities from my combo printer/scanner/copier, neither over network nor USB. Would another language make my life easier? Or perhaps there's a better Java library?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Scaramouche posted:

Isn't that browser specific? I haven't touched gradients in a while but when I did I seem to remember having to roll one way for IE and another for Chrome/FF

Kind of irrelevant to OP I guess because they're doing WPF but still curious.

I'm willing to believe that IE has poorly though out color management, yes. But the latest CSS spec says that colors are specified in sRGB space. Which means that linearly blending their values does not work. I believe both Firefox and Chrome convert to linear to do any blending.

fankey
Aug 31, 2001

Thanks for the responses. My post might have been a little confusion - I know how the linear gradients are different - what I was looking for was a 'readable' implementation of CSS standard gradients for reference so I can create my own implementation. The linear ones are pretty straightforward - I've already gotten my code to support some of the crazy patterns here. The radial gradients are where things get difficult determining exactly what they are doing via inspection ( aka playing around in codepen ).

luchadornado
Oct 7, 2004

A boombox is not a toy!

Farchanter posted:

I have a Java project that will be populating an object by cherry-picking the needed pieces of data from a few existing REST services. Is there a preferred design pattern to go about doing this?

What do you mean design pattern? You're kind of implementing a facade pattern just by nature of what you're doing. You'll probably want some DI via Guice. Other than that, I'm a fan of Paul Graham's take on the subject:

quote:

When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough-- often that I'm generating by hand the expansions of some macro that I need to write.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Helicity posted:

What do you mean design pattern? You're kind of implementing a facade pattern just by nature of what you're doing. You'll probably want some DI via Guice. Other than that, I'm a fan of Paul Graham's take on the subject:

One thing that's nice about modern DI frameworks is that a lot of what you would call a pattern in another language (like singleton, decorator, factory) just ends up being a matter of calling your DI's register method with different options.

luchadornado
Oct 7, 2004

A boombox is not a toy!

Bruegels Fuckbooks posted:

One thing that's nice about modern DI frameworks is that a lot of what you would call a pattern in another language (like singleton, decorator, factory) just ends up being a matter of calling your DI's register method with different options.

Yeah, if you have a class called HttpClientSingletonFactory you're probably doing things in a needlessly complex way. Just ask Guice for a single instance of something.

On more thinking, I'd personally just have main class for DI binding, a service that does the actual facade work, and then a gateway to help talk to each backend. That's fairly idiomatic Java without going into some sort of hellhole like https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

epswing
Nov 4, 2003

Soiled Meat
This is probably really simple, but I'm not great at regex.

I'm looking for a regex that matches a string which
  • starts with a letter or number
  • can contain letters, numbers, and dashes
  • ends with a letter or number
  • can be a single letter or number

The follow regex is almost what I want, but doesn't match a single letter: ^[\w][\w-]*[\w]$

Should match: "a", "1", "a1", "a-1", "aa--11--bb--22"
Should not match: "", "-", "a-", "-a"

My googling has resulted in lots of results concerning matching the same character at the beginning/end of a string.

epswing fucked around with this message at 14:04 on Feb 2, 2019

Nippashish
Nov 2, 2005

Let me see you dance!

epalm posted:

The follow regex is almost what I want, but doesn't match a single letter: ^[\w][\w-]*[\w]$

Just match the single letter separately: ^\w[\w-]*\w$|^\w$

epswing
Nov 4, 2003

Soiled Meat

Nippashish posted:

Just match the single letter separately: ^\w[\w-]*\w$|^\w$

Oh... right. Thanks!

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Or you can do ^\w([\w-]*\w)?$
(one character at the start, optional group of the other stuff ending with a character, line ends)

Also might be worth testing them on your input to see if one is faster, it's possible to write single regexes that are way slower than just splitting them up into multiple tests

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