Q: Spring boot one to one with foreign key I am want to store room details and room types in my db. I have created an entity for Room as follows.
@Data
@Entity
public class Room {

        @Id
        private String room_id;

        private Boolean status;

        private Double price;

        private Long type;

        private Long occupancy;

        @OneToOne(fetch = FetchType.LAZY, optional = true)
        @JoinColumn(name = "type_id", nullable = false)
        private RoomType roomType;

}

I have create a RoomType entity as follows:
@Data
@Entity
public class RoomType {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String type;
}

To save a Room Entity in my DB, the following is the request body format need to be given
{
  "room_id": "string",
  "status": true,
  "price": 0,
  "roomType": {
    "id": 1,
    "type": "string"
  }
}

I want to have the request body as follows
{
  "room_id": "string",
  "status": true,
  "price": 0,
  "roomType": 1  # This the roomType foreign key
}

I want to have one to one relationship, so when retrieving the Room details, I will get the roomType values also in the following format.
   {
      "room_id": "string",
      "status": true,
      "price": 0,
      "roomType": {
        "id": 0,
        "type": "string"
      }
    }

Or Is there any better way to handle this type of problem in spring boot??

A: I think there are two different concepts in here:

*

*The inner representation of a Room in your service (The classes you use and their relations)

*The outer representation (The one exposed by your API)

If you want those two representation to be the same, you could just serialize/deserialize data using the Room class directly (which I assume is what you are currently doing). For example:
@Controller
class MyController {
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ResponseBody
    public Room createRoom(@RequestBody Room room) {
        // Here room will be automatically deserialized from the request body
        // Do stuff with the received room in here
        // ...
        // Here the returned room will be automatically serialized to
        // the response body
        return createdRoom;
    }
}

However, if you don't want the inner and outer representations to be the same, you can use the DTO pattern (Data Transfer Object). Example in Spring here.
Now, you would have three different classes, Room and it's DTOs:
public class RoomRequestDTO {
        private String room_id;
        private Boolean status;
        private Double price;
        private Long type;
        private Long occupancy;
        private Integer roomType; // This is now an Integer

       // Setters and Getters ...
}

public class RoomResponseDTO {
        private String room_id;
        private Boolean status;
        private Double price;
        private Long type;
        private Long occupancy;
        private RoomType roomType;  // This is a RoomType instance

       // Setters and Getters ...
}

Now, your controller would receive RoomRequestDTOs and send RoomResponseDTOs:
@Controller
class MyController {
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ResponseBody
    public RoomResponseDTO createRoom(@RequestBody RoomRequestDTO roomReqDTO) {
        Room room = ... // Convert from DTO to Room
        // Do stuff with the received room in here
        RoomResponseDTO roomRespDTO = ... // Convert to the DTO
        return roomRespDTO;
    }
}

This approach also has the advantage that you can now change the inner representaion of Room without afecting the API. This is, you could decide to merge the Room and RoomType classes in one, without affecting the outer representation.
Note: In the example I have linked, they use the ModelMapper library. If you do not desire to introduce that dependecy, you could simple add a contructor and a method to the DTOs as such
public RoomResponseDTO(Room room) {
    // Manually asign the desired fields in here
    this.id = room.getId();
    // ...
}
public Room toRoom() {
    Room room = new Room();
    // Manually asing the desired field in here
    room.setId(this.id);
    // ...
    return room;
}

However, this approach would make you have to change these methods whenever you want to change the representations of Room. The ModeMapper library does this for you.


Q: Mocha: Can't stub function in file that was already required in another test file I'm using Mocha to run a test suite on fileToTest.js with requires greeting.js
// --fileToTest.js--

const { greeting } = require('./greeting');

module.exports = () => greeting();

// --greeting.js--

module.exports.greeting = () => 'hi!';

By itself, this test file successfully stubs greeting.
// --test2.js--
let parent;
const sinon = require('sinon');
const chai = require('chai');
const greeting = require('../../greeting.js');

const { expect } = chai;

describe('stubbed /hi', () => {
  before(async () => {
    sinon.stub(greeting, 'greeting').callsFake((req, res, next) => 'bye!');
    parent = require('../../parent.js');
  });

  after(async () => {
    greeting.greeting.restore();
  });
  it('should say bye', async function () {
    expect(parent()).to.be.equal('bye!');
  });
});

However if I run a test suite and have another test file that requires fileToTest.js, like test1.js below, the first test above (test2.js) won't stub greeting.
// --test1.js--
const chai = require('chai');
const fileToTest = require('../../fileToTest.js');

const { expect } = chai;

describe('not stubbed /hi', () => {
  it('should say hi', () => {
    expect(fileToTest()).to.be.equal('hi!');
  });
});

It seems once test1.js requires fileToTest, mocha doesn't reload the fileToTest on the test2.js's require. So fileToTest is stuck with the old greeting function.
Whats the proper way to stub a function in this situation?
Repo

A: This answer worked. I had to delete the cache.
  before(async () => {
    delete require.cache[require.resolve('../../fileToTest.js')]; // <------

    sinon.stub(greeting, 'greeting').callsFake((req, res, next) => 'bye!');
    fileToTest = require('../../fileToTest.js');
  });


Q: I get "Incorrect argument" error when i try to run a simple test on couchbase nodejs server var couchbase = require("couchbase");

var cluster = new couchbase.Cluster('127.0.0.1:8091');
var bucket = cluster.openBucket('beer-sample', function(err) {
    if (err) {

        throw err;
    }

    bucket.get('aass_brewery-juleol', function(err, result) {
        if (err) {

            throw err;
        }

        var doc = result.value;

        console.log(doc.name + ', ABV: ' + doc.abv);

        doc.comment = "Random beer from Norway";

        bucket.replace('aass_brewery-juleol', doc, function(err, result) {
            if (err) {

                throw err;
            }

            console.log(result);

            process.exit(0);
        });
    });
});

Here is my file. It's the example from here : http://docs.couchbase.com/developer/node-2.0/hello-couchbase.html
So when i try to run the server with "nodejs test1.js"  i get "Incorrect argument" error.
At bucket.js, module.js and in cluster.js into node_modules/couchbase/lib/
I have installed couchbase and i have full nodejs installed. I'm new in this and i cant understand where is my mistake. Maybe something with the versions of the couchbase or the node version i dunno.
Here is my full error which i get into the terminal:
Error: Incorrect argument
at New Bucket (home/anton/node_modules/couchbase/lib/bucket.js:213:16)
at Object<anonymus> (home/anton/PhpstormProjects/couchbase/test1.js:6:22)
at Cluster.openBucket (home/anton/node_modules/couchbase/lib/cluster.js:37:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3

A: The "Canonical" format for connecting to a cluster is couchbase://host where host in your case is localhost.
Depending on the version you're using, newer enhancements may have been added to allow for the common host:8091 antipattern, but would still be incorrect.
Chances are your code can still work if you upgrade to a newer version - but you should still use the couchbase:// variant (without the port).


Q: Return previous row when using boolean indexing Question
How do I return the previous row, as well as the row meeting a condition, when using boolean indexing?
Example:
sodf = pd.Series([9,10,10,9,10,11])
sodf

0     9
1    10
2    10
3     9
4    10
5    11
dtype: int64

Boolean condition:
sodf[sodf == 11]

5    11

Desired output:
4    10
5    11

A: You can get the index of sodf==11 and then get the loc value -1 onwards.
Here's how to do it.
import pandas as pd

sodf = pd.Series([9,10,10,9,10,11])

x = sodf[sodf == 11].index[0]
print (sodf.loc[x-1:])

Output will be:
4    10
5    11

If you just want the value of the previous row, then you can also give
print (sodf.loc[x-1])

The output will be just the value as this is a pd.Series with one column:
10

A: Try something like this:
i = sodf[(sodf == 9)].index
i = i.union(i-1)
i = i[i>=0]

sodf[i]

Output
0     9
2    10
3     9
dtype: int64


Q: Deleting columns/fields from polygon shapefile attribute table? I have a polygon shapefile that is loaded with old demographic data in its attribute file, I just received the new data today in xls format.  What I want to do is just delete the old demo data from the existing shapefile by selecting the fields in the attribute table and right clicking delete. Then I would do a simple join using the ID numbers for each feature to add the new data from the new table then just export it out as a new shapefile.  The problem is that for some reason I can not delete entire columns from the attribute table.
How would you go about stripping the data from this polygon shapefile?

A: Deleting the fields is scary way of going about this.  Are you absolutely sure you'll never need them?  There are several non-destructive ways to accomplish your goal.  One is to:

*

*load the shapefile and new table in ArcMap,

*join them on the ID field,

*right click the layer and choose Properties,

*on the Fields tab deselect all of the fields of the shapefile and click OK,

*right click the layer and export the data to a new file.

Only the checked fields will be exported to the new file and the old file will be preserved.

A: *

*Use ArcToolbox > Data Management Tools > Fields > Delete Field.

*Choose your shapefile as the Input Table.

*Use the Select All button, then unselect the field(s) you want to keep.

*Hit OK.

ArcGIS 10 running on a 64 bit OS has a bug whereby you cannot delete columns using the right-click > delete field operation. Should be fixed in SP1 (I hope).

A: Make sure that you are not editing the shapefile when trying to alter its columns. Also, make sure other applications (like ArcCatalog) are not locking the shapefile.

A: My method is to make my join. then go to the layer properties and turn off all the fields I don't want. then if I need a subset of selected objects (maybe only the ones that got a join) make that selection. Then use the data export and export to a new shape file. The time involved is a fraction of the time for waiting for each attribute field to delete and update. Another trick to use if you don't go this way is to pause the draw window while deleting fields. this will save a bundle of time also.
HTH


Q: Something changed: no longer able to SSH to home: xFinity I need some help understanding the current situation that I am having with my home network.
My home network is very simple:  My ISP is xFinity with a Dynamic IP that doesn't change very frequently. Last IP change occured 6 months ago. It comes into an Arris SB6183 modem that I own. From the Arris, it goes into a Linksys E8540 WiFi 6 Router (or a Netgear R6250 DD-WRT due to troubleshooting). From here, I only have 2 computers:  one Linux Desktop, and one personal Windows laptop that I use for web-browsing.
The Linux Desktop machine (LAN IP is 192.168.1.200) has SSHD Service on Port 22. The Router port forwards incoming SSH 22 connection from Internet to Port 22 on 192.168.1.200. Router firewall (SPI) is disabled.
Everything stopped working about 2 weeks ago. I am not able to SSH from outside into my Linux Desktop machine. If I am on the internal LAN, then SSH works just fine.
Using CanYouSeeMe.org shows me that Port 22 cannot connect:  "Reason:  connection timed out"
Here is what I tried:

*

*Removed the Router and Laptop and plugged in the Linux Desktop
straight into the Arris modem. SSH attempts still shows "Request
timed out"

*Made sure that UFW Firewall on Linux is off. No Fail2Ban.

*Replaced the Linksys E8450 with Netgear R6250 DD-WRT. No change.

*Called xFinity Customer Support and asked "Is Comcast blocking external incoming IPs to Port 22 ?" they responded "We don't block Port 22"

*Contacted Comcast Customer Security Assurance and Abuse and asked them to verify if my profile has some Security Profile/Screen in place or some sort of flag. They responded NO.

Then, finally I put a Port Forwarding rule on the router: incoming connection on port 2222 go to SSH 22 on Linux Desktop. And this works!! If I initiate external SSH connection attemps on port 2222 I do indeed connect to my Linux desktop.
In a related news, my Reolink Security APP on my Android Samsung phone no longer connects to my Home Camera over Cellular Data. It connects fine if my Phone connets to the Lan over WiFi.
What are your thoughts ? Does it look like my ISP is blocking incoming connections ? Any help greatly appreciated!


Q: Reading from file line by line known structure but length is unknown I'm sorry to ask this question, because I found similar answered questions, but I'm having difficulty to understand how to read lines of unknown length but the structure is the same.
Each line is structured by the following: name:id:buyingPrice:sellingPrice:profit:quantity
The names and IDs are strings while the rest are doubles.
My problem is I don't know how to setup a while that reads and stores each field, would it be possible to get a detailed explanation on how to accomplish this?
Here's my read of the file(just with strings) :
file = fopen("fileData.txt", "rt");

if(file != NULL){
    char lineSize[128] = "";

    while(fgets(line, 128, file) != NULL){
        fscanf("%s:%s:%s:%s:%s:%s", string1, string2, string3, string4, string5, string6);

    }
    fclose(file);

A: Have you thought about using strtok to parse the tokens after the fgets?

A: What I would use is the 'a' modifier for the scanf-format: Simply say 'fscanf("%as:%as:...", ...)', pass in the addresses of unallocated pointers and let fscanf malloc them for you.
This originated as a gnu extension, but AFAIK, it has made it into the C11 standart.


Q: Should I use the new HTML5 semantic elements? I'm in the process of upgrading my website, and this involves the decision of using the new HTML5 semantic elements
 over regular old
 elements.
I do plan on supporting IE7 and IE8, but I know that these versions don't support the above semantic elements. I've read up about 'plugins' like Modernizr, Initializr and HTML5shiv, and I know that older browsers will then support the new elements IF JavaScript is enabled, but what am I supposed to do if it's not?
By default, the  tag is given the class of no-js and if JavaScript is enabled, Modernizr/Initializr replaces this class with js. That's all well and good, but there are some things I'm uncertain about. So far, what is covered?
Sorted

*

*IF JavaScript is enabled, IE7 and IE8 are supported by Modernizr/Initializr.

*With a reset.css file, other older browsers support these new tags.

*Modern browsers are all fine.

Problems

*

*IF JavaScript is disabled, what am I supposed to do about IE8 and below? The no-js class is added to the  tag, so what exactly can I do with that?

*How can I use  to my advantage here? I don't want to make pages too large with coding.

So, aside from those questions, I also want to ask if it's really worth using these tags, when I can just use good ol'
 tags which would both support older browsers and also keep file sizes down by eliminating the required coding to make the new tags work in older browsers?
Thank you,
Dylan.

A: It's good practice to use both, for example

If you need to support those obsolete browsers, I wouldn't do anything more than that. The benefits, such as they are, are not worth the extra effort.

A:
I do plan on supporting IE7 and IE8, but I know that these versions don't support the above semantic elements. I've read up about 'plugins' like Modernizr, Initializr and HTML5shiv, and I know that older browsers will then support the new elements IF JavaScript is enabled, but what am I supposed to do if it's not?

If JavaScript is not enabled, then while the content of the new elements will be shown, CSS will not be correctly applied to them. While in theory you could use a noscript element to trigger a redirect to a version of the page not using the new elements (via a meta refresh tag within the noscript), then you'd be maintaining two versions of your site.
For example, given this page: Live Copy
<!DOCTYPE html>

<meta charset=utf-8 />
<title>HTML5 Elements</title>

This text should be green

...early versions of IE will show the text in the default color. Adding the HTML5 shiv prior to the style element:

...which as you know requires JavaScript, makes the text green: Live Copy

A: It's not necessary to follow the new semantic. New semantic is developed mostly for search engines, not for site functionality. If you really want to support IE, do it for IE.
If you really consider no-script cases and CSS is not enough for you, than all you can do is PHP/ASP magic.
One my friend works exclusively in Flash, because no js, totally client side, no cares about browsers... Who knows...

A:
Should I use the new HTML5 semantic elements?

Yes.

IF JavaScript is disabled, what am I supposed to do about IE8 and below?
  The no-js class is added to the  tag, so what exactly can I do with that?

You can do something like this,
HTML

     // Whole website coding here

      Use an upgraded browser

CSS
    .no-js #wrapper {
      display: none;
    }

    #old-browsers {
     display: none;
    }

    .no-js #old-browsers {
      display:block;
    }

