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
bitprophet
Jul 22, 2004
Taco Defender
Must be sed's interpretation of regex, I wasn't able to convince it to do what you want (not even anything as simple as '[0-9]+' was matching, so either I was being retarded in my sed usage or that's the aspect it doesn't support...?) but Python's RE library works fine, I think it's largely PCRE compatible:

quote:

re.findall(r'[0-9]+\(([0-9]{1,3})%',"16(100%)")
Out[5]: ['100']

Upon further investigation, it looks like you need the -E flag for sed to use extended regex instead of simple:

quote:

jeff@jeff.local:~ $ echo "16(100%)" | sed -Ee "s/[0-9]+\(([0-9]+)%\)/\1/"
100

EDIT: I used + instead of {1,3} there but same difference in this case :v: Also, I used + instead of * for the earlier part, which is probably better unless your input sometimes lacks the leading number entirely; I also removed the all-encompassing parentheses which I am pretty sure were extraneous :)

bitprophet fucked around with this message at 20:03 on Feb 28, 2008

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender
Yea, you probably managed to compile the CLI version of PHP without SSL support, but mod_php (which is often a separate package in package managers) with. I don't remember if phpinfo() gives meaningful output when run via CLI, but if it does, that should make it explicit - it would list the build args and all the modules it's got set up.

bitprophet
Jul 22, 2004
Taco Defender
According to the Pragmatic book on Ruby, it looks like constants are simply normal variables which raise a warning when changed. So you get the flexibility of being able to change them when desired (although, yes, I don't quite understand why one would not then use a normal variable...) but the extra rigidity of a warning being emitted when you do so.

bitprophet
Jul 22, 2004
Taco Defender
Your compsci professor was either misinformed or just out of date -- the Terminal.app that ships with OS X has been quite decent compared to average xterm since around 10.3/10.4, and is even better now in 10.5. Given that the X11 terminal looks and behaves like complete rear end, there's no reason to use it unless you're just using it to launch a GTK app like e.g. Wireshark.

bitprophet
Jul 22, 2004
Taco Defender

Plastic Jesus posted:

alias wireshark='open -a /Applications/Wireshark.app'

There is no reason to use xterm/iterm/anydamnedterm on OS X.

Sorry, I meant the wireshark that installs via MacPorts :v: I forget why I installed it that way and not via whatever gives you a nice shiny .app, but that's how it's set up v:shobon:v it's a GTK app and has to be launched in X11.

And, yea, it's rather difficult to avoid the terminal entirely, at least if you're a non-Cocoa developer or sysadmin.

bitprophet
Jul 22, 2004
Taco Defender
Regex is almost always the wrong answer to the question "how do I parse this HTML or XML?". Find an HTML parsing library, .NET must have one.

Of course, if you're dealing with actual HTML like that, which is not valid XHTML, I'm not 100% sure how such libs will perform, but I'm reasonably sure they'll still be able to deal with it for you.

bitprophet
Jul 22, 2004
Taco Defender

Runaway Five posted:

Okay, I feel really stupid You are 100% correct. Thank you. Man, this feels like the dumbest C++ thing I've done in a long time.

For what it's worth, some languages let you do this on the fly, although I don't remember the technical term for it (I believe there was one).

In Python, for example:
code:
>>> a = 25
>>> b = 50
>>> c = 75
>>> d = 100
>>> print a, b, c, d
25 50 75 100
>>> d, c, b, a = a, b, c, d
>>> print a, b, c, d
100 75 50 25
>>> 

bitprophet
Jul 22, 2004
Taco Defender

Scaevolus posted:

In Python this is called unpacking, and it works by making a tuple (a,b,c,d) and then unpacking it and doing the assignment to each variable. So it's the equivalent of making four temporary variables, and then doing the assignment.

Sounds about right; also fits with how higher level languages usually do things that are syntactically simpler than their lower level counterparts, but not necessarily any faster or more efficiently.

bitprophet
Jul 22, 2004
Taco Defender

A student posted:

I'm really excited about using computers to test models of society. Books like Nexus and Complex Adaptive Systems convinced me that this was something I needed to learn. Maybe the model would help demonstrate an idea. Maybe it would only provide an excuse to say "Dance, puppets. DANCE!" Either way, science, mad or otherwise, would progress.

Unfortunately I'm an end-user with mediocre math skills. One with more experience fiddling with hardware than fiddling with code. Worse than that, I'm a sociologist. Is it possible for the programming-ignorant to learn how to code relatively simple models?

Absolutely -- Python is generally recommended in this area -- it's used very heavily in the sciences, all kinds, from NASA to bioinformatics. Python combines simplicity (thus easy to learn) with power (thus able to express lots of stuff, and do a lot of processing without a lot of code) and this makes it really attractive for people who aren't necessarily professional programmers, but still want to use computers to model the stuff they're working on.

It can make use of C modules in the event that your particular modeling requires some highly performance-oriented code, too.

bitprophet
Jul 22, 2004
Taco Defender

Triple Tech posted:

My code is very intimate with the database. (It manages the data going in and cleans it up.) And it's getting very messy/cumbersome. So I was thinking about making an abstract layer between the business logic and the raw database calls, to make maintaining database changes a lot easier. So my code will just ask questions, without knowing how they're implemented, and this layer will obviously sit on a DB.

What's this layer called? I've heard this advice doled out many times, but now that I actually need it, I want to look up more definitive sources to make sure I'm not missing out on any patterns or practices.

An object-relational mapper (ORM) is typically what this is called, assuming I'm reading you correctly. Not sure what a non-object-oriented version would be called, if such things exist.

For example, Storm (I think it's...Java? Perl?) and SQLAlchemy or SQLObject (Python).

bitprophet
Jul 22, 2004
Taco Defender

Free Bees posted:

Ruby's libraries outside of web stuff are lacking and Ruby's execution speed up until a few weeks ago was too slow to do any serious computation (it's probably still slower than comparable languages). Sorry, I'm as disappointed as you are :(

I'd also wager that part of the reason is Python basically "got there first": it's extremely similar (interpreted, terse syntax compared to C++/Java/etc, powerful language constructs, etc) but has a much bigger/better built-in library plus a significantly larger pool of third-party libraries.

It's also as old or older, and probably as important, was more widely adopted in the English speaking world before Ruby managed to break out of Japan (which was really only in the mid '00s when Rails came out).

So my conjecture is that Ruby basically has no niche to fill outside of people who like Ruby because they've used Rails; the "want to script/do systems engineering/do non-C embedded work/etc/etc, without using Java or C++" niche was filled by Python beforehand, due to the above factors.

bitprophet
Jul 22, 2004
Taco Defender

Dijkstracula posted:

So I'm taking a computational differential equations class this term, which has a project component. I'd like to do my work in something that isn't Matlab. I assumed that any real scientific computing, based on the limited set of applications that I've used, would have to be written in some unholy alliance of C and Fortran. However, I came across SciPy and it sounds like they're trying to market Python of all things as a scientific computing language. Anybody have any thoughts about if this is a direction that things might go in, or is this nothing more than a bunch of Python dorks with Not Invented Here syndrome not wanting to link against LAPACK?

Uh. SciPy has been used for years and in some areas (like bioinformatics) Python is basically the king.

Like every other language, it does have its own share of NIHS, but SciPy is definitely not that, as far as I know :)

bitprophet
Jul 22, 2004
Taco Defender

Dijkstracula posted:

No kidding, I had no idea :) Great, that's good to hear. Thanks.

No prob, sorry for sounding acerbic, was kind of defensive given your "golly they're using Python for this?!" tone ;)

