text:
Q: Fix missing HTML tags using Greasemonkey userscript I need to open a web page that is somehow missing .... That is, the page content is only:

 ...

 ...

without the enclosing HTML tags.
Firefox is willing to render this page, but not Chrome. I want to use userscript to fix it.
But since head and body has no parent, I can't insert anything before&after them.
Any idea how to do it? Thanks!

A: I don't think this will solve your issue or not. Please try this using jQuery :
$(document).ready(function(html){
       html = '' + html + '';
});

where html is the page without html tags.
See this.


text:
Q: Matlab installation (LD_LIBRARY_PATH) messes up other library files I am trying to install Matlab on a Linux machine, but setting LD_LIBRARY_PATH (as the installation requires) breaks other library files. I am not an Linux expert, but I have tried several things and cannot get it working correctly. I have even contacted Matlab support, got the issue elevated to the dev team, and was basically told "haha sucks to suck". I have seen a few other people online have had the same issue, but either their questions were never answered or they had a slightly different problem and their solution didn't apply to me.
Installing on a VM running Ubuntu:
I set LD_LIBRARY_PATH as the instructions say, then it breaks network files. I can ping google.com, but I cannot nslookup google.com or visit it in a browser. Nslookup provides this error:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)
03-Feb-2016 11:32:22.361 ENGINE_by_id failed (crypto failure)
03-Feb-2016 11:32:22.362 error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
03-Feb-2016 11:32:22.363 error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:447:
03-Feb-2016 11:32:22.363 error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:418:id=gost
(null): dst_lib_init: crypto failure

The installation worked though (I can run my Java programs that reference compiled Matlab functions). Unsetting LD_LIBRARY_PATH fixes the network files but then I can't run programs anymore.
Installing on EC2 instance:
On an EC2 instance it does not break the network files (nslookup is fine). Instead it messes up Python library files. Trying to use any aws cli command, I get the error:
File "/usr/bin/aws", line 19, in <module>
  import awscli.clidriver
File "/usr/lib/python2.7/dist-packages/awscli/clidriver.py", line 16, in <module>
  import botocore.session
File "/usr/lib/python2.7/dist-packages/botocore/session.py", line 25, in <module>
  import botocore.config
File "/usr/lib/python2.7/dist-packages/botocore/config.py", line 18, in <module>
  from botocore.compat import six
File "/usr/lib/python2.7/dist-packages/botocore/compat.py", line 139, in <module>
  import xml.etree.cElementTree
File "/usr/lib64/python2.7/xml/etree/cElementTree.py", line 3, in <module>
  from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"

Printing sys.path in Python shows lib-dynload is already there though, so it doesn't seem to the problem.
And when trying to run the program, I get:
Exception in thread "main" java.lang.LinkageError: libXt.so.6: cannot open shared object file: No such file or directory
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.dlopen(Native Method)
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.loadLibraryAndBindNativeMethods(DynamicLibraryUtils.java:134)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1529)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:48)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:59)
at VectorAddExample.VectorAddClass.<init>(VectorAddClass.java:62)
at com.mypackage.Example.main(Example.java:13)

I'm at a brick wall and really have no clue how to proceed.

A: Maybe something else already needs LD_LIBRARY_PATH set to work. Make sure you prepend not overwrite:
export LD_LIBRARY_PATH=new/path:$LD_LIBRARY_PATH

Edit:
OK, if LD_LIBRARY_PATH was initially empty, this suggests that Matlab comes with shared libraries that are incompatible with your system ones:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)

suggests that /usr/lib/libdns.so.100 needs libcrypto.so.1.0.0, which is now being resolved to the one that comes with MATLAB, which is incompatible.
You can check the dependencies of a dll by
ldd /usr/lib/libcrypto.so.1.0.0

and hopefully you can find a configuration that keeps both MATLAB and your system happy. Unfortunately, this may involve a lot of trial and error.
If there is no such configuration, you can try setting LD_LIBRARY_PATH only when you run MATLAB:
LD_LIBRARY_PATH=$MATLAB_LD_LIBRARY_PATH matlab
Edit 2:
Well, for the Python issue, it seems to boil down to pyexpat, which is a wrapper around the standard expat XML parser. Try doing (name guessed since I don't have a Linux right now):
ldd /usr/local/lib/python2.7/site-packages/libpyexpat.so
and see what that depends on. Probably, it will be libexpat.so, which is now being resolved to MATLAB's version.

A: try the following command:
export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:$LD_LIBRARY_PATH

A: Perhaps not helpful for OP but if you are generating a python package with MATLAB, you could modify the generated __init__.py file MATLAB creates for your package.
Specifically, the generated __init__.py file contains the following line (as of MATLAB 2017a):
PLATFORM_DICT = {'Windows': ['PATH','dll',''], 'Linux': ['LD_LIBRARY_PATH','so','libmw'], 'Darwin': ['DYMCR_LIBRARY_PATH','dylib','libmw']}

For Linux platform, you could simply replace LD_LIBRARY_PATH with something else such as MCR_LIBRARY_PATH to prevent mucking with your shared libs.
sed -i -e 's/LD_LIBRARY_PATH/MCR_LIBRARY_PATH/g' /MY/PACKAGE/BUILD/PATH/__init__.py

Then obviously export MCR_LIBRARY_PATH before using python.

redpajama_set_name: RedPajamaStackExchange


text:
Q: C++ UDP two way client/server delivery I'm building a UDP server for handling of position updates in a flight simulator (so, the packets will be rapid and guaranteed delivery isn't needed). The server creates and binds a UDP socket as per "session" in the server. The server then communicates the position information from the master to the viewers. This logic works (although, I currently have it coded to echo every message sent to it back to the sender, for testing) on a LAN (I had the server and client setup on the same system to test).
When I moved it to WAN, the client was no longer able to receive messages from the server, but the server received messages from the client. I am afraid it is a firewall/port blocking issue, however, I am coming here in hopes of either finding a different/correct way to do what I'm doing, or instructions on how I can escape the blocking.
The code for the server is as follows:
user newuser;
ommand = raw_connections[i].sockfd;
sockaddr_in sin;
socklen_t len = sizeof(sin);
getsockname(raw_connections[i].sockfd, (sockaddr*)&sin, &len); //raw_connections is a vector of sockets that haven't yet authenticated
newuser.addr.sin_addr = sin.sin_addr;
newuser.addr.sin_family = sin.sin_family;
newuser.addr.sin_port = atoi(inp[4].c_str()); //the UDP port as specified by the client
flights[fpos].users.push_back(newuser); //fpos is the index in the vector

The above data is called as a result of a TCP socket between my program's UI and the system (the portion of that will handle user lists, administration, etc. - the UDP port is given to it from the position system, which generates it as follows:)
sockaddr_in service1;
service1.sin_family = AF_INET;
service1.sin_addr.s_addr = INADDR_ANY;
service1.sin_port = htons(0);

server_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

mode = 1;
ioctlsocket(server_sock, FIONBIO, &mode);

soreuse = 1;
ioctlsocket(server_sock, SO_REUSEADDR, &soreuse);

sockaddr_in sin;
socklen_t len = sizeof(sin);
getsockname(server_sock, (sockaddr*)&sin, &len);
udpport = sin.sin_port; //the value of UDP port here is what's given to the client, and ultimately, the server

The sending portion of the server is this:
sockaddr_in addr;
int sz = sizeof(addr);
char* buff = new char[1024];
int recvdf = recvfrom(gp->data_socket,buff,1024,NULL,(sockaddr*)&addr,&sz);
if (recvdf > 0) {
    cout << "got packet with size " << recvdf  << " on port " << addr.sin_port << endl;
    unsigned sz = gp->users.size();
    for (unsigned i = 0; i < sz; i++) {
        sendto(gp->data_socket, buff, recvdf, NULL, (sockaddr*)&gp->users[i].addr, sizeof(gp->users[i].addr));
    }
}
delete[] buff;
Sleep(1);

Finally, the interaction on the client side is this:
char* buffer = new char[1024];
int recvd = recvfrom(server_sock, buffer, 1024, NULL, (sockaddr*)&server_addr, &sockaddrsize);
if (recvd > 0) {
    int i = 282;
}
delete[] buffer;
sendto(server_sock, "test\0", 5, NULL, (sockaddr*)&server_addr, sockaddrsize);

Any suggestions to get it working? (The useless variable declared was used as a breakpoint in Visual Studio.)

A: Very likely your client is protected by a firewall that is blocking the incoming UDP packets from the Internet.  To get around that, you can either instruct the client's sysadmin to manually open up a hole in the firewall for incoming UDP on the port your server is sending the packets to (and if a NAT is involved, they'll need to set up port-forwarding on the NAT as well), or you can investigate UDP hole-punching techniques.
Neither of the above techniques is particularly elegant or robust, though, so you might just want to have a fall-back mode for your software where all data is delivered via TCP stream.  Performance won't be quite as good, but sometimes it is better to have it "just work", and TCP will allow that.

A: First of all, your wording is very confusing: "UDP server" "viewer" "client" "the system" "the position system" ... . You wrote "I currently have it coded to echo every message sent to it back to the sender, for testing." However your "client" code only replies with a fixed string "test\0".
When you have any doubts, you should write a minimal test code separate from your main project.
I assume the "viewer" is the "client."
You wrote

The sending portion of the server is this:

int recvdf = recvfrom(gp->data_socket, ... );
for (unsigned i = 0; i < sz; i++) {
    sendto(gp->data_socket, ..., (sockaddr*)&gp->users[i].addr ... );
}

Finally, the interaction on the client side is this:

int recvd = recvfrom(server_sock, ... );
sendto(server_sock, "test\0", ... (sockaddr*)&server_addr, ... );

But you also replied to @Jeremy

I was afraid of that, however, isn't the firewall traditionally supposed to allow data receipt on a port it sent from?

There's a contradiction between these two.  Your server first send UDP datagrams to the clients and then the clients response back.  The first packet between your server and clients is sent from the server.  That's what I understood from your code.  You already knew this isn't going to work with typical firewalls.
Although @Jeremy is right in that each firewall is configured differently, most (home use) firewalls satisfy your assumption.  I suspect your code just doesn't utilize such a typical behavior of common firewalls.  If your "client" side can use, for example, Windows internet time synchronization which is in fact a UDP SNTP client and sends UDP datagram from an ephemeral source port to the time server, you should be able to receive UDP datagrams from your server as well.


text:
Q: I know how to do it with K Maps but how to solve it without using them Let X=X1X0 and Y=Y1Y0 be unsigned 2-bit numbers. The output function F = 1 if X is
equal to or less than Y and F = 0 otherwise. Find the minimized expression for F?