How can I use  to my advantage here? I don't want to make pages too large with coding.
IE Consideration:
IE7 is 7 years old and most developers today do not support it. IE7 / IE8 users with js disabled is pretty low and you shouldnt develop for those exceptions. Instead you should give them a suggestion to upgrade with above method. You can use the noscript tag for the same usecase.

A: What you could do (and what a lot of big website's do) is to display a notice when javascript is disabled (optionally when the browser is IE7 or IE8 but you'll need a serverside check for that), that the website would not be displayed the way it is supposed to. See "How to detect if JavaScript is disabled?" on how to do so.
Only 5.3% (source) of internet users are using Internet Explorer < 8 and 0.25% to 2% (source) of the total users have Javascript disabled. You could spend a lot of time making a smooth solution for max 5% x 2% = 0,01% of your visitors or you could spend 5 minutes building the notice system I described.


Q: Extreme points of a convex compact shape cut with a hyperplane Here is a statement that I think I have a proof for, but I am looking for a reference:
Let $S$ be a convex compact subset of a real inner product space. Let $H$ be a closed halfspace in the same space. Every extreme point of $H\cap S$ is either an extreme point of $S$, or is the convex combination of two adjacent extreme points of $S$.
(A closed halfspace is defined by a linear inequality $\{x:\langle a,x\rangle \geq b\}$. Adjacency is defined in the usual way: two extreme points are adjacent if, for any point $p$ on the line segment connecting them, $p$ cannot be written as a convex combination of two points that do not lie on the line segment)


