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
Super Dude
Jan 23, 2005
Do the Jew
I fixed the problem. I reorganized how the binary/logical expressions were handled in my grammar and everything is good now. Thanks for the help guys!

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009
Is there an SQL for files? I mean, something like, SELECT linenum, line FROM file 'whatever.txt' WHERE line LIKE %foo% AND so on SORT BY line ASC LIMIT 10.

This isn't something that I need, I'm just curious whether anything like it might exist.

TasteMyHouse
Dec 21, 2006
grep?

No Safe Word
Feb 26, 2005

qntm posted:

Is there an SQL for files? I mean, something like, SELECT linenum, line FROM file 'whatever.txt' WHERE line LIKE %foo% AND so on SORT BY line ASC LIMIT 10.

This isn't something that I need, I'm just curious whether anything like it might exist.

awk + grep + sort

TasteMyHouse
Dec 21, 2006
Perl, Python, or Ruby will also do the job nicely

Munkeymon
Aug 14, 2003

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



If you really wanted to, you could even write a script to dump the file into an in-memory SQLite database and then run a query on that

JawnV6
Jul 4, 2004

So hot ...

pseudorandom name posted:

The ones that aren't listed as "microcoded" in AMD's optimization manual.

So by "everybody" you mean AMD. Gotcha.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

JawnV6 posted:

So by "everybody" you mean AMD. Gotcha.

I think he was having an Inigo Montoya moment wrt. microcode

JawnV6
Jul 4, 2004

So hot ...
Well, they're defining it this way:
  • FastPath Single - Decodes directly into one macro-op in microprocessor hardware.
  • FastPath Double - Decodes directly into two macro-ops in microprocessor hardware.
  • Microcode - Decodes into one or more (usually three or more) macro-ops using the on-chip microcode-engine ROM (MROM).