A: This question looks like homework, so I'll nudge you in the right direction.
Write down all the cases for which \$F = 1\$ as products of \$X_1\$, \$X_0\$, \$Y_1\$ and \$Y_0\$ and add them together. For example, if \$X_1=X_0=Y_1=Y_0=0\$, then \$F=1\$, hence \$\overline{X}_1\overline{X}_0\overline{Y}_1\overline{Y}_0\$ is one of your terms.
Alternatively, you can add all the cases for which \$F=0\$, negate the whole expression and use De Morgan's law to rewrite it as a product of sums, but this only makes sense if you have considerably less cases where \$F=0\$.
After you find your direct expression, simplify it.


text:
Q: FastAPI: datetime with timezone in request doesn't work from fastapi import FastAPI
from datetime import datetime
from ..models import Contact
from ..database import Database

app = FastAPI()

# Dependency
def get_db():
    db = Database()
    try:
        yield db
    finally:
        db.disconnect()

@app.get("/contacts/", response_model=List[Contact])
async def get_contacts(address: int, start_time: datetime, end_time: datetime, duration: int, distance: int, db: Database = Depends(get_db)):
    contacts = detect_contacts(db, address, start_time, end_time, duration, distance)
    return contacts

I'm trying to get query parameters start_time and end_time as datetime values with timezone, based on ISO 8601 or RFC 3339.
It works fine without timezone, for example, "2021-01-19 16:00:00" or "2021-01-19T16:00:00", but not with timezone, for example, "2021-01-19 16:00:00+05:00" or "2021-01-19T16:00:00+05:00", returning such error:
{
    "detail": [
        {
            "loc": [
                "query",
                "start_time"
            ],
            "msg": "invalid datetime format",
            "type": "value_error.datetime"
        }
    ]
}

FYI, it's explicitly mentioned in the documentation that it supports ISO 8601 format for datetime.datetime type:
Extra Data Type - FastAPI

A: Seeing the comments above it looks like alex_noname might have gotten to the heart of the issue. He has shown how the ISO string should be encoded to be safely sent within a query parameter.
The + sign used for the timezone is a reserved character that should be encoded in a url, otherwise it might be interpreted in another way, often as a space: e.g. if you google "datetime not working" the url of the result will look like google.com/search?q=datetime+not+working.
This is likely what is causing issues with the timezone. You can try to print to the terminal the parameter to check if it's decoded properly, you might see a space in place of the plus sign.


text:
Q: Google Cloud Kubernetes external autoscale I need to create a custom autoscaler in Google Cloud Kubernetes Engine.
I develope a software that write time series data to a custom metric in Google Cloud Monitoring and I want that Kubernetes autoscaler uses this data to manage the number of replicas.
I read a lot of documentation but I have a lot of doubts:

*

*Is mandatory to deploy the custom metrics stackdriver adapter? If yes, why?

*Which is the difference between "target total value" and "target average value" and how they work?

*I saw that is possible to create more than one metric, how autoscaler works with 2 or more metrics?


text:
Q: CSS: How to prevent two elements from overlapping when the browser is resized? Note: I know this question has been asked a ton of times before, but none of the solutions to those questions worked for me. Bear in mind I'm pretty inexperienced when it comes to front-end work.
When my browser is downsized, the block on the right -- #client-body -- moves towards and overlaps the #client-toolbar block.
How do I make it so that when my browser is resized, all nothing actually changes position, and instead scroll bars appear?
CSS:
html {
    background-color: #E6E6E6;
    color: #1A1A1A;
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
}

#nav {
    background-color: #290052;
    width: 100%;
    font-family: Arial;
    height: 50px;
    position: relative;
}

#nav ul {
    padding: 0;
    margin: auto;
    position: relative;
}

#nav ul li {
    display: inline-block;
    margin-right: 15px;
    float: right;
}

#nav ul li a {
    color: #ffffff;
}

#nav ul li a,visited {
    color: #ffffff;
    display: block;
    padding: 15px;
    text-decoration: none;
}

#client-body {
    display: block;
    height: 700px;
    width: 750px;
    background-color: #ffffff;
    position: relative;
    margin-right: auto;
    margin-left: auto;
    margin-top: 50px;
    margin-bottom: auto;
    padding: none;
}

#client-toolbar {
    display: block;
    height: 700px;
    width: 250px;
    background-color: #ffffff;
    position: relative;
    margin-left: 150px;
    float: left;
    margin-top: -700px;
}

#client-toolbar ul {
    list-style-type: none;
}

#client-toolbar a {
    font-family: Arial;
    color: #313131;
}

#client-toolbar #track-time {
    height: 233.333px;
}

#client-toolbar #edit-client{
    height: 233.333px;
}

#client-toolbar #add-project {
    height: 233.333px;
}

#footer {
    width:100%;
    height:30px;
    position:absolute;
    bottom:0;
    left:0;
    clear: both;
    margin-left: 25px;
}

#footer ul {
    list-style-type: none;
    padding: none;
}

#footer ul a {
    padding: 5px;
    font-family: Arial;
}

#footer ul li {
    display: inline;
}

.center_hero-unit {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
}

.btn-su {
    display: inline-block;
    height: 60px;
    width: 200px;
    background: #005CE6;

    color: #ffffff;
    font-family: Arial, sans-serif;
    text-decoration: none;
    vertical-align: middle;
}

(Client) index.html.erb:

<%= link_to "Track time", '#' %>

<%= link_to "Add client", '#' %>

<%= link_to "Add project", '#' %>

HTML header:

        <% if signed_in? %>

<%= link_to "Sign out", signout_path, method: "delete" %>

<%= link_to "Settings", edit_user_path(current_user) %>

<%= link_to "Clients", clients_path %>

<%= link_to "Projects", projects_path %>

<%= link_to "Home", projects_path %>

        <% else %>

<%= link_to "Home", root_path %>

<%= link_to "Sign in", signin_path %>

        <% end %>

HTML footer:

<%= link_to "Support",   '#' %>

<%= link_to "More", '#' %>

Main HTML file:
<!DOCTYPE html>

    <title>Time Tracking App</title>
    <%= stylesheet_link_tag "custom", media: "all",
                                           "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>

    <%= render 'layouts/header' %>
    <%= yield %>
    <%= render 'layouts/footer' %>


text:
Q: Is it possible to switch the value of a css property using an if statement in styled-components? I'm trying to display a label that says "required" or "optional" at the end of a tag using the CSS after selector. My idea is to look like this.

I'm using React.js and the styled-components library, so I take props.required as an argument, "required" when {props.required == true}, "required" when {props.required == false} I tried to switch the display, such as "optional".
// form.js
<FormTitle required={true}>Name</FormTitle>
<FormTitle required={false}>Phone Number</FormTitle>

// styles.js
import styled from 'styled-components'
const FormTitle = styled.div`
  ...
  &:after {
    content: ${props => props.required ? "required": "optional"};
    background-color: ${props => props.required ? "#FF0101": "#6FC173"};
    ...
  }
`

But when I do this, the label does not appear.

Apparently, switching the content property of CSS with the if the statement of javascript causes a problem. Because if you don't use an if statement for the content property, everything else works.
  ...
  &:after {
    content: "required";
    background-color: ${props => props.required ? "#FF0101": "#6FC173"};
    ...
  }
`

Is there a way to solve this?

A: The content property expects the value to be wrapped by quotes. Wrap the expression with standard quotes:
const FormTitle = styled.div`
  ::after {
    content: '${props => props.required ? "required": "optional"}';
    background-color: ${props => props.required ? "#FF0101": "#6FC173"};
  }
`

Another option is to use the styled component .attrs() to set a data attribute on the element, and then you use the attribute's value as the content of the pseudo element (::after):
const FormTitle = styled.div.attrs(props => ({
  'data-required': props.required ? 'required': 'optional',
}))`
  &::after {
    content: attr(data-required);
    background-color: ${props => props.required ? "#FF0101": "#6FC173"};
  }