Q: Why Doesn't CreateProcess() Work? I have a program that attempts to restart Explorer in Windows 7; it first ends the process, then starts it again.
Simple?
So it looks -- it indeed seems to work. However, I noticed something funny: When I try to start a program (say, XP's Power Calculator powertoy) under compatibility mode, it no longer works! Nothing happens -- the process is created and immediately quits.
If I run Explorer through the Run dialog of Task Manager, the program runs fine.
What's going on?!
#include <windows.h>
int main()
{
    PROCESS_INFORMATION pi;
    STARTUPINFO si = {sizeof(si)};
    TCHAR path[] = TEXT("explorer");
    DWORD f = 0; //I tried a variety of these flags; didn't work
    return CreateProcess(NULL, path, NULL, NULL, FALSE, f, NULL, NULL, &si, &pi);
}

Edit 1:

*

*The fact that it was 32-bit with WOW64 redirection disabled made no difference. I made it 64-bit and the issue was the same.

*I tried ShellExecute but it didn't work either.

Edit 2:
The same exact code just worked for me a couple of times, and then stopped working again... huh?

A: This isn't really an answer to the "why", but I managed to find out how to fix it myself:
Instead of copying environmental variables from the current process, if I copy them with CreateEnvironmentBlock, then it works.
I still haven't figured out what's causing it, though...


Q: Flicker in Gradient panel I have inherited a control from TPanel and in the Paint event handler, I have drawn the entire client rect using a gradient. This works perfectly fine until the user resizes.
When the panel is resized, the panel component flickers too much.
How can i avoid this flicker. I saw the gradients in MS office 2007, even if we resize the client area, there will not be a flicker. Please enlighten me on this.
Thanks in anticipation

A: You may want to look at this question How to eliminate the flicker on the right edge of TPaintBox (for example when resizing)
Good overview of options to avoid flicker and also for TPanel.
Edit :
I made a quick test in my Delphi XE version on windows 7.
With this code I cannot reproduce any flicker.
The inherited Paint is removed and the Paint routine is quite fast.
If you still can see flicker, the proposal from Simon can be implemented, but better keep the bitmap created for the lifetime of the component itself.
unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TGradientPanel = class(TPanel)
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    sPanel : TGradientPanel;
  public
    { Public declarations }
 end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Uses Math;

 procedure GradVertical(Canvas:TCanvas; Rect:TRect; FromColor, ToColor:TColor) ;
 var
   Y:integer;
   dr,dg,db:Extended;
   C1,C2:TColor;
   r1,r2,g1,g2,b1,b2:Byte;
   R,G,B:Byte;
   cnt:Integer;
 begin
    C1 := FromColor;
    R1 := GetRValue(C1) ;
    G1 := GetGValue(C1) ;
    B1 := GetBValue(C1) ;

    C2 := ToColor;
    R2 := GetRValue(C2) ;
    G2 := GetGValue(C2) ;
    B2 := GetBValue(C2) ;

    dr := (R2-R1) / Rect.Bottom-Rect.Top;
    dg := (G2-G1) / Rect.Bottom-Rect.Top;
    db := (B2-B1) / Rect.Bottom-Rect.Top;

    cnt := 0;
    for Y := Rect.Top to Rect.Bottom-1 do
    begin
       R := R1+Ceil(dr*cnt) ;
       G := G1+Ceil(dg*cnt) ;
       B := B1+Ceil(db*cnt) ;

       Canvas.Pen.Color := RGB(R,G,B) ;
       Canvas.MoveTo(Rect.Left,Y) ;
       Canvas.LineTo(Rect.Right,Y) ;
       Inc(cnt) ;
    end;
 end;

constructor TGradientPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Self.ParentBackground := FALSE;
end;

procedure TGradientPanel.Paint;
var
  rect : TRect;
begin
  //inherited;  // Avoid any inherited paint actions as they may clear the panel background
  rect := GetClientRect;
  GradVertical( Self.Canvas, rect, clBlue, clRed);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  sPanel := TGradientPanel.Create( Self);
  sPanel.Parent := Self;
  sPanel.Top := 10;
  sPanel.Left := 10;
  sPanel.Width := 300;
  sPanel.Height := 300;
  sPanel.Anchors := [akLeft,akRight,akTop,akBottom];
  sPanel.Enabled := TRUE;
  sPanel.Visible := TRUE;
end;

end.

A: A way to reduce flicker is to draw the gradient to a temporary bitmap the draw the entire contents of the bitmap to the panel. This method assumes you have an OnPaint method and a canvas to draw on in your inherited panel.
So something like this (untested)
var bmp : Tbitmap;

procedure AfterConstruction;
begin
  bmp := TBitmap.Create;
end;

procedure Destroy()
begin
  if Assigned(bmp) then FreeandNil(bmp);
end;

//redraw you bmp gradient
procedure Panel1.OnResize();
begin
  if Assigned(bmp) then //ensure the bmp s created in your constructor
  begin
  try
    bmp.SetBounds(Panel1.Clientrect); //ensure the bmp is the same size as the panel
    //draw your gradient on the bmp
    Panel1.OnPaint();//repaint the tpanel

  finally
    bmp.Free;
  end;
end;

//paint to the panel
procedure Panel1.OnPaint()
begin
  Panel1.Canvas.Draw(0,0,bmp); //use the OnPaint method to draw to the canvas
end;
  end;
end;


Q: jsf cascading list How do I cascade the lists so if user changes selection in selectedCategory list it should update the selectedTo list.
Here is my snippet:
<h:selectOneMenu id="selectedCategory" value="#{converterBean.selectedCategory}">
  <f:ajax execute="selectedCategory" render="selectedFrom"/>
  <f:selectItems value="#{converterBean.categories}"/>
</h:selectOneMenu>
<h:selectOneListbox id="selectedFrom" value="#{converterBean.selectedFrom}" size="5">
  <f:selectItems value="#{converterBean.fromList}"/>
  <f:ajax execute="selectedCategory selectedFrom" render="selectedTo"/>
</h:selectOneListbox>
<h:selectOneListbox id="selectedTo" value="#{converterBean.selectedTo}" size="5">
  <f:selectItems value="#{converterBean.toList}"/>
</h:selectOneListbox>

I notice that it updates the selectedFrom list but does not cascade further to selectTo list.
As per suggestion to try render both selectedFrom and selectedTo for category selection the request posted from the page is:
POST http://localhost:8081/converter_web/faces/converter.xhtml HTTP/1.1
Accept: */*
Faces-Request: partial/ajax
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Referer: http://localhost:8081/converter_web/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host: localhost:8081
Content-Length: 1253
Connection: Keep-Alive
Pragma: no-cache
Cookie: JSESSIONID=DDDEA598A60CC468763C36B536513B41

converter_form=converter_form&converter_form%3AselectedCategory=temperature&converter_form%3AselectedFrom=mm&converter_form%3AselectedTo=cm&converter_form%3Avalue=0.0&javax.faces.ViewState=b%2BArKl5NJujWibUQzHf3dUG2JlT%2Bnq7KygA2%2FXpXXscCouBr5xT9Br%2BmoP78%2FvuPAYG%2Bi7Q0jFEKGqJpFgRo%2BDU4ZV251yac84pu3bZ71V9j%2BHvRPMkWw82S8q0v2p1jmn3msPXxvKrQQ1oVpr7pGBPXc2faQGXHW55Md%2BKSkspIgCxXx3x3T6NDaJ1%2BGTEFkyb1DE%2BdoQHQ4EjqV3jEC5mq56OlsHgEmkQ8TVCQM%2FPmAfUBWiQEHqBYzohXNfFpO3kfdrKjeTrq648UtGPYU88VJ9mtIOptYEfwFKN9y%2FG9MOBKEfRZ9XlJz2bPt1zmATIg3iRT1W7YVtmHq7e9g%2FUxsM82duMxFUWhoFPHfrFk4tt48LFH29Hk60y3eeFxqtg7g1JxPD1aQrLN9sxBduS53nFWObCms1YU40uvMT2yjX0kp4wM8YwqT2jTFDtLHcVBide1RGTnzFGzjOrbCJ8rIEmWfPa1yUMkXRBBsgpKWFIl0ueBQiCT%2BDoD9UXlNOQGS%2F5tIdP%2BVTO%2FkWiBo5X99SpKwKY8%2B2pqzJKDrPRXIwci52Wi%2Fo%2Fw%2B0TkpnVrtDaDl7w2eYjmq7bYZFRDjWy3Jtgc5V1DUF%2BhX3Bfiq7l%2Fq5YL4DYx0NBI2esfJ0LTFCqXu8aCk%2BWOPOWnOCSGA5Y9EGUXgzV6q%2Fp%2FFWa8Kj8E%2FeoB380eFwXAEiyyRGv&javax.faces.source=converter_form%3AselectedCategory&javax.faces.partial.event=change&javax.faces.partial.execute=converter_form%3AselectedCategory&javax.faces.partial.render=converter_form%3AselectedFrom%20converter_form%3AselectedTo&javax.faces.behavior.event=valueChange&javax.faces.partial.ajax=true

We would expect only selectedCategory be send but its sending all form fields in ajax call.  It though calls getCategories(), getFromList(), getToList() but when it calls getToList it uses category=temperature and from=mm.  from=mm is what is passed in POST request as selectedFrom=mm.
Regards,
Miten.

A: Change this:
  <f:ajax execute="selectedCategory" render="selectedFrom"/>

To this:
  <f:ajax execute="selectedCategory" render="selectedFrom selectedTo"/>

A: I added ajax listener as below so indicate that category change is being invoked so that getFromList will set selectedFrom to new item from its list instead of one being posted.  Then getToList will find correct category and from unit to query its to list.
<f:ajax execute="selectedCategory" render="selectedFrom"></f:ajax>

to
<f:ajax listener="#{converterBean.categoryChanged}" execute="selectedCategory" render="selectedFrom selectedTo"></f:ajax>


Q: How to find xpath for  with no class or unique identifier

Welcome
Hello welcome.

Welcome!!!
Good morning

A: You can just use the FirePath plugin that mozilla has.
Or if not then for the following code

Welcome
Hello welcome.

Welcome!!!
Good morning

The xpath for second p element will be : html/body/p[2]
For the span within it: html/body/p[2]/span

A: Use // slash to find all the elements present on the DOM with start with p tag
//p will return you all element present on the DOM in p tag
Hope it will help you :)


Q: Bootstrapped confidence intervals for the parameters of a linear model applied to multiply imputed data I would like to construct CIs for $\beta$ in the linear model
$Y = X\beta + \epsilon$
I observe $\{X', Y'\}$ which is $\{X,Y\}$ contaminated with values missing at random. $\epsilon$ is not Gaussian and not homoscedastic.
I propose to construct CIs for $\beta$ by:

*

*Generating several imputed data sets $\{X^i, Y^i\}_{i \in {1, \ldots, N}}$ using, say, multiple imputation by chained equations;

*Constructing bootstrap replicates of $\hat\beta$ by randomly selecting an imputed data set then, based on this dataset, generating a bootstrap of the cases replicate of $\hat\beta$.(A new dataset is randomly selected for each individual replication).

*Using a standard method to construct a CI from the bootstrap replicates, say, Efron's bias corrected accelerated CIs.

Is this the best way to go about it?

A: Shao and Sitter 1996 demonstrate that the right approach is:

*

*Take a bootstrap sample, respecting the dependencies in the data (see below);

*Run one imputation on this sample, estimating the imputation model and producing one model + noise replicate;

*Run a complete case analysis on this;

*Repeat 1-3 $B$ times;

*Combine using the bootstrap rules (not the Rubin rules).

$B$ must be bootstrap-large, not the Rubin-large... 5 hundred rather than 5. The biggest issue that comes up with complex survey data which are in the focus of Shao & Sitter's paper is that there are non-trivial dependencies and indepedencies present in complex survey data. By design, observations between strata are independent, and imputation that borrow strength across the whole data set violate that independence. By design, observations within the same PSU are correlated. Both of these effects need to be addressed by the bootstrap scheme. For complex surveys, this needs to be the complex survey bootstrap. For time-series, this needs to be the block bootstrap.
The process proposed by orizon (as clarified by Stef) may be right, and I have been rolling it in my head for some while in the past couple of years, but never had the chance to really review it for statistical soundness.

A: Steps 2 and 3 ignore the fact that some of the data have been imputed. Hence the bootstrap estimate of the distribution of $\hat\beta$ will be too narrow.
Rubin's pooling rules combine the within and between imputation uncertainty. Though this procedure assumes that $\hat\beta$ is normally distributed around the population value $\beta$, it is actually quite robust against violations of normality.


Q: Rotational Friction This is the question-
Consider a cylinder of mass $M$ resting on a rough horizontal rug that is pulled out from under it with acceleration $a$ perpendicular to the axis of the cylinder. What is $F$ (friction) at a point P? It is assumed that the cylinder does not slip.

Options-
A) $F = M g$
B) $F = M a$
C) $F = \frac{M}{2} a $
D) $F = \frac{M}{3} a $
My attempt-
Since rolling is nothing but rotation about the point of contact (P in this case), according to me P should be at relative rest, therefore $F=Ma$. This should have been a short and crisp question, help me out please answer given is $F=\frac{M}{3} a$, and if you can perhaps please point me out to articles for such rolling friction question, I get stumbled whenever they ask friction in rolling. Thanks in advance..
Edit-
This idea also came to my mind-
Moment of inertia for a solid cylinder= I = $\frac{MR^2}{2}$
Let the frictional force be F, then,
$F*R=(torque)=I*\alpha$
$F*R=\frac{(M*R^2)*(a)}{2R}$
(as the cylinder is in pure rolling)
therefore- $F=\frac{Ma}{2}$
which is again incorrect any pointers to where I went wrong here again would be appreciated.. thanks

A: The job of the friction is to enforce the no slip constraint. So let us find the relative acceleration of the two parts and find the force $F$ which makes it zero.
The cylinder EOM are (positive is to the left) $ F = m \dot{v} $ and $r F = I \dot{\omega}$
and the tangential cylinder acceleration at P is $\dot{v}_P = \dot{v} + r \dot{\omega}$
To make the tangential acceleration equal to the rug you have
$$ a = \dot{v}_P = \frac{F}{m} + \frac{r^2 F}{I}  \\  F  = \left(\frac{1}{m} + \frac{r^2}{I}\right)^{-1} a $$
where the part in the parenthesis is the effective mass of a rolling cylinder on its surface. For a solid cylinder the mass moment of inertia is $I=\frac{m}{2} r^2$ and thus
$$ F = \left(\frac{1}{m} + \frac{2}{m}\right)^{-1} a  = \frac{m}{3} a$$


Q: With "azure-iot-sdk-java"; What is the expected lifetime of a DeviceClient instance I am developing a long-running program that sends data periodically to an Azure IoT Hub. I am using the com.microsoft.azure.sdk.iot.device/DeviceClient Java class to accomplish this.
It's basically working, which is nice, but I have some questions about the lifetime of the DeviceClient instance.
Should I instantiate exactly one DeviceClient instance at program startup, and then repeatedly call .sendEventAsync any time I have data to send? Or should I instantiate a new DeviceClient instance fresh from the connection string each time I want to send data? Or something in-between (e.g., send no more than 100 messages with a given DeviceClient instance, or let no DeviceClient instance live more than 72 hours)?
As I said, it's basically working, we've successfully sent many many events, but we have also seen some funny behavior. For example, after a few weeks the client silently stops sending (oof), or after some time the client claims send SUCCESS_OK, but the events don't arrive in the IoT hub for several hours (up to 16 (!)). I can definitely imagine these occurrences steming from my misuse of the library, so any hints about how to use it correctly would be much appreciated.
Thanks in advance for your time and consideration.

A: You should only have one long-living DeviceClient instance. Especially if you are using MQTT or AMQP as transport protocol, the DeviceClient will open the connection - and keep it open. Over that open connection it will send the messages. And also the for cloud-to-device messages / twin updates, the same channel is used.
Also, the client usually handles any connection-retry logic so you don't have to deal with that manually.


Q: How to run a rails migration as sql file My database admins do not want to control access to any drop/alter/create commands.  Is there anyway to emulate what rails is doing to the schema migrations table and convert the migrations themselves in a reliable way to fake rails out into thinking it has been ran and also handle rollbacks?  They want to run this from their end of course.  I have seen a few suggestions, but no wholistic approach. Perhaps the answer is it really shouldn't be done, which is what I think right now as I believe it will just cause headaches and unreliability down the road.


Q: giving meaning to a prior distribution without invoking "physical probability" When we refer to a concrete probability space the events to which probabilities are assigned should have a specific well defined meaning. Now when we refer to a prior distribution of some parameter it should therefore be clear what is being said about reality if the parameter takes a certain value.
Now if the different values of the parameter aren't refering to different members of a population (for example urns with a different amount of red balls) then the parameter is only refering to different distributions. For this to have any meaning it seems to me that these distributions must be seen as "real" in the sense of the frequentist interpretation of a "physical probability". For the degree of belief interpretation of probability it would be nice not to have to refer to the concept of a physical probability, since it is not without it's own issues. My question is how/if it would be possible to assign a meaning to different values of a prior parameter, which does not stem from a population, without refering to physical probabilities.

A: Using probabilities of distributions is only irreducible if we’re dealing with repeatable experiments, and in such situations an evidential interpretation of probabilities has no problem with frequentist probabilities.
Consider a paradigmatic non-frequentist scenario, say, a one-off, non-repeatable life choice where I want to decide whether I’ll be better off becoming a mathematician or a coin manufacturer. As part of the decision-making process, I might try to estimate the probability that I’ll make more money as a mathematician, and as part of that, I might model the income for both options with normal distributions and assign some probabilities to their parameters. None of this means that there are any “physical” probabilities involved – this is merely a device to assign some reasonable set of probabilities, and we can entirely do away with the normal distribution, its parameters and their distribution by integrating over the parameters to obtain individual probabilities for individual income values instead.
By contrast, talk of probabilities of distributions is irreducible when we’re dealing with a repeatable experiment. But an evidential interpretation of probabilities doesn’t deny that there are (to a very good approximation) such things as repeatable experiments, and that in a repeatable experiment the probability to be assigned to an outcome is equal to the relative frequency of the outcome when the experiment is repeated. What’s characteristic of an evidential interpretation of probabilities is not that probablities are never frequencies, but that they don’t have to be and that that’s not how they’re defined and conceptualized. For a repeatable experiment, the distribution of its outcomes is a specific, well-defined feature of the experiment to which we can assign probabilities just like to any other feature.
(Here sampling from a population is a special case of a repeatable experiment.)


Q: How do I combine large csv files in python? I have 18 csv files, each is approximately 1.6Gb and each contain approximately 12 million rows. Each file represents one years' worth of data. I need to combine all of these files, extract data for certain geographies, and then analyse the time series. What is the best way to do this?
I have tired using pd.read_csv but i hit a memory limit. I have tried including a chunk size argument but this gives me a TextFileReader object and I don't know how to combine these to make a dataframe. I have also tried pd.concat but this does not work either.

A: The memory limit is hit because you are trying to load the whole csv in memory. An easy solution would be to read the files line by line (assuming your files all have the same structure), control it, then write it to the target file:
filenames = ["file1.csv", "file2.csv", "file3.csv"]
sep = ";"

def check_data(data):
    # ... your tests
    return True # << True if data should be written into target file, else False

with open("/path/to/dir/result.csv", "a+") as targetfile:
    for filename in filenames :
        with open("/path/to/dir/"+filename, "r") as f:
            next(f) # << only if the first line contains headers
            for line in f:
                data = line.split(sep)
                if check_data(data):
                    targetfile.write(line)

Update: An example of the check_data method, following your comments:
def check_data(data):
    return data[n] == 'USA' # < where n is the column holding the country

A: Here is the elegant way of using pandas to combine a very large csv files.
The technique is to load number of rows (defined as CHUNK_SIZE) to memory per iteration until completed. These rows will be appended to output file in "append" mode.
import pandas as pd

CHUNK_SIZE = 50000
csv_file_list = ["file1.csv", "file2.csv", "file3.csv"]
output_file = "./result_merge/output.csv"

for csv_file_name in csv_file_list:
    chunk_container = pd.read_csv(csv_file_name, chunksize=CHUNK_SIZE)
    for chunk in chunk_container:
        chunk.to_csv(output_file, mode="a", index=False)

But If your files contain headers than it makes sense to skip the header in the upcoming files except the first one. As repeating header is unexpected. In this case the solution is as the following:
import pandas as pd

CHUNK_SIZE = 50000
csv_file_list = ["file1.csv", "file2.csv", "file3.csv"]
output_file = "./result_merge/output.csv"

first_one = True
for csv_file_name in csv_file_list:

    if not first_one: # if it is not the first csv file then skip the header row (row 0) of that file
        skip_row = [0]
    else:
        skip_row = []

    chunk_container = pd.read_csv(csv_file_name, chunksize=CHUNK_SIZE, skiprows = skip_row)
    for chunk in chunk_container:
        chunk.to_csv(output_file, mode="a", index=False)
    first_one = False

A: You can convert the TextFileReader object using pd.DataFrame like so: df = pd.DataFrame(chunk), where chunk is of type TextFileReader. You can then use pd.concat to concatenate the individual dataframes.


Q: In Java or Scala, is there a way to add a callback to an exception so that when the exception is caught, the callback is invoked? Problem statement:
I have an RPC client lib 1 that is used by many services with all code in a mono repo. This RPC client lib 1 throws a set of runtime exceptions (S1).
Now there is another RPC client lib 2 that I try to migrate all services from using lib 1 to lib 2. However, RPC client lib 2 throws a different set of runtime exceptions (S2).
I am trying to get a list of services that are going to be affected if the RPC client exception semantics change from S1 to S2.
Approach 1: read through code of all services that currently use RPC client lib 1. Obviously this approach is not scalable because there are many services and exception handling logic could be complex and not straightforward.
Approach 2: static analysis. However, I am not sure if any static analysis can detect the situation where an exception thrown by the RPC lib is caught at many levels above in the call stack.
Approach 3: explore if there is a way to register a callback to an exception and expect the callback to be invoked when the exception is caught. Ideally when the callback is invoked, it is provided with the information about where the exception is caught.

A: Sounds like AspectJ pointcut "after catching" (not exising). Existing is "after throwing"
https://coderanch.com/t/498256/frameworks/AOP-pointcut-CATCH-block
https://www.eclipse.org/aspectj/doc/next/progguide/printable.html#the-handler-join-point
How to intercept method which handles its own exceptions using AspectJ
Spring AOP - Invoking advice from catch block
Maybe java agents/bytecode manipulation can be helpful
Using Instrumentation to record unhandled exception
You can consider to instrument catch blocks throughout the codebase with Scalameta (or Scalafix)
import scala.meta._

val transformer = new Transformer {
  override def apply(tree: Tree): Tree = tree match {
    case q"try $expr catch { ..case $cases } finally $expropt" =>
      val cases1 = cases.map {
        case p"case $pat if $expropt => $expr" =>
          pat match {
            case p"${pat: Pat.Var}: $tpe" =>
              p"""case $pat: $tpe if $expropt =>
                println("Exception " + ${pat.name} + " is caught")
                $expr
              """
            case p"$pat" =>
              p"""case $pat if $expropt =>
                println("Exception " + ${pat.toString} + " is caught")
                $expr
              """
          }
      }
      q"try $expr catch { ..case $cases1 } finally $expropt"
    case _ => super.apply(tree)
  }
}

transformer(q"""
  try {
    1 / 0
  } catch {
    case e: RuntimeException =>
      println(e)
      throw e
  }
""")

//try {
//  1 / 0
//} catch {
//  case e: RuntimeException =>
//    println("Exception " + e + " is caught")
//    {
//      println(e)
//      throw e
//    }
//}

transformer(q"""
  try {
    1 / 0
  } catch {
    case _ =>
      println("swallowed")
  }
""")

//try {
//  1 / 0
//} catch {
//  case _ =>
//    println("Exception " + "_" + " is caught")
//    println("swallowed")
//}

transformer(q"""
  try {
    1 / 0
  } finally {
    case _ =>
      println("not catching")
  }
""")

//try {
//  1 / 0
//} finally {
//  case _ =>
//    println("not catching")
//}

https://scalameta.org/
https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html
Scala conditional compilation
Macro annotation to override toString of Scala function
How to merge multiple imports in scala?
https://scalacenter.github.io/scalafix
For Java sources Spoon (https://spoon.gforge.inria.fr) can be a replacement for Scalameta.

A: Solution 1 can work. If you are only worried about different semantics then it is sufficient to search in client code for occurrences of the exceptions defined by lib1. If client code catches a more generic exception (e.g. Exception or Throwable) then the precise semantics don't matter and you can leave that code alone.
Assumptions:

*

*Lib1's exceptions are specific and are not thrown by other code (e.g. not RuntimeException but Lib1Exception is okay).

*Lib1 and lib2 throw different exceptions but for the same reasons: if lib1 would throw an exception, lib2 would as well (and vice versa).

A: "Approach 3" is a "nogo". I would go with "approach 4": write a wrapper client library (L3?) that throws the exceptions you want.
It may look like somewhat more work initially, but will definitely pay for itself when you change your mind and want to go back to L1, or when there are L4, L5 and L6 you want to try. It is also probably going to be a lot easier to unit-test.


Q: Save Data from internet in asset folder I want to save data from internet in asset folder in Android. I used Eclipse IDE to develop the android application.
How i can achieve this ?
Thanks.

A: The assets directory is readonly. It's defined and initialized at compile time, you cannot add or edit its contents.
Source (note it doesn't mention anything about writing to files...only reading them.)
Use the SDCard for such operations.

A: slote is right . use internal file storage/SD Card or sqLite database to save image


Q: reading wave audio file into an array in android i am a newbie in android but i have tried to the best of my ability, i want to read a wave audio file into an array of shorts, bytes, floats to be able to manipulate it. With Java you can use JavaSound and you good but android is giving me headache


Q: Ruby on Rails - Track API calls made to 3rd party service I have a 3rd party API service that I am interacting with, via my Rails app, and they have quite low daily limits.
Wondering what the best way to track API calls is?

*

*Database

*Redis

*In memory

*Other

I have a service object that makes all the calls. Just need a good way to track each call made and not go over the daily limit.


Q: Find the number of ordered triples $(a,b,c)$ so that: $a\times\gcd (b,c)=b\times \gcd (a,c)=c\times \gcd (a,b)=2^6 \times 3^8 \times 5^{10} $
Find the number of ordered triples $(a,b,c)$ of positive integers so that the following relations hold:
  $$a\times\gcd (b,c)=b\times \gcd (a,c)=c\times \gcd (a,b)=2^6 \times 3^8 \times 5^{10} $$
  I just know the official answer is 2080.

I think we must consider the prime factorization of $a,b,c$ and try to find the powers of primes in each,but seems too difficult to me...

A: Hint:
Let the highest power of $2$ in $a,b,c$ be $A,B,C$
$\implies A+$min$(B,C)=B+$min$(C,A)=C+$min$(A,B)=6$
Now WLOG $A\ge B\ge C$
$\implies A+B=C+A=6\implies B=C,6=A+B\le A+A\iff A\ge3$
So, we can have  four combinations $\{(3,3);(4,2);(5,1);(6,0)\}$
Similarly for the other two primes namely, $3,5$

A: Well first off, each of the $a,b,c$ divide $2^63^85^{10}$ so each $a,b,c$ is of the form $2^m3^k5^j$.
Let $a = 2^{m_a}3^{k_a}5^{j_a};b = 2^{m_b}3^{k_b}5^{j_b};c = 2^{m_c}3^{k_c}5^{j_c}$
$a\gcd(b,c) = 2^{m_a + \min(m_b, m_c)} 3^{k_a + \min(k_b, k_c)}5^{j_c + \min(j_b, j_c}$ etc.
So $m_a + \min(m_b, m_c) = m_b+ \min(m_a, m_c) = m_c + \min(m_a, m_b)=6$. etc.
Let's label $m_1$ to be the least of $m_a, m_b, m_c$ and $m_2$ to be the median value of of $m_a, m_b, m_c$ and $m_3$ to be the maximum of the three.
So $m_1 + m_2 = m_2 + m_1 = m_3 + m_1 = 6$ so $m_2 = m_3 = 6 - m_1$ so the possible values are $(0, 6,6), (1,5,5), (2,4,4), (3,3,3)$.  For the first three there are $3$ options for whether it is $m_a, m_b$ or $m_c$ that is the least value.  So there are 10 possible ways to distribute the powers of $2$ to the triplets.
I.E. the triples must be of one of these 10 forms:
$a = 3^{k_a}5^{j_a};b = 64*3^{k_b}5^{j_b};c = 64*3^{k_c}5^{j_c}$.. $a = 64*3^{k_a}5^{j_a};b = 3^{k_b}5^{j_b};c = 64*3^{k_c}5^{j_c}$..$a = 64*3^{k_a}5^{j_a};b = 64*3^{k_b}5^{j_b};c = 3^{k_c}5^{j_c}$. or
$a = 2*3^{k_a}5^{j_a};b = 32*3^{k_b}5^{j_b};c = 32*3^{k_c}5^{j_c}$.. $a = 32*3^{k_a}5^{j_a};b = 23^{k_b}5^{j_b};c = 32*3^{k_c}5^{j_c}$..$a = 32*3^{k_a}5^{j_a};b = 32*3^{k_b}5^{j_b};c = 2*3^{k_c}5^{j_c}$. or
$a = 4*3^{k_a}5^{j_a};b = 16*3^{k_b}5^{j_b};c = 16*3^{k_c}5^{j_c}$.. $a = 16*3^{k_a}5^{j_a};b = 4*3^{k_b}5^{j_b};c = 16*3^{k_c}5^{j_c}$..$a = 16*3^{k_a}5^{j_a};b = 16*3^{k_b}5^{j_b};c = 4*3^{k_c}5^{j_c}$. or
$a = 8*3^{k_a}5^{j_a};b = 8*3^{k_b}5^{j_b};c = 8*3^{k_c}5^{j_c}$
By the exact same reasoning, the powers of $3$ must be: $(0,8,8)....(3,5,5)(4,4,4)$ and there are $3*4 + 1 = 13$ ways to distribute the powers of $3$ into triplets.
And the powers of $5$ must be: $(0, 10,10) .... (4,6,6)(5,5,5)$ and there are $3*5+1 = 16$ ways to distribute the powers of $5$ into triplets.
SO there are $10*13*16 = 2080$ possible triplets.
They are $a = 2^{m_a}3^{k_a}5^{j_a};b = 2^{m_b}3^{k_b}5^{j_b};c = 2^{m_c}3^{k_c}5^{j_c}$ where

*

*two of $m_a, m_b, m_c$ are equal and larger or equal to the third and the sum of all three add to $6$. (There are 10 ways to do this.)

*two of $j_a, j_b, j_c$ are equal and larger or equal to the third and the sum of all three add to $8$. ( There are 13 ways to do this.)

*two of $k_a, k_b, k_c$ are equal and larger or equal to the third and the sum of all three add to $10$. (There are 16 ways to do this.)


Q: Refresh Dataframe created by writing to Parquet files in append mode Is there a way that I can refresh a dataframe that is being created by appending to the parquets in pyspark?
Basically I am writing to parquet in append mode, data that I get daily.
If I want to check the parquet file created I load it up in pyspark and do a count of the data. However if new data is appended to the parquet and I try a count again on the dataframe without reloading the dataframe I do not get the updated count. Basically, I have to create a new dataframe everytime there are any changes to my parquet file. Is there a way in Spark, where the changes are automatically loaded once my parquet is updated?


Q: jQuery click function is not attaching click event to anchor HTML
Inside

I have a series of image links with unique ids as below

Javascript / JQuery
The above div is created by a $.get() to a webservice which returns a chunk of HTML in variable response. On success, the $.get() calls the below function:
var thumbnailsDiv = function (response)
    {
        var json = $.parseJSON(response);
        $('#foo-bar-baz').html(json.html);
        alert("Setting click functions on thumbnails");
        $('.foo-bar-thumbnail-image').unbind().click(function () {
            alert("I am thumbnail " + $(this).id);
        }, false);
    };

As you can see above, I'm trying to bind a click function to each of the image links. However this is not working (with or without the unbind()).
After the above code has run, if I inspect the image links in the Dev Tools, I can see that there are two click event attached already to the thumbnails. Neither of these is my function above. The paths for both of them are from other applications libraries embedded on the page: one is labelled 'jQuery' and the other is labelled 'Bubbling' and 'DOM2'. I'm guessing that it is these attached events that mean I can't add my event above, but I don't know enough about jQuery or javascript to know if this is true (I am a server-side developer normally, I don't know front-end stuff at all.)
Any suggestions as to how I get an on-click event working for these elements would be much appreciated, so that I can replace the demo code above with the code I need to run.

A: You just need to bind the click event to the parent element which already exists on the page.
$('#foo-bar-baz').on('click', '.foo-bar-thumbnail-image', function(){
  // what you want to happen when click
  // occurs on elements that match '.foo-bar-thumbnail-image'
  // within '#foo-bar-baz'
  alert("I am thumbnail " + $(this).id);
});

A: You should be using $(document).on('click','.foo-bar-thumbnail-image',function() ... instead of $.click(function()... since the event handler is on elements that were rendered on the page via JS. That's a "delegated" event handler - you can read more about that here https://learn.jquery.com/events/event-delegation/


Q: After running computer-janitor, ubuntu crashed ( Possibly deleted configuration packages) I have some problem, so can anyone help me ?
After I have run computer janitor, my computer crashed. What happens ;

*

*All of the sets are gone.

*I cannot see my Desktop ( I think it erased image of the ubuntu ) .

*I can not use usb ( In terminal, error message is thrown "port cannot be used" )

After I opened my computer, at left corner, there is a terminal. Moreover, background of desktop is colored by violet ( I think it is violet ) .
What I can use ;

*

*I can only  use terminal.

*No program is erased ( I can use them over terminal )

*No file is erased

How can I save my computer ?
Without loosing any file, I can upgrade to any version of ubuntu. ( remember : I can only use terminal. )
My other question : how can upgrade ubuntu to any version of ubuntu over using Tty ?
EDIT :
 lsb_release -a

 No LSB modules are available
 Distributor ID : Ubuntu
 Description : Ubuntu 19.04.4 LTS
 Release : 10.04
 Codename: lucid

 uname -a

 Linux <name> 1.6.32-41-generic #90-Ubuntu SMP Tue may 22 11:29:51 UTC 2012 x86_64 GNU/Linux

A: Try sudo apt-get install ubuntu-desktop , it will try to install the deleted packages that janitor deleted. Use of Janitor is not Recommended
Also for recovering deleted file try here .
And use of janitor is not recommended as fossfreedom said here

Computer Janitor is being dropped in the next version of Ubuntu -
  mainly because nobody used it and the serious perceived issues that it
  could break your system with some of its suggestions.


Q: ValueError: only 1-dimensional arrays can be used import scipy
from matplotlib.pyplot import specgram
sample_rate,X = scipy.io.wavfile.read("a3.wav")
print(X.shape)
specgram(X,Fs=sample_rate,xextend=(0,30))

i am new to python . and first time use python for audio processing . and have struct on following problem . please help .
i want to plot the spectrogram for a wave file.
In above code sample of python I got following Output:
(528038, 2)
ValueError: only 1-dimensional arrays can be used


Q: What does the -> operator do in Objective-C Sorry if this question has been asked before but there were literally no results when i typed it into google. As the title states, I would like to know what the -> operator does. I see it everywhere: [self processTorrent:alert->handle]; but don't know what it does

A: It's the structure dereference ("member b of object pointed to by a") in C. Objective-C is a strict superset of C.
The the usual way to access a member a is as s.a which, given the pointer, is expressed as (*p).a or can instead be accessed by the shorthand:
p->a  using the structure dereference operator.
struct point
{
    int* x;
    int* y;
};

structure point* struct1;

As with any pointer. To change the address it points to:
struct1->x = &varX;

To change the value at the address to which it points:
*(struct1->x) = varX;


Q: How can I calling JavaScript in WebView from Android? I am beginner in Android development and want to create Android app with JavaScript.
I can run my page in WebView.
I can run JavaScript in WebView.
I can call Android Toast message (or Dailog alert ) from JavaScript to Android.
But I can NOT run JavaScript function from Android !
Can you help me to fix my code
[ Download an android studio project ]
http://r7eq.weebly.com

Code of MainActivity.java

package com.example.adnroid_script;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

public class MainActivity extends Activity {
    public static WebView myWebView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myWebView=(WebView) findViewById(R.id.webview);
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.addJavascriptInterface(new jsInterface(), "FromJS");
        myWebView.loadUrl("file:///android_asset/index.html");
    }

    public class jsInterface{
        @JavascriptInterface
        public void ToAndroid(String jsMessage){
            Toast toast = Toast.makeText(getApplicationContext(),"I sent javascript code to myWebView", Toast.LENGTH_LONG);
            toast.show();
            WebView myWebView = (WebView) findViewById(R.id.webview);
            //   ### The bug is here ###   //
            myWebView.loadUrl("javascript:document.write('
Android say : It is working now !
');");
        }
    }
}


Q: Spring boot lazy initialisation is causing issue for datasource I am trying to implement lazy-initialization in my spring boot microservice.
My application is using below items.

*

*Flyway (I have disabled it from yml)

*postgresql

*Kafka

Whenever I deploy this microservice on Jenkins my sping boot application is failing on startup.
The reason is that on my Jenkins i have nothing installed (kakfa, postgresql or flyway)
What i am adivised is we should use lazy loading, I.e Our application should start without this dependencies and my /health endpoint should be UP.
I have made lazy-initialization: true and flyway: enable: false
This is starting my application like a charm!
Now whenever i am trying to call /health endpoint, I am getting below error.

Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory
  method 'dataSource' threw exception; nested exception is
  java.lang.IllegalArgumentException: URL must start with 'jdbc'

Looking into the logs, It seems spring is trying to connect to database when we are calling /health endpoint.
Is there a way to tell spring that check only app is running or not using /health and doesn't check other stuff?
Please let me know if I am missing something to provide if you need it.
Thanks!


Q: Use jQuery to lift element value then return item from array and update another element I have a select element...
<select name="tour" id="tour">
<optgroup label="tour">
<option value="0" selected="selected">Please Select Tour</option>
<option value="Tour1">Tour1</option>
<option value="Tour2">Tour2</option>
</optgroup>
</select>

I have an array...
<?php $array = array(Tour1=>100,Tour2=>200); ?>

I have a field element...
<input type="text" size="5" id="distance" readonly="readonly" name="distance" value="" class="value" />

I'm looking to set up a jQuery script that looks for a change in the value in the select element 'tour', searches for it in my array, returns the associative value, and writes it to the value of my input field 'distance'.
Desired output: When Tour1 is selected, text input field 'distance' will show 100.

A: 1st Pass the PHP array to JavaScript using json_encode:
var phpArray = <?php echo json_encode($array); ?>;

2nd Bind to the change event of that <select>:
$('#tour').on('change', /* see below */);

