mongodb dies on regex search - regex

Simple regex search:
> db.lipsum.find({"d.text":{$regex:'cursus'}});
does well, and returns many thousands.
A bit more complex one:
db.lipsum.find({"d.text":{$regex:'cursus((?!turpis massa).)*$'}});
kills the mongod:
Tue Nov 26 11:01:03 DBClientCursor::init call() failed
Tue Nov 26 11:01:03 query failed : lipsum.lipsum { d.text: { $regex: "cursus((?!turpis massa).)*$" } } to: 127.0.0.1:27017
Error: error doing query: failed
Tue Nov 26 11:01:03 trying reconnect to 127.0.0.1:27017
Tue Nov 26 11:01:03 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
There is nothing in mongodb.log. The last lines are:
Tue Nov 26 11:00:17 [conn2] query lipsum.lipsum query: { d.text: { $regex: "cursus" } } cursorid:5200338523215960499 ntoreturn:0 keyUpdates:0 locks(micros) r:1266 nreturned:101 reslen:159838 1ms
Tue Nov 26 11:00:18 [conn2] run command admin.$cmd { replSetGetStatus: 1.0, forShell: 1.0 }
Tue Nov 26 11:00:18 [conn2] command admin.$cmd command: { replSetGetStatus: 1.0, forShell: 1.0 } ntoreturn:1 keyUpdates:0 reslen:76 0ms
So there are 2 questions:
How to get detailed information what happened ?
How to write correct regex to fetch objects that have no "turpis massa" after "cursus"?
Mongodb 2.2.4, Ubuntu 13.04.
My testing db:
load("lorem.js"); // from https://github.com/f/loremjs
var lorem = new Lorem;
lorem.type = Lorem.TEXT;
lorem.query = '2p';
for(var i=0; i < 20000; i++){
db.lipsum.insert({t: $currentDate, d: {text:lorem.createLorem()}})
}

Related

`glog` example is not showing output as expected

I am trying to understand glog and therefore trying to run the example code on their github page.
I have installed glog (version - 0.6.0) and its dependency gflags (version - 2.2) on my mac OS (10.15.7)
I compile the example below
#include <glog/logging.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
using the following command (and it compiles without any errors or warnings).
g++ glog-test.cpp -I/usr/local/include -L/usr/local/lib -lglog -lgflags -o glog-test.o
When I run the example using the following command,
./glog-test.o --logtostderr=1 --stderrthreshold=0
I expect to see the message Found 3 cookies on my terminal, but I see nothing being printed.
I have also experimented with different values for logtostderr (0, 1) and stderrthreshold (0, 1, 2, 3) and nothing gets written to the directory or gets printed on the terminal.
Any help in understanding what I am doing wrong here would be much appreciated, thank you!
You have to parse the command line flags manually through gflags::ParseCommandLineFlags
#include <glog/logging.h>
#incldue <gflags/gflags.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
Just checked, the following works..
GLOG_stderrthreshold=0 GLOG_logtostderr=1 ./glog-test.o
which gives
Found 3 cookies
I do have gflags and installed, as seen by
cd /usr/local/lib
ls -l | grep "libgflags"
which gives
-lrwxr-xr-x 1 sn admin 48 Jun 5 2020 libgflags.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.2.dylib
lrwxr-xr-x 1 sn admin 46 Jun 5 2020 libgflags.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.dylib
-rw-r--r-- 1 sn admin 170520 Jun 27 00:35 libgflags.a
lrwxr-xr-x 1 sn admin 42 Jun 5 2020 libgflags.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.dylib
lrwxr-xr-x 1 sn admin 58 Jun 5 2020 libgflags_nothreads.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.2.dylib
lrwxr-xr-x 1 sn admin 56 Jun 5 2020 libgflags_nothreads.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.dylib
-rw-r--r-- 1 sn admin 168096 Jun 27 00:35 libgflags_nothreads.a
lrwxr-xr-x 1 sn admin 52 Jun 5 2020 libgflags_nothreads.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.dylib
so I am not sure why
./glog-test.o --logtostderr=1 --stderrthreshold=0
didn't work.