But I don't see how you could code LEAVE in less than 3 ops and I don't see why you'd proscribe against 'microcoded' instructions as a blanket recommendation anyway. It's not a very useful distinction at that granularity.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
PS I know this is kind of inside baseball, but do you know how life for AMD guys is? Luther Forest might be in my future due to location :(

JawnV6
Jul 4, 2004

So hot ...
Hit me up on IRC

Electrical Fire
Mar 29, 2010
I haven't had time to look through the thread, so sorry if this has been asked before. What is the best language to learn for the sake of having programming knowledge? Is there one language that is more extensively used, or perhaps one that will help you better understand programming in general? I've taken a course in C and one in C++; should I learn more about them or try something different?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
EF: Do you intend to do anything practical, or are you more interested in programming from a theoretical/puzzle solving perspective?

In my highly opinionated... opinion:
Lisp weenies would probably suggest Scheme is a great language for learning about programming from a high-level, abstract standpoint.
Java and C# are great general-purpose languages with libraries for drat near anything, but you often have to type a lot, and there are tons of awful examples online.
Python, Ruby, Perl and PHP are all more generally of the philosophy that common tasks should have short, cryptic solutions, to varying degrees of insanity.
Forth is fun if you like the idea of coding in assembly but making loops out of branches gets old too quickly.
C and C++ are useful if you see yourself going into the industry, but probably more trouble than they're worth if you just want to have fun.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah at this point I wouldn't learn C/C++ unless there is an intrinsic career reason to do so (e.g. a job) or a specific academic one. I learned both long ago and haven't used them in... ten years? ANSI C especially was helpful from a structure/discipline standpoint, but you can get that from other interpretation-light languages.

If you just want to screw around I'd suggest something in .NET if you don't have a problem with Microsoft. If you want to go deeper Java is a good choice, though with many frustrating/ineffable compromises. If you want a job quickly, sadly, PHP/ruby/etc. might be a good way to go.

Thermopyle
Jul 1, 2003

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

Internet Janitor posted:

Python, Ruby, Perl and PHP are all more generally of the philosophy that common tasks should have short, cryptic solutions, to varying degrees of insanity.

I'm far from a professional and don't have the background to make any assertions about this, so I'm curious about what you mean here WRT Python?

When I was first "learning programming" a few years ago, I stopped and started with a few different languages, but finally stuck with it once I tried Python because I found it amazingly un-cryptic.

raminasi
Jan 25, 2005

a last drink with no ice

Electrical Fire posted:

I haven't had time to look through the thread, so sorry if this has been asked before. What is the best language to learn for the sake of having programming knowledge? Is there one language that is more extensively used, or perhaps one that will help you better understand programming in general? I've taken a course in C and one in C++; should I learn more about them or try something different?

If you're willing to sink a shitload of time into it, I would really recommend working your way through SICP. It's going to be awhile until you get far enough into it that you'll be able to talk to people about programming "in general," though.

That being said, Python is regularly touted as a "good beginning language," although I don't know it myself.

TasteMyHouse
Dec 21, 2006
Python owns. Don't believe that guy who said it was cryptic -- at the core of the Python philosophy is making things clear, explicit, and obvious.


IMO, you shouldn't learn just one language. Learn a whole bunch at the same time! Pick two really different languages (for me, this was C++ and Python), and work through Project Euler or something -- when you figure out how to do something in one language, figure out how to do it in the other one. Try to understand what makes the two implementations different, try to think about what kind of design choices the language designers faced, etc. To be a good programmer you have to be able to think of things from several different angles at once, and working with multiple languages and trying to understand the WHY of them is good practice for that.

Electrical Fire
Mar 29, 2010
Thanks for all the advice. I'm actually an electrical engineering student, which is one reason why I want to have some programming knowledge.

I was already thinking about playing around with Python, and since it seems like it's thought highly of, for the most part, maybe I'll look into it when I find some free time. Hopefully I haven't forgotten everything I learned in C/C++.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


If you're EE, you're going to have to learn Matlab eventually anyway, so why not start now? The student edition is only about $100, and that'll be good enough for a while.

TasteMyHouse
Dec 21, 2006

ultrafilter posted:

If you're EE, you're going to have to learn Matlab eventually anyway, so why not start now?

Because MATLAB is a giant pile of poo poo and should be avoided at all costs

shrughes
Oct 11, 2008

(call/cc call/cc)
I don't "get" Agda. I'm doing exercise 2.2 of Dependently Typed Programming in Agda and I'm completely stuck.

quote:

Remember tabulate and _!_ from Section 2.4. Prove that they are indeed each other's inverses.

(a) This direction should be relatively easy.

code:
lem-!-tab : forall {A n} (f : Fin n -> A)(i : Fin n) ->
            tabulate f ! i == f i
lem-!-tab f i = {! !}

(Here are the definitions of tabulate and Fin and _!_)

code:
data Nat : Set where
  zero : Nat
  suc  : Nat -> Nat

data Fin : Nat -> Set where
  fzero : {n : Nat} -> Fin (suc n)
  fsuc  : {n : Nat} -> Fin n -> Fin (suc n)

_!_ : {n : Nat}{A : Set} -> Vec A n -> Fin n -> A
[]        ! ()
(x :: xs) ! fzero    = x
(x :: xs) ! (fsuc i) = xs ! i

tabulate : {n : Nat}{A : Set} -> (Fin n -> A) -> Vec A n
tabulate {zero} f = []
tabulate {suc n} f = f fzero :: tabulate (f o fsuc)

data _==_ {A : Set}(x : A) : A -> Set where
  refl : x == x
To me, it seems like the proper way to do this is to wave my hands and cry "refl!" and hope that the unifier figures it out. I don't get how to actually do this though.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

shrughes posted:

I don't "get" Agda. I'm doing exercise 2.2 of Dependently Typed Programming in Agda and I'm completely stuck.


(Here are the definitions of tabulate and Fin and _!_)

code:
data Nat : Set where
  zero : Nat
  suc  : Nat -> Nat

data Fin : Nat -> Set where
  fzero : {n : Nat} -> Fin (suc n)
  fsuc  : {n : Nat} -> Fin n -> Fin (suc n)

_!_ : {n : Nat}{A : Set} -> Vec A n -> Fin n -> A
[]        ! ()
(x :: xs) ! fzero    = x
(x :: xs) ! (fsuc i) = xs ! i

tabulate : {n : Nat}{A : Set} -> (Fin n -> A) -> Vec A n
tabulate {zero} f = []
tabulate {suc n} f = f fzero :: tabulate (f o fsuc)

data _==_ {A : Set}(x : A) : A -> Set where
  refl : x == x
To me, it seems like the proper way to do this is to wave my hands and cry "refl!" and hope that the unifier figures it out. I don't get how to actually do this though.

I can't promise you the exact Agda syntax right now as I don't have a compiler handy, but I'll walk you through the proof skeleton I'd use.

You have a function to tabulate, and a bounded index. Pattern match on the index.

If the index is zero, you're asking if tabulate f ! fzero == f fzero. This is a trivial consequence of the definitions of tabulate and !, and the unifier should handle it. For that case, simply provide the proof refl.

If the index is nonzero, you're asking if tabulate f ! (fsuc i) == f (fsuc i). This is nontrivial. If you walk the definitions of ! and tabulate slightly, you are asking if tabulate (f o fsuc) ! i == f (fsuc i). Consider g = f o fsuc. You can recurse using lem-!-tab g i to show that tabulate g ! i == g i. You need to show that g i can replace f (fsuc i), but because that's a trivial proof the unifier can handle it.

So your final proof should look something like this:

code:
lem-!-tab : forall {A n} (f : Fin n -> A)(i : Fin n) -> tabulate f ! i == f i
lem-!-tab f fzero = refl
lem-!-tab f (fsuc i) = lem-!-tab (f o fsuc) i

ShoulderDaemon fucked around with this message at 20:22 on Oct 5, 2011

MrMoo
Sep 14, 2000

GrumpyDoctor posted:

That being said, Python is regularly touted as a "good beginning language," although I don't know it myself.

I'm seeing listed in quite a few jobs these days, from Quants to HPC. BofA has some developer/architect positions in Python too:

http://careers.bankofamerica.com/Jo...y=&LocationID=0

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Electrical Fire posted:

Thanks for all the advice. I'm actually an electrical engineering student, which is one reason why I want to have some programming knowledge.

I was already thinking about playing around with Python, and since it seems like it's thought highly of, for the most part, maybe I'll look into it when I find some free time. Hopefully I haven't forgotten everything I learned in C/C++.

Yeah if you're EE you're probably going to be stuck with ANSI C for life if you're doing programming/design, just so many embedded systems. For a laugh check out the Coding Horrors thread, where the recent mantra is 'EEs are the world's second worst programmers (after dedicated academics)'.

Python is pretty neat, and relatively low investment to learn. I think what Internet Janitor meant about 'insanity' is that like all of those scripty languages there's the 'right' way, the 'easy' way, and the way you don't understand because you copied and pasted it off the internet. People using the latter two often ends up in code that's :psyduck: worthy.

Cynnik
Nov 19, 2002

this seems all too familiar
I am on OS 10.7.1

I spent a few hours last week setting up a bunch of network aliases.

I was dumb and smb'ed to the ip address rather than the host name before creating the aliases.

Is there a way I can effect all of these in bulk and change smb://xxx.xxx.xxx.xxx/porn to smb://host.name/porn ?

raminasi
Jan 25, 2005

a last drink with no ice

MrMoo posted:

I'm seeing listed in quite a few jobs these days, from Quants to HPC. BofA has some developer/architect positions in Python too:

http://careers.bankofamerica.com/Jo...y=&LocationID=0

Oh sure, I didn't mean to imply it wasn't good for anything else.

My own question: I've got a collection of flat surfaces in 3-dimensional space that form the facets of some arbitrary polyhedral solid with nothing "weird" about it (although it's not necessarily convex).