Python seems to do very well in academia, I'm assuming because it's got a very simple/easy syntax (so people who aren't CS professors can still pick it up pretty easily), while remaining powerful (so you can express your crazy scientific algorithms/ideas without writing tons of e.g. Java boilerplate) and with a seriously large amount of built-in and third-party libraries (like SciPy, PyGame, etc etc).

EDIT: Sorry for all the Python cheerleading I seem to do in this thread and others :shobon:

DOUBLE EDIT: To sate my own curiosity I looked up SciPy's SVN repo to see just how long they've actually been around; looks like the first commit to SVN was in 02/2001, so that's pretty decent as such things go.

bitprophet fucked around with this message at 23:11 on Feb 11, 2009

bitprophet
Jul 22, 2004
Taco Defender

ErIog posted:

I figured it out finally. Apparently the simple decompress function was not lofty enough for the data I was using. I had to create an object then call decompress from that. It's stupid as hell, but it works.

Few things in Python are "stupid as hell", although regrettably there are a number of things which could be explained more thoroughly (but Python's docs are still among the best I've ever seen). Put another way -- the split between zlib.decompress() and zlib.decompressobj().decompress() is almost definitely there for a reason, even if it's not an obvious one.

I found this in the doc for the method that gives you that decompression object:

The Python zlib docs posted:

Returns a decompression object, to be used for decompressing data streams that won't fit into memory at once.

Could your file be sufficiently large that it's eating up all your free memory (or conversely, if you're running this without much free memory to start with, the file doesn't need to be all that big)?

bitprophet
Jul 22, 2004
Taco Defender
I don't use tcsh, but, why not simply define a function (instead of an alias)? In my bash experience, anytime you find yourself cursing any limitation of the alias functionality, that's when you should be doing a function. Just a thought.

bitprophet
Jul 22, 2004
Taco Defender
I'm not 100% sure I follow what you were originally asking for, but if it's simply "echo before actually running a command" you could do something like this, again in bash syntax which may or may not work in tsch:
code:
function echo_then_do_something() {
    echo -e "\033[0;31mTEXT"
    /usr/bin/do_something $@
}
Which would do the echo, then call whatever you want, and the $@ (IIRC, and yet again may-be-different-in-tcsch) would pass in all arguments you give to the function, to the 'real' binary. E.g. echo_then_do_something foo bar results in /usr/bin/do_something foo bar.

bitprophet
Jul 22, 2004
Taco Defender

BigRedDot posted:

One other mention. If you are using the python shell at all you should really, really install ipython. They should honestly just make it the default python shell as it is so much better that the standard shell in every conceivable way (automatic debugger invocation, syntax highlighting, tab completion, command history, output cache, aliases, shell command access, doctest support, object exploration....)

Totally.


Click for full size

bitprophet
Jul 22, 2004
Taco Defender

Avenging Dentist posted:

Yes. I will leave it as an exercise to the reader to type "Python tutorial" into Google.
Oh, don't be a dick.

cannibustacap, while you should read the python.org tutorial and check the docs for the csv and datetime modules (i.e. the exact functions below may not be 100% accurate), this is roughly what it's going to look like in Python:
code:
import csv
from datetime import datetime
from time import mktime

reader = csv.reader(open('/path/to/my/file.csv'))

for line in reader:
    datetime_obj = datetime.strptime(line[<column index goes here>], "%m/%d/%y")
    timestamp = mktime(datetime_obj.timetuple())
    print(timestamp)
This would be less code if Python's datetime module wasn't a piece of poo poo. Please note that the rest of the language and stdlib is much better! :)

