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
qntm
Jun 17, 2009
Related: In Python a in [b, c, d] is equivalent to a == b or a == c or a == d, but it sometimes bugs me that you can't write a is in [b, c, d] to mean a is b or a is c or a is d. The best you can do is any(a is x for x in [b, c, d]).

Adbot
ADBOT LOVES YOU

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

code:
if (a `elem` [b, c, d]) then x

Thanks, why the hell didn't I think of that :v:

On a deeper topic, I'm currently working on combining Replace with folds, and I can't figure out how to implement the recursion.

Here's basically what I've got so far:
code:
foldReplace s y = foldr (\x acc -> replace x ("<TAG>" ++ x ++ "<TAG>") y) [] s
And it works. Kind of. It accepts a list of Strings as s, a longer String as y and then does... well, something. It seems what I get out of it is the version where just the last replacement has been made.

For instance, if I run it with
code:
s = ["1", "2", "3"]
y = ["1 2 3 4 5 6 7 8"]

-- output: "<TAG>1<TAG> 2 3 4 5 6 7 8"
And if I run it with s flipped, I get a similar result except 3 will be tagged. And I think the problem is that I'm not passing the modified y on to subsequent runs of foldReplace. But how would I do that? I don't know where to even begin with this type of folds :-/

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Well, your lambda is taking acc (the result of the last fold op) as an accumulator, but isn't doing anything to it, and is just applying the function to y.

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

Well, your lambda is taking acc (the result of the last fold op) as an accumulator, but isn't doing anything to it, and is just applying the function to y.

Yeah, in retrospect that is 100% obvious. It works fine now as

code:
foldReplace s y = foldr (\x acc -> replace x ("<TAG>" ++ x ++ "<TAG>") acc) y s


Oh well, on the upside I guess I am learning piece by piece, even though I feel like the world's biggest idiot most of the time :v:

ToxicFrog
Apr 26, 2008


TooMuchAbstraction posted:

That's just functions as first-class objects (or "first-class functions"). I guess using that specifically for an object constructor is like having an extremely bare-bones factory.

Or "first-class classes" -- in Python, for example, class definitions are callable but are not the same thing as functions. They are first-class values, though.

Sedro
Dec 31, 2008

qntm posted:

Related: In Python a in [b, c, d] is equivalent to a == b or a == c or a == d, but it sometimes bugs me that you can't write a is in [b, c, d] to mean a is b or a is c or a is d. The best you can do is any(a is x for x in [b, c, d]).
If you wanted identity, why would you implement equality in the first place?

qntm
Jun 17, 2009

Sedro posted:

If you wanted identity, why would you implement equality in the first place?

I don't remember the exact use case, but __eq__ had already been implemented and meant something other than object identity.

Linear Zoetrope
Nov 28, 2011

A hero must cook
What's the best way to remote edit files? I have some code I cannot run or test locally, due to dependency issues, so my workflow is:

edit -> git commit/push -> git pull from ssh'd terminal window -> run -> watch it crash and then repeat, with increasingly horrible commit messages

I mean, it's a solo project so a silly commit history isn't that much of a problem, it's just a bit inefficient and obnoxious. Using scp seems even more obnoxious. I tried some remote editing Sublime Text plugin, but it's not working well on Windows. MSYS2's version of vim is... not stellar and sometimes has some really bad behavior, and vim isn't really my favorite editor anyway.

JawnV6
Jul 4, 2004

So hot ...

Jsor posted:

What's the best way to remote edit files?
Sorry to presume the XY, but a few thoughts:
1) Are you sure you can't locally replicate things? VM, docker, etc. can't get you a local-ish version of your environment? I developed a small javascript utility using python to set up a local web server on 0.0.0.0:9999
2) scp replaces two of those steps (the git ones) and should be a common enough that you can wrap it up in a single command (scp workingdir/* host:/path/). What does "run" look like? Through the ssh'd terminal or accessing a web server?

Linear Zoetrope
Nov 28, 2011

A hero must cook

JawnV6 posted:

Sorry to presume the XY, but a few thoughts:
1) Are you sure you can't locally replicate things? VM, docker, etc. can't get you a local-ish version of your environment? I developed a small javascript utility using python to set up a local web server on 0.0.0.0:9999
2) scp replaces two of those steps (the git ones) and should be a common enough that you can wrap it up in a single command (scp workingdir/* host:/path/). What does "run" look like? Through the ssh'd terminal or accessing a web server?

ssh'd terminal. It's a hardware issue, I'm doing GPGPU stuff and my home card has memory issues.

The scp thing is possible, the problem is that the directory I'm scping to has a pretty long path I'd prefer not to remember/type, there's always `!scp`, but I've accidentally screwed stuff up before by absent-mindedly changing my working directory. I guess there's always a .sh file in each directory that's just an scp line, which is functional if inelegant.

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
...vim?

You can also execute commands via ssh directly, so e.g.

quote:

ssh user@host 'run command/to/very/long/path'
That way the command history (including the long path) is local and you don't have to re-type it each time you reconnect to the remote computer.

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED
I just X11 forward my IDE installed remotely. vim is my go-to for editing scripts. It's honestly not great but it works.

ExcessBLarg!
Sep 1, 2001

Jsor posted:

What's the best way to remote edit files?
Options:
  • Run "$EDITOR" on the remote.
  • Edit locally, rsync local changes to the remote. rsync > scp, since you can use the same command to sync the entire directory regardless of which file you edited.
  • SSHFS, if your local machine supports it. Mount the remote as a file system, edit locally, no need to sync.
  • Do the work in a network share, mount the network share, edit locally, no need to sync.

tazjin
Jul 24, 2015


ExcessBLarg! posted:

Options:
  • Run "$EDITOR" on the remote.
  • Edit locally, rsync local changes to the remote. rsync > scp, since you can use the same command to sync the entire directory regardless of which file you edited.
  • SSHFS, if your local machine supports it. Mount the remote as a file system, edit locally, no need to sync.
  • Do the work in a network share, mount the network share, edit locally, no need to sync.

Or using emacs with TRAMP. If you know Emacs it will be hard to find a more convenient way.

Peanut and the Gang
Aug 24, 2009

by exmarx
I need a open source tool to manage multiple nodejs instances. It'll boot 8 instances (or whatever I config it to), auto-restart each instance on crash or if mem usage exceeds 512mb (also configurable) and let me issue commands to monitor mem/cpu usage of all. Also, it'll ideally nodebalance (pun intended) to send incoming http requests to whichever instances are running correctly.
Know any programs that can do this?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
This'll be your guy I reckon:

https://github.com/Unitech/pm2

You could also just use supervisord or somethings, but pm2 is specific to node and probably a shoe in for getting what you want without too much effort.

Peanut and the Gang
Aug 24, 2009

by exmarx

Maluco Marinero posted:

This'll be your guy I reckon:

https://github.com/Unitech/pm2

You could also just use supervisord or somethings, but pm2 is specific to node and probably a shoe in for getting what you want without too much effort.

OOooooo, that looks nice. Thanks man!

ExcessBLarg!
Sep 1, 2001

Peanut and the Gang posted:

auto-restart each instance on crash
systemd or upstart can take care of this.

Peanut and the Gang posted:

mem usage exceeds 512mb
Memory leak?

systemd and upstart can be configured to limit the memory size of a task.

Thermopyle
Jul 1, 2003

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

Jsor posted:

What's the best way to remote edit files? I have some code I cannot run or test locally, due to dependency issues, so my workflow is:

edit -> git commit/push -> git pull from ssh'd terminal window -> run -> watch it crash and then repeat, with increasingly horrible commit messages

I mean, it's a solo project so a silly commit history isn't that much of a problem, it's just a bit inefficient and obnoxious. Using scp seems even more obnoxious. I tried some remote editing Sublime Text plugin, but it's not working well on Windows. MSYS2's version of vim is... not stellar and sometimes has some really bad behavior, and vim isn't really my favorite editor anyway.

I dunno what language you're using, but PyCharm has a nice remote mode that does lets you work on remote files and even use a remote interpreter on your local machine.

http://blog.jetbrains.com/pycharm/2015/03/feature-spotlight-python-remote-development-with-pycharm/

22 Eargesplitten
Oct 10, 2010



Am I right in thinking that the amount of time that a file takes to load is based on the size of the file, regardless of how resource-intensive the file will be once it loads? I had been thinking an AI file would load slower than a texture, but then I realized that the AI files are a fraction of the size of the textures or models in a modern game.

Linear Zoetrope
Nov 28, 2011

A hero must cook
Thanks for the remote suggestions, everyone.

22 Eargesplitten posted:

Am I right in thinking that the amount of time that a file takes to load is based on the size of the file, regardless of how resource-intensive the file will be once it loads? I had been thinking an AI file would load slower than a texture, but then I realized that the AI files are a fraction of the size of the textures or models in a modern game.

Load into memory? Yeah, it's purely* a function of how big the file is. This is ignoring any processing of the file you need to do, e.g. if you need to dynamically compile plugin code for your AI it may be slower, but a theoretical smaller-in-bytes texture may also be slower if you need to decompress it before use and so on.


* May not be pedantically accurate, obviously if they're stored on different types of disks etc etc

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Jsor posted:

* May not be pedantically accurate, obviously if they're stored on different types of disks etc etc

The magic words are "all else being equal".

ExcessBLarg!
Sep 1, 2001

22 Eargesplitten posted:

Am I right in thinking that the amount of time that a file takes to load is based on the size of the file, regardless of how resource-intensive the file will be once it loads?
Honestly it depends on the kind of file and the type of application.

Many file formats are designed so they don't have to be loaded into memory all at once. Of course in modern computers with many GB of RAM, it's not usually a problem to load the entire contents of files into memory; but even 20 years ago it was often impractical or infeasible to do so. As an example, the PDF format was designed so that a PDF reader can load and render a single page at once, regardless of the number of pages and overall size of the PDF file itself. That said, how long it takes to load (really, render) a single page of a PDF document depends greatly on the page contents, which if they include a lot of vector graphics, may involve a lot of complex data structures and drawing operations, but otherwise not necessarily take up much memory or disk space. I'm not as familiar with Illustrator itself, but I think that concept generally applies across vector graphic editors.

It's interesting to note that the predecessor to PDF, PostScript, is a fully complete (i.e., Turing-complete) programming language and thus, can take arbitrary long to render a single page.

Shaman Tank Spec
Dec 26, 2003

*blep*



Does Haskell offer any convenient way of picking out text between two substrings? The tagger I've worked on here for a while is working, and for further processing I'd want to be able to extract the tagged elements.

They are surrounded by elements in the format of
code:
Blah blah blah blah <ITEM="Weapon">Text Goes Here</ITEM> blah blah blah
And what I'd want out of this is:
code:
<ITEM="Weapon">Text Goes Here</ITEM>
The best way I've come up with is an unholy mess of splits, but it's very messy and inelegant. Plus from what I've seen Haskell doesn't actually offer an inclusive split, so I can't even say splitOn "<ITEM" without losing the tag.

Apparently regex would be very helpful for this but regex + Haskell is a mire I'd rather avoid if I can.

Shaman Tank Spec fucked around with this message at 20:09 on May 6, 2016

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
If you're getting this in-depth with text parsing in Haskell, you should probably just look into Parsec.

sarehu
Apr 20, 2007

(call/cc call/cc)
You're a programmer and an apex predator. Implement it yourself.

qntm
Jun 17, 2009

Jsor posted:

Using scp seems even more obnoxious.

I use WinSCP and Notepad++. Hitting Save automatically transfers the modified local temp file back to the remote machine. It's hardly a development environment but it does the job.

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

If you're getting this in-depth with text parsing in Haskell, you should probably just look into Parsec.

ThanKs, I might do.

The trouble with doing it manually is that splits seem kinda wonky if you're splitting at the beginning or end of a list.

Shaman Tank Spec
Dec 26, 2003

*blep*



sarehu posted:

You're a programmer and an apex predator. Implement it yourself.

Thanks for the pep talk, that's precisely what I did and it was surprisingly easy to do with just basic Haskell syntax. Once again a proper functional programmer would probably poo poo their pants and die at my code but it's done!

Amberskin
Dec 22, 2013

We come in peace! Legit!
Hello. I'm teaching myself Docker. I'm not sure this is the correct place to ask about it...

Problem: I've built a docker image to run the old systems simulator, simh (references http://simh.trailing-edge.com and git://github.com/simh/simh). That image is based on debian, plus a bunch of packages to actually build the simulators, including some network setup and the whole gcc. My specific question is how can I build an image which uses gcc to do the building but does not need it at runtime. In other words, how do I make available gcc at buildtime, but not at runtime.

Suposing that is posible at all.

Sedro
Dec 31, 2008

Amberskin posted:

Hello. I'm teaching myself Docker. I'm not sure this is the correct place to ask about it...

Problem: I've built a docker image to run the old systems simulator, simh (references http://simh.trailing-edge.com and git://github.com/simh/simh). That image is based on debian, plus a bunch of packages to actually build the simulators, including some network setup and the whole gcc. My specific question is how can I build an image which uses gcc to do the building but does not need it at runtime. In other words, how do I make available gcc at buildtime, but not at runtime.

Suposing that is posible at all.

A docker image is a diff of the image it's based on. As long as you delete the dependency when you're done, it won't bloat the image.

So on debian you would apt-get install --yes <stuff> && <do things> && apt-get purge --yes --auto-remove <stuff>

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
Is there any downside to basically always using Docker when working with simple projects? I like the idea of a sandboxed code that I can move to any of my dev machines and it's been working well for me the last couple weeks. However, it's possible that my regular workflow was just lovely and I wasn't good about using things like virtualenv to do this stuff anyway.

Amberskin
Dec 22, 2013

We come in peace! Legit!

Sedro posted:

A docker image is a diff of the image it's based on. As long as you delete the dependency when you're done, it won't bloat the image.

So on debian you would apt-get install --yes <stuff> && <do things> && apt-get purge --yes --auto-remove <stuff>

Thanks! That makes sense.

tazjin
Jul 24, 2015


IT BEGINS posted:

Is there any downside to basically always using Docker when working with simple projects? I like the idea of a sandboxed code that I can move to any of my dev machines and it's been working well for me the last couple weeks. However, it's possible that my regular workflow was just lovely and I wasn't good about using things like virtualenv to do this stuff anyway.

I do this a lot, there's a few quirks you will notice and take care of on your own over time but in general it's fine and makes life easier.

My personal machines run different distributions and Docker synchronises my dev environment smoothly.

IT BEGINS
Jan 15, 2009

I don't know how to make analogies

tazjin posted:

I do this a lot, there's a few quirks you will notice and take care of on your own over time but in general it's fine and makes life easier.

My personal machines run different distributions and Docker synchronises my dev environment smoothly.

Cool - I haven't run into anything too bad yet, my big concern right now moving forward is how to distribute command line apps if I primarily use Docker to maintain them. I'm not a fan of forcing Docker as a dependency if it's not a webapp, but if it makes my entire process better than probably the trade-off is worth it.

Boz0r
Sep 7, 2006
The Rocketship in action.
Can someone recommend me good books on software architecture, on different levels of abstraction?

tazjin
Jul 24, 2015


IT BEGINS posted:

Cool - I haven't run into anything too bad yet, my big concern right now moving forward is how to distribute command line apps if I primarily use Docker to maintain them. I'm not a fan of forcing Docker as a dependency if it's not a webapp, but if it makes my entire process better than probably the trade-off is worth it.

You should use distribution package systems for that because you want easy removal / upgrade paths for end-users.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

autotools question

I'm trying to cross compile a package from source which requires me to run autotools (autoreconf) to generate the ./configure script etc.
The problem is the tools dir that I have for the target device has its own libtoolize script, which is throwing errors since there are explicit path variables set from someone else's system. I don't know the first thing about autotools, is libtoolize in any way target-platform dependent or can i just delete this other guys script that is causing problems and let it run from my /usr/bin/libtoolize ?

MrMoo
Sep 14, 2000

What you might find is older versions have issues cross platform, so you need to cleanup and rebuild with a newer set, usually projects include some sort of bootstrap like script:
Sh code:
RUN $LIBTOOLIZE --force --copy
RUN aclocal
RUN autoheader
RUN automake --copy --add-missing
RUN autoconf
Where $LIBTOOLIZE is libtoolize or glibtoolize.

Adbot
ADBOT LOVES YOU

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

MrMoo posted:

What you might find is older versions have issues cross platform, so you need to cleanup and rebuild with a newer set, usually projects include some sort of bootstrap like script:
Sh code:
RUN $LIBTOOLIZE --force --copy
RUN aclocal
RUN autoheader
RUN automake --copy --add-missing
RUN autoconf
Where $LIBTOOLIZE is libtoolize or glibtoolize.

there's an autogen.sh script, which basically just calls autoreconf.

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