Insert and Update an array of dynamic length into a table

Question: My table is
(id int,property varchar)

Suppose I want to insert {3, 'a, b, c'}. How can I do it in a stored procedure?
The table entry would be:
id property
3   a
3   b
3   c

Also when i want to update my id=3 row by {3, 'ab, b, bg, ht'} . What would be the stored procedure for this insert and update operation? My table entries should become
id property
3   ab
3   b
3   bg
3   ht

Comment: the edition is not right. It changed the initial idea. Should be {3, 'a, b, c'}
Comment: It means my id is 3 and property is {a,b,c}. three table entries for each property item.
Comment: I tried solving the above problem by first deleting the matched rows and then inserting the new rows. I was looking for an efficient approach to solve it. And answer by t-clausen.dk by use of 'merging' is quite appropriate for my problem.Kindly re-open my problem as it enlightens the approach of merging in sql as well.
Answer: sample table:
create table yourtable (id int,property varchar(5))

Procedure for that table:
create procedure p_test
(
@id int,
@prolist varchar(2000)
) as
begin
;with x as
(
  SELECT * FROM yourtable WHERE id = @ID
)
MERGE INTO
x t1
using
(SELECT @id id, ltrim(t.c.value('.', 'VARCHAR(2000)')) property
FROM (
    SELECT x = CAST('<t>' +
        REPLACE(@prolist, ',', '</t><t>') + '</t>' AS XML)
) a
CROSS APPLY x.nodes('/t') t(c))  t2 on t1.id = t2.id and t1.property = t2.property
when not matched then INSERT (id,property)
VALUES(t2.id, t2.property)
when matched
THEN UPDATE SET t1.id = t2.id
WHEN NOT MATCHED BY SOURCE THEN DELETE
;
end

Testing:
exec p_test 3, 'b,c'
select * from yourtable
exec p_test 3, 'a,b,c'
select * from yourtable
exec p_test 3, 'a,c'
select * from yourtable
exec p_test 4, 'g,h'
select * from yourtable

Result:
id  property
3   b
3   c

id  property
3   b
3   c
3   a

id  property
3   c
3   a

id  property
4   g
3   c
3   a
4   h

EDIT:
in order to update a new column use this table:
create table yourtable (id int,property varchar(5), is_active bit default 1)

Use this procedure:
alter procedure p_test
(
@id int,
@prolist varchar(2000)
) as
begin
;with x as
(
  SELECT * FROM yourtable WHERE id = @ID
)
MERGE INTO
x t1
using
(SELECT @id id, ltrim(t.c.value('.', 'VARCHAR(2000)')) property
FROM (
    SELECT x = CAST('<t>' +
        REPLACE(@prolist, ',', '</t><t>') + '</t>' AS XML)
) a
CROSS APPLY x.nodes('/t') t(c))  t2 on t1.id = t2.id and t1.property = t2.property
when not matched then INSERT (id,property, is_active)
VALUES(t2.id, t2.property, 1)
when matched
THEN UPDATE SET t1.id = t2.id, is_active = 1
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET t1.is_active = 0
;
end

Comment: thanks a lot. One small query , can u please give the idea behind the merging. Also if 'my_table' had a column is_active and instead of deleting the row when not matched by source ,I want to update  is_active to 0. How to do it?
Comment: :Any help on above query?
Comment: @zooney that is a good question. I don't know right now. It may be necessary to make another expression inthe stored procedure
Answer: First one:
insert into <tableName>(id, property) values(3, 'a');
insert into <tableName>(id, property) values(3, 'b');
insert into <tableName>(id, property) values(3, 'c');

Second issue:
update <tableName> set property='ab' where property = 'a';
update <tableName> set property='bg' where property = 'c';
insert into <tableName>(id, property) values(3, 'ht');

And now, a question: are you sure this is what your problem needs? Usually, when we call a column id we want it to be an identifier, that is, unique for each row. This may be a little bit off topic, but just in case...
Comment: :well above scenario is just an example. the data would be dynamic.
Comment: @zooney I understand. Then try those queries, they should work. Substitute your table name for  and give it a go.
Answer: There should be an id/primary key which will be unique. Profide any unique field and update records on the base of that unique field. Or you can make property unique or pair of id and property unique.
Comment: This is the case normally. However it is perfectly possible to do what the OP wants, though admittedly quite awkward.
Answer: If I understood well, you could do something similar to this:
  Insert INTO @tempTable
  SELECT 3, * FROM dbo.splitstring('a,b,c,d')

It's just a pseudocode and you should do it inside your stored procedure.
If this is the right approach you have to take a look at this: T-SQL split string


Can I use 1/4" plywood subfloor with 1/2" cement board to tile my bathroom?