bitprophet
Jul 22, 2004
Taco Defender

pokeyman posted:

I agree 100%, but I'm sorta curious: what does a good datetime module look like? Any library I've ever used for dates has some annoying thing or other. (Though dates and times are annoying as poo poo and I'm pretty sure no excellent library exists for them.)

That's actually a great question, I don't think I've ever seen one that didn't have at least one major wart. I'm sure this is in part due to timekeeping being messed up in general, but still...

In looking around for the "datetime object => Unix epoch timestamp" bit that I put in, I found a discussion (involving none other than Tim Peters, in fact) pointing out that part of the issue is that the datetime object can encapsulate a number of potential dates which cannot be correctly translated into epoch timestamps.

But I still don't get why there's no ".to_timestamp()" method that simply raises a TypeError or similar for those bad dates, and returns a useful value otherwise :saddowns:


Avenging Dentist posted:

I'm not sure I understand the meaning of this sentence???

RTFM is all good and well, but it's not like it was hard to throw together a quick example of how (comparatively) easy it is to whip up a "read CSV, do date math" snippet in Python, and it's more likely to have a good outcome (i.e. another Python user.) Note that I did still tell him to RTFM...I just did it nicely. (Perhaps if I'd given it in almost-Python pseudocode, so it couldn't be copy/pasted, that would've been better, but meh.)

bitprophet
Jul 22, 2004
Taco Defender
I've had this kind of problem too; I just ended up installing gsed from MacPorts :sigh: (it's also in Homebrew as gnu-sed)

bitprophet
Jul 22, 2004
Taco Defender

Bob Morales posted:

Should I go back to Perl? Do people even still use it? Should I try something new and shiny like Python or whatever is 'in' right now?

Perl isn't well represented anymore except for its old standby of sysadmin-type scripts, though even there Python is eating some of its lunch. That said, there's still some folks using it and I know there's at least one or two Web-oriented frameworks/libraries for it somewhere, so if you try the below suggestions and feel Perl fits your brain best still, it's not a terrible choice -- it's just past its heyday.

Ruby is a popular near-direct descendant of Perl (and Smalltalk.) It has a cleaner syntax than Perl in many regards, while retaining a lot of what makes Perl so flexible (builtin regex, special vars, trailing if statements, etc etc.) Ruby has a significant presence in the Web space in the Ruby on Rails platform.

Python is also excellent for Web work (see: Django, Pylons, etc) and is also more widely applicable than Ruby for non-Web stuff, insofar as Ruby's ecosystem -- libs, users, documentation, etc -- is largely dominated by Rails. Python has a more spartan (but more readable, and just as powerful in most cases) syntax compared to Ruby or Perl. Might be a good contrast to what you're used to, and I know a number of folks who came to Python from Perl and loved it.

PHP is generally poo poo; don't use it. I and many others could elaborate, but generally, anyone intelligent doing serious work without a prior need for PHP such as its extreme ubiquity, its decent speed (if well written, which is rare) or a legacy codebase, avoids it.

bitprophet fucked around with this message at 02:16 on Mar 5, 2010

bitprophet
Jul 22, 2004
Taco Defender

Dijkstracula posted:

Make it into a plain old cronjob, or, if you're feeling like a more Pythonic ( :suicide: ) solution, you can look into the sched module, which I can't speak personally on.

Honestly, a cronjob is usually the most Pythonic way to run periodic tasks, because real Pythonistas know when the best tool for a job is one not written in Python :) And nothing says the cronjob can't be calling a Python script, of course.

