Problem trying to create a boolean view filter

Question: Drupal 7.22
Views 7.x-3.7
Hi,
I have two similar content types and have added a boolean field to both (x for one and y for the other).
I want to create a view that displays any of the two types if x or y is true.
If I add the first filter criteria: Content: x (= Yes), I see a result in the preview pane.
If I remove the first filter criteria and add the second filter criteria: Content: y (= Yes), I see a result in the preview pane.
So both work on their own.
If I try to 'or' them I get neither?
I have tried this in various ways (one filter group or two separate groups).
I have also tried simplifying this by changing the fields to text but the or is still not working?
Please can anyone help or point me in the right direction?
Thanks!
a.
Answer: Add a boolean value to both content types, should be the same boolean you created. no need to create a different boolean field for each content type.
create a view:

filter for the "Operator -  Is one of" and chose your two content types.
filter for you boolean field wich was added to both content types "Operator - Is one of" and select "yes" or 1 depending on your field yes value.
add what ever fields needed.

I have created two content types "content one" and "content two" and added the boolean field "check me" to both.
here is my view:
Comment: Hi saadlulu, that is fantastic, thanks so much for your help.  Very much appreciated.  Do I need to do anything to mark this as answered and credit you?  a.


Finding the Inverse of a Logarithmic Function with a Quadratic Argument

Question: $f(x)=\log_2(x^2-3x-4)$
Find $f^{-1}(x)$
My approach:
$y=\log_2(x^2-3x-4)$
$x=\log_2(y^2-3y-4)$
$2^x=y^2-3y-4$
$2^x+4=y(y-3)$
This is where I am stuck in my attempt on the problem.
Comment: You want to solve $y^2-3y-(2^x+4)=0$ for $y$
Comment: Apply the formula for quadratic equations and check which of the solutions satisfy $x=\log_2(y^2-3y-4)$
Comment: @Peter I don't quite understand why we should use the quadratic formula in order to find the inverse function, could you explain a bit more?
Answer: $f$ is not injective. Inverse does not exist.


How to remove inner div from create block in drupal 7

Question: Here, i struggling to remove inner div from create block in drupal 7.Here my working code with wrong result:

<?php  if($page['footer_bottom_left']){ print render($page['footer_bottom_left']);} ?>

  <?php  if($page['footer_bottom_left']){ print render($page['footer_bottom_right']);} ?>

I used string_tags before render it remove entire html tags. But i need to remove only block div and content div.Here my wrong result:

Plan du site

Acessibilite

Credits

Mentions legales

Correct format:

Plan du site

Acessibilite

Credits

Mentions legales

How to remove inner div from custom block in drupal 7.Kindly guide me..?
Comment: I feel like we need more information. Are you using a custom template file? A preprocess hook and adjustment for this specific block?
Comment: Yes i used custom template ! @AlexLaughnan and how to create custom function for changing block in template.php file?
Answer: The markup you require removing comes from one or more template files. While i have no idea what theme you are using, ill assume its one that hasn't overidden the default template files..
If you go and get the file modules/system/region.tpl.php and copy it to your theme folder you can remove the markup you do not require. e.g. delete

To get rid of the rest of the markup you will have to override the block template in the same fashion, to only remove the markup from 1 specific block you can use naming suggestions here https://www.drupal.org/node/1089656
note: Flush the caches for the theme to pick up the presence of any new template files.


Como mudar o ícone do arquivo compilado no Delphi?

Question: Desenvolvi um auto build para meus projetos, tudo funciona bem. Porém, nesse construtor de aplicativos o usuário poderá escolher o ícone a ser usado, mas não sei como fazer-lo. Já fiz uma breve pesquisa, mas sem sucesso.
Grato.
Answer: Segue o código abaixo de um exemplo que utilizei a um tempo atrás.
<code>unit icon;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, madRes, Vcl.StdCtrls,
  Vcl.Imaging.pngimage, Vcl.ExtCtrls, Vcl.ComCtrls, about;

type
  TForm1 = class(TForm)
    Image1: TImage;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    StatusBar1: TStatusBar;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Button2: TButton;
    GroupBox4: TGroupBox;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Edit2: TEdit;
    Image2: TImage;
    OpenDialog2: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    Edit1.Text := OpenDialog1.FileName;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

  if OpenDialog2.Execute then
  begin
    Image2.Picture.LoadFromFile(OpenDialog2.FileName);
    Edit2.Text := OpenDialog2.FileName;
  end;

end;

procedure TForm1.Button3Click(Sender: TObject);
var
  op: string;
  change: dword;
  valor: string;

begin

  valor := IntToStr(128);

  op := InputBox('Backup', 'Backup ?', 'Yes');

  if op = 'Yes' then
  begin
    CopyFile(PChar(Edit1.Text), PChar(ExtractFilePath(Application.ExeName) +
      'backup' + ExtractFileExt(Edit1.Text)), True);
  end;

  try
    begin
      change := BeginUpdateResourceW(PWideChar(wideString(Edit1.Text)), false);
      LoadIconGroupResourceW(change, PWideChar(wideString(valor)), 0,
        PWideChar(wideString(Edit2.Text)));
      EndUpdateResourceW(change, false);
      StatusBar1.Panels[0].Text := '[+] Changed !';
      Form1.StatusBar1.Update;
    end;
  except
    begin
      StatusBar1.Panels[0].Text := '[-] Error';
      Form1.StatusBar1.Update;

    end;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  Form1.Close();
  Form2.Close();
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  OpenDialog1.InitialDir := GetCurrentDir;
  OpenDialog2.InitialDir := GetCurrentDir;
  OpenDialog2.Filter := 'Icons|*.ico|';

end;

end.
</code>
Créditos: Hackman


Sorting database results by category

Question: I have a table in my database with the fields 'Category' and 'Title'. I have multiple records with the same category but other titles. What I'd like to do is print the category once on my page then show the all the titles with the same category.
So Something like this:
Category 1
Title 3(=newest)
Title 2
Title 1(=olddest)

Category 2
Title 1

Category 3
Title 3(=newest)
Title 2
Title 1(=olddest)

Im using the Laravel 4 framework with Eloquent. So I'm getting the result back as an JSON object.
What I have at the moment:
view
@foreach($photos as $photo)

    {{$photo->Category}}

    @foreach($photo as $category)
        {{ $photo->Title }}
    @endforeach

@endforeach

Controller
$photos = Photo::orderBy('Date')->get(); // Sort by so that newest photos come first per category
return View::make('myView')->with('photos', $photos);

When looking a bit further I came on to array_add helper but I'm not sure if I can use it and how I really should use it.
Can someone help me achieve the result I need?
Answer: You can do something like:
$photos = Photo::orderBy('category')->orderBy('created_at', 'desc')->get();
return View::make('myView')->with('photos', $photos);

Then
<?php $category = ''; ?>
@foreach($photos as $photo)

    @if($category != $photo->Category)
        {{$photo->Category}}
        <?php $category = $photo->Category; ?>
    @endif

    {{ $photo->Title }}

@endforeach

Comment: I can't really do that, because later I'll have to sort on date. The photos will be later be ordered on date.
Comment: You're right, I've changed the original question. Hope you still can help me with that
Comment: So you just have to order by category, first, and then created_at (descending). Just edited my answer.
Comment: Just tested it out, doesn't work completely though: I'm getting only the first category printed out and every title (even of other categories) printed 3 times. I'm looking for the bug in the code at the moment

Sorting database results by category


How do I monitor RAID status when using an external eSATA RAID5 SATA port multiplier?

Question: I am using an external eSATA device which takes 5 SATA drives and presents them as one large HW RAID5 to linux (ubuntu).
It uses a SiI3726 chipset.
Linux sees and handles the sata device just fine, but I'm wondering if there's any way to query/monitor the RAID5 status that's hiding behind this HW RAID.
(from dmesg -- I swear I don't have a 16T single drive...)
<code>[   16.409678] sd 4:0:0:0: [sde] 31255691264 512-byte logical blocks: (16.0 TB/14.5 TiB)
[   16.409727] sd 4:0:0:0: [sde] Write Protect is off
[   16.409730] sd 4:0:0:0: [sde] Mode Sense: 00 3a 00 00
[   16.409752] sd 4:0:0:0: [sde] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   16.463573]  sde: sde1
[   16.463785] sd 4:0:0:0: [sde] Attached SCSI disk
</code>
(from lshw)
<code>   *-disk:4
        description: ATA Disk
        product: SATA H/W RAID5
        physical id: 4
        bus info: scsi@4:0.0.0
        logical name: /dev/sde
</code>
Any guidance on peering at the system underneath would be appreciated.
RAID status is my big concern, but actual drive models would be helpful too.
I looked at some libatasmart tools, but couldn't find anything regarding SATA port multipliers in general.
There are utilities to check/set the RAID settings in OSX/Windows, so it is apparently possible.  I'm looking for a way to do this in Linux and then potentially add to Nagios, etc.
Here's what the HW looks like:
Comment: port multipliers are the devil!  Some of them have very ugly failure modes.  Where a failure on any single disk results in the failure of all of the disks behind the multiplier.  I have experienced this type of failure first hand.  See: http://www.zdnet.com/are-sata-port-multipliers-safe-7000011897/ https://www.usenix.org/system/files/fastpw13-paper7_0.pdf If you can avoid using one, I strongly suggest that you do.  At least keep a good backup.
Comment: they may be the devil, but I'm trying to work with the devil I've found in the colo -- I probably wouldn't buy them myself.
Comment: @JoelK Can you provide information on the manufacturer/make/model of the external eSATA device? Without that information, it's difficult to help you.
Comment: Also, can you show the relevant portion of `lspci`?
Comment: Sorry to say, you would need a driver for Linux to support this feature. Without the driver, there is no way that Linux will be able to see the devices which are 'multiplexed' (e.g. Many channels combined into one). It will only see the single device. The same problem exists with a number of cheap RAID controllers.
Comment: lspci shows the onboard SATA controller, but I'm not sure I see how that helps..  Intel Corporation 631xESB/632xESB SATA AHCI Controller (rev 09)
Comment: motherboard is a Supermicro X7DVL-3. Expander is a DATOptic  -- there is an OSX utility that works with a USB-eSATA adapter to 'configure' the device -- perhaps it's possible to snoop what's happening over usb -- http://www.datoptic.com/ec/1u-rackmount-port-multiplier-esata-host.html
Comment: @JoelK Don't you have an eSATA card in your server?
Comment: @ewwhite I mentioned the motherboard because it has the sata and sas onboad.  LSISAS 1068E 8-Port  SAS controller, and ESB2  SATA controller are both on the motherboard...  (not a seperate card)  http://www.supermicro.com/products/motherboard/Xeon1333/5000V/X7DVL-3.cfm
Comment: @JoelK How are you connected to the external enclosure?
Comment: @JoelK: Which controller is the enclosure connected to-- the LSI SAS or the Intel SATA? Seeing the output of the kernel boot messages would certainly be helpful, if you're willing to post it.
Comment: @ewwhite connected via eSATA
Answer: You may be one of the only people who have run into this issue :)
Well, possibly... The use of SATA multipliers is a no-no in server-class systems. Heck, using SATA is a bit risky these days, with ever-increasing drive capacities.
It's not surprising that you've had a difficult time finding information about the SATA port multiplier and monitoring under Linux. Using a SAS expander is the preferred and more supportable approach. Expanders are the norm for server backplanes and external storage JBOD enclosures. As a result, port multipliers are somewhat rare and don't have much mindshare. Adding a layer of abstraction through eSATA almost eliminates any chance of your drives being exposed to the OS, unless the card you're using in the host has OS-lever driver support.
What type of eSATA host card are you using?
At this point, I would rely on the enclosure and visual LED status checks to determine array health. Provide more information about the device, and there's a slim chance status can be communicated to the host (if using the right card), but I wouldn't expect it otherwise.
Edit:
The enclosure being used here does not have LED indicators for drive health. You won't have any way of visually determining drive array status or doing this via your host.