`

Examples - Sandbox


text:
Q: Add new partition to LUKS+LVM I have the second half of my hard drive encrypted. Now I want to encrypt the first half as well. Being the second partition I can't extend the LUKS partition. Can I add the first partition to the existing LUKS or do I have to set another LUKS for this one partition?

A: You'll need to create another LUKS container.
Your LVM volume group can span both LUKS containers. You'd simply create an LVM physical volume in the LUKS container and add it to the LVM volume group. However, that means both LUKS containers would need to be unlocked before you can bring up the LVM volume group.


text:
Q: Dataframe groupby to get stints I have a new code I'm trying to write where a dataframe gets filtered/edited to obtain "stints" for each individual. Using the dataframe below as an example, I'm basically trying to get each persons start/end dates for a given location. Usually I can get started on my own but I'm stumped as to how to approach this so if anyone has ideas I would greatly appreciate it.

Person
Location
Date

0
Tom
A
1/1/2021

1
Tom
A
1/2/2021

2
Tom
A
1/3/2021

3
Tom
B
1/4/2021

4
Tom
B
1/5/2021

5
Tom
B
1/6/2021

6
Tom
A
1/7/2021

7
Tom
A
1/8/2021

8
Tom
A
1/9/2021

9
Tom
C
1/10/2021

10
Tom
C
1/11/2021

11
Tom
A
1/12/2021

12
Tom
A
1/13/2021

13
Tom
B
1/14/2021

14
Tom
B
1/15/2021

15
Mark
A
1/1/2021

16
Mark
A
1/2/2021

17
Mark
B
1/3/2021

18
Mark
B
1/4/2021

19
Mark
A
1/5/2021

20
Mark
A
1/6/2021

21
Mark
C
1/7/2021

22
Mark
C
1/8/2021

23
Mark
C
1/9/2021

24
Mark
C
1/10/2021

25
Mark
A
1/11/2021

26
Mark
A
1/12/2021

27
Mark
B
1/13/2021

28
Mark
B
1/14/2021

29
Mark
B
1/15/2021

Expected outcome:

Person
Location
StintNum
Start_Date
End Date

0
Tom
A
1
1/1/2021
1/3/2021

1
Tom
B
2
1/4/2021
1/6/2021

2
Tom
A
3
1/7/2021
1/9/2021

3
Tom
C
4
1/10/2021
1/11/2021

4
Tom
A
5
1/12/2021
1/13/2021

5
Tom
B
6
1/14/2021
1/15/2021

6
Mark
A
1
1/1/2021
1/2/2021

7
Mark
B
2
1/3/2021
1/4/2021

8
Mark
A
3
1/5/2021
1/6/2021

9
Mark
C
4
1/7/2021
1/10/2021

10
Mark
A
5
1/11/2021
1/12/2021

11
Mark
B
6
1/13/2021
1/15/2021

A: IMO, a clean way is to use groupby+agg, this enables to set custom aggregators easily and is faster than apply:
df['Date'] = pd.to_datetime(df['Date'])

group = df['Location'].ne(df['Location'].shift()).cumsum()

df2 = (
 df.groupby(['Person', group], as_index=False)
   .agg(Location=('Location', 'first'),
        # line below is a dummy function to set a column placeholder
        # uncomment it you want the columns in order
        #StintNum=('Location', lambda x: float('NaN')),
        Start_Date=('Date', 'min'),
        End_Date=('Date', 'max'),
       )
)

df2['StintNum'] = df2.groupby('Person').cumcount().add(1)

Output:
   Person Location  StintNum Start_Date   End_Date
0    Mark        A         1 2021-01-01 2021-01-02
1    Mark        B         2 2021-01-03 2021-01-04
2    Mark        A         3 2021-01-05 2021-01-06
3    Mark        C         4 2021-01-07 2021-01-10
4    Mark        A         5 2021-01-11 2021-01-12
5    Mark        B         6 2021-01-13 2021-01-15
6     Tom        A         1 2021-01-01 2021-01-03
7     Tom        B         2 2021-01-04 2021-01-06
8     Tom        A         3 2021-01-07 2021-01-09
9     Tom        C         4 2021-01-10 2021-01-11
10    Tom        A         5 2021-01-12 2021-01-13
11    Tom        B         6 2021-01-14 2021-01-15

A: Try this:
df['Date'] = pd.to_datetime(df['Date'])
new_df = df.groupby([df['Person'], df['Location'].ne(df['Location'].shift(1)).cumsum()], sort=False).apply(lambda x: pd.Series([x['Date'].min(), x['Date'].max()], index=['Start_Date','End_Date'])).reset_index()
new_df['StintNum'] = new_df.groupby('Person').cumcount().add(1)

Output:
>>> new_df
   Person  Location Start_Date   End_Date  StintNum
0     Tom         1 2021-01-01 2021-01-03         1
1     Tom         2 2021-01-04 2021-01-06         2
2     Tom         3 2021-01-07 2021-01-09         3
3     Tom         4 2021-01-10 2021-01-11         4
4     Tom         5 2021-01-12 2021-01-13         5
5     Tom         6 2021-01-14 2021-01-15         6
6    Mark         7 2021-01-01 2021-01-02         1
7    Mark         8 2021-01-03 2021-01-04         2
8    Mark         9 2021-01-05 2021-01-06         3
9    Mark        10 2021-01-07 2021-01-10         4
10   Mark        11 2021-01-11 2021-01-12         5
11   Mark        12 2021-01-13 2021-01-15         6

A: def function1(dd:pd.DataFrame):
    dd1=dd.groupby(["Person","Location"],as_index=False).agg(StintNum=("col1","first"),Start_Date=("Date",min),End_Date=("Date",max))
    return dd1

col1=df1.groupby("Person",group_keys=False).apply(lambda dd:dd.Location.ne(dd.Location.shift()).cumsum())

df1.assign(col1=col1).groupby(["Person","col1"],sort=False).apply(function1).reset_index(drop=True)

output:
  Person Location  StintNum Start_Date   End_Date
0     Tom        A         1   1/1/2021   1/3/2021
1     Tom        B         2   1/4/2021   1/6/2021
2     Tom        A         3   1/7/2021   1/9/2021
3     Tom        C         4  1/10/2021  1/11/2021
4     Tom        A         5  1/12/2021  1/13/2021
5     Tom        B         6  1/14/2021  1/15/2021
6    Mark        A         1   1/1/2021   1/2/2021
7    Mark        B         2   1/3/2021   1/4/2021
8    Mark        A         3   1/5/2021   1/6/2021
9    Mark        C         4  1/10/2021   1/9/2021
10   Mark        A         5  1/11/2021  1/12/2021
11   Mark        B         6  1/13/2021  1/15/2021


text:
Q: Why can't I force users to login to download a zip file from my website? I have a directory which contains a zip file and a pptx (PowerPoint) file. In the directory is this .htaccess (regex?) code:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.me.uk/ [NC]
RewriteCond %{REQUEST_URI} !hotlink.(pptx|ppt|pdf|zip|7z|rar|xls|xlsx|doc|docx) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*.(pptx|ppt|pdf)$ http://mydomain.me.uk/  [NC]

When a user puts in the direct URL for pptx file, they are correctly served a 404 unless they are logged in. For zip and 7z (7zip) files they can still download those files without being logged in, even though those file extensions are correctly listed (to block) in my .htaccess code.
Why doesn't this code work for archived files?

A: This might be completely stupid, but maybe it has something to do with HTTP compression. Try disabling mod_deflate, restart apache, and see if it works then. This is just a hunch though and might have nothing to do with it.

A: Well I'm here to answer my own question!
There were two things wrong with my original code:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.me.uk/ [NC]
RewriteCond %{REQUEST_URI} !hotlink.(pptx|ppt|pdf|zip|7z|rar|xls|xlsx|doc|docx) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*.(pptx|ppt|pdf)$ http://mydomain.me.uk/  [NC]

The final line neglected to mention all of the file formats I wanted to suppress although this was all referenced correctly on line 3 (my code was incomplete!)
In addition to this as afdggfh said: I needed to suppress gzip compression in the specified folder.
As such I came up with much more robust code instead:
RewriteEngine On
RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.me.uk/ [NC]
RewriteCond %{REQUEST_URI} !hotlink.(pptx|ppt|pdf|zip|7z|rar|xls|xlsx|doc|docx) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*.(pptx|ppt|pdf|zip|7z|rar|xls|xlsx|doc|docx)$ http://mydomain.me.uk/  [NC]

Above is the code that works!


text:
Q: Changing order of documents in mongoose I am fooling around with databases for the first time using mongoose.js, but I can't figure out something that to me seems like pretty basic functionality.
I want to put a specific document one position up in the database, to update the order in which the documents are loaded when I fetch them all.
I can't find some build-in method for this except for maybe .sort(), but that would mean I have to keep track of the indexes of each instance, change them accordingly when I want to change the order and then sort the database based on that new property, this seems like reinventing the wheel to me.
Am i simply overlooking some basic concept about databases and am I not supposed to do this? Or am I missing the function I'm looking for?

A: MongoDB doesn't provide any ability to explicitly modify the natural order of the documents in a collection and may move docs around in the collection as they are updated.
If you want your docs returned in a specific order, the docs must contain a field you can sort on to put them in that order.  For the sort to be performant, you typically need to also create an index on that field.

A: You can use a bypass to achieve
this behavior:
Let say you have chat rooms and you want the room who was the latest to be updated will be at the top of the list.
You can create a wrapper Document which will contain array of room sub documents
let RoomsSchema = Schema({
   isActive: { type: Boolean },
   name: { type: String, required: true },
   ownerId:{type: String},
   participants: { type: Array },
   messages: [MessageSchema],
   updateTime: { type: Date },
   creationTime: { type: Date },
}, { versionKey: false });

let MainDoc = Schema({
   rooms:[RoomsSchema]
});

Then let say you'll have a schema function to add message, something as follows:
MainDoc.statics.ADD_Message = async function (roomId, message) {
    let main = await this.findOne({});
    let room = await main.rooms.id(roomId);
    room.messages.push(message);
    let roomIdx = main.rooms.findIndex(x => x._id == room._id);

    if (roomIdx > -1) {
        main.rooms.splice(roomIdx, 1);
        main.rooms=[room,...main.rooms];
     }
     return main.save();
};


text:
Q: PHP array_unique() - do some logic first before reducing the array I have this array data:
array:3 [
  0 => array:5 [
    "menu_id" => 7
    "menu_name" => "Kasagbutan Meals"
    "menu_price" => "100.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
  1 => array:5 [
    "menu_id" => 7
    "menu_name" => "Kasagbutan Meals"
    "menu_price" => "100.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
  2 => array:5 [
    "menu_id" => 6
    "menu_name" => "Coke"
    "menu_price" => "50.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
]

When I ran it with array_unique(), the data becomes like this:
array:2 [
  0 => array:5 [
    "menu_id" => 7
    "menu_name" => "Kasagbutan Meals"
    "menu_price" => "100.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
  2 => array:5 [
    "menu_id" => 6
    "menu_name" => "Coke"
    "menu_price" => "50.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
]

How can I add the qty before it reduces the array? I want to add the qty of the removed array item. So basically, the ideal array result should be like this:
array:2 [
  0 => array:5 [
    "menu_id" => 7
    "menu_name" => "Kasagbutan Meals"
    "menu_price" => "100.00"
    "qty" => "2" ----> THIS BECOMES 2 BECAUSE THE OTHER ITEM HAS A QTY OF 1.
    "special_instructions" => ""
  ]
  2 => array:5 [
    "menu_id" => 6
    "menu_name" => "Coke"
    "menu_price" => "50.00"
    "qty" => "1"
    "special_instructions" => ""
  ]
]

A: array_unique() is simply a reduce operation. What you want is a slightly more complex one so use array_reduce()
$exclude = array_flip(['qty']); // list of properties to exclude when creating a hash

$totals = array_reduce($arr, function($totals, $item) use ($exclude) {
    $id = array_diff_key($item, $exclude);
    ksort($id); // sort by key to always get the same order
    $hash = crc32(json_encode($id));
    if (array_key_exists($hash, $totals)) {
        $totals[$hash]['qty'] += $item['qty'];
    } else {
        $totals[$hash] = $item;
    }
    return $totals;
}, []);

This builds up a new array keyed by a hash of identifying values (everything except for qty) that, upon finding an entry it already knows about, increases the qty.
I've gone with a CRC32 hash of the JSON encoded string for speed. You can use just about any hashing / serialization combo though.
Demo ~ https://3v4l.org/YDsfc
Special nods to the following posts:

*

*PHP best way to MD5 multi-dimensional array?

*Return all array elements except for a given key


text:
Q: Sitecore Intranet Login ReturnUrl=%2fDefault.aspx My Sitecore Intranet Portal used to work fine, and i haven't done any changes to my site in days, but suddenly when i try to go to my frontpage i will get a blank "Untitled Page" at this location:
"/forms/IntranetLogin.aspx?ReturnUrl=%2fDefault.aspx"

Anyone know what could be causing this?

A: Can you check if you have presentation information on your home item? Also, do you see this "Default page" right on the page with URL you supplied, or you are redirected to another page?

A: If you haven't made any changes to your content or Sitecore configuration, was there perhaps a Windows Update that fouled things up? Double check that ASP.NET is properly configured and enabled. What version of IIS are you running on?

A: The problem was caused by our Intranet not being able to connect to the LDAP database (our database with users). Someone changed the password to the database without telling, we changed it now and it works perfectly.


text:
Q: Meaning of "Jacobian determinant"? In his book on optimal control, George Leitmann uses a meaning of "Jacobian determinant" I don't understand (and I do understand the standard definition). Can anyone explain it? In particular, which function's Jacobian is being taken? (Also, why? I understand this why bit might be hard without more context.) The relevant excerpts from the book are, in order:
http://imgur.com/2vKMmkF,2WDQM91#0
http://imgur.com/2vKMmkF,2WDQM91#1
(Unfortunately, I don't have access to "Ref 6.1").
EDIT: I'm not requiring a firm answer like "This is definitely what it means." Even conjecture is fine.

A: This so called Jacobian determinant is simply the Wronskian (up to a transposition). Why he has chosen to use that particular language, i'm not sure.

A: In the determinant symbol,
$g_{\alpha}$ is the partial derivative of the function with respect to $\alpha$ and $g_{t\alpha}$ is the partial derivative with respect to $t$ of the function $g_{\alpha}$ and similarly for $\beta$. The determinant has the value
$$ g_{\alpha}g_{t\beta} - g_{\beta}g_{t\alpha} $$.
So $g_{t\beta}$ for example, really means
$$ \frac{\partial^{2}g}{{\partial t}{\partial \beta}} $$


text:
Q: How should I be learning deep learning? This might be quite a broad question, but I was wondering if I could leverage the wisdom of the people on this site.
So I have recently started to learn about deep learning. I have written a simple feedforward network from scratch, learnt how to code up MLPs, and CNNs using various kinds of regularization techniques in Tensorflow.
I have started to read papers, and this was when it occurred to me that there is still so much to learn and I'm a bit overwhelmed by how much there is.
Furthermore, while studying RMBs I read that they are hardly used today for pre-training but rather batch normalization is used, so I don't want to be studying something that is already out of date!
As I am self-studying are there any suggestions as to what areas of deep learning that should take priority after MLPs, CNNs and RMBs? Or this question is too hard to answer, I guess the next best question is how would you study deep learning if you could do it again?

A: A good place to start is this book, you can download it online.
Quick recap and starting points:

*

*If you're looking for image processing, CNN are a great choice and it seems you already played with it.

*For speech recognition - you can take a look at RNN (recurrent neural networks). Basically you can use them for images and videos too. And (sic!) you can use CNN to process audio (especially if it's preprocessed with FFT to get a 2D spectrum)

*NLP utilizes RNN as well. In order to extract features, you might take a look at Word2Vec. Additionally, encoder-decoder architecture is being used for machine translation.

*(Active research, not for production) for statistical inference and unsupervised learning (anomaly detection etc.) - you might take a look at auto-encoders and RBMs. Autoencoders are particularly used as an alternative for Factor Analysis: Factor Analysis vs Autoencoders

*Deep learning helps with reinforcement learning too: https://www.cs.toronto.edu/~vmnih/docs/dqn.pdf

*Recommender Systems use deep-learning as well.

TensorFlow models (they are usually state-of-the-art): https://github.com/tensorflow/models
Small collection of Java-examples to complement those from TensorFlow: https://github.com/deeplearning4j/dl4j-examples

A: Deep learning is quite of broad topic. I can not say that you can not learn everything ( human capabilities are unlimited ) but working in every field is little difficult.
As far as I can see you have grasped all the basic concepts so its time to choose a field where you want to apply your knowledge or do more research.
If you want to work choose a  field where you want to apply your knowledge and learn with it. Natural Language Processing , Image processing , Object recognition, Audio signal Processing and many more fields are there. Choose a field and build something useful.
If you want to read more and do research, new experiments/research are being done daily. You can improve them or can develop your new concept. GAN ( Generative Adversarial Networks ), using Reinforcement learning with Deep learning, deep dream (Inceptionism: Going Deeper into Neural Networks ), Generative context aware encoder decoder and many more new things are there.


text:
Q: is there a shortcut to delete spaces and tabs around a point in zsh In emacs, there is this shortcut
M-\
Delete spaces and tabs around point (delete-horizontal-space).

https://www.gnu.org/software/emacs/manual/html_node/emacs/Deletion.html
it also works in bash. I wonder if there is an equivalent in zsh, or how to define one, please?

A: I don't think there is, but you can always write it yourself as:
delete-horizontal-space() {
  emulate -L zsh
  set -o extendedglob
  LBUFFER=${LBUFFER%%[[:blank:]]##}
  RBUFFER=${RBUFFER##[[:blank:]]##}
}

zle -N delete-horizontal-space
bindkey '\e\\' delete-horizontal-space


text:
Q: how to query by values in MongoDB My collection looks like:
{
"_id" : ObjectId("520c8976586f12c80900301d"),
"IDENTITY" : "ae4ff1546ecfe6ce6e8ebb2d870d57fb",
"NAME" : "Winmain Yao",
"TYPE" : "COMPANY",
"PUBLIC" : 1,
"BACKGROUND" : null,
"CONTACT" : {
  "PHONE" : {
    "WORK" : "18630283895",
    "HOME" : "188837283"
},
"EMAIL" : {
  "DEFAULT00001" : "zxwinmain@gmail.com"
},
"IM" : [],
"SITE" : [],
"ADDRESS" : [],
"SOCIAL" : []
},
"RELATION" : {
  "ACCOUNT" : "16713a29767fa4e8f139dfb249900c07",
  "USER" : "84a9e7a8e5f3a13d411cfa8ff4a62a50"
},
"CREATED" : 1376553334,
"UPDATED" : 0,
"DELETED" : 0
}

Now I want to get the customer who's phone = 18630283895, how can I do that?
Thanks a lot.

A: The following:
"PHONE" : {
    "WORK" : "18630283895",
    "HOME" : "188837283"
},

Is the wrong approach. As you invariably will have further types of phone numbers, you have ended up with a "key that is actually a value". This makes it difficult to query (and index). The better approach to this is:
"PHONE" : [
    { type: "WORK", number: "18630283895" },
    { type: "HOME", number: "188837283" },
],

Then you can very easily index it with:
db.collection.ensureIndex( { "PHONE.number": 1 } );

And query for numbers with:
db.collection.find( { "PHONE.number" : "18630283895" } );


text:
Q: How to change widget preview image programmatically I have widget witch changes it's icon according to settings. It's working for widget icon but I don't know if it possible to do for previewImage.
Is it possible to change widget preview image programmatically?

A: I believe it is impossible for appwidgets. Only xml resources are accepted:
https://developer.android.com/guide/topics/appwidgets/index.html#preview
but you may want to try different drawable sizes:
http://developer.android.com/guide/practices/screens_support.html#range


text:
Q: Very slow query performance in aws postgresql for a table with 4 billion rows The Problem
We have a relational table where we store user activity. A query like the following takes 77 seconds!
FROM "site_activity"
WHERE
    (
        NOT "site_activity"."is_deleted"
        AND "site_activity"."user_id" = 68812389
        AND NOT (
            "site_activity"."kind" IN (
                'updated',
                'duplicated',
                'reapplied'
            )
        )
        AND NOT (
            "site_activity"."content_type_id" = 14
            AND "site_activity"."kind" = 'created'
        )
    )
ORDER BY
    "site_activity"."created_at" DESC,
    "site_activity"."id" DESC
LIMIT  9;

The query plan looks like this
                                     QUERY PLAN
--------------------------------------------------------------------------------------------
Limit
    (cost=17750.72..27225.75 rows=9 width=16)
    (actual time=199501.336..199501.338 rows=9 loops=1)
  Output: id, created_at
  Buffers: shared hit=4502362 read=693523 written=37273
  I/O Timings: read=190288.205 write=446.870
  ->  Incremental Sort
      (cost=17750.72..2003433582.97 rows=1902974 width=16)
      (actual time=199501.335..199501.336 rows=9 loops=1)
        Output: id, created_at
        Sort Key: site_activity.created_at DESC, site_activity.id DESC
        Presorted Key: site_activity.created_at
        Full-sort Groups: 1  Sort Method: quicksort  Average Memory: 25kB  Peak Memory: 25kB
        Buffers: shared hit=4502362 read=693523 written=37273
        I/O Timings: read=190288.205 write=446.870
        ->  Index Scan Backward using site_activity_created_at_company_id_idx on public.site_activity
            (cost=0.58..2003345645.30 rows=1902974 width=16)
            (actual time=198971.283..199501.285 rows=10 loops=1)
              Output: id, created_at
              Filter: (
                (NOT site_activity.is_deleted) AND (site_activity.user_id = 68812389)
                AND ((site_activity.kind)::text <> ALL ('{updated,duplicated,reapplied}'::text[]))
                AND ((site_activity.content_type_id <> 14) OR ((site_activity.kind)::text <> 'created'::text))
              )
              Rows Removed by Filter: 14735308
              Buffers: shared hit=4502353 read=693523 written=37273
              I/O Timings: read=190288.205 write=446.870
Settings: effective_cache_size = '261200880kB',
          effective_io_concurrency = '400',
          jit = 'off',
          max_parallel_workers = '24',
          random_page_cost = '1.5',
          work_mem = '64MB'
Planning:
  Buffers: shared hit=344
Planning Time: 6.429 ms
Execution Time: 199501.365 ms
(22 rows)

Time: 199691.997 ms (03:19.692)

Table Facts

*

*It contains a little more than 4 billion rows.

*The table structure is
                                            Table "public.site_activity"
    Column      |           Type           | Collation | Nullable |                   Default
----------------+--------------------------+-----------+----------+----------------------------------------------
id              | bigint                   |           | not null | nextval('site_activity_id_seq'::regclass)
created_at      | timestamp with time zone |           | not null |
modified_at     | timestamp with time zone |           | not null |
is_deleted      | boolean                  |           | not null |
object_id       | bigint                   |           | not null |
kind            | character varying(32)    |           | not null |
context         | text                     |           | not null |
company_id      | integer                  |           | not null |
content_type_id | integer                  |           | not null |
user_id         | integer                  |           |          |
Indexes:
    "site_activity_pkey" PRIMARY KEY, btree (id)
    "site_activity_modified_at_idx" btree (modified_at)
    "site_activity_company_id_idx" btree (company_id)
    "site_activity_created_at_company_id_idx" btree (created_at, company_id)
    "site_activity_object_id_idx" btree (object_id)
    "site_activity_content_type_id_idx" btree (content_type_id)
    "site_activity_kind_idx" btree (kind)
    "site_activity_kind_idx1" btree (kind varchar_pattern_ops)
    "site_activity_user_id_idx" btree (user_id)
Foreign-key constraints:
    "site_activity_company_id_fk_site_company_id" FOREIGN KEY (company_id)
        REFERENCES site_company(id) DEFERRABLE INITIALLY DEFERRED
    "site_activity_content_type_id_fk_django_co" FOREIGN KEY (content_type_id)
        REFERENCES django_content_type(id) DEFERRABLE INITIALLY DEFERRED
    "site_activity_user_id_fk_site_user_id" FOREIGN KEY (user_id)
        REFERENCES site_user(id) DEFERRABLE INITIALLY DEFERRED

a. kind is treated as an enum. In db we store it as varchar. But in the application (python) we treat it as enum. So the values are fixed. There are around 100 values in it.
b.content_type_id has around 80 values.

*This is the distribution of values,
a. context is actually JSON with a max 8Mb size.
a. 3 content_type_id values holds 92% of the rows. They are 14 and 19.
a. 3 kind consumes 75% rows. These are created, updated and sent.
a. The combination of kind and content_type_id creates 460 values. Among them, 1 combination contains 35% of rows and we exclude them in the query all time.

*The replica instance has type db.r5.12xlarge. 24 cores, 48 vCPUs, 384GB Mem, storage type io1.
Question

*

*How do we handle if the table grows to 100 billion? In the current projection, this can happen in the next 3-5 years.

*Is NoSQL a good solution? Note we are not accessing the documents with only id or kind.

Notes

*

*The facts that I presented might bias the solution to replication in the same host and then later sharding over multiple hosts. But if there is some other solution that can keep up to the 100 billion mark, we should be good.

*We don't have to use AWS. But preferred.

A: The current plan is to scan the rows already ordered by "created_at" (using an index) and then stop once it finds 10 (plus maybe a few rows to account for ties) passing the rest of of the conditions.  It thinks it will do this very quickly, after only about 1/73,000 of the table (27225.75 / 2003433582.97).  but in fact it had to scan much more than that (14735308 / 4000000000, or 1/270 of the table).  So it grossly misestimated that part.  I don't know if it misestimated it because the number of rows meeting the conditions was estimated incorrectly (It thought there would be 1902974, we don't know how many there actually were, since it stopped early and so stopped counting them) or because it assumed the matching rows would be evenly dispersed over the index, when they were not.
The best index for you will probably be on (user_id, created_at).  That way you get to jump to just the part of the index which has the correct user_id (which I assume is where the vast majority of your selectivity comes from) and then still walk that part already in order by "created_at".  And you can drop the original index just on (user_id), as the new one will be good for anything that the old one is good for.  You could also add "is_deleted" between the other two columns in that index, as it will not spoil the ordering property and will provide some additional selectivity (but probably not much).  Any other columns added there will spoil the ordering property, however.

A: Query
Start by formatting the WHERE clause to make it easier to understand. Comes down to:
FROM   site_activity s
WHERE  s.user_id = 68812389
AND    NOT s.is_deleted
AND    s.kind <> ALL ('{updated,duplicated,reapplied}'::text[])
AND    (content_type_id <> 14 OR kind <> 'created')
ORDER  BY s.created_at DESC, s.id DESC
LIMIT  9;

Index
Assuming you always exclude rows with the last 3 lines (your description seems to indicate as much, but it remains unclear), this partial, multicolumn index would be the optimum:
CREATE INDEX ON public.site_activity (user_id, created_at, id)
WHERE  NOT is_deleted
AND    kind <> ALL ('{updated,duplicated,reapplied}'::text[])
AND   (content_type_id <> 14 OR kind <> 'created')

Adding id only makes sense if there are many rows with the same (user_id, created_at). Else drop id from the index.
Excluding most rows pays for such big indexes. Also, Postgres does not have to estimate the selectivity of those WHERE clauses that match the WHERE clauses of the index, since it (more or less) knows how many rows qualify. The partial index will also help Postgres chose the optimal query plan.
The index only applies while all filters also are added to the query, obviously.
Table definition
It would pay to optimize your table definition. Like:
                              Table public.site_activity
    Column      |     Type     | Nullable |                   Default
----------------+--------------+----------+----------------------------------------------
id              | bigint       | not null | nextval('site_activity_id_seq'::regclass)
user_id         | int          | not null |  -- NOT NULL ??
kind            | smallint     | not null |  -- "around 100 values"
content_type_id | smallint     | not null |  -- "around 80 values"
created_at      | timestamptz  | not null |
modified_at     | timestamptz  | not null |
object_id       | bigint       | not null |
company_id      | int          | not null |
is_deleted      | bool         | not null |
context         | text         | not null |

Most importantly, kind now occupies 2 bytes instead of 33 bytes or more. See:

*

*What is the overhead for varchar(n)?
Plus substantial savings from rearranging the column order. See:

*

*Calculating and saving space in PostgreSQL
The big column context ("with a max 8Mb size") will typically be stored out-of-line in a TOAST table for most rows, so the tuples to work with shrink to half their size. This makes a difference for most operations.
And I suspect that some of your indexes may be expendable.

A: Try an index like this, it should cover all columns in your where conditions:
CREATE INDEX idx_stackoverflow ON site_activity (created_at DESC, user_id, is_deleted, kind, content_type_id);

The current index used, filters out almost 15 million records to get just 9 records. That's a huge waste of time.
Maybe you want to create this index concurrently, that could take some extra time but won't block other processes.


text:
Q: How to use Exchange 2010 cmdlet in batch file I can run Get-ActiveSyncDeviceAccessRule correctly in Exchange Management Shell directly.
(reference: http://technet.microsoft.com/en-us/library/dd776124.aspx)
Then I wrote a batch file as below, but I got CommandNotFoundException. I'd like to know how I can use this cmdlet with cmd.exe? Could anyone can help me? Thank you.
(Editor's note: The next three lines were wrapped for formatting. Originally 1 line)
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  Get-ActiveSyncDeviceAccessRule >C:\ActiveSyncDeviceAccessRule_output.txt
  2>C:\standardError.txt
echo %errorlevel% >C:\exitCode.txt

And I get error in standardError.txt as below:
The term 'Get-ActiveSyncDeviceAccessRule' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:31
+ Get-ActiveSyncDeviceAccessRule <<<<
    + CategoryInfo          : ObjectNotFound: (Get-ActiveSyncDeviceAccessRule:
   String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

A: (Answered by the OP in a question edit. Converted to a community Wiki Answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:

I've solved my problem. I missed some command to connect the Exchange server. And the cmdlet Get-ActiveSyncDeviceAccessRuleis belong to Exchange Server 2010 SP1. You can find the target command in the properties window of Exchange Management Shell.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ".
'C:\Program    Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1';
Connect-ExchangeServer -auto"

I updated my batch file as below. And it works.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ".
'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1';
Connect-ExchangeServer -auto;Get-ActiveSyncDeviceAccessRule"
>C:\ActiveSyncDeviceAccessRule_output.txt 2>C:\standardError.txt
echo %errorlevel% >C:\exitCode.txt


text:
Q: Kubernetes Ingress cannot fetch cluster ip of service I setup a kubernetes single node master plane with calico and haproxy. Now whenever I am going to create an Ingress, the address remains empty and the server returns a 503 error.
The following shows my kubernetes deployments.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: wordpress
          ports:
            - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: web-ingress
spec:
  rules:
    - host: wordpress.example.org
      http:
        paths:
          - path: /
            backend:
              serviceName: nginx-service
              servicePort: 8080

This is my output from the kubernetes cl.
NAME                             HOSTS                   ADDRESS   PORTS   AGE
ingress.extensions/web-ingress   wordpress.example.org             80      35s

NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP    10h
service/nginx-service   ClusterIP   10.97.189.233   <none>        8080/TCP   35s

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/nginx-deployment   1/1     1            1           35s

NAME                                    READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-7798df5dd5-gnwf2   1/1     Running   0          35s

NAME                      ENDPOINTS              AGE
endpoints/kubernetes      164.68.103.199:6443    10h
endpoints/nginx-service   192.168.104.150:8080   36s
Pascals-MBP-c8a4:api-gateway pascal$

I expect that the ingress will receive the cluster ip of the service and is listening on the given host uri and serving another information than the given 503 errors.
// Edit: Its a standalone node, not a desktop version or minikube installation!

A: The container port of this image was 80 and I exposed 8080.

A: The service default type is ClusterIP, but it is meant only for cluster-internal communication.
For external traffic you should switch to a NodePort type.
For example:
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP
      name: http
  selector:
    run: nginx

If I am not mistaken nginx alb controller allows using ClusterIP (or LoadBalancer).
More info here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types


text:
Q: How do you partition results weekly in SQL? I have to find the 3 highest spending customers from Customer (customer name, id) and order (order id, order amt, order date) for every week. If I run the query today, it should show the top 3 for all weeks for which order date exists.
I am thinking about doing a Partition by over the date (weekly), but I can't find any method to do that? Has anyone done a weekly partition of results?
I know it's not right, but this is what I have:
Select Top 3 customer_name, id OVER (partition by [week])
(
    Select c.customer_name, c.id, o.order_amt,
    from customer c
    Join Order o
        on c.id=o.id
    group by c.id
)

A: the query should be something like this
Select customer_name, id, order_amt, [week]
(
    Select c.customer_name, c.id, o.order_amt, [week],
           rn = row_number() over (partition by [week] order by o.order_amt desc)
    from customer c
    Join Order o
        on c.id=o.id
) d
where rn <= 3

A: According to your table structure, where orders.order_id is customer.id
use this statement
select
    *
from
(
    select
        details.*
        ,dense_rank() over (partition by week_num order by order_amt desc) as rank_num
    from
    (
        select
            c.id as customer_id
            ,c.name
            ,sum(o.order_amt) as order_amt
            ,datepart(WEEK,o.order_date) as week_num
        from customer c
        join orders o on c.id=o.order_id
        group by c.id,c.name,datepart(WEEK,o.order_date)
    )details

)dets
where dets.rank_num<=3

Updated : changed statement to use just 2 tables

A: this is an idea,
;WITH CTE
AS (
    SELECT c.customer_name
        ,c.id
        ,o.order_amt
        ,datepart(wk, datecol) AS Weekcol
    )
    ,CTE1
AS (
    SELECT c.customer_name
        ,c.id
        ,o.order_amt
        ,ROW_NUMBER() OVER (
            PARTITION BY Weekcol ORDER BY order_amt DESC
            ) AS rowNUm
    FROM CTE
    )
SELECT *
FROM CTE1
WHERE rowNUm <= 3


text:
Q: SQL query access pivot - error message 'field that has an invalid data type' I'm running an SQL Query on MS Access.
the query looks like this:
TRANSFORM MIN(X_VALUE*MULTIPLE & ' ' & Y_VALUE)
SELECT A.ID
FROM ((MY_TABLE_A A
       INNER JOIN MY_TABLE_B B ON B.ID = A.ID)
      INNER JOIN MY_TABLE_C C ON C.FOO1_ID = A.FOO1_ID)
LEFT JOIN MY_TABLE_D D ON A.FOO2_ID = D.FOO2_ID

WHERE A.NUM ='FOO'
AND A.FOO_ID<>0
AND FOO3=1
GROUP BY A.ID PIVOT X_NAME IN('BLAH1', 'BLAH2')

when running this against local MDB file, it works.
when running this against Linked MDB (tables are linked to remote Oracle DB), I'm getting

ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] The Microsoft
  Access database engine could not execute the SQL statement because it
  contains a field that has an invalid data type.

I've googled it, and couldn't find anything useful.
Any idea what can I do?
thanks.

A: The only statement in the query that even vaguely seems it would cause data type issues is the mixed types in the transform statement. Perhaps the following would work:
TRANSFORM MIN(CSTR(X_VALUE*MULTIPLE) & ' ' & CSTR(Y_VALUE))


text:
Q: Cannot access Jenkins I have installed Jenkins on my Ubuntu 12.04 desktop machine using this guide:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
I also needed to follow this guide:
http://aslamnajeebdeen.com/blog/how-to-fix-apache-could-not-reliably-determine-the-servers-fully-qualified-domain-name-using-127011-for-servername-error-on-ubuntu
From my other machine (mac laptop) I now try to access Jenkins through safari:
http://192.168.1.100/jenkins

where 192.168.1.100 is the ip address of my desktop machine but I get an Error 404. I have also tried:
http://jenkins

but nothing happens. What am I missing?
The Jenkins service is running on my desktop PC:
service jenkins status
...
Jenkins Continuous Integration Server is running with the pid 3713

And if I enter: localhost:8080 in a browser on my desktop pc I get the jenkins web interface.
PROBLEM SOLVED:
I have followed this guide:
http://www.zzorn.net/2009/11/setting-up-hudson-on-port-80-on-debian.html
and it now works.

A: I had the same problem but not using Apache, rather only Jenkins on Ubuntu
I solved it by replacing HTTP_HOST=127.0.0.1 with HTTP_HOST=0.0.0.0 on /etc/default/jenkins

A: Jenkins is set to listen on port 8080 by default,
so you should point your browser to:
http://localhost:8080/
(or, in your case: http://192.168.1.100:8080/ )
EDIT:
If still not able to connect, you may wish to check your firewall settings.


text:
Q: JavaScript not executing in .NET WebBrowser control Two friends of mine have tested a project I have been working on which relies on the use of the WebBrowser control, and have managed to come across a constant scenario in which the WebBrowser control is unable to execute any JavaScript on the contained web page.
For the sake of narrowing it down I created a new Windows Forms project that contains only a WebBrowser control, and tries to navigate to the following page: http://javatester.org/javascript.html
The result on my friends computer was the below (click to enlarge):

As you can see, it doesn't render ANYTHING when trying to call the JS specific code, alternatively if you view it in a web browser with JS disabled or enabled, you'll see something.
He exported his registry keys that contain the setting for JavaScript being enabled (see https://gist.github.com/4699943) and the value for 1400 in each of the keys matches the same settings I use, and when I run the program I have no issue.
The code for the entire test project is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            this.webBrowser1.Navigate("http://javatester.org/javascript.html");
        }
    }
}

If a new project is created using this code that targets the 4.5 framework (either on my machine or his) it works, however if one is created using 4.0 or lower the above result occurs. I'm not sure if this is a coincidence or if it is indeed something to do with the problem / solution.
It should be noted that if he navigates to this page in Internet Explorer there are no issues, it detects that JavaScript is enabled, this problem solely resides in this test application and the main project that it is a part of.
Any help would be appreciated, I've spent a good two months trying to figure this out and still can't.

A: From my tests WebBrowser with .NET 4 reports a web browser agent string of IE 7.0.  Therefore, check your JavaScript works correctly in IE7 first.

A: The scripts do not load if you are using the webbrowser control.Document Text property. It perfectly fine with the Navigate method. I need the document text property to work as i get html from third party. The same html content work perfectly fine if i create an html file out of it and open it in the regular IE browser. The webbrowser control is buggy.


text:
Q: Redis clients not being dropped by ASP.NET app, running on Azure We have a .NET 4.6.1 ASP.NET Web Forms app running on an Azure App Service. I say Web Forms, but the app also has Web Api 2 baked in, as well as two WebJob projects performing several tasks each.
We use StackExchange.Redis for caching. We also use Redis for SessionState. I mention this, because the problems began with a build up of Redis connections that would not die unless we restarted the ASP.NET app. We use the Lazy pattern for resharing the ConnectionMultiplexer. Local tests confirmed that the connection was indeed being shared within individual requests.

Reasonably confident with our Redis configuration, we started looking at metrics related to the ASP.NET app. The thread count mirrors our Redis client graphs. The thing is, I don't know what is normal when it comes to thread counts. But I would expect them to dispose/disappear/die over the course of a couple of days. Not build up.

We use Async/Await extensively, but we don't typically tackle threading directly. Last line may sound a little naive, sorry don't know how else to put it. We tend see our busiest times during the working day, with minimal activity over night.

We're at a loss, what are we doing wrong? Am I right, should we see the thread count drop with reduced activity on the site? Maybe I've already said something that you can point at and say "What the hell are you doing?", and that'd be great. What I'm really after though, is suggestions for what we might be responsible for this build up of threads and how we might manage it going forward.

Update 03/08
The thread chart in the second image, is being aggregated by SUM. If you change the aggregation to MIN, MAX, or AVG, you see a much more reasonable thread count that demonstrates threads being disposed of correctly. This is obviously a big relief for the web app.
I'm assuming, though my googling has not managed to confirm it, that the SUM indicates a total of threads created since the last app restart. If I'm correct in that assumption, the fact that the SUM of web app thread count matches the AVG Redis client count, confirms our original suspicion that not only is our Connection Multiplexer not sharing connections, they're not being closed off when the operation is finished.
This is our Redis class, which looks the same as the other 1000 examples on the interweb, at least as far as I can tell:
Imports System.Configuration
Imports StackExchange.Redis

Public Class RedisCache

    Private Shared ReadOnly Property LazyConnection As New Lazy(Of ConnectionMultiplexer)(Function()
            Dim cacheConnection = ConfigurationManager.AppSettings("CacheConnection")
            Dim multiplexer = ConnectionMultiplexer.Connect(cacheConnection.ToString())
            multiplexer.PreserveAsyncOrder = False

            Return multiplexer
        End Function)

    Public Shared ReadOnly Property Connection As ConnectionMultiplexer
        Get
            Return LazyConnection.Value
        End Get
    End Property

    Public Shared ReadOnly Property UseCache As Boolean
        Get
            Return ConfigurationManager.AppSettings("CacheConnection") IsNot Nothing
        End Get
    End Property

End Class

As I've already mentioned, we also use Redis for Session State, for which we have a very basic config:
<sessionState
    mode="Custom"
    customProvider="RedisSessionProvider"
    <providers>
        <add name="RedisSessionProvider"
            type="Microsoft.Web.Redis.RedisSessionStateProvider"
            port="6380"
            host="***"
            accessKey="***"
            applicationName="***"
            retryTimeoutInMilliseconds="5000"
            ssl="true"/>
    </providers>
</sessionState>

Does anyone have any ideas what is prolonging the life of these clients?

Update 03/08 Part Two
I've been thinking about how we can potentially narrow down the issue. Easiest place to start is with "is it Cache, Session or Redis as whole?" To that end, we're going to spin up an extra Redis server, which in the next release will have either the Cache or the Session State pointed at it. Hopefully one of those servers will exhibit the same behaviour that we're trying to fix, while the other behaves, umm, better. The former of the two would be where we focus our efforts.
One other little thing I've done, in our test environment, is to create a test property, that generates a new GUID, in the same way the Connection property works:
Private Shared ReadOnly Property LazyGuid As New Lazy(Of Guid)(Function() Guid.NewGuid())

Public Shared ReadOnly Property Guid As Guid
    Get
        Return LazyGuid.Value
    End Get
End Property

I've then created a few calls from various parts of the web app, to the new GUID property, as well as to the existing Redis code:
<Route("guid"), HttpGet>
Public Async Function GetGuid() As Task(Of Tuple(Of String, String))
    Return New Tuple(Of String, String)(RedisCache.Guid.ToString(), If(RedisCache.UseCache, RedisCache.Connection.ClientName, Nothing))
End Function

<Route("guid"), HttpPost>
Public Async Function PostForGuid() As Task(Of Tuple(Of String, String))
    Return New Tuple(Of String, String)(RedisCache.Guid.ToString(), If(RedisCache.UseCache, RedisCache.Connection.ClientName, Nothing))
End Function

<Route("guid/sync"), HttpGet>
Public Function GetSyncGuid() As Tuple(Of String, String)
    Return New Tuple(Of String, String)(RedisCache.Guid.ToString(), If(RedisCache.UseCache, RedisCache.Connection.ClientName, Nothing))
End Function

The examples above, along with some calls embedded in ASPX page, across multiple sessions (and time zones), yielded the same results. So at the moment I strongly suspect that the fault lies either with the RedisSessionStateProvider, or at least our use of it.

Update 13/08
Firstly, I've been running two instances of Redis on the test server for about a week. One taking Session requests, the other taking requests from the RedisCache class above. Both are sitting at a steady 15-20 connections.
The main point of this update though. I had the idea to run CLIENT LIST on the production Redis. With the client count sitting at around 1.3k, I managed to grab a sample of 850 client rows.
Out of the entire sample, there was one client that had a last command of GET, the rest were UNSUBSCRIBE or INFO. Ages range from 5000 seconds to 65,000 seconds. The idle times range from 0 to 60 seconds. I understand that the UNSUBSCRIBE commands relate to StackExchange.Redis' handling of pub/sub functionality which, to my knowledge, I'm not using.
Why are these clients staying active and multiplying??
id=1367825 addr=*** fd=45 name=*** age=465516 idle=56 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=info numops=7680
id=1319911 addr=*** fd=611 name=*** age=489772 idle=48 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=info numops=8082
id=1409149 addr=*** fd=477 name=*** age=444591 idle=34 flags=N db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=unsubscribe numops=7328
id=1319912 addr=*** fd=508 name=*** age=489772 idle=38 flags=N db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=unsubscribe numops=8072
id=2169495 addr=*** fd=954 name=*** age=59035 idle=56 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=info numops=984
id=2169496 addr=*** fd=955 name=*** age=59035 idle=56 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=info numops=984
id=1219863 addr=*** fd=557 name=*** age=540498 idle=38 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=info numops=8917
id=1032642 addr=*** fd=594 name=*** age=635373 idle=56 flags=N db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=unsubscribe numops=10474

Update 14/08
A potentially positive development. I logged a ticket on Github. Sounds like a issue with our symptoms has been fixed in 2.0. Clients that never die

A: It's been a crazy couple of months I can tell you. The StackExchange team released 2.0.495, 28 days ago. Which was amazing but for our reliance on RedisStateProvider, which in turn depends on the StrongName variant of StackExchange.Redis. The StrongName variant was discontinued in 2.0, so I logged a ticket with the Azure team. Would you believe that they then came out with their own release, 15 days ago. Amazingly amazing.
Good news/bad news situation. The update worked, yay! It worked a bit too well, boo. Communications that we're previously lavishing themselves amongst 1.1k+ connections were suddenly squeezed into 40 or so connections. Timeouts galore. The error messages came with very helpful link though. The suggestion being that a pool of ConnectionMultiplexers might be the answer. Using code based on this SO, we've implemented our own pool that can be scaled up or down using app settings. The pool is still in the testing phase so it's too early to say whether it's the answer to our problems, but the result are looking promising.


text:
Q: volley returns error response I have to make a json post request  with the following parameters.
{"method":"login","data":{"username":"korea","password":"123456"}}

I use volley to make post request and follwoing is my code to do post request.
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, loginURL, null,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                Toast.makeText(mContext,response.toString(),Toast.LENGTH_SHORT).show();

                            }
                        },
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Log.e("Volley", "Error");

                            }
                        }
                ){
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String,String> map = new HashMap<String,String>();
                        map.put("method","login");
                        map.put("username","korea");
                        map.put("password","123456");
                        return map;
                    }
                };
                requestQueue.add(jsonObjectRequest);
                requestQueue.start();

Im getting error response from server. How to get proper response from server?

A: Change Request.Method.GET to Request.Method.POST. Then pass a JSONObject as the third parameter where you currently have null;
For example:
JSONObject data = new JSONObject();
data.put("username","korea");
data.put("password","123456");

JSONObject jsonObject = new JSONObject();
jsonObject.put("method","login");
jsonObject.put("data",data);

JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, loginURL, jsonObject, responseListener, errorListener);

A:
I use volley to make post request and follwoing is my code to do post request

That is not a POST request, AFAICT. You are using Request.Method.GET.

A: Use following method to post the data to server
public void postDataVolley(Context context,String url,JSONObject sendObj){
    try {
        RequestQueue queue = Volley.newRequestQueue(context);

        JsonObjectRequest jsonObj = new JsonObjectRequest(url,sendObj, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.d("Volley", "Volley JSON post" + response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("Volley", "Volley JSON post" + "That didn't work!");
            }
        });

        queue.add(jsonObj);

    }catch(Exception e){

    }
}


text:
Q: Getting Started With SPARQL, Sandboxing I'm a firm believer in learning a platform or technology by playing with it. So I've kind of glanced at SPARQL and thus far haven't really gotten to into it because it just ... looks daunting (as does everything at first).
I'd like an environment with a couple of documents that I can cross reference and query. My temptation is to do SQL like things such as joining a city to it's home country - but maybe that's the wrong frame of mind. I've looked at the examples on dbpedia and right of the bat there's question marks, 5 namespaces, angle brackets and other hoopla.
http://dbpedia.org/snorql/ looks like a good place to play.
Anyone have some experiences to share? Any resources in particular that really launched your learning?

A: I've heard that the ARQ SPARQL tutorial is a useful start. As you've found, dbpedia is a  daunting data set to start with, but sparql.org also provides a very simple dataset to try querying online.

A: I agree with you. So, I have put together a starter kit to help with starting an initial data set. It's still in the very early "alpha" stage, but I have been able to use it to create a set of triples to work from. https://github.com/barobba/RDF-SPARQL-Starter-Kit
Also, here is a related post I just made on StackOverflow:
How to get started with RDF? (Particularly for relational database developers?)

A: As comment_bot says the ARQ SPARQL tutorial is a good place to start.
If you really want to understand it then you will need to read the full SPARQL specification which has lots of examples and explains it in a lot of detail.  If you just want to use it then you shouldn't worry about section 12 onwards as that goes into in-depth technical details of the formal definition of SPARQL and how you might go about implementing it.
But also like you say you do need to just play around with queries - again comment_bot mentions sparql.org which is a handy sandbox
Also be aware that currently there is a Working Group actively working on SPARQL 1.1 which will add in a number of useful features such as aggregates and negation which are either missing or hard to do under the existing specification.
You may also want to keep an eye on SemanticOverflow which is the Semantic Web equivalent of SO and quite a few of the people involved in writing the SPARQL specification visit that site so if you have an obscure/complex SPARQL question it's the place to ask


text:
Q: Azure Data Factory, Copy Data, Teradata ODBC , dateTime timestamp mapping We're implementing a ADF copy activity of Azure Sql Server to on prem Teradata with the ODBC connector.
We cant make the mapping work for a DateTime > Timestamp6 column and gets various errors when testing. (due to changing the source format)
The source query has been cast/converted to various formats into an intermediate Blob File.
The cast/converts has been:
* convert(varchar(26), EventUtcTimeStamp,121) EventUtcTimeStamp //"2020-11-03 12:01:21.928294"
* convert(varchar(19), EventUtcTimeStamp,121) EventUtcTimeStamp //"2020-11-03 12:01:21"
* cast(DATEDIFF(s, '1970-01-01 00:00:00.000', eventUtcTimeStamp) as bigint) * 1000 eventUtcTimeStamp //1604404881000

The Blob File is the source for the second Copy activity where the target is the teradata table. This generates various ErrorCode=TypeConversionFailure's .
We suspect the cause to be the sink mapping to teradata, since it cant be changed from DateTime.
The blob file looks ok.
Any one encountered this and know how to tweak it to work, if possible at all?
Copy Activity
Sink Mapping Teradata

A: So, it seems the ODBC sink with Teradata as a target is not fully supported.
We solved this by creating an ODBC Teradata "staging" table with varchar only columns and some stored procedures/triggers to move it into the real columns.
Quoting from here

I got confirmation from Product team that data factory can recognize
date formats as in this document. Today Teradata as a sink is not
supported in dataflow yet to convert it as datetime before loading
into sink. So, unfortunately, this is not possible without
modification at sink today.
I would recommend to submit an idea in feedback forum that is closely
monitored by data factory product team and will be implemented in
future releases.


text:
Q: Why does the dynamically created fields in a form not pass when submitted? Dynamically created select elements (form fields) does not get sent when form is submitted.
added the element to the form.objects array
var selectHeads = ['first','second'];
function orderFill(firstSelect){
var base = firstSelect.id.split('-');
++base[1];
var sel = document.createElement('select');
sel.id = base[0] + '-' + base[1];
sel.name = sel.id;

var opt = document.createElement('option');
opt.value = orderHeads[0];
opt.innerHTML = orderHeads[0];
sel.appendChild(opt);

var opt = document.createElement('option');
opt.value = orderHeads[1];
opt.innerHTML = orderHeads[1];
sel.appendChild(opt);

firstSelectfirstSelect.parentNode.appendChild(sel);
document.mainform.elements.push(sel);
document.getElementById(base[0] + '-' +
base[1]).setAttribute('onchange','orderFill(this)');
}

When the first select is changed a second select is created.  When it's changed a third is created.  When submitted, the second select selected data is sent to be processed.


text:
Q: Django views filter by date startswith I have a model label like this:
date_realization = models.DateField(_('Realised in'),
                                     default=timezone.now)

Then an url like this :
    url(r'^date/(?P<daterealization>[\w\.@+-]+)/$', DateEntriesView.as_view(), name='articles-date'),

When I am sending the url, it's like this:

www.mondomaine.com/articles/date/2016-01

And my date_realization field is like this :

2016-01-13

And what I want to do is to return all articles that have this date.
So I tried what I did for categories, but the behaviour is a bit different here.
This is what I tried to do :
class DateEntriesView(ContextSourcesMixin, BaseArticleView, BaseArticleListView):
model = Article
context_object_name = 'article_list'
template_name = 'base_templates/template_press.html'
_date_realization = None
paginate_by = None
view_url_name = 'djangocms_press:articles-date'

def get(self, *args, **kwargs):
    # submit object to cms toolbar to get correct language switcher behavior
    if hasattr(self.request, 'toolbar'):
        self.request.toolbar.set_object(self.date_realization)
    return super(DateEntriesView, self).get(*args, **kwargs)

@property
def date_realization(self):
    if not self._date_realization:
        try:
            date_realization_qs = Article.objects.active_translations(
                get_language(),
                date_realization__startswith=self.kwargs['daterealization']
            )

            self._date_realization = date_realization_qs.latest('pk')
        except Article.DoesNotExist:
            raise Http404("Article does not exist for this site")
    return self._date_realization

def get_queryset(self):
    qs = super(DateEntriesView, self).get_queryset()
    if 'date_realization' in self.kwargs:
        qs = qs.filter(date_realization__pk=self.date_realization.pk)
    return qs

def get_context_data(self, **kwargs):
    kwargs['date_realization'] = self.date_realization
    return super(DateEntriesView, self).get_context_data(**kwargs)

But I got this exception message:

Exception Type: FieldError at /en/press/date/2016-01/
Exception Value: Relation fields do not support nested lookups

Thus, I feel stuck.
EDIT:
Well, the model Article is very long,
@version_controlled_content
@python_2_unicode_compatible
class Article(ModelMeta, TranslatableModel):
taints_cache = True

"""
Press article element,
"""
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
date_realization = models.DateField(_('Realised in'),
                                     default=timezone.now)
image = FilerImageField(verbose_name=_('Featured image'), blank=True,
                             null=True,
                             on_delete=models.SET_NULL,
                             related_name='image_press_article',
                             help_text=_('Set if the article will be featured'))

sources = models.ManyToManyField(ArticleSource, verbose_name=_('Source'),
                                    blank=False, null=True, related_name='sources_press_article')

regions = models.ManyToManyField(Country, verbose_name=_('Country of the article'),
                                 blank=True, null=True,
                                 related_name='regions_press_article')

global_regions = models.BooleanField('Global', default=False)

featureArticle = models.BooleanField(_('Feature'), help_text=_('Feature this article'), default=False)

sites = models.ManyToManyField(Site, verbose_name=_('Sites'), blank=True,
                                                    null=True,
                                                    help_text=_('Select sites in which show the project.'))

article_url = models.CharField(_('Article Url'), max_length=310, blank=False,
                                   help_text=_('Use to link to the original source'))

countries_displayed_in = models.ManyToManyField(
    Country,
    verbose_name=_('Countries displayed in'),
    blank=True,
    null=True,
    related_name='displayed_in_press_article',
    help_text='Select the countries in which this project will be visible.'
    'If not selected, the project will be visible in all countries otherwise it will be'
    'visible only for users that are located in the countries selected')

translations = TranslatedFields(
    title=models.CharField(_('title'), max_length=510),
    slug=models.SlugField(_('slug'), blank=False, db_index=True, max_length=300),
    description=HTMLField(_('article description if featured'), default='', blank=True,
                          configuration='HTMLFIELD_CKEDITOR_SETTINGS_CONTENT'),

    meta_description=models.TextField(verbose_name=_('article meta description'),
                                      blank=True, default=''),
    meta_keywords=models.TextField(verbose_name=_('article meta keywords'),
                                   blank=True, default=''),
    meta_title=models.CharField(verbose_name=_('article meta title'),
                                help_text=_('used in title tag and social sharing'),
                                max_length=255,
                                blank=True, default=''),
    meta={'unique_together': (('language_code', 'slug'),)}
)

objects = ProjectManager()

_metadata = {
    'title': 'get_title',
    'description': 'get_description',
    'keywords': 'get_keywords',
    'locale': None,
    'image': 'get_image_full_url',
    'published_time': 'date_created ',
    'modified_time': 'date_modified',
    # Handle the get_absolute_url in the view to have access to the request
    # and so, to the current_app namespace instance
    # 'url': 'get_absolute_url',
}

def country(self):
    return "\n".join(([p.name for p in self.regions.all()]))

def source(self):
    return "\n".join([p.name for p in self.sources.all()])

def get_title(self):
    title = self.safe_translation_getter('meta_title', any_language=True)
    if not title:
        title = self.safe_translation_getter('title', any_language=True)
    return title.strip()

def get_keywords(self):
    return self.safe_translation_getter('meta_keywords').strip().split(',')

def get_description(self):
    description = self.safe_translation_getter('meta_description', any_language=True)
    if not description:
        description = self.safe_translation_getter('description', any_language=True)
    return escape(strip_tags(description)).strip()

def get_image_full_url(self):
    if self.image:
        return self.image.url
    return ''

class Meta:
    verbose_name = _('Press article')
    verbose_name_plural = _('Press articles')
    get_latest_by = 'date_realization'

def __str__(self):
    title = self.safe_translation_getter('title', any_language=True)
    return title if title is not None else '(not translated)'

def save(self, *args, **kwargs):
    super(Article, self).save(*args, **kwargs)
    main_lang = self.get_current_language()
    for lang in self.get_available_languages():
        self.set_current_language(lang)
        if not self.slug and self.title:
            self.slug = slugify(self.title)
    self.set_current_language(main_lang)
    self.save_translations()

def get_slug(self):
    return self.safe_translation_getter(
        'slug',
        language_code=get_language(),
        any_language=False)

A: I'd instead parse the date's month/year through the urlconf.
 url(r'^date/(?P<date_year>[0-9]+)-(?P<date_month>[0-9]+)/$',
                     DateEntriesView.as_view(), name='articles-date'),

and then in your view :
date_realization_qs = Article.objects.active_translations(
                get_language(),
                date_realization__month=self.kwargs['date_month'],
                date_realization__year=self.kwargs['date_year']
            )

Keep in mind that if you try and call a key from self.kwargs that doesn't exist, you will get an error. Perhaps it's better to call self.kwargs.get('date_month',datetime.date().month) to have a default of current month if none supplied (as well as calling the same for year).


text:
Q: Removing rows from a table if they have an email record from another table I have 2 tables, one with customers, containing their name, email, company, etc. I have another table that just contains the emails of the customers that need to be removed. I need to develop a query to delete all rows from the first table if they contain an email in the second. These tables are in a Microsoft SQL Server database.
As I am in the process of learning SQL I have no idea how to do this, I've searched through questions and can't find a similar enough one.

A: You can use exists() like so:
delete c
from customers as c
where exists (
  select 1
  from emails as e
  where e.email = c.email
  )

or in():
delete c
from customers as c
where c.email in (select email from emails)

A: Use an IN clause:
Delete from [customers] where [email] in (Select [email] from [toberemoved])


text:
Q: Configuring a Login Helper in Rspec Im creating a helper login to my Rspec tests.
On my spec_helper.rb I have:
 RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end

And in my folder -> spec/support/helpers/authentication.rb
module Helpers
  module Authentication
    def sign_in_as(user)
       visit 'spud/user_session/new'
       fill_in 'Login', with: ''
       fill_in 'Password', with: ''
       click_on 'Login'
    end
  end
end

When I run rspec it gives me this error:
spec_helper.rb:46:in `block in <top (required)>': uninitialized constant Helpers (NameError)