bitprophet
Jul 22, 2004
Taco Defender

Pantsmaster Bill posted:

How would I create a function that prints its own definition? I've been given the problem in Haskell, but I can't figure how I would do it in any language, short of opening the file and printing from there.

Depends very much on the language's implementation, both in terms of whether it's even possible, and in terms of the specific methodology you'd use to obtain the source code.

Here's a Python example, though it only appears to work if defined in an actual on-disk file -- won't work in the interpreter. I assume this is because it's actually reading the file to get the source; this ain't exactly something one does in daily coding (unless you work in Lisp a lot I guess) v:shobon:v
code:
import inspect

def foo():
    print inspect.getsource(foo)

foo()

bitprophet
Jul 22, 2004
Taco Defender

Ziir posted:

Could you please elaborate?

The OS X platform is significantly more homogenous than the Linux/PC world, which for better or worse means that both development for it and use of it is going to be less fraught with problems (at the cost of choice/openness).

That's not to say that Linux these days is somehow bad for either of those things, but there's no way that an open source ecosystem targeting a myriad of possible hardware/software configurations is going to exhibit the same level of polish and ease of development/use as one produced by a single company targeting its own, comparatively tiny number of hardware and software configs.

In my experience, what it boils down to is your opinion of Apple's policies and/or the level of your desire to control the software you're using. For a lot of open source developers over the last 5-10 years, the "don't have to gently caress with anything to make things just work" aspect of OS X combined with the fact that its underlayer is a fairly traditional Unix has made it the ideal platform. The only software I've ever seen that is Linux exclusive is, as you might imagine, related to the Linux kernel itself.

(Apple's apparently-totally-awesome set of APIs for native application dev is also a major draw, even moreso nowadays with all the mobile junk going on. And even with the strides Ubuntu has made in OSS usability, it's still not quite there yet.)


Which is all just a :words: or :goonsay: way of expanding on what shrughes is saying.

bitprophet
Jul 22, 2004
Taco Defender

Avenging Dentist posted:

If you think it's likely that you'll be programming stuff that gets put on a cluster, use whatever OS the cluster uses (or as close to it as possible). Do you really want to deal with weird compiler issues because of Apple's customized (and frequently outdated) version of GCC?

Yea, I didn't read very closely. I do usually recommend people develop on their target platform when possible, it just makes the most sense. On the other hand, depending on exactly what's going on, a Mac may still be the best workstation platform and you can just use VMs for more easily targeting the deploy environment. Best of both worlds.


Ziir posted:

What text editors do you guys use with your Macs? I really like Notepad++ for Windows and I'm starting to get the hang on Vim on Linux.

I use Vim (not MacVim...terminal vim) on my Mac, but I'm a weirdo who likes the fact that his editor behaves 100% the same regardless of whether his terminal is open to a local tty or a remote one.

Most Mac-using developers I know or know of, use Vim or Emacs (either native or console versions) or TextMate, which is not free but is pretty darn tootin' for the price. (Just...don't try opening any large files in it. :laugh:)

bitprophet
Jul 22, 2004
Taco Defender

DholmbladRU posted:

thanks. Was an issue with the profiles.

It's extremely bad form to nuke your questions (and/or to not post your solutions) online -- what if some poor soul came by afterwards who had your same issue? They'd be up poo poo creek :(

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender

Reo posted:

The idea being that as you move from one node to another, nodes similar to that one pop up and you can just keep on navigating like that.

Mind map, I think.

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