Question: Believe it or not, I pulled up the hardwood floor in my bathroom and the subfloor is 1/4" plywood. If I put a good mortar on top of that plywood and use a 1/2" cement board on top of that, will that be a sufficient support for new tile? I'll of course use more mortar over the cement board.
Comment: I'd be willing to bet that your subfloor is nominally 3/8" plywood (something like 11/32 actual). 1/4" just doesn't make sense (not that 3/8" is much better).
Answer: No, presuming this is not on a concrete slab.
Are you sure that the subfloor is 1/4"? I don't think you can even walk on that without going right through. I would think it is more likely an underlayment.
You need minimum of 3/4" subfloor with the cement board on top to ensure the deflection is not large enough for those tiles to quickly pop off from the flex. You really don't want anything less than 9/8" (1" and 1/8") of flooring under the tile and the floor should not really have a "bounce" to it.
I had an old house that I wanted to tile the kitchen in and had to reinforce the joists to get it stiff enough to do a 3/4" subfloor + cement board for the tiles, so it's not just about the subfloor/underlayment/cement board.

Can I use 1/4” plywood subfloor with 1/2” cement board to tile my bathroom?


Boost.log - Get current file name when using file rotation

Question: I know that this question may be a duplicate but I want to know whether there is still no possibility to get the current log file name when there is a file backend with filename rotation?!
Thanks in advance.
Edit:
With filename rotation I mean something like the following where the filename changes when the log file gets rotated:
auto fileSink = logging::add_file_log(
    keywords::file_name = "..\\Logs\\%Y%m%d_Tracing_%H%M%S.log",
    keywords::rotation_size = 2 * 1024 * 1024,
    keywords::min_free_space = 15 * 1024 * 1024,
    keywords::open_mode = std::ios_base::app);

Comment: It's a property of the backend. If you use the `add_file_log` from utility/setup/file.hpp then you never see the backend. Instead you just get the `sink` which is probably what you need 80% of the time. I looked at [`aux::add_file_log` implementation](https://www.boost.org/doc/libs/1_75_0/boost/log/utility/setup/file.hpp) but it looks strongly like the backed is left undocumented on purpose
Answer: As sehe mentioned:

It's a property of the backend.

Therefor I managed to separate the sink initialization from the corresponding backend:
typedef sinks::synchronous_sink<sinks::text_file_backend> fileSink;
boost::shared_ptr<fileSink> fileSinkSink;
fileSinkSink = logging::add_file_log(
    keywords::file_name = "..\\Logs\\%Y%m%d_Tracing_%H%M%S.log",
    keywords::rotation_size = 2* 1024 * 1024,
    keywords::min_free_space = 15 * 1024 * 1024,
    keywords::open_mode = std::ios_base::app);

Now I figured out that I can access the backend and thereby the current file name:
char currentFileName[200] = "";
strcpy(currentFileName, fileSinkSink->locked_backend().get()->get_current_file_name().string().c_str());

Thanks for that hint! It solved my problem!


Problems establishing serial connection with beagle bone black on ttyUSB0

Question: I have tried using minicom, Putty, screen and cKermit to no avail.   It looks as if the connection is intermittent from the output of dmesg | grep tty.
[1627865.078080] usb 5-2: Product: AM335x USB
[1627865.078086] usb 5-2: Manufacturer: Texas Instruments
[1627865.152124] rndis_host 5-2:1.0: usb0: register 'rndis_host' at usb-0000:00:13.0-2, RNDIS device, 9a:1f:85:1c:3d:0e
[1627865.398299] userif-2: sent link down event.
[1627865.398309] userif-2: sent link up event.<6>[1627905.546191] usb 5-2: USB disconnect, device number 41
[1627905.547204] rndis_host 5-2:1.0: usb0: unregister 'rndis_host' usb-0000:00:13.0-2, RNDIS device
[1627905.748089] userif-2: sent link down event.
[1627905.748098] userif-2: sent link up event.<6>[1627910.599519] usb 5-2: new full-speed USB device number 42 using ohci_hcd
**[1627910.758329] usb 5-2: not running at top speed; connect to a high speed hub
[1627910.768319] usb 5-2: New USB device found, idVendor=0451, idProduct=6141
[1627910.768331] usb 5-2: New USB device strings: Mfr=33, Product=37, SerialNumber=0
[1627910.768340] usb 5-2: Product: AM335x USB
[1627910.768346] usb 5-2: Manufacturer: Texas Instruments
[1627910.842502] rndis_host 5-2:1.0: usb0: register 'rndis_host' at usb-0000:00:13.0-2, RNDIS device, 9a:1f:85:1c:3d:0e
[1627911.082551] userif-2: sent link down event.
[1627911.082555] userif-2: sent link up event.<6>[1627921.042308] usb 5-2: USB disconnect, device number 42
[1627921.043378] rndis_host 5-2:1.0: usb0: unregister 'rndis_host' usb-0000:00:13.0-2, RNDIS device**
[1627921.243451] userif-2: sent link down event.
[1627921.243461] userif-2: sent link up event.<6>[1627925.167815] usb 5-2: new full-speed USB device number 43 using ohci_hcd
[1627925.326657] usb 5-2: not running at top speed; connect to a high speed hub
[1627925.336645] usb 5-2: New USB device found, idVendor=0451, idProduct=6141
[1627925.336658] usb 5-2: New USB device strings: Mfr=33, Product=37, SerialNumber=0
[1627925.336666] usb 5-2: Product: AM335x USB
[1627925.336673] usb 5-2: Manufacturer: Texas Instruments
[1627925.411023] rndis_host 5-2:1.0: usb0: register 'rndis_host' at usb-0000:00:13.0-2, RNDIS device, 9a:1f:85:1c:3d:0e
[1627925.665530] userif-2: sent link down event.
[1627925.665540] userif-2: sent link up event.<3>[1627960.208500] hub 5-0:1.0: unable to enumerate USB device on port 3
[1627960.448125] usb 2-3: new high-speed USB device number 51 using ehci_hcd
[1627960.581809] usb 2-3: New USB device found, idVendor=14cd, idProduct=121f
[1627960.581814] usb 2-3: New USB device strings: Mfr=1, Product=3, SerialNumber=2
[1627960.581816] usb 2-3: Product: Mass Storage Device
[1627960.581818] usb 2-3: Manufacturer: Generic
[1627960.581820] usb 2-3: SerialNumber: 121F20110712
[1627960.582540] scsi32 : usb-storage 2-3:1.0
[1627961.579368] scsi 32:0:0:0: Direct-Access     Mass     Storage Device   1.00 PQ: 0 ANSI: 0 CCS
[1627961.580592] sd 32:0:0:0: Attached scsi generic sg3 type 0
[1627961.871287] sd 32:0:0:0: [sdc] 15644672 512-byte logical blocks: (8.01 GB/7.45 GiB)
[1627961.871786] sd 32:0:0:0: [sdc] Write Protect is off
[1627961.871799] sd 32:0:0:0: [sdc] Mode Sense: 03 00 00 00
[1627961.872313] sd 32:0:0:0: [sdc] No Caching mode page found
[1627961.872325] sd 32:0:0:0: [sdc] Assuming drive cache: write through
[1627961.875901] sd 32:0:0:0: [sdc] No Caching mode page found
[1627961.875913] sd 32:0:0:0: [sdc] Assuming drive cache: write through
[1627961.876801]  sdc: sdc1 sdc2
[1627961.883007] sd 32:0:0:0: [sdc] No Caching mode page found
[1627961.883019] sd 32:0:0:0: [sdc] Assuming drive cache: write through
[1627961.883028] sd 32:0:0:0: [sdc] Attached SCSI removable disk
[1627987.679657] usb 5-2: USB disconnect, device number 43
[1627987.680127] rndis_host 5-2:1.0: usb0: unregister 'rndis_host' usb-0000:00:13.0-2, RNDIS device
[1627987.880125] userif-2: sent link down event.
[1627987.880135] userif-2: sent link up event.<6>[1636287.932125] usb 2-3: USB disconnect, device number 51
[1636372.495480] usb 5-3: new full-speed USB device number 45 using ohci_hcd
[1636372.673303] usb 5-3: New USB device found, idVendor=0403, idProduct=6001
[1636372.673316] usb 5-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3

It looks like it is connected from this output but when I try to connect to /dev/ttyUSB0 it doesn't recognize ttyUSB0.
I have tried changing the permissions also like it was suggested in another post to no avail.  When I am trying to connect with Putty at /dev/ttyUSB0 with a speed of 115200 baud nothing happens visually when I click connect.
I am also using moserial but I do not see USB0 in it's drop down.  Any hints or direction on where to search is greatly appreciated?
Answer: According to the  beaglebone support site you do not need any special drivers for it to work on linux, but you might need to run the script (mkudevrule.sh) they provide to create some udev rules. And check your USB cable for proper contact (I know it sound trivial but it only takes a few seconds to check and can save you lots of hours of troubleshooting.)
Comment: Thanks.  Using `mkudevrule.sh` fixed my issue.
Answer: I had the same issue, turned out to be the mini-usb cable (probably wasn't providing enough power). You may want to try with the shortest cable you find.


Can I safely sell everything marked as "Treasure" in Resident Evil Village?

Question: I've collected a few pieces of treasure from my time in RE8. Some of it, like crystal skulls, can obviously be sold to the Duke because it drops from common enemies.
On one corpse I found an item called "Ingrid's Necklace" which seems it could be used in a puzzle later on. I've found other treasures that seem like they could be more than just trinkets, but I haven't found a clear use for them in there same way that Key Items can be used.
That raises the question? Can I sell these intriguing treasures for Lei and not a risk failing a puzzle? Or should I hold on to them because the Village is a dangerous place and I never know what supplies I'll need?
Comment: FWIW if you haven't worked it out by now Ingrid's Necklace is not in the treasures menu but the key items. Might be worth examining it....
Comment: Are you thinking of Luiza's necklace? Ingrid's necklace is in the treasures menu
Comment: Oh Luiza's, yeah... woops
Answer: No treasures ever act as keys later on, so you can sell every treasure without locking yourself out of any puzzles.
However, some treasures marked as combinable can be combined with others for more money, so you don't always want to instantly sell every treasure.
Comment: @PausePause On the menu that shows your treasures, treasures that can be combined have a "combinable" descriptor. Any treasure that's combinable can be combined with another treasure for more money, and all combinable treasures are unique.
Comment: Thanks for letting me know. Are there any common treasures that I should learn to combine before selling?
Comment: Thanks! I just saw that myself!

Can I safely sell everything marked as “Treasure” in Resident Evil Village?


The Stone-Čech compactification is the biggest compactification for Tychonov spaces

Question: What shown below is a reference from "Elementos de Topología General" by Fidel Cassarubias Segura and Ángel Tamariz Mascarúa

Definition
Let $X$ be a Tychonov space and
  $$
\beta=\Delta_{f\in C(X,[0,1])}f:X\rightarrow[0,1]^{C(X,[0,1])}
$$
  the diagonal function of the collection $C(X,[0,1])$ and $\beta X$ the closure of $\beta[X]$ in $[0,1]^{C(X,[0,1])}$. So the compactification $(\beta,\beta X)$ is named Stone-Čech compactification of $X$.
Theorem
If $X$ is a Tychonov space then any Hausdorff compactification $(h,K)$ of $X$ is such that $(h,K)\preccurlyeq(\beta,\beta X)$.
Proof. From previous lemma we know that $K$ is embeddable in $[0,1]^{C(K,[0,1])}$ and so without loss of generality we can suppose that $K$ is a subspace of $[0,1]^{C(K,[0,1])}$. So we consider the function
  $$
H:[0,1]^{C(X,[0,1])}\rightarrow[0,1]^{C(K,[0,1])}
$$
  defined as
  $$
[H(\xi)](g):=\xi(g\circ h)
$$
  where $g\in C(K,[0,1])$ and $\xi\in[0,1]^{C(X,[0,1])}$.
So we observe that if $g$ is an element of $C(K,[0,1])$ and if we compose $H$ with the projection $\pi_g:[0,1]^{C(K,[0,1])}\rightarrow[0,1]$ we obtain the projection $\pi_{g\circ h}:[0,1]^{C(\beta X,[0,1])}\rightarrow[0,1]$, that is $\pi_g\circ H=\pi_{g\circ h}$, and so for the universal mapping theorem for products we can claim that $h$ is continuous.
So we consider the continuous function $p:=H|_{\beta X}:\beta X\rightarrow[0,1]^{C(K,[0,1])}$ and we prove that $p\circ\beta=h$. So we pick $x\in X$ and $g\in C(K,[0,1])$ and we observe that
  $$
[(p\circ\beta)(x)](g)=[p(\beta(x))](g)=[H(\beta(x))](g)=[\beta(x)](g\circ h)=(g\circ h)(x)=[h(x)](g)
$$
  and so for the arbitrariness of $g$ we can claim that $[p\circ\beta](x)=h(x)$ for any $x\in X$, that is $p\circ\beta=h$. Then finally we observe that $p[\beta X]=K$ and so we can claim that $(h,K)\preccurlyeq(\beta,\beta X)$.

Here for the sake of completeness the original text of the proof: I hope that I made a good translation.

Well I don't understand why $p[\beta X]=K$ and why $(g\circ h)(x)=h(x)(g)$. Then in addition I don't understand why  the domain of $\pi_{g\circ h}$ is $[0,1]^{C(\beta X,[0,1])}$ rather than $[0,1]^{C(X,[0,1])}$, but this seems to be irrelevant for the proof.
So could someone help me, please?
Answer: $p \circ \beta = h$ tells you also that $p[\beta[X]] = h[X]$ and $h[X]$ is dense in $K$ (from $(h,K)$ being a compactification). So $p[\beta X]$ is a compact (hence closed in the Hausdorff $K$!) subset of $K$ that contains the dense set $h[X]$ and so must equal $\overline{h[X]}=K$.
Note the subtlety in the proof of $p \circ \beta=h$, where we identify a point of $K$ by its "vector of values" in $[0,1]^{C(K,[0,1])}$, and that's why we work with the values at all $g \in C(K, [0,1])$.
Indeed in this context $\pi_{g \circ h}$ has domain $[0,1]^{C(X, [0,1])}$ as this is the domain on which $H$ is defined, and fits with the given diagram.
It's probably just a typo, but it "happens" that $C(X,[0,1]$ "sort of equals" $C(\beta X,[0,1])$ anyway (every $f$ defined on $X$ has a natural "extension" $\beta f$ defined on $\beta X$ (namely $\pi_f \restriction_{\beta[X]}$) and we can "restrict" any continuous map $g$ from $\beta X$ to $[0,1]$ by $g \circ \beta: X \to [0,1]$ and these operations are each other's inverses. So we have a antural isomorphism between $C(X,[0,1])$ and $C(\beta X, [0,1])$, which will in fact turn out to characterise $\beta X$ among all compactifications of $X$.
Comment: @AntonioMariaDiMauro $p \circ \beta = h$ so $p[\beta X]$ contains $h[X]$. $p[\beta X]$ is compact, because $\beta X$ is and $p$ is continuous.
Comment: @AntonioMariaDiMauro this is because we identify $K$ with a subset of that power.
Comment: @AntonioMariaDiMauro yes sorry I meant $H$ instead of $\beta$. Your last fact is the definition of $H$!
Comment: Perhaps I understood. We know that $\beta X$ is compact and so $p[\beta X]$ is too compact, since $p$ is continuous; moreover $[0,1]^{C(K,[0,1])}$ is hausdorff and contains $p[\beta X]$ and so this is closed. Then $\beta[X]\subseteq\overline{\beta[X]}:=\beta X$ and so $p[\beta[X]]=h[X]$ is contained in $p[\beta X]$, that is closed, and so $K=\overline{h[X]}\subseteq p[\beta X]\equiv p[\overline{\beta[X]}]\subseteq\overline{p[\beta[X]]}=\overline{h[X]}=K$, that is $p[\beta X]=K$. Is it right?
Comment: Sorry, but rereading the proof I don't understand why $(p\circ h)(x)=h(x)(g)$, since $(p\circ h)(x)=g(h(x))$. Anyway  $h(x)$ is a function of the product $[0,1]^{C(K,[0,1])}$. Could you help me, please?
Comment: Okay, but more exatly why the value in $x$ of the function $g\circ h$ is equal to the value in $g$ of the function $h(x)$?
Comment: @AntonioMariaDiMauro $p$ is the restriction of $\beta$ and that's how $\beta$ is defined.
Comment: So I know that there is an embedding $\phi$ of $K$ in $[0,1]^{C(K,[0,1])}$ and so I can claim that $h(x)$ is a function of $[0,1]^{C(K,[0,1])}$. Now I must prove that for any function $g\in [0,1]^{C(K,[0,1])}$ it results that $g(h(x))=[h(x)](g)$. Could you prove it, please?
Comment: Okay, so for any $\xi\in[0,1]^{C(X,[0,1])}$ and $g\in C(K,[0,1])$ it results that $[H(\xi)](g)=\xi(g\circ h)$. Now we have $h(x)\in[0,1]^{C(K,[0,1])}$ and if for any $x\in X$ we found a $\xi_{h(x)}\in[0,1]^{C(X,[0,1])}$ such that $h(x)=H(\xi_{h(x)}$), then it results that $[h(x)](g)=[H(\xi_{h(x)})](g)=\xi_{h(x)}(g\circ h)$. So how to prove that $\xi_{h(x)}(g\circ h)=(g\circ h)(x)$? Could you help me, please?


Migrating to a different distro, but keeping files

Question: I'd like to test out a new Linux distro (Arch-based) by replacing a partition that already has Ubuntu on it. I wouldn't like to lose all my files, and know that it would be easy to back up all the files temorariliy and then do a fresh install. However, since Linux distros tends to use the same structure generally (e.g. using /usr, /home, etc) would it be possible to just change the operating system without having to overwrite these things?
Thank you!
Answer: I know this is probably after the fact, but distro hopping is a really good reason for putting /home on it's own partition. Easiest solution for now and the future is to backup, install whatever distro you want (putting /home on it's own partition) and restoring. That way when you want to switch again you don't have to mess around too much.
Comment: So if I move my /home directory onto another partition, then will it be completley safe to distro hop, files-wise? I know I should back up anyway just in case, but theoretically it's fine?
Comment: Pretty much, at least it is easier. Just be careful when you install. For example, installing ubuntu you would not select the "install ubuntu along side xxx" or whatever, but go to the "something else" selection instead, give / the partition you are sacrificing and format it, and give /home your home directory WITHOUT formating it.... Bear in mind that this is no replacement for backing stuff up.
Answer: No, although the file names and directory structure is similar, it is not exact across distros. In addition the libs are again similar, but different enough that you can not preserve all your system files.
Obviously some system files are going to be the same, but not enough similarity to do as you propose.
Best to back up your data in $HOME and any system files you edited.
Why not dual boot,try running a new distro live, see if you like it. Or use virtualization such as KVM or Virtualbox?
Comment: +1 I would like to second the Virtualbox method.  While performance will be reduced, you can get the "feel" of the system to see if you like it with no uninstall pain.  Live media or dual booting is good to but not sure how easy it is to set up in an "Arch-based" distro. (it may not be hard, I have no experience with Arch, I only know it's reputation as a DIY install)


ffmpeg 10.04 Could Not Find Codec Parameters

Question: I am getting an error while executing the command
ffmpeg -i /path/to/video.mp4 :
  ffmpeg version git-2012-07-24-93342de Copyright (c) 2000-2012 the FFmpeg developers
      built on Jul 24 2012 23:55:41 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
      configuration: --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-vdpau --enable-version3 --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab
      libavutil      51. 65.100 / 51. 65.100
      libavcodec     54. 44.100 / 54. 44.100
      libavformat    54. 20.100 / 54. 20.100
      libavdevice    54.  2.100 / 54.  2.100
      libavfilter     3.  3.100 /  3.  3.100
      libswscale      2.  1.100 /  2.  1.100
      libswresample   0. 15.100 /  0. 15.100
      libpostproc    52.  0.100 / 52.  0.100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x2a1b240] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), 1280x720): unspecified pixel format
    Consider increasing the value for the 'analyzeduration' and 'probesize' options
    /path/to/video.mp4: could not find codec parameters