The line 46 its exactly the "config.include Helpers::Authentication, type: :feature"
What Im missing here?

A: The problem is that I was adding the
RSpec.configure do |config|
   #adding a login method for all tests
   config.include Helpers::Authentication, type: :feature
 end

on the spec_helper.rb
I just changed it to the file rails_helper.rb and it works


text:
Q: Sharing configuration across multiple tracesources I'm stuck with TraceSource configuration.
I have a lot of TraceSource following the "one per class pattern" and now I would like to configure all of them in a app.config.
Is it possible ?
I add that the TraceSource are in a .dll and I would like to use the .exe app.config.
Thanks for your help.
Vincent.


text:
Q: ESXi 4.0 Licensing Limits From what I understand, the software is free and you just need to register to remove the 60-day limitation. Does this mean I have to register every time I install ESXi on a new machine? Or can I use the same key for different ESXi 4.0 installations?

A: This may have changed since but the last time I registered for keys I was prompted to enter a quantity, so you should be able to obtain what you need without having to repeat the registration.

A: As John mentioned, you can obtain a key for a certain number of activations. Each time you install a new ESXi machine, you activate with the same key.


text:
Q: Close app while in background at certain times What I want to do is to tell the user to press the home button and reopen the app, which requires the app quitting upon entering the background - it's for a reset app settings thing. But I do want the app to background in all other times. Do I use the app delegate?
If there is an easier way, e.g. somehow restarting the main view controller then that would be helpful.