Edit
I reached out to the manufacturer for support:
The OP post a wrong part that is why no one can help :-)
See: https://serverfault.com/a/644247/13325
Comment: @JoelK The enclosure details weren't clear as of your initial question. The details were scarce. I think you're saying that you have this external unit connected to a motherboard that has an eSATA connection, or maybe an SATA adapter plate. I explained that Linux support for this is rightfully poor. I'm sorry it's not what you want to hear, but your best shot at getting RAID status with what you have is to use an HBA that has known-good Linux support *or* to contact the manufacturer.
Comment: The point of posting the photo was to illustrate how barebones the enclosure is and that there would be no form of monitoring or diagnostics via [SCSI Enclosure Services](http://en.wikipedia.org/wiki/SCSI_Enclosure_Services) (*or the SATA equivalent*).
Comment: So you recommend a web cam? :-)
Comment: @RonaldPottol Possibly!
Comment: @ewwhite Posting images from the URLs that I gave to you  isn't giving me any new information.  I already know what the system looks like and about the LEDs on the front.  I need a software mechanism to poll the RAID status of a port multiplier.   There are utilities for Windows and OSX that are able to get this info, I'm looking for equivalent work in Linux.  I know this all works even over USB-eSATA (this is how we provision the units) -- again, I just need some visibility in Linux-land.
Comment: ah, well you don't have a picture of the important which is in the chassis -- I'll put that up here.
Comment: It looks like I was right w/ my guess on the part, then, based on the OP's picture.  >smile<  re: bringing in the manufacturer - touche!   Edit: Actually, I'm a little confused. The page the manufacturer links to has no eSATA port. I wonder if the manufacturer linked to the right thing... Hmm...
Answer: This is DATOptic-Support Team, the manufacture of the 1U stand-alone Hardware RAID.
The control uses in this 1U rack is NOT SiI-3726.
It is JM393: http://www.datoptic.com/ec/5x-drive-hardware-raid-controller.html
There is some GUI in Linux but not all flavor - go the page and click support TAB
There is some CLI and OpenSuSE RAID GUI...
Comment: yes, it's +x     -- here's the strace
Comment: strace ./HWRaidManager.dat
execve("./HWRaidManager.dat", ["./HWRaidManager.dat"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
dup(2)                                  = 3
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
fstat(3, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fdb5ac8f000
lseek(3, 0, SEEK_CUR)    = -1 ESPIPE (Illegal seek)
write(3, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
Comment: I try to run http://www.datoptic.com/Download/HWRaidManager.dat, and I get -bash: ./HWRaidManager.dat: No such file or directory..
Comment: file says it's dynamically linked.HWRaidManager.dat: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, BuildID[sha1]=0x61e72a2461d2b0683ba056b6d76995fbae0844eb, not stripped
 but ldd says  not a dynamic executable
Comment: Did you make the file executable?
Answer: I feel like the enclosure you're using has this RAID/port-multiplier board in it. (The pictures seem to match-up.)  (Ugh-- actually, it's close but not exactly the same. The jumper layout is like the model SPM393PS-SEV, but that model is supposedly 4 disks / 2 hosts.)
If that's the case, the manufacturer's web site purports to have a "X86 - Linux Daemon Tool - CLI" package available, among other software offerings. Not having one of these things, obviously, I can't actually run it, but the strings in the file seem to be promising.
If it is that unit and the Linux-based software doesn't work you could always strap an Arduino to the pins of the status LED on the back and monitor that. (Ugly, to be sure, but it could be made to work...)


Extension of the Jacobi triple product identity

Question: The Jacobi triple product identity is:
$$\prod\limits_{n=1}^{ \infty }(1-q^{2n})(1+zq^{2n-1})(1+z^{-1}q^{2n-1})=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2}  $$
I would like to extend the idea for $\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $
My idea is below for extension:
Let's assume we define $G(z,q,h)$ as
$$G(z,q,h)\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $$
$$G(z,q,h)\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $$
$z=ZQ^{2}h^{3}$
$q=Qh^{3}$
$$G(ZQ^{2}h^{3},Qh^{3},h)\prod\limits_{n=1}^{ \infty }(1+ZQ^{2}h^{3}(Qh^{3})^{2n-1}h^{3n^2-3n+1})(1+(ZQ^2h^3)^{-1}(Qh^3)^{2n-1}h^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty Z^n Q^{2n}h^{3n} Q^{n^2} h^{3n^2} h^{n^3} $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\prod\limits_{n=1}^{ \infty }(1+ZQ^{2n+1}h^{3n^2+3n+1})(1+Z^{-1}Q^{2n-3}h^{-3n^2+9n-7})=\sum\limits_{n = - \infty }^ \infty Z^n Q^{2n+n^2}h^{3n+3n^2+n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\frac{(1+Z^{-1}Q^{-1}h^{-1})}{(1+ZQh)}\prod\limits_{n=1}^{ \infty }(1+ZQ^{2n-1}h^{3n^2-3n+1})(1+Z^{-1}Q^{2n-1}h^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty Z^n Q^{2n+n^2}h^{3n+3n^2+n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\frac{(1+Z^{-1}Q^{-1}h^{-1})}{(1+ZQh)} \frac{\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}}{G(Z,Q,h)}=\sum\limits_{n = - \infty }^ \infty Z^n Q^{2n+n^2}h^{3n+3n^2+n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}=G(Z,Q,h)ZQh\sum\limits_{n = - \infty }^ \infty Z^n Q^{2n+n^2}h^{3n+3n^2+n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}=G(Z,Q,h)\sum\limits_{n = - \infty }^ \infty Z^{n+1} Q^{1+2n+n^2}h^{1+3n+3n^2+n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}=G(Z,Q,h)\sum\limits_{n = - \infty }^ \infty Z^{n+1} Q^{(n+1)^2}h^{(n+1)^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}=G(Z,Q,h)\sum\limits_{n = - \infty }^ \infty Z^n Q^{n^2} h^{n^3}  $$
$$G(ZQ^{2}h^{3},Qh^{3},h)=G(Z,Q,h) \tag 1$$
If $h=1$ then
$G(z,q,1)=\prod\limits_{n=1}^{ \infty }(1-q^{2n})$ can be gotten from Jacobi_triple_product.
I really wonder how I can find the function $G(z,q,h)$. Please help me which Technics can be applied to find it. Also If you know there is other works about this subject, please share links and references.
Thanks a lot for responses.
Note:
If $z=x^3$,$q=x^3$,$h=x$
$$G(x^3,x^3,x)\prod\limits_{n=1}^{ \infty }(1+x^3x^{6n-3}x^{3n^2-3n+1})(1+x^{-3}x^{6n-3}x^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty x^{3n} x^{3n^2} x^{n^3} $$
$$xG(x^3,x^3,x)\prod\limits_{n=1}^{ \infty }(1+x^{3n^2+3n+1})(1+x^{-3n^2+9n-7})=\sum\limits_{n = - \infty }^ \infty x^{1+3n+3n^2+n^3}  $$
$$xG(x^3,x^3,x)\frac{1}{(1+x)}\prod\limits_{n=1}^{ \infty }(1+x)(1+x^{3n^2+3n+1})(1+x^{-1})(1+x^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty x^{(n+1)^3}  $$
$$xG(x^3,x^3,x)\frac{(1+x^{-1})}{(1+x)}\prod\limits_{n=1}^{ \infty }(1+x^{3n^2-3n+1})(1+x^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty x^{n^3}  $$
$$G(x^3,x^3,x)\prod\limits_{n=1}^{ \infty }(1+x^{3n^2-3n+1})(1+x^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty x^{n^3}  $$
The relation is below for $G()$ from Equation 1 If $z=x^3$,$q=x^3$,$h=x$
$$G(x^{12},x^6,x)=G(x^3,x^3,x) \tag 2$$
$$G(x^{12},x^6,x)=G(x^3,x^3,x)=G(1,1,x) \tag 3$$
EDIT: I thought If I can find a few term of $G(z,q,h)$ by hand and maybe seen what the pattern of $G(z,q,h)$. I really wonder if we can find $G(z,q,h)$ in product terms as Jacobi did in his product formula.
$$G(z,q,h)\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $$
$$G(z,q,h)(1+zqh)(1+z^{-1}q^{1}h^{-1})(1+zq^3h^7)(1+z^{-1}q^{3}h^{-7})....=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}  $$
$$G(z,q,h)(1+q^2+q(zh+z^{-1}h^{-1}))(1+q^6+q^3(zh^7+z^{-1}h^{-7}))...=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}$$
$$G(z,q,h)(1+q^2+q^6+q^8+q(zh+z^{-1}h^{-1})+q^7(zh+z^{-1}h^{-1})+q^3(zh^7+z^{-1}h^{-7})+q^5(zh^7+z^{-1}h^{-7})+q^4(zh+z^{-1}h^{-1})(zh^7+z^{-1}h^{-7}))...=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $$
$$G(z,q,h)( 1+q^2+q^6+q^8+q(zh+z^{-1}h^{-1})+q^7(zh+z^{-1}h^{-1})+q^3(zh^7+z^{-1}h^{-7})+q^5(zh^7+z^{-1}h^{-7})+q^4(z^2h^8+z^{-2}h^{-8})+q^4(h^{6}+h^{-6}))...=\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3} $$
$$G(z,q,h)( 1+q^2+q^6+q^8+q(zh+z^{-1}h^{-1})+q^7(zh+z^{-1}h^{-1})+q^3(zh^7+z^{-1}h^{-7})+q^5(zh^7+z^{-1}h^{-7})+q^4(z^2h^8+z^{-2}h^{-8})+q^4(h^{6}+h^{-6}))...= 1+q (zh+z^{-1}h^{-1})+q^4 (z^2h^8+z^{-2}h^{-8})+.... $$
EDIT: (Updated on 15th April)
We can see first 3 term of $G(z,q,h)$ easily.To find 4th term:
$$G(z,q,h)=1-q^2+q^3\left( (zh+z^{-1}h^{-1}) - (zh^7+z^{-1}h^{-7}) \right) +a_4 q^4 +....  $$
$$G(z,q,h)(1+q^2+q^6+q^8+q(zh+z^{-1}h^{-1})+q^7(zh+z^{-1}h^{-1})+q^3(zh^7+z^{-1}h^{-7})+q^5(zh^7+z^{-1}h^{-7})+q^4(z^2h^8+z^{-2}h^{-8})+q^4(h^{6}+h^{-6}))...= 1+q (zh+z^{-1}h^{-1})+q^4 (z^2h^8+z^{-2}h^{-8})+.... $$
$$(1-q^2+q^3\left( (zh+z^{-1}h^{-1}) - (zh^7+z^{-1}h^{-7}) \right) +a_4 q^4 +.... ) (1+q^2+q^6+q^8+q(zh+z^{-1}h^{-1})+q^7(zh+z^{-1}h^{-1})+q^3(zh^7+z^{-1}h^{-7})+q^5(zh^7+z^{-1}h^{-7})+q^4(z^2h^8+z^{-2}h^{-8})+q^4(h^{6}+h^{-6}))...= 1+q (zh+z^{-1}h^{-1})+q^4 (z^2h^8+z^{-2}h^{-8})+.... $$
$a_4=-1+(z^2h^8+z^{-2}h^{-8})-(z^2h^2+z^{-2}h^{-2})$
Thus first 4 terms of $G(z,q,h)$ is:
$$G(z,q,h)=1-q^2+q^3\left( (zh+z^{-1}h^{-1}) - (zh^7+z^{-1}h^{-7}) \right) + q^4 \left(-1+(z^2h^8+z^{-2}h^{-8})-(z^2h^2+z^{-2}h^{-2})  \right) +....  $$
If we order it little bit more .
$$G(z,q,h)=1-q^2-q^4 +q^3\left( zh(1-h^6) + z^{-1}h^{-1}(1-h^{-6}) \right) + q^4 \left(z^2h^2(h^6-1)+z^{-2}h^{-2}(h^{-6}-1)  \right) +....  $$
I will update If I find more terms of $G(z,q,h)$
EDIT: (Updated on 17th April)
I have found 5th term .
$a_5= (zh+z^{-1}h^{-1}) - (z h^{19}+z^{-1}h^{-19}) +(z^3 h^3+z^{-3}h^{-3}) - (z^3 h^9+z^{-3}h^{-9})$
$$G(z,q,h)=1-q^2+q^3\left( (zh+z^{-1}h^{-1}) - (zh^7+z^{-1}h^{-7}) \right) + q^4 \left(-1+(z^2h^8+z^{-2}h^{-8})-(z^2h^2+z^{-2}h^{-2})  \right) + q^5\left( (zh+z^{-1}h^{-1}) - (z h^{19}+z^{-1}h^{-19}) +(z^3 h^3+z^{-3}h^{-3}) - (z^3 h^9+z^{-3}h^{-9}) \right)+ ....  $$

$$G(z,q,h)=1-q^2-q^4 +q^3\left( zh(1-h^6) + z^{-1}h^{-1}(1-h^{-6}) \right) + q^4 \left(z^2h^2(h^6-1)+z^{-2}h^{-2}(h^{-6}-1)  \right) + q^5 \left( zh(1-h^{18}) + z^{-1}h^{-1}(1-h^{-18})+z^3h^3(1-h^6)+z^{-3}h^{-3}(1-h^{-6})  \right)+....  $$
I have not seen a general pattern of the terms yet but I believe there is very beautiful pattern in it. If you help me to find more terms , I will be very appreciated. Maybe the pattern of terms of $G(z,q,h)$ can be seen more .Thanks.
EDIT: 27/01/2020
$$G(z,q,h)=\frac{\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}}{\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}= C(q,h)+\sum\limits_{n = 1 }^ \infty \frac{A_n(q,h)}{(1+zq^{2n-1}h^{3n^2-3n+1})}+\sum\limits_{n = 1 }^ \infty \frac{B_n(q,h)}{(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}$$
If we apply $z-->z^{-1}$  and $h-->h^{-1}$
$$B_n(q,h)=A_n(q,h^{-1})$$
$$C(q,h)=C(q,h^{-1})$$
$$G(z,q,h)=\frac{\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}}{\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}= C(q,h)+\sum\limits_{n = 1 }^ \infty \frac{A_n(q,h)}{(1+zq^{2n-1}h^{3n^2-3n+1})}+\sum\limits_{n = 1 }^ \infty \frac{A_n(q,h^{-1})}{(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}$$
If we apply
$z=ZQ^{2}h^{3}$
$q=Qh^{3}$
$$\frac{\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}}{\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}= C(qh^3,h)+\sum\limits_{n = 2 }^ \infty \frac{A_{n-1}(qh^3,h)}{(1+zq^{2n-1}h^{3n^2-3n+1})}+\frac{A_1(qh^3,h^{-1})}{(1+z^{-1}q^{-1}h^{-1})}+\sum\limits_{n = 1 }^ \infty \frac{A_{n+1}(qh^3,h^{-1})}{(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}$$
$$A_{n+1}(q,h)=A_{n}(qh^3,h)$$  for $n>0$
$$C(q,h)=C(qh^3,h)-\frac{A_1(q,h)}{(1+zqh)}+\frac{A_1(qh^3,h^{-1})}{(1+z^{-1}q^{-1}h^{-1})}$$
$$C(q,h)=C(qh^3,h)-\frac{A_1(q,h)}{(1+zqh)}+\frac{A_1(qh^3,h^{-1})zqh}{(1+zqh)}$$
$$A_1(q,h)=C(qh^3,h)-C(q,h)$$
$$A_n(q,h)=C(qh^{3n},h)-C(qh^{3(n-1)},h)$$
$$G(z,q,h)=\frac{\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}}{\prod\limits_{n=1}^{ \infty }(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}= C(q,h)+\sum\limits_{n = 1 }^ \infty \frac{C(qh^{3n},h)-C(qh^{3(n-1)},h)}{(1+zq^{2n-1}h^{3n^2-3n+1})}+\sum\limits_{n = 1 }^ \infty \frac{C(qh^{-3n},h)-C(qh^{-3(n-1)},h)}{(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})}$$
$z=-q^{-1} h^{-1}$
$$\frac{\sum\limits_{n = - \infty }^ \infty (-1)^n q^{n^2-n} h^{n^3-n}}{\prod\limits_{n=2}^{ \infty }(1-q^{2n-2}h^{3n^2-3n})\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{-3n^2+3n})}= C(qh^{3},h)-C(q,h)$$
$q=qh^{-3/2}$
$$C(qh^{3/2},h)-C(qh^{-3/2},h)=\frac{\sum\limits_{n = - \infty }^ \infty (-1)^n q^{n^2-n} h^{-3/2(n^2-n)} h^{n^3-n}}{\prod\limits_{n=2}^{ \infty }(1-q^{2n-2}h^{-3(n-1)}h^{3n^2-3n})\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{-3n^2})}$$
$$C(qh^{3/2},h)-C(qh^{-3/2},h)=\frac{\sum\limits_{n = - \infty }^ \infty (-1)^n q^{n^2-n} h^{-3/2(n^2-n)} h^{n^3-n}}{\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{3n^2})\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{-3n^2})}$$
$$C(qh^{3/2},h)-C(qh^{-3/2},h)=\frac{\sum\limits_{n = - \infty }^ \infty (-1)^{n+1} q^{n(n+1)} h^{\frac{n(n+1)(2n+1)}{2}}}{\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{3n^2})\prod\limits_{n=1}^{ \infty }(1-q^{2n}h^{-3n^2})}$$
$q-->q^{1/2}$,
$h-->h^{1/3}$
$$[C(\sqrt{q/h},\sqrt[3] {h})-C(\sqrt{qh},\sqrt[3] {h})]\prod\limits_{n=1}^{ \infty }(1-q^{n}h^{n^2})\prod\limits_{n=1}^{ \infty }(1-q^{n}h^{-n^2})=\sum\limits_{n = - \infty }^ \infty (-1)^{n} q^{\frac{n(n+1)}{2}} h^{\frac{n(n+1)(2n+1)}{6}}$$
$$C(q,1)=\prod\limits_{n=1}^{ \infty }(1-q^{2n})$$
I do not know how to find $C(q,h)$ but few terms of it :
$$C(q,h)=C(q,h^{-1})=1-q^2-q^4+....$$
Maybe someone can help me to find more terms and its closed form.
Thanks a lot for helps
EDIT: 30/01/2020
I have new idea about zeros of $\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}$
The direction of this question will not give zeros for$\sum\limits_{n = - \infty }^ \infty z^n q^{n^2} h^{n^3}$ as @mr_e_man showed in his answer. Thus I will go in different way in another question.
I focused on zeros in a new question.
My new question can be found here:
Comment: This a very interesting result, it's hard to check but I will see when I have some time
Comment: Where did those products come from, with $h^{n^3-(n-1)^3}$? What if $G$ cancels those and replaces them with different products?
Comment: Notice that this only converges when $|h|=1$ and $|q|<1$. Including another factor $r^{n^4}$ with $|r|<1$ would make it converge for any $h\neq0$, but would obviously complicate everything. Yet the quartic form can be reparametrized, analogously to Ramanujan's theta function, as $$z^nq^{n^2}h^{n^3}r^{n^4}=a^{(n-3)(n-2)(n-1)n/4!}b^{(n-2)(n-1)n(n+1)/4!}c^{(n-1)n(n+1)(n+2)/4!}d^{n(n+1)(n+2)(n+3)/4!}$$ which has the advantage that all exponents are non-negative. The sum converges at least when $|abcd|<1$. Another possible parametrization uses the exponents $n(n\pm1)/2,\;\big(n(n\pm1)/2\big)^2$.
Comment: And I think we should choose a parametrization (whether quartic or cubic) that simplifies nicely when $n$ is replaced with $n+1$.
Comment: On second thought, it looks like we can't avoid negative exponents; they appear with $n\mapsto n+1$, for example $a^{n(n-1)/2}b^{n(n+1)/2}\mapsto b(b^{-1})^{n(n-1)/2}(ab^2)^{n(n+1)/2}$. As for "simplifying nicely", I had in mind specifically $$\sum_{n\in\mathbb Z}a^nb^{\binom n2}c^{\binom n3}d^{\binom n4}=\sum_{n\in\mathbb Z}a^{n+1}b^{\binom{n+1}2}c^{\binom{n+1}3}d^{\binom{n+1}4}$$ $$=a\sum_{n\in\mathbb Z}(ab)^n(bc)^{\binom n2}(cd)^{\binom n3}d^{\binom n4}$$ because the binomial coefficients satisfy $\binom{n+1}k=\binom nk+\binom n{k-1}$.
Comment: Here's a promising special case: If we have a root of unity $h^6=1$, then $$\sum_{n\in\mathbb Z}z^nq^{n^2}h^{n^3}=\sum_{n\in\mathbb Z}(zh)^nq^{n^2}$$ $$=\prod_{n=1}^\infty(1-q^{2n})(1+zhq^{2n-1})(1+z^{-1}h^{-1}q^{2n-1})$$ $$=\prod_{n=1}^\infty(1-q^{2n})(1+zq^{2n-1}h^{3n^2-3n+1})(1+z^{-1}q^{2n-1}h^{-3n^2+3n-1})$$ since $n^3\equiv n\bmod6$ and $3n^2-3n=6\binom n2\equiv0\bmod6$.
Comment: Actually, reparametrizing $$z^nq^{n^2}h^{n^3}=a^nb^{\binom n2}c^{\binom n3}=(ab^{-1/2}c^{1/3})^n(b^{1/2}c^{-1/2})^{n^2}(c^{1/6})^{n^3}$$ gives $c=h^6=1$, so that special case _trivially_ reduces to the classical triple product. I'll have to think more about this, and try to consolidate these wandering comments...
Comment: @mr_e_man : Thanks a lot for your comments. Yes I know, $h^6=1$ works fine Reparametrizing is very good idea. Main problem is the products if really zeros or not as you noted in your your first comment. I asked other related questions about this topic. You can see if you want  https://math.stackexchange.com/questions/2839426/prove-or-disprove-that-sum-limits-k-1-t-fk-0-where-fm-sum-limits
Comment: For the arrow, instead of writing "- - >" you can use the symbol "\to" or "\mapsto".
Comment: Does this series ever converge (except when it is $0$ or when $|h|=1$) ? When $z,q \ne 0$ and $|h|>1$ we have $\lim_{n\to\infty} |z^n q^{n^2} h^{n^3}|=\infty$; but when $z,q \ne 0$ and $0<|h|<1$ we have $\lim_{n\to -\infty} |z^n q^{n^2} h^{n^3}|=\infty$
Comment: @GEdgar  this only converges when $|h|=1$ and $|q|<1$.  You can think that $h=e^{ix}$  that x is a real number.
Answer: $$\sum_{n\in\mathbb Z}z^nq^{n^2}h^{n^3}$$
By your conjecture, this function contains $(1+zqh)$ as a factor. Let's generalize a bit to $(1+zqh^c)$, for some constant $c$. But if that were true, then it would have to vanish when
$$z=-q^{-1}h^{-c},$$
that is,
$$0=\sum_{n\in\mathbb Z}(-1)^nq^{n^2-n}h^{n^3-nc}$$
$$=\cdots+q^6h^{-8+2c}-q^2h^{-1+c}+q^0h^0-q^0h^{1-c}+q^2h^{8-2c}-q^6h^{27-3c}+q^{12}h^{64-4c}-\cdots$$
$$=\big(1-h^{1-c}\big)q^0-\big(h^{-1+c}-h^{8-2c}\big)q^2+\big(h^{-8+2c}-h^{27-3c}\big)q^6-\cdots.$$
Since this is supposed to vanish for all $|q|<1$, all coefficients of powers of $q$ must vanish:
$$h^{1-c}=1,\quad h^{8-2c}=h^{-1+c},\quad h^{27-3c}=h^{-8+2c},\quad\cdots$$
$$h^{1-c}=1,\quad h^{9-3c}=1,\quad h^{35-5c}=1,\quad\cdots$$
and since $h=e^{i\theta}$ is also a variable, while the right sides of the equations are constant, the exponents must vanish:
$$c=1,\quad c=3,\quad c=7,\quad\cdots$$
which is clearly impossible. (More explicitly, if $h^p=e^{i\theta p}=1$, then $\theta p=n2\pi$ for some integer $n$; the right side takes discrete values, while the left side takes a continuum of values unless $p=0$.)
Therefore, $(1+zqh^c)$ is not a factor of the function.
By similar reasoning, for any constants $a,b,c$ with $a\neq0$ and either choice of sign, $(1\pm z^aq^bh^c)$ is not a factor. (There may be factors with $a=0$, but a product of these doesn't depend on $z$, while the original function does depend on $z$.)
Comment: : Thanks a lot for your answer and comment for this old question. I started to work on it again after your comments. It became again active subject for me.   I asked a new question  that I focused on zeros. Maybe you can wish to check it  .Best Regards


How to translate a word in <a title (tpl)?

Question: How to translate the word Menu ?
t('Menu') (after class="tb-main-menu-button ...) doesn't work in this case.
<?php
if($menu_bar = render($page['menu_bar'])): ?>

<div class="container <?php print $grid; ?>">

Menu
<?php print $menu_bar; ?>

Comment: where is this snippet ( which file) ?  did you try to put `t('Menu')` in another place? are you sure you translate it ?
Comment: Did you add `` ?
Comment: Menu is right there after class="tb-main-menu-button responsive-menu-button"> I tried to put t('Menu') but it doesn't work in the class. What should be done?
Answer: Try: <?php print t('Menu') ?>
Like so:
<?php print t('Menu') ?>

This will make the string translatable in the admin interface.


new variables from untidy data based on suffix matching

Question: I'd like to restructure my data frame, which features data on whether a home was viewed, purchased, or sold, and what the date for the viewing/purchase/sale was.
The data has been enterred in such a way that whilst there are multiple date variables (var_datevar_A5_3_B32,var_datevar_A5_4_B33,var_datevar_A5_5_B34), each of these variables contains a mix of sales-dates, purchase-dates, and viewing-dates.
So if a want to know if a date in eg var_datevar_A5_3_B32 is a viewing, sales, or purchase date, I need to check variables with a matching prefix (A5_3_B32), ie  var_viewed_A5_3_B32, var_sold_A5_3_B32, and var_purchased_A5_3_B32, and see which one is coded as "Y".
I'd like to add three new variables to my data frame: a sales dates only variable (var_date_sold), a purchase dates only variable (var_date_purchased), and a viewing dates only variable (var_date_viewed), like in dfgoal.
I've made an attempt but apart from that I can't figure out how to paste the date into my new variable, I'd like a more general solution because in my real data set I've got loads of variables like this.
Thanks for any help!
# Starting point
df <- data.frame(var_home=c("a","b","c","d","e"),
                 var_datevar_A5_3_B32=c("01-12-2012","05-06-2014","03-09-2015","03-03-2016",NA),var_datevar_A5_4_B33=c("07-12-2012",NA,"07-07-2017","13-03-2016",NA),var_datevar_A5_5_B34=c("05-03-2013",NA,NA,"23-03-2016",NA),var_purchased_A5_3_B32=c(NA,"Y",NA,NA,NA),var_purchased_A5_4_B33=c("N","N","Y",NA,NA),var_purchased_A5_5_B34=c("Y",NA,NA,NA,NA),
                 var_viewed_A5_3_B32=c("Y","N","Y","Y",NA),var_viewed_A5_4_B33=c(NA,NA,NA,"Y","N"),var_viewed_A5_5_B34=c(NA,NA,NA,"Y",NA),var_sold_A5_3_B32=c("NA","N",NA,"N",NA),var_sold_A5_4_B33=c("Y","N",NA,"N",NA),var_sold_A5_5_B34=c("N",NA,NA,NA,"Y"))

# Goal
dfgoal <- data.frame(var_home=c("a","b","c","d","e"),
                 var_datevar_A5_3_B32=c("01-12-2012","05-06-2014","03-09-2015","03-03-2016",NA),var_datevar_A5_4_B33=c("07-12-2012",NA,"07-07-2017","13-03-2016",NA),var_datevar_A5_5_B34=c("05-03-2013",NA,NA,"23-03-2016",NA),var_purchased_A5_3_B32=c(NA,"Y",NA,NA,NA),var_purchased_A5_4_B33=c("N","N","Y",NA,NA),var_purchased_A5_5_B34=c("Y",NA,NA,NA,NA),
                 var_viewed_A5_3_B32=c("Y","N","Y","Y",NA),var_viewed_A5_4_B33=c(NA,NA,NA,"Y","N"),var_viewed_A5_5_B34=c(NA,NA,NA,"Y",NA),var_sold_A5_3_B32=c("NA","N",NA,"N",NA),var_sold_A5_4_B33=c("Y","N",NA,"N",NA),var_sold_A5_5_B34=c("N",NA,NA,NA,"Y"),
                 var_date_viewed =c("01-12-2012",NA,"03-09-2015","03-03-2016,13-03-2016,23-03-2016",NA),var_date_sold=c("07-12-2012",NA,NA,NA,NA),var_date_purchased=c("05-03-2013","05-06-2014","07-07-2017",NA,NA))

# Attempt pseudo-code
var_date_viewed <- ifelse((!is.na(var_datevar_A5_3_B32) & var_viewed_A5_3_B32=="Y") | (!is.na(var_datevar_A5_4_B33) & var_viewed_A5_4_B33=="Y") | (!is.na(var_datevar_A5_5_B34) & var_viewed_A5_5_B34=="Y"), PASTE_THE_DATE,NA)

Answer: A different approach using the packages dplyr, tidyr and stringr:
library(tidyr)
library(dplyr)
library(stringr)

df %>%
  gather(datevar, date, contains("datevar")) %>%
  gather(action, action_yn, -datevar, -date, -var_home) %>%
  mutate(date_code = str_extract(datevar, "A\\d_\\d_B\\d\\d$"),
         action_code = str_extract(action, "A\\d_\\d_B\\d\\d$"),
         action = str_extract(action, "^var_[[a-z][^_]]+"),
         action = str_remove(action, "^var_")) %>%
  filter(date_code == action_code) %>%
  filter(action_yn == "Y") %>%
  select(-datevar) %>%
  group_by(var_home, action) %>%
  summarise(date = str_c(date, collapse = ",")) %>%
  mutate(action = str_c("var_date_", action)) %>%
  spread(action, date)

# A tibble: 5 x 4
# Groups:   var_home [5]
#   var_home var_date_purchased var_date_sold var_date_viewed
#   <fct>    <chr>              <chr>         <chr>
# 1 a        05-03-2013         07-12-2012    01-12-2012
# 2 b        05-06-2014         NA            NA
# 3 c        07-07-2017         NA            03-09-2015
# 4 d        NA                 NA            03-03-2016,13-03-2016,23-03-2016
# 5 e        NA                 NA            NA

I'll split the code into several parts to explain, what is done.
First transform the data from wide to long format and first gather all datvar and then all actions together in one column each with the corresponding value (date and action_yn).
df <- df %>%
  gather(datevar, date, contains("datevar")) %>%
  gather(action, action_yn, -datevar, -date, -var_home)

df
#     var_home              datevar       date                 action action_yn
# 1          a var_datevar_A5_3_B32 01-12-2012 var_purchased_A5_3_B32      <NA>
# 2          b var_datevar_A5_3_B32 05-06-2014 var_purchased_A5_3_B32         Y
# 3          c var_datevar_A5_3_B32 03-09-2015 var_purchased_A5_3_B32      <NA>
# 4          d var_datevar_A5_3_B32 03-03-2016 var_purchased_A5_3_B32      <NA>
# 5          e var_datevar_A5_3_B32       <NA> var_purchased_A5_3_B32      <NA>
# ...

Then extract the code (the last part of each column name) with a regular expression. Here I assume, that this is always structured like A#_#_B## where # is a number. Further the specific action is extracted again using a regular exxpression.
df <- df %>%
  mutate(date_code = str_extract(datevar, "A\\d_\\d_B\\d\\d$"),
         action_code = str_extract(action, "A\\d_\\d_B\\d\\d$"),
         action = str_extract(action, "^var_[[a-z][^_]]+"),
         action = str_remove(action, "^var_"))

df
#     var_home              datevar       date    action action_yn date_code action_code
# 1          a var_datevar_A5_3_B32 01-12-2012 purchased      <NA>  A5_3_B32    A5_3_B32
# 2          b var_datevar_A5_3_B32 05-06-2014 purchased         Y  A5_3_B32    A5_3_B32
# 3          c var_datevar_A5_3_B32 03-09-2015 purchased      <NA>  A5_3_B32    A5_3_B32
# 4          d var_datevar_A5_3_B32 03-03-2016 purchased      <NA>  A5_3_B32    A5_3_B32
# 5          e var_datevar_A5_3_B32       <NA> purchased      <NA>  A5_3_B32    A5_3_B32
# ...

As we're only interested in the actions with "Y" and onlöy the dates corresponding to the right action we filter by de codes and action_yn. The datevar is not needed anymore and therefore dropped.
df <- df %>%
  filter(date_code == action_code) %>%
  filter(action_yn == "Y") %>%
  select(-datevar)

df
#     var_home       date    action action_yn date_code action_code
#  1         b 05-06-2014 purchased         Y  A5_3_B32    A5_3_B32
#  2         c 07-07-2017 purchased         Y  A5_4_B33    A5_4_B33
#  3         a 05-03-2013 purchased         Y  A5_5_B34    A5_5_B34
#  4         a 01-12-2012    viewed         Y  A5_3_B32    A5_3_B32
#  5         c 03-09-2015    viewed         Y  A5_3_B32    A5_3_B32
#  6         d 03-03-2016    viewed         Y  A5_3_B32    A5_3_B32
#  7         d 13-03-2016    viewed         Y  A5_4_B33    A5_4_B33
#  8         d 23-03-2016    viewed         Y  A5_5_B34    A5_5_B34
#  9         a 07-12-2012      sold         Y  A5_4_B33    A5_4_B33
# 10         e       <NA>      sold         Y  A5_5_B34    A5_5_B34

Finally for each var_home and each action, the dates are pasted together (if there are several), the action is renamed (to get the desired final columnnames) and the each action is spread in its own column (with spread):
df <- df %>%
  group_by(var_home, action) %>%
  summarise(date = str_c(date, collapse = ",")) %>%
  mutate(action = str_c("var_date_", action)) %>%
  spread(action, date)

If you want to have this information together with the original data, assume this is stored in df_org. Then you can use join:
left_join(df_org, df, by = "var_home")
#   var_home var_datevar_A5_3_B32 var_datevar_A5_4_B33  ...  var_sold_A5_4_B33 var_sold_A5_5_B34 var_date_purchased var_date_sold var_date_viewed
# 1        a           01-12-2012           07-12-2012  ...  Y                 N                 05-03-2013         07-12-2012    01-12-2012
# 2        b           05-06-2014                 <NA>  ...  N                 <NA>              05-06-2014         <NA>          <NA>
# 3        c           03-09-2015           07-07-2017  ...  <NA>              <NA>              07-07-2017         <NA>          03-09-2015
# 4        d           03-03-2016           13-03-2016  ...  N                 <NA>              <NA>               <NA>          03-03-2016,13-03-2016,23-03-2016
# 5        e                 <NA>                 <NA>  ...  <NA>              Y                 <NA>               <NA>          <NA>


complex conjugate pairs of a quartic

Question: I tried my hand at this question, which included finding the partial fractions of $\frac{x^2}{1-x^5}$. I found a factor of $1-x$ for the denominator, but I do not know how to work out the complex conjugate pairs of $x^4+x^3+x^2+x+1$ as M. Strochyk gave them. I could probably do it if one root was given.
Answer: What M. Strochyk did was solve $1-x^5 = 0$ for real and complex roots using De Moivre's Theorem. First, we want to solve:
$$x^5 = 1$$
We first convert the $"1"$ into complex form, which is $1+0i$. Then we convert $1+0i$ into polar form, and we need to find $r$ and $\theta$. $r = \sqrt{1^2+0^2} = 1$ and $\theta = \arctan(\frac{0}{1}) = 0, \pi, 2\pi,... $
So which is $1(\cos(0 + n\pi) + i\sin(0 + n\pi))$ for all integers $n > 0$. So:
$$x^5 = 1(\cos(0 + n\pi) + i\sin(0 + n\pi))$$
$$x = (\cos(0 + n\pi) + i\sin(0 + n\pi))^{1/5}$$
Using De Moivre's Theorem:
$$x = (\cos((0 + n\pi)*(1/5)) + i\sin((0 + n\pi)*(1/5))$$
We know there are a maximum of $5$ roots, therefore we want $n$ to be $0,1,2,3$ and $4$. Then you plug $n$ into the equation above, and you'll get M.Strochyk's answers.

complex conjugate pairs of a quartic


Are Strings also static: String creation within Methods

Question: I know that at compile time when a String is created, that String will be THE string used by any objects of that particular signature.
String s = "foo";  <--Any other identical strings will simply be references to this object.
Does this hold for strings created during methods at runtime?  I have some code where an object holds a piece of string data.  The original code is something like
for(datum :data){
    String a = datum.getD();  //getD is not doing anything but returning a field

    StringBuffer toAppend = new StringBuffer(a).append(stuff).toString();

    someData = someObject.getMethod(a);
    //do stuff

}

Since the String was already created in data, it seems better to just call datum.getD() instead of creating a string on every iteration of the loop.
Unless there's something I'm missing?
Answer: String instances are shared when they are the result of a compile-time constant expression.  As a result, in the example below a and c will point to the same instance, but b will be a different instance, even though they all represent the same value:
String a = "hello";
String b = hell() + o();
String c = "hell" + "o";

public String hell() {
   return "hell";
}

public String o() {
   return "o";
}

You can explicitly intern the String however:
String b = (hell() + o()).intern();

In which case they'll all point to the same object.
Comment: I was not aware of .intern()
This answers the grander question I was driving at.
Answer: The line
 String a = datum.getD();

means, assign the result of evaluating datum.getD() to the reference a . It doesn't create a new String.
Comment: @Mark - maybe he does, maybe he doesn't.  It is hard to tell *what* his code is supposed to mean ... and hence what he is really asking about.
Comment: Yeah I think he knows that.  Read the second last sentence.
Comment: @Stephen: *"it seems better to just call datum.getD() instead of creating a string"*...seems he knows quite clearly that `datum.getD()` doesn't create a string.  He said so himself.
Comment: @Stephen: I will give you that it's confusing as to what the OP's alternative would be in this case.
Comment: Since this is in a for loop, ever iteration a new reference is created to the string in datum.getD()
My thinking is that I already have what I want in my data collection.  Why create a new reference every iteration instead of just calling for my data?
Answer: You are correct that strings are immutable so all references to the same string value use the same object.
As far as being static, I do not think Strings are static in the way you describe. The Class class is like that, but I think it is the only object that does that.
I think it would be better to just call the datum.getD() since there is nothing that pulling it out into its own sting object gains for you.
If you do use the datum.getD() several times in the loop, then it might make sense to pull the value into a String object, because the cost of creating a string object once might be less than the cost of calling the getD() function multiple times.
Comment: You can definitely have two String instances that represent the same string. So your first sentence is wrong. Also: `datum.getD()` most likely *doesn't* create a new `String` object each time it's called (especially if it's a normal getter as its name implies).


lmhosts and hosts file to allow user joining to domain controller

Question: I have a domain controller on a diffrent ip range as my computer and would like to know if it is possible to join it to the domain using host file and lmhosts file?
I don't want to use VPN
I don't want to use MS Direct Access
I don't want to put my computer on the same ip range as my domain controller.a
I don't want to change any DNS settings
Laptop running Windows 8 Pro
DC on Windows Server 2012
Thanks
Comment: Can you ping the DC's IP address from your Laptop?
Comment: Yes I can ping the IP address from the laptop
Answer: In you hosts file add entry's that point to your DCs IP address for your FQDN, your domain's short name and the DC's name.
I would also recommend you add your domains DNS servers to your network config, you can keep the primary and secondary the way you have them, just add the domains DNS IP as a third one. You can add a third DNS by clicking on the "Properties" button after you select IPv4 under your network adapters Properties and then clicking on the Advanced button.
Ex.

Domain: ad.sa.com
FQDN: ad.sa.com
Short Name: sa
DC Name: DC

This is for a setup where the domain users are joined to "ad.sa.com", the server hosting the domain (ie. the Domain Controller) is named "DC" and the users log-in with the prefix of sa (ex. sa\username)
Comment: Ok so let's say I want to use a different network adapter that can still ping the domain controller I would have to setup the dns settings again, and that is what I am trying to avoid....
Comment: So the users log on to the domain using sa\username and the domain that has to be joined is ad.sa.com so what would the FQDN, domain short name and DC name be? I am assuming the DC name is the name of the computer running the domain controller?
Comment: Then don't add the DNS servers, but you wont be able to see any systems on the network by their name unless you've put them in your hosts file.
Comment: the short name would be "sa" the DC name would be the name of the DC computer.
Comment: and the FQDN would be ad.sa.com? so i can add in my hosts file: ip  ad.sa.com enter ip sa enter ip dcname
Comment: Yes, except I don't know what your FQDN is, my guess would be that it's sa.com but if you look under the System Properties of a system that is joined to the domain on the "Computer Name" tab it will have an entry called "Domain:" and that will be your FQDN.
Comment: I submitted an edit to your answer does that make sense or should I be using the full computer name ie. dc.ad.ik.io?
Comment: I've changed your edit a bit but that was basically what I was saying.
Comment: let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/8187/discussion-between-armand-and-sane)


What is the intuition of invertible process in time series?

Question: I'm reading a book on time series and I started scratching my head in the following part:

Could someone explain the intuition for me? I couldn't get it from this text. Why do we need the process to be invertible? What is the big picture here? I'm new on this stuff so if you could be kind to use student-level terms when explaining this :)
Comment: Besides the invertibility is important if the time series observation or disturbance term is convergent.This is important for forecasting. If the process does not satisfy the condition of invertiblity it is impossible to forecast.
Answer: In the AR($\infty$) representation, the most recent error can be written as a linear function of current and past observations:
$$w_t = \sum_{j=0}^\infty (-\theta)^j x_{t-j}$$
For an invertible process, $|\theta|<1$ and so the most recent observations have higher weight than observations from the more distant past. But when $|\theta| > 1$, the weights increase as lags increase, so the more distant the observations the greater their influence on the current error. When $|\theta|=1$, the weights are constant in size, and the distant observations have the same influence as the recent observations. As neither of these situations make much sense, we prefer the invertible processes.
Answer: A time series is invertible if errors can be inverted into a representation of past observations.
For the time series data, the error ($\epsilon$) at time $t$ ($\epsilon_t$) can be represented as:
$$\epsilon_t = \sum\limits_{i=0}^{\infty}(-\theta)^i \, y_{t-i}$$
With every lagged value ($y_{t-i})$, its coefficient is $i^{th}$ power of $\theta$ term. So, the infinite series converges to a finite value only if $|\theta|<1$, which also means that recent past observations are given more weight than distant past observations.
Therefore, time series is invertible if $|\theta|<1$ (possibility of representing errors as linear combination of past observations)


D7 Node Field: Create OG Member Checklist in Node Edit Form

Question: I'm using Drupal 7 to create an intranet site. I'm using OG groups to create committee and department pages. I want to create a field in a "Meeting Minute" node type where a list is populated with all group members. The node author could then select whether the committee member was present or absent at a meeting.
I'm able to use an Entity Reference field to select from all users on the site, but I want to limit these checkboxes to just group members.
I'm striking out here; any ideas on where to start would be much appreciated.
Using the OG 7.x-1.x branch.
UPDATE: I have tried to use the "Entity Reference View Widget" module to accomplish this, but that doesn't seem to work either.
I'm going to try to restate this for clarity — I need a field on a node edit page that allows me to select one or more users who are also members of a group from the organic groups module.
Answer: Use hook_form_alter to do a entity field query or SQL query to get a list of UIDs that belong to 1 group ... OG may have a function to retrieve that list I dunno.
Once you have a list of UIDs use Devel and dpm($form); the form object and you can simply unset() the #options values for UIDs that dont belong in the OG group. Here's a similar thing I did for limiting to a taxonomy term_reference field to a given level of a nested taxonomy.
If you're paranoid you can also append your own validator function to the form_submit function and cross check that valid UIDs (members in the OG group) are being saved .... but I dont usually bother to do that for intranet sites (I have "trusted" users / staff members ... not joe blow public).
Sample code doing basically the same thing for a taxonomy term reference field.
/**
 * Implements hook_form_alter().
 */
function eap_student_videos_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
      // Field specific overrides.
      case 'eap_studentvideos_node_form':
          $form['field_eap_video_country']['#after_build'][] = 'eap_country_term_limit_to_countries';
          break;
    }
}

