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. |
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)
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_startsnsec];++nsec); /* count sections */
char ***list=malloc(nsec*sizeof*list);
for(unsigned i=0;i<nsec;++i)
listi=parse_section(section_startsi],section_startsi+1]);
free(section_starts);
free(text); /* it's all copied into 'list' now */
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=&wikibeg];
if(wikibeg=='=' && wikinonblank=='=') { // 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;
}
|
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)
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 ツ Jenova 20 ( email) 08:26, 3 September 2013 (UTC)
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)
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 ( talk • contribs) 14:03, 3 September 2013 (UTC)
Hi .. how do I find my rendered book? thank you — Preceding unsigned comment added by Hodgepodge25 ( talk • contribs) 15:40, 3 September 2013 (UTC)
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)
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. |
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)
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_startsnsec];++nsec); /* count sections */
char ***list=malloc(nsec*sizeof*list);
for(unsigned i=0;i<nsec;++i)
listi=parse_section(section_startsi],section_startsi+1]);
free(section_starts);
free(text); /* it's all copied into 'list' now */
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=&wikibeg];
if(wikibeg=='=' && wikinonblank=='=') { // 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;
}
|
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)
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 ツ Jenova 20 ( email) 08:26, 3 September 2013 (UTC)
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)
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 ( talk • contribs) 14:03, 3 September 2013 (UTC)
Hi .. how do I find my rendered book? thank you — Preceding unsigned comment added by Hodgepodge25 ( talk • contribs) 15:40, 3 September 2013 (UTC)
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)