A:     For your app to run in background always use this code.
    Put this code under the method ApplicationDidEnterBackground  in your app delegate class            .m file
- (void)applicationDidEnterBackground:(UIApplication *)application
{
     UIApplication *app = [UIApplication sharedApplication];
        UIBackgroundTaskIdentifier bgTask = 0;
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
        }];

}


text:
Q: Microsoft LifeCam NX-6000 not working in Ubuntu 11.10 64 bit
Possible Duplicate:
How do I get Microsoft LifeCam NX-6000 video to work?

I am facing some issues with my webcam and I need some help because I have tried everything but I can't get it work.
I have installed libv4l-0 and cheese webcam booth,but my webcam still doesn't work.I have tried to plug it in different usb ports but still nothing.
When I run dmesg | grep uvc command in terminal I get this:

dmesg | grep uvc

[   56.343062] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam NX-6000 (045e:00f8)
[   56.343418] uvcvideo: UVC non compliance - GET_DEF(PROBE) not supported. Enabling workaround.
[   56.344165] usbcore: registered new interface driver uvcvideo
[   69.528571] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[   69.528694] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  684.265874] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  684.266495] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  684.267117] uvcvideo: Failed to query (129) UVC probe control : 0 (exp. 26).
[  684.268370] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  684.269370] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  684.269993] uvcvideo: Failed to query (129) UVC probe control : 0 (exp. 26).
[  983.936746] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[  983.936869] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[ 1310.904475] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam NX-6000 (045e:00f8)
[ 1310.904817] uvcvideo: UVC non compliance - GET_DEF(PROBE) not supported. Enabling workaround.
[ 1331.600728] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).
[ 1331.600851] uvcvideo: Failed to query (GET_DEF) UVC control 2 on unit 5: 0 (exp. 2).