function _eap_region_tids() {
  return array(24,35,48,8,4);
}

function eap_country_term_limit_to_countries(&$element) {
    $options = $element[LANGUAGE_NONE]['#options'];
    $result = db_query('
        SELECT tth.tid, ttd.name AS term_name
        FROM taxonomy_term_hierarchy tth
        LEFT JOIN taxonomy_term_data ttd ON tth.tid = ttd.tid
        WHERE tth.parent IN  (:tids)
        ORDER BY 2 ASC
    ', array(':tids' => _eap_region_tids()));
    $country_tids = $result->fetchAllAssoc('tid');
    $country_tid_array = array_combine(array_keys($country_tids), array_keys($country_tids));
    $new_options = array_intersect_key($options, $country_tid_array);
    array_walk($new_options, function(&$value, &$key) { $value = str_replace('-','',$value); });
    // array_merge() destroys the array keys.
    $new_options = array('_none' => '- Select a value -') + $new_options;
    $element[LANGUAGE_NONE]['#options'] = $new_options;
    return $element;
}

Comment: Thanks for the tip. I'll try this today and let you know if it works for me.


Sending SMS from legacy system without the option for physical sms/gsm modems

Question: My problem is that there is a legacy system for building automation (ventilation, temperature, lighting etc) without the possibility for upgrades, that needs to send text messages through a connected GSM modem. It does not have interfaces for connecting to the standardised SMS services around. The system is hosted in a virtual environment without the option for inserting physical equipment like GSM modems, even with a serial-to-IP converter.
What I'm trying to find is really some piece of software, commercial is fine, that can act as a bridge between the legacy system and the modern SMS services. The software would probably have to emulate the modem to receive and process the AT-commands from the legacy system, convert the data into a proper format, for example SMPP, and then forward the request to the SMS service for sending the message.
Another option is a simple software acting only as a virtual GSM modem, saving the messages somewhere (DB, files etc) for further consumption.
I'm stumped at the moment, so I hope some of you have seen some solutions for this somewhere.
Comment: Are email-toSMS gateways unsuitable, and if so, why?
Comment: @MadHatter Unfortunately yes, the system doen not support sending e-mail...
Comment: OK, fair enough.
Comment: Any chance your automation system speaks OPC or DDE?
Comment: does this system have internet access? Could it post directly to an api at a hosted SMS gateway? Could you write the SMS text to an alternate location and use a secondary system to read that data and process accordingly?
Comment: @duenni I have no idea, but I doubt it. Most of these old automation systems are created by people good at BAC-net, PLS etc, and not so much ip, windows or general best practice. We have other systems we need to host where the system has to run in the user context as it is not able to run as a service, which means never log out of the server.
Comment: @Patrick Unfortunatly the system does not know what internet is, or even an API. Imagine it running as it was designed: A dusty old win xp PC tucked away in a handy closet with GSM modems attached directly to the COM-port.We've taken over a few of those dust-piles over the years and virtualized them in our datasenter as our clients request better up-time for the systems.
Comment: whilst I understand your pain I'm afraid virtualisation of GSM hardware isn't anything I know about. I wish you luck!
Comment: Maybe you don't need a virtual GSM modem but a [COM port redirector](https://en.wikipedia.org/wiki/COM_port_redirector). Your systems speaks to a virtual COM port, this port opens a TCP/IP connection to a server with a real GSM modem attached (and a modern OS) which processes this requests and fires up your SMS.
Comment: @duenni I'm sorry, but as I've stated in the question, we do no have the option to host hardware, not even serial-to-ip converters. The virtual COM-port will not have anything to connect to if I cant find a software solution...
Comment: Ok but how will this get running without another (virtual) server? Your legacy system has no internet connection and no modem can be attached. How do you plan to connect to the "outside world"?
Comment: @duenni The legacy server does not know what internet is, but with a virtual COM-port it can connect to a TCP port on another virtual server. But I cant connect a modem there either, because it is virtual. Thats why I need some software on the receiving end of the virtual COM-port to act like a modem, so the legacy server can understand whats going on. It only speaks in AT-commands.
Answer: You can use tcpser(1) to emulate a physical modem that accepts connections on a virtual serial port and forwards the data stream to a TCP server - that you'd probably have to write yourself.
It's not a turnkey solution but it might be a good start.
Comment: Wow! Great answer. Does that run on windows as well? Or is it able to receive from a virtual COM-port on another server?
Comment: After some testing and debugging it seems like tcpser only supports the dialing modems. According to the internet it was made to emulate one of the first Hayes modems created in 1981. It is supposedly updated updated to support more modern commands as well, but my testing indicates that it does not handle GSM-specific commands well. I was able to work around the PIN code checking, but not the check for the modem being registered to a network. I've taken a quick look at the source code as well and there seems to be dial up modems that it focuses on.
Comment: I am still rewarding you the correct answer and the bounty, because I now have some source code I can use as reference to quickly hack together a Node.js, go or Python-script to interpret the bare minimum of commands to do just the messaging.
Answer: codehead clearly got the bounty and the correct answer. His answer led me to discover a piece of software that inspires me to create an emulator that support at minimum the commands for the SMS-sending. Development will be done using the fabulous SMS Server Tools 3, NodeJS and adjustments for corner cases from real systems can be done when they surface.
The project will be open sourced under the MIT license and hosted on GitHub:
https://github.com/hakash/virtual-gsm


Module development - Layout of dynamic content

Question: I am creating a drupal module that receives content from a Web Based XML API. The module takes some search parameters from a  user and embeds these into a XML command. I am at the point where I am receiving back a response and am able to process the returned data and display it on the page using a simple return statement. At the moment I am simply returning a html table that is created in the module.
What I would like to do is make content available to other Drupal modules such as Views or Display Suite. But as this data is not coming from the database but being created on the fly I am not sure where to start. Any help would be much appreciated.
Thanks
Simon
Answer: Some pointers:
Try getting the data in your database somehow. You could import the data into nodes or you could use the Entity API. That way, you could expose your data to modules such as Views. The only thing you'll need to do left is to synchronize the data in your database with the XML data that you're receiving.
Comment: The problem is that the data is only valid for that user and contains price information that is only valid for 8 hours. Also part of the agreements with our supplier of the data is that we can not cache it, because the prices are so volatile. Thanks anyway and would appreciate it if this sparks any other ideas on how I may attack this problem.
Comment: I think that most of the modules rely on having data in the database, so if caching isn't an option I think you're pretty much screwed for integrating with a lot of modules.
Comment: I am thinking that I might go down the road of template files bundled with the module and use template suggestions in the module code.
Comment: That might be the best option indeed. I used to do it for a custom module but was able to switch to using Views etc.


Do I need custom scope for B2C SSO app registration?

Question: I am able to get access token from B2C only if I define a custom scope for app registration (Expose an API section), see below:

I can't understand why I need it. So, it make sense to grant permissions for Microsoft Graph. Every time user allows MY APP to act on behalf of him (in my case during SSO login), MY APP can read user profile and B2C can return users info like email in b2c token.
If I omit custom scope, and will use something like openid, I will get next error

AADB2C90055: The scope 'openid' provided in request must specify a
resource, such as 'https://example.com/calendar.read'.
Answer: I created an Azure AD B2C application and granted API permissions:

When I pass scope as openid, access token dint not get generated:
https://b2caadtenant.b2clogin.com/b2caadtenant.onmicrosoft.com/B2C_1_SUSI/oauth2/v2.0/token

client_id:ClientID
scope:openid
grant_type:authorization_code
redirect_uri:https://jwt.ms
client_secret:ClientSecret
code:code

Note that: By default, Azure AD B2C automatically returns the access token unless you explicitly request permission to one of your custom APIs and hence custom scope must be passed to generate access token.

When I pass scope with custom API, access token generated like below:
scope: https://b2caadtenant.onmicrosoft.com/xxx/user_impersionation openid

References:
Azure B2C login with Cypress oauth 2.0 - {tenant}.b2clogin.com - Stack Overflow by Sridevi
Error code reference - Azure AD B2C


How many triplet primes of the form $p, p+2, p+4$ are there? Prove your conjecture.

Question: I am giving this problem to 8th grade students, and I am hoping that people can help me find elementary ways to prove this problem. I would love to find other arguments that are accessible to 8th graders, so that I can help them with their arguments. Here is one "proof" I have so far.
There is only one such prime triplet $(3,5,7)$. Either the first number is divisible by $3$, or it is not.
If the first number is divisible by $3$, then the number the first number is not prime (except the case $3,5,7$), so it is not a prime triplet.
If the first number is not divisible by $3$, then there are two cases. The remainder equals 1 or the remainder equals $2$.
If $r=1$, we have a group of 3s with 1 left over. The next prime triplet is $p+2$, so adding 2 to the remainder of 1 will create another group of 3. Therefore, $p+2$ is divisible by 3, so this is not a prime triplet.
If $r=2$, we have a group of 3s with 2 left over. The third prime triplet is $p+4$, so adding 4 to the remainder of 2 will create two more groups of 3. Therefore, $p+4$ is divisible by 3, so this is not a prime triplet.
So, in any case, one of the numbers will be divisible by 3 making $3,5,7$ the only prime triplet.
Comment: $(3,5,7)$ is not of the form $(p,p+2,p+3)$.
Comment: Did you mean $p, p+2, p+4$ in the title?
Comment: Sorry, meant p, p+2, p+4
Comment: Only one, since 3 is divisible by 1 and itself. Let p=3*odd, where odd is positive odd integer. Consider all twin primes of the form: p+2, p+4. p or p+6 will always be divisible by 3.
Answer: If $p+4$ isn't divisible by $3$, then neither is $p+1$. So the three consecutive integers $p$, $p+1$ and $p+2$ aren't divisible by $3$, which is impossible, since there are only two integers between successive multiples of $3$.
Answer: Alternate:
$$
\frac{p(p+1)(p+2)}{3} = \binom{p+2}{3}
$$
is a binomial coefficient, so it is an integer.  Therefore $p(p+1)(p+2)$ is divisible by $3$.  Since $3$ is prime, it follows that one of $p, p+1, p+2$ is divisible by $3$.  And of course $p+1$ is divisible by $3$ if and only if $p+4$ is.
Answer: Note the following
$$p\left(p+2\right)\left(p+4 \right)=p\left(p+1+1\right)\left(p+2+2\right)=p\left(p+1\right)\left(p+2+2\right)+p\left(p+1+3\right)$$=
$$p\left(p+1\right)\left(p+2 \right)+2p\left(p+1\right)+p\left(p+1\right)+3p$$=
$$p\left(p+1\right)\left(p+2 \right)+2p\left(p+1\right)+p\left(p+1\right)+3p$$=
$$p\left(p+1\right)\left(p+2 \right)+3p\left(p+1\right)+3p \text{       (Imp.)    }$$
When do you think p(p+2)(p+4) would not be divisible by 3 for $p>3$ considering Imp.?
Comment: I disagree. I also separated all terms (the same terms, just combined) divisible by $3$. I also did it step by steps, just in fewer steps.
Comment: Good, but

$$
p(p+2)(p+4)=p(p+2)(p+1+3)=p(p+1)(p+2)+3p(p+2)
$$

would be a lot shorter.
Comment: @joriki you didn't mention the intermediate steps. I confused the OP. What I did is step by step. I seperated all terms divisible by 3.
Answer: There is only 1, which is 3, 5, 7.
I think your method is most suitable for 8-grade students.

Suppose for the sake of contradiction that there exists another triplet, i.e. (p, p+2, p+4)
We also know that $p+4\equiv p+1 \pmod 3$ hence we can replace the current triplet with (p, p+1, p+2)
We know that if we have $n$ consecutive integers, then one of these integers is divisible by $n$. Proof: There are $n$ residue classes mod $n$. If you have $n$ consecutive integers, they will fill up all $n$ residue classes. One of them must be in the residue class of things divisible by $n$; i.e. things $=0\pmod{n}$.
Hence the result follows.


Downloading a file through PERL script

Question: I have the below PERL script that tries to download a file that contains the output of that script.
I face an error which says:

Can't call method "header" on an undefined value at C:/Apache24/cgi-bin/trim.pl

However my output file gets written properly at the right destination. Please help me out with fixing the code and get the output file downloaded.
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;

my $q            = new CGI;
my $upload_dir   = "C:/Apache24/htdocs/files" ;
my ($bytesread, $buffer);
my $numbytes     = 1024;
my $trim_out_dir = "C:/Users/Admin/Desktop/vijay/Metagenomics/NGSQCToolkit_v2.3/CGI_Out";
my $out_file     = "$trim_out_dir/trimmed.fasta";
my $safe_filename_characters = "a-zA-Z0-9_.-";

$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );

my $file         = $q->param( "seq" )     || error( $q, "No file received." );
my $length       = $q->param( "len");
my $quality      = $q->param( "qual");

open ( UPLOADFILE, ">$upload_dir/$file" ) or die "$!";

while ($bytesread = read($file, $buffer, $numbytes)) {
    print UPLOADFILE $buffer;
}

close UPLOADFILE;
system("Reads.pl -i $upload_dir/$file -n $length -o $out_file");
open ( DOWNLOADFILE, "<$out_file" ) or die "$!";

print $cgi->header(
    -type       => 'application/octet-stream'
    -attachment => '$out_file');

close DOWNLOADFILE;

Answer: This does not compile with strict, and since you are using strict, it does not seem likely that this is the code you executed. Your $cgi object is never defined, and therefore would stop the script at compile time. This line:
print $cgi->header(

should probably be
print $q->header(

You should also know that
-attachment => '$out_file');

will mean that the attachment param will not contain the value of the variable $out_file, it will contain the literal name of the variable. If you want it to contain the value of the variable, you need to either remove the quoting, or use double quotes.
More importantly, you should also know that your script is very unsafe. You are using values directly from the cgi object without verifying them. Both the open statement and the system statement could easily be manipulated to execute arbitrary commands on your system. For example:
$out_file = "foo; rm -rf /";
system("Reads.pl -i $upload_dir/$file -n $length -o $out_file");

You may wish to read the documentation on security, and perhaps use taint mode (-T switch).
Comment: I have tweaked my script as below. As I am new to PERL I am unaware of the document security concepts.

    open ( DOWNLOADFILE, "<$out_file" ) or die "$!";

    print $q->header(
            -type => 'application/octet-stream'
            -attachment => "$out_file");

    close DOWNLOADFILE;

This time the script runs successfully, but the out_file is not available for download. Please can you help me with this.
Answer: Instead of
print $cgi->header(

you probably mean
print $q->header(

Using use strict should have caught this error.

Downloading a file through PERL script


Problemas para deletar números repetidos em um ArrayList

Question: Estou tendo problemas para retirar números repetidos de um ArrayList, aqui está o trecho do código:
for( int i = 0 ; i < houses.size(); i++ ) {
   for( int j = 1; j < houses.size(); j++ ) {
        if(houses.get(i).equals(houses.get(j)) && i!=j){
            houses.remove(j);
        }
    }
 }

Ele deleta de forma correta a maioria dos elementos repetidos, mas em alguns casos deleta alguns a mais, queria muito saber o que há de errado com este código, pois não consigo descobrir.
Comment: Você está removendo elementos durante a iteração. Isso dá problema porque bagunça os índices.
Comment: Deleta a mais ou a menos? Não consigo imaginar por que estaria deletando a mais, poderia dar um exemplo de onde isso acontece?
Comment: Números armazenados como string?
Comment: Alguma das respostas resolveu o problema? Acha que pode aceitar uma delas? Veja o [tour] como fazer isso. Você estaria ajudando a comunidade identificando a melhor solução. Só pode aceitar uma delas, mas pode votar em qualquer coisa no site todo.
Comment: e se usar um Set?
Comment: Qual é o tipo da lista? Pode por mais partes do código?
Answer: Você não pode remover itens do objeto sendo iterado, porque ele passa ter outra estrutura durante a iteração iniciada. Tem que criar uma estrutura auxiliar. Se quiser fazer na mão mesmo e não usar um HashSet:
ArrayList<String> aux = new ArrayList<String>();
for (String item : houses) if (!aux.contains(item)) aux.add(item);
houses = aux;

Veja funcionando no ideone. E no repl.it. Também coloquei no GitHub para referência futura.
Answer: A estrutura de dados que está usando não é ideal para o que você quer fazer. Não sei o motivo de estar usando ArrayList, mas se você precisa que a estrutura não aceite valores repetidos o ideal é usar o Set para não ter que fazer tratamentos adicionais e deixar o código mais limpo.
    Set<String> houses = new HashSet<>();

    public void add (String house){
        // nunca aceitará valor repetido
        houses.add(house);
    }


Tomcat usando todos os cores

Question: bom dia!
Existe alguma configuração a ser feita para o Tomcat utilizar todos os cores existentes na máquina?
Estou perguntando, pois percebi que o tomcat aqui não usa todos os cores.
Abraço,
Answer: Segundo este link, a seguinte configuração no compilador permite corrigir esse comportamento:
<code>-Djava.net.preferIPv4Stack=true
</code>

Tomcat usando todos os cores


Need advice on my quadratic formula functions

Question: Okay The program compiles, but i am getting wrong output. Any help would be awesome. i do understand there are many other examples on this topic and i have looked at them all. None seemed to have help me clearly understand.

#include <iostream>
#include <cmath>

using namespace std;

double quadplus(float a, float b, float c);
double quadminus(float a, float b, float c);

int main()
{
  double a, b, c;
  double discriminant;

  cout << "Please Enter variables for a, b, and c." << endl << endl;
  cout << "Enter number for variable a." << endl << endl;
  cin >> a;
  cout << "Enter number for variable b." << endl << endl;
  cin >> b;
  cout << "Enter number for variable c." << endl << endl;
  cin >> c;
  discriminant = (b * b) - (4 * a * c);

  if(discriminant == 0)
      cout << quadplus(a,b,c) << endl;
  else if(discriminant > 0)
      cout << quadplus(a,b,c) << endl;
  else if(discriminant < 0)
      cout << quadminus(a,b,c) << quadplus(a,b,c) << endl;

  return 0;
}

double quadplus(float a, float b, float c)
    {
        return ((-1 * b) + (sqrt(( b * b) - (4 * a * c))) / (2 * a));
    }
double quadminus(float a, float b, float c)
     {
        return ((-1 * b) - (sqrt(( b * b) - (4 * a * c))) / ( 2 * a));
     }

Answer: cout << quadplus << endl;

should probably be
cout << quadplus(a, b, c) << endl;

Also, if the discriminant is negative, your solutions will be
complex numbers of the form x + yi and your code doesn't properly account
for that.  If discriminant != 0,  you should probably print both roots.
Comment: Im not sure what i would change if there where complex numbers.
Comment: In that case, you could take the square root of the absolute value of the discriminant (so, positive and real), then calculate x = -b/2a,  y = sqrt(abs(discriminant))/2a, and report the complex roots as x - yi and x + yi.


Equivalent characterization of quasi-concavity

Question: For $f: \mathbb R^n \to \mathbb R$ prove that the two statements are equal:

For all $x,y \in \mathbb R^n$ and for all $t \in [0,1]$, $f(tx+(1−t)y)\geq \min (f(x),f(y))$
For all $k \in \mathbb R$, $\{ x : f(x) \geq k\}$ is a convex set.
Answer: For $\implies$: Fix $k \in \mathbb{R}$. Then if $x,y \in \{s : f(s) \geq k\}$, must have for any $t \in [0,1]$, $f(tx + (1-t)y) \geq \min(f(x),f(y)) \geq k$, so must have $tx + (1-t)y \in \{s : f(s) \geq k\}$, i.e. it is convex.
For $\impliedby$: Let $\min(f(x),f(y)) = k$. Then by convexity, must have $tx + (1-t)y \in \{s : f(s) \geq k\}$. So must have $f(tx + (1-t)y) \geq k =\min(f(x),f(y))$.


A linearly dependent subset

Question: Once again, I have a linear algebra question, this one goes as follows:
if $A$ is a linearly dependent subset of $\Bbb R^n$ then the dimension of the  subspace spanned by $A$ is strictly less than $|A|$
I have an idea for an argument for this question however I am having trouble expressing precisely.
Idea:
Since $A$ is a linearly dependent subset of $\Bbb R^n$ there must exist at least one $a \in A$  such that $a$ could be written as a linear combination of the remaining vectors in $A$. If we remove all such $a$ from $A$ will would obtain a subset of $A$ where all the vectors in the subset would be linearly  independent, and would span the same subspace spanned by $A$ and thus be a basis for  the subspace and since it contains less elements then $A$. The dimension of the subspace would be less than |$A$|. After all the dimension of a vector space is equal to the number of vectors in any basis.
Any idea on how to express this more concisely and precisely?
Comment: This is true only if the set $A$ is finite. Your argument is good.
Comment: @egreg How would It express this more concisely and with the use of mathematical notation.
Answer: Your argument is good, but I'd explain it more briefly.

The dimension of a (finitely generated) space is the minimum cardinality of a spanning set.
If $A$ is linearly dependent, then there exists $a\in A$ such that $a\in\operatorname{Span}(A\setminus\{a\})$, so that $\operatorname{Span}(A)=\operatorname{Span}(A\setminus\{a\})$.
The minimum cardinality of a spanning set is at most $|A\setminus\{a\}|$, which is less than $|A|$.

A linearly dependent subset


Curvature and torsion of coordinate curve on the sphere

Question: find the curvature and torsion of a $v=v_0$ (= constant) coordinate curve on the sphere
$x(u,v)= (a.\cos u.\sin v$, $a.\sin u .\sin v $, $a.\cos v$),  $\;0 < u < 2\pi$ , $0 < v < \pi$
I couldn't find how to solve because the two variables $(u,v)$.
Any help is appreciated.
Comment: yes it needs to be used as P and Q. thanks!
Comment: but $v$ has been freeze at $v_0$
Comment: so can I convert it like this? r(t) = (a.cost.sinv, a.sint.sinv, a.cosv) should I do this and solve it in a single variable format?
Comment: being $v$ constant your parametrization should be $(aP\cos u, aP\sin u, aQ)$ where $P=\cos v_0$ and $Q=\sin v_0$ are constants. So the position on the curve depends only on $u$.
Answer: Here is a direct approach. Let us use geographical terms.
$v$ is colatitude (= 90° - latitude) : we have a fixed $z=z_0=a \cos v_0$ ; it means that we are cutting the sphere with a horizontal plane. The result is necessarily a circle. We have what is called a parallel (see remark below); let us check that its projection on the $xOy$ plane is a circle ; indeed it has the  following equation
$$x^2+y^2=a^2 (\sin v_0)^2 \left[(\cos t)^2+(\sin t)^2\right]=(a \sin v_0)^2$$
that of a circle with radius $R=a \sin v_0$.
As a consequence this curve :

has torsion $0$ (because it is a plane curve),
for its curvature, the inverse of its radius of curvature : $K=1/R=1/(a \sin v_0)$.

Remark : Some parallels are famous : for example the Tropic of Cancer (latitude $\approx 23.5°$, colatitude $66.5°$), the Artic circle (invert the values given just before ; do you know why ?), the Equator...
Comment: a nice approach, thank you so much!


Microsoft Graph API, cant retrieve profile picture with django

Question: I'm having the issue that requesting the photo from the Microsoft Graph API does not retrieve the photo and actually returns a 404 error.
xff/xd8/xff/xe0/x00/x10JFIF/x00/x01/x01/x01/x00%60/x00%60/x00/x00/xff/xdb/x00C/x00/x08/x06/x06/x07/x06/x05/x08/x07/x07/x07/t/t/x08/n/x0c/x14/r/x0c/x0b/x0b/x0c/x19/x12/x13/x0f/x14/x1d/x1a/x1f/x1e/x1d/x1a/x1c/x1c%20$./'%20%22,
i get this is the base64 decoded jpeg, however i cant figure out how to use it to actually display an image in a html page.
Here is the code in my views that is creating the request, which is in my initialize context view:
def initialize_context(request):
## non relevant code ##

        graph_photo_endpoint = 'https://graph.microsoft.com/beta/me/photo/$value'
        headers = {'Authorization': 'Bearer ' + token}
        photo_response = requests.get(graph_photo_endpoint, headers=headers)
        if photo_response.status_code == 200:
            context['photo_data'] = photo_response.content
            photo_response.headers['Content-Type'] = 'image/jpeg'

## non relevant code ##
    return context

Which is retrieved by my view that needs to load the photo, which the user needs to be signed in for to access:
@azure_ad_login_required
def profile(request):
    context = initialize_context(request)
    return render(request, 'profile.html', context)

Here is the html code to define the photo:

And this is what my graph_helper looks like:
import requests
import base64
from requests_oauthlib import OAuth2Session

graph_url = 'https://graph.microsoft.com/v1.0'

def get_user(token):
    # Send GET request to retrieve user information from Microsoft Graph API
    user = requests.get('{0}/me'.format(graph_url),
                        headers={'Authorization': 'Bearer {0}'.format(token)},
                        params={'$select': 'displayName,mail,mailboxSettings,userPrincipalName,givenName,companyName,surName,jobTitle'})
    user.headers['Content-Type'] = 'image/jpeg'
    return user.json()

I'm not sure what i'm doing wrong here, anyone able to help me out?
Answer: Thanks for your input, this made me think about why i would do it the way i was doing it.
This made me come up with this solution:
token = get_token(request)
context = initialize_context(request)
graph_url = 'https://graph.microsoft.com/v1.0'
photo_endpoint = f"{graph_url}/me/photo/$value"
access_token = token

response = requests.get(photo_endpoint, headers={'Authorization': f'Bearer {access_token}'}, stream=True)

if response.ok:
    # Save the photo locally or process it as needed
    with open('static/assets/main/images/profile_photo.jpg', 'wb') as f:
        for chunk in response.iter_content(1024):
            f.write(chunk)
else:
    # Handle error if photo retrieval fails
    print(f"Failed to retrieve profile photo: {response.status_code} - {response.text}")

and for the html side:

Answer: Locate the line
context['photo_data'] = photo_response.content

in initialize_context, and try amending that line to:
context['photo_data'] = io.BytesIO(photo_response.content)

You'll need to import IO at the top of that file:
import io

I typically create an abstract user class and create a one to one UserProfile class to saving/cache the image. Using Django's ImageFile in a manner similar to:
from django.core.files.images import ImageFile
...

profile_photo = io.BytesIO(photo_response.content)
# userprofile being the instance of userprofile previously set
userprofile.avatar = ImageFile(profile_photo, name='foo.jpg')

Then in a template file I can use:

If you are not storing the image, you may need to embed the base64 encoding right in the src, however, I don't like doing that as for each request, you need to go look up the image (which I think is unnecessary).
You may end up with something like what is described here at :

but I'm not sure if you'd have the b64 data in photo_data context or not. You may need to test that out.
No guarantee any of that will work - I've got a very different sort of setup than you in how I retrieve those images but maybe there is something here that will help you out.


Is there any functional equation $f(ab+cd)= f(a)+f(b)+f(c)+f(d)$?

Question: I am looking for a real, continuous function that satisfies the functional equation
$$
f(ab+cd)= f(a)+f(b)+f(c)+f(d)
$$
where $a,b,c,d$ are real.
This is equivalent to a function satisfying these two functional equations:
$$
f(x+y)=f(x)+f(y)
$$
$$
f(xy)=f(x)+f(y)
$$
or Cauchy's functional equation and the logarithmic functional equation, respectively. I have the suspicion that the only the function $f(x) = 0$ satisfies this, but I am very confused as to how a solution may be found analytically. Thank you in advance.
EDIT: I saw in the comments that if f(x) is defined at zero the answer is trivial. If the domain were restricted to not include zero or even to not include all nonpositive numbers, would the answer change? If so, how? What if the function were discontinuous? Thank you again.
Comment: If $f$ is defined at $0$:  Taking $y=0$ we see that $f(0)=f(x)+f(0)\implies f(x)=0$.
Comment: @lulu if the domain were to be restricted to not include zero, would this answer change?
Comment: Not sure.  I doubt it, these equations are very strong.  But I don't see a proof off the top of my head.  The second equation  (plus continuity) pretty much tells you the function is a log, and logs don't satisfy the first equation.
Comment: If $f$ is not defined at $0$, then it is not obvious to me why the given equation is equivalent to the two other equations. In fact, it's not clear to me even when $f$ is defined at $0$.
Answer: Let $a=b=1, c=x, d=0$. Then $f(1)=f(ab+cd)=f(1)+f(1)+f(x)+f(0)$. Thus $f(x)=C:=-f(1)-f(0)$ for all $x$,i.e., $f=C$ is constant. Then the original equation gives $C=4C$, i.e., $C=0$. So $f=0$ is the only solution, even without assuming continuity.
Answer: Observe that all continuos solutions to Cauchy's functional equation $f:\Bbb R\to \Bbb R$ $$f(x+y)=f(x)+f(y)$$ are of the form $$f(x):=ax\quad \text{for some $a\in\Bbb Z$}$$
Can you end it now?

 Plugging this into the second functional equation $$f(xy)=axy=f(x)+f(y)=a(x+y)\iff axy=a(x+y)$$ This holds $\forall x,y\in\Bbb R$ if and only if $a=0$ and so $f(x)=0$ is the only continous solution.
Answer: If $f$ has the positive numbers as its domain, it is zero regardless of continuity.
Note first that $f$ satisfies the relation $f(x+y)=f(xy)$ for all $x,y$ in its domain. Now, fix any two positive numbers $u$ and $v$. If $u^2> 4v$, then $u=x+y$ and $v=xy$ for $x,y=\frac{u \pm \sqrt{u^2-4v}}{2}$, and these $x,y$ are positive. So $f(u)=f(v)$.
Similarly, if $v^2 > 4u$, then $f(u)=f(v)$.
But if $u^2 \le 4v$ and $v^2\le4u$, then
$u^2\le4(2\sqrt{u})$, which implies that $u\le 4$. So $4^2 \ge 4u$, which means that $f(u)=f(4)$. Since $u$ and $v$ are symmetric, we also have $f(v)=f(4)$. So $f(u)=f(v)$.
Since $u$ and $v$ are arbitrary, $f$ is constant, which means that it is zero.


Questions about the conditional Radon-Nikodym derivative

Question: Let $(\Omega, \mathcal{A}, \mathbb{P})$ be a probability space and $X:(\Omega, \mathcal{A})\rightarrow (\mathcal{X}, \mathcal{F})$ and $Y:(\Omega, \mathcal{A})\rightarrow (\mathcal{Y}, \mathcal{G})$ be random variables. Assume there exists a regular conditional distribution $\mathbb{P}_{Y|X}$
My first question revolves around the Radon Nikodym derivative of the regular conditional distribution $\mathbb{P}_{Y|X}$ w.r.t. some dominating measure $\lambda$ on $\mathcal{Y}$.
So as I understand it, $\frac{d\mathbb{P}_{Y|X=x}}{d\lambda}$ is for each fixed $x$ a function in $y$. I.e., for each $x$ we get a different function. Each of these functions is measurable in $y$. Is this correct so far?
1.) If we fix $y$, is it a function in $x$ then? If so, is it measurable in $x$? (if it is not measurable what would be the conditions for it to be measurabe?) How would I write this notation-wise? I am wondering about the notation, since then I wouldnt condition on $X=x$, right? Does the factorization lemma come into play that gives the relation between $\mathbb{P}_{Y|X=x}$ and $\mathbb{P}_{Y|X}$? Also is $\frac{d\mathbb{P}_{Y|X=x}}{d\lambda}$ only depending on $y$ but for instance $\frac{d\mathbb{P}_{Y|X}}{d\lambda}$ would be a function of both $x$ and $y$?
2.) would it also make sense to form a Radon-Nikodym derivative when the dominating measure was some other conditional distribution $Y|X$. I.e., assume there is another probability measure $R$ on $\Omega$. Then let $R_{Y|X}$ be a regular conditions distribution such that $R_{Y|X=x}$ dominates $\mathbb{P}_{Y|X=x}$ for each $x$. So would it make sense/be well defined to build the Radon nikodym derivative of these two conditional distributions? What would be the interpretation and would it depend only on $y$ or both on $x$ and $y$? Could we also form the Radon Nikodym derivative of $\mathbb{P}_{Y|X}$ and $R_{Y|X}$? Would it also make sense if the dominating measure was a distribution defined on the product space $\mathcal{X}\times\mathcal{Y}$? Would that change on what arguments the radon nikodym derivative would depend on then?
3.) What I am ultimately interested in is the following:
So as far as I understand it, in Fubinis theorem for transition kernels
$$\int_{\mathcal{X}\times{\mathcal{Y}}}f(x, y)\mathbb{P}_{X, Y}(d(x,y))=\int_{\mathcal{X}}\int_\mathcal{Y}f(x,y)\mathbb{P}_{Y|X=x}(dy)\mathbb{P}_X(dx),$$
we cannot exchange the integral. However, my question is, if this is possible if I use the above mentioned Radon-Nikodym derivative:
$$ \int_{\mathcal{X}}\int_\mathcal{Y}f(x,y)\mathbb{P}_{Y|X=x}(dy)\mathbb{P}_X(dx)=\int_{\mathcal{X}}\int_\mathcal{Y}f(x,y)\frac{d\mathbb{P}_{Y|X=x}}{d\lambda}\lambda(dy)\mathbb{P}_X(dx)=\int_{\mathcal{Y}}\int_\mathcal{X}f(x,y)\frac{d\mathbb{P}_{Y|X=x}}{d\lambda}\mathbb{P}_X(dx)\lambda(dy)$$
Would this be allowed?
Answer: Fubini's theorem only applies in a product space $Z=X\times Y $ when $X$ and $Y$ are independent, that is, if $P_Z(A\times B)=P_X(A)\times P_Y (B)$.
In case of non-independence:
$$\int f(x,y)dP_Z=\int \int f(x,y)dP_XdP_Y$$
is no longer valid, but this other one:
$$\int f(x,y)dP_Z=\int dP_X\int f(x,y)dP_{Y/X}$$
If pdfs existed for $P_X(p(x)$) and for $P_{Y/X}(q(x,y))$ (which is not always the case), we could write:
$$\int f(x,y)dP_Z=\int p(x)dx\int f(x,y)q(x,y)dy=\int\int p(x)q(x,y)f (x,y)d(x,y)$$
Logically, in this last integral we can apply Fubini's theorem.
Comment: Hi thanks for your answer! Could you also answer the other 2 questions?
Comment: Also my third question was about whether i could interchange the order of Integration when dealing with the densities
Comment: If it exists, $\frac{dP_{Y/X}}{d\Lambda}$ would be a $(P_X\otimes\Lambda)$-measurable function : $q(x,y)$ (defined a.e.). The measures $P_X$ and $\Lambda$ are independent, so the last equation in part (3) is perfectly valid. Regarding section (2), the Radon-Nikodim derivative will exist as long as the necessary conditions are met ($\sigma$-finitude, absolute continuity, etc.), whether conditional measures or not. For example, $\frac{dP_{Y/X}}{dQ_{Y/X}}$ might make sense, which would obviously be a function of $(x,y)$.


