Wikipedia:Reference desk/Archives/Computing/2013 September 3

Computing desk
< September 2 << Aug | September | Oct >> September 4 >
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.


September 3 edit

Wikipedia bot scripting in C edit

Hi I wonder how to get a table that content the comment list on a talk page such as: list[0][0][0] would be read as first section; first comment; first letter

For example if the comment is "hello everyone first person date and time"

list[0][0][0] would be h

list[0][0][] would content the string "hello everyone first person date and time"

list[0][1][] could content "hello first person, thanks second person date/time"

Or Maybe a something like a struct would be better rather than a table.

If it is impossible or too difficult, I'd like use pywikipedia or APIbot(PHP). 2A02:8422:1191:6E00:56E6:FCFF:FEDB:2BBA (talk) 00:06, 3 September 2013 (UTC)[reply]

It's not impossible, but it's likely to be rather painful because C's string handling is verbose and few other users of the MediaWiki API use C (so there will be little in the way of examples, libraries, and colleague support). It will also be hard to reliably parse comments (simply because parsing is hard); it might be worthwhile to consult the page history to see who added what text, but you'd have to decide what to do with edits that did other than simply add one or more comment paragraphs. The outline, though, is easy and would look like (error handling omitted, and C99 used, for brevity)
const char *page_name=/* ... */,*text=get_wikitext(page_name);
char **section_starts=find_sections(text);   /* array of pointers into 'text'; the last points at its '\0' */
unsigned nsec;
for(nsec=0;*section_starts[nsec];++nsec);    /* count sections */
char ***list=malloc(nsec*sizeof*list);
for(unsigned i=0;i<nsec;++i)
  list[i]=parse_section(section_starts[i],section_starts[i+1]);
free(section_starts);
free(text);  /* it's all copied into 'list' now */
parse_section() would in turn have to find the comment starts and ends between its two arguments and use malloc() to create an array of strings to return (each of which in turn needing malloc() and strcpy() to hold a separate copy of a single comment). (Alternatively, you could mimic strtok() and modify the text string in place by substituting NULs for newlines separating the comments. Then you wouldn't free(text) until you were finished with a page, since all the comment pointers would be reusing its memory.) --Tardis (talk) 13:31, 3 September 2013 (UTC)[reply]
Well the most difficult thing in this example is to implement the functions you described: get_wikitext() find_sections() parse_section().
After thinking a little, creating a new type using some typedefs could be the best thing. My compilers support C++. I don't know how to code using class. So the typedefs can be coded with latest C++ standard as long as I can use them in a extern "C" {}. Again, if this too difficult, it could be done in a better supported language2A02:8422:1191:6E00:56E6:FCFF:FEDB:2BBA (talk) 21:56, 3 September 2013 (UTC)[reply]
Update I had some idea for the way to get a section, but I have no idea how to get the second column. Isolate a specific message is difficult. you can see some examples here. An another thing which is difficult: If the user made more than one edit on the talk page he/she may have updated the message to do something like spell checking. But their must be a way do this: after writing this line sinebot wont put an unsigned comment.
That's a lot of points:
  • Of course the parts I didn't write are the hard part — if this were all so easy as to be included in a comment, I wouldn't call it painful!
  • You don't need C++ for typedefs; it merely allows you to refer to struct foo as simply foo without having a typedef. (Are you planning to link some other C code against what you're writing? If not, the extern "C" is also irrelevant.)
  • I'm not sure what to make of your de-wiki link; it seems to be redirected to a list of bots.
  • You put "!nosign!" into your edit summary, so of course no signature occurred. I already suggested the page history.