And when I run lsusb I get this :
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 008 Device 002: ID 045e:070f Microsoft Corp.
Bus 001 Device 005: ID 045e:00f8 Microsoft Corp. LifeCam NX-6000

Can anybody help please?


text:
Q: How to pass a global value to a .js file in Angular In my Angular/Django REST app I need Youtube videos to be displayed from a <video> element.
So I retreive the youtube video src from my backend with youtube dl and send it to my frontend for it to be displayed.
In order to deal with the CORS issue, I wrote this proxy.conf.json:
{ "\/api": {
    "target": "https://r5---sn-25ge7nsk.googlevideo.com",
    "secure": true,
    "changeOrigin": true,
    "logLevel": "debug",
    "pathRewrite": {
      "^\/api": "/"}
  }
}

It works great.
But because each video has a different starting url (ex: "https://r2---sn-25g57nsk.googlevideo.com", "https://r1---sn-25ge7esk.googlevideo.com"....), I decided to load the target dynamically.
So I changed my proxy.conf.json for this proxy.conf.js
const PROXY_CONFIG = [
  {
    context: ["/api"],
    target: proxyUrl,
    secure: true,
    changeOrigin: true,
    logLevel: "debug",
    pathRewrite: { "^\/api": "/" }

  }
]
module.exports = PROXY_CONFIG;