Conversion from string "valor" to type 'Integer' is not valid in VB.NET

Question: I'm a C# programmer but now I have to code VB.NET and I having a situation trying to translate this line of C# code to VB.NET
what I want is to check if the value that I obtained via MySQLDataReader is DBNull, in C# I use this to check if a string value is null or not
data.empName = dr.IsDBNull(1) ? "No name !!!" : dr.GetString(1).ToString();

But now I need the same verification but in VB.NET and also the data type retrieved via MySQLDataReader is decimal, this is what I got for the time beign
IIf(dr.IsDBNull("valor"), 0.0, dr.GetDecimal(dr.GetOrdinal("valor")))

but when I debug the app got the error message:
An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code
Additional information: Conversion from string "valor" to type 'Integer' is not valid.
the data type in the MySQL table is Decimal(10,2), could you please help me and tell me what am I doing wrong
Answer: The line should have read, the evaluation of dr.IsDBNull("valor") was incorrect and caused the exception. To remedy, try this
IIf(dr.IsDBNull(dr.GetOrdinal("valor")), 0.0, dr.GetDecimal(dr.GetOrdinal("valor")))


How to benchmark SSL performance IIS

Question: We are moving from Windows 2003 IIS 6 to Windows 2012 IIS 8. When moving over to the 2012 we have seen a slow down of the website of at least 10 times and sometimes more under load.
Initial testing shows that encrypted pages are slower, however unencrypted pages are much faster on 2012.
I would like to bench mark the time taken to setup a SSL connection to prove or disprove SSL is the cause of the problem. What is the best way of doing a benchmark on SSL?
I was hoping to find a browser plugin that would provide the total time taken to do the SSL handshake, but have been unable to find anything.
Any tools or advise would be greatly appreciated.
Comment: Just time the site with SSL on vs SSL off that should give you the data you need. What sort of encryption are you using, 2048 bit?
Comment: @DrewKhoury We can't turn SSL off, as the issue only happens in the live system. Yes we are using 2048 for both 2003 and 2012 servers.
Comment: benchmarking usually involves testing things in different environments. Is there a technical reason why you can't setup a test environment with SSL?
Comment: @DrewKhoury we have a test environment, however when we test against the test environment everything runs fine. The 2012 test environment was installed from the same image as live and the setup is almost identical. What I would like to do is benchmark the live 2003 against the live 2012. If the SSL handshake is fast enough I will know to look somewhere else.
Answer: I haven't tried this myself but a few minutes of searching resulted in the following:
sslswamp
http://linux.die.net/man/1/sslswamp

