Q: Change Partion Drive Space Okay I am having some trouble here - pretty new to the Linux environment and need some help. I have a 2.7 TB RAID array, and someone configured a partition at around 200 GB but it really needs to be larger like 2.2 TB. How do I Make the partition larger?
Also it looks like there is a duplicate 2.2 TB partition.
I need the disk, /dev/mapper/vg_orchestrator1-lv_home, 219.9 GB partition, to be the 2.2 TB, and I am not sure how/if I can resize that partition or if I need to make something new and copy content over.
Here is some information from some commands I've run.
List of Discs using fdisk
[root@orchestrator1 ~]# fdisk -l

Disk /dev/sda: 299.4 GB, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d0e98

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       36405   291908608   8e  Linux LVM

Disk /dev/sdb: 2698.6 GB, 2698581639168 bytes
255 heads, 63 sectors/track, 328083 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3d468517

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60735   487849952+  83  Linux

Disk /dev/mapper/vg_orchestrator1-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_orchestrator1-lv_swap: 25.4 GB, 25367150592 bytes
255 heads, 63 sectors/track, 3084 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/3600508e000000000cad0b2b5c22f8d02: 2698.6 GB, 2698581639168 bytes
255 heads, 63 sectors/track, 328083 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3d468517

Device Boot      Start         End      Blocks   Id  System
/dev/mapper/3600508e000000000cad0b2b5c22f8d02p1               1       60735   487849952+  83  Linux

Disk /dev/mapper/3600508e000000000cad0b2b5c22f8d02p1: 2199.0 GB, 2199020350464 bytes
255 heads, 63 sectors/track, 267348 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System

Disk /dev/mapper/vg_orchestrator1-lv_home: 219.9 GB, 219857027072 bytes
255 heads, 63 sectors/track, 26729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/3600508e000000000cad0b2b5c22f8d02p1p1: 2199.0 GB, 2199020318208 bytes
255 heads, 63 sectors/track, 267348 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