Answer: Adjust -probesize and/or -analyzeduration.
The files I was testing were in fact damaged. But if anyone faces this problem, setting -probesize and -analyzeduration to 100 and 10000000 for example might help.
From a popular comment by @DiverseAndRemote.com

my solution was
ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i /path/to/video.mp4

2147483647 is max_int
Comment: my solution was `ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i /path/to/video.mp4`. 2147483647 is max_int
Comment: I have here some heavy cases where even `-analyzeduration 999999999 -probesize 999999999` not work.
Comment: @DiverseAndRemote.com That seemed to do the trick for me. Since your comment is so popular I edited the answer and added it there, to help others landing here.
Comment: @rekire do post the solution if you find it!


Expected value questions

Question: Just wanted some input for the following expected value questions:

Suppose a person offers to play a game with you. In this game, when
  you draw a card from a standard 52-card deck, if the card is a face
  card you win $3, and if the card is anything else you lose 1 dollar. If you
  agree to play the game, what is your expected gain or loss?

I computed the following:
Total number of face cards in a deck = 12.
So the expected value would be:
$\frac{1}{52}\left[\left(3\cdot 12\right)+\left(-1\cdot 40\right)\right]$
...which comes out to -1/13, or an expected loss of around 7.7 cents, right?
The other question I have is a lot harder, and I'm not sure how to solve it:

A fair coin is tossed until either a head comes up or
  four tails are obtained. What is the expected number of
  tosses?

I'm used to expected value questions where the number of times you participate in the activity is explicitly givens, so I'm not sure how to begin this one.
Comment: First one looks good.  For the second, just notice that the game can't take more than four tosses to decide.  Just work out all four cases by hand.
Answer: First one is right. For the second one note the following:
the probability that the game ends after one toss is the same as the probabilty for head, i.e. $\frac 12$. So far, so goood.
If the game ends after two tosses, it has to be that the first toss was tail (because otherwise the game would have ended after the first toss) and the second toss was head (because otherwise the game would still continue). So the probability that the game ends after two tosses is the probability for T H, which is $\frac 12 \cdot \frac 12= \frac14$.
Similarly,  for three tosses we have to have T T H , so the probability is $\Bigl(\frac12\Bigr)^3=\frac 18$.
Finally, if the game ends after exactly four tosses, then the first three tosses had to result in tail (because otherwise the game would have stoped before). And the forth toss can either be heads or tails: if it is heads then the came stops, and if it is tails then I have four tails in a row.
Hence the probability is $\Bigl(\frac12\Bigr)^3 \cdot \Bigl(\frac12 +\frac12 \Bigr)=\frac 18$.
The exptected value is then given by:
$$
E[X]= 1 \cdot \frac 12 + 2 \cdot \frac14 + 3\cdot \frac18 + 4\cdot \frac18= 1.875
$$
Comment: Ah I see! Thank you for this. So in this case, the "value" we are computing is the number of tosses, right?
Comment: @ChrisT  right :)

Expected value questions


Proving Euler Angle Rotations of ZXZ spans SO(3)

Question: I am looking for a succinct proof that showcases a ZXZ combination of rotations can reach and orientation in SO(3). I know this combination is one of the 6 (or 12 if you include both intrinsic and extrinsic rotation), but the majority of proofs I find really get into the weeds. Is there something out there complete, yet brief?
Answer: There isn't much to prove. Each rotation in $SO(3)$ can be identified with a set of three mutually orthogonal unit vectors $\hat{\mathbf x}, \hat{\mathbf y}, \hat{\mathbf z}$, obtained by applying the rotation to the coordinate vectors $\hat{\mathbf i}, \hat{\mathbf j}, \hat{\mathbf k}$. Since the rotation must preserve orientation, $\hat{\mathbf x}, \hat{\mathbf y}, \hat{\mathbf z}$ follow the same relative relationships as $\hat{\mathbf i}, \hat{\mathbf j}, \hat{\mathbf k}$. In particular, $\hat{\mathbf y} = \hat{\mathbf z} \times \hat{\mathbf x}$.

A $Z$ rotation - that is, a rotation about the $z$ axis (the vector $\hat{\mathbf k}$) - can move any vector not on the $yz$-plane into that plane. Apply this to move $\hat{\mathbf z}$ into the $yz$-plane. Let $\hat{\mathbf x}_1, \hat{\mathbf y}_1, \hat{\mathbf z}_1$ be the results of applying this $Z$ rotation to the original vectors.
An $X$ rotation - about the $x$ axis, or vector $\hat{\mathbf i}$ - can rotate any non-zero vector in the $yz$-plane onto the positive $z$-axis. Do this for the vector $\hat{\mathbf z}_1$. Let $\hat{\mathbf x}_2, \hat{\mathbf y}_2, \hat{\mathbf z}_2$ be the results of applying this rotation to $\hat{\mathbf x}_1, \hat{\mathbf y}_1, \hat{\mathbf z}_1$. Now $\hat{\mathbf z}_2$ is a unit vector pointing in the direction of positive $z$-axis. This is the definition of $\hat{\mathbf k}$. So $\hat{\mathbf z}_2 = \hat{\mathbf k}$. Since $\hat{\mathbf x}_2, \hat{\mathbf y}_2$ are perpendicular to $\hat{\mathbf z}_2$, they must both lie in the $xy$-plane.
Another $Z$ rotation can rotate any non-zero vector in the $xy$-plane onto the positive $x$-axis. Apply this to $\hat{\mathbf x}_2$, and let $\hat{\mathbf x}_3, \hat{\mathbf y}_3, \hat{\mathbf z}_3$ be the results of applying this rotation to $\hat{\mathbf x}_2, \hat{\mathbf y}_2, \hat{\mathbf z}_2$. Since $Z$-rotations do not affect the $z$-axis, $\hat{\mathbf z}_3 = \hat{\mathbf z}_2 = \hat{\mathbf k}$. $\hat{\mathbf x}_3$ is a unit vector pointing along the positive $x$-axis, and thus must be $\hat{\mathbf i}$, and finally $\hat{\mathbf y}_3 = \hat{\mathbf z}_3 \times \hat{\mathbf x}_3 = \hat{\mathbf k} \times \hat{\mathbf i} = \hat{\mathbf j}$.

Combining these three rotations gives a result that rotates $\hat{\mathbf x}, \hat{\mathbf y}, \hat{\mathbf z}$ onto $\hat{\mathbf i}, \hat{\mathbf j}, \hat{\mathbf k}$. Just the opposite of what we need. But that is a simple matter of reversing the three component rotations and their order:

Reverse the direction of the third rotation to get a $Z$ rotation taking $\hat{\mathbf i}, \hat{\mathbf j}, \hat{\mathbf k}$ to $\hat{\mathbf x}_2, \hat{\mathbf y}_2, \hat{\mathbf z}_2$.
Reverse the direction of the second rotation to get an $X$ rotation taking $\hat{\mathbf x}_2, \hat{\mathbf y}_2, \hat{\mathbf z}_2$ to $\hat{\mathbf x}_1, \hat{\mathbf y}_1, \hat{\mathbf z}_1$.
Reverse the direction of the first rotation to get a $Z$ rotation taking $\hat{\mathbf x}_1, \hat{\mathbf y}_1, \hat{\mathbf z}_1$ to $\hat{\mathbf x}, \hat{\mathbf y}, \hat{\mathbf z}$

The combination of those three rotations takes $\hat{\mathbf i}, \hat{\mathbf j}, \hat{\mathbf k}$ to $\hat{\mathbf x}, \hat{\mathbf y}, \hat{\mathbf z}$, and is thus the rotation in $SO(3)$ we needed.


Create a Woocommerce custom template with product filter

Question: I'm creating a custom template where I want to show the product feed with some filters.
This is the code I'm using to display the product loop:
<code>    <ul class="products">
            <?php
            $args = array(
                'post_type' => 'product',
                'product_cat' => $product_category
            );
            $loop = new WP_Query($args);
            if ($loop->have_posts()) {
                while ($loop->have_posts()):
                    $loop->the_post();
                    wc_get_template_part('content', 'product');
                endwhile;
            } else {
                echo __('No products found');
            }
            wp_reset_postdata();
            ?>
    </ul>