The best thing I can think of as a sensible definition of a comment (which is really what this is about), following WP:SIGN, is to break after lines that end with a timestamp (since those are added after people's varied signatures). Using WP:INDENT is tempting, but doesn't work well for posts (like this one) that have internal structure. --Tardis (talk) 07:32, 4 September 2013 (UTC)[reply]
Thanks for your fast answer. What I want are the hardest parts because I can do the remainder myself of course. I put !nosign! because I wanted to be sure Sinebot wont sign. This not necessary for creating a dear wanted Sinebot equivalent for common. It is to perform some actions on a specific user message. It is to be general purpose. 2A02:8422:1191:6E00:56E6:FCFF:FEDB:2BBA (talk) 12:21, 4 September 2013 (UTC)[reply]
Update By C++ for typedef I mean using full C++ features inside typedef. I don't really know how to deal with C++. it don't mind using typedef using things such as class as long as they are ready to use. SymbolicC++ don't have anything with bot creation or wikimedia, but it is an example of what usage I am thinking with it's "Symbolic" type. — Preceding unsigned comment added by 2A02:8422:1191:6E00:56E6:FCFF:FEDB:2BBA (talk) 16:57, 4 September 2013 (UTC)[reply]
OK, since I'm a sick puppy, I tried to actually implement this (as a library, not a program, since you never said what you wanted to do with it in the end). My choices of HTTP and JSON libraries are somewhat arbitrary, and I haven't even tried to install them myself. Therefore, this is entirely untested and may not even compile, but it should be close. My heuristics for parsing are equally unsophisticated. Bonne chance! --Tardis (talk) 05:58, 9 September 2013 (UTC)[reply]
Reading Wikipedia comments in C++
#include<vector>
#include<string>

#include<yajl/yajl_parse.h>
#include<curl/curl.h>

using namespace std;

struct FindWiki {
  string wiki;
  bool write;
};

extern "C" {
  static size_t curl_yajl(void *buf,size_t sz,size_t n,void *user) {
    sz*=n;                      // when would n!=1?
    return yajl_parse(*static_cast<yajl_handle*>(user),
                      static_cast<const unsigned char*>(buf),sz)
      ==yajl_status_ok ? sz : 0;
  }

  static int yajl_key(void *ctx,const unsigned char *s,size_t n) {
    if(n==1 && *s=='*') static_cast<FindWiki*>(ctx)->write=true;
    return true;
  }  
  static int yajl_str(void *ctx,const unsigned char *s,size_t n) {
    FindWiki &f=*static_cast<FindWiki*>(ctx);
    if(f.write) {f.wiki.assign(s,n); f.write=false;}
    return true;
  }  
}

string getWiki(const char *pageName) {
  struct YAJL {
    YAJL() : h() {}
    ~YAJL() : {if(h) yajl_free(h);} // abstraction leakage
    operator yajl_handle() {return h;}
    yajl_handle h;
  } yajl;
  struct CURL {
    CURL() : p(curl_easy_init())
    {if(!p) throw runtime_error("can't initialize CURL");}
    ~CURL() {if(p) curl_easy_cleanup(p);}
    operator CURL*() {return p;}
  private:
    CURL *p;
  } curl;

  static const yajl_callbacks ycall={0,0,0,0,0,yajl_str,0,yajl_key};
  FindWiki fw;
  yagl.h=yajl_alloc(&ycall,0,static_cast<void*>(&fw));

  {
    string url("http://en.wikipedia.org/w/api.php?format=json&"
               "action=query&titles=");
    char *page=curl_easy_escape(curl,pageName,0);
    if(!page) throw runtime_error("Can't escape "+string(pageName));
    url+=page; url+="&prop=revisions&rvprop=content";
    curl_free(page);
    curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
  }

  curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,curl_yajl);
  curl_easy_setopt(curl,CURLOPT_WRITEDATA,static_cast<void*>(&yagl.h));
  curl_easy_setopt(curl,CURLOPT_USERAGENT,"wiki comments (libcurl)");

  if(const CURLcode err=curl_easy_perform(curl))
    throw runtime_error(curl_easy_strerror(err));
  if(yajl_complete_parse(yagl)!=yajl_status_ok)
    throw runtime_error("YAJL error"); // calling yajl_get_error() is hard
  return fw.wiki;
}

typedef vector<string> section_t;
typedef vector<section_t> comments_t;
comments_t getComments(const string &wiki) {
  typedef string::size_type idx_t;
  comments_t ret;
  section_t *sec=0;
  idx_t beg=0,end,cstart=string::npos;
  do {
    end=wiki.find('\n',beg);
    // Disregard whitespace at the end of the line:
    const idx_t nonblank=wiki.find_last_not_of(" \t",end);
    if(nonblank==string::npos || nonblank<beg) continue; // ignore blank line
    if(cstart==string::npos) cstart=&wiki[beg];
    if(wiki[beg]=='=' && wiki[nonblank]=='=') { // section header
      ret.push_back(section_t());
      sec=&ret.back();
      cstart=string::npos;
    } else if(sec && nonblank-beg>5 && !wiki.compare(nonblank-5,6," (UTC)")) {
      sec->push_back(string(wiki,cstart,nonblank+1-cstart));
      cstart=string::npos;
    }
    beg=end+1;
  } while(end!=string::npos);
  return ret;
}

Average computer configuration by years edit

Is there a comparative historical table or something alike with average computer configuration (CPU, memory, video card, monitor etc.) by years? For example I'd like to know what a new average computer was in 1990, 1992, 1994, 1996, 1998 etc.--Lüboslóv Yęzýkin (talk) 05:21, 3 September 2013 (UTC)[reply]