Now, my geometry library can assemble them into a representation of the solid that I can then perform boolean set operations on, which is what I eventually need. The problem is that it can only do this if they're all oriented the same, i.e. applying the right-hand rule to each of their vertex series yields vectors that all point the same way relative to the interior of the solid. (Alternatively, it will only work if there are no duplicate directed edges.) Unfortunately, I'm going to have to enforce this myself, but I can't think of an elegant way to do it. All I can think of is manually examining the set of directed edges and flipping the order of a surface if I encounter any duplicates, but that feels kind of brute-forcey. (Fortunately, I can get away with that - I won't encounter more than about twenty surfaces so performance isn't a huge issue.)

shrughes
Oct 11, 2008

(call/cc call/cc)

ShoulderDaemon posted:

So your final proof should look something like this:

code:
lem-!-tab : forall {A n} (f : Fin n -> A)(i : Fin n) -> tabulate f ! i == f i
lem-!-tab f fzero = refl
lem-!-tab f (fsuc i) = lem-!-tab (f o fsuc) i

That's how I was trying to prove it. It turned out my problem was that tabulate f ! i == f i should be (tabulate f ! i) == f i.

Nullsmack
Dec 7, 2001
Digital apocalypse
Visual Basic question, I'm using Visual Basic 2008 express edition. I am trying to figure out how to see when a mouse button is clicked anywhere on the screen but I'm running into a brick wall I guess. I see there are nice functions like SetCursorPos and GetCursorPos that can set/get xy coords easily. I see the mouse_event function that can let me send clicking events. How do I receive buttondown/buttonup events even if my form isn't visible or under the mouse cursor? I've been trying to make sense of the SetWindowsHookEx but then I see documentation that says it doesn't work globally?

