Jump to content

Wikipedia:Reference desk/Archives/Computing/2012 November 30

From Wikipedia, the free encyclopedia
Computing desk
< November 29 << Oct | November | Dec >> December 1 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


November 30

[edit]

blender modelling

[edit]

Would it be possible to sculpt and rig a character in blender, move it into different positions and export those as .stl files, retaining all information on how the different parts are arranged?

86.15.83.223 (talk) 10:26, 30 November 2012 (UTC)[reply]

Yes, Blender can both export in .stl format and you can choose what to export (highlight in object mode). OsmanRF34 (talk) 11:11, 30 November 2012 (UTC)[reply]

URL of a single element on a web page

[edit]

Hi all,

I was wondering if it is possible to load a single element of a webpage in a browser? For example it is easy to just load a single image like www.example.com/example.jpg , but is it possible to just load the text "main page" on wikipedia, or in my case I need to load the text "As of Nov 28 2012" just below the graph at http://funds.ft.com/uk/Tearsheet/Summary?s=GB0003197281:GBX without loading all of the pesky ads/images and so forth. Essentially I have hundreds of similar pages and have automated reading that bit in VBA but it takes ages loading all the web page every time. If so, how would you acomplish this? Many thanks for any help given. 80.254.147.164 (talk) 13:16, 30 November 2012 (UTC)[reply]

It simply can't be done. You could see if the website has an API available to let you progamatically query things without loading all the HTML. What you're doing now is called screen-scraping, which is often against the TOS of a website. If you do it somewhat often the people running the site may notice and cut you off, and no matter what you'll be vulnerable to slight changes in the layout of the page breaking your code. 209.131.76.183 (talk) 13:53, 30 November 2012 (UTC)[reply]
You can't selectively pre-load specific data unless the website makes that explicitly available to you. Otherwise you have to just do what you're already doing. Though I'm confused as to why it "takes ages" — you should be able to just load the HTML first, then grab anything you want out of that, right? Without ads or images or whatnot. Your VBA code sounds inefficient. (We can help on that, if you post it.) --Mr.98 (talk) 14:03, 30 November 2012 (UTC)[reply]
How would I do that? All examples I have seen involve loading the page first then opening the HTML file. The relevant bit of my code is:
      URL = "http://funds.ft.com/uk/Tearsheet/Summary?s=" & ISIN & ":" & Curr
      With IE
        .Navigate2 URL
        .Visible = True  
      End With
     Do Until IE.readyState = READYSTATE_COMPLETE
     DoEvents
     Loop

80.254.147.164 (talk) 15:22, 30 November 2012 (UTC)[reply]

It looks like you're using VBA to drive IE, so it's IE loading the page. Presumably it's all the ancillary stuff you don't want on that page that's slowing things down. Slaving IE like this seems like a pretty desperate way of doing things when all you want is the HTML text itself. You'll surely get on much better having your program download the html itself. This MSDN article discusses web scraping in full Visual Basic. -- Finlay McWalterTalk 15:35, 30 November 2012 (UTC)[reply]
That looks like VB.NET to me, not VBA. Among the tip-offs is that VBA doesn't really do multithreading. --Mr.98 (talk) 00:27, 1 December 2012 (UTC)[reply]
What you are really asking VBA to do, if you just want the text content, is to make a simple HTTP request and then give you the contents. Here's a bare outline of how such a thing would work (this code was originally written for MS Access; it might take some adapting to use it in Word or Excel or whatever you are using; if you have difficulties, just Google the line that's giving you guff, or ask us on here):
Public Function http_Resp(ByVal sReq As String) As String

    Dim byteData() As Byte
    Dim XMLHTTP As Object

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")

    XMLHTTP.Open "GET", sReq, False
    XMLHTTP.send
    byteData = XMLHTTP.responseBody

    Set XMLHTTP = Nothing

    http_Resp = StrConv(byteData, vbUnicode)