See History Of Recommended PC Configurations. First answer from Googling "computer configuration by year"  .--220 of Borg 07:41, 7 September 2013 (UTC)[reply]
Whaaat?! I did that on the day this was posted, and found absolutely nothing! Oh well, as long as the OP's question gets answered! :) --.Yellow1996.(ЬMИED¡) 18:31, 7 September 2013 (UTC)[reply]
Indeed it seems that such information on-line is rather scanty.  A search of newspaper PC adverts over time may be another source. Past editions of Scott Mueller|'s Upgrading and Repairing PCs might also have such info. The list linked above though seems to be fairly accurate. IIRC the entry level PC for late 1988 matched my first Windows type PC closely i.e. 6.4 Gb HDD, 64 Mb SDRAM. --220 of Borg 04:15, 8 September 2013 (UTC)[reply]
Thanks! It's strange that if I add the word "average" and type "years" Google indeed will find nothing.--Lüboslóv Yęzýkin (talk) 08:35, 8 September 2013 (UTC)[reply]
Ah, that was what I added: "average" - strange how just a simple change like that can effect google results so. --.Yellow1996.(ЬMИED¡) 17:49, 8 September 2013 (UTC)[reply]

Ram versus CPU? edit

How much difference is there between a slight upgrade in processor and an upgrade in ram? Would it usually be more effective to upgrade the processor, or just as effective to add 4gb of ram? Or do I need to be more specific? Thanks Jenova20 (email) 08:26, 3 September 2013 (UTC)[reply]

You should run a system monitor to check out your CPU and RAM usage. That will tell you which one is topping out when your computer slows to a crawl. I think low RAM is most often the culprit. StuRat (talk) 08:38, 3 September 2013 (UTC)[reply]
What's a system monitor StuRat? Thanks Jenova20 (email) 08:40, 3 September 2013 (UTC)[reply]
It keeps track of how many system resources you are using, and presents them in some form, like a table, dials, or graph. What operating system are you using ? We should be able to point you to the system monitor(s) for your O/S. StuRat (talk) 08:49, 3 September 2013 (UTC)[reply]
Windows 7 64-bit. Thanks Jenova20 (email) 09:58, 3 September 2013 (UTC)[reply]
Click on the start menu, in the box that says "Search programs and files" type in Performance Monitor, click on that when it's found to open it. Dismas|(talk) 10:06, 3 September 2013 (UTC)[reply]
Thank you both very much Jenova20 (email) 10:25, 3 September 2013 (UTC)[reply]
OT - Jenova, the first char of your sig renders as 30c4 on my screen?
Poor Man's System Monitor aka Task Manager works, too. If your program gets stuck at 100% CPU usage, it is probably just that: CPU usage, and a faster CPU could help. If the CPU usage is below 75% but the program is working hard, it is usually due to I/O, possibly paging. If the RAM load is higher than your physical RAM, it is very probably paging. Otherwise it is file I/O. Both can be remedied by a faster HDD or SSD, but only RAM is the real remedy to paging. If you're not using more RAM than you have physical RAM, any additional RAM is a waste of money.
Multi-core CPUs are quite tricky; there could be one core at 100% and one close to 0%, and that could get reported as 50% average load. Many older programs use one core only. If one core stays at 100% for some time, a faster CPU could be a substantial improvement, but a CPU with more cores will probably help uck fall – unless the individual cores are faster. - ¡Ouch! (hurt me / more pain) 07:21, 6 September 2013 (UTC)[reply]
(Aside) The first character in Jenova's sig is (IIRC) a Japanese Katakana character... though it looks like a smiley face! it's possible your language pack isn't installed or installed incorrectly. --.Yellow1996.(ЬMИED¡) 02:55, 7 September 2013 (UTC)[reply]

Cannot open image attachments on iOS 5.1.1 edit

Was it just me, or is anyone else having trouble opening JPEG/PNG/GIF attachments with iOS? The email account in question is a Yahoo one, and I'm trying to grab them off the default email app. The attachments only appear as a generic paper icon with a blue down arrow on it. Clicking on them would make the file appear like it's being downloaded, but nothing happens afterwards. I tried uninstalling iFile and the downloader tweak from Cydia, but still no dice. I'm ruling in the possibility of Polaris Office and a few other applications conflicting with the system-default email app, but is there anything that I should take note of? Blake Gripling (talk) 12:38, 3 September 2013 (UTC)[reply]

iOS 5 is not the current version of iOS; and the presence of Cydia almost assures that you have modified the device software to use an unsupported configuration. So, you are now in "untested waters," and it's very unlikely that Apple can diagnose your problem; it's even more unlikely that Cydia's developers will care to investigate it. (Cydia's developers have zero stake in your customer satisfaction!) The good news is, you can easily restore your device to iOS 6.1, which is available at no cost, and will restore your device to a known-to-work configuration. Otherwise, all bets are off - but because you've "jail-broken" the device, you are asserting that you're an expert system-programmer who knows how to modify complex software systems and debug these kinds of complicated software problems yourself, right?
My recommendation is to revert to a known-to-work software version that is tested by Apple, iOS 6.1, or the soon-to-be-available iOS 7. Nimur (talk) 15:37, 3 September 2013 (UTC)[reply]
Yeah, nothing too big of an issue, but it's an annoyance. I guess I could wait for iOS7 to be released. Blake Gripling (talk) 01:19, 4 September 2013 (UTC)[reply]