3rd Update the value:
function (event) {
    $('#distance').val(phpArray[$(this).val()]);
}

A: what you want to do is not possible. PHP is a server side script. What you could do in order to make your scripts working is to pass the php Array to Javascript when loading the page. That way Javascipt is able to read it and to change the input.
Option would be to use AJAX or define a JS array with the php Array's data:
var js_array = <? echo json_encode($you_array); ?>;

For this solution you need to add a  in your HTML page's  if you're pointing to your JS script external.
For a longer explanation why using your php Array in Javascript that easy is not possible, see here: Difference between Javascript and PHP


Q: Spring boot SUM(column) with specification I have an entity, says:
class MyEntity {
    Long id;
    String attr1;
    String attr2;
    String attr3;
    String attr4;
    Double attr5;
}

I use Specification to query the result filtered by attributes like:
class MySpecification implements Specification<MyEntity> {
    private String attr1;
    private String attr2;
    private String attr3;
    private String attr4;

@Override
public Predicate toPredicate(Root<MyEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
    List<Predicate> restriction = new ArrayList<>();
    if (!StringUtils.isEmpty(attr1)) {
        restriction.add(criteriaBuilder.equal(root.get("attr1"), attr1));
    }
    if (!StringUtils.isEmpty(attr2)) {
        restriction.add(criteriaBuilder.equal(root.get("attr2"), attr2));
    }
    // And so on
    Predicate predicate = criteriaBuilder.disjunction();
    predicate.getExpressions().add(criteriaBuilder.and(restriction.toArray(new Predicate[restriction.size()])));
    return predicate;
    }
}