End Function
Basically you past your URL to sReq and, in theory, it'll return the HTML of the URL in question. Then you'll need to process it (e.g. parse the XML; there are VBA APIs for this as well if you Google around a bit) and extract the value you want. Much quicker than trying to get IE to do it for you. --Mr.98 (talk) 00:27, 1 December 2012 (UTC)[reply]
I've managed to work that into my macro, but I am having trouble parsing the XML; it is very confusing as I'm not sure how alot of the links relate to my case. Currently I have the html as one massive string and am using InStr("Name of element") To find where the element is in the HTML string and then returning the value. Would parsing the XML be faster than this method (it currently can run through 60 ish websites a minute - ie one a second). 80.254.147.164 (talk) 14:22, 3 December 2012 (UTC)[reply]

Handling game state in VB

[edit]

I am writing a BlackJack Program in VB.NET. The game has 4 actions the player can take: Bet, Hit, Stand, and Deal. The player can only take some of these actions at certain parts during the game, for example, at the start of a new round you can only Bet, and not Hit, Stand or Deal. The actions you can take are tracked using properties: CanBet, CanHit CanStand and CanDeal. So for example, at the start of the round they are all set to false and CanBet is set to true. The UI handles a property changed event to update the state of the relevant buttons.

For example, here is the Bet routine:

    Public Sub Bet(ByVal amount As Integer)
 
        ResetPlayerActions()
        CanHit = True
        CanStay = True
 
        BetAmount = amount
        Me.Amount -= amount
        NewHand()
 
    End Sub

Is this the correct way to implement this behavior, or are there any design patterns that can do a better job.

86.40.42.232 (talk) 15:00, 30 November 2012 (UTC)[reply]