</code>
How can I create the filters to let the user choose products attributes? (for ex. colors, tag)
Comment: This question is a bit too broad. You could write custom JS/AJAX, you could use the FacetWP plugin - there are several ways to do this. What have you tried so far?
Comment: I tried with a couple of plugins, but they don't recognize my loop
Answer: The Filter Everything plugin should work. It allows you to easily create filters based on categories, tags, custom taxonomies, product attributes, acf fields, etc.
I believe you can use a shortcode or drop a widget where you want the filters, like in the side bar, and set what container has your loop.
You can copy and customize the template parts, like the radio button layout or the checkbox layout, and apply each set of filters the layout you want.
For instance you can set up radio buttons for category and checkboxes for tags, a drop down for size, and swatches for color, all styled how you want.


Simplest solution for hanging 50lb frame with welded hooks

Question: I have a 50lb mirror I'd like to hang. It has an iron frame with two hangers welded onto the curved top edge on the back. Here's a close-up of one of them:

The hangers are about 17" apart on center, and the keyhole cutouts are 3/4" wide. The wall is standard drywall, and there happens to be a stud dead-center where I'd like to hang it.
What are the simplest and safest options here? Considerations:

I haven't checked yet but there's no guarantee that the brackets are 100% level, so the solution needs to be able to account for that.
I'd like for the mirror to hang as flush to the wall as possible, minimizing lean-out and gap.
I'm pretty conservative re: hanging weight and would strongly prefer using the stud for support, although I can be convinced otherwise. I saw this (Hillman no-stud hanger) mentioned in another answer and perhaps two of those could work if the result hangs fairly close to the wall, although point #1 could make this very challenging.
Preference is for a minimum of "construction": cutting wood, etc. This technique (spanning plywood) seems to be a good solution, and I can make it happen, but if there's something simpler that is as safe I'd be interested.