windows XP vs 8 edit

so, trying this feature... My wife's laptop runs XP, would it run faster with Win8 - Win 8 seems like a cleaner OS. — Preceding unsigned comment added by Wikicheesecake (talkcontribs) 14:03, 3 September 2013 (UTC)[reply]

If the hardware doesn't change, it wouldn't. 190.60.93.218 (talk) 15:34, 3 September 2013 (UTC)[reply]
(ec) Hard to say without knowing more about your wife's laptop. Windows 8 has minumum hardware requirements, listed here. An older laptop, one which came with Windows XP installed, might not be up to the job. For example, old laptops that I have seen with Windows XP installed, from the mid-2000s typically have 256MB of memory, a small hard drive of ~40GB, and slow dualcore - clearly insufficient for Windows 8. Astronaut (talk) 15:39, 3 September 2013 (UTC)[reply]
Yeah we definitely need the specs of her laptop in order to make a better judgement... with XP it could meet the requirements, or fall way short. --.Yellow1996.(ЬMИED¡) 16:06, 3 September 2013 (UTC)[reply]
The next question would be, "Would she save any time with Windows 8?" and would take a discussion of the user interfaces. IMO, the 9x style is clean and fast, and easy to use; the XP style is a bit too playful without providing anything useful beyond the 9x style but just as easy to use, the Vista/7 GUI is still quite immature and confusing compared to XP and 98, and the Windows 8 GUI is an atrocity. If you love your wife, don't make her suffer like that.
There is hardly any laptop configuration that would run faster with 8. If you want a newer OS than XP, Windows 7 is the way to go. - ¡Ouch! (hurt me / more pain) 08:25, 5 September 2013 (UTC)[reply]
Source? I swear I've read about improvements in the scheduler and paging, and my system seemed slightly quicker after upgrading from 7, but obviously that's subjective. There was so much focus on the metro interface and everyone needing to voice an opinion on it that the performance improvements got overlooked. A quick search didn't find any information on the scheduler or caching changes, but I did find this set of benchmarks: [1]. I don't have a name (talk) 12:19, 5 September 2013 (UTC)[reply]
The question where the speedup came from remains. Is it the OS itself or did better codecs come with Win8? And, if it's the latter, can the same codecs be used with Winows 7, and will they speed things up on old hardware? There might be optimizations which don't save any time on old CPUs and even slow old CPUs down. Finally, the speedups seem to fluctuate between 0 and 20%, and the larger RAM footprint means that if 7 pages, 8 will page more. If XP pages at all, abandon all hope thou who installest Windoweth 8. - ¡Ouch! (hurt me / more pain) 15:52, 7 September 2013 (UTC)[reply]
I suppose the real question is whether or not an XP-vintage laptop can smoothly handle Aero. I know 7 works fine without it, but the oldest mobile graphics I've run 8 on were the Intel integrated graphics on a Core 2 Duo system that was designed with 7 (or maybe Vista) and Aero in mind. I don't know how well it handles older graphics hardware. I don't have a name (talk) 12:22, 5 September 2013 (UTC)[reply]

book creator - rendered, document ready for download, file not found edit

Hi .. how do I find my rendered book? thank you — Preceding unsigned comment added by Hodgepodge25 (talkcontribs) 15:40, 3 September 2013 (UTC)[reply]

There should be a download link that you can get to through the Book Editor interface. Is that interface failing to show up? Did you create the book while logged in? Nimur (talk) 15:45, 3 September 2013 (UTC)[reply]

VLC duration unknown edit

I was wondering what was the cause VLC player (or any other media player) may have trouble figuring out the real duration of a file, or shows a erroneous duration when first played, then corrects itself over the playback of the file, why is this? 190.60.93.218 (talk) 18:40, 3 September 2013 (UTC)[reply]

Unfortunately, I wasn't able to find an answer... and I don't know it off the top of my head; though this appears to be a really common problem (there are many threads/posts about it on the web) but not conlusions as to why it happens. Now that I think of it I've never had the problem happen to me in VLC, but it has happened in Winamp... --.Yellow1996.(ЬMИED¡) 19:01, 3 September 2013 (UTC)[reply]
The media file may be missing the 'MOOV' atom, or the media player may have had trouble finding it and is trying to estimate the duration by taking the file size and dividing it by the average bitrate so far. Unilynx (talk) 19:38, 3 September 2013 (UTC)[reply]