Now I want to get sum of attr5 by the Specification, how can I do that ?
Thank you in advanced.

A: After some research, here is solution:
Create an interface:
interface MyRepositoryCustom {
    <S extends Number> S sum(Specification<MyEntity> spec, Class<S> resultType, String fieldName);
}

Implementation:
@Repository
class MyRepositoryCustomImpl implements MyRepositoryCustom {

    @Autowired
    private EntityManager entityManager;

    @Override
    public <S extends Number> S sum(Specification<MyEntity> spec, Class<S> resultType, String fieldName) {
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<S> query = builder.createQuery(resultType);
        Root<MyEntity> root = applySpecificationToCriteria(spec, query);
        query.select(builder.sum(root.get(fieldName).as(resultType)));
        TypedQuery<S> typedQuery = entityManager.createQuery(query);
        return typedQuery.getSingleResult();
    }

    protected <S> Root<MyEntity> applySpecificationToCriteria(Specification<MyEntity> spec, CriteriaQuery<S> query) {
        Root<MyEntity> root = query.from(MyEntity.class);
        if (spec == null) {
            return root;
        }
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        Predicate predicate = spec.toPredicate(root, query, builder);
        if (predicate != null) {
            query.where(predicate);
        }
        return root;
    }
}

Main repository should extend both JpaRepository and MyRepositoryCustom:
@Repository
interface MyEntityRepository extends JpaRepository<MyEntity, Long>, MyRepositoryCustom {

}