Maybe the abstraction of a Finite-state machine will help with this. For each state the game is in, only a certain subset of actions are allowed. Astronaut (talk) 18:26, 30 November 2012 (UTC)[reply]
Are there any conditions where you can hit but can't stand, or vice-versa ? If not, then a single variable will do.
Stylistically, I'd place the "CanHit = True" and "CanStay = True" lines after the "BetAmount = amount" and "Me.Amount -= amount" lines. It won't make any difference in the execution for non-objected oriented code, but it just seems more logical to enable the next actions after the bet has been placed and the hand has been dealt (did I miss where you did this ?). Under an object-oriented approach, setting those Boolean variables early might trigger play to start before the bet has been set. BTW, do splits, double-downs, insurance, and side bets have to wait for version 2.0 ? And I assume we reshuffle after every hand ? StuRat (talk) 19:21, 30 November 2012 (UTC)[reply]
You didn't say whether you wish to take an object-oriented approach or not. I assume VB.net gives you the choice. First, let me discuss the non-object oriented approach:
I seem to see a logic error. If "NewHand" is only called at the beginning of a hand, then there's no need to tell it you can hit and stay, as that's always the case at the beginning of a hand (I sure hope NewHand doesn't have a call to Bet, as that would make for an infinite loop). If you did want Boolean variables to flag when you can hit and stay, say to pass on to the next subroutine, then initializing those at the start of "NewHand" would make more sense than here. However, I suspect that what you call "NewHand" is actually intended to be called not only when the hand is new, but for each subsequent action, as well. In this case, initializing the values for "CanHit" and "CanStay" here is appropriate, but the name "NewHand" is not. It should be called something like "MakeMove", if it is indeed to be called for every move, not just the initial move.
In addition, you may be able to do away with the "CanHit" and "CanStay" variables entirely. They are only useful if the conditions you evaluate to determine whether you can hit or stay are remote from where you want to use those variables. If it's as simple as (in pseudocode) "if DealerPoints < 21 and MyPoints < 21", or (allowing for 5-card Charlies) "if DealerPoints < 21 and MyPoints < 21 and MyCards < 5", then just put that line where you would put "if CanHit".
I also don't think you need CanBet and CanDeal variables, as the dealing always happens directly after placing the bet. In Object-oriented programming they tend to do it this way, but, in a more traditional approach, you can just place the deal code after the bet code.
So, to summarize this all, let me suggest (non-object-oriented) pseudocode like this (only the subroutine names are listed):
MAIN
      .
      .
      .
 do until UserQuits: 
   MakeBet
        .
        .
        .
   DealCards
        .
        .
        .
   do while DealerPoints < 21 and MyPoints < 21 and MyCards < 5 and not UserStanding: 
     MakeMove
          .
          .
          .
   ComputeHandResults
        .
        .
        .
Of course, if you want to take advantage of the object-oriented approach, you can do that instead. That might look more like this:
 MAIN  
   CanBet = True
   CanDeal = False
   CanPlay = False
   HandOver = False
   UserHasQuit = False
   MakeBet (fires when CanBet is set to True)
        .
        .
        .
     CanBet = False
     CanDeal = True
   DealCards (fires when CanDeal is set to True)
        .
        .
        .
     CanBet = False
     CanPlay = True
   MakeMove (fires when CanPlay is set to True)
        .
        .
        .
      if DealerPoints ≥ 21 or MyPoints ≥ 21 or MyCards = 5 or UserStanding:
         CanPlay = False
         HandOver = True 
   ComputeHandResults (fires when HandOver is set to True)
        .
        .
        .
     HandOver = False
     if UserQuits:
       UserHasQuit = True
     else:
       CanBet = True
   UserQuit (fires when UserHasQuit variable is set to True) 
        .
        .
        .
StuRat (talk) 19:49, 30 November 2012 (UTC)[reply]
The game is it's own object, the window knows nothing of the game rules, it just enables/disables whatever actions the game says are available (via INotifyPropertyChanged). There are style problems which I intend to fix, I just what to mack sure I'm on the right track with this first.

BTW, do splits, double-downs, insurance, and side bets have to wait for version 2.0 ? And I assume we reshuffle after every hand ?

Yes they do. They are not on the Assessment Brief, so there's no marks for adding them. Shuffling is done only once, when the deck(s) is/are first created. This allows card counting! 86.40.42.232 (talk) 21:58, 30 November 2012 (UTC)[reply]
Also, it limits the number of hands you can play. With 52 cards in the deck and an average of maybe 6 cards per two-player hand, I'd only expect to get in maybe 8 hands. StuRat (talk) 22:24, 30 November 2012 (UTC)[reply]
You should probably start designing your code at a higher level first, where you list individual functions and what each will do, before getting into the details of where each variable is initialized. Have you done this yet ? StuRat (talk) 22:28, 30 November 2012 (UTC)[reply]
On the subject of packs of cards and shuffling, at the casino's I've played in the dealer has had perhaps as many as 8 decks in a shoe. A marker is placed someway towards the back of the shoe by one of the players and when the marker is reached all the cards are shuffled before the next round starts. Astronaut (talk) 18:58, 3 December 2012 (UTC)[reply]

Wireless icon origin, name, etc?

[edit]

Does the icon often associated with WiFi (not the Wi-Fi Alliance's logo) have an official name? Who came up with it and when? Is it copyrighted? Paganpan (talk) 19:50, 30 November 2012 (UTC)[reply]

My guess is it's rooted in the history of radio and wireless radios. I doubt whoever first came up with or popularized it bothered to take any credit. Iconography/symbology/graphic design wasn't exactly as important or career associated back then, I dare say. No doubt the history of people drawing invisible emanating "waves" from a particular point is about as old as drawing. ¦ Reisio (talk) 20:17, 30 November 2012 (UTC)[reply]

po files and plural forms

[edit]

Translating a website from English to Polish I am stuck at the following phrase: "Last %s items", where %s is a number larger 1. The translation in Polish will depend on the size of %s as the language has multiple plural forms. Is it possible to add a condition (if statement) directly in the po file to take care of this or would I have to go back to the website code to add an if condition there? I read about "plural forms" in this context, but is this what I need? bamse (talk) 21:33, 30 November 2012 (UTC)[reply]

GNU's documentation for its implementation of gettext says the PO syntax supports the ternary (conditional) operator ?:, documented here. It looks like you can nest multiple ternary operators to handle the complications of Polish language plurals (Polish is explicitly called out in the programmatic section of gettext's plurals documentation here). -- Finlay McWalterTalk 21:57, 30 November 2012 (UTC)[reply]
Thanks for pointing me in the right direction. In fact it was easier than that. Just had to wrap all such strings in "ngettext" and I get the option to translate to various plural forms in poedit. bamse (talk) 23:33, 30 November 2012 (UTC)[reply]