Issue with sorting a vector of C++17 Filesystem::last_write_time

I'm having an issue trying to sort a vector of files by their last write time. Sorting seems to work as intended, however sometimes even though the time string shows a higher date, the time_t is lower.
Example Output:
Wed Aug 19 01:51:07 2020 || 1597819867
Wed Aug 19 05:17:20 2020 || 1597832240
Tue Aug 18 18:54:26 2020 || 1597794866
Tue Aug 18 18:43:20 2020 || 1597794200
Tue Aug 18 18:42:38 2020 || 1597794158
Wed Aug 19 22:52:44 2020 || 1597895564 <-Wrong
Thu Aug 13 18:25:32 2020 || 1597361132 <-Wrong
Wed Aug 12 22:36:51 2020 || 1597289811 <-Wrong
Mon Aug 17 21:49:45 2020 || 1597718985
My Code:
for (int i = 0; i < 200; i++) {
auto diff = GetFileWriteTime(pth) - GetFileWriteTime(dates[i]);
if (diff > 0.0) {
itPos = dates.begin();
if (i > 0) { itPos = dates.begin() + i - 1; }
dates.insert(itPos, pth);
dates.pop_back();
break;
}
}
}

rrdtool fetch command always returns -nan value

I have an rrd file whose output from rrdtool info is as follows:
$rrdtool info ifInOctets.rrd
filename = "ifInOctets.rrd"
rrd_version = "0003"
step = 300
last_update = 1497312000
header_size = 1416
ds[ifInOctets].index = 0
ds[ifInOctets].type = "COUNTER"
ds[ifInOctets].minimal_heartbeat = 900
ds[ifInOctets].min = 0.0000000000e+00
ds[ifInOctets].max = 9.9999999990e+09
ds[ifInOctets].last_ds = "3.4019552910E+09"
ds[ifInOctets].value = 8.1322780295e+08
ds[ifInOctets].unknown_sec = 0
rra[0].cf = "AVERAGE"
rra[0].rows = 2016
rra[0].cur_row = 1544
rra[0].pdp_per_row = 1
rra[0].xff = 5.0000000000e-01
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
rra[1].cf = "AVERAGE"
rra[1].rows = 1488
rra[1].cur_row = 754
rra[1].pdp_per_row = 12
rra[1].xff = 5.0000000000e-01
rra[1].cdp_prep[0].value = 1.0418342945e+08
rra[1].cdp_prep[0].unknown_datapoints = 0
rra[2].cf = "AVERAGE"
rra[2].rows = 366
rra[2].cur_row = 84
rra[2].pdp_per_row = 288
rra[2].xff = 5.0000000000e-01
rra[2].cdp_prep[0].value = 1.1808838469e+09
rra[2].cdp_prep[0].unknown_datapoints = 0
rra[3].cf = "MAX"
rra[3].rows = 366
rra[3].cur_row = 29
rra[3].pdp_per_row = 288
rra[3].xff = 5.0000000000e-01
rra[3].cdp_prep[0].value = 1.3983258476e+07
rra[3].cdp_prep[0].unknown_datapoints = 0
rra[4].cf = "MIN"
rra[4].rows = 366
rra[4].cur_row = 101
rra[4].pdp_per_row = 288
rra[4].xff = 5.0000000000e-01
rra[4].cdp_prep[0].value = 5.7478020724e+05
rra[4].cdp_prep[0].unknown_datapoints = 0
And the XML export of the data looks (in part) like:
<!-- Tue Jun 06 10:00:00 EDT 2017 / 1496757600 -->
<row>
<v>+6.3341370319E06</v>
</row>
<!-- Tue Jun 06 10:05:00 EDT 2017 / 1496757900 -->
<row>
<v>+3.0319877350E06</v>
</row>
<!-- Tue Jun 06 10:10:00 EDT 2017 / 1496758200 -->
<row>
<v>+9.8097124846E06</v>
</row>
<!-- Tue Jun 06 10:15:00 EDT 2017 / 1496758500 -->
<row>
<v>+1.0005290356E07</v>
</row>
<!-- Tue Jun 06 10:20:00 EDT 2017 / 1496758800 -->
<row>
But for some reason all that rrdtool will output is
$rrdtool fetch ifInOctets.rrd AVERAGE
ifInOctets
1497541500: -nan
1497541800: -nan
1497542100: -nan
1497542400: -nan
1497542700: -nan
So far i've tried adjusting the min, max, and step but so far i've had no luck. Any help would be much appreciated.
This is because you haven't defined values for resolution, start and end.
From rrdtool usage,
Usage: rrdtool [options] command command_options
* fetch - fetch data out of an RRD
rrdtool fetch filename.rrd CF
[-r|--resolution resolution]
[-s|--start start] [-e|--end end]
[-a|--align-start]
[-d|--daemon <address>]
This will work,
rrdtool fetch ifInOctets.rrd AVERAGE -r 300 -s 1496757600 -e 1496758800

