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
sarehu
Apr 20, 2007

(call/cc call/cc)

Jabor posted:

Presumably you could manually sum up time spent in A itself, plus the total time spent in functions (other than B) called directly by A.
That doesn't work, because B isn't necessarily called directly by A, and it can be called by multiple callees. Also, even if it was called directly by A in exactly one place and nowhere else, I'd need to also know how much of B is spent in its recursive call A. Of course, a portion of that is then spent within another B, and so on downward...

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

sarehu posted:

That doesn't work, because B isn't necessarily called directly by A, and it can be called by multiple callees. Also, even if it was called directly by A in exactly one place and nowhere else, I'd need to also know how much of B is spent in its recursive call A. Of course, a portion of that is then spent within another B, and so on downward...

You don't actually need to know how much of B's time is spent in another recursive call - just work it out by adding up the individual non-B components instead of trying to start at the total and subtract out the time spent in B.

You can still do this if the actual call to B is a few levels removed, though it could get painful quickly depending on how far away it is/how many distinct calls there are.

sarehu
Apr 20, 2007

(call/cc call/cc)
There's no realistic way to do that manually, because the mutual recursion is all-over. Anyway it looks like processing the raw samples is doable.

Edit: Yeah just a one-screen Perl script.

sarehu fucked around with this message at 07:27 on Jan 25, 2016

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

sarehu posted:

There's no realistic way to do that manually, because the mutual recursion is all-over.
My condolences.

quote:

Edit: Yeah just a one-screen Perl script.

ufarn
May 30, 2009
This doesn’t seem to have done the trick - both the `sudo -H` trick and the chown one. For the latter, neither of the directories existed, so maybe something is wrong with the way pip is set up at the moment; `which pip` yields /usr/local/bin/pip, which should probably be pointing to my user dir?

My UNIX-fu is pretty awful, so how do I go about fixing this - short of just ignoring the problem by using virtualenv everywhere.

SurgicalOntologist
Jun 17, 2004

/\ /\ Also you, use conda.

Trees and Squids posted:

Has anyone had any success installing pandas on a virtualenv? I'm on Ubuntu 14.04 and cannot do it. StackOverflow is not helping me. I have no idea what any of the error messages I'm receiving mean. This comes up in angry red:

Never had trouble, even back when I was using pip + virtualenv.

What is /root/divsnipe? Are your virtulanevs somehow requiring root access? That kind of defeats the purpose.

In any case, use conda (conda.pydata.org) and your troubles will be over.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


I'm tinkering with learning some client-server communications stuff (a controller client talking to a process manager on the server, in this case--starting/stopping/monitoring long term calculations, basically). I'm a rank newbie at communication of any sort, though. For the current scenario my client program would be in either C# or Java, running on Windows; the server would be on Linux (RHEL 6.5 if that matters), in C++. Given these, are good old BSD sockets (System.Net.Sockets in .NET, socket.h in C) going to be the course I have to take? Or are there other options for both sides I can/should try to learn?