Q: Support Emoji in Markdown Stack Exchange uses Markdown, but unlike so many other sites (e.g. GitHub, Discourse, Slack) that use Markdown, we don't support Emoji. I'd like to be able to write :smile:, :thumbsup:, :heart: or even :poop: and have it render correctly on all Stack Exchange sites.

See the Emoji Cheat Sheet for more examples.
To clarify - I'm not asking for emoji character support.  We can already do emoji with Unicode characters, like this:  ☺  ❤
I'm asking specifically that the markdown engine recognize the emoji tags like :smile:.  It would be great if it rendered with better graphics, but rendering with their text equivalents would also be acceptable.

A: No.

A: I don't buy the argument that emoticons are noise, or that they should be unique to social media, but I really don't see the point of having them on Stack Exchange. In questions and answers, you can already include inline images in the normal way if you really want emoticons (not that I would recommend it). And comments are disposable. Adding emoji markup seems to suggest the opposite. You can already use ASCII emoji which should be enough to convey that meaning.

A: Why, why oh why?
ASCII is so beautiful, so neat, fast, clean, elegant.
Noise is not welcome.

A: If emoji's were "noise", then using that same logic, it could be said smiling in public to others is also "noise". And seeing in color is "noise".
I understand ASCII art conveys meaning, and I'm not downplaying its use. However, ASCII is black and white. And our brains are wired to process images much quicker, with deeper meaning, than ASCII text. Our brains can extrapolate more meaning, quicker using pictures than text.
Emoji's convey meaning in a color, graphical way which our brains can process quicker with deeper meaning. It seems to me, that alone should encourage their use on StackOverflow. But, I'm not a Stack Overflow developer, nor moderator. So...  :shrugs:

A: If you use Windows, you can use AutoHotKey and add emojis via Markdown with this script.
There are cases where I see emojis are useful. For example, in Software Recommendation there is a feature request to have checkbox. Or when the conversation seems to be heated, an emoji can reduce the heat, and the recipient can focus on the information rather than let the emotion overwhelming.

Some other useful AutoHotKey scripts I recommend too: LaTeX, AutoCorrect, Quick Type HTML Tags


