I have a list of keywords, about 25,000 of them. I would like people who add a certain < script tag on their web page to have these keywords transformed into links. What would be the best way to go and achieve this?
I have tried the simple javascript approach (an array with lots of elements and regexping/replacing each) and it obviously slows down the browser.
I could always process the content server-side if there was a way, from the client, to send the page's content to a cross-domain server script (I'm partial to PHP but it could be anything) but I don't know of any way to do this.
Any other working solution is also welcome.
What I must to learn to write php web-site grabber (parser)?
It must collect information from other websites, such as as weather forecast, wiki "on this day", some news and other useful and interesting "every day" information!
what i must to read for writing m3u player on php?
sorry for my bad english
At the moment I have a regular expression that looks like this:
^(cat|dog|bird){1}(cat|dog|bird)?(cat|dog|bird)?$
It matches at least 1, and at most 3 instances of a long list of words and makes the matching words for each group available via the corresponding variable.
Is there a way to revise this so that I can return the result for each word in the string without specifying the number of groups beforehand?
^(cat|dog|bird)+$
works but only returns the last match separately , because there is only one group.
Hi,
In my program, I have a list of "server address" in the following format:
host[:port]
The brackets here, indicate that the port is optional.
host can be a hostname, an IPv4 or IPv6 address.
port, if present can be a numeric port number or a service string (like: "http" or "ssh").
If port is present and host is an IPv6 address, host must be in "bracket-enclosed" notation (Example: [::1])
Here are some valid examples:
localhost
localhost:11211
127.0.0.1:http
[::1]:11211
::1
[::1]
And an invalid example:
::1:80 // Invalid: Is this the IPv6 address ::1:80 and a default port, or the IPv6 address ::1 and the port 80 ?
::1:http // This is not ambigous, but for simplicity sake, let's consider this is forbidden as well.
My goal is to separate such entries in two parts (obviously host and port). I don't care if either the host or port are invalid as long as they don't contain a : (290.234.34.34.5 is ok for host, it will be rejected in the next process); I just want to separate the two parts, or if there is no port part, to know it somehow.
I tried to do something with std::stringstream but everything I come up to seems hacky and not really elegant.
How would you do this in C++ ?
I don't mind answers in C but C++ is prefered. Any boost solution is welcome as well.
Thank you.
I may have string like,
"""Hello, %(name)s,
how are you today,
here is amount needed: %(partner_id.account_id.debit_amount)d
"""
what would be the best solution for such template may i need to combine regular expression and eval, input string may differ like $partner_id.account_id.debit_amount$ - for the moment I've kept as python string format - just for testing.
I have to create a module in a specific project, which already uses PrototypeJS.
What I have:
- An XML File with information
What I want:
- A simple div, which displays the (with XPath filterd) Content of the XML-File.
I am complete new to PrototypeJS and dont know where to begin, so I appreciate your help.
Blessing
chris
I would like to have a string (char*) parsed into a tm struct in C. Is there any built-in function to do that?
I am referring to ANSI C in C99 Standard.
I have an SQL file which will give me an output like below:
10|1
10|2
10|3
11|2
11|4
.
.
.
I am using this in a Perl script like below:
my @tmp_cycledef = `sqlplus -s $connstr \@DLCycleState.sql`;
after this above statement, since @tmp_cycledef has all the output of the SQL query,
I want to show the output as:
10 1,2,3
11 2,4
How could I do this using Perl?
I've got a utility that outputs a list of files required by a game. How can I run that utility within a C program and grab its output so I can act on it within the same program?
UPDATE: Good call on the lack of information. The utility spits out a series of strings, and this is supposed to be complete portable across Mac/Windows/Linux. Please note, I'm looking for a programmatic way to execute the utility and retain its output (which goes to stdout).
I have a wget-like script which downloads a page and then retrieves all the files linked in IMG tags on that page.
Given the URL of the original page and the the link extracted from the IMG tag in that page I need to build the URL for the image file I want to retrieve. Currently I use a function I wrote:
sub build_url {
my ( $base, $path ) = @_;
# if the path is absolute just prepend the domain to it
if ($path =~ /^\//) {
($base) = $base =~ /^(?:http:\/\/)?(\w+(?:\.\w+)+)/;
return "$base$path";
}
my @base = split '/', $base;
my @path = split '/', $path;
# remove a trailing filename
pop @base if $base =~ /[[:alnum:]]+\/[\w\d]+\.[\w]+$/;
# check for relative paths
my $relcount = $path =~ /(\.\.\/)/g;
while ( $relcount-- ) {
pop @base;
shift @path;
}
return join '/', @base, @path;
}
The thing is, I'm surely not the first person solving this problem, and in fact it's such a general problem that I assume there must be some better, more standard way of dealing with it, using either a core module or something from CPAN - although via a core module is preferable. I was thinking about File::Spec but wasn't sure if it has all the functionality I would need.
Is there some ultra fast "syntax check my code, but don't compile mode" for g++/clang? Where the only goal is to just check if the code I have is valid C++ code?
I'm working on a project that involves parsing a large csv formatted file in Perl and am looking to make things more efficient.
My approach has been to split() the file by lines first, and then split() each line again by commas to get the fields. But this suboptimal since at least two passes on the data are required. (once to split by lines, then once again for each line). This is a very large file, so cutting processing in half would be a significant improvement to the entire application.
My question is, what is the most time efficient means of parsing a large CSV file using only built in tools?
note: Each line has a varying number of tokens, so we can't just ignore lines and split by commas only. Also we can assume fields will contain only alphanumeric ascii data (no special characters or other tricks). Also, i don't want to get into parallel processing, although it might work effectively.
edit
It can only involve built-in tools that ship with Perl 5.8. For bureaucratic reasons, I cannot use any third party modules (even if hosted on cpan)
another edit
Let's assume that our solution is only allowed to deal with the file data once it is entirely loaded into memory.
yet another edit
I just grasped how stupid this question is. Sorry for wasting your time. Voting to close.
Hi, I need to get a particular version string from a file (call it version.lst) and use it to compare another in a shell script. For example sake, the file contains lines that look like this:
V1.000 -- build date and other info here -- APP1
V1.000 -- build date and other info here -- APP2
V1.500 -- build date and other info here -- APP3
.. and so on. Let's say I am trying to grab the first version (in this case, V1.000) from APP1. Obviously, the versions can change and I want this to be dynamic. What I have right now works:
var = `cat version.lst | grep " -- APP1" | grep -Eo V[0-9].[0-9]{3}`
Pipe to grep will get the line containing APP1 and the second pipe to grep will get the version string. However, I hear grep is not the way to do this so I'd like to learn the best way using awk or sed. Any ideas? I am new to both and haven't found a tutorial easy enough to learn the syntax of it. Do they support egrep? Thanks!
I'm new to Python, so I'm not sure exactly what this operation is called, hence I'm having a hard time searching for information in it.
Basically I'd like to have a string such as:
"[[size]] widget that [[verb]] [[noun]]"
Where size, verb, and noun are each a list.
I'd like to interpret the string as a metalanguage, such that I can make lots of sentences out permutations from the lists. As a metalanguage, I'd also be able to make other strings that use those pre-defined lists to generate more permutations.
Are there any capabilities for variable substitution like this in Python? What term describes this operation if I should just Google it?
I am using the SAX parser in java. I am not sure:
1) What classes I need for this kind of situation? I am guessing I want to have
Classes for (please let me know if my thoughts are completely wrong):
-FosterHome (Contains an Arraylist of Family and Child)
-Family (Contains ArrayList for Child and a String fro parent)
-Child (contains ArrayList for ChildID)
2) How to handle this situation in the startElement and endElement method
What complicates is due to the ChildID appearing in both the ChildList and the RemainingChildList. Appreciate anyone who can help me out.
<FosterHome>
<Orphanage>Happy Days Daycare</Orphanage>
<Location>Apple Street</Location>
<Families>
<Family>
<Parent>Adams</ParentID>
<ChildList>
<ChildID>Child1</ChildID>
<ChildID>Child2</ChildID>
</ChildList>
</Family>
<Family>
<Parent>Adams</ParentID>
<ChildList>
<ChildID>Child3</ChildID>
<ChildID>Child4</ChildID>
</ChildList>
</Family>
</Families>
<RemainingChildList>
<ChildID>Child5</ChildID>
<ChildID>Child6</ChildID>
</RemainingChildList>
</FosterHome>
info = {'phone_number': '123456', 'personal_detail': {'foo':foo, 'bar':bar}, 'is_active': 1, 'document_detail': {'baz':baz, 'saz':saz}, 'is_admin': 1, 'email': '[email protected]'}
return HttpResponse(simplejson.dumps({'success':'True', 'result':info}), mimetype='application/javascript')
if(data["success"] === "True") {
alert(data[**here I want to display personal_detail and document_details**]);
}
How can I do this?
Is there a way to convert it into object form? So that each field of the result can be accessed results[i].field
where i is the number of records in the mysql result..
This is my JSON String
http://pastebin.com/Cky1va3K
I finished installing Ubuntu 10 for netbooks, and XAMPP. The XAMPP website tutorial made it very easy to install, then left me high and dry. Everything works, but I have no idea where to put my handwritten php files.
After a few hours of googling, and trying to understand the file explorer, I realized I have no idea where anything is in ubuntu. For an answer, please don't just tell me "go to "X" directory. I won't know how to navigate there.
I also did a file search for htdocs with no luck.
Background:
I'm invoking a web service method which returns a JSON string. This string can be of type ASConInfo or ASErrorResponse.
Question:
Using the DataContractJsonSerializer, how can I convert the returned JSON string to one of those objects?
Thanks in advance
I have tried the following technique, but it does not work:
public static object test(string inputString)
{
object obj = null;
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(inputString)))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(object));
obj = ser.ReadObject(ms) as object;
}
return obj;
}
[WebMethod]
public string TypeChecker()
{
string str = "{\"Error\":191,\"ID\":\"112345678921212\",\"Length\":15}";
//string strErro = "";
object a = test(str);
if (a is ASResponse)
{
return "ASResponse";
}
if (a is ASErrorResponse)
{
return "ASErrorResponse";
}
return "Nothing";
}
I have data that looks like this:
#info
#info2
1:SRX004541
Submitter: UT-MGS, UT-MGS
Study: Glossina morsitans transcript sequencing project(SRP000741)
Sample: Glossina morsitans(SRS002835)
Instrument: Illumina Genome Analyzer
Total: 1 run, 8.3M spots, 299.9M bases
Run #1: SRR016086, 8330172 spots, 299886192 bases
2:SRX004540
Submitter: UT-MGS
Study: Anopheles stephensi transcript sequencing project(SRP000747)
Sample: Anopheles stephensi(SRS002864)
Instrument: Solexa 1G Genome Analyzer
Total: 1 run, 8.4M spots, 401M bases
Run #1: SRR017875, 8354743 spots, 401027664 bases
3:SRX002521
Submitter: UT-MGS
Study: Massive transcriptional start site mapping of human cells under hypoxic conditions.(SRP000403)
Sample: Human DLD-1 tissue culture cell line(SRS001843)
Instrument: Solexa 1G Genome Analyzer
Total: 6 runs, 27.1M spots, 977M bases
Run #1: SRR013356, 4801519 spots, 172854684 bases
Run #2: SRR013357, 3603355 spots, 129720780 bases
Run #3: SRR013358, 3459692 spots, 124548912 bases
Run #4: SRR013360, 5219342 spots, 187896312 bases
Run #5: SRR013361, 5140152 spots, 185045472 bases
Run #6: SRR013370, 4916054 spots, 176977944 bases
What I want to do is to create a hash of array with first line of each chunk as keys
and SR## part of lines with "^Run" as its array member:
$VAR = {
'SRX004541' => ['SRR016086'],
# etc
}
But why my construct doesn't work. And it must be a better way to do it.
use Data::Dumper;
my %bighash;
my $head = "";
my @temp = ();
while ( <> ) {
chomp;
next if (/^\#/);
if ( /^\d{1,2}:(\w+)/ ) {
print "$1\n";
$head = $1;
}
elsif (/^Run \#\d+: (\w+),.*/){
print "\t$1\n";
push @temp, $1;
}
elsif (/^$/) {
push @{$bighash{$head}}, [@temp];
@temp =();
}
}
print Dumper \%bighash ;
Hello,
I have created a RSS parser and 3 TableViews and it parses the RSS files fine but I don't know how to notify the TableViewController when parsing has ended so it can update the view.
The TableViewController initiates the parser and the parsing of a feed.
parser = [[RSSParser alloc] initWithURL:@"http://randomfeed.com"];
I can access the single feed items like
[parser feedItems];
In parser.m i have implemented the delegate methods of NSXMLParser:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
- (void)parserDidEndDocument:(NSXMLParser *)parser
So how do i get parserDidEndDocument to notify my controllers so i can add the data to the tableview.
Cheers from a obj-c beginner.
Hello SO;
I've been fighting with this problem all day and am just about at my wit's end.
I have an XML file in which certain portions of data are stored as escaped text but are themselves well-formed XML. I want to convert the whole hierarchy in this text node to a node-set and extract the data therein. No combination of variables and functions I can think of works.
The way I'd expect it to work would be:
<xsl:variable name="a" select="InnerXML">
<xsl:for-each select="exsl:node-set($a)/*">
'do something
</xsl:for-each>
The input element InnerXML contains text of the form
<root><element a>text</element a><element b><element c/><element d>text</element d></element b></root>
but that doesn't really matter. I just want to navigate the xml like a normal node-set.
Where am I going wrong?
I am trying to return the duration of the video but am having trouble.
#YOUTUBE FEED
#download the file:
file = urllib2.urlopen('http://gdata.youtube.com/feeds/api/videos/2s0vk2wEMtA')
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
#entire feed
root = etree.fromstring(data)
for entry in root:
for item in entry:
print item
When I print item, I see as the last element:
Element '{http://gdata.youtube.com/schemas/2007}duration' at 0x10c4fb7d0
But I don't know how to get the value from this. Any advice?