How to debug a splice operation in a Perl script? - perl

#! usr/bin/perl
#months=('Jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
#new=('1','2');
print "#months\n";
splice(#months,0,1,#new);
print "#months\n";
When I run this I expect output to be as
Jan feb mar apr may jun jul aug sep oct nov dec
1 2 mar apr may jun jul aug sep oct nov dec
But I am getting output as
Jan feb mar apr may jun jul aug sep oct nov dec
1 2 feb mar apr may jun jul aug sep oct nov dec
The Feb should also be replaced by 2, right? But why it isn't happening.

Syntax of splice command is
splice ARRAY,OFFSET,LENGTH,LIST
You specify LENGTH to be 1, so only one element is removed from the original list (that element is Jan). If you want feb to be removed too, then you must use a LENGTH of 2
splice(#months, 0, 2, #new);

Related

IPython /bin/bash: /bin/bashfile.txt: Permission denied

This issue is inside IPython:
1) when i run the following, it works fine
for x in range(10):
!date
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
2) when i want to redirect it into the file, it gives the following error message:
for x in range(10):
!date > ${x}.txt
/bin/bash: /bin/bashfile.txt: Permission denied
Im honestly not sure why am i getting that error message. I don't understand it.
If you want to interpolate the value of the Python variable x into a shell command in IPython, the syntax for that is $x or {x}, not ${x}. When x is 0, ${x} expands to $0, which the shell then does its own expansion for. Your command should be
!date > {x}.txt
(It's unlikely that $0 would have expanded to /bin/bashfile, suggesting that you probably didn't actually run the code you posted.)
Not sure what exactly you are trying to do here, but you're trying to write to a file that you do not have write permission for.
Make a new file and try writing to it and you'll succeed.

MongoDB natural sort returns data with ObjectIDs shuffled in time

I perform the following query:
db.preference.find({}, {_id: 1}).sort({$natural: 1}).forEach(function(d) {
print(d._id.getTimestamp())
})
Here's part of the output:
Thu Mar 26 2015 12:39:06 GMT+0100 (CEST)
Thu Mar 26 2015 12:41:07 GMT+0100 (CEST)
Thu Mar 26 2015 12:48:55 GMT+0100 (CEST)
Mon Mar 30 2015 17:08:44 GMT+0200 (CEST)
Tue Mar 31 2015 12:34:36 GMT+0200 (CEST)
Tue Mar 31 2015 12:35:01 GMT+0200 (CEST)
Tue Mar 31 2015 12:34:47 GMT+0200 (CEST)
Thu Nov 20 2014 10:55:07 GMT+0100 (CEST)
Wed Apr 29 2015 10:02:33 GMT+0200 (CEST)
Wed Apr 29 2015 10:02:53 GMT+0200 (CEST)
Wed Apr 29 2015 10:03:13 GMT+0200 (CEST)
Wed Apr 29 2015 10:00:11 GMT+0200 (CEST)
Wed Apr 29 2015 10:18:23 GMT+0200 (CEST)
Mon Feb 23 2015 11:54:11 GMT+0100 (CEST)
Tue May 12 2015 16:40:45 GMT+0200 (CEST)
Fri May 15 2015 17:04:04 GMT+0200 (CEST)
Wed May 14 2014 18:13:40 GMT+0200 (CEST)
Tue Jun 09 2015 14:17:11 GMT+0200 (CEST)
Tue Jun 16 2015 16:03:31 GMT+0200 (CEST)
Tue Nov 04 2014 21:15:21 GMT+0100 (CEST)
Fri Mar 14 2014 10:16:48 GMT+0100 (CEST)
Wed Jun 17 2015 11:14:57 GMT+0200 (CEST)
Fri Mar 14 2014 10:15:30 GMT+0100 (CEST)
It's easy to see that the dates are seriously shuffled, while I expected strictly ascending order.
Collection is not capped, and the documents are often modified. ObjectIds are never generated in the code explicitly. Collection is not shared.
Any ideas why natural sorting works this way?
Can someone explain while natural ordering works in.
What did you expect?
Use the $natural operator to use natural order for the results of a
sort operation. Natural order refers to the logical ordering of
documents internally within the database.
The $natural operator uses the following syntax to return documents in
the order they exist on disk: ...
See MongoDB documentation.