My experience with hanging anything close to this heavy is to just use a z-bar, but I don't have that option with this frame.
Comment: Unrelaed, I would suggest de-rusting the frame before hanging it too.
Comment: I think those speckles are intentional
Answer: (Suitably sturdy) Picture hanging wire. Wire between the hangers, put a screw or hook into the stud, hang and adjust.
"100 lb" rated picture hanging wire is easy to find. As is 200 if you want more safety factor...
Comment: They might also be concerned with the edge of the hanger cutting the wire - easy solution to that is S-hooks at each end, or go absurd and follow the "do not use wire" advice **literally** by using small chain instead ;^) A "thimble" (not for your finger - for the inside of a loop/eye of wire rope) would be another approach to prevent cutting, but might be hard to find that small.
Comment: It's worth noting that the tension in the wire is increased because the wire isn't vertical. If the wire is 60 degrees from vertical (30 from horizontal) the tension is doubled. Even so, with two hanging points, each will only apply half the tension, so 100lb wire will have a safety factor of 2 (which isn't much, for domestic stuff)
Comment: Wire can cause a picture or mirror to lean away from the wall depending on the slack in the wire and where it is attached which might not be what you want, especially with a mirror.  Of course if the mirror is hung a little high, you might want it angled down a bit... Just be aware this makes it very hard to hang it flat.
Comment: Thank you! Do you have any comment on the response I left to the other answer that suggested wire?
Answer: Since the answer has to take into consideration that the two hangers are not level, you're stuck with one solution: hang it like a picture. Go to your home store and get some stainless steel picture hanging wire rated for 50 to 100 pounds. Make a strong loop around one end and hook it into one of the hangers. Do the same to the other hanger so there's not much slack in the wire. Add two wires if it will help you sleep at night. Then screw a 1-1/4" lag screw and washer into the center of that 2x4 stud you like so much. Leave just enough space between the washer and the wall to slide the wire behind. Lift the mirror and slide it around until you hook the wire behind the washer.
Comment: Those hangers are likely designed to take the load vertically, but wiring together like a picture will change that angle and possibly warp the frame.  Also, the load on each hanger will be (significantly) greater than a plain hang - the vertical component will be the same, so you can calculate (or visualise) the horizontal component when you see the angle.
Comment: Thanks! It has one of those standard "do not use wire" notices on the back that some manufacturers put on all their frames. I'm inclined to try this anyway, because my understanding is that those warnings are there to prevent warping and D-ring pull-outs in *wooden* frames, and to prevent people from mounting heavy stuff to a single point without a stud. Can you lend credence to that? This frame is welded iron and extremely sturdy, including the hangers. There's not much clearance for slack in the wire, which I know can create a lot of force, but I can get extra-sturdy wire to compensate.
Answer: Cut a piece of steel bar / tube that is thin enough to fit between the back of the glass and the front of the hangers and will reach between the two welded brackets. The bar needs to be strong enough to support the mirror at it's ends without significant bending so it might need to be wide. Drill and tap this so you can fix it to the hangers such that it can't move. Just to be clear, the bar is to sit inside the thickness of the frame of the mirror between the front of the welded hooks and the back of the glass. Attach to the mirror and find the point at which the whole assembly hangs vertically. Remove from the mirror and attach a length of suitable chain or wire to the bar so it bridges this centre point on the bar by maybe an inch either way.
Use this chain or wire on a suitable hook or bolt screwed into the stud. It gives you a little wiggle room in case you didn't get the position it hangs vertically quite right.
If the concern of the manufacturer is that wire between the two welded hangers will distort the frame by pulling the sides together, this stops it happening.
Comment: Typo: s/`it's`/`its`/.  Note that the main direction of force is downwards, so the bar/tube can be a strip, aligned vertically, or an asymmetrical angle section.  The horizontal force should generally be under 10kg, so as long as you screw the bar securely to the hangers to prevent it twisting, the asymmetry keeps it small and light.  Note that you'll probably get the strip in between the hangers and glass if you choose well, which will help get it flush to the wall.
Comment: You might not need the inch of chain if you choose a metal rod that can sit securely on the hook/screw - and when you find the balance point, make a small notch to stop it slipping.
Comment: I did think of that... with access to suitable equipment you could kink the bar so it sat closer to the wall / further from the glass at that point so the screw / bolt head could sit between the bar and the glass. I'm not sure it would need a notch, at 50 lbs it's not going to move very easily. Can't correct that silly it's error unfortunately
Comment: Thanks, this is good to consider. Given that the whole frame is very stiff and sturdy, I would think you could also prevent the sides from pulling together while hanging from wire attached to the hangers by just wedging a carefully-sized piece of lumber between the hangers.


Need assistance choosing a image management gem

Question: I am interested in building a Rails based system for handling the display and organization of large amounts of photos. This is sort of like Flickr but smaller. Each photo will have metadata associated with it. Photos will be shown in a selectable list and grid view. It would be nice to be able to load images as they are needed as well (as this would probably speed things up).
At the moment I have a test version of my database working by images loading from the assets/images directory but it is beginning to run slow when displaying several images (200-600 images). This is due to the way I have my view setup. I am using a straight loop to display the images in both list and grid layouts.
I also manually resized the thumbnails and a medium sized image from a full sized source image. I am investigating other resizing methods. Any advice is appreciated here as well.
As I am new to handling the images this way, could someone point me in a direction based on experience designing and implementing something like Flickr?
I am investigating the following tools:

Paperclip

http://railscasts.com/episodes/134-paperclip
Requirements: ImageMajick

attachment_fu

http://clarkware.com/blog/2007/02/24/file-upload-fu#FileUploadFu
Requirement: One of the following: ImageScience, RMagick, miniMagick, ImageMajick?

CarrierWave

http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary
http://cloudinary.com/blog/advanced_image_transformations_in_the_cloud_with_carrierwave_cloudinary
Comment: I won't go over a long explanation here but you should take a look at Dragonfly https://github.com/markevans/dragonfly
Answer: I'd go with Carrierwave anyday. It is very flexible and has lot of useful strategies. It generates it's on Uploader class and has all nifty and self explanatory features such as automatic generation of thumbnails (as specified by you), blacklisting, formatting image, size constraints etc; which you can put to your use.
This Railscast by Ryan Bates - http://railscasts.com/episodes/253-carrierwave-file-uploads is very useful, if you haven't seen it already.
Answer: Paperclip and CarrierWave are totally appropriate tools for the job, and the one you choose is going to be a matter of personal preference. They both have tons of users and active, ongoing development. The difference is whether you'd prefer to define your file upload rules in a separate class (CarrierWave), or if you'd rather define them inline in your model (Paperclip).
I prefer CarrierWave, but based on usage it's clear plenty of people feel otherwise.
Note that neither gem is going to do anything for your slow view with 200-600 images. These gems are just for handling image uploads, and don't help you with anything beyond that.
Note also that Rails is really pretty bad at handling file uploads and file downloads, and you should avoid this where possible by letting other services (a cdn, your web server, s3, etc) handle these for you. The central gotcha is that if you handle a file transfer with rails, your entire web application process is busy for the duration of the transfer. (For related discussion on this topic, see: Best Ruby on Rails Architecture for Image Heavy App).


Check if the element inside an iFrame has any content

Question: So I've tried to do a bunch of research and can't seem to find the correct answer for my question so I wanted to reach out and see if anyone knows much.
What I'm attempting to achieve:
Check the contents inside an iFrame and return a boolean whether there is content or not.
Here is what I've attempted:
function check_iframe_body_content(element) {
    let has_content = false;

    let iframe = element.contents().find('body');
    console.log(iframe);

    if (iframe.length > 0) {
        has_content = true;
    }

    return has_content;
}

The element is the iFrame return, which will be an array:

When the script tags are disabled, I get the following return:

When the script tags are enabled, I get the following return:

How can I properly determine if the  is empty and when it's not? I've tried to do .length on multiple different occasions and each time it comes back as has_content = true because it finds the body element, but it's actually empty.
All help will be appreciated!
Comment: Does this answer your question? [How to identify if a webpage is being loaded inside an iframe or directly into the browser window?](https://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t)
Comment: If you use `querySelector` like `iframe.querySelector('body')` then check if `innerHTML` is empty or not. i think that work.
Comment: Use `querySelector` with `innerHTML` and check if is empty.
Comment: @SimoneRossaini, do you have an example of a proper use case like this? I never attempted to try to grab contents from an iFrame, wouldn't `innerHTML` return true anyways on an empty body since `` is HTML?
Comment: @SimoneRossaini, thank you! Let me attempt this.
Comment: @Ron, thanks Ron! Will look into that also.
Answer: You wont have access to the content inside iframe if it's loaded from another website as it's a major security breach.
if that was possible a website could add an iframe to google.com and get access to user personal information like their email address, name and etc.
depending on why you want to check content of iframe, there might be other workarounds.
Comment: [How to get the body's content of an iframe in Javascript?](https://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript)
Comment: So long story short, I am implementing OneTrust, which is a cookie compliance tool and it leaves a blank component on iFrames when the scripts/cookies are blocked - Basically need to determine if an iFrame has empty content and then add a message on top to let users know that they are seeing a white screen because the cookies are blocked.
Comment: So iframe is loaded from a third party website and you want to see if it has loaded some content or not ? correct ?
Comment: @PooyaEstakhri, correct - We are adding in a iFrame and I want to display an message if the iFrame has no content when loaded. otherwise load it regularly and don't display a message if it has content.
Comment: As i mentioned in the answer, you cant check contents of an iframe if it's loaded from a third party website. but what you can do is to check if third party cookies are enabled. check here :https://stackoverflow.com/questions/3550790/check-if-third-party-cookies-are-enabled
Comment: @SimoneRossaini not if it's a third party website.


Azure Jenkins Android SDK not found

Question: I´ve created a fresh jenkins server in azure, everything works fine so far, but the build cannot find the ANDROID_HOME enviroment variable even if it is set.

I´m really not sure whats going on here, because it seems to be that everything is set up correctly. Is it possible that jenkins is using a different user so the variable is not found?
Answer: AFAIK this issue is not related to Azure. Looks like its related to permission issue.
Try to resolve the issue by following below steps.

Go to Jenkins -> Manage Jenkins -> Configure System
Check for "Environment variables"
Add name: ANDROID_HOME and value:
click "add"
Scroll down and click "save"

If you have already done with the above steps, then try to make sure you have given 777 permission to android sdk dir as shown below (in some cases better to provide permission to its parent directory).
chmod 777 your_android_sdk_dir
If you have already done with the above step, then try to restart Android Studio and see if it builds the project successfully.
Hope this helps!!

Azure Jenkins Android SDK not found


How can I determine my logged in status on the client? [finished]

Question: I'm using Express/Passport.  All my files are served statically like this.
<code>// static bundle from webpack
app.use('/', express.static(__dirname + '/../client-react/dist'));
</code>
So when I'm on the client I have not way to know if I'm logged in.
Passport is working fine and I am able to get profile data on the server.
Ajax Request is here:
<code>    $.ajax({
      url: "/api/items",
      success: (results) => {
        console.log(results);
        this.props.dispatch({type: 'updateBookmarks', bookmarks: results});
      }
    });
  }
</code>
Server Response is here:
<code>router.route('/items').get((req, res) => {

    console.log(req.user);

    DB.selectAllDomains().then((results) => {
        res.json(results);
    });
});
</code>
Answer: The client doesn't know if user is logged in. Client makes a request to your server, you should have access to req.user on your sever if passport is integrated properly. The server can respond with key/value in req.user . Now your client has received info about the logged in user.
Check this out Passport.js: how to access user object after authentication?
Comment: Your sever needs to respond with req.user
example: res.json(req.user);

Use fetch or ajax to make a request to your sever.
Comment: Can you post you ajax request here?
Comment: Do you have body parser installed?
Comment: Disregard the previous comment. Uninstall the body parser. You don't need it. Can you post your ajax request. Sorry, its hard to help without seeing your ajax request.
Comment: Im curious: use

  $.ajax({
      url: "/api/items",
      success: function(results) {
        console.log(results);
        this.props.dispatch({type: 'updateBookmarks', bookmarks: results});
      }
    });
  }
Comment: You ned add
`type: "GET"` to your request. I missed that. Also don't assume. I haven't seen a arrow function example in there docs as well.
Comment: Add
`type: 'GET', dataType: 'json', ` to your ajax request. Im trying to help.
Here is a example: https://jsfiddle.net/hofo/x7s9c4wL/


how to enable drivers for BCM43142

Question: My laptop is Dell Inspiron 17R 5720. My OS is Ubuntu 13.10. I was using WiFi before but one day it stopped working.
Outputs of some commands:
enedil@enedil-Dell:~$ lspci -k | grep -A2 Broadcom
02:00.0 Network controller: Broadcom Corporation BCM43142 802.11b/g/n (rev 01)
Subsystem: Dell Wireless 1704 802.11n + BT 4.0
Kernel driver in use: wl

enedil@enedil-Dell:~$ rfkill list all
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: brcmwl-0: Wireless LAN
Soft blocked: no
Hard blocked: no
2: hci0: Bluetooth
Soft blocked: no
Hard blocked: no

enedil@enedil-Dell:~$ lsmod | grep wl
wl                   4207760  0
cfg80211              480503  1 wl
lib80211               14381  2 wl,lib80211_crypt_tkip

enedil@enedil-Dell:~$ uname -a
Linux enedil-Dell 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

enedil@enedil-Dell:~$ lspci -vvnn | grep 14e4
02:00.0 Network controller [0280]: Broadcom Corporation BCM43142 802.11b/g/n     [14e4:4365] (rev 01)

I don't know what to do, especially that yesterday, I changed my Internet connection to wireless.
EDIT: When I click on network applet (I'm using Unity) I see message under grey Wi-Fi: Device unsupported.
Comment: Please check the message logs for any informative clues: dmesg | grep -e wl -e eth1
Comment: There isin't any output.
Comment: Please try: sudo modprobe wl and then: dmesg | grep -e wl -e eth1
Comment: FATAL: Module wl not found.
Comment: Try sudo apt-get install bcmwl-kernel-source
Answer: Please reinstall the driver. With a temporary wired ethernet connection, please open a terminal and do:
sudo apt-get install --reinstall linux-headers-3.11.0-15-generic linux-headers-generic
sudo apt-get install --reinstall bcmwl-kernel-source
sudo modprobe wl

Detach the ethernet. Your wireless should be working now.
Answer: If you have previously installed the bcmwl-kernel-source package, you will need to remove it by using the purge method:
sudo apt-get purge bcmwl-kernel-source

Prepare the installation:
sudo apt-get update

Update the Ubuntu list of PCI IDs:
sudo update-pciids

Install the driver:
sudo apt-get install bcmwl-kernel-source

Finally, reboot:
sudo reboot

how to enable drivers for BCM43142


timedatectl on ubuntu server 20.04

Question: I have an ubuntu server (20.04) where timedatectl is failing to set the timezone.  On the first call, it always fails, on the second it thinks it has succeeded but actually it hasn't:
Beforehand the timezone is Europe/Paris:
root@oxpad:~# timedatectl
               Local time: Wed 2021-08-11 02:02:44 CEST
           Universal time: Wed 2021-08-11 00:02:44 UTC
                 RTC time: Wed 2021-08-11 00:02:44
                Time zone: Europe/Paris (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

** The time is CEST == Central European Summer Time **
root@oxpad:~# date
Wed Aug 11 02:02:46 CEST 2021

Change the timezone:
root@oxpad:~# timedatectl set-timezone Europe/London
Failed to set time zone: Access denied
root@oxpad:~# timedatectl set-timezone Europe/London
root@oxpad:~#

Apparent success
root@oxpad:~# timedatectl
               Local time: Wed 2021-08-11 01:02:58 BST
           Universal time: Wed 2021-08-11 00:02:58 UTC
                 RTC time: Wed 2021-08-11 00:02:58
                Time zone: Europe/London (BST, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

But actual failure
root@oxpad:~# date
Wed Aug 11 02:02:59 CEST 2021
root@oxpad:~#

and indeed no other services see the updated local time.  It seems that timedatectl is alone in thinking it has succeeded.
This is completely repeatable. It is an issue because we will be deploying quite a few of these servers and if the timezone cannot be set, we have a problem.  I would really like to understand the relationship between timedatectl and "real" system time, as seen by date and other processes, as that would probably lead to an understanding of the problem.  Any pointers would be welcome.
Interestingly, setting the timezone on an Ubuntu 20.04 desktop system with timedatectl works fine.  It is almost as if timedatectl sets the timezone over dbus but dbus is not set up properly on the server version of the OS.
All of this testing is on newish installations, not more than a few days old and clean apart from adding a few packages.
Does anyone know what is going on here?  Help would be much appreciated.
More logs:
On the Ubuntu 20.04 server there is an error in the logs when changing time, on the 20.04 desktop the same service log shows success.  The error:
root@oxpad:~# systemctl status systemd-timedated
● systemd-timedated.service - Time & Date Service
     Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:systemd-timedated.service(8)
             man:localtime(5)
             https://www.freedesktop.org/wiki/Software/systemd/timedated

Aug 11 02:02:33 oxpad systemd[1]: systemd-timedated.service: Succeeded.
Aug 11 02:02:38 oxpad systemd[1]: Starting Time & Date Service...
Aug 11 02:02:38 oxpad systemd[1]: Started Time & Date Service.
Aug 11 02:02:38 oxpad systemd-timedated[35339]: Failed to set time zone: Permission denied
Aug 11 02:02:53 oxpad systemd-timedated[35339]: Failed to set time zone: Permission denied

Comment: Note: Setting the timezone with `dpkg-reconfigure tzdata` works, however selecting a  timezone in an interactive menu isn't very automatable.
Comment: An interesting but not particularly helpful link: https://www.freedesktop.org/wiki/Software/systemd/timedated/
Answer: I could not duplicate your error on a plain Ubuntu 20.04 image.  You should be checking if the command changes /etc/timezone and the /etc/localtime symlink.  Also check what the permissions on those files are.  If you are running selinux or other security software then that is another possible cause for the error.
root@ubuntu:~# date
Wed Aug 11 16:05:25 UTC 2021
root@ubuntu:~# timedatectl
               Local time: Wed 2021-08-11 16:05:28 UTC
           Universal time: Wed 2021-08-11 16:05:28 UTC
                 RTC time: Wed 2021-08-11 16:05:29
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
root@ubuntu:~# cat /etc/timezone
Etc/UTC
root@ubuntu:~# ls -l /etc/localtime
lrwxrwxrwx 1 root root 29 Aug 11 15:39 /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC

root@ubuntu:~# timedatectl set-timezone Europe/London
root@ubuntu:~# date
Wed Aug 11 17:05:51 BST 2021
root@ubuntu:~# timedatectl
               Local time: Wed 2021-08-11 17:05:59 BST
           Universal time: Wed 2021-08-11 16:05:59 UTC
                 RTC time: Wed 2021-08-11 16:06:00
                Time zone: Europe/London (BST, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
root@ubuntu:~# cat /etc/timezone
Europe/London
root@ubuntu:~# ls -l /etc/localtime
lrwxrwxrwx 1 root root 35 Aug 11 17:05 /etc/localtime -> ../usr/share/zoneinfo/Europe/London

These steps are another way to automate changing the timezone.

Update the /etc/localtime symlink
Run dpkg-reconfigure --frontend noninteractive tzdata

You can see these steps will update the /etc/timezone file as well.
root@ubuntu:~# date
Wed Aug 11 16:09:30 UTC 2021
root@ubuntu:~# ln -f -s /usr/share/zoneinfo/Europe/London /etc/localtime
root@ubuntu:~# dpkg-reconfigure --frontend noninteractive tzdata

Current default time zone: 'Europe/London'
Local time is now:      Wed Aug 11 17:10:30 BST 2021.
Universal Time is now:  Wed Aug 11 16:10:30 UTC 2021.

root@ubuntu:~# date
Wed Aug 11 17:10:34 BST 2021
root@ubuntu:~# cat /etc/timezone
Europe/London
root@ubuntu:~# ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Aug 11 17:10 /etc/localtime -> /usr/share/zoneinfo/Europe/London

Comment: Regarding updating the symlink and running dpkg-reconfigure, that is in fact what I did and it works.  Thank you for the suggestion, it will help future readers!
Comment: Regarding checking permissions and Selinux, I did this but got no joy.  What I will try next is to change the service that launches the timedatectl daemon so that it runs inside strace, so that I can see what it is doing.  I would prefer to get to the root of the problem than work around it.

timedatectl on ubuntu server 20.04


How can I determine which equipment in my basement is beeping periodically?

Question: I have a few pieces of equipment in the basement and one of them is beeping every 2 hours (approximately) or so.
1) Sump Pump
2) Radon Mitigation System.
3) Verizon Fios - Optical Network Terminal (ONT).
4) Furnace
5) Water heater
How do I identify which one is making the beeping sound?
Comment: Does this answer your question? [what is beeping in my house?](https://diy.stackexchange.com/questions/10871/what-is-beeping-in-my-house)
Comment: often equipment will have a light indicating an error or low battery. My guess would be to check the sump pump, radon, and ONT as I don't believe the furnace or water heater will beep
Comment: sump pump doesn't have a battery backup.
Answer: It's almost certainly your FiOS ONT. The power supply contains a battery, and it beeps when the battery dies. You can take the battery to a hardware store and buy a replacement for a couple of dollars, or call FiOS and they will send you a battery.
Those other deices you listed usually don't beep, except for the sump pump if it's got a water level alarm or a battery backup, but usually the water level alarm is constant. It may have indicator lights to tell you what's wrong.
Comment: The unit I had worked as long as it still had AC power.
Comment: Now that you mention it, the alarm beeps every 1 minute according to the manual.
https://www.verizon.com/support/residential/battery-backup/backup-unit

This beep is more like once in 2 hours.
Comment: I seem to recall the ONT manual was not accurate. I would unplug the battery and see if the resulting beep is the same tone.
Comment: If I unplug the battery, will I still have the internet connectivity in the house?
Comment: The ONT power supply has indicator lights to tell you the health of the battery.
Comment: My ONT has a 12V 7AH battery backup that costs a bit more than a couple dollars to replace. More like 20 to 40 dollars depending on what you choose to buy. For example https://www.amazon.com/Yuasa-NP7-12-Sealed-Battery-Terminal/dp/B00FA61Q1G/ref=sr_1_14?keywords=12V+7AH+battery&qid=1583989889&sr=8-14
Comment: I took out the battery from the ONT power supply. So far I haven't heard any beeps. It is Day 3 today.
Answer: Is it possible that you've been pranked?
A beep every two hours doesn't sound like something that would be designed into a product to make you aware of an issue
Consider a prank noise maker such as Electronic Cricket.
Comment: To make matters more worse, some have a proximity sensor - besides randomization -  that will mute them if a person is in the same room or nearby.
Comment: while we are brainstorming off-beat ideas, I personally went looking for a smoke detector with a dying battery in my home for about a week, to the point of taking one down at a time and placing on my desk to see if it was the one chirping. Turned out that the person who composed the music in a video game used the chirp during a flame-themed battle.
Comment: Are you kidding me? I've been chasing a beep for 5  years.  I think it's a smoke detector that was mounted in the rafters after a foam insulation ceiling went up.
Comment: to make matters worse, many of them have some randomization to the timing to further make it both hard to find and increase the level of frustration :\


How to use the Wolfram Language or another tool to find a second order pde solution with initial conditions?

Question: I want to find a solution the Cauchy problem using the Wolfram Language or some other tool.
I have next task:
$$
3\frac{\partial^2 u}{\partial x^2} + 8\frac{\partial^2 u}{\partial x \partial y} - 3\frac{\partial^2 u}{\partial y^2} - 60\frac{\partial u}{\partial x} + 20\frac{\partial u}{\partial y} = 0,\\
u(x,0) = -4e^{2x},~ \frac{\partial u}{\partial y}(x,0) = -9xe^{2x}
$$
So, I tried to run this using wolfram notebook:
weqn = 3D[u[x,y],{x,2}] + 8D[u[x,y],{x}, {y}] -3D[u[x,y],{y,2}] - 60D[u[x,y],x] +20D[u[x,y],y] == 0
ic = {u[x,0] ==-4e^(2x), Derivative[0,1][u][x,0] == -9xe^(2x)}
sol = DSolve[{weqn, ic},u,{x,y}]

but I got very big and strange answer (I couldn't even see it in full), may be I did something wrong. The answer of task on a piece of paper is prettier.
And so, can I somehow solve similar tasks using Wolfram or another tool?
Comment: Change $-4e^{2x}$ in $-4E^{2x}$ and correct $xe^{2x}$ in $x\;E^{2x}$ with a space between $x$ and $E$. I got $u(x,y)=-e^{2 x+6 y} \left(9 x y+12 y^2-24 y+4\right)$
Comment: @Raffaele, Ok, using `E` instead `e` is more correct?
Comment: It's the syntax of Mathematica, just like you have to write Pi for $\pi$ or Sin[x] for $\sin x$
Comment: @Raffaele, Thank you! Now it works!
And may be you know how can I write correctly next task in Wolfram?
$$ \frac{\partial^2 u}{\partial x \partial y} = 0, ~ u(x,x^2) = 0, \frac{\partial u}{\partial y}(x,x^2) = \sqrt{|x|}, ~ |x| < 1 $$
I write this, but it don't work:

`weqn = D[u[x,y],x,y] == 0` ---

`ic = {u[x,x^2] == 0, Derivative[0,1][u][x,x^2] == Sqrt[Abs[x]], Abs[x] < 1}` ---

`sol = DSolve[{weqn, ic},u,{x,y}]`
Answer: I got the answer in the comments under my question. The correct code should be like this:
weqn = 3D[u[x,y],{x,2}] + 8D[u[x,y],{x}, {y}] -3D[u[x,y],{y,2}] - 60D[u[x,y],x] +20D[u[x,y],y] == 0
ic = {u[x,0] ==-4E^(2x), Derivative[0,1][u][x,0] == -9x E^(2x)}
sol = DSolve[{weqn, ic},u,{x,y}]

You should use E instead e, because mathematica.


Win10 created more than 4 primary partitions, it seems?! gparted is not amused

Question: first the story: I moved my Windows partition "to the left", then were unable to (dual) boot Windows, tried the repair option on the Win8 CD ... and now seem to have more than 4 primary partitions. gparted now shows the whole disk unallocated "Can't have overlapping partitions".
Here's what the partition table looks like (viewed from live CD):
ubuntu@ubuntu:~$ sudo parted /dev/sda unit s print
Error: Can't have overlapping partitions.

ubuntu@ubuntu:~$ sudo fdisk -l -u /dev/sda

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000524e5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2046   134217727    67107841    5  Extended
/dev/sda2       134217728   150798335     8290304   82  Linux swap / Solaris
/dev/sda3   *   150798336   151515135      358400    7  HPFS/NTFS/exFAT
/dev/sda4   *   237004800   237721599      358400    7  HPFS/NTFS/exFAT
/dev/sda5       237721600   488394751   125336576    7  HPFS/NTFS/exFAT

/dev/sda1 is where my ext4 Linux partition used to be. I am aware of the answers at GParted shows "unallocated" on my sda drive (parallel boot with Win XP) and also read a lot more. I understand that I can only have 4 primary partitions and /dev/sda5 should be within an extended partition - causing the "overlapping" warning.
What I do not know: How do I solve the problem? I'd prefer to keep my old linux partition - but even if I did not, I can't just reinstall Ubuntu, because the disk is in an invalid state. And I am lucky that windows works fine on /dev/sda5 and would prefer not to remove this partition.
What I also do not understand: What are the two mini-partitions 3 and 4 good for? I assume that windows had created them as boot partitions or something like that ... so, can I remove one of them? Windows mounts the second one as D: and shows files like Temp\disklayout.txt including information on the disk like it used to be before the "repairs":
  Partition ###  Typ               Größe    Offset
  -------------  ----------------  -------  -------
  Partition 0    Erweitert           63 GB  1023 KB
  Partition 4    Logisch             63 GB  1024 KB
  Partition 1    Primär            8096 MB    64 GB
  Partition 2    Primär             350 MB   113 GB
  Partition 3    Primär             119 GB   113 GB

Thanks a lot for helpful directions!
Update 1
I tried to get rid of the superfluous partition using sfdisk and writing a modified table to the disk. And when the last partition showed up twice, I used fdisk to remove that one. The result looked good.
/dev/sda1 : start=     2046, size=134215682, Id= 5
/dev/sda2 : start=134217728, size= 16580608, Id=82
/dev/sda3 : start=237004800, size=   716800, Id= 7, bootable
/dev/sda4 : start=237721600, size=250673152, Id= 7

When I then did a try with fixparts, it's analysis is ... irritating:
MBR command (? for help): p

** NOTE: Partition numbers do NOT indicate final primary/logical status,
** unlike in most MBR partitioning tools!

** Extended partitions are not displayed, but will be generated as required.

Disk size is 488397168 sectors (232.9 GiB)
MBR disk identifier: 0x000524E5
MBR partitions:

                                                   Can Be   Can Be
Number  Boot  Start Sector   End Sector   Status   Logical  Primary   Code
   2             134217728    150798335   logical     Y        Y      0x82
   3      *      237004800    237721599   logical     Y        Y      0x07
   4             237721600    488394751   primary              Y      0x07

Although sfdisk displays the first partition, fixparts won't.
Update 2
Well, well. I wasn't so lucky with fixparts, but testdisk did the trick. Not alone, but the critical part. Here's what helped for me (I'm writing from the once-lost Ubuntu, jippi) - may be helpful for someone else.
A warning in advance: I never thought that messing around with parition tables was so much fun! But probably don't do that (without a full disk backup), if have have important data on the disk.

The first part would probably been easier just using fdisk /dev/sda to delete the superfluous partition.

Downloaded the partition table via fsdisk -d /dev/sda > SomeUSBFile
Manually removed the superfluos partition from this file (and changed the numbers of the remaining partitions accordingly)
Written the modified partition table via fsdisk /dev/sda < SomeUSBFile
Deleted the last partition, that now was displayed two times via fdisk

The Linux partition was still missing, so I ran testdisk from the Ubuntu live USB stick. It found that there actually is no extended partition, but a primary linux partition instead. But it did not see the Windows 10 partitition.

So I, again, wrote the partition table to a file fsdisk -d /dev/sda > SomeUSBFile
let testdisk write the new partition table (the one, it found after searching for partitions),
exported this partition table to another file,
copied the line of the linux partition, and
inserted this line into the original partition table's file to
import this modified version via fsdisk /dev/sda < SomeUSBFile.

Windows still run :)
The ubuntu live-USB then allowed to mount the linux partition (which is strange, as I had enabled encryption during the linux installation...), and install a new grub MBR to /dev/sda (http://howtoubuntu.org/how-to-repair-restore-reinstall-grub-2-with-a-ubuntu-live-cd)
Finally, the swap partition (the old one was now "unknown" in gparted) has to be recreated in gparted.
Comment: By definition a sda5 must be inside the extended partition as it is a logical partition. And you can only have one boot flag on a primary NTFS partition for Windows to boot from. Not sure how you managed to get this configuration. It almost looks like you copied sda3 into sda4?? And the Linux partition inside sda1 was lost as Windows tools often rewrite partition table without the Linux logical partition. Do not use Windows except to shrink or increase NTFS partitions, or you will have issues. Can you tell if sda4 is a copy of sda3, that may determine what to do. If you can backup do that.
Comment: Thank you. Yes, I am aware that sda3 and sda4 are - uum - not perfect. They have probably not exactly the same content (at least one is mounted and refers to the "old" configuration, see edits to my posting).
Comment: Okay ... another idea: Can I somewhat disable a partition temporarily and see if that helps? I thought of removing if from the partition table via ubuntu live CD but re-enter it, if everything breaks down. I did not ever do something like this, therefore comments would be apprechiated.
Comment: Do this first. Then at least you can restore to current, but invalid state: First backup partition table, use your drive for sdX or sda, sdb etc.
`sudo sfdisk -d /dev/sdX >parts_ parts.txt` or
`sudo sfdisk -d /dev/sda > parts_sda.txt`  Then see what testdisk and/or fixparts show.
Comment: An extended partition type 5 is not a real partition or it  is a container for logical partitions (kinda). see `sudo sfdisk -T`. You need to change 5 to 83, then fixparts may see it. Start also then should be 2048. As extended needed 2 sectors before first partition inside it. You may be able to use testdisk also to recover partition.
Comment: Okay ... I did not think so far that the first partition may not be extended, but only had a wrong type number. That was probably the best guess that the Windows repair could make for a linux partition. But this looked so sound to me, that I did not consider it. Would have solve the problem faster, probably. Thank you!
Comment: Your `sfdisk` effort to delete a "superfluous" partition actually deleted an important partition. When you ran `fixparts`, it showed the modified partition table without showing the extended partition. You'd have been better off at least *trying* with `fixparts` before adjusting the partition table with other tools. I can't promise it would have worked, but it might have done so.
Comment: I am quite sure, the partition, I deleted, was not important. It was rather an old boot partition of Windows - and Windows had created a new one during my initial repair efforts. Using `fixparts` first would probably been more sensible -- if I had the idea to change the assumes-extended partition to type 83 in time...
Answer: My FixParts utility (part of the gdisk package in Ubuntu) might be able to fix the problem; however, I can't promise that -- the fact that your logical partition resides entirely outside the space allocated to the extended partition might throw it for a loop. (That problem is extremely rare, and I don't recall enough details of how FixParts reads MBR partition tables to predict how it will react.) You can try running FixParts on the disk and view the partition table to see if it can detect your partitions without risk -- it won't save the partition table until you tell it to do so (via the w option).
If FixParts flakes out on the disk, there are at least three other options:

Using fdisk or some other tool, delete some or all of your partitions and then re-create them. The output you've already shown provides everything you need -- the start and end points (in sectors) and partition type codes.
Delete all your partitions and then use TestDisk to recover a valid partition table. This approach is normally one of last resort, and it sometimes fails, but it may be helpful if you have problems with the preceding approach.
Back up all your partitions' contents, erase the partition table, create new partitions, and restore your partitions' contents. This is a major undertaking and you may encounter problems getting everything to boot again, so I'd do it only as a last resort. Backing up before trying other approaches is advisable, though.

As oldfred says, the Windows partitioning tool is unreliable when working with MBR partition tables that contain extended and logical partitions. I recommend avoiding it if at all possible.
Comment: Sfdisk shows extended partition. Fixparts automatically creates or changes extended partition, so no need to show it. Both are correct. Issue is extended partition, should be a primary Linux partition. And you then have the standard 4 primary partition limit issue which fixparts can help you with. http://askubuntu.com/questions/149821/my-laptop-already-has-4-primary-partitions-how-can-i-install-ubuntu
Comment: Before killing my whole disk, maybe you could give me some directions for MBR beginners: I do not fully understand the `fixparts` output (see update in my original question). It would be great help, if you could explain me the inconsistency between `sfdisk` and `fixparts`.
Comment: Your answer gave me the right direction to solve the problem. I never thought I could work on the partition table without killing the whole system - now I am really happy! Thanks, again.


How secure is the traffic behind the SSH tunnel to VPS virtual server?

Question: If I buy a VPS virtual server on the net, and establish a ssh tunnel to it: how secure is my communication?
Between my machine and the VPS is probably quite secure. But what about the traffic behind the VPS?
I mean especially in terms of passwords, banking details etc: could they be read by the VPS hosting provider? Or anyone else?
Comment: This depends on the connections you make. Connections from the VPS to anything are basically the same as if you would connect from your machine directly. In general, Connection security is mostly defined by the target machine security settings for the connection, not the route or your client.
Comment: You ask "How secure is a SSH tunnel to VPS virtual server?" then "what about the traffic behind the VPS?". Which is it?
Comment: How is this related to Ubuntu? This question would be much better on [Security.SE].
Answer: The VPS will be able to see

Websites/Serveraddresses you connect to.
Unencrypted contents (http, ftp, ...)

The VPS won't be able to see

Encrypted contents (https, sftp, ssh, ...)

Note: This is a general concern. You always have to use https OR trust your provider (and any node between you and the server) to not steal your passwords etc.

In terms of sneaking on which websites you visit, you always have to trust someone. It's just a matter who you trust more. Be it your VPS provider, your VPN provider, your ISP or your boss at work.
That said, there are networks that try to prevent that by rerouting your traffic through several nodes (e.g. TOR).


WP8, Consuming SOAP with self-signed certificate

Question: I am able to consume a webservice over SOAP. However, I would like to use an https connection with a self-signed certificate.
How can I force my app to use my certificate? I was able to achieve the same thing with Android.
Thank you, Martin.
Answer: A working example from one of my projects.
I'm not really sure if it will work on WP8, but on desktop everything works fine.
Here is the service class.
internal class PermissiveCertificatePolicy
{
    private string _subjectName;
    private static PermissiveCertificatePolicy _currentPolicy;

    public PermissiveCertificatePolicy(string subjectName)
    {
        _subjectName = subjectName;
        ServicePointManager.ServerCertificateValidationCallback += RemoteCertValidate;
    }

    public static void Enact(string subjectName)
    {
        _currentPolicy = new PermissiveCertificatePolicy(subjectName);
    }

    private bool RemoteCertValidate(object sender, X509Certificate cert,
        X509Chain chain, SslPolicyErrors error)
    {
        return cert.Subject == _subjectName;
    }
}

Here is the example of usage:
namespace WcfClient
{
    internal class Program
    {
        private const string RCertName = "CN=WMSvc-WIN-R0NU6K5QG87";

        private static void Main(string[] args)
        {
            PermissiveCertificatePolicy.Enact(RCertName);

            using (MyClient proxy = new MyClient("Ws2007HttpBinding_IHistory"))
            {
                ...
            }
        }
    }
}

Comment: Thank you for your help. I'm afraid ServicePointManager is not available for WP8.


Continuity under the integral sign?

Question: I've been reading Folland's Harmonic analysis book, in which he claims the following on page 56:

Suppose $G$ is a locally compact (and of course Hausdorff) topological group G, $H$ a (closed) subgroup of $G$, and $\displaystyle f\mapsto\int_Hf(h)dh$ a continuous linear functional on $C_c(H)$, the compactly supported functions on $H$. Then for any $f\in C_c(G)$, the function on $G$ given by $\displaystyle g\mapsto \int_Hf(gh)dh$ is obviously continuous.

How is this obvious? The only remotely close results of this sort I have seen are:

If $f\in C_c(X\times Y)$ and $\mu$ is a Radon measure on $Y$, then $\displaystyle x\mapsto \int f(x,y)d\mu(y)$ is continuous.
If $X$ is non-empty subset of a metric space, and $(Y,\Sigma,\mu)$ is a measure space, then $\displaystyle x\mapsto\int_Y f_x(y)d\mu(y)$ is continuous if $f\colon X\times Y\to\mathbb R$ is such that

each $f_x$ (given by $f_x(y)=f(x,y)$) is measurable
$x\mapsto f(x,y)$ is continuous for almost all $y$
there is an integrable $g\colon Y\to\mathbb R$ so that $|f(x,y)|\leq g(y)$

Neither of these shows what Folland claims since $(g,h)\mapsto f(g\cdot h)$ does not have to be compactly supported, and locally compact groups don't have to be metrizable.
Comment: Just a guess: can you uniformly approximate $f$ by a sum of things that look like delta functions?
Answer: OK, this should work. Since $f$ is $C_c(G)$, so is $L_{g^{-1}}f$. Let $K,K_g$ be the respective supports. Now apply the fact that $f$ is left uniformly continuous (cf. Prop 2.6, p.34) and that the Haar measures of compact sets are finite (Folland, $Real \ Analysis$, 2nd ed., p.341, Prop.11.4): If $F(g):= \int\limits_Hf(gh)\,dh$, one could prove the continuity of $F$ at $e$ as follows. Given $\epsilon>0$ there is an open $U\subset G$, a nbd. of $e$ such that for each $g\in U$, $||L_{g^{-1}}f - f||_\infty < \epsilon$. Hence, on $U$ $|F(g) - F(e)| = \left|\int\limits_H f(gh)\,dh - \int\limits_H f(h)\,dh\right| \le \int\limits_{K\cup K_g}|L_{g^{-1}}f(h) - f(h)|\,dh \le \epsilon\,\mu(K\cup K_g)$ where $\mu$ is the Haar measure on $H$. Now using the local compactness of $G$ and the usual compactness arguments, the RHS can be made independent of $g$ in a nbd of $e$.
Comment: Yes. Do you have a reference for this argument? Unless I'm misreading, Nachbin's book seems to mistakenly quote result #1 in my question (which leads me to believe Folland may have that incorrect argument in mind). In any case, I figured out that this proof can be unraveled and modified to show that for $f\in C_c(G/H)$, the association $gH\mapsto f_{gH}$ where $f_{gH}(\gamma)=f(\gamma gH)$ is a continuous map $G/H\to C_c(\Gamma)$ as long as one of $\Gamma$ or $H$ is compact (but both are closed). Any reference to this stronger fact would be appreciated as well.
Comment: The refs for the "left uniformly continuous" bit are Folland (AHA and RA). The compactness argument is of a routine sort. Btw, the dominated convergence theorem can also be used if instead one shows using compactness that the integrand is majorised by an $L^1$ function on some nbd of $e$. The first result quoted in your OP is proved as 7.34 Lemma, p.227, in Folland's RA, 2ed, provided both $\mu$ and $\nu$ are Radon. I don't have a reference to hand for the continuity of the map you mention.

Continuity under the integral sign?


A problem relying on van der Waerden's theorem, and the existence of sums divisible by a given number $n$

Question: Say we are given a sequence of integers $\{a_i\}_{i \in \mathbb{N}}$, as well as a pair of integers $n, m$. How can we show that there always exist positive integers $s, r$ such that the sums
$a_s + a_{s+1} + \cdots + a_{s+r -1},
\\
a_{s+r} + a_{s + r + 1} + \cdots + a_{s + 2r - 1},
\\
\quad \quad \quad \quad \quad \quad \vdots
\\
a_{s + (m-1)r} + a_{s + (m-1)r + 1} + \cdots + a_{s + mr -1}$
are all divisible by $n$.
My first instinct is to use van der Waerden's theorem, perhaps more than once, in order to make the argument work, but I'm having trouble making this argument rigorous. Does this approach even work?
Comment: Could you share your attempt?
Comment: I haven't actually gotten very far, which is why I'm seeking help. Basically the idea would be to inject our sequence onto the natural numbers, and then apply van der Waerden's theorem to get a collection of arithmetic progressions of length $r$ satisfying the desired property. We can then inject this new sequence onto $\mathbb{N}$ and repeat the argument to get the desired result.
Answer: Your idea is actually correct. Just consider the sums $S_k=a_1+a_2+....+a_k$ and color all integers in $n$ colours depending on their remainder modulo $n.$ More precisely, colour of $k$ is determined by $S_k\bmod n.$ Van der Warden then tells you that there is an arithmetic progression $S_s,S_{s+r},S_{s+2r}...S_{s+(m+1)r}$ with the same remainders modulo $n.$ Substract the latter to get the desired result.


When to use GSON to parse object?

Question: I am trying to pass an array list of objects from one activity to another. I have seen people use the GSON library to serialize objects, and have also seen people make their object implement the Parceable interface, or the Serializable interface. I am curious as to what the technical difference/advantages of using one over the other is.
Please note, this is not meant to be an opinion-based question, more of a technical inquiry.
Thanks in advance.
Comment: I don't know the answer, but I only use GSON if I am passing objects between devices or over a network. if its just one activity to another GSON is probably overkill.
Answer: Parcelable is the Android-specific recommended way to get data from one activity to another. See How do I pass data between Activities in Android application? for the specifics of how to do the passing.
Now if you were implementing a cross-platform application, or if you needed to send the same model to a web service, it might be beneficial to use JSON as a serialization format. Serializable could be used if you were only cross-platform but always with JVM languages. That said I would just implement both interfaces and use the best method for each application. JSON over the network and Parcels between activities.
In general when choosing a serialization method, you should consider what qualities you're looking for. Qualities like:

Maintainability
Network size
Serialization/Deserialization performance
Ease of implementation
Human readability

Pick whichever serialization format will get you the best for your use cases, and implement as many as you need to cover all of your use cases.

When to use GSON to parse object?


xpath expression to select text from link

Question: I have such content of html file:
book name
Help me to construct xpath expression to get link text (book name).
I try to use /a, but expression evaluates without results.
Answer: If the context is the entire document you should probably use // instead of /. Also you  may (not sure about that) need to get down one more level to retrieve the text.
I think it should look like this
//a/text()

EDIT: As Tomalak pointed out it's text() not text
Comment: There is no `` element under ``. You mean `//a/text()`.
Answer: Have you tried
//a

?
More specific is better:
//a[@class='bf' and starts-with(@href, '/book/')]

Note that this selects the  element. In your host environment it's easy to extract the text value of that node via standard DOM methods (like the .textContent property).
To select the actual text node, see the other answers in this thread.
Comment: your answer helped me more, but without starts-with parameter!
Comment: @alex: It was just meant to be an example of "more specific is better". ;)
Answer: It depends also on the rest of your document. If you use // in the beginning all the matching nodes will be returned, which might be too many results in case you have other links in your document.
Apart from that a possible xpath expression is //a/text().
The /a you tried only returns the a-tag itself, if it is the root element. To get the link text you need to append the /text() part.


Why does a 20MB JSON Array creates a 2GB Table

Question: in Oracle 19C DB i have a json with the following format
"rows":[[1, "sometext", "some other text", timestamp, ...],
[..],
...]

with 43 Items (most of them strings from 1 to 150 characters long) and 1.2 Mio Itemsets.
It is saved in a blob column (JSON_BLOB ~ 20 MB) of a table (JSON_BLOB_TABLE ) with the "is json" constraint.
When i create a table like:
CREATE TABLE MY_JSON_TABLE AS (
select j.*
from JSON_BLOB_TABLE d,
     json_table (
        d.JSON_BLOB, '$' columns (
            nested path '$.rows[*]' columns (
                col1 NUMBER PATH '$[0]',
                col2 VARCHAR2(8) PATH '$[1]',
                ...
            )
        )
     ) j
)

the size of this table by
SELECT BYTES/1024/1024 MB FROM USER_SEGMENTS WHERE SEGMENT_NAME = 'MY_JSON_TABLE';

is more than 2000 MB. How is that possible? The amount of rows in this table is still 1.2 Mio, no columns were added.
Am i missing an important table configuration here to save space?
Comment: 2 GB  in Json for 1,2 million records is not so much. You could use `compress` for the table
Comment: I wouldn't be concerned about that space. 2 gb is barely a rounding error in a data center..  Thumb drivers bigger than that cost less than lunch..  But as to the question, "why", you'd need to look at the storage parameters for the table in question.  There is always overhead in table storage - it's not just the data itself that takes space.  Look at things like 'PCTFREE, PCTUSED, and INITTRANS.  Before making changes to thes just to save a few measly MB, be sure you understand what they mean, why they are currently set the way they are, and the impact of changing them.
Answer: You made two significant errors in your observation:
First you confuse the size of the data and the size of the table.
The latter is always higher due to overhead and free space
Here simple example - the table has 1000 rows with approx. 1000 bytes per row
create table tab as
select rownum id, lpad('x',999,'y') txt
from dual connect by level <= 1000;

But it allocates 2 MB
select BYTES/1024/1024 MB  from user_segments where segment_name = 'TAB';
        MB
----------
         2

But the size of the data in the table is as expected close to 1MB  (checking the table statistics)
select NUM_ROWS, AVG_ROW_LEN,
(NUM_ROWS * AVG_ROW_LEN) /1024/1024 MB
from user_tables where table_name = 'TAB';

  NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
      1000        1004 ,957489014

The second problem which is more serious is your estimatimation of the JSON column size.
create table tab_json as
select 1 id,
JSON_ARRAYAGG(JSON_OBJECT (id, txt RETURNING BLOB) ORDER BY id RETURNING BLOB)  js
from tab;

select BYTES/1024/1024 MB  from user_segments where segment_name = 'TAB_JSON';

        MB
----------
,0625

The table with JSON column (stored as BLOB) containing all the data of 1 MB is only 62 KB large! How is this possible!!
Very simple - the JSON is stored as BLOB i.e. not in the table, but in LOB segment. You must find the LOB segment in USER_LOBS and check it's size
select SEGMENT_NAME from user_lobs where table_name = 'TAB_JSON';

SEGMENT_NAME
-------------------------
SYS_LOB0000073542C00002$$

select BYTES/1024/1024 MB  from user_segments where segment_name in (
select SEGMENT_NAME from user_lobs where table_name = 'TAB_JSON');
        MB
----------
    2,1875

Now if you compare the whole size of the JSON table (i.e. table segments + LOB segments) you see there is no big surprise but the results are comparable.


HTML table structure is getting flattened

Question: Lo here, mighty internets! I'm coding emails (ugh!), so evidently that means more tables than I've written in a decade. Aside from how some deprecated properties get ignored, it seems browsers also flatten the structure of a table.
So, let's say I have these tables here. The first one outputs as expected, a 2-column layout. The second one doesn't. Adding tr and td elements to contain the insides of a cell actually breaks the layout.
To see it happen, inspect the resulting output. You'll notice that the second table becomes a bunch of tr tags. The td that controlled the width:

is rendered as an empty element, instead of containing its children tr and td tags.
My question: does anyone know why that's happening?
EDIT: for reference, the W3C validator complains of stray end tags, but they're closing something properly. This HTML was auto-generated from a Pug template, I don't think it's invalid.
Answer: Simple mistake - prepare a facepalm.
You forgot to initiate the nested table, aka you forgot to put in a table tag on the interior tables prior to the new TR tag.
The structure needs to be TABLE - TR - TD - TABLE - TR - TD - CONTENT when you use a nested table.
You previously had: TABLE - TR - TD - TR - TD - CONTENT - which results in your code trying to correct itself and move the TRs around into a valid format, creating the weirdness you experieinced.
See below for corrected HTML:
<!DOCTYPE html>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>

Alles auf einen Blick

Zu den Themen EU-Regulierung, Kostenkontrolle, Datenroaming oder Ländergruppen finden Sie wichtige Hinweise auf unseren Info-Seiten.

        <button>Jetzt informieren</button>

Schnell zur Lösung

Finden Sie jederzeit und unkompliziert den direkten Weg zur Lösung Ihres Anliegens. Unser Hilfe & Service Bereich ist die richtige Anlaufstelle.

        <button>Jetzt entdecken</button>

Alles auf einen Blick

Zu den Themen EU-Regulierung, Kostenkontrolle, Datenroaming oder Ländergruppen finden Sie wichtige Hinweise auf unseren Info-Seiten.

            <button>Jetzt informieren</button>

Schnell zur Lösung

Finden Sie jederzeit und unkompliziert den direkten Weg zur Lösung Ihres Anliegens. Unser Hilfe & Service Bereich ist die richtige Anlaufstelle.

            <button>Jetzt entdecken</button>

Comment: So you can't have `tr` inside `td` tags? You need an additional `table` as a container?
Comment: Yeah, it's legit. I added the extra `table` tags and it works. :facepalm:


Find a path that is less than n pixels far from mouse position in D3

Question: I'm trying to improve selecting lines on chart by increasing margin of error for click by few pixels. I found very good solution that is using Voronoi algorithm:
https://bl.ocks.org/mbostock/8033015
This is very smart approach, but has no use in my case. I just want to implement some kind of override function for click that spreads the range of click to few nearest pixels.
Answer: One simple solution is to create a double of your path, with a transparent bigger stroke, and listen to this double's event.
Here is a non d3 proof-of concept:

.bg {
  stroke: transparent;
  stroke-width: 25px;
  fill: none;
}
.fg {
  stroke: black;
  stroke-width: 1px;
  fill: none;
}
.bg:hover + .fg {
  stroke: red;
}
.fg:hover {
  stroke: green;
}
<svg width="500" height="500">
  <path class="bg" d="M 100 100 L 300 100 L 200 300 z"></path>
  <path class="fg" d="M 100 100 L 300 100 L 200 300 z"></path>
</svg>
Comment: Yes, I also considered this approach, but the problem appears when the paths (the visible ones) are too close to each other. E.g. one of them is 2px far from the point of click and second is 8px far. The second will be clicked because it covers the first one. Btw. I found another solution for now. I'm listening for click event on whole svg, getting mouse position from event and looking for elements that are paths in the nearest neighborhood of this mouse position.
Comment: @mankers all solutions will come with this exact problem. If two pathes are as close as the mouse coords, then you have to choose. With above solution, this can be controlled through the place in svg tree your nodes are.
Comment: Yes, you're right, but I want to simply find the one that is closer, so I think that the approach to check all neighbors, starting from the exact point of click, then iterate through the points laying on the circle with radius 1px. No success - increase radius and keep checking. We can then set maximum radius and when we achieve it we stop with no success. I know that it's more time consuming, but the maximum radius that I'm interested in is not going to be bigger than 3px.
Comment: I've just known further requirements for my task and it seems that my solution is too slow now. I also have to handle mouse move event, so it's not good idea to do these calculations after every mouse movement. Another reason to accept your approach is quite small prescision (3px), so the situations like I described in previous comment (paths overlapping) should be very rare and unnoticeable to user. Thanks a lot for your help! +1