Then I created a global.ts:
import { Injectable } from '@angular/core';
@Injectable()
export class Globals {
  proxyUrl: string = "https://r5---sn-25ge7nsk.googlevideo.com"
}

Without forgotting to add it in my app.module.ts. The idea is to retreive the begining of the url of the video, then set it as the value of the global proxyUrl, and then play the video.
My issue now is that I can't figure out how to import proxyUrl into my proxy.conf.js
I've tried:
import {Globals} from "./src/app/global"

But I got: Unexpected token { in return.
What is the correct way to fix my issue?

A: You can handle it in interceptor layer.
For detailed info, look at the official docs.
For a real example, please look at this reply.


text:
Q: Custom Errors in my Website When I am Connecting a website through remote machine, The Website showing the run-time error
Details: To enable the details of this specific error message to be viewable on remote machines, please create a  tag within a "web.config" configuration file located in the root directory of the current web application. This  tag should then have its "mode" attribute set to "Off".
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's  configuration tag to point to a custom error page URL.
But i want to display entire site in my website, and one more thing i am using Ajax controls in website, they are CalenderExtender control.
Only Ajax Control tabs showing errors, remaining will be executed perfectly.
enter code here

  <!-- Web.Config Configuration File -->

     <configuration>
       <system.web>
     <customErrors mode="Off"/>
       </system.web>
     </configuration>

  <!-- Web.Config Configuration File -->

   <configuration>
     <system.web>
       <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
     </system.web>
   </configuration>

A: You seem to have an exception somewhere, it may (or may not) be related to your configuration of the AJAX controls, and you need to correct this first. Check the event log on the server to see the exception details, or just configure your site to expose the details in the browser (which is suggested in the error message you're currently seeing.
You should have only a single <customErrors> tag in your web.config:
<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

Set the mode to "off" if you want the site to display all the exception details. However, on production websites, it's generally recommended never to display these details to users.