Q: A dog biting a complete binary Christmas tree - expected value, variance Professor Macarius bought a complete binary Christmas tree having $2^D - 1$ vertices. Unfortunately, on the Christmas Eve his dog Brutus bit the tree. Each of the edges is bit with probability $\frac{1}{2}$, independently from other edges. Let $X$ be the number of vertices in the remaining tree (connected part containing the tree's tip).
Count the expected value and variance of $X$.
My solution:
Let $1, 2, ..., 2^D - 1$ be the numbers of the vertices counting from the top left ($1$ is the number of the tip, $2$ is the number of the left son of the tip etc.). Let $X_i$ be a Bernoulli random variable such that $X_i=1$ if vertex no. $i$ is in the remaining part of the tree. $$EX_i = \frac{1}{2}^{\lfloor{log_2{i}}\rfloor}$$
$$X = X_1 + ... + X_{2^D - 1}$$
$$EX = \sum_{i=1}^{2^D - 1}\left(\frac{1}{2}\right)^{\lfloor log_2 i \rfloor} \le H_{2^D - 1}$$
Is it correct? Can you get a better approximation for $EX$?
How to count the variance? I'm unfortunately unable to count $EX^2$.

A: The expectation can be calculated by saying that there if levels are labelled $0,1,\ldots,D-1$, there are $2^d$ vertices at level $d$ and each of these has probability $\frac1{2^d}$ of staying connected to the tip, so the overall expected number connected is $\sum_d  2^d \frac1{2^d} = D$


Q: Need help understanding RESTful apis in PHP For a few weeks, I've been trying to gather as much information on implementation of RESTful apis in PHP as I can but in vain. All the information that is given online only explain the most basic concepts but never did I come across a very real example with complete code on how RESTapi actually works.
For Example, POST is used create a new resource. But how? How is it implemented in real life? How do I do this in cURL? I am aware of the complete basics but am unable to find any concrete and complete example that explains everything. Most of the tutorials simply name the functions they've used but did not bother explaining what is happening exactly, what the flow of the program is, etc.
If someone can help with a complete example (say, a library registration and database) I'll really appreciate it. I'm really confused.

A: I will describe POST method in REST.
Client send HTTP request via POST method with JSON data.
For example, client send some data to create a word "nice".
POST http://localhost/word/1

JSON content
{
  "data": {
    "type": "word",
    "attributes": {
      "word": "nice"
    }
  }
}

In PHP you need get a response and convert to array and insert ot DB. Why insert? Because request method is POST.


Q: Running SDRTrunk (A Java application) in a gnome session .desktop env can't move application or resize I am using a Raspberry Pi 4 8GB to try to run SDRTrunk.
I have it running in a gnome .desktop with
[Desktop Entry]
Type=Application
Path=/home/pi/sdr-trunk-0.5.0-beta7/
Exec=/home/pi/sdr-trunk-0.5.0-beta7/bin/sdr-trunk
TryExec=--maximize --full-screen
Name=SDRTrunk
DesktopName=SDRTrunk
Comment=Testing

The application launches and runs upon login, but its in the bottom right half/corner of the screen. I am unable to move it with a mouse, and I can not access the min/max options to see if those even work.
I have tried the --maximize --full-screen on the same exec, as well as above.
When closing the application I am logged out instantly just like it should.
OS: Raspberry Pi OS Lite 64bit
Desktop Env Installed Via apt-get install gnome-session


Q: What is the limit value of $a$ that $\sum\limits_{k = 1 }^ \infty \frac{ \ln(k)}{k^a}$ converges  if a>1 then the series $\sum\limits_{k =  1 }^ \infty \frac{ 1}{k^a}  $   converges
What is the limit value of $a$ for the series below?
$$\sum\limits_{k =  1 }^ \infty \frac{ \ln(k)}{k^a}  $$
My steps to find the value:
if $x > 1$ then $\ln x <x   $
thus
$$\sum\limits_{k =  1 }^ \infty \frac{ \ln(k)}{k^a}  < \sum\limits_{k =  1 }^ \infty \frac{ k}{k^a} = \sum\limits_{k =  1 }^ \infty \frac{ 1 }{k^{a-1}}$$
if $a>2$, It is sure that $\sum\limits_{k =  1 }^ \infty \frac{ \ln(k)}{k^a}$ the series converges.
But we can find a lower value for the series.
Could you please help me to find the exact value of $a$ that  the series converge?
Thanks for answers

A: It converges for $a\gt 1$. Try the integral test.

A: It can easily proved that for all $\varepsilon>0$ there exists $x_0$ such that for all $x>x_0$:
$$\ln x <x^\varepsilon$$
It can be shown in couple of ways (i.e calculating $\lim_{x\to \infty}\frac{\ln x}{x^\varepsilon} $)*.
Now, for any given $a>1$ we can write $a=1+2\delta$ and from the previous statement we can find a natural $N$ such that for every $n>N$:
$$\ln n<n^\delta$$
So we get:
$$\sum_{n=N+1}^\infty \frac{\ln n}{n^a} = \sum_{n=N+1}^\infty \frac{\ln n}{n^{1+2\delta}}<\sum_{n=N+1}^\infty \frac{ n^\delta}{n^{1+2\delta}}=\sum_{n=N+1}^\infty \frac{1}{n^{1+\delta}}$$
The latter sum is a "p-series" tail with p>1 and therefor converges.
*Addition -
$$\lim_{x\to \infty}\frac{\ln x}{x^\varepsilon}\overset{\text{L'Hopital}}{=\!=\!=\!=\!=\!=}\lim_{x\to \infty}\frac{\frac{1}{x}}{\varepsilon \cdot x^{\varepsilon-1}}=\frac {1}{\varepsilon}\lim_{x\to \infty}\frac{1}{x^\varepsilon}=0$$

A: Let $f(x)=e^x-1-x$, then $f'(x)=e^x-1$ and the only $x\in\mathbb{R}$ so that $e^x-1=0$ is $x=0$. Note that $f''(0)=1$ so $f(x)$ reaches a minimum of $0$ at $x=0$. Therefore, for all $x\in\mathbb{R}$,
$$
1+x\le e^x\tag{1}
$$
Thus, we get that for all $x\in\mathbb{R}$, $x<e^x$, and therefore, for all $x>0$, $$
\log(x)< x\tag{2}
$$
For any $\alpha>0$, apply inequality $(2)$ to $x^\alpha$ and divide by $\alpha$ to get
$$
\log(x)< \tfrac1\alpha x^\alpha\tag{3}
$$
Then for any $\epsilon>0$, we have
$$
\begin{align}
\sum_{k=1}^\infty\frac{\log(k)}{k^{1+\epsilon}}
&<\sum_{k=1}^\infty\frac{\frac2\epsilon k^{\epsilon/2}}{k^{1+\epsilon}}\\
&=\frac2\epsilon\sum_{k=1}^\infty\frac1{k^{1+\epsilon/2}}\tag{4}
\end{align}
$$
and $(4)$ converges for all $\epsilon>0$. Thus, for any $\alpha>1$,
$$
\sum_{k=1}^\infty\frac{\log(k)}{k^\alpha}\tag{5}
$$
converges.

Alternatively, since $\frac{\log(x)}{x^\alpha}$ is a decreasing function when $x\ge e$ and $\alpha\ge1$,
$$
\begin{align}
\sum_{k=3}^\infty\frac{\log(k)}{k^\alpha}
&\le\int_1^\infty\frac{\log(x)}{x^\alpha}\mathrm{d}x\\
&=\int_0^\infty\frac{x}{e^{\alpha x}}\,e^x\,\mathrm{d}x\\
&=\frac1{(\alpha-1)^2}\int_0^\infty x\,e^{-x}\,\mathrm{d}x\\
&=\frac1{(\alpha-1)^2}\tag{6}
\end{align}
$$
Thus, for any $\alpha>1$, we again have that $(5)$ converges.

A: Here's another approach.
Let $\displaystyle c_k = \frac{\log k}{k^a}$.
Examine the ratio of successive terms for large $k$,
$$\frac{c_{k+1}}{c_{k}} = 1 - \frac{a}{k} + \frac{1}{k\log k} + O\left(\frac{1}{k^2}\right).$$
By Raabe's test the series converges for $a>1$ and diverges for $a<1$.
By Bertrand's test the series diverges for $a=1$.

Raabe's test tells us that if
$$\left|\frac{a_{n+1}}{a_{n}}\right| \sim 1 - \frac{s}{n} \hspace{5ex}(n\to\infty),$$
then the series converges absolutely if $s>1$, diverges if $s<1$, and may converge or diverge if $s=1$.
A simplified version of Bertrand's test tell us that if
$$\left|\frac{a_{n+1}}{a_{n}}\right| \sim 1 - \frac{1}{n} - \frac{s}{n\log n} \hspace{5ex}(n\to\infty),$$
then the series converges absolutely if $s>1$, diverges if $s<1$, and may converge or diverge if $s=1$.

A: All you need to have for your serie to converge is $a>1$. Indeed, $\displaystyle\frac{\ln k}{k^a} = \frac{\ln k}{k^{\frac{a-1}{2}}}\times\frac{1}{k^{1+\frac{a-1}{2}}} = o(\frac{1}{k^{1+\frac{a-1}{2}}})$.

A: Case 1: $a>1$. Pick $b \in (1,a)$.
Then
$$\lim_k \frac{\frac{ \ln(k)}{k^a}}{\frac{1}{k^b}}=0 \,.$$
Since $\sum_k \frac{1}{k^b}$ is convergent, by the Limit Comparison Theorem your series is convergent.
Case 2: $a \leq 1$.
Then
$$\lim_k \frac{\frac{ \ln(k)}{k^a}}{\frac{1}{k^a}}=\infty \,.$$
Since $\sum_k \frac{1}{k^a}$ is divergent, then by the Limit Comparison Theorem your series is divergent.


Q: Slider AutoplayJquery doesn't work How can I add autoplay in this slider?
https://codepen.io/mikun/pen/YWgqEX
        $('.slide-nav').on('click', function(e) {
  e.preventDefault();
  // get current slide
  var current = $('.flex--active').data('slide'),
    // get button data-slide
    next = $(this).data('slide');

  $('.slide-nav').removeClass('active');
  $(this).addClass('active');

  if (current === next) {
    return false;
  } else {
    $('.slider__warpper').find('.flex__container[data-slide=' + next + ']').addClass('flex--preStart');
    $('.flex--active').addClass('animate--end');
    setTimeout(function() {
      $('.flex--preStart').removeClass('animate--start flex--preStart').addClass('flex--active');
      $('.animate--end').addClass('animate--start').removeClass('animate--end flex--active');
    }, 1200);
  }

});

It's working good, but without an autoplay.


Q: Notice unserialize error in CakePHP via Redis Update:
Per suggestion from the accepted answer below, I tested reading a negative number:
$negativeInt = -1;
Cache::write('my-test-count', $negativeInt, 'short');
$readVal = Cache::read('my-test-count', 'short');
debug($readVal);
exit;

The unseralize error reproduces consistently when trying to read any negative number.  It's now an accepted bug, which I assume will be resolved by 2.8.1

Original Question:
I keep getting this error, but can't figure out why or even how to further troubleshoot.
The line that throws the error should only get hit if Cache::read() returns false.  But, that line would throw an unserialize error itself if I didn't put the @ before it.
Question:
How can I reliably use Redis for counts without getting unserialize Notices on a regular basis?  If the data in the key is "bad", how can I know that without getting the Notice just from doing a ::read.  I've tried making sure my data is (int) (see below), but that doesn't seem to help.

Notice (8): unserialize(): Error at offset 0 of 2 bytes
  [APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Engine/RedisEngine.php,
  line 136]

Upon inspection of the error:
> unserialize - [internal], line ??
> RedisEngine::read() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Engine/RedisEngine.php, line 136
> Cache::read() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Cache.php, line 358
> Cache::remember() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Cache.php, line 567
> Item::getCount() - APP/Model/Item.php, line 812

It appears to be coming from this function:
public function getCount($id) {
    $model = $this;

    // here is where the Cache::read() and debug are in the update below

    return Cache::remember('item' . $id. '_count', function() use ($model, $id) {
        $count = $model->find('count', array(
            'conditions' => array(
                $model->alias . '.status' => 1,
                $model->alias . '.id' => $id
            )
        ));
        return ($count === false) ? 0 : (int)$count;
    }, 'my_counts'); // THIS IS LINE 812
}

public function decrementCount($id, $offset = 1) {
    if(empty($id)) return false;
    $count = @Cache::read('item' . $id . '_count', 'my_counts');
    if($count === false) {
        $this->getCount($id);
    } else {
        Cache::decrement('item' . $id . '_count', $offset, 'my_counts');
    }
}

public function incrementCount($id, $offset = 1) {
    if(empty($id)) return false;
    $count = @Cache::read('item' . $id. '_count', 'my_counts');
    if($count === false) {
        $this->getCount($id);
    } else {
        Cache::increment('item' . $id. '_count', $offset, 'my_counts');
    }
}

UPDATE:
This function gets run in a loop (through 1-20 items).  When I add the following before the Cache::remember(...:
$toReturn = Cache::read('item' . $id. '_count', 'my_counts');
debug($toReturn);

It gives this:

*

*debug: (int) 0

*debug: (int) 0

*Notice (8): unserialize(): Error at...  (from the Cache::read)

*debug: false

*Notice (8): unserialize(): Error at...   (from the Cache::remember

*debug: (int) 0

*Notice (8): unserialize(): Error at...  (from the Cache::read)

*debug: false

*Notice (8): unserialize(): Error at...   (from the Cache::remember

*0

*3

*1

*1
...

A: It seems to be a core bug. I might be able to answer to why this issue occurs.
I am guessing that this issue is caused by int(-1).
When writing data, RedisEngine doesn't serialize the data if it is an integer.
Therefore, int(-1) will be saved without calling serialize().
public function write($key, $value, $duration) {
    if (!is_int($value)) {
        $value = serialize($value);
    }
    ...
}

But when reading data, the implementation seems asymmetric. I don't know Redis well, but I am guessing that Redis stores int(-1) as string(-1). As ctype_digit("-1") returns false, string(-1) would be unserialized wrongly.
public function read($key) {
    $value = $this->_Redis->get($key);
    if (ctype_digit($value)) { // ctype_digit("-1") === false
        $value = (int)$value;
    }
    if ($value !== false && is_string($value)) { // is_string("-1") === true
        $value = unserialize($value);
    }
    ...
}

Thus, you will see "Notice (8): unserialize(): Error at offset 0 of 2 bytes". The size of string(-1) is 2 bytes.
What about opening an issue on github, if you could reproduce that writing int(-1) and reading it throws a notice.
Aside from that, a workaround would be stop using Cache::decrement(). On race conditions, the method will store int(-1).
You may use Cache::write() instead if it is not an important data. For example:
$count = Cache::read('item' . $id. '_count', 'my_counts');
if ($count === false || 0 > $count - $offset) {
    $this->getCount($id);
} else {
    Cache::write('item' . $id. '_count', $count - $offset, 'my_counts');
}

But if it is an important data, then you may need to implement exclusive lock/unlock.
Thank you for reading this to the end and sorry if I am wrong.

A: Solution:
return ($count === false) ? 0 : (int)$count;

Long version:
You shouldn't increment/decrement serialized value.
Cache::remember does something like this:
$key = 'key';
$value = 10;
$serialized = serialize($value); // $serialized = 'i:10;'
$redis->set($key, $serialized);

Cache::read does something like this:
$key = 'key';
$serialized = $redis->get($key); // $serialized = 'i:10;'
$value = unserialize($serialized); // $value = (int) 10
return $value;

But Cache::decrement does something like this:
$key = 'key';
$count = 1;
$redis->decrby($key, $count); // Error, decrby expects plain value, "10", not "i:10;" ( http://redis.io/commands/decrby )

Also, if you decrement successfully, then you will have plain value in redis, so result will be:
$key = 'key';
$serialized = $redis->get($key); // $serialized = '10'
$value = unserialize($serialized); // error, cannot unserialize '10'

EDIT:
After checking source:
https://github.com/cakephp/cakephp/blob/master/src/Cache/Engine/RedisEngine.php
I see that Cake does checks:
    if (!is_int($value)) {
        $value = serialize($value);
    }

So all you need to do to avoid serialization is to make sure that you are storing (int).

A: Just remove third parameter, it should be work
return Cache::remember('item' . $id. '_count', function() use ($model, $id) {
    $count = $model->find('count', array(
        'conditions' => array(
            $model->alias . '.status' => 1,
            $model->alias . '.id' => $id
        )
    ));
    return ($count === false) ? 0 : (int)$count;
});


Q: Recommendations for keeping a build server updated As a guy who frequently switches between QA, build and operations, I keep running into the issue of what to do about operating system updates on the build server.  The dichotomy is the same on Windows, Linux, MacOS or any other o/s that can update itself via the internet:

*

*The QA team wants to keep the build server exactly as it is from the beginning of the product release cycle to the end, since installing updates could destabilize the server and means that successive builds aren't made against the same baseline.

*The ops team wants the software to be deployed on a system with all the latest security patches; this can mean that the software isn't deployed on exactly the same version of the o/s that it was built on.

I usually mitigate this by taking release candidate builds and installing them on a test server that has a completely up-to-date o/s, repeating the automated tests that are run on the build server and doing some additional system level testing to make sure everything looks good before deployment.  However, this seems inefficient to me; does anyone have a better way ?

A: Personally i don't think you have much of an issue here - just apply the latest updates to the build server. The main reasons i say this are:

*

*it is highly unlikely that your code or any of the dependencies on the build server are so tightly coupled to the OS version that installing regular updates is going to affect anything, let alone break it. There can be minor differences between window messages etc between Windows versions, but those are few and far between, and are usually quite well documented out there on teh interweb. If you are using managed technology stacks like WPF/Silverlight or ASP.Net and even mostly Winforms then you will be isolated from these changes - they should only affect you if you are doing hardcore stuff using the WinAPI directly to create your windows or draw your buttons.

*it is a good practice to always engineer your product against the latest version of the OS, because you need to encourage your customer to implement those updates too - IOW you should not be in a position where you have to say to your client to not install update xyz because your application will not run against it - especially if that update is a critical security update

*testing for differences between OS versions should be done by the QA team and should independant of what is on the build server

*you do not want your build server to get in to such a state that it has been so isolated from the company update process that when you finally do apply them all it barfs and spits molten silicon everywhere. IOW, the longer you wait to update, the higher the risk of something going wrong and doing so catastrophically. Small and frequent/incremental updates are lower risk than mass updates once per decade :)
The build server updates that you do have to be cautious about are third party controls or library updates - they can frequently contain breaking changes or considerably altered behavior. They really should be scheduled, and followed up by a round of testing looking for any changes.

A: Virtualize!
Using stuff like VMWare Server you can script the launch and suspend of virtual machines. So you can script VM resume, SSH to launch build, copy, VM suspend, repeat. (I say this, but I abandoned my work on this. Still, I was making progress at the time.)
Also, you can trust your OS vendors. Can't you?
They have an interest in compatibility. If you build on Windows XP it is almost certain to work on XP SP3 and Vista and Windows 7.
If you build on RedHat Enterprise 5, it had better work on 5.1, 5.2, 5.3, 5.4, etc.
In my experience this has worked out OK so far for me and I recommend building on your lowest patch OS versions. With the Linux stuff in particular I have found newer releases linking to more recent libraries not available on older versions.
Of course it doesn't hurt to test your code on a copy of the deployment server. It all depends on how certain you want to be.

A: Take the build server off the network, that way you do not need to worry about installing security updates. Only load the source from CD, thumb drive or whatever other means.
Plug it back in at the end of your release cycle and then let all the updates take place.

A: Well, for the most stable process, I would have two build servers, "Build with Initial config, Build with update config", and two autotest test servers with similar differences. Use virtualization to do this effectively and scriptably.


Q: 500 Internal Server Error on a WordPress site My site was hacked some weeks ago. I have deleted the old files and copied a backup file on the server. For some reason it is showing 500 internal server error.
What have I tried?
I have tried to delete all the plugins but the error is still there. Please guide.
Edit:
Here is how my .htaccess file looks like,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Following is my error log:
MAIN error_log:
[Wed Aug 26 06:25:28 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:28 2015] [notice] [client 182.18.129.224] mod_rbl: 182.18.129.224 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 91.72.17.134] mod_rbl: 91.72.17.134 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:29 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 89.248.167.137] mod_rbl: 89.248.167.137 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 185.93.187.69] mod_rbl: 185.93.187.69 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [error] [client 104.41.151.86] ModSecurity: Access denied with connection close (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/etc/httpd/modsecurity.d/eig_rules.conf"] [line "615"] [id "900036"] [msg "Wordpress BOT exploit :: No UA/Referer"] [hostname "www.bgyinfosys.com"] [uri "/foodsawasdee/wp-login.php"] [unique_id "Vd2wOkKT9FYAACSiIEQAAAFO"]
[Wed Aug 26 06:25:30 2015] [notice] [client 185.93.187.69] mod_rbl: 185.93.187.69 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [error] [client 189.11.10.177] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://cemat.edu.pe/
[Wed Aug 26 06:25:30 2015] [error] [client 189.11.10.177] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://cemat.edu.pe/
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [error] [client 104.41.151.86] ModSecurity: Access denied with connection close (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/etc/httpd/modsecurity.d/eig_rules.conf"] [line "615"] [id "900036"] [msg "Wordpress BOT exploit :: No UA/Referer"] [hostname "www.bgyinfosys.com"] [uri "/foodsawasdee/wp-login.php"] [unique_id "Vd2wOkKT9FYAACVuLSIAAAHW"]
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 52.28.117.58] mod_rbl: 52.28.117.58 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [error] [client 104.41.151.86] ModSecurity: Access denied with connection close (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/etc/httpd/modsecurity.d/eig_rules.conf"] [line "615"] [id "900036"] [msg "Wordpress BOT exploit :: No UA/Referer"] [hostname "www.bgyinfosys.com"] [uri "/foodsawasdee/wp-login.php"] [unique_id "Vd2wOkKT9FYAACVuLSkAAAHZ"]
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:30 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 119.31.234.188] mod_rbl: 119.31.234.188 is listed in RBL.
[Wed Aug 26 06:25:31 2015] [notice] [client 89.248.167.137] mod_rbl: 89.248.167.137 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 119.31.234.188] mod_rbl: 119.31.234.188 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 52.28.117.58] mod_rbl: 52.28.117.58 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 149.210.165.239] mod_rbl: 149.210.165.239 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 119.31.234.188] mod_rbl: 119.31.234.188 is listed in RBL.
[Wed Aug 26 06:25:32 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 119.31.234.188] mod_rbl: 119.31.234.188 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 203.155.20.3] mod_rbl: 203.155.20.3 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 107.173.245.2] mod_rbl: 107.173.245.2 is listed in RBL., referer: http://media.bramptonsda.org/
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 203.155.20.3] mod_rbl: 203.155.20.3 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:33 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 203.155.20.3] mod_rbl: 203.155.20.3 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 107.173.245.2] mod_rbl: 107.173.245.2 is listed in RBL., referer: http://media.bramptonsda.org
[Wed Aug 26 06:25:34 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:34 2015] [notice] [client 107.173.245.2] mod_rbl: 107.173.245.2 is listed in RBL., referer: http://media.bramptonsda.org
[Wed Aug 26 06:25:34 2015] [notice] [client 203.155.20.3] mod_rbl: 203.155.20.3 is listed in RBL.
[Wed Aug 26 06:25:35 2015] [notice] [client 107.173.245.2] mod_rbl: 107.173.245.2 is listed in RBL., referer: http://media.bramptonsda.org/index.php/component/users/?view=registration
[Wed Aug 26 06:25:35 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:35 2015] [notice] [client 192.169.60.146] mod_rbl: 192.169.60.146 is listed in RBL.
[Wed Aug 26 06:25:35 2015] [notice] [client 107.173.245.2] mod_rbl: 107.173.245.2 is listed in RBL., referer: http://media.bramptonsda.org/index.php?option=com_user&view=register
[Wed Aug 26 06:25:35 2015] [error] [client 216.244.82.251] Failed loading /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so:  /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so: undefined symbol: zend_new_interned_string
[Wed Aug 26 06:25:35 2015] [notice] [client 203.155.20.3] mod_rbl: 203.155.20.3 is listed in RBL.
[Wed Aug 26 06:25:35 2015] [notice] [client 50.63.153.98] mod_rbl: 50.63.153.98 is listed in RBL.
[Wed Aug 26 06:25:35 2015] [notice] [client 198.11.179.195] mod_rbl: 198.11.179.195 is listed in RBL.
[Wed Aug 26 06:25:36 2015] [error] [client 101.169.255.249] Failed loading /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so:  /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so: undefined symbol: zend_new_interned_string, referer: https://www.google.com.au/
[Wed Aug 26 06:25:36 2015] [notice] [client 89.248.167.137] mod_rbl: 89.248.167.137 is listed in RBL.

A: Check for old or missing hidden files like .htaccess etc. These are prone to cause 500 Internal server error especially when not matching the installation.