swamp is a utility that can be used to test and/or benchmark SSL/TLS
  servers. It is quite configurable and allows for various different
  characteristics of the server's behaviour to be tested.

This is how you would use it:
<code>swamp -connect IP:www.localnet:443
</code>
ab - Apache HTTP server benchmarking tool
You may want to look into Apache ab, even though they only have an experimental SSL feature.
http://httpd.apache.org/docs/2.2/programs/ab.html

-s When compiled in (ab -h will show you) use the SSL protected https rather than the http protocol. This feature is experimental and very
  rudimentary. You probably do not want to use it.

How to benchmark SSL performance IIS


IDataErrorInfo not updated

Question: I encountered a problem with the IDataErrorInfo Interface and a wizard I'm currently programming.
The intention of my programm is to ask some Inputs ( usually done with a barcode scanner) and depending on the inputs start a specific sequence.
This is working as intendet. To make sure to catch wrong scans all inputs are check with an event ( OnValueParseFailed) If this event is triggered my current textbox is focused and all text selected:

<code>    this.MyWizardViewModel.ValueParseFailed += (s, e) =>
    {
        switch (e.Parameter)
        {
            case "ProductionOrder":
                this.TextBoxProduction.Focus();
                this.TextBoxProduction.SelectAll();
                break;
</code>
The Interface itself is included this way:

<code>    public string this[string name]
    {
        get
        {
            string result = null;

            if ((name == "ProductionOrder") && (!string.IsNullOrEmpty(this.ProductionOrder)))
            {
                if (this.System.FirmwareVersion == 0)
                    result = Lang.Strings.WrongEntry;
            }
</code>
Its working for the first run.  But if the wizard is finished or aborted and run a second time without closing the app, no error message is shown.
The Reset simply returns the app to default values.

<code>    public void ResetApplikation()
    {
        this.System.Clear();  // reset System values

        this.ProductionOrder = string.Empty;
        this.BmsTypeCode = string.Empty;
        this.CellStack1TypeCode = string.Empty;
        this.CellClass1 = string.Empty;
        this.CellStack2TypeCode = string.Empty;
        this.CellClass2 = string.Empty;
        this.IsSystemProgrammed = false;
        this.IsSystemParameterized = false;

        this.MyMachine.Abort();  // reset wizard state
    }
</code>
While debugging I can see the Interface to be handeled correctly. But no error is displayed.
In XAML  the binding is set TwoWay
<code>    <TextBox Name="TextBoxProduction" Grid.Row="2" Width="200"  Margin="10"
     Style="{StaticResource TextBoxNormal}" Loaded="TextBoxProduction_Loaded"
     Text="{Binding Path=ProductionOrder, ValidatesOnDataErrors=True,
     NotifyOnValidationError=True, Delay=100,
     UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
</code>
I'm using MahApps but as the textbox class is based on the wpf textbox I doubt a bug in this element is the problem.  Any suggestions would be great.
Thank you.
Comment: How are you showing the wizard? Is it inside a Window? Also how are your properties defined (i.e. DependencyProperty or INotifyPropertyChanged)?
Comment: afaik WPF elements dont subscribe to IDataErrorInfo, but they do on INotifyDataErrorInfo objects.
Comment: So you should implement INotifyDataErrorInfo instead of IDataErrorInfo
Comment: @Domysee `ValidatesOnDataErrors` enables the support for `IDataErrorInfo`.
Comment: Do you implement `INotifyPropertyChanged`?
Comment: Yes, INotifyPropertyChanged is implemented. I haven't heard yet about INotifyDataErrorInfo. I'm currently testing this and give a feedback if this is solving the problem.
Answer: The Answer of Domysee helped me.
Implementing INotifyDataErrorInfo instead of IDataErrorInfo was a major change but it fixed the problem!

IDataErrorInfo not updated