If it ends up being pure BSD sockets, about all I know with them is how to write an echo program (again, client in C#, server in C++). Any advice or links on how (not to) go about organizing this so it's not a nightmare later?

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Ciaphas posted:

I'm tinkering with learning some client-server communications stuff (a controller client talking to a process manager on the server, in this case--starting/stopping/monitoring long term calculations, basically). I'm a rank newbie at communication of any sort, though. For the current scenario my client program would be in either C# or Java, running on Windows; the server would be on Linux (RHEL 6.5 if that matters), in C++. Given these, are good old BSD sockets (System.Net.Sockets in .NET, socket.h in C) going to be the course I have to take? Or are there other options for both sides I can/should try to learn?

If it ends up being pure BSD sockets, about all I know with them is how to write an echo program (again, client in C#, server in C++). Any advice or links on how (not to) go about organizing this so it's not a nightmare later?

Is there a high performance requirement for the communication? If not, you can probably simplify a lot of it with something like Websockets & JSON objects. It has overhead, but has easily used patterns and libraries for any language/platform you could be using.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Skandranon posted:

Is there a high performance requirement for the communication? If not, you can probably simplify a lot of it with something like Websockets & JSON objects. It has overhead, but has easily used patterns and libraries for any language/platform you could be using.

For the communications, not at all. Thanks, that gives me some stuff to start googling for.

Steve French
Sep 8, 2003

Websockets and JSON may be easier, and this suggestion may be overkill for what you're trying to do, but I personally really prefer *not* using HTTP/JSON for anything that doesn't need to be accessible via a web browser or third parties.

If you're so inclined, consider checking out https://thrift.apache.org/

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

ufarn posted:

This doesn’t seem to have done the trick - both the `sudo -H` trick and the chown one. For the latter, neither of the directories existed, so maybe something is wrong with the way pip is set up at the moment; `which pip` yields /usr/local/bin/pip, which should probably be pointing to my user dir?

My UNIX-fu is pretty awful, so how do I go about fixing this - short of just ignoring the problem by using virtualenv everywhere.

You probable forgot to source your virtualenv.

Thermopyle
Jul 1, 2003

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

Steve French posted:

Websockets and JSON may be easier, and this suggestion may be overkill for what you're trying to do, but I personally really prefer *not* using HTTP/JSON for anything that doesn't need to be accessible via a web browser or third parties.

If you're so inclined, consider checking out https://thrift.apache.org/

What is the reason for this?

Steve French
Sep 8, 2003

Thermopyle posted:

What is the reason for this?

The reasons I prefer using Thrift when I can (and to be clear, not advocating that he or anyone else should be using it over JSON, just throwing it out there as an option for those who might not be aware of it. I'm also not really a web developer, so there may be some tools for JSON that accomplish some or all of these goals that I'm not aware of):

I like having a schema. Defined in a central place, it makes it much clearer to someone writing/using a client what the requests should look like, and what the responses will look like. It's also helpful that it is actually enforced, and makes it a lot easier to avoid inconsistencies between the client and server, especially when they're written in different languages. Being able to explicitly specify that particular fields are required or optional is especially useful.

Schema versioning is also nice: while it's not a brainless process, it helps a lot for making backwards compatible changes to components using the thrift definition without having to necessarily change all of them at once.

Thrift generates native types in a lot of different languages for all of the structures, constants, and service interfaces that you define, which means a lot less boilerplate to write (potentially multiple different times, if a number of different languages are in use in your system).

The transport and protocol are pluggable, and though I don't have a whole lot of experience with swapping them out (my use has mostly been framed transport and binary protocol), in theory you could still use it with HTTP and JSON.

For a small one off project, I suppose probably not worth using, since there's a bit of work to get it set up the first time and the advantages are stronger when you're writing multiple clients. I should also note that most or all of the above are also applicable to protocol buffers and Avro, and probably others, though I don't have a lot of experience with protocol buffers and even less with Avro.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me
It's hard to get simpler than Websockets for bi-directional communication. Client pushes some string, onMessage(string) gets called on server. Server pushes string, onMessage(string) gets called on client. Add in serialized JSON objects, and you can now easily send full objects back and forth with minimal effort.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





i used to be a thrift contributor and while it has it's uses i think that for 95% of use cases you are better off going with http and json (or xml, i guess) for any sort of internal network api. the tooling and infrastructure is just so much better than what thrift/protobufs can offer. http frameworks in all languages are light years ahead of the codegen that thrift/protobufs have built in and you get pretty major features like auth, caching and sessions almost for free. your client for development is curl or your browser instead of some generated header file you need to wire up to use

the schemas you get with thrift/protobufs are nice, but you can get the same thing from jsonschema or avro or something similar

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


By protobuf you mean google protocol buffers, right? Just making sure I have the right search terms :v:

It appears WebSockets aren't supported, client or server, in .NET on Windows 7, even if you're at the latest framework; you just get stubbed out/abstract classes. That's... odd. Should I be using something else on the client (C#) end or is there a third-party implementation I can use (initial googling shows websocket-sharp on github, maybe)? What about the C++ side, any particular implementations? Looks like websocketpp is the first hit.

Sorry for the Let Me Google That For You questions, my work internet is spotty as heck right now (this is the fourth time I've tried this reply)

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Ciaphas posted:

By protobuf you mean google protocol buffers, right? Just making sure I have the right search terms :v:

It appears WebSockets aren't supported, client or server, in .NET on Windows 7, even if you're at the latest framework; you just get stubbed out/abstract classes. That's... odd. Should I be using something else on the client (C#) end or is there a third-party implementation I can use (initial googling shows websocket-sharp on github, maybe)? What about the C++ side, any particular implementations? Looks like websocketpp is the first hit.

Sorry for the Let Me Google That For You questions, my work internet is spotty as heck right now (this is the fourth time I've tried this reply)

It should be available in .NET 4.5, https://msdn.microsoft.com/en-us/library/system.net.websockets.websocket(v=vs.110).aspx

I think you just need to inherit from the provided Websocket class and implement the remaining few methods, like onMessage.

Here's how to write one from scratch with TcpListener
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_server

Can't really answer the C++ side, been over 10 years since I touched that.

JawnV6
Jul 4, 2004

So hot ...
We're using protobufs, for our data it was a huge savings on JSON encoding (201b down to 56b). Easy to spin up encoder/decoders across Python, scala, C.

Are websockets more than "use two different garden-variety sockets for tx/rx so waiting on ACK doesn't apply backpressure?"

FAT32 SHAMER
Aug 16, 2012



I'm getting the cannot resolve symbol R in Android Studio for using Roboguice's InjectView, for example:

Java code:
@InjectView(R.id.input_name) EditText _nameText;
I have synced my build.gradle (Module: app) file and it still isn't being recognized, did I gently caress it up somehow?

code:
dependencies {
		compile 'com.android.support:support-v4:22.2.1'
		compile fileTree(dir: 'libs', include: ['*.jar'])
		compile 'com.android.support:appcompat-v7:22.2.0'
		compile 'com.android.support:design:22.2.0'
		compile 'com.jakewharton:butterknife:6.1.0'
}

Sedro
Dec 31, 2008
I don't know anything about android or roboguice, but are you sure you added the dependency?

https://github.com/roboguice/roboguice/wiki/InstallationGradle

FAT32 SHAMER
Aug 16, 2012



Sedro posted:

I don't know anything about android or roboguice, but are you sure you added the dependency?

https://github.com/roboguice/roboguice/wiki/InstallationGradle

Oh god dammit :doh:

Ironically, this still didn't fix the issue, so I'm still up a tree. Maybe I won't bother with these fancy plugins and instead just write a lot more code.

edit: i figured it out, my logo.gif had a capitalized L and for whatever reason it wouldnt sync all the way

FAT32 SHAMER fucked around with this message at 02:41 on Jan 27, 2016

mad_Thick
Aug 4, 2014
Hey all, I'm taking Intro to Programming this quarter, and we're doing Python. I'm working on an assignment, and I have been having trouble with it.

Here's what the assignment is asking...

Write a function called pq that, given values for the seven parameters listed below, computes the corresponding preparedness quotient PQ.
Here's how the parameters must be ordered in the function header:

pq(i s c pn pa d n)

I = importance of event (1-10 with 10 being "singing national anthem at the Super Bowl")
S = number of hours of sleep you had last night
C = shots of espresso or other stimulants consumed
Pn = hours of preparation needed to excel
Pa = hours you actually spent preparing
D = difficulty of the subject matter (1-10 with 10 being "quantum physics")
N = level of nervousness (1-10 with 10 being "tightrope walking across Grand Canyon")

Here are some examples of how your function should work:
>>> pq(6,8,2,5,3,5,7)
0.8888888888888888
>>> pq(6,8,2,5,5,5,7)
1.4814814814814814


So far, this is what I've come up with...

def pq(i,s,c,pn,pa,d,n):
denominator = 8 * pa * (s + c)
numerator = 3 * pn * (d + n + i)
return denominator/numerator

def main():
i = float(input("On a scale of 1 to 10, what is the level of importance of the event: "))
s = float(input("How many hours of sleep did you get last night? "))
c = float(input("How many shots of espresso or other stimulants have you consumed? "))
pn = float(input("How many hours of preparation are need to excel? "))
pa = float(input("How many hours did you ACTUALLY spend preparing? "))
d = float(input("On a scale of 1 to 10, what is the difficulty of the subject matter? "))
n = float(input("On a scale of 1 to 10, how nervous are you? "))
print ("Your prepardness qoutient is: " + (pq))

main()


I know the error is in print ("Your prepardness qoutient is: " + (pq)). I'm sure my code is all effed up, but I really have no idea what I'm doing, and mostly trying to emulate an example. Any help would be greatly appreciated.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

You defined the function but you didn't call it. Look at the examples to see what the syntax for calling a function looks like, then use that with your variables when you want to actually calculate the result.
e: Also, use the
code:
[code]
tag for posting source, so you can preserve indentation.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

mad_Thick posted:

Hey all, I'm taking Intro to Programming this quarter, and we're doing Python. I'm working on an assignment, and I have been having trouble with it.

Here's what the assignment is asking...

Write a function called pq that, given values for the seven parameters listed below, computes the corresponding preparedness quotient PQ.
Here's how the parameters must be ordered in the function header:

pq(i s c pn pa d n)

I = importance of event (1-10 with 10 being "singing national anthem at the Super Bowl")
S = number of hours of sleep you had last night
C = shots of espresso or other stimulants consumed
Pn = hours of preparation needed to excel
Pa = hours you actually spent preparing
D = difficulty of the subject matter (1-10 with 10 being "quantum physics")
N = level of nervousness (1-10 with 10 being "tightrope walking across Grand Canyon")

Here are some examples of how your function should work:
>>> pq(6,8,2,5,3,5,7)
0.8888888888888888
>>> pq(6,8,2,5,5,5,7)
1.4814814814814814


So far, this is what I've come up with...

def pq(i,s,c,pn,pa,d,n):
denominator = 8 * pa * (s + c)
numerator = 3 * pn * (d + n + i)
return denominator/numerator

def main():
i = float(input("On a scale of 1 to 10, what is the level of importance of the event: "))
s = float(input("How many hours of sleep did you get last night? "))
c = float(input("How many shots of espresso or other stimulants have you consumed? "))
pn = float(input("How many hours of preparation are need to excel? "))
pa = float(input("How many hours did you ACTUALLY spend preparing? "))
d = float(input("On a scale of 1 to 10, what is the difficulty of the subject matter? "))
n = float(input("On a scale of 1 to 10, how nervous are you? "))
print ("Your prepardness qoutient is: " + (pq))

main()


I know the error is in print ("Your prepardness qoutient is: " + (pq)). I'm sure my code is all effed up, but I really have no idea what I'm doing, and mostly trying to emulate an example. Any help would be greatly appreciated.

A function with 7 parameters? Who designed this question? This is all sorts of badness right at the beginning...

Anyways, I don't see you actually calling pq anywhere. You assign a bunch of variables, then try to use pq like a variable. You probably want a "result = pq(i,s,c,pn,pa,d,n)", then you can print the value of result.

b0lt
Apr 29, 2005
Also, you're dividing the denominator by the numerator.

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:

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What's a good way to play around with database data?

I'm basically trying to clean up a bunch of data from 3-4 different legacy databases. Find duplicates (that aren't exact), find people's names (as compared to company names), change some naming conventions, just all kinds of random stuff.

I can get the data all in CSV format and then plunk it into a MySQL database and then export it into another CSV for the final import into a new system.

I'm dreaming of something like MySQL workbench combined with Python or Ruby. I know I can just use a raw Python/Ruby program to read in the CSV or worth with the database but I want a guy in Helpdesk to be able to help me with some of the stuff and I don't want confuse him by making him learn how to interact with databases or CSV files in languages he's new to.

Sedro
Dec 31, 2008
OpenRefine is pretty good

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LINQPad, but I'm guessing that's not on the table based on the languages you mentioned :)

NihilCredo
Jun 6, 2011

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

2nding the LINQPad suggestion.

If you can do your data processing in just plain SQL, and it sounds like you probably can, then SQLite Browser is effortless, cross-platform, and can import/export CSV files (that one is actually built into the SQLite libraries).

NihilCredo fucked around with this message at 22:41 on Jan 27, 2016

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Hey all, I have a somewhat basic bash question: I have a .bin file that contains the configuration one or more processes, each of which contain four lines with hundreds of characters each line. I'm trying to figure out the best bash-compatible line to search for a specific pattern and only edit the second line that matches the pattern at a specific character position (line 2, character 175). Because there can be multiple process configurations within the same file, I need to be able to search via pattern and edit the second line of that result, not necessarily just the second line (ie. line 2, 6, 10, etc).

Through trial and error I have determined that this line typically contains one of two unique patterns I can search for using sed to replace, which works at the moment but I have a suspicion it could come back to bite me in the rear end and I want to know if there's a better way.

Right now I am using the following:

sed -i "/${i}/s/AO J/DO J/1" /tmp/TASK.bin
sed -i "/${i}/s/A J/D J/1" /tmp/TASK.bin

($i is the pattern name called from an array)

Any help would be appreciated.

ToxicFrog
Apr 26, 2008


PierreTheMime posted:

Hey all, I have a somewhat basic bash question: I have a .bin file that contains the configuration one or more processes, each of which contain four lines with hundreds of characters each line. I'm trying to figure out the best bash-compatible line to search for a specific pattern and only edit the second line that matches the pattern at a specific character position (line 2, character 175). Because there can be multiple process configurations within the same file, I need to be able to search via pattern and edit the second line of that result, not necessarily just the second line (ie. line 2, 6, 10, etc).

Through trial and error I have determined that this line typically contains one of two unique patterns I can search for using sed to replace, which works at the moment but I have a suspicion it could come back to bite me in the rear end and I want to know if there's a better way.

Right now I am using the following:

sed -i "/${i}/s/AO J/DO J/1" /tmp/TASK.bin
sed -i "/${i}/s/A J/D J/1" /tmp/TASK.bin

($i is the pattern name called from an array)

Any help would be appreciated.

I'm not clear what you're trying to do here. You want to edit the second line of all process configurations that match a given pattern? Is the pattern guaranteed to be in the second line as well, or the first line, or could it appear in any of the lines? You want to edit the second line at a given character offset, but in your example you're replacing a pattern instead?

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
I'm looking for a way to display currently opened tickets (in Remedy) that are critical in nature.

We have personnel that send out the alert communications and they use an email template

code:
Critical - <Application> - Active - <TicketNumber> - <Bridge Number>

Application(s):   <Application>
Summary:   <Summary>
Status:   <Status>
Assigned Group / Assignee:   <Assigned Group>
Incident Coordinator:   <Coordinator>
System Available:   <Y/N>
Basically a window I could put up somewhere that populates a line with
<TicketNumber> - <Application> - <Status> - <Coordinator> - <Summary>

And to remove said line item once an email goes out that has "Status: Resolved"

I;m not sure if this would be an email scrubber, or something that pulls out of Remedy

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

ToxicFrog posted:

I'm not clear what you're trying to do here. You want to edit the second line of all process configurations that match a given pattern? Is the pattern guaranteed to be in the second line as well, or the first line, or could it appear in any of the lines? You want to edit the second line at a given character offset, but in your example you're replacing a pattern instead?

My example is what I'm currently using that works because the pattern is likely rare, but I cannot guarantee in the future it won't appear prior to the one I want to replace. It would be safer to properly replace only the character, but I'm not sure how to get it to only read lines containing a pattern and then modify the second returned line at position 175.

Edit:
Here's an example file with three processes defined (SBSA_UXINS, SBSA_UXIMP, and SBSA_FRCST). As you can see, there's a ton of empty space and data in a specific format (I've removed some information to avoid breaking tables). You can see the pattern I search for on the second line of each process.

code:
TACHES     00          000U_ITOWTC32SBSA_FRCST000                         0000A0000                         
TACHES     00          000U_ITOWTC32SBSA_FRCST000                         0001D0892T              X00          000U_ITOWTC32SBSA_FRCST000 999999999999999999999900000000000000AO J 0100{00....
TACHES     00          000U_ITOWTC32SBSA_FRCST000                         0000F0001                     
TACHES     00          000U_ITOWTC32SBSA_UXIMP000                         0000A0000              
TACHES     00          000U_ITOWTC32SBSA_UXIMP000                         0001D0892T              X00          000U_ITOWTC32SBSA_UXIMP000 999999999999999999999900000000000000AO J 0100{00.....
TACHES     00          000U_ITOWTC32SBSA_UXINS000                         0000A0000                                                         
TACHES     00          000U_ITOWTC32SBSA_UXINS000                         0001D0892T              X00          000U_ITOWTC32SBSA_UXINS000 999999999999999999999900000000000000AO J 0100{00.....

PierreTheMime fucked around with this message at 19:57 on Jan 30, 2016

ToxicFrog
Apr 26, 2008


You said that there are three processes defined, and earlier you said that there are four lines per process, but there's a total of seven lines in that example. :psyduck:

Also, when you say "only read lines containing a pattern and then modify the second returned line", do you mean "for each line containing that pattern, modify the line immediately after that in the file", or do you mean "modify the next line that contains that pattern, ignoring intervening lines"?

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

ToxicFrog posted:

You said that there are three processes defined, and earlier you said that there are four lines per process, but there's a total of seven lines in that example. :psyduck:

Also, when you say "only read lines containing a pattern and then modify the second returned line", do you mean "for each line containing that pattern, modify the line immediately after that in the file", or do you mean "modify the next line that contains that pattern, ignoring intervening lines"?

Yeah, apparently I clipped the code so it doesn't present all twelve lines, but the first two of each are there and that's the important bit. I want to modify the second line returned when searching for a specific pattern, and that modification will occur at exactly the 175th character.

For example, in the text I gave, if I want to update process SBSA_UXINS, it would change the following:

quote:

TACHES 00 000U_ITOWTC32SBSA_FRCST000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_FRCST000 0001D0892T X00 000U_ITOWTC32SBSA_FRCST000 999999999999999999999900000000000000AO J 0100{00....
TACHES 00 000U_ITOWTC32SBSA_FRCST000 0000F0001
TACHES 00 000U_ITOWTC32SBSA_UXIMP000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_UXIMP000 0001D0892T X00 000U_ITOWTC32SBSA_UXIMP000 999999999999999999999900000000000000AO J 0100{00.....
TACHES 00 000U_ITOWTC32SBSA_UXINS000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_UXINS000 0001D0892T X00 000U_ITOWTC32SBSA_UXINS000 999999999999999999999900000000000000DO J 0100{00.....

Presumably the easiest way to manage this is to reduce the search using the name of the process, so it would be reduced to:

quote:

TACHES 00 000U_ITOWTC32SBSA_UXINS000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_UXINS000 0001D0892T X00 000U_ITOWTC32SBSA_UXINS000 999999999999999999999900000000000000AO J 0100{00.....

At which point it would jump to the second returned line at position 175 and replace the character there with a D.

quote:

TACHES 00 000U_ITOWTC32SBSA_UXINS000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_UXINS000 0001D0892T X00 000U_ITOWTC32SBSA_UXINS000 999999999999999999999900000000000000DO J 0100{00.....

As I mentioned, the command I use now works because the pattern is fairly unique, so what it does currently accomplishes the job but in a "dirty" way that might bite me later if that same pattern occurs earlier in the data.
sed -i "/${i}/s/AO J/DO J/1" /tmp/TASK.bin & sed -i "/${i}/s/A J/D J/1" /tmp/TASK.bin produces this:

quote:

TACHES 00 000U_ITOWTC32SBSA_UXINS000 0000A0000
TACHES 00 000U_ITOWTC32SBSA_UXINS000 0001D0892T X00 000U_ITOWTC32SBSA_UXINS000 999999999999999999999900000000000000DO J 0100{00.....

ToxicFrog
Apr 26, 2008


There's probably a way to do this with sed, but I'm not good enough.

You can do it with awk, though:


code:
# replacer.awk
# run me with: awk -v process_name=SBSA_UXINS -v replace_with=D -f replacer.awk

(flag == 1) && $0 ~ process_name {
  $0=(substr($0,1,173) replace_with substr($0,175,length($0)));
  flag=2;
}
(flag == 0) && $0 ~ process_name { flag=1; }
{ print $0; }
awk doesn't support -i/--in-place, so you'll need to use a temporary:

code:
$ awk -v process_name=SBSA_UXINS -v replace_with=D -f replacer.awk < task.bin > task.tmp
$ mv task.tmp task.bin
As always, double-check the output, I haven't tested this super rigorously.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

ToxicFrog posted:

There's probably a way to do this with sed, but I'm not good enough.

You can do it with awk, though:


code:
# replacer.awk
# run me with: awk -v process_name=SBSA_UXINS -v replace_with=D -f replacer.awk

(flag == 1) && $0 ~ process_name {
  $0=(substr($0,1,173) replace_with substr($0,175,length($0)));
  flag=2;
}
(flag == 0) && $0 ~ process_name { flag=1; }
{ print $0; }
awk doesn't support -i/--in-place, so you'll need to use a temporary:

code:
$ awk -v process_name=SBSA_UXINS -v replace_with=D -f replacer.awk < task.bin > task.tmp
$ mv task.tmp task.bin
As always, double-check the output, I haven't tested this super rigorously.

Thanks for the input--I'll give it a shot when I get a second. I've actually managed to never use awk before, but I figured that might be the route to go.

22 Eargesplitten
Oct 10, 2010



I'm trying to start unit testing, and I'm not sure what to use for my test cases. Should I figure out the possible cases for each button the user could push, and then test each one of those? Or am I making more work for myself than I need to?

Adbot
ADBOT LOVES YOU

Star War Sex Parrot
Oct 2, 2003

22 Eargesplitten posted:

I'm trying to start unit testing, and I'm not sure what to use for my test cases. Should I figure out the possible cases for each button the user could push, and then test each one of those? Or am I making more work for myself than I need to?
Read up on the concept of code coverage and decide how granular you want to get.

https://en.wikipedia.org/wiki/Code_coverage

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