df -h command
[root@orchestrator1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_orchestrator1-lv_root
                   50G   45G  1.7G  97% /
tmpfs                  24G   80K   24G   1% /dev/shm
/dev/sda1             477M  123M  325M  28% /boot
/dev/mapper/vg_orchestrator1-lv_home
                  202G   61M  192G   1% /home

And cat /etc/fstab command:
[root@orchestrator1 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Apr 27 13:14:35 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
/dev/mapper/vg_orchestrator1-lv_root /                       ext4   defaults        1 1
UUID=62e2c26b-9f29-4de4-96b1-d76ff142d23d /boot                   ext4    defaults        1 2
/dev/mapper/vg_orchestrator1-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_orchestrator1-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sdb                /home                   ext4    defaults        1 2

pvs
[root@orchestrator1 ~]# pvs
  PV  VG               Fmt  Attr PSize   PFree
/dev/disk/by-id/scsi-3600508e000000000e30eb35adb098c03-part2 vg_orchestrator1 lvm2 a--  278.38g    0

lvs
[root@orchestrator1 ~]# lvs
LV   VG  Attr LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
lv_home vg_orchestrator1 -wi-ao---- 204.76g
lv_root vg_orchestrator1 -wi-ao----  50.00g
lv_swap vg_orchestrator1 -wi-ao----  23.62g


Q: Program to check if N^2 number of elements can be converted to a N*N symmetric matrix? I was solving some problems on matrices the other day when this question hit me. Is there any way we can check if N^2 number of elements can be arranged in such a way that they form a symmetric matrix?
For instance, if N=3, then N^2=9
Let the elements be : 1 2 3 1 2 3 1 2 3.
The above elements can be arranged to form a symmetric matrix like:-
1 2 3
2 3 1
3 1 2
Similarly, 9 1s can be used to form a matrix as follows:-
1 1 1
1 1 1
1 1 1
But the elements 1 2 3 4 5 6 7 8 9, can in no way be arranged to form a symmetric matrix.
I thought about this question a lot but could not come up with a solution. Could someone please help me?

A: In an N×N symmetric matrix, every entry above the main diagonal has an equal counterpart below the main diagonal. This means that, aside from the N elements on the main diagonal, all elements come in equal pairs. (Elements on the main diagonal can also come in equal pairs, but they're not required to; the matrix's symmetry isn't affected by, for example, whether a22 = a33 or not.)
So, you can simply count how often each distinct value occurs, and see how many of the values occur an odd number of times. If there are N or fewer distinct values that occur an odd number of times, then the main diagonal of an N×N matrix can accommodate the unpaired values, so a symmetric matrix is possible; otherwise, not.


Q: Meigee Widget code 1.9.1.2 not displaying correctly I noticed after installing the new security patch my homepage products blocks disappeared. I removed this code which pulled the New products to the home page, however this code blocks all other codes and when I try adding a new widget the size of the blocks are too small
{{widget type="catalog/product_widget_new" display_products="all_products" show_paginator="0" products_per_page="6" products_count="6" column_count="6" template="catalog/product/widget/new/content/new_grid.phtml"}}


Q: Slow loading of Images using Glide on RecyclerView I have a recyclerView with a grid layout, at a time 6 cards are being displayed on the screen and JSON with 10 objects are called and for image loading, I'm using glide
Now Image loading was not up to the marking
So I search more regarding Glide and found a method for calling the thumbnail
Glide
     .with(Context)
     .load(url)
     .thumbnail(0.25f)
     .transition(DrawableTransitionOptions.withCrossFade())
     .into(ImageView);

But still wasn't helpful much
then I use another method of calling a RequestBuilder
It did help but not the desired level
Can anyone suggest what else I could do to decrease the loading time of images to make the user experience better?

A: Use these options (In kotlin) -
GlideApp.with(mContext)
                .apply(getRectangleRequestOptions(true))
                .load(url)
                .thumbnail(0.5f)
                .into(layout.bannerAdapterImg)

Where getSquareRequestOptions is -
fun getSquareRequestOptions(isCenterCrop:Boolean=true): RequestOptions {
        return RequestOptions().also {
            it.placeholder(R.drawable.ic_placeholder)
            it.error(R.drawable.ic_err_image)
            it.override(200, 200)                         // override size as you need
            it.diskCacheStrategy(DiskCacheStrategy.ALL)   //If your images are always same
            it.format(DecodeFormat.PREFER_RGB_565)        // the decode format - this will not use alpha at all

            if(isCenterCrop)
                it.centerCrop()
            else
                it.fitCenter()
        }
    }

*For java code just update getSquareRequestOptions function in java.
This is the best glide can do. If it still takes time than compress images from server side.


Q: How to change the pitch of a .wav file in Android? Can somebody tell me how to change the pitch of a wave file in Android?

A: Android does not have such functions built in, and the process is not at all trivial. If you would like to try and code it yourself, I suggest looking at such algorithms as PSOLA, WSOLA and Phase Vocoder for pitch alteration. The book DAFX by Udo Zölzer discusses many of these in quite good detail and most of it is fairly straightforward. Phase Vocoder, I believe, works the fastest, but also takes more DSP and mathematical knowledge to understand. PSOLA is perhaps the least mathematically complicated. I personally prefer WSOLA and Enhanced WSOLA (EWSOLA), but those take quite a bit of processing power.
For correlation techniques (if you use WSOLA) I suggest doing it if frequency domain (Google FFT-based correlation). It is much quicker.
If most of this had just gone over your head, you might want to reconsider doing this altogether, but I by no means try to discourage you. = )


Q: What could cause an SFTP host key fingerprint mismatch? A remote user has tried to connect to my SFTP/SSH server for the first time, using the "Transmit" client under Mac OS X, and has found that the host key fingerprint doesn't match the expected value.
I have a screenshot of the displayed fingerprint and have compared it with the output of ssh-keygen -lf /etc/ssh/ssh_host_dsa_key and ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub, and it doesn't match either of these.
I have also unsuccessfully compared the fingerprint against the output of cut -d ' ' -f 2 < /etc/ssh/ssh_host_dsa_key.pub | base64 -d | sha1sum and cut -d ' ' -f 2 < /etc/ssh/ssh_host_rsa_key.pub | base64 -d | sha1sum (because it seems that there are different fingerprinting algorithms in use?).
The message box on client side is titled (translated into English)

Unknown host key for < hostname >

and states

The server is unknown. The fingerprint of the host key is < 16 octets >. ( Allow ) ( Deny ) [ ] Always

So there is no indication whether RSA or DSA key is used, or whether MD5 or some SHA algorithm is used for creating the fingerprint.
The fingerprint displayed to the remote user has 16 colon-separated octets, so it doesn't appear to use SHA-224 or anything higher. Update: I just noticed that even an SHA-1 hash will have 20 octets, so the displayed fingerprint is not in any SHA format apparently.
The connection ultimately goes to the correct server, because I can see the login attempt in my server logs if the user allows the connection. So it appears that the host name/IP is entered correctly on client side.
A connection to another (completely unrelated) SFTP server shows an incorrect fingerprint as well (but a different one than for the first server).
If I try to connect to the server myself using OpenSSH from some other host (or locally from the server itself), I am shown the correct fingerprint (the MD5 fingerprint for RSA host key).
The server is running Debian 6 LTS with the standard OpenSSH server.
What could cause this fingerprint mismatch? How can I debug this problem?

A: If it is the first time they connected, it doesn't matter if there's a mismatch... the client just had some unrelated old entry that happened to have the same host name or ip address associated with it. Just clear it with:
ssh-keygen -R $name_or_ip

After you do that, it should certainly say whether it is RSA, ECDSA, etc. the next time you connect. If not, try using a proper client like the OpenBSD OpenSSH client which is standard on Linux, or trying -v (or -vvvv, etc. verbose options). And then verify and accept the new key. The key fingerprint format in old clients is md5 (and in new ones is sha256, in some weird base64 format instead of ascii-hex), and the right way to get the fingerprint on the server side is:
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key

A: Turns out that the FTP program in use was not Transmit but was Cyberduck 4.5.1. The problem with the wrong fingerprint was already known as Wrong host key fingerprint. Updating to the latest version fixed this problem, and the displayed fingerprint is now correct.


Q: Ms Access Gathering data from subdatasheet Im trying to find a query which shows only fields with IS NULL from a subdatasheet column.
So far I have:
SELECT EmployeeId,FirstName,LastName,Salary
FROM Employee
WHERE ServiceDate IS NULL

Within the EmployeeId there is an expandable subdatasheet and I'm trying to figure out how to call upon the "ServiceDate" which is within the subdatasheet to display which employee hasn't got a service.
  I hope this make sense.
EDIT:
Here are the two tables:
http://i.stack.imgur.com/3LWSh.jpg
http://i.stack.imgur.com/8zSVS.jpg
Result I'm after:
EmployeeId  FirstName   LastName    Salary
E003        Ken         Moore       $59,000.00

A: Try something on these lines:
SELECT Employee.EmployeeId,Employee.FirstName,Employee.LastName,Employee.Salary
FROM Employee
LEFT JOIN Services
ON Employee.EmployeeId = Services.EmployeeId
WHERE Services.EmployeeId IS NULL

Do not forget that MS Access has a Find Unmatched query wizard.
You might like to look at:
Fundamental Microsoft Jet SQL for Access 2000
Intermediate Microsoft Jet SQL for Access 2000
Advanced Microsoft Jet SQL for Access 2000


Q: Why is infinite intersection "towards infinity" an empty set? Why is the infinite intersection "towards infinity" an empty set?
Or i.e.
Why is:
$$\cap_{i=1}^{\infty} F_i = \emptyset$$
$$F_n=[n, \infty)$$
There's intuition, the intersection is always the "smallest of the sets" so eventually it will be $(\infty,\infty)$ or something like that.

A: Suppose, to obtain a contradiction, that $F=\cap_n F_n$ is non-empty. Let $x \in F$. Then, $x\ge n$ for all $n \in \mathbb N$. However, there is no largest real number, so we must conclude that $F = \emptyset$.

A: Let's follow your intuition:

There's intuition, the intersection is always the "smallest of the
  sets" so eventually it will be $(\infty,\infty)$ or something like
  that.

Okay, but $(\infty,\infty)$ doesn't have any elements in it. Assuming we're dealing with the domain of real numbers, $\infty$ isn't one. (Recall that in real numbers the symbol $\infty$ isn't a number; it's always a shorthand placeholder for some statement about unbounded limits.)
On the other hand, even if we were talking about the extended real numbers where $\infty$ is an element, the notation $(\infty,\infty)$ indicates that endpoints are not included; that being $\infty$, so again this is an "interval" with no points in it.

A: It might be a little easier to understand via the contrapositive:
Let $x$ be any real number.  Then we know that there exists a positive integer $n_x$ larger than $x$.  (This is the so-called Archimedean property of the reals, but intuitively you can think of $n_x$ just being $x$ rounded up to the next integer, or if $x$ is negative you can just let $n_x$ be $1$.)  That means $x$ is not in the set $F_{n_x}$, so it certainly cannot be in the intersection $\bigcap_n F_n$.  This is true no matter what $x$ is, so $\bigcap_n F_n$ cannot contain any real numbers at all, which is to say it equals the empty set.

A: To belong in the intersection, any element would have to belong in each of the sets $[n,\infty)$ which means it must be larger than every finite number. Since there is no finite number with this property, the intersection is therefore empty.

A: The intersection is made up of real numbers which are greater than or equal to every positive integer. By Archimedes' property, there's none.


Q: MLP parameters vs train set size for function fitting: right approach? (positions, velocities, accelerations) = ($q$, $\dot{q}$, $\ddot{q}$) are generalized coordinates of a Lagrangian system
I'm trying to learn the Lagrangian L($q$, $\dot{q}$) by comparing analytical accelerations and predicted accelerations. These are found by manipulating Euler-Lagrange equations into $\ddot{q}$=f(L)=$(\nabla^{\space}_{\dot{q}}\nabla^T_{\dot{q}}L)^{-1}(\nabla_qL-(\nabla^{\space}_q\nabla_{\dot{q}}^TL)\dot{q})$
In synthesis, this is my forward method:
MLP Input ($q$, $\dot{q}$) (4 scalars, because we consider 2D systems)
MLP Output L($q$, $\dot{q}$) (1 scalar)
Calculate $\ddot{q}$= f(L)
These accelerations are then compared with analytical accelerations given by the same q, qt with an MSE loss function.
This happens pointwise in time, in the sense that the set ($q$, $\dot{q}$, $\ddot{q}$) do not carry time information, they're a triplet (sextuplet, because each has D=2) of scalars.
The predicted accelerations are not that bad, but when calculating predicted $q$, $\dot{q}$ by integration, even a small error propagates to a noticeably wrong trajectory.
Before enduring the painful road of hyperparameter optimization, I want to make sure my intuition on the issue is right, so I can confidently assume my MLP structure is not the main bottleneck. Please correct me on anything I'm missing.
Because I'm trying to fit a scalar function, the MLP can be thought of as an equation in P parameters, where P is the number of trainable params of the net.
Training it and comparing predictions with N targets (analytical  $\ddot{q}$, so how many doublets $q$, $\dot{q}$ i'm feeding to the MLP) imposes N restraints, so I can think of it as solving a system of N equations in P parameters.
As such, my intuition tells me I need to have AT LEAST N=P points ($q$, $\dot{q}$) to correctly solve it.
In the following example, I have P = 3361. Feeding it N = 4096 points will be enough to train them. Training with N = 16384 points should be better on one hand (because a larger training set can better generalise the predictions, given some initial conditions), but following the N eq in P variables reasoning,  it feels like overdetermining the system. I have tried various configurations of this, and having N >> P seems better at fitting  $\ddot{q}$, though never providing correct trajectiories because of the aformentioned propagation of errors in integration.
class LNN(nn.Module):
    def __init__(self):
        super(LNN, self).__init__()
        self.fc1 = nn.Linear(4, 32)
        self.fc2 = nn.Linear(32, 32)
        self.fc3 = nn.Linear(32, 32)
        self.fc4 = nn.Linear(32, 32)
        self.fc5 = nn.Linear(32, 1)
        self.sp = nn.Softplus(beta=0.5)   #beta = 1 is steeper, so derivative = 1 is approached faster

    def lagrangian(self, x):
        x = self.sp(self.fc1(x))
        x = self.sp(self.fc2(x))
        x = self.sp(self.fc3(x))
        x = self.sp(self.fc4(x))
        x = self.fc5(x)
        return x

    def forward(self, x):  #   q, qt
        n = x.shape[1]//2  #    2
        xv = torch.autograd.Variable(x, requires_grad=True)
        xv_tup = tuple([xi for xi in x])
        tqt = xv[:, n:]    #   qt

        jacpar = partial(jacobian,  self.lagrangian, create_graph=True)
        hesspar = partial(hessian,  self.lagrangian, create_graph=True)

        A = tuple(map(hesspar, xv_tup))    #
        B = tuple(map(jacpar, xv_tup))            ####################
                                                  ####THIS IS f(L)####
        multi = lambda Ai, Bi, tqti, n:  torch.pinverse(Ai[n:, n:]) @ (Bi[:n, 0] - Ai[n:, :n] @ tqti)
        multi_par = partial(multi, n=n)
        tqtt_tup = tuple(map(multi_par, A, B, tqt))
        tqtt = torch.cat([tqtti[None] for tqtti in tqtt_tup])

        xt = torch.cat([tqt, tqtt], axis=1)
        xt.retain_grad()
        return xt                        #qt (same as input), qtt

    def t_forward(self, t, x):
        return self.forward(x)

For the training part, I'm feeding the net analytical trajectories where points are shuffled, with the following parallel in mind:
training on batches of a continuous part of a curve, then going through the next part and so on, is like training an image recognition net by feeding ALL cats first, then ALL dogs etc, slowing down the learning of different features by focusing on the ones of a specific class. Again, this is (i think) true because of the pointwise nature of the training.
Here x = ($q$, $\dot{q}$), xt = ($\dot{q}$, $\ddot{q}$) (it's easier to pair them like this for how the code is built)
x = torch.tensor(anal_solve_ode(x0[:2], x0[2:], t_train)) #trajectories from analytical qtt and init. cond.
xt = torch.tensor(get_xt_anal(x, t_train)).float()  #get analytical accelerations for each q, qt i x
ind = torch.randperm(x.shape[0])
x = x[ind, :]   #shuffle
xt = xt[ind, :]

This method, together with training with trajectories coming from different initial conditions, seems to result in better generalisation.
Any input or experience on the matter?

A: One point to consider is that main modern neural networks are substantially over-parameterized by "traditional" standards. And that's not necessarily a bad thing and even happens in more traditional settings e.g. with splines as illustrated in this nice discussion of the double-descent phenomenon. So, I would not assume the number of trainable parameters needs to be less than the number of training samples, although that may be true. Additionally, there's a lot of recent work on this kind of set-up (e.g. here), so it's worth researching that.


Q: Sizes of tensors must match except in dimension 2. Got 16 and 32 (The offending index is 0) I'm getting following error :

Sizes of tensors must match except in dimension 2. Got 16 and 32 (The offending index is 0)

in following code:
x1=self.avg_pool(l1)
print('x1:', x1.shape)
x2=self.avg_pool(l2)
print('x2:', x2.shape)
x3=self.avg_pool(l3)
print('x3:', x3.shape)
x4=self.avg_pool(l4)
print('x4:', x4.shape)
x = self.aspp(x)
print('x:', x.shape)
x=torch.cat((x4,x3,x2,x1,x),dim=1)
cout1=x

I'm getting shapes of x1,x2,x3,x4,x as
x1: torch.Size([5, 256, 32, 32])
x2: torch.Size([5, 512, 32, 32])
x3: torch.Size([5, 1024, 32, 32])
x4: torch.Size([5, 2048, 32, 32])
x: torch.Size([5, 256, 16, 16])

A: You are concatenating on dim=1, well that means you need to join the tensors one after the othe ralong dim=1. The value that you get after concatenation along dim=1 is value=256+512+1024+2048+256, provided shapes of the tensors match in other dimensions too. The size of tensor x should be x=(5,256,32,32).

A: Inputs (values of l1, l2, l3, l4) are not provided, so I just guessed it and tried to mimic your code. Below snippet works fine.
import torch
import torch.nn as nn
import torch.nn.functional as F

class Pyramid_Pooling(nn.Module):
    def __init__(self, levels, inChans, outChans):

        super(Pyramid_Pooling, self).__init__()
        self.inChans = inChans
        self.outChans = outChans
        assert len(levels) == 4

        self.pool_4 = nn.AvgPool2d((levels[3], levels[3]))
        self.pool_3 = nn.AvgPool2d((levels[2], levels[2]))
        self.pool_2 = nn.AvgPool2d((levels[1], levels[1]))
        self.pool_1 = nn.AvgPool2d((levels[0], levels[0]))

        # lower the number of channels to desired size
        self.bottleneck_pyramid = nn.Conv2d(
            self.inChans, self.outChans, kernel_size=1
        )

    def forward(self, en1, en2, en3, en4):
        pooled_out_1 = self.pool_1(en1)
        print(pooled_out_1.shape)
        pooled_out_2 = self.pool_2(en2)
        print(pooled_out_2.shape)
        pooled_out_3 = self.pool_3(en3)
        print(pooled_out_3.shape)
        pooled_out_4 = self.pool_4(en4)
        print(pooled_out_4.shape)

        cat = torch.cat((pooled_out_1, pooled_out_2, pooled_out_3, pooled_out_4), 1)
        out = self.bottleneck_pyramid(cat)

        return out

I tried to guess your inputs and issue might be somehwere in input dimensions. You want to output 32 x 32 then input should be like below. Also added a 1x1 conv to lower the channels to desired output.
x_train_0 = torch.randn((3, 256, 32, 32), device = torch.device('cuda'))
x_train_1 = torch.randn((3, 512, 64, 64), device = torch.device('cuda'))
x_train_2 = torch.randn((3, 1024, 128, 128), device = torch.device('cuda'))
x_train_3 = torch.randn((3, 2048, 256, 256), device = torch.device('cuda'))

inChans = x_train_0.shape[1] + x_train_1.shape[1] + x_train_2.shape[1] + x_train_3.shape[1]
outChans = 512

# kernel_size = [1,2,4,8]
pyramid_pooling = Pyramid_Pooling([1, 2, 4, 8], inChans, outChans)
pyramid_pooling.to(torch.device('cuda'))
out = pyramid_pooling(x_train_0, x_train_1, x_train_2, x_train_3)
print(f"Output shape: {out.shape}")

Output will look like this:
torch.Size([3, 256, 32, 32])
torch.Size([3, 512, 32, 32])
torch.Size([3, 1024, 32, 32])
torch.Size([3, 2048, 32, 32])
Output shape: torch.Size([3, 512, 32, 32])


Q: mod_rewrite rule for "www to non www" doesn't redirect sub-pages I have made a thorough search before I have asked this question here. Please hear me out:
I am trying to redirect my blog from www to non www and it doesn't redirect any sub-pages. I have an http > https redirect in place as well and it works perfectly for both domain as well as the sub-pages. Here are the rules I have in my .htaccess
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^^rcp-pep-ipn //?rcp-pep-listener=IPN [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteBase /
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    </IfModule>
    # END WordPress

I'd really appreciate an explanation if I am doing anything wrong here. I have literally pulled my hair since I have used the exact same code (from the second RewriteBase /) for all other sites and it worked flawlessly.

A: You should bring those protocol checking conditions to the beginning. You have some problems within the rules too. Try:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,NE,L]
  RewriteRule ^rcp-pep-ipn /?rcp-pep-listener=IPN [QSA,L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>


Q: Search files in shared Google Drive I have the problem.
Earlier I had the file for search in my own Google Drive. And the script worked.
function checkInFiles(){

  var nameJSON = 'jobToCAF';

  var files = DriveApp.searchFiles('title contains "' + nameJSON + '"');

  while (files.hasNext()) {
     var file = files.next();
     Logger.log(file.getName());

  }
}

Script searches for files named like 0080076042_jobToCAF.JSON.
The difference is that now the file is located in shared Google Drive and search doesn't work.
Can you help ?


Q: Different Java behavior for Generics and Arrays Why does java allows inconsistent type to be entered into a generic object reference but not in an array?
For Eg:
When initializing array:
int[] a = {1, 2, 3};

And, if I enter:
int[] a = {1, 2, "3"}; //Error for incompatible types

While for generics,
import java.util.ArrayList;

public class Test {
    private static ArrayList tricky(ArrayList list) {
        list.add(12345);
        return list;
    }
    public static void main(String[] args) {
        int i = 0;
        ArrayList<String> list = new ArrayList<>();
        list.add("String is King");
        Test.tricky(list);
    }
}

The above code will let you add any Type in the list object, resulting in a run time exception in some cases.
Why is there such a behavior?? Kindly give a proper explanation.

A: The method's parameter has no generic so all classes are allowed.
You may google 'type erasure' for more information.
If you add the generic type to your method you will get a compiler error:
private static ArrayList<String> tricky(ArrayList<String> list) { // ...

By the way, you do not need to return the list because you modify the same instance.

A: Here's why:

The reason you can get away with compiling this for arrays is because
there is a runtime exception (ArrayStoreException) that will prevent
you from putting the wrong type of object into an array. If you send a
Dog array into the method that takes an Animal array, and you add only
Dogs (including Dog subtypes, of course) into the array now referenced
by Animal, no problem. But if you DO try to add a Cat to the object
that is actually a Dog array, you'll get the exception. Generic
Methods (Exam Objectives 6.3 and 6.4) 615 616 Chapter 7: Generics and
Collections
But there IS no equivalent exception for generics, because
of type erasure! In other words, at runtime the JVM KNOWS the type of
arrays, but does NOT know the type of a collection. All the generic
type information is removed during compilation, so by the time it gets
to the JVM, there is simply no way to recognize the disaster of
putting a Cat into an ArrayList and vice versa (and it becomes
exactly like the problems you have when you use legacy, non-type safe
code)

Courtesy : SCJP Study guide by Kathy Sierra and Bert Bates

A: When you declare you ArrayList like ArrayList list = ... you do not declare the type of object your list will contain. By default, since every type has Object as superclass, it is an ArrayList<Object>.
For good practices, you should declare the type of your ArrayList<SomeType> and, thereby, avoid adding inconsistant elements (according to the type)

A: Because you haven't defined the generic type of your list it defaults to List<Object> which accepts anything that extends Object.
Thanks to auto-boxing a primitive int is converted to an Integer, which extends Object, when it is added to your list.
Your array only allows int's, so String's are not allowed.

A: This is because in your method parameter you did not specify a particular type for ArrayList so by default it can accept all type of objects.
import java.util.ArrayList;

public class Test {

//Specify which type of objects you want to store in Arraylist
    private static ArrayList tricky(ArrayList<String> list) {
        list.add(12345);   //This will give compile time error now
        return list;
    }
    public static void main(String[] args) {
        int i = 0;
        ArrayList<String> list = new ArrayList();
        list.add("String is King");
        Test.tricky(list);
    }
}

A: When you use the tricky method to insert data into your ArrayList Collection, it doesn't match the specified type i.e String, but still This is compatible because of Generics compatibility with older Legacy codes.
If it wouldn't have been for this i.e if it would have been the same way as of arrays, then all of the pre-java generic code would have been broken and all the codes would have to be re-written.
Remember one thing for generics, All your type-specifications are compile time restrictions, so when you use the tricky method to insert data in your list reference, what happens is the compiler thinks of it as a list to which ANYTHING apart from primitives can be added.
Only if you would have written this:
...
public class Test {
    private static ArrayList tricky(ArrayList<String> list) {
        list.add(12345); //Error, couldn't add Integer to String
        return list;
    }
...
}

I have written a documented post on this, Read here.


Q: I can't fetch array elements on view section that have been passed from the controller using foreach() method I passed the array that have been fetched from the model into the view section. The values are fetched on controller part as well as on the view part. The used the foreach() method to fetch the array elements as shown below
Controller Part
function view_savings()
    {
        $user = $this->session->userdata(uname);
        $report['savings'] = $this->money_m->get_savings($user);
        $this->load->view('showsavings',$report);
    }

View Part
<?php
      foreach($savings as $vs)
      {
          echo $vs->username;
          echo $vs->stype;
          echo $vs->inst_name;
          echo $vs->acc_name;
          echo $vs->smonth;
          echo $vs->syear;
       }
?>

The array values are displayed from the $savings array(). Is there any problem with my code. Please help me..

A: Before calling the view,
print_r($report['savings']);

With above code are you getting any result??

A: just try it
<?php

  if(isset($savings) && count($savings) > 0)
  {
   foreach($savings as $vs)
   {
      echo $vs['username'];
      echo $vs['stype'];
      echo $vs['inst_name'];
      echo $vs['acc_name'];
      echo $vs['smonth'];
      echo $vs['syear'];
    }
   }
?>

Good Luck ['}

A: Use this in your view
  <?php
  foreach($savings->result() as $vs)
  {
      echo $vs->username;
      echo $vs->stype;
      echo $vs->inst_name;
      echo $vs->acc_name;
      echo $vs->smonth;
      echo $vs->syear;
   }
   ?>


Q: Change ASP.Net Label text colour if contains '-' I'm trying to change the text/font colour of my ASP.net label if it contains a '-' symbol.
This is a for a percentage change label so negative numbers need to be green and positive red.
I keep getting TypeError: document.getElementById(....) is null
I know window.onLoad isn't best practice, this is just to get it tested quickly.
Can anyone advise what I've done wrong..going round in circles.
window.onload = fillDays;

function fillDays() {
    var change = document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").value;

    if (change.indexOf(char) = '-') {
        document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").style.color = "green";
    }
    else {
        document.getElementById("<%=lblPercentageDifferenceToFillReqCurrentVsPreviousMonth %>").style.color = "red";
    }
    console.log("fillDays")
};

A: You have to use ClientID
var change = document.getElementById("<%= lblPercentageDifferenceToFillReqCurrentVsPreviousMonth.ClientID %>").value;

Assuming that it is an actual Control like
<asp:TextBox ID="lblPercentageDifferenceToFillReqCurrentVsPreviousMonth" runat="server"></asp:TextBox>


Q: Value is POSTED definitely but isset() says NO See the code give given below. I was fighting with this code since last 5 hours to know why isset() is evaluating the condition as false if value is posted exactly what it shall POST.
If I uncomment the line no. - 4,5,6,7,8 and put rest of the code from line no. 10 to 28 I can see the POSTED value .
Can Anyone help in this by any guidance or suggestion. I will be thankful.
<?php
include 'dbconnection.php';
include 'functions.php';

// var_dump($_POST); what happens when you uncomment this line?

//sec_session_start();
 //  $email = $_POST['logemail'];
 //  $password = $_POST['p'];
//  echo $password;
//  echo $email;
 // Our custom secure way of starting a php session.

if(isset($_POST['logemail'], $_POST['p'])) {
   $email = $_POST['logemail'];
   $password = $_POST['p']; // The hashed password.
   if(login($email, $password, $mysqli) === true) {
      // Login success
      //$url = 'mwq';
    //echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    echo $password;
    echo $email;

   } else {
      // Login failed
      header('Location: login.php?error=1');
   }
} else {
   // The correct POST variables were not sent to this page.
   echo 'Invalid Request Data Not POSTED';
}
?>

A: Without seeing the form I can only theorize what happens:

*

*You started with a clean slate, the form shows, you enter the username and password and submit it

*The code passes the condition and then performs the login

*The result of login(...) !== true for whatever reason (wrong password or bug in the code)

*The page redirects to login.php?error=1.

Now, the $_POST is empty and $_REQUEST contains array('error' => 1). Perhaps the login.php shouldn't redirect to itself but rather redirect back to the page where you show the form.


Q: retrieve a picture stored in a folder Zk Tomcat I'm new in zk programming, I had stored pictures from my app to a folder out the server(tomcat) and I want to retrieve it , the folder is c:\temps and supposing the picture names is myPic.jpg when I write pics.setSrc("c:\temps\myPic.jpg"); it doesn't work for me what could I do to fix it the storage is very well but retrieving the picture is working only on the Eclipse IDE but in other browsers it's not working
@Wire
private org.zkoss.zul.Image pics;
private static final String SAVE_PATH = "C:\temps\";
private ProfileDao pd = new JpaProfileDao();
private ListModel<profile> profileModel;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
profileModel = new ListModelList<Profile>(pd.findAll());
prfileSelect.setModel(profileModel);
String src="C://tmp//testimg.jpg";
pics.setSrc(src);
Clients.showNotification(pics.getSrc());
}

in the browser I have these problem
Not allowed to load local resource:file:///C://temps//testimg.jpg

A: you're trying to access to a file in the server side ,the server doesn't know about your disc
so use the aliases for tomcat
       <Context crossContext="true" docBase="here_the_path_in_disc" path="project_name/resource_name" reloadable="true"/>

A: I haven't worked with ZK for a while, but I'm pretty sure you need to give it an URL, relative to your webapp root directory. So something like "/images/testimg.jpg" or a canonical URL like "https://www.google.dk/images/srpr/logo11w.png", like you would if you ere writing HTML.

A: Best approach will be to use alternativedocroot on Glassfish or aliases option on Tomcat - aliases


Q: Carrierwave video thumbnail I am using the carrierwave gem (http://github.com/jnicklas/carrierwave) for ruby on rails.
How do I go about creating thumbnails for video uploads?
In my previous implementation with Paperclip, I was using FFMPEG.
How / where should this be done in Carrierwave?
There aren't too many useful resources on Google on this. Perhaps, someone with more experience can provide feedback.
Has anyone attempted to do this. Do share!

A: I have got it working as mentioned
It seems that the processing via ffmpeg needs to be done before model.save

A: It's not implemented actually on Carrierwave. So you need code it yourself by some process action in your Upload Class.


Q: How can I iterate over a file more than once? Currently, this code is giving me all lines from searchfile once. But with my newbie understanding, it should print out all lines from searchfile for every infile line!
searchfile = open('.\sometext.txt', 'r')
infile = open('.\somefile', 'r')

for line1 in infile:
    for line2 in searchfile:
        print line2

searchfile.close()
infile.close()

I tried to use searchfile.readlines() to create a list to print all infile lines for all searchfile lines, but it still does not work. Does anyone have a clue?

A: I suppose searchfile is a file you opened earlier, e. g. searchfile = open('.\someotherfile', 'r').
In this case, your construction doesn't work, because a file is an iterable which can be iterated over only once and then it is exhausted.
You have two options here:

*

*Reopen the file on every outer loop fun

*Read the file's contents into a list an iterate over this list as often as you need to.

What happens in your code?
At the start of the nested for loops, both your files are open and can be read from.
Whenever the first inner loop run is over, searchfile is at its end. When the outer loop now comes to process its second entry, the inner loop is like an empty loop, as it just cannot produce more entries.

A: The in and with keywords
You don't need two nested for loops!
Instead use the more pythonic in keyword like so:
with open("./search_file.txt", mode="r") as search_file:
    lines_to_search = search_file.readlines()

with open("./file_to_search.txt", mode="r") as file_to_search:
    for line_number, line in enumerate(file_to_search, start=1):
        if line in lines_to_search:
            print(f"Match at line {line_number}: {line}")

Pro tip: Open your files using the with statement to automatically close them.

A: You need to set searchfile current position to the beginning for every infile iteration. you can use seek function for this.
searchfile = open('.\sometext.txt', 'r')
infile = open('.\somefile', 'r')

for line1 in infile:
    searchfile.seek(0,0)
    for line2 in searchfile:
        print line2

searchfile.close()
infile.close()

A: We need a bit more details about what are your objects in this code. But you probably would like to do:
    infile = open('.\somefile', 'r')

    for line1 in infile:
       for line2 in line1:
         print line2

    searchfile.close()
    infile.close()

If your infile is a list of lists - That are the cases where a nested for loop would make sense.


Q: Object Detection on Cloud using React-Native Expo Complete React Native noobie here. I am trying to make an app in React Native Expo that will send an image to a cloud platform (still haven't decided on which one). The cloud will then recognize the objects in the image, put them in a square, and then return the image to the phone. I've been researching for days and I found APIs like Google Vision, and I found that Google has a module for  multiple object detection. This is exactly what I need to do but I don't know how to implement it. I've been looking online and found a project that seems to be similar but is lacking object detection it rather has image labeling which is not what I need.

*

*Are there any 3rd party APIs I can use in my project that can be used in i.e. Firebase?

*How do I connect my app with i.e. Firebase? Can someone give me an example?

*The picture needs to be manipulated on the cloud thus the squares need to be added on the cloud. Is this possible? I've checked out Google Vision but it seems to just return a JSON file (might be wrong)?

*What would be the best cloud service that already has the API I need?


Q: Position of an element in webpage I am trying to get the (x,y) co-ordinates of an element in javascript. I am using offset of jquery. My code is:
    var offsets = $('#11a').offset();
    var top = offsets.top;
    var left = offsets.left;
    console.log("Coordinates of re-ranker (top,left): " +top + "," +left)

My element is:

The value in console.log is different from the pixel values of 11a which is something like 60px x 23px. The value i am getting in console.log is something totally different and also in decimal. So what values am I getting in offsets? Is it different from pixel values?

A: .offset returns pixel values relative to the document. It is entirely possible for this method to return float values as not all sizes are pixel integers, for example:
Consider this HTML:

The following command for me (for me):
console.log($("div").offset().left); // Outputs 276.203125

jsFiddle of the above.
However, it is important to note the yellow box on the linked page:

jQuery does not support getting the offset coordinates of hidden
  elements or accounting for borders, margins, or padding set on the
  body element.
While it is possible to get the coordinates of elements with
  visibility:hidden set, display:none is excluded from the rendering
  tree and thus has a position that is undefined

A: It gets you the offsets of the element relative to the document!
You can learn more here: http://api.jquery.com/offset/

A: You can get the css values via
$("#11a").css("top").replace("px", ""); // You have to remove the 'px' it returns


Q: location based services - how to improve the location with RSSI, TA and ARFCN? I get LAC,CellId from my device. With these values I can know the Lat/Lng and, by triangulation, the area where the device is.
I also get ARFCN, TA and RSSI. Is it possible to improve the location by using these values ?

A: You need to have access to cellid to lat/lng db from mobile network operator to get lat/long of your device. Other way of getting this is by using location apis provided by android, iphone etc.

A: Signal Strength could possibly give you an indication of how far from a tower you are, thus improving accuracy
What platform are you using?


Q: Call servelt from jsp inside  tag How can I call a servlet from jsp inside an  tag and pass him a parameter ?

I can write  but how to pass him a parameter ?

A: yes You can do that in two ways:

*

*create a function with an ajax call to your servlet.

*point your href to the servlet link (as JB Nizat mentioned)

for the first method, you can follow the below way (if you use jquery) :
function callServer(){
   $.ajax({
            url: 'ServletName',
            type: 'POST',
            data: 'parameter1='+parameter1,
            cache: false,
            success: function (data) {
                //console.log("SERVLET DATA: " + data);
                if (typeof (data) !== 'undefined' && data !== '' && data !== null) {
                    var response = JSON.parse(data);
                    console.log(response);

               }

           },error: function(data){

           };
});

}

and call this function in your  tag like below:

or the much better way like :

you can select the better approach !

A: Using Anchor tag without Ajax like this you can try
click me to send parameter to servlet


Q: Update Field based on another table's Field values i want to update a filed named "outofdate"(type date : 2015-01-14 10:03:11 ) based on another filed name "lastmodification" .
i want to add 10 days to "outofdate" field where :outofdate < NOW() (actual date)
My code is not working:
Update *
`mytable` set outofdate = lastmodification + 84500*10
WHERE  outofdate < NOW( ) LIMIT 0,100

thx in advance!

A: Update *?  That is not valid syntax.  I think the rest is basically ok:
Update mytable
    set outofdate = lastmodification + interval 10 day;
    WHERE outofdate < NOW( )
    LIMIT 0, 100;

Note that the number of seconds in a day is not 84,500.  Also, for date/time data  types, use date_add() or interval addition.


Q: How to replace url hyphen(-) with underscore(_) in CodeIgniter 4 $routes->setTranslateURIDashes(true);
I have tried this method in routes.php file but it's not working. Plz help

A: Add to app/config/Routes.php:
$routes->setTranslateURIDashes(true);


Q: Firebase authentication - onVerificationCompleted and onCodeSent both called I have question which is same as Firebase authentication - I get onVerificationCompleted callback 3s after getting onCodeSent However above question doesn't help me with my problem.
I've following flow in my app.
Signup (Activity)
-> onVerificationCompleted: I redirect user to CreateAccount activity.
-> onCodeSent: I redirect user to OTP screen -> on OTP verified user will be redirected to CreateAccount activity.
Issue/Problem:
I'm getting two call back initially user is redirected to CreateAccount via onVerificationCompleted and after few seconds I get call back of onCodeSent so app automatically opens OTP app.

*

*How to avoid two call backs?

*How to prevent OTP screen in case of onVerificationCompleted called?


Q: Как выполнять программу дальше, если произошла ошибка? $htmlDoct = new DOMDocument();
$htmlDoct->loadHTMLFile($location);
$searchNode = $htmlDoc->getElementById($imgid);
$valueSrc = $searchNode->getAttribute('src');

Cделала программу, которая получает src фото по id, но если src не найдено то $ searchNodet-> getAttribute ( 'src'); останавливает выполнение программы, как выполнять программу дальше если не найден src?

A: Проверять значение, возвращаемое методами getElementById

Возвращаемые значения
Возвращает объект DOMElement или NULL, если элемент не найден.

и getAttribute

Возвращаемые значения
Значение атрибута или пустое значение, если атрибут с указанным именем name не найден.

$htmlDoct = new DOMDocument();
$htmlDoct->loadHTMLFile($location);
$searchNode = $htmlDoc->getElementById($imgid);
if ($searchNode !== null) {
  // нашли элемент
  $valueSrc = $searchNode->getAttribute('src');
  if ($valueSrc !== "") {
    // нашли атрибут
  } else {
    // атрибут отсутствует
  }
} else {
  // элемент отсутствует
}


Q: How to debug what is stopping ping to respond on our server? We used to have a sysadmin person months ago who had disabled ping response on one of our servers. But now we want to re-enable ping response.
I tried to check if the ping was disabled from config. These values are set to 0.
root@dumpty:/mnt/NAS# cat /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
0
root@dumpty:/mnt/NAS# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
0

And here is the sysctl.conf:
root@dumpty:/mnt/NAS# cat /etc/sysctl.conf | grep icmp
#net.ipv4.icmp_echo_ignore_broadcasts = 1
#net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.icmp_echo_ignore_broadcasts = 0
net.ipv4.icmp_echo_ignore_all = 0

The ping is still not working. I know that the server is able to recieve ping because I can see the requests in the tcpdump but I don't see the outgoing responses, examples:
tcpdump capture for ping:
root@dumpty:/mnt/NAS# tcpdump -nni eth0 icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
18:39:45.260686 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 1, length 64
18:39:46.259975 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 2, length 64
18:39:47.260289 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 3, length 64
18:39:48.259971 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 4, length 64
18:39:49.261652 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 5, length 64
18:39:50.261956 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 6, length 64
18:39:51.260058 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 7, length 64
18:39:52.260309 IP 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 8, length 64
^C
8 packets captured
13 packets received by filter
0 packets dropped by kernel

I may be wrong but this is the command I found on web that's supposed to capture incoming packets:
root@dumpty:/mnt/NAS# tcpdump -nni eth0 -e icmp[icmptype] == 8
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
18:40:48.260108 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 64, length 64
18:40:49.260064 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 65, length 64
18:40:50.260119 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 66, length 64
18:40:51.260092 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 67, length 64
18:40:52.260285 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 68, length 64
18:40:53.260465 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 69, length 64
18:40:54.262405 00:10:db:ff:10:01 > bc:30:5b:da:51:a6, ethertype IPv4 (0x0800), length 98: 103.227.98.242 > SEVERIP: ICMP echo request, id 4799, seq 70, length 64
^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel

and this is outgoing
root@dumpty:/mnt/NAS# tcpdump -nni eth0 -e icmp[icmptype] == 0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel

I don't see any outgoing packets, I also checked iptables for any rules blocking icmp
root@dumpty:/mnt/NAS# sudo iptables -L INPUT | grep reject
REJECT     tcp  --  anywhere             anywhere             tcp dpt:9200 reject-with icmp-port-unreachable
REJECT     tcp  --  anywhere             anywhere             tcp dpt:httpflags: FIN,SYN,RST,ACK/SYN #conn src/32 > 15 reject-with tcp-reset
root@dumpty:/mnt/NAS# sudo iptables -L INPUT | grep icmp
REJECT     tcp  --  anywhere             anywhere             tcp dpt:9200 reject-with icmp-port-unreachable
root@dumpty:/mnt/NAS# sudo iptables -L INPUT | grep drop
root@dumpty:/mnt/NAS#

We have a reject on port 9200 but I think it shouldn't be blocking all ports? What else can stop our pings from responding? Did I miss any other config?
I tried my best to debug, any help is much appreciated.
Note: I edited the output of my console and replaced our sever IP with SEVERIP
EDIT:
Adding iptables OUTPUT chain
root@dumpty:/mnt/NAS# sudo iptables -L OUTPUT
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

EDIT2:
root@dumpty:/mnt/NAS# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
root@dumpty:/mnt/NAS# iptables -t raw -vnL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
root@dumpty:/mnt/NAS# iptables -t mangle -vnL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination


Q: Correct way to parse JSON payload with multiple root objects I'm using AFNetworking for my network requests. Assume that I have the following JSON payload:
{
    "car": [{
         "name": "Blue BMW",
         "owner_id": "123"
    }],
    "owners": [{
        "id": "123",
        "name": "John"
    }]
}

What is the correct way to parse that JSON structure considering that the object graph is not persisted using CoreData. Iterating through the owners object to find the owner details for each car would be highly inefficient, so what is a better approach?

A:
Iterating through the owners object to find the owner details for each car would be highly inefficient, so what is a better approach?

O(n^2) is perfectly fine for reasonably small n. On a modern iOS device, you'd have to get into an order of 10k objects for this to even see a performance hit—likely much smaller than what you're being sent back by JSON.
As others mentioned before in comments, and as the old saying goes, "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil".
Just code it. If your app is slow, profile it in instruments. Only then can you really know what the bottlenecks in your application are (humans are generally very bad at guessing a priori)

A: Use NSJSONSerialization class to parse JSON.
Use + (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error
to create  a Foundation object from given JSON data.


Q: Assorting linked list in c i have a list of this struct and i want to sort the list depending on the value
of draw_number, and the list has a pointer front that points to the first struct
of the list and a pointer rear that points on the last struct of the list .I found many codes for sorting a list but i can't do my job for my code. the struct is:
typedef struct itm{
    int draw_number;
    char date[11];
    char temi[6];
    struct itm *next;
}item;

A: Simplest will be bubble sort.
item* sort(item *start){
    item *node1,*node2;
    int temp;
    for(node1 = start; node1!=NULL;node1=node1->next){
        for(node2 = start; node2!=NULL;node2=node2->next){
            if(node2->draw_number > node1->draw_number){
                temp = node1->draw_number;
                node1->draw_number = node2->draw_number;
                node2->draw_number = temp;
            }
        }
    }
return start;
}


Q: Can I set font face by file comments in Emacs? I wonder if we can set the font in Emacs according to the comments in the file.
E.g.

-*- fond: "my-font"; -*-

A: You can use the eval file local variable which can evaluate lisp expressions if you allow it.

A: For full details, see Specifying File Variables
There are two ways to specify file local variable values: in the first line, or with a local variables list. Here's how to specify them in the first line:
 -*- mode: modename; var: value; ... -*-

Here is an example first line that specifies Lisp mode and sets two variables with numeric values:
 ;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-

Instead of using a -*- line, you can define file local variables using a local variables list near the end of the file. The start of the local variables list should be no more than 3000 characters from the end of the file, and must be on the last page if the file is divided into pages.
A local variables list starts with a line containing the string ‘Local Variables:’, and ends with a line containing the string ‘End:’. In between come the variable names and values, one set per line, like this:
 /* Local Variables: */
 /* mode:c           */
 /* comment-column:0 */
 /* End:             */

Note that /*  */  is  only present to mark these lines as comments to the C source code... Emacs looks only for Local Variables: followed on another line by End:


Q: using current session for drupal_http_request() so I'm using drupal_http_request()Docs to fetch another page...the thing is that page is within a logged in area so the function returns the login page instead of the proper page that contains the current session....is there a way to configure drupal_http_request() so that it uses the current session to fetch the page or to pass the session data in?

A: When you want to inject the session into the HTTP request, you must mimic the standard behavior. Depending on how your session works, this means either adding the session cookie or the session get parameter.
drupal_http_request()Docs allows you to specify headers. You can for example build the cookie header for your session and then send it with the request.
To see how the cookie header is build, analyse the request-headers your browser sends to your drupal site, you can do that with firebug. Look for the Cookie: header in the request headers. Note that it can differ depending on server configuration.
You then can add the cookie information to the $headers parameter:
$headers = array('Cookie' => 'your sessionid cookie data');
drupal_http_request($url, $headers);


Q: Remove specific things from given line in bash I am having this below as an output
2017-04-10 12:23:00.307411 IP 124.108.16.209.443 > 192.168.180.3.44526: tcp 1209
2017-04-10 12:23:00.836184 IP 192.168.180.3.43095 > www.facebook.com.443: tcp 303
2017-04-10 12:23:09.948709 IP www.facebook.com.443 > 192.168.180.3.47172: tcp 38
2017-04-10 12:23:09.986789 IP 192.168.180.31.47172 > www.facebook.com.443: tcp 0

and I want output like this,
2017-04-10 12:23:00 IP 192.168.180.3 > www.facebook.com
2017-04-10 12:23:09 IP 192.168.180.31 > www.facebook.com

and importantly want to remove lines which starts with alphabets after IP word and also delete that line which do not starts with 192.168.180 after IP word, basically from above example I only want 2nd and 4th line as output.

A:
to remove lines which starts with alphabets after IP word and also
  delete that line which do not starts with 192.168.180 after IP word

awk approach:
awk '$4!~/^[[:alpha:]]/ && $4~/^192\.168\.180/' file

space is a default field separator in awk.
$4!~/^[[:alpha:]]/:
    $4 - fourth field
    !~ - not matches
    /^[[:alpha:]]/ - regular expression, means "starts with alphabetic characters"
&& - boolean "and" operator.
boolean1 && boolean2 - True if both boolean1 and boolean2 are true.
$4~/^192\.168\.180/ - matches a line if the fourth field starts with 192.168.180

Additional approach:
To strip the unneeded parts of certain columns use the following approach:
awk -v p=".[^.]+$" '$4!~/^[[:alpha:]]/ && $4~/^192\.168\.180/
     {$7=$8="";for(i=2;i<=6;i+=2)gsub(p,"",$i);print}' file

The output:
2017-04-10 12:23:00 IP 192.168.180.3 > www.facebook.com
2017-04-10 12:23:09 IP 192.168.180.31 > www.facebook.com

A: I - - want to remove lines which starts with alphabets after IP word and also means (essentially) the same thing as keep lines which start with numerals and
delete that line which do not starts with 192.168.180 after IP word means to keep lines which have with IP 192.168.180 in them and basically makes the first requirement obsolete. man grep:
DESCRIPTION
       grep searches the named input FILEs for lines containing a match to the
       given PATTERN. - - By default, grep prints the matching lines.

Try:
grep "IP 192.168.180" file
2017-04-10 12:23:00.836184 IP 192.168.180.3.43095 > www.facebook.com.443: tcp 303
2017-04-10 12:23:09.986789 IP 192.168.180.31.47172 > www.facebook.com.443: tcp 0

A: You can try sed, something like this, it just syntax:
sed -e '/pattern here/ { N; d; }'

N and d are the command you can use.
This delete 1 lines after a pattern (including the line with the pattern):
patter= your string
sed -e '/pattern/,+1d' file.txt


Q: Minimum value that not zero In Applescript, I need to find the integer value nearest to zero but not zero. Numbers are all zero or greater than zero. At present, I have three integers.
I guess I could write a loop, but is there an easier way?
examples:
{0,3,4} find 3.
{1,0,0} find 1
{4,10,2} find 2
{0,0,0} find nothing or 0

A: You need to write a loop because, at some point, every item in the list needs to be evaluated, so there's no getting around that (assuming an iterative method; you could, of course, write a recursive algorithm that doesn't contain an explicit loop—I'll illustrate both below).
1. Iteration
The iterative method keeps track of the lowest, non-zero number encountered as we work our way, one-by-one, through each number in the list.  When we reach the end of the list, the tracked value will be the result we're after:
on minimumPositiveNumber from L
    local L

    if L = {} then return null

    set |ξ| to 0

    repeat with x in L
        set x to x's contents
        if (x < |ξ| and x ≠ 0) ¬
            or |ξ| = 0 then ¬
            set |ξ| to x
    end repeat

    |ξ|
end minimumPositiveNumber

get the minimumPositiveNumber from {10, 2, 0, 2, 4} --> 2

2. Recursion
The recursive method compares the first item in the list with the lowest, non-zero value in the rest of the list, keeping the lowest, non-zero value:
on minimumPositiveNumber from L
    local L

    if L = {} then return 0

    set x to the first item of L
    set y to minimumPositiveNumber from the rest of L

    if (y < x and y ≠ 0) or x = 0 then return y

    x
end minimumPositiveNumber

get the minimumPositiveNumber from {10, 2, 0, 2, 4} --> 2


Q: How can i download some of content instead of all content of web page when i click on Save as HTML in browser When I click on save as HTML button its Download all content of web page but i have require to Download some for specific content from all content.

function download(filename, contents) {
  const anchor = document.createElement('a');
  anchor.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(contents));
  anchor.setAttribute('download', filename);
  anchor.style.display = 'none';
  document.body.appendChild(anchor);
  anchor.click();
  document.body.removeChild(anchor);
}

const btn = document.querySelector('#save-btn');

btn.addEventListener('click', (evt) => {
  const container = document.createElement('div');
  const html = document.createElement('html');
  html.innerHTML = document.documentElement.innerHTML;
  container.appendChild(html);
  download('index.html', container.innerHTML);
});

Hello World

<button id="save-btn">Save as HTML</button>

Hello World-1

Hello World-2

Hello World-3

On above HTML Example, when i click on save as HTML Button i have download some of portion of file like download div content instead of all content.
in sort when I open download file it display only this content:

Hello World-1

Hello World-2

Hello World-3

A: To only download the HTML of a specific element, change the logic to select that element instead of the entire body, like this:
document.querySelector('#save-btn').addEventListener('click', e => {
  e.preventDefault();
  let html = document.querySelector('div').outerHTML; // update this selector in your local version
  download('index.html', html);
});

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);
  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();
  document.body.removeChild(element);
}

Working example


Q: Use of new machine learning capability for search problems (reinforcement learning) I work with search algorithms, often of an adversarial nature, and want to understand how to apply Mathematica's machine learning capabilities, especially those new in version  11, to this type of problem.
For example, a simple kind of search is checkers or chess where you want to find the best move. The search tree is too large to fully explore by brute force, so an intelligent method is needed to triage the search and decide what possibilities to search and what possibilities to ignore.
Most of the functions in Mathematica Machine Learning seem to be focused around classification or prediction, so it is not clear how they apply to the search problem. Typically in the search problem there are two key subtasks: SELECTION and EVALUATION. For a given node in the search tree, the system needs to evaluate the node, how good is it? Also, if the search algorithm decides to explore a new path it might have many choices of possible moves to make, how does it prioritize which ones to search first? That is the selection problem. So, ideally I want to understand how to apply Mathematica's machine learning functions to those two tasks, for a problem like searching a move tree in chess or similar game.
Note that in many instances, the relevant paradigm is reinforcement learning. The system learns from playing many games how to improve itself.


Q: Can we provide accumulated bad spam flag statistics to moderators? At the moment, we currently do not provide moderators any visibility into who casts spam and offensive flags. The official reasoning for this is explained in this answer from Shog9. This is kind of hard-rooted at the moment. They do have the ability to see the spam/offensive flag history of a user, but this is only shown when already looking at the user. Thus it would be for confirming suspicions and not finding someone.
Let us take the quote from Jeff Atwood there - we get the names for moderator attention flags so that, if necessary, a dialogue can be established. This is really the root of when we ever attach names to things - when it's usable to do stuff.
I'd like to suggest that in cases where a user is submitting a large number of declined spam and offensive flags, that the moderators have some ability to be told of this information and who is behind it. Example trigger conditions could be a significant number of spam/offensive flags declined within a 30 day period. This kind of aggregation of bad flags is exactly the kind of thing which would spur contact between moderator and user to correct the behavior (much like how we presented flag weight back before it came public), but at the moment there's no way for the moderators to be informed who would be behind it. They'd just have to deal with mountains of bad flags, which is a major hindrance to sites with such large flag volume that spam flags can't always be left to timeout.

A: I think that there should be a list with users that

*

*At least 10 Rejected Flags

*Over 60% of their flags are rejected

This would be helpful to allow moderators to see problematic users. It might also be a good idea to add a special note to flags that are proposed by a user with a recent history of bad flags. Then further investigation could be prompted.


Q: Unable to import the package in jupyter notebook I am unable to import the package in the conda env inside jupyter notebook.
I can import the package via terminal but it's not loading in the notebook.
Can someone help me to debug this?
Update: Tried to add site-packages to path as well as per the suggestions by @Azhar

A: I had a same problem. Solution for me was:

*

*In jupyter print %pip install lasio

*Reset the kernel and start again

That's all. By the way, via conda it didn't work.
Good lick!


Q: How to decrease deletion time in IBM db2 We are using IBM db2, trying to delete 200000 data from different tables, using stored procedure invoked through java code.
It's taking 75+ hours to delete, suggest ways to optimize the deletion time.
we can't stop the log for the deletion.
we can't use the truncate feature.

A: Something like this is one way
/*
 * Example of deleting X rows of data at a time from a table to avoid e.g. transaction log full on row organized talbes
 *
 */

BEGIN
    DECLARE DONE  BOOLEAN DEFAULT FALSE;
    --
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' BEGIN SET DONE = TRUE; END;
    --
    WHILE NOT DONE
    DO
        DELETE FROM (SELECT * FROM MY_TABLE WHERE COL1 = 'A' FETCH FIRST 20000 ROWS ONLY)
        COMMIT;
    END WHILE;
END

You could also consider using MDC tables to allow "rollout" deletion, or other physical design optimizations


Q: How can I define a Java 9 module inside both a source and source-test directories? I'm having a really hard time with some Java modules. I'm working on an old Java project which has been "migrated" to Java 11. Nowhere in the project is there any module-info.java file defined.
I'm getting compilation errors in Eclipse/VS Code, which look like:
The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml

I don't fully understand why it's causing the problem, but I added a module-info.java definition to the root of the module.
module com.company.app {
    requires java.xml;
}

And that compilation error went away. I now have visibility errors everywhere and many, many more than before.
I've started to fix the visibility errors with exports and imports entries as needed, but now I have a problem.
In one of the projects, there is a source and a separate source-test folder. I've defined a module definition in the source folder.
The code in the source-test folder is separate, but has the same package structure. The following code:
import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.experimental.categories.Category;

The import org cannot be resolved. (in the line of the import static).
The type org.junit.Test is not accessible (in the corresponding line)
The type org.junit.experimental.categories.Category is not accessible (once again, in the corresponding line.)
I don't want to add the junit dependency to the main project code, since it's a testing dependency. However, if I define another module-info.java module inside the source-test folder, it complains about the build path containing a duplicate entry 'module-info.java'.
How can the dependencies and modules be correctly defined?


Q: Why have I to write c - '0' instead of just c? Hey I can't understand why my code doesn't write when I put just ++ndigit[c] (instead of ++ndigit[c -'0'], then with ++nchar[c] it's ok.
If you have any tuto I'll be really interested !
#include <stdio.h>

int main()
{
  int c, i, y, ns;
  int ndigit[10];
  int nchar[26];

  ns = 0;

  for(i = 0; i >= 0 && i<= 9; ++i) {
    ndigit[i] = 0;
  }

  for(y = 'a'; y <= 'z'; ++y) {
    nchar[y] = 0;
  }

  while((c = getchar()) != EOF) {
    if(c == ' ' || c == '\t') {
      ++ns;
    }

    if(c >= 'a' && c <= 'z') {
      ++nchar[c];
    }

    if(c >= '0' && c <= '9') {
     ++ndigit[c];
     //++ndigit[c-'0'];
    }

    if(c == '\n') {
      printf("chiffres: ");
      for(i=0;i<10;++i) {
        printf("%d:%d ", i, ndigit[i]);
      }

      printf("lettres: ");
      for(y='a';y<='z';++y) {
        printf("%d:%d ", y, nchar[y]);
      }
      printf("space: %d\n", ns);
    }
  }
}

A: Actually when you set the variable to c='0', it means that the value of c is now the ascii value of '0' and that is = 48.
Since you are setting the value of c to 48 but the array size is 10, your code will get a runtime exception because you are trying to access an index that doesn't even exist.
Remember when you use '0' it means character. So setting this value to an int variable makes the value equals to the ascii value of that character. Instead you can use c=0 directly.

A: Because the character '4' (for example) is usually not equal to the integer 4. I.e. '4' != 4.
Using the most common character encoding scheme ASCII, the character '4' has the value 52, and the character '0' has the value 48. That means if you do e.g. '4' - '0' you in practice to 52 - 48 and get the result 4 as an integer.


Q: Share project between Windows Store Application And WCF Service Is it possible to create and "share" a class library project between an Windows Store Application and WCF Service project ?
I created Windows Store Application project and WCF Service project. Now, both projects should  refer a Class library project.
If I create a regular Class Library project, the WCF Service project can refer it.
But when I add the reference to the Windows Store Application Visual Studio 2012 says :

Unable to add the reference to project XXX

So I decided to replace the regular Class Library project by a Class Library(Windows Store apps).
Now the Windows app project can refer the Class Library(Windows Store apps).
But when I add the reference to the WCF Service Visual Studio says :

Unable to add the reference to project XXX

A: To share code between the two projects create a Portable Class Library (PCL) project and reference it in the two projects.
Make sure you choose the right .Net framework (for compatibility with WCF project).


Q: How to use the find command in Java Wanted to know if there is a find functionality in Java.
Like in Linux we use the below command to find a file :
find / -iname <filename> or find . -iname <filename>

Is there a similar way to find a file in Java? I have a directory structure and need to find certain files in some sub directories as well as sub-sub directories.
Eg: I have a package abc/test/java
This contains futher directories say
abc/test/java/1/3 , abc/test/java/imp/1, abc/test/java/tester/pro etc.

So basically the abc/test/java package is common and it has a lot of directories inside it which contain a lot .java files.
I need a way to obtain the absolute path of all these .java files.

A: You can use unix4j
Unix4jCommandBuilder unix4j = Unix4j.builder();
List<String> testClasses = unix4j.find("./src/test/java/", "*.java").toStringList();
for(String path: testClasses){
    System.out.println(path);
}

pom.xml dependency:
<dependency>
    <groupId>org.unix4j</groupId>
    <artifactId>unix4j-command</artifactId>
    <version>0.3</version>
</dependency>

Gradle dependency:
compile 'org.unix4j:unix4j-command:0.2'

A: You probably do not have to re-invent the wheel because library named Finder already implements the functionality of Unix find command: https://commons.apache.org/sandbox/commons-finder/

A: Here's a java 8 snippet to get you started if you want to roll your own. You might want to read up on the caveats of Files.list though.
public class Find {

  public static void main(String[] args) throws IOException {
    Path path = Paths.get("/tmp");
    Stream<Path> matches = listFiles(path).filter(matchesGlob("**/that"));
    matches.forEach(System.out::println);
  }

  private static Predicate<Path> matchesGlob(String glob) {
    FileSystem fileSystem = FileSystems.getDefault();
    PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + glob);
    return pathMatcher::matches;
  }

  public static Stream<Path> listFiles(Path path){
    try {
        return Files.isDirectory(path) ? Files.list(path).flatMap(Find::listFiles) : Stream.of(path);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
  }
}


Q: Linkedin authentication request error so I'm implementing the option to login with your linkedin account, but I find that sometimes you will get a request error saying:

Request Error
We’re sorry, there was a problem with your request. Please make sure you have cookies enabled and try again.
Or follow this link to return to the home page.

So I did some digging and I found that this error pops up if you don't have a certain cookie from linkedin called JSESSIONID. This is only created when you go to linkedin.com, but not my extension authentication page. Anyone have an explanation and a solution?
Thanks

A: Here is a work around:
link to an approved solution
it provides a java implementation, and they point out it is more about the version of the library you are using.
hopefully it helps.


Q: How to combine several list and create dataframe pandas I have list that contains something like this:
[] [['a' 'b' 5] ['c' 'd' 2]] []
I don't understand, how to combine these several lists in one list and exclude empty lists. Finally, I need to get Data Frame with 3 columns.

A: You can do something like this-
from functools import reduce
nested_list = [[], ['a','b',5],['c', 'd', 2], []]
merged_list = reduce((lambda x, y:x+y), nested_list)

This solution applies for single level down type nested lists([[a,b,c],[x,y,z]]).
If you can provide what type of list you want to be merged I can provide a solution for that. For now, I have assumed it's just a single level down nested list.

A: Assuming the desired output will be looked like this:
col1    col2           col3
NaN     ['a' 'b' 5]    NaN
NaN     ['c' 'd' 2]    NaN

And currently you are having the following list at your hands:
>>>a_list
   [[], [['a' 'b' 5], ['c' 'd' 2]], []]

Then you can do the following to create the DataFrame:
>>>import pandas as pd
>>>import numpy as np
>>>df = pd.DataFrame(columns=['col1','col2','col3'])
>>>a_list = [[], [['a' 'b' 5], ['c' 'd' 2]], []]
>>>for i in range(len(df.columns.tolist())):
...    try:
...        df[df.columns[i]] = a_list[i]
...    except:
...        df[df.columns[i]] = np.nan
>>>df
  col1       col2 col3
0  NaN  [a, b, 5]  NaN
1  NaN  [c, d, 2]  NaN


Q: Virtualbox- Can't set up 2nd adapter to network, even though VM is powered off I am trying to add a 2nd adapter to my VM so that I can ping to my VM from another computer, but so far I've been unsuccessful.  The specific problem I am having is that, when I click "Enable Network Adapter" under the "Adapter 2" tab, and I select "Host-only Adapter next to the "Attached to:" dropdown, I am not given any options besides "Not selected" in the "Name" dropdown.
I saw this answer, but my VM was already off when I tried to add the new adapter.
UPDATE: See screenshot:

A: Before being able to select a host-only network, you need to create one:

*

*from the CLI,
VBoxManage hostonlyif create

*from the GUI, File -> Preferences -> Network -> Host-only network -> (+)Add host-only network


Q: Looking to convert an console app to a asap.net web form I currently have this console app that extracts words from an image using Microsoft's Optical Character Recognition (OCR). the results currently post into a console app, I want to create the same thing but for a web page form. What's the best way to do that? Can I use a list box or a label to show the results instead of console.writeline?
here's the code for the console app
static class Program{

    // Add your Computer Vision subscription key and endpoint to your environment variables.
    const string subscriptionKey = ("********");    const string endpoint = ("https://wesam.cognitiveservices.azure.com/");

    // the OCR method endpoint
    static string uriBase = endpoint + "vision/v2.1/ocr";

    static async Task Main()
    {
        // Get the path and filename to process from the user.
        Console.WriteLine("Optical Character Recognition:");
        Console.Write("Enter the path to an image with text you wish to read: ");
        string imageFilePath = @"C:\Users\alabe\Downloads\Syria.jpg";

        if (File.Exists(imageFilePath))
        {
            // Call the REST API method.
            Console.WriteLine("\nWait a moment for the results to appear.\n");
            await MakeOCRRequest(imageFilePath);
        }
        else
        {
            Console.WriteLine("\nInvalid file path");
        }
        Console.WriteLine("\nPress Enter to exit...");
        Console.ReadLine();
    }

    /// <summary>
    /// Gets the text visible in the specified image file by using
    /// the Computer Vision REST API.
    /// </summary>
    /// <param name="imageFilePath">The image file with printed text.</param>
    static async Task MakeOCRRequest(string imageFilePath)
    {
        try
        {
            HttpClient client = new HttpClient();

            // Request headers.
            client.DefaultRequestHeaders.Add(
                "Ocp-Apim-Subscription-Key", subscriptionKey);

            // Request parameters.
            // The language parameter doesn't specify a language, so the
            // method detects it automatically.
            // The detectOrientation parameter is set to true, so the method detects and
            // and corrects text orientation before detecting text.
            string requestParameters = "language=unk&detectOrientation=true";

            // Assemble the URI for the REST API method.
            string uri = uriBase + "?" + requestParameters;

            HttpResponseMessage response;

            // Read the contents of the specified local image
            // into a byte array.
            byte[] byteData = GetImageAsByteArray(imageFilePath);

            // Add the byte array as an octet stream to the request body.
            using (ByteArrayContent content = new ByteArrayContent(byteData))
            {
                // This example uses the "application/octet-stream" content type.
                // The other content types you can use are "application/json"
                // and "multipart/form-data".
                content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");

                // Asynchronously call the REST API method.
                response = await client.PostAsync(uri, content);
            }

            // Asynchronously get the JSON response.
            string contentString = await response.Content.ReadAsStringAsync();

            // Display the JSON response.
            Console.WriteLine("\nResponse:\n\n{0}\n",
                JToken.Parse(contentString).ToString());

            Rootobject r = JsonConvert.DeserializeObject<Rootobject>(contentString);

            foreach (Region region in r.regions)
            {
                foreach (Line line in region.lines)
                {
                    foreach (Word word in line.words)
                    {
                        Console.WriteLine(word.text);
                        Console.Write("");
                    }
                    Console.WriteLine();
                }

            }
        }
        catch (Exception e)
        {
            Console.WriteLine("\n" + e.Message);
        }
    }

    /// <summary>
    /// Returns the contents of the specified file as a byte array.
    /// </summary>
    /// <param name="imageFilePath">The image file to read.</param>
    /// <returns>The byte array of the image data.</returns>
    static byte[] GetImageAsByteArray(string imageFilePath)
    {
        // Open a read-only file stream for the specified file.
        using (FileStream fileStream =
            new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
        {
            // Read the file's contents into a byte array.
            BinaryReader binaryReader = new BinaryReader(fileStream);
            return binaryReader.ReadBytes((int)fileStream.Length);

        }

    }

}

A: Instead of chasing down Web Forms, try using Blazor and .Net Core. You still get to re-use your existing C# code. Quick tutorial here: Blazor Tutorial
Starting a new Blazor app (provided you have .Net core installed) is as simple as running one of the following commands from powershell in a folder of your choosing.
//serverside (renders views on server and syncs to client)
dotnet new blazorserver

//clientside (c# is transpiled to webassembly and runs purely in client browser - still finicky but YMMV)
dotnet new blazorwasm

You could use that existing working project as a springboard to learn a new technology, and gets you up and running fast.
I have followed the following article for getting file uploads, and you could customize example to get image bytes. blazor-inputfile


Q: Combine JSON decoding pipeline, when response can be an array or an object at runtime I have an API that may return a JSON array of JSON objects or a single JSON object.
How do I write a combine publisher pipeline that handles this case?
I normally hard-code the type of the JSON-response when I add my combine decode operator to my pipeline:
.decode(type: [MyArrayType].self, decoder: JSONDecoder())
.decode(type: MyObjectType.self, decoder: JSONDecoder())

A: It's definitely possible to update the publisher chain and to try to decode an array of [SomeDecodable], and failing that, fallback on decoding the SomeDecodable itself.
The pattern would be to wrap it in a FlatMap, and to deal with a failure inside of it.
So, let's say you have some upstream publisher with an output of Data and failure of Error, and you're trying to decode some generic type T: Decodable, this could be a way to approach:
upstream
  .flatMap { data in
     Just(data)
       // attempt to decode as [T]
       .decode(type: [T].self, decoder: JSONDecoder())
       // if successful, publish each element one-by-one
       .flatMap { arr -> AnyPublisher<T, Error> in
           Publishers.Sequence(sequence: arr).eraseToAnyPublisher()
       }
       // if error, attempt to decode as T, possibly failing
       .tryCatch { _ in Just(data).decode(type: T.self, decoder: JSONDecoder()) }
  }
  // this will be an AnyPublisher<T, Error>
  .eraseToAnyPublisher()


Q: How to import normalised json data from several files into a pandas dataframe? I have json datafiles in several directories that I want to import into Pandas to do some data analysis. The format of the json depends on the type defined in the directory name. For example,
dir1_typeA/
  file1
  file2
  ...
dir1_typeB/
  file1
  file2
  ...
dir2_typeB/
  file1
  ...
dir2_typeA/
  file1
  file2

Each file contains a complex nested json string that will be a row of the DataFrame. I will have two data frames for each TypeA and TypeB. Later on I will append them if needed.
So, far I've got all the files paths I need with os.walk and am trying to go through
    import os
    from glob import glob

    PATH = 'dir/filepath'
    files = [y for x in os.walk(PATH) for y in glob(os.path.join(x[0], 'file*'))]

    for file in files:
        with open(issuefile, 'r') as f:
            data = f.read()

        data_json = json_normalize(json.loads(data))
        type = ' '.join(issuefile.split('/')[3]
        data_json['type'] = type
        # append to data frame for typeA and typeB
        if 'typeA' in type:
            # append to typeA dataframe
        else:
            # append to typeB dataframe

There is one added issue, which is files inside a directory may have slightly different fields. For example, file1 may have a few more fields that file2 in dir1_typeA. So, I need to accommodate that dynamic nature in data frame for each type as well.
How do I create these two dataframes?

A: I think you should concatenate the files together first before you read them into pandas, here is how you'd do it in bash (you could also do it in Python):
cat `find *typeA` > typeA
cat `find *typeB` > typeB

Then you can import it into pandas using io.json.json_normalize:
import json
with open('typeA') as f:
    data = [json.loads(l) for l in f.readlines()]
    dfA = pd.io.json.json_normalize(data)

dfA

#          that this.first this.second
# 0  otherthing      thing       thing
# 1  otherthing      thing       thing
# 2  otherthing      thing       thing


Q: Composition and Limits Suppose that $f$ is a continuously differentiable function with $\lim_{x \rightarrow \infty} f(x)=k$ and $g$ is a Lipschitz continuous function. Prove that $\lim_{x \rightarrow \infty} g(x,f(x))-g(x,k)=0$.

A: Let $C$ be a Lipschitz constant for $g$ and let $\epsilon > 0$. Then, since $\lim_{x \to \infty}f(x)=k$, there is some $M>0$ such that $$x > M \quad \implies\quad  |f(x)-k|<\frac{\epsilon}{C}.$$ It follows that
$$x > M \quad \implies\quad |g(x,f(x))-g(x,k)| \leq C|f(x)-k| < C\frac{\epsilon}{C}= \epsilon,$$
i.e. $\lim_{x \to \infty}g(x,f(x))-g(x,k)=0$.


Q: accessing images I am new to Symfony.
I created a layout page in which I have this :

but the image isn't displayed in the page when accessed from the browser.
I put the file header.jpg in the web/images/ folder.
I thought I could learn Symfony in a week while working on a small project. is it possible ?

A: Use slash at the beginning like

You can also use image_tag (which is better for routing)
image_tag('/images/header.jpg', array('alt' => __("My image")))

In the array with parameters you can add all HTML attributes like width, height, alt etc.
P.S. IT's not easy to learn Symfony. You need much more time

A: If you don't want a fully PHP generated image tag but just want the correct path to your image, you can do :
<img src="<?php echo image_path('header.jpg'); ?>"> width="700" height="228" alt="" />

Notice that the path passed to image_path excludes the /images part as this is automatically determined and created for you by Symfony, all you need to supply is the path to the file relative to the image directory.
You can also get to your image directory a little more crudely using
sfConfig::get('sf_web_dir')."/images/path/to/your/image.jpg"

It should be noted that using image_tag has a much larger performance cost attached to it than using image_path as noted on thirtyseven's blog
Hope that helps :)


Q: Distributed mutex There are hundreds of servers in our cloud. There is a script which can be invoked at any time by any of these servers. I have to make sure that at any given time only one server is running the script. While one server has acquired lock on the script, and another server tries to execute, just write to a log file and exit. There can be multiple such scripts, each having a separate mutex lock. That means I want a solution which accommodates multiple servers multiple scripts. I am looking for a very simple solution. Please point to me to any available tool or suggest me on popular ways of implementing this.

A: Do you mean you want to implement something yourself like a single server which controls the locks for each script?
All your others servers would have to ask it for 'permission' to run the script and then inform it when they are done, probably with some timeout check mechanism also. You would need to think about having some high availability mechanism to ensue your 'lock controller' server does not become a single point of failure for the entire system. Also, you may want to check if you will need to queue requests rather than just existing - even if it is not a requirement now, if it is likely to become one it might be easier to design for it from the start.
Some common approaches are listed in the answers to these question here - the questions are a bit old but I think still relevant:
Distributed Lock Service
What are some good ways to do intermachine locking?


Q: Why is my SPARQL query so slow? I'm trying to fetch a number of queries from the database of the EU plenary debates through a SPARQL interface (Interface here, schema here). As I do that I would like to retrieve the names of the speaker, their home country and their partyname.
This takes me 5 minutes to complete for each agenda item, which seems slow. Am I making any obvious mistakes in my query that is slowing it down?
SELECT ?text (SAMPLE(?speaker) AS ?speaker) (SAMPLE(?given) AS ?given) (SAMPLE(?surname) AS ?surname) (SAMPLE(?acronym) AS ?country) (SAMPLE(?partyLabel) AS ?partyLabel) (SAMPLE(?type) AS ?type)
WHERE {
   <http://purl.org/linkedpolitics/eu/plenary/2010-12-16_AgendaItem_4> dcterms:hasPart ?speech.
   ?speech lpv:speaker ?speaker.
   ?speaker foaf:givenName ?given.
   ?speaker foaf:familyName ?surname.
   ?speaker lpv:countryOfRepresentation ?country.
   ?country lpv:acronym ?acronym.
   ?speech lpv:translatedText ?text.
   ?speaker lpv:politicalFunction ?func.
   ?func lpv:institution ?institution.
   ?institution rdfs:label ?partyLabel.
   ?institution rdf:type ?type.
   FILTER(langMatches(lang(?text), "en"))
} GROUP BY ?text

Note, changing ?speech lpv:translatedText ?text. to ?speech lpv:textt ?text. reduces query time to 30 seconds.

A: There doesn't look to be anything particularly wrong with your SPARQL query and you have made no obvious mistakes (other than some syntax validity issues which I discuss later)
The problem appears to be that the SPARQL service you are using uses a triple store that doesn't cope with queries with large numbers of joins very well. When experimenting with your query moving the triple patterns around produced a Stack Overflow in the SPARQL service!
I would suggest downloading the data yourself from http://linkedpolitics.ops.few.vu.nl/home - there are links under point 3 of the About the Data section from which you can download the data yourself.  You can then load it into the triple store of your choice and run your query against that instead.
For example I downloaded the data and put it into Apache Jena Fuseki (disclaimer - I work on the Apache Jena project) and was able to run the query almost instantaneously after I fixed the query to be proper valid SPARQL.
Making the Query valid SPARQL
The query as given is not strictly valid SPARQL so you'll need to correct it in order to run it elsewhere.
Firstly the various prefixes used are not defined by the query because the service you are using inserts them automatically, to run this query against another triple store you'll need to add the following to the start of the query:
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX lpv: <http://purl.org/linkedpolitics/vocabulary/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

It is also not legal to perform a variable assignment where the variable name given is already in scope e.g. (SAMPLE(?speaker) AS ?speaker) so those need to change:
(SAMPLE(?speaker) AS ?speaker1)

Which results in the following valid and portable SPARQL query:
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX lpv: <http://purl.org/linkedpolitics/vocabulary/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?text (SAMPLE(?speaker) AS ?speaker1) (SAMPLE(?given) AS ?given1) (SAMPLE(?surname) AS ?surname1) (SAMPLE(?acronym) AS ?country1) (SAMPLE(?partyLabel) AS ?partyLabel1) (SAMPLE(?type) AS ?type1)
WHERE {
   <http://purl.org/linkedpolitics/eu/plenary/2010-12-16_AgendaItem_4> dcterms:hasPart ?speech.
   ?speech lpv:speaker ?speaker.
   ?speaker foaf:givenName ?given.
   ?speaker foaf:familyName ?surname.
   ?speaker lpv:countryOfRepresentation ?country.
   ?country lpv:acronym ?acronym.
   ?speech lpv:translatedText ?text.
   ?speaker lpv:politicalFunction ?func.
   ?func lpv:institution ?institution.
   ?institution rdfs:label ?partyLabel.
   ?institution rdf:type ?type.
   FILTER(langMatches(lang(?text), "en"))
} GROUP BY ?text