Looking for Google Apps script to find and highlight dates from past month in red

I have a Google spreadsheet with columns I and J with data as headers Est Closing Month and Est Closing Calendar Year respectively, I need a script which will loop through columns I and J and find dates which are in the past month of this year and highlight them in Red.
Following is example data
ColI ColJ
Aug 2014
Nov 2014
Aug 2014
Jul 2014
Jul 2014
Dec 2014
Dec 2014
After I run the script the output put should be
Aug 2014
Nov 2014
Aug 2014
Jul 2014 -> Both Cells should be in red
Jul 2014 -> Both Cells should be in red
Dec 2014
Dec 2014
Thank you for all the help.
have you tried conditional formatting ?

why g-wan loops on loading handler scripts and csp script each day at midnight?

I have a strange behavior on my g-wan server: each day at midnight g-wan loops on loading scripts. This is what I see in gwan.log:
[Tue Apr 09 00:00:00 2013 GMT] memory footprint: 1.47 MiB.
[Tue Apr 09 00:00:00 2013 GMT] Host /var/www/gwan/0.0.0.0_8082/#0.0.0.0
[Tue Apr 09 00:00:00 2013 GMT] log files enabled
[Tue Apr 09 00:00:00 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:00:00 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:00:00 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:f624bc05-f51507c3-61b20c9c-ecfe9e19
[Tue Apr 09 00:00:00 2013 GMT] Host /var/www/gwan/0.0.0.0_8083/#0.0.0.0
[Tue Apr 09 00:00:00 2013 GMT] log files enabled
[Tue Apr 09 00:00:00 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:00:00 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:00:00 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:525aa623-2728dd50-0e67a6ad-6763a30b
[Tue Apr 09 00:00:00 2013 GMT] memory footprint: 5.45 MiB.
[Tue Apr 09 00:00:01 2013 GMT] memory footprint: 1.47 MiB.
[Tue Apr 09 00:00:01 2013 GMT] Host /var/www/gwan/0.0.0.0_8082/#0.0.0.0
[Tue Apr 09 00:00:01 2013 GMT] log files enabled
[Tue Apr 09 00:00:01 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:00:01 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:00:01 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:f624bc05-f51507c3-61b20c9c-ecfe9e19
[Tue Apr 09 00:00:01 2013 GMT] Host /var/www/gwan/0.0.0.0_8083/#0.0.0.0
[Tue Apr 09 00:00:01 2013 GMT] log files enabled
[Tue Apr 09 00:00:01 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:00:01 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:00:01 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:525aa623-2728dd50-0e67a6ad-6763a30b
....
....
[Tue Apr 09 00:02:01 2013 GMT] memory footprint: 3.22 MiB.
[Tue Apr 09 00:02:01 2013 GMT] Host /var/www/gwan/0.0.0.0_8082/#0.0.0.0
[Tue Apr 09 00:02:01 2013 GMT] log files enabled
[Tue Apr 09 00:02:01 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:02:01 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:02:01 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:f624bc05-f51507c3-61b20c9c-ecfe9e19
[Tue Apr 09 00:02:01 2013 GMT] Host /var/www/gwan/0.0.0.0_8083/#0.0.0.0
[Tue Apr 09 00:02:01 2013 GMT] log files enabled
[Tue Apr 09 00:02:01 2013 GMT] loaded main.c 39.13 KiB MD5:15795d7c-42184ef2-c8075784-a3aa84aa
[Tue Apr 09 00:02:01 2013 GMT] loaded process_kv.c 44.44 KiB MD5:349b8978-bbebb4eb-120c6f1a-7d06f98e
[Tue Apr 09 00:02:01 2013 GMT] loaded Connection Handler main.c 18.71 KiB MD5:525aa623-2728dd50-0e67a6ad-6763a30b
[Tue Apr 09 00:02:01 2013 GMT] memory footprint: 7.13 MiB.
[Tue Apr 09 00:02:11 2013 GMT] ------------------------------------------------
[Tue Apr 09 00:02:11 2013 GMT] G-WAN 4.3.14 64-bit (Mar 14 2013 07:33:12)
[Tue Apr 09 00:02:11 2013 GMT] ------------------------------------------------
[Tue Apr 09 00:02:11 2013 GMT] Local Time: Tue, 09 Apr 2013 02:02:11 GMT+2
....
So during 2 minutes g-wan loops and after g-wan is started normally by monit I believe.
Do you have an explanation and a workaround?
I recently change my web hosting provider and from now I use a VM under Microsoft Hyper-V.
The problem remains: G-Wan is restarted by Monit which logged the following events:
Wed, 16 Oct 2013 02:02:12: process PID changed from 2171 to 20631
Wed, 16 Oct 2013 02:02:13: process PPID changed from 1 to 2171
Wed, 16 Oct 2013 02:02:43: process PID changed from 20631 to 20975
Wed, 16 Oct 2013 02:03:13: process PID changed from 20975 to 21318
Wed, 16 Oct 2013 02:03:44: process PID changed from 21318 to 21573
Wed, 16 Oct 2013 02:04:14: process PID changed from 21573 to 2171
Wed, 16 Oct 2013 02:04:14: process PPID changed from 2171 to 1
Wed, 16 Oct 2013 02:33:06: process is not running
Wed, 16 Oct 2013 02:33:37: process is running with pid 776
It happens every day even on my new VM with another hypervisor.
I am not the only one with this behavior.
Do you have an explanation and a workaround?
Thank you
Jerome
The loop means that the child process is not responding, hence the parent killing the old child and restarting a new child.
Could you email us the whole log files (trace and gwan.log)? Your partial post is missing the the informative parts.
UPDATE
That new problem for 4-years old code that worked fine so far is a platform issue, for which we have found a workaround, to be published with the next release in a few weeks.

How can I tell what version of eclipse I have?

I'm trying to use the eclipse delta pack, and I need to use the same exact version of the delta pack as the version of eclipse I'm using. When looking at Help>About Eclipse I see:
Version: 3.7.0.v20110530-9gF7UHNFFt4cwE-pkZDJ7oz-mj4OSEIlu9SEv0f
Build id: I20110613-1736
However, it seems the versions listed on the eclipse site have a different format. Here are the versions listed here: http://archive.eclipse.org/eclipse/downloads/
3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400)
3.7RC3 Thu, 26 May 2011 -- 17:08 (-0400)
3.7RC2 Thu, 19 May 2011 -- 11:38 (-0400)
3.7RC1 Thu, 12 May 2011 -- 20:00 (-0400)
3.7M7 Thu, 28 Apr 2011 -- 08:48 (-0400)
3.7M6 Thu, 10 Mar 2011 -- 11:19 (-0500)
3.7M5 Thu, 27 Jan 2011 -- 20:34 (-0500)
3.7M4 Wed, 8 Dec 2010 -- 13:00 (-0500)
3.7M3 Thu, 28 Oct 2010 -- 14:41 (-0400)
3.7M2a Tue, 21 Sep 2010 -- 10:24 (-0400)
3.7M1 Thu, 5 Aug 2010 -- 17:00 (-0400)
Which version do I use?
Assuming you have the latest version.
I would say you can go for 3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400) looking at the Build id: I20110613-1736 - 2011 Jun 13 #17:36
You have the latest 3.7 build.
I20110613-1736 corresponds to 3.7 Mon, 13 Jun 2011 -- 17:36 (-0400)
It is not in the list of archived downloads you posted.
If you want you can try the one which is closest to yours: 3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400)