How to print from two lists

I have two lists with diffrent itemsas follows:
numbers = ['1','2','3','4','5','6','7',]
days = ['mon','tue','wed','thu','fri','sat','sun',]
I want to print from both to look like this:
result = 1
mon
2
tue
3
wed
4
thu.....etc
Is there such as code that does this?
Regards
You can use zip to combine two lists.
The zip() function is probably what you want here.
You can print such output with this.
for n, m in zip(numbers, days):
print(n, m)
Output -
1 mon
2 tue
3 wed
4 thu
5 fri
6 sat
7 sun
Hope it helps.
Update - zip function combines two equal-length collections (e.g. list) together and produces a tuple object.
This can resolve your problem.
<?php
//array 1
$numbers = ['1','2','3','4','5','6','7',];
// array 2
$days = ['mon','tue','wed','thu','fri','sat','sun',];
// use for loop
for($i = 0; $i < 7; $i++) {
echo $numbers[$i].' '.$days[$i].'<br>';
}
?>
Output -
1 mon
2 tue
3 wed
4 thu
5 fri
6 sat
7 sun

Range through times to pretty print by year

Currently I'm printing post archive dates like so with https://play.golang.org/p/P1-sAo5Qy8:
2009 Nov 10»Something happened in 2009
2005 Nov 10»Something happened 10 years ago
2009 Jun 10»Summer of 2009
Though I think it's nicer to print by year:
2009
2009 Nov 10»Something happened in 2009
2009 Jun 10»Summer of 2009
2005
2005 Nov 10»Something happened 10 years ago
How would I range reverse chronically over the Posts PostDate, to print the grouping that I want? Can it be done all in the template?
Implement the sort.Interface on your Posts struct, then sort it in reverse order.
type Posts struct {
Posts []Post
}
func (p Posts) Len() int {
return len(p.Posts)
}
func (p Posts) Less(i, j int) bool {
return p.Posts[i].PostDate.Before(p.Posts[j].PostDate)
}
func (p Posts) Swap(i, j int) {
p.Posts[i], p.Posts[j] = p.Posts[j], p.Posts[i]
}
and
posts := Posts{p}
sort.Sort(sort.Reverse(posts))
That will give you the posts in the sequence you want them.
Next you'll have to implement a func using a closure so you can check if the current year is the same as the one for the last post to get the grouping by year. If yes output just the post, otherwise output a header with the year followed by the post.
currentYear := "1900"
funcMap := template.FuncMap{
"newYear": func(t string) bool {
if t == currentYear {
return false
} else {
currentYear = t
return true
}
},
}
and to use it:
{{ range . }}{{ if newYear (.PostDate.Format "2006") }}<li><h1>{{ .PostDate.Format "2006" }}</h1></li>{{ end }}
See a working example on the Playground.