Thanks for any help you can give.

Sedro
Dec 31, 2008
Use SetWindowsHookEx to inject a low-level mouse hook (WH_MOUSE_LL).

Nullsmack
Dec 7, 2001
Digital apocalypse

Sedro posted:

Use SetWindowsHookEx to inject a low-level mouse hook (WH_MOUSE_LL).

Thanks, I was thrown off by things saying global hooks weren't supported in .net
This worked perfectly, I just had to shut off the Close button and put my own exit button in.. the code I found for a low level mouse hook did override the finalize function to insert a command to shut down the hook.. but for some reason when I hit the close button it would freeze my mouse and the program for a few seconds. Doing it myself in my own exit button works perfectly though. Weird as hell.

All well, I can count mouse clicks now which makes me happy. :)

Sedro
Dec 31, 2008
My guess is closing the window kills the message loop, so your callback is no longer accessible by Windows. The finalizer runs eventually and your hook gets released. That is one of the dangers of hooks- if your process stops responding, input stops working.

You should have some event like OnClosed where you can stick your cleanup code. Generally you want to use the finalizer as a last resort, especially for critical cleanup. Check out the disposable pattern.

Nullsmack
Dec 7, 2001
Digital apocalypse
It merits further experimentation. I think at one point I followed someone's code to make a "are you sure you want to exit" box show up when you close the form.. but before it did show up, the finalize code ran to unhook the low level mouse hook and caused the program and my mouse to hang for a few seconds. Might just be stuck with having my own exit button unless I can figure out how to have the regular close "X" button setup to work like my exit button. It's not a big deal either way.

Ration
Dec 3, 2005

My mile could not pump the plumb
SQL Question:

I have a google maps API (v3) query dumped to an XML.

I have two tables. I'm calling a query to select all elements of one table and a few of the second.

The second table contains a "rating" field. There are multiple entries and I have the two tables linked by ID.

The two tables correspond, everything is fetching correctly, but it outputs the field "rating" as multiple entries. This causes me to have duplicates with (potentially) different output.

AVG will be the solution! So, I implemented the AVG(rating) AS ratingavg.

It is giving me the average of the entire table, as opposed to the results from the above search. I do not need the entire table to be averaged, just the ratings that apply to the query. How can I accomplish this?

I'm assuming that I'll have to use a case... but I'm clueless as to how to work it out. Google has failed me.

In short: I need the AVG(rating) of the resulting query, not the entire table.

code:

<?php
require("mydbshit.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT markers.name, markers.id, markers.address, markers.lat, markers.lng, markers.sname, markers.tele, markers.url, comments.page_id, FROM markers, comments WHERE markers.id = comments.page_id;"
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'sname="' . parseToXML($row['sname']) . '" ';
  echo 'tele="' . parseToXML($row['tele']) . '" ';
  echo 'url="' . parseToXML($row['url']) . '" ';
  echo 'ratingavg="' . parseToXML($row['ratingavg']) . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>

nielsm
Jun 1, 2009



Ration posted:

SQL Question:
You may be better off asking that in the SQL megathread :)

Ration posted:

I have two tables. I'm calling a query to select all elements of one table and a few of the second.

The second table contains a "rating" field. There are multiple entries and I have the two tables linked by ID.

The two tables correspond, everything is fetching correctly, but it outputs the field "rating" as multiple entries. This causes me to have duplicates with (potentially) different output.

AVG will be the solution! So, I implemented the AVG(rating) AS ratingavg.

It is giving me the average of the entire table, as opposed to the results from the above search. I do not need the entire table to be averaged, just the ratings that apply to the query. How can I accomplish this?

AVG() is called an aggregate function. Aggregates run over the entire dataset, unless you tell the database system how to the rows in the intermediate result set are related in groups.
(Other aggregate functions are COUNT, MIN and MAX.)

You need to add a GROUP BY clause to your query:
code:
SELECT markers.name,
       markers.id,
       markers.address,
       markers.lat,
       markers.lng,
       markers.sname,
       markers.tele,
       markers.url,
       comments.page_id,
       AVG(comments.rating) avgrating
FROM   markers,
       comments
WHERE  markers.id = comments.page_id
GROUP  BY markers.id
This tells the database system that all results with the same marker-id forms a single group, and aggregates must be performed over those groups.

You may also want to read up on joins, what you probably want to do here is not an inner join (as you are getting now) but more likely a left join, where even markers without comments are included in the result set.

mistermojo
Jul 3, 2004

To develop and publish an app for Blackberry, do I have to pay for anything?

I found posts talking about 200$ for 10 tokens, whatever that means, from about a year ago but I can't find anything about that on the Blackberry Developer Zone website.

Fridurmus
Nov 2, 2009

:black101: Break a leg! :black101:
I've been learning Ruby- both for Rails and other frameworks like it, and as a general scripting language. It's my first language period, and I've been enjoying it. But one thing I can't seem to find is any sign that people actually use the language for something -other- than Rails. Is Ruby just overshadowed by its best-known framework, and I'm not seeing the people using it otherwise? Or is it legitimately a one-trick pony, only otherwise useful for quick scripts? :v:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Ruby is known almost exclusively to the general programming-language-aware public as the language Rails is implemented in. But there's plenty more. For example, looking on GitHub (https://github.com/search?type=Repositories&q=language%3Aruby), I see:

homebrew, a package manager for Mac OS X
blueprint, a CSS framework
jekyll, a static site generator
chef, a systems integration thinger

In that search you'll undoubtedly notice that the proportion of Rails-related projects vastly exceeds any other group, but don't let that discourage you on Ruby. And (while it's in early stages) there are Ruby apps in the Mac App Store.

TasteMyHouse
Dec 21, 2006
homebrew owns. It's the kind of thing that makes me want to learn Ruby better... but I feel like I'm betraying Python

Sab669
Sep 24, 2009

Really dumb question from a really amateur programmer:

In C# (or in general, I suppose- but I'm most comfortable with C#), where exactly is the "best" place to put stuff that you'll end up using through out all of the application?

Specifically:
http://pastebin.com/7YvPRhUC

This is the first assignment we had to do for my XML class this semester, and I feel like I really shouldn't be creating a new XPathNav/Doc/NodeIterator in each function, but I'm not sure where the best/proper place to put it is.

edit; Hmm. When I first typed out that application, I typed everything out so that it'd all be executed in the button click handler, and it works fine. When I seperated it out into 3 different functions, the popItems function doesn't work properly. There are 3 items in the XML file, and when the popItems functions runs it only prints out the first of the three. Not really important- I can just ask my professor next class, but this struck me as really strange.

Sab669 fucked around with this message at 15:41 on Oct 12, 2011

Adbot
ADBOT LOVES YOU

TasteMyHouse
Dec 21, 2006

Sab669 posted:

Really dumb question from a really amateur programmer:

In C# (or in general, I suppose- but I'm most comfortable with C#), where exactly is the "best" place to put stuff that you'll end up using through out all of the application?

Specifically:
http://pastebin.com/7YvPRhUC

This is the first assignment we had to do for my XML class this semester, and I feel like I really shouldn't be creating a new XPathNav/Doc/NodeIterator in each function, but I'm not sure where the best/proper place to put it is.

edit; Hmm. When I first typed out that application, I typed everything out so that it'd all be executed in the button click handler, and it works fine. When I seperated it out into 3 different functions, the popItems function doesn't work properly. There are 3 items in the XML file, and when the popItems functions runs it only prints out the first of the three. Not really important- I can just ask my professor next class, but this struck me as really strange.

All those items that you're recreating over and over should be made instance variables.

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