text:
Q: How to stop a thread when you exit Kivy I wrote the following code:
test.py
#-*- coding: utf-8 -*-

import time
from kivy.app import App
from kivy.uix.widget import Widget
import threading

class TextWidget(Widget):
    def __init__(self, **kwargs):
        super(TextWidget, self).__init__(**kwargs)
        self.thread1 = None
        self.thread2 = None
        self.stop_flag = True

    def printTime(self):
        print(time.time())

    def schedule(self,interval, f, wait=True):
        base_time = time.time()
        next_time = 0
        while not self.stop_flag:#接続を切るボタンが押されるまでループ
            self.thread2 = threading.Thread(target=f)
            self.thread2.start()
            if wait:
                self.thread2.join()
            next_time = ((base_time - time.time()) % interval) or interval
            time.sleep(next_time)

    def thread_start(self):
        self.stop_flag=False
        self.thread1 = threading.Thread(target=self.schedule,args=(1.00/200, self.printTime, False))
        self.thread1.start()

    def thread_stop(self):
        if self.thread1:
            self.stop_flag=True
            self.thread1.join()
            self.thread1=None

class TestApp(App):
    def __init__(self, **kwargs):
        super(TestApp, self).__init__(**kwargs)
        self.title = 'test'

if __name__ == '__main__':
    TestApp().run()

test.kv
TextWidget:

<TextWidget>:
    BoxLayout:
        orientation: 'vertical'
        Button:
            text: "thread_start"
            on_press: root.thread_start()
        Button:
            text: "thread_stop"
            on_press: root.thread_stop()

It works with the start button and stop button of the thread, but when I press the close button in the upper right corner of the window to end it, the thread continues to remain.
How can I close the window and close the thread at the same time?
The past questions seemed to be helpful, but the Widget class was not written, so I didn't know how to imitate it.
How to run a Method on the exit of a kivy app

A: Like mentioned by John above, a daemon thread runs without blocking the main program from quitting. So, if the main program is killed, the thread is also killed.
Refer this for more details!


text:
Q: relation between gradle version and gradle build tool version I'm new to gradle and got 2 questions:

*

*gradle itself is a build tool, so why is the need for Android gradle tool com.android.tools.build:gradle:0.7.+ in the script?

*What is the relation between the version of gradle installed (say 1.9) and the version of that Android gradle tool, like 0.7.+ in classpath 'com.android.tools.build:gradle:0.7.+'. If I changed the latter's version to 0.8.+ then the build fails on 'could not find plugin AppPlugin'.

A: I will try to answer your questions.

*

*As you said, Gradle is a build tool, but the line you have mentioned in your first question is referring to Gradle Java plugin version. Gradle has plugin for building Java projects. These plugins extend upon the general purpose build tool Gradle is, and may provide additional features. You can read more about the Gradle plugins here.

*The reason your build fails when you change the plugin version is simple, the plugin version 0.8 is not there. There is a relationship between Gradle version and the plugin version and a developer has to maintain that. You can only use a plugin version which has been released and is compatible with the Gradle version. I hope the answer to first question answers this anyways.

A: 1) Gradle is a build tool, but it requires specific plugin to work.
Android Tool Team is releasing the Android plugin for Gradle.
com.android.tools.build:gradle:0.6.+
com.android.tools.build:gradle:0.7.+
com.android.tools.build:gradle:0.8.+

Here you can find the repo:
https://android.googlesource.com/platform/tools/base/
The current dev branch is idea133. Otherwise you can check gradle_0.8/gradle_0.7 branches.
2) There is a  relation between gradle-plugin and the gradle version.
For example
com.android.tools.build:gradle:0.6.+  -> gradle 1.8
com.android.tools.build:gradle:0.7.+  -> gradle 1.9
com.android.tools.build:gradle:0.8.+  -> gradle 1.9/1.10

You can find gradle version used in your project in the file gradle/wrapper/gradle-wrapper.properties
Also there is a  relation between gradle-plugin and the IDE version.
For example:
Android Studio 0.3.x -> gradle-plugin 0.6
Android Studio 0.4.x -> gradle-plugin 0.7
Android Studio 0.4.3+ -> gradle-plugin 0.8

For updated news you can check this link: http://tools.android.com/recent
You can also check this updated post:
Android Studio Gradle issue upgrading to version 0.5.0 - Gradle Migrating From 0.8 to 0.9 - Also Android Studio upgrade to 0.8.1
If you change your plugin version, check compatibility, and then click sync project with your gradle files.It will download a new plugin version if you need it.

redpajama_set_name: RedPajamaStackExchange


text:
Q: How to remodel sigmoid function so as to move stretch/enlarge it? I have a question similar to this.
I want the sigmoid to have asymptotes to $+1$ and $0$ in specific points $\frac{1}{A}$ and $-\frac{1}{A}$, as in the Figure (where $\frac{1}{A}=2$ and $-\frac{1}{A}=-2$).

How can I modify the curve
$S(t) = \frac{1}{1+e^{-t}}$
so as to make this happen?
Thank you.

A: The original $S(t)$ has flexes at $t=\log(2\pm\sqrt 3)$. Now define
$$
Z(t)=S(kt)
$$
for some stretch scalar $k\in\mathbb R^+$, and convince yourself that $Z'''(t)=0$ iff $S'''(kt)\cdot k^3=0$ iff $S'''(kt)=0$. Hence $Z(t)$ has flexes at
$$
t=\frac{\log(2\pm\sqrt 3)}{k}=\pm\frac{1}{A}
$$
and for $A,k>0$ this leads to
$$
k=A\log(2+\sqrt 3)
$$
which makes $Z(t)=S(kt)$ solve your problem. Thus the final form matching requirements for the flexes is
$$
Z(t)=\frac{1}{1+\text{e}^{-A\log(2+\sqrt 3)t}}
$$

If in addition to that we want $W(\pm\frac 1A)=\pm 1$, then by symmetry around the point $(0,0.5)$ this simply means
$$
W(t)=\frac{1}{Z(1/A)-0.5}(Z(t)-0.5)
$$
here is a graph showing $S(t),Z(t)$ and $W(t)$ defined this way.

Here $S(t)$ is blue, $Z(t)$ is red, and $W(t)$ is purple.

EDIT: OK, I think that I know a function that could do the job, if you want it. In the theory of smooth manifolds, we use so-called bump functions based on the function $$
f(t)=
\begin{cases}
\text{e}^{-1/t}&\text{ for } t>0\\
0&\text{ otherwise }
\end{cases}$$
which can then be used to define a function with a graph similar to what you are suggesting here, namely $$h(t)=\frac{f(t/4+1/2)}{f(t/4+1/2)+f(1/2-t/4)}$$
having the following graph:

where $f(t)$ is the red curve and $h(t)$ is the blue curve. Note that $h(t)\in(0,1)$ for $t\in(-2,2)$ and $h(t)\in\{0,1\}$ elsewhere.


text:
Q: Why does comparing Integers by reference (==) work? In Herbert Schildt's "Java: The Complete Reference, 9th Edition", there's an example that kinda baffles me. Its key point that i can't comprehend could be summed up to the following code:
class Test {
    public static void main (String args[]) {
        Integer i1 = 6;
        Integer i2 = 6;

        Integer i3 = 6;
        Integer i4 = (args.length + 1) * 6;

        if (i1 == i2) System.out.println("WTF");
        if (i3 == i4) System.out.println("Super WTF!!!");
    }
}

To my surprise, the result of compiling and executing such code using JDK 8 update 40 is as follows:
WTF
Super WTF!!!

All the Java books, manuals and other informational resources that i've seen state that the equality operator (==), when used to compare objects, simply matches their reference values. So, if two object variables refer to distinct instances, then the == operator returns false, even if the internal contents of those objects are the same. Which is quite different from the behavior expressed by the example above.
While checking SO for similar questions, i found a somewhat related one, which is about comparing String objects using ==. There, an interesting feature of Java called interning was mentioned. Apparently, all the string literals and compile-time string constants are sort of "cached" by JVM, so that, for example, multiple String references initialized with the same string literals actually point to the same object.
But here we deal with numeric values and Integer objects. Also, one of the variables, i4, is initialized using a number of command line arguments supplied to the program, which is definitely a run-time information. Yet, == still finds it equal to i3.
So, given all the above, how exactly is the equality operator supposed to work in Java? Does it, or does it not, inspect the objects' contents when comparing them?
Thanks!

A: Integer objects are cached as mentioned by the Javadocs of Integer#valueOf(int):

This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

The statement Integer i4 = (args.length + 1) * 6; calls Integer#valueOf(int) which returns the cached instance. On the other hand, if you use Integer i4 = new Integer((args.length + 1) * 6);, the reference equality will return false.

A: I think the example shows us how java int pool is working. So in the i4 case if you provided no arguments on runtime the result is 6. Now the int pool kicks in and uses the i1 value which is part of the -128 to to 127 int pool. So on an object level they really equal and that's what == is all about.

A: When you autobox an int, you're internally calling Integer.valueOf(int), which according to the documentation may return cached values. So it makes perfect sense that you're seeing reference equality.
More generally, you should never assume two references are distinct unless you explicitly constructed them. And for the record, string interning is available at runtime as well, through the String.intern() method.


text:
Q: Does the order of table references matter in MySQL? Consider the following simplified query:
SELECT * FROM x, y JOIN z ON z.id = x.bean_id

It doesn't work; MySQL (Technically MariaDB 10.0.21) gives the error:
Unknown column 'x.bean_id' in 'on clause'

However, if I switch the order of the table references (x, y becomes y, x), then the query executes successfully:
SELECT * FROM y, x JOIN z ON z.id = x.bean_id

What's going on here?

A: Your immediate error can be relieved by wrapping the x, y implicit cross join in parentheses:
SELECT * FROM (x, y) JOIN z ON z.id = x.bean_id

I think the error has to do with ambiguity as to which join y belongs.
Demo
But you are mixing the old school implicit join syntax with the modern (and proper) explicit join syntax.  Don't do that, in fact don't use the old join syntax at all.  Instead, always use explicit joins:
SELECT *
FROM x
INNER JOIN y
    ON x.id = y.id
INNER JOIN z
    ON z.id = x.bean_id;

A: The code looks suspect in that there is an implicit join between x and y:
SELECT * FROM y, x JOIN z ON z.id = x.bean_id

Is there a missing join condition between x and y?
Or is it your intention to do a cross join between x and y, and have a join condition purely on whether z? A cross join is a relatively unusual kind of join.
If the latter, I would rewrite the query to make it clear, for example:
SELECT
    *

FROM
    x

CROSS JOIN
    y

INNER JOIN
    z
    ON (z.id = x.bean_id)

The above is exactly equivalent to your current code which you say is working.
Alternatively, if there is a condition missing from the join between x and y, then it would take the following form:
SELECT
    *

FROM
    x

INNER JOIN
    y
    ON (/*INSERT MISSING JOIN EXPRESSION BETWEEN x AND y HERE*/)

INNER JOIN
    z
    ON (z.id = x.bean_id)

A: Yes, it matters.

However, the precedence of the comma operator is less than that of INNER JOIN, CROSS JOIN, LEFT JOIN, and so on. If you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur. Information about dealing with this problem is given later in this section.

Pls see https://dev.mysql.com/doc/refman/5.7/en/join.html for more details.
BTW, Why do you use x,y,z to stand for your situation, but the error message is orignal column name 'bean_id'?


text: Q: cat: /var/lib/dhcp3/dhclient.leases: No such file or directory I searched on how to print dhcp details on Ubuntu , I found few information here. However it always displays "/var/lib/dhcp3/dhclient.leases: No such file or directory". How to resolve this issue ?


text:
Q: process control Lets say I have a file, and the permissions of that file change.I want to log, report, and even require authentication for all changes to that file (even as root). as in, I do not want this file to change in anyway, without asking my permission first, and I want detail about what process, user, time, memory allocation is requesting the change. Any thing that attempts to access the file must be reported.
In windows I use strict process control to do this. How can I achieve this level of process control in linux?

A:
require authentication for all changes to that file (even as root)

I have a feeling that this is not possible. Definitely not completely waterproof. The superuser is God on the system.

To monitor a file or folder, you can use the following command:
sudo apt-get install auditd    # if not already installed

sudo auditctl -w <path_to_file> -p w -k <filter_key>
sudo ausearch -k <filter_key>

Example:
$ sudo auditctl -w /etc  -p w -k etc
$ sudo touch /etc/test
$ sudo ausearch -k etc
----
time->Tue Apr 21 15:40:36 2015
type=CONFIG_CHANGE msg=audit(1429623636.816:8542): auid=4294967295 ses=4294967295 op="add_rule" key="etc" list=4 res=1
----
time->Tue Apr 21 15:40:45 2015
type=PROCTITLE msg=audit(1429623645.648:8547): proctitle=746F756368002F6574632F74657374
type=PATH msg=audit(1429623645.648:8547): item=1 name="/etc/test" inode=136296 dev=08:01 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE
type=PATH msg=audit(1429623645.648:8547): item=0 name="/etc/" inode=131073 dev=08:01 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT
type=CWD msg=audit(1429623645.648:8547):  cwd="/"
type=SYSCALL msg=audit(1429623645.648:8547): arch=c000003e syscall=2 success=yes exit=3 a0=7ffd8f419d9d a1=941 a2=1b6 a3=691 items=2 ppid=7399 pid=7400 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=4294967295 comm="touch" exe="/bin/touch" key="etc"

from man auditctl:
-p [r|w|x|a]
      Describe  the  permission  access  type that a file system watch
      will trigger on. r=read, w=write, x=execute, a=attribute change.
      These  permissions  are  not  the standard file permissions, but
      rather the kind of syscall that would do this kind of thing. The
      read & write syscalls are omitted from this set since they would
      overwhelm the logs. But rather for reads  or  writes,  the  open
      flags are looked at to see what permission was requested.

A: Setting immutable attribute on the file would help preventing any changes to it.
As for monitoring - you can probably achieve it in many ways starting with some shell script verifying size, checksum, modification time or whatever else you find useful, ending on some more sophisticated integrity checking solutions like tripwire or whatever currently is recommended. For one file it may be a bit overkill, however. (and not sure if tripwire isn't actually currently a bit outdated - may be good anyway to look for this kind of solution if monitoring of changes is required)
And that probably still doesn't exhaust options. :)

A: You can choose tripwire file integrity manager.
http://www.tripwire.com/register/tripwire-enterprise-file-integrity-manager/
http://www.thegeekstuff.com/2008/12/tripwire-tutorial-linux-host-based-intrusion-detection-system/


text:
Q: How to echo a variale in html (newbie) I wan to echo a random swf variable into html, but I can not seem to get the right result.
By checking with firebug I can see that it outputs my php code php echo '$randomImage'
What I have so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

<?php

$imagesDir = '/';

$images = glob($imagesDir . '*.{swf}', GLOB_BRACE);

$randomImage = $images[array_rand($images)];

?>

  <object width="675" height="517"><param value="<?php echo '$randomImage' ?>" name="movie"><embed width="475" height="317" type="application/x-shockwave-flash" src="<?php echo '$randomImage' ?>"></object>

A: Remove the quotes.
<?php echo $randomImage; ?>

PHP interprets that as a string rather than the variable $randomImage. You can use variables in quotes but they have to be double quotes like so.
echo "$randomImage";

There is no reason to do this however because you can just echo the variable. This is useful in situations when you want to format a string with multiple variables without concatenation operations.
echo "Hello, my name is $myName!, I am a $species.";

Which is more simple and readable than the alternative.
echo "Hello, my name is ", $myName ,"!, I am a ", $species ,".";

A: You either:

*

*Need to use double quotes

*Can get rid of the qutes altogether

By placing your variable in single quotes you are telling PHP that your dollar sign is to be taken literally and not used to indicate that there is variable.
So use
<?php echo $randomImage ?>

Or
<?php echo "$randomImage" ?>

A: To echo properly you should remove the quotes '$randomImage' -> $randomImage or you can wrap them in "" (double quotes) "$randomImage"


text:
Q: I am trying to "split text to column" on a .csv file in pages I have one column that is asking for my customer's name, some of my customers put just one and others put several names (first, last, title, etc.) I am trying to change this column to split at the space. I found an answer on here that gave me the following formulas LEFT(C2, FIND(" ",C2,)) and =RIGHT(B2, LEN(B2)−FIND(" ", B2)) This is working for me BUT if there is no space (they only put their first name) then it won't split out to the first column making half my users not have a first name.

A: In the event that the user inputs one name with no spaces, the formula in the OP could be wrapped in an IFERROR formula.
IFERROR(TRIM(RIGHT(B2, LEN(B3)−FIND(" ", B2,))),"")

The IFERROR statement returns simply and empty string "" if there are no spaces.  (No spaces returns an error because FIND() results in an error when it cannot find a space.) The formula returns the characters to the right of the space. If no spaces found, it simply returns the contents of B2. (Of course, there is no way for the computer to know if the single name entered is a first or last name, even tricky for humans.)
Something similar could be used to return the first name or just the name in the original string:
IFERROR(TRIM(LEFT(B2,FIND(" ", TRIM(B2)))),B2)

The only gotcha will be if there are several names.  But this is a good starting point. A useful resource is the Formulas and Functions Help for the Mac apps—Keynote, Pages, Numbers, and iBooks Author.  Look for Text Functions.  Good function combinations can give the desired result.  Work from the inside out.  For example, TRIM(B2) will remove all leading and trailing spaces. Then, FIND(" ",TRIM(B2)) will look for the first space without having to worry if there was a leading space.  Hope this helps!
Examples:


text:
Q: What is the maximum size of message that can be transferred from one bolt to another in a topology I have a topology in build using streamparse, it receives input from kafka and later spout transmits the message to master bolt,
Master bolt computes and generates 10 MB of message and this message must be passed to other 3 bolts.
The data is getting generated successfully in the master bolt, but getting the following error while it is getting transferred to the other Bolt
ERROR Unable to write to stream UDP:localhost:514 for appender syslog: org.apache.logging.log4j.core.appender.AppenderLoggingException: Error flushing stream UDP:localhost:514

A: The log you posted doesn't seem to have anything to do with message size. It's saying it can't write a log to localhost:514. Maybe your logging is misconfigured?
As far as I know, the maximum message size is solely determined by your max heap size, so it will depend on your RAM and JVM configuration. I'd be surprised if you're hitting a limit at 10 MB.


text:
Q: Quick and Simple Real Analysis Bound Given the inequalities:
$$|f(x) - g(x)| < \epsilon\quad \forall \quad x \in [a,b]$$
and
$$|g(x)| < M \quad \forall \quad x \in [a,b]$$
where $\epsilon > 0$ and $M > 0$.
What is the tightest bound that I can get on $|f(x)|$

A: Triangle inequality gives us
$$|f(x)| \leq |f(x) - g(x)| + |g(x)| < \epsilon + M$$


text:
Q: React progress element has a bug on IE10 Why is IE10 (I haven't checked in IE11 and above) rendering value 1, regardless of the value I am passing in, when rendering a progress element using React?
var Hello = React.createClass({
  render: function() {
    return <progress value="50" max="100"></progress>;
  }
});

ReactDOM.render(
  <Hello />,
  document.getElementById('container')
);

Check out this fiddle - https://jsfiddle.net/co4wz3ft/5/
It works as expected in Chrome and Firefox.

A: After countless desperate attempts, I found out that inverting the order of the properties (declaring max before value) fixes the issue:
var Hello = React.createClass({
  render: function() {
    return <progress max="100" value="50"></progress>;
  }
});

ReactDOM.render(
  <Hello />,
  document.getElementById('container')
);

I assume React was trying to set the value, before setting max, then value would be trimmed to the default max, which is one. But I am still keen to hear a better explanation from someone else!

A: Hello I've updated your fiddle like this and it seems to work: https://jsfiddle.net/co4wz3ft/11/
var Hello = React.createClass({
  render: function() {
    return <progress value="0.7"></progress>
  }
});

ReactDOM.render(
  <Hello name="World" />,
  document.getElementById('container')
);

It needs further investigation but you may use it like that right now.


text:
Q: System.ArgumentException: The "RecursiveDir" name is reserved, and cannot be used I have a line in an csproj file:
<MSBuild Projects="..\WebUI\WebUI.csproj" Targets="_CopyWebApplication;_BuiltWebOutputGroupOutput" Properties="OutDir=%(WebOutputDir.FullPath);WebProjectOutputDir=%(WebOutputDir.FullPath)" />

that is throwing the error:
System.ArgumentException: The "RecursiveDir" name is reserved, and cannot be used.
I've managed to narrow it down to the one line, and I'm not sure how to resolve so that this builds.  This is a TFS 2015.3 server.  The project has been building successfully on a Bamboo server, we're moving to TFS.

A: You're hitting an MSBuild bug. To work around it, set the MSBUILDTARGETRESULTCOMPRESSIONTHRESHOLD environment variable to a high number, for example:
SET MSBUILDTARGETRESULTCOMPRESSIONTHRESHOLD=1000000


text:
Q: Create Shared Variables in Memory For Child Process to Parent C# I'm programming a local streaming service. And I need to use two different Process for Server Software (Do not ask why e.e). The "child" Process Makes The Hardwork and I need to get results, but the workflow are in milliseconds ('cause is a videogames stream service). I tried with: Process.OutputDataReceived EventHandler, but the results are a lot of text and the Console takes valious time to write.
Also I tried with FileStream, But by logic and research I knew that using MemoryStream is faster to store and obtain data. The problem is that I do not know how to obtain the data that the child process saves.
The next code is not bad, but it's just to let them know that I also try with that code:
Parent Process:
public class MemoryRead
{
    Process process = null;
    int bufferSize = 256000;

    public MemoryRead(Process Process, int BufferSize){
        process = Process;
        bufferSize = BufferSize;
    }

    const int PROCESS_WM_READ = 0x0010;

    [DllImport("kernel32.dll")]
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

    [DllImport("kernel32.dll")]
    public static extern bool ReadProcessMemory(int hProcess,
      int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);

    public string GetString(int BytesAdress = 0x0046A3B8)
    {
        IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
        int bytesRead = 0;
        byte[] buffer = new byte[bufferSize];
        ReadProcessMemory((int)processHandle, BytesAdress, buffer, buffer.Length, ref bytesRead);

        return Encoding.UTF8.GetString(buffer);
    }

}

Child Process:
GCHandle handler = GCHandle.Alloc(VideoData, GCHandleType.Pinned);
IntPtr address = handler.AddrOfPinnedObject();
Console.WriteLine((address.ToString()));

The Child Process returns a int "address", and I Get that with Process.OutputDataReceived EventHandler to Call MemoryRead.GetString(), but that returns null, Basically as if the address did not exist. I just want more options, also if they have nothing to do with MemoryStream.


text:
Q: How to model financial HFT time-series data with multi scale autocorrelation I work with tick level time-series univariate prices data. Tick level means that there are hundreds to thousands observations per second. The observations are timestamped, so one can use both wall clock and event time (or whatever you want). Most of the price changes are very small (1e-5 of %), but the small changes add up and there might be occasional big price changes. Sometimes there is little activity, sometimes there are clusters of high activity (bigger and more frequent price changes). There is strong autocorrelation structure at the scale of milliseconds and seconds due to market microstructure. Strong means that the difference between current price and the predicted price is big enough to make money in practice. There is also weaker autocorrelation at longer time scales (minutes, hours, days), but as the effects are more long-lasting, they add up and it is easier to exploit it because you have more time to react, so actually these long-term autocorrelations are also important in practice.
The goal is to model the autocorrelation structure of the price process to get a long-term price forecast that would incorporate the information about autocorrelation at different scales. I am looking for a solution that works at least somehow:

*

*it is computationally feasible,

*it doesn't leave out huge (like 50%) chunks of information

The solution doesn't have to be grounded in formal theory (specifying a proper stochastic process and estimating its parameters) and it doesn't have to be perfect (a consistent, or even "almost kind of consistent" estimator is enough, no efficiency or unbiasedness is needed). In my opinion, please prove me wrong, for the datasets of this size (1bln univariate observations), computational feasibility means OLS, probably with online/chunk updates.
What are the options known to me?

*

*

*

*Self-exciting point processes. This is theoretically the
right way to model this situation. However, to the best of my
knowledge (I've never seriously tried them), it is computationally
feasible only for an unrealistically simplified case that loses most
of the information (100k observations subsample, a simple kernel
that captures only positive autocorrelation at one scale). Does
anybody know if these are successfully used in practice in finance?

*ARIMA. Just work in event time and you have equally spaced
observations. MA is not very useful, because of the empirical
autocorrelation structure and computational complexity. So ARIMA
actually means AR. A big advantage is that you can get an integrated
n-step ahead forecast (sum of expected future price changes n steps
ahead) in a closed form. The problem here is that if you want to
capture different autocorrelation at both tick frequency and 1
second frequency, then with 1000 observations per second you need
AR(1000). A simple AR(1000) would be both computationally infeasible
and would give way too much "preventable" variance in the estimates.
And for 1 tick and 1 day frequency one would need AR(86 400 000). I
think that this is a solvable problem using a HAR (Hererogeneous AR)
approach, some kind of sampling and iterative aggregation at
different frequencies (even if this would be totally unsound from a
theoretical perspective).

*ARFIMA and other fractal and multi
scale stuff. Sound relevant, but computationally infeasible with no
gain to show for it. I've tried it many times and it totally doesn't
work. Does anybody know if these are successfully used in practice
in finance?

*Frequency domain. I was looking for non/semiparametric estimators for the auto-correlation function. Working in frequency domain could also be used to diagnose how much variance is there on different frequencies. I didn't get any encouraging results here, maybe it is totally irrelevant, maybe I am just very weak in this area.

*Continuous time task formulation. I don't even
know how to formulate a momentum (positive returns autocorrelation)
continuous time process. I think this might help with conceptual
understanding, but I don't see how this helps with empirical
estimation.

*Subsampling. Use various smart subsampling schemes to
reduce the amount of data while retaining most of the information.
Event time, cusum on price change, cumulative realised volatility. I
think this must totally be part of the solution.
I see the biggest opportunity in the following approach. Firstly, use an unusually large "regularised" (or semiparametric?) AR model (~20 parameters, taking into account lags up to ~1000), for example something like HAR (Heterogeneous AR). This still doesn't allow to combine daily and tick frequency in one model. So, secondly, we need to use one model to estimate high frequency component, then get its predictions, subsample data to decrease frequency, estimate a model for a different frequency. Such multi scale model combination sounds totally theoretically unfounded (a subsampled AR process is not AR) and I am not sure if it would work in practice.
Do you know

*

*a solution

*a potential approach that I've missed here

*what is used in practice by quants?

*non/semiparametric approaches to estimating the auto-correlation function

This might be a bit of an open-ended and (hopefully) discussion-inspiring question, but it is very practical for me and I think it would be very practically useful for other quant traders.


text:
Q: automatic repaint when minimizing window I have a JFrame, with two panels, in one panel I draw a line, as I was working I minimized the Window of the java program i'm doing, when i maximized it THE LINE THAT I DREW WAS DIFFERENT, it repainted it in a different place!
Does anyone have an idea of how to lock the painting so that when i minimize it doesn't screw the drawing??
Thank you!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

class JFramePaint1 extends JFrame implements ActionListener /*implements ActionListener*/{

    public static int activa = 0;
    public static JButton drawing = new JButton("drawing");
    public static JButton erase = new JButton("erase");
    public static int x1=0, y1=0,x2=0,y2=0;

   public JFramePaint1(){
                                                    //row column
      JPanel container = new JPanel(); //new JPanel(new GridLayout(2,1));
      JPanel header = new JPanel();
    //  header.setLayout(new GridLayout(50, 2));
    // header.setLayout(new FlowLayout());
     header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS));
     container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS)); //lo quite ahorita
     // container.setLayout(new FlowLayout());

     ContentComponent c = new ContentComponent();

      drawing.addActionListener(this);
      erase.addActionListener(this);

    //header.setSize(30,30);

     //drawing.setAlignmentY(Component.BOTTOM_ALIGNMENT);
     container.add(Box.createRigidArea(new Dimension(100, 0)));

     header.add(drawing); //lo quite ahorita
     header.add(erase);
     container.add(header);
    //container.add(Box.createRigidArea(new Dimension(5,0)));
    //header.add(drawing);

      // container.add(header);
      container.add(c);   //lo quite ahorita

      add(container);

    //  add(c);
       //add(c);
   }
   public static void main(String[] a) {

        JFramePaint1 VentanaDiverti = new JFramePaint1();
        VentanaDiverti.setSize(800, 700);
        VentanaDiverti.setLocation(200, 0);
        VentanaDiverti.setTitle("Diverti");
        VentanaDiverti.setResizable ( false );
        VentanaDiverti.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        VentanaDiverti.setVisible(true);

    /* JFrame f = new JFrame();
    // JFramePaint1 f = new JFramePaint1();
       f.setTitle("Drawing Graphics in Frames");
        f.setSize(800, 650);
        f.setLocation(200,50);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        f.setContentPane( new ContentComponent());
        f.getContentPane().add(b);

        //f.addWindowListener(this);
        //b.addActionListener(this);

        f.setVisible(true);*/

   }
   static class ContentComponent extends JPanel {

     public void paint(Graphics g) {

         BufferedImage image;
         /*reset the variables, this makes the repaint look the same! it's as comments so that you can see what happens
         x1=0;
            y1=0;
            x2=0;
            y2=0;
        */
       try {
          image = ImageIO.read(new File("image name and path"));
       } catch (IOException ex) {
            // handle exception...
       }

         g.setColor (Color.RED);
         // void    fillRect(int x, int y, int width, int height)
         // Fills the specified rectangle.
         g.fillRect(0, 0, 800, 600);
         if( activa == 1){

         g.setColor(Color.BLACK);
        // g.drawRect(40, 40, 150, 80);
         int x = 40;
         int y= 40;
         for(int i = 0; i< 4; i++){

            //g.drawRect(x+10, y+10, 150, 80);
            x = x+10;
            y = y+10;
         }
         //drawLine(int x1, int y1, int x2, int y2)
         //Draws a line, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
           x1+=20;
           x2+=20;
           y2+=50;
           g.drawLine(x1,y1,x2,y2);
           x2+=30;
           y1=y2;
           g.drawLine(x1,y1,x2,y2);
          // g.drawLine(20,0,20,50);

         }
        // activa = 0;

      }//del paint
   }
    public void actionPerformed(ActionEvent e)
      {
          if(e.getSource()== drawing)
        {   System.out.println("entro");
           if(activa==0){
            activa = 1;

            repaint();}

        }
        if(e.getSource()==erase){
            activa = 0;
            x1=0;
            y1=0;
            x2=0;
            y2=0;
            repaint();
        }
      }
    public void windowClosing(WindowEvent e)
     {

        System.exit(0);

     }
     public void windowOpened(WindowEvent e){}

     public void windowClosed(WindowEvent e){}

     public void windowActivated(WindowEvent e){}

     public void windowDeactivated(WindowEvent e){}

     public void windowIconified(WindowEvent e){}

     public void windowDeiconified(WindowEvent e){}
}

A:
I think it is not normal for the program to auto paint when i minimized it and then maximized it.

It is very normal for this to happen. The paint method can be called at any time, whenever the system needs to redraw a portion of your window (see Painting in AWT for specific details). When you minimize the window, whatever you drew into it before is not saved anywhere, so when you maximize the window, all of the contents need to be drawn again, so paint will be called automatically.
For this reason, you should not perform any updates to your data in paint. You should do these in a separate method, store the results in your variables and only use these existing results to draw the content.
Since the following parts do not change:
image = ImageIO.read(new File("image name and path"));
x1+=20;
x2+=20;
y2+=50;
x2+=30;

move them into a separate method, say updatePoints. Then in your actionPerformed method, first call updatePoints() and then repaint().

A: You could add a window listener to your jframe that calls the panels paint method when a resize/maximize/whatever event is triggered.

A: Basically, just to add to what casablanca said, what is happening is that since your x1, x2, y1, y2 variables are static, they are getting updated every time you perform a paint, and then staying at that value until the next repaint, at which time they are updated again, etc...
My recommendation would actually be to separate your data from your display code.  So, instead of having x1, x2, y1, and y2 declared as static global variables, have them part of the inner class (what you call ContentComponent, and have a starting x1, x2, y1, y2 values as your global variables, like this:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

class JFramePaint1 extends JFrame implements ActionListener /*implements ActionListener*/{

  public static int activa = 0;
  public static JButton drawing = new JButton("drawing");
  public static JButton erase = new JButton("erase");
  public static final int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;

  public JFramePaint1() {
    //row column
    JPanel container = new JPanel(); //new JPanel(new GridLayout(2,1));
    JPanel header = new JPanel();
    //  header.setLayout(new GridLayout(50, 2));
    // header.setLayout(new FlowLayout());
    header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS));
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS)); //lo quite ahorita
    // container.setLayout(new FlowLayout());

    ContentComponent c = new ContentComponent();

    drawing.addActionListener(this);
    erase.addActionListener(this);

    //header.setSize(30,30);

    //drawing.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    container.add(Box.createRigidArea(new Dimension(100, 0)));

    header.add(drawing); //lo quite ahorita
    header.add(erase);
    container.add(header);
    //container.add(Box.createRigidArea(new Dimension(5,0)));
    //header.add(drawing);

    // container.add(header);
    container.add(c); //lo quite ahorita

    add(container);

    //  add(c);
    //add(c);
  }

  public static void main(String[] a) {

    JFramePaint1 VentanaDiverti = new JFramePaint1();
    VentanaDiverti.setSize(800, 700);
    VentanaDiverti.setLocation(200, 0);
    VentanaDiverti.setTitle("Diverti");
    VentanaDiverti.setResizable(false);
    VentanaDiverti.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    VentanaDiverti.setVisible(true);

    /* JFrame f = new JFrame();
    // JFramePaint1 f = new JFramePaint1();
       f.setTitle("Drawing Graphics in Frames");
        f.setSize(800, 650);
        f.setLocation(200,50);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        f.setContentPane( new ContentComponent());
        f.getContentPane().add(b);

        //f.addWindowListener(this);
        //b.addActionListener(this);

        f.setVisible(true);*/

  }
  static class ContentComponent extends JPanel {

    static int x1, x2, y1, y2;

    public void paint(Graphics g) {
      x1 = sx1;
      x2 = sx2;
      y1 = sy1;
      y2 = sy2;

//      BufferedImage image;
      /*reset the variables, this makes the repaint look the same! it's as comments so that you can see what happens
      x1=0;
         y1=0;
         x2=0;
         y2=0;
      */
//      try {
//        image = ImageIO.read(new File("image name and path"));
//      } catch(IOException ex) {
//        // handle exception...
//      }

      g.setColor(Color.RED);
      // void    fillRect(int x, int y, int width, int height)
      // Fills the specified rectangle.
      g.fillRect(0, 0, 800, 600);
      if(activa == 1) {

        g.setColor(Color.BLACK);
        // g.drawRect(40, 40, 150, 80);
        int x = 40;
        int y = 40;
        for(int i = 0; i < 4; i++) {

          //g.drawRect(x+10, y+10, 150, 80);
          x = x + 10;
          y = y + 10;
        }
        //drawLine(int x1, int y1, int x2, int y2)
        //Draws a line, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
        x1 += 20;
        x2 += 20;
        y2 += 50;
        g.drawLine(x1, y1, x2, y2);
        x2 += 30;
        y1 = y2;
        g.drawLine(x1, y1, x2, y2);
        // g.drawLine(20,0,20,50);

      }
      // activa = 0;

    }//del paint
  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource() == drawing) {
      System.out.println("entro");
      if(activa == 0) {
        activa = 1;

        repaint();
      }

    }
    if(e.getSource() == erase) {
      activa = 0;
      repaint();
    }
  }

  public void windowClosing(WindowEvent e) {

    System.exit(0);

  }

  public void windowOpened(WindowEvent e) {}

  public void windowClosed(WindowEvent e) {}

  public void windowActivated(WindowEvent e) {}

  public void windowDeactivated(WindowEvent e) {}

  public void windowIconified(WindowEvent e) {}

  public void windowDeiconified(WindowEvent e) {}
}


text:
Q: "IllegalFormatConversionException: d != java.lang.String" when padding number with 0s? I had a perfectly working code yesterday, in the exact form of:
int lastRecord = 1;
String key = String.format("%08d", Integer.toString(lastRecord));

Which would pad it nicely to 00000001.
Now I kicked it up a notch with twoKeyChar getting a string from a table and lastRecord getting an int from a table.
As you can see the concept is essentially the same - I convert an int to a string and try to pad it with 0s; however, this time I get the following error:
java.util.IllegalFormatConversionException: d != java.lang.String

The code is below:
String newPK = null;
String twoCharKey = getTwoCharKey(tablename);
if (twoCharKey != null) {
     int lastRecord = getLastRecord(tablename);
     lastRecord++;
     //The println below outputs the correct values: "RU" and 11.
     System.out.println("twocharkey:"+twoCharKey+"record:"+lastRecord+"<");
     //Now just to make it RU00000011
     newPK = String.format("%08d", Integer.toString(lastRecord));
     newPK = twoCharKey.concat(newPK);
}

I feel like I must have typed something wrong, because there is no reason for it to break since the last time when it worked. Any help/hint is appreciated! Thank You!

A: You don't need the Integer.toString():
 newPK = String.format("%08d", lastRecord);

String.format() will do the conversion and the padding.

A: Very late to the party.
If you still are facing an issue to the String.format(); code even after implementing accepted answer.
This did not work for me:
String.format("%08d", stringvariable);

Because of two reasons:

*

*It will not work as d will expect for decimal point not string.

*Use %8d instead of %08d as formatter did not work for me if I used this %08d
If you are using String based Variable with String data. Use this.
String.format("%8s", stringvariable);

A: I our case with this problem it was do to java/kotlin conversion issue handling vargs because we had wrapped resources in a Kotlin file, where the missing trick was the flattern * operator
class LocalizedResources @Inject constructor(
    @ApplicationContext context: Context
) {
    private val resources = LokaliseResources(context)

    fun getString(@StringRes resId: Int): String {
        return resources.getString(resId)
    }

    fun getString(@StringRes resId: Int, vararg formatArgs: Any?): String {
        return resources.getString(resId, *formatArgs)
    }
}

A: It worked for me, It should be integer here 12 should be integer.
String.format("%04d", Integer.parseInt("12"));

output - 0012

A: In Android you should replace %1$s ... %d ... %.2f with %1$s ... %2$d ... %3$.2f.
This way you will avoid java.util.IllegalFormatConversionException: d != java.lang.String and f != java.lang.String exceptions.


text:
Q: how to initialize H2 database in spring boot Reading spring boot 5 in action, chapter 3 -> working with H2 database, the structure of the project:
.
├── HELP.md
├── mvnw
├── mvnw.cmd
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── example
│   │   │           └── tacocloud
│   │   │               ├── controllers
│   │   │               │   ├── DesignTacoController.java
│   │   │               │   └── OrderController.java
│   │   │               ├── models
│   │   │               │   ├── Ingredient.java
│   │   │               │   ├── Order.java
│   │   │               │   └── Taco.java
│   │   │               ├── repositories
│   │   │               │   ├── interfaces
│   │   │               │   │   └── IngredientRepository.java
│   │   │               │   └── JdbcIngredientRepository.java
│   │   │               ├── TacoCloudApplication.java
│   │   │               └── WebConfig.java
│   │   └── resources
│   │       ├── application.properties
│   │       ├── data.sql
│   │       ├── schema.sql
│   │       ├── static
│   │       │   ├── images
│   │       │   │   └── TacoCloud.png
│   │       │   └── style.css
│   │       └── templates
│   │           ├── design.html
│   │           ├── home.html
│   │           └── orderForm.html
│   └── test
│       └── java
│           └── com
│               └── example
│                   └── tacocloud
│                       └── TacoCloudApplicationTests.java
└── taco-cloud.iml

When I start the project with maven plugin mvn spring-boot:run:
2021-07-31 12:41:30.065  INFO 4910 --- [           main] c.e.tacocloud.TacoCloudApplication       : Starting TacoCloudApplication using Java 11.0.11 on Shepherd with PID 4910 (/home/shepherd/Desktop/spring/taco-cloud/target/classes started by shepherd in /home/shepherd/Desktop/spring/taco-cloud)
2021-07-31 12:41:30.067  INFO 4910 --- [           main] c.e.tacocloud.TacoCloudApplication       : No active profile set, falling back to default profiles: default
2021-07-31 12:41:31.195  INFO 4910 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-07-31 12:41:31.205  INFO 4910 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-31 12:41:31.206  INFO 4910 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.50]
2021-07-31 12:41:31.281  INFO 4910 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-31 12:41:31.281  INFO 4910 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1163 ms
2021-07-31 12:41:31.371  INFO 4910 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-31 12:41:31.474  INFO 4910 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-07-31 12:41:31.999  INFO 4910 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-31 12:41:32.013  INFO 4910 --- [           main] c.e.tacocloud.TacoCloudApplication       : Started TacoCloudApplication in 2.413 seconds (JVM running for 2.812)

I can see there is no sql execution and thus the initial tables from main/resources/schema.sql and main/resources/data.sql are not created. (even though the sql files are located in right directory according to docs).
So when I try to GET this page from /design (main/java/com/example/tacocloud/controllers/DesignController.java):
@GetMapping
    public String showDesignForm(Model model){
        List<Ingredient> ingredients = new ArrayList<>();
        ingredientRepo.findAll().forEach(ingredients::add);

        Type[] types = Ingredient.Type.values();
        for(Type type: types){
            model.addAttribute(type.toString().toLowerCase(),
                    filterByType(ingredients, type));
        }

        return "design";
    }

which calls the repostiory function findAll()(main/java/com/example/tacocloud/repositories/JdbcIngredientRepository.java):
 @Override
    public Iterable<Ingredient> findAll() {
        return jdbc.query("SELECT id, name, type FROM Ingredient",
                this::mapRowToIngredient);
    }

I got thymeleaf error as it is unable to render the template, as the data needed are not available because the schema.sql with the table is not executed. How to enable the spring to execute the schema.sql in order to have those data available?
PS: the schema.sql:
create table if not exists Ingredient (
    id varchar(4) not null,
    name varchar(25) not null,
    type varchar(10) not null
);

create table if not exists Taco (
    id identity,
    name varchar(50) not null,
    createdAt timestamp not null
);

create table if not exists Taco_Ingredients(
    taco bigint not null,
    ingredient varchar(4) not null
);

alter table Taco_Ingredients
    add foreign key (taco) references Taco(id);
alter table Taco_Ingredients
    add foreign key (ingredient) references Ingredient(id);

create table if not exists Taco_Order (
    id identity,
    deliveryName varchar(50) not null,
    deliveryStreet varchar(50) not null,
    deliveryCity varchar(50) not null,
    deliveryState varchar(2) not null,
    deliveryZip varchar(10) not null,
    ccNumber varchar(16) not null,
    ccExpiration varchar(5) not null,
    ccCVV varchar(3) not null,
    placedAt timestamp not null
);

create table if not exists Taco_Order_Tacos(
    tacoOrder bigint not null,
    taco bigint not null
);

alter table Taco_Order_Tacos
    add foreign key (tacoOrder) references Taco_Order(id);
alter table Taco_Order_Tacos
    add foreign key (taco) references Taco(id);

application.properties:
spring.thymeleaf.cache=false
spring.sql.init.mode=always`

PSS:
git repo:
https://github.com/tacocloud/taco-cloud

A: In Spring Boot 2.5, the initialization of data.sql and squema.sql is different when using Hibernate. Here is the upgrading guide: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#upgrading-from-spring-boot-24.
The TLDR is that data.sql now runs before Hibernate is initialized. If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true in your properties file. Be aware that this is not a good practice.

A: You need the following property also
spring.jpa.hibernate.ddl-auto=none
You must carefully read the documentation and you will understand.

Spring Boot chooses a default value for you based on whether it > thinks your database is embedded (default create-drop) or not  (default none)

This means that for the embedded h2 database the default property that is applied is spring.jpa.hibernate.ddl-auto=create-drop
So even if you provide your scripts they are overriden by hibernate create-drop schema initialization. That is why you need to manualy set spring.jpa.hibernate.ddl-auto=none

A: As it found out, the problem was neither database nor any properties set. The problem was actually in the view. The project is using thymeleaf templating and it is using special attribute of form tag -> th:object. I have not specified which object should accept data submitted from this form and thus the template engine dump exception. The reason I though the exception was caused by H2 is I haven't seen any log statements of execution of initial schema (schema.sql) and its subsequent population (data.sql). So the real reason was in the view template.

A: I assume that you are using the latest Spring Boot version.
You have to set the following in your application.properties to activate this feature:
spring.sql.init.mode=always


text:
Q: Converting multiple rows into one row with multiple columns dynamically, pivot does not seem to work I'm seeing a lot of posts about this but I can't seem to find the right answer.
Here's the data:

The first 2 rows are part of one set. I want to convert the first two rows into 1 row and have the last column ("Info"), be turned into 2 columns (because there's 2 rows) and because they are different.
Same with the IDs: 14, 24, etc.
This is what I tried:
 SELECT
  BankId,
  BankDate,
  TypeCode,
  Amount,
  FundsType,
  BankRef,
  CustRef,
  Text,
  ptable.Comment1,
  ptable.Comment2,
  ptable.Comment3,
  ptable.Comment4,
  ptable.Comment5,
  ptable.Comment6,
  ptable.Comment7,
  ptable.Comment8,
  ptable.Comment9,
  ptable.Comment10,
  ptable.Comment11,
  ptable.Comment12,
  ptable.Comment13,
  ptable.Comment14,
  ptable.Comment15
FROM (
  SELECT BankId, BankDate, TypeCode, Amount, FundsType, BankRef, CustRef, Text, Info, [16TId], [88TId]
  FROM #test --ORDER BY [16TId], [88TId]
) AS SourceTable
PIVOT (
  MIN([88TId])
  FOR [Info] IN ([Comment1], [Comment2], [Comment3], [Comment4], [Comment5], [Comment6], [Comment7], [Comment8], [Comment9], [Comment10], [Comment11],
                 [Comment12], [Comment13], [Comment14], [Comment15]
  )
) AS ptable;

And this is what the data looks like:

The data from the "INFO" column does not populate into the "Comment1, Comment2, etc" columns.
I tried to do an PIVOT but it does not work. Can anyone give me a hand?

A: You want to show the Info than you should be using MAX(Info). The cn is to generate a sequential number for each of the comment / Info
Change to
FROM
(
     SELECT BankId, BankDate, TypeCode, Amount, FundsType, BankRef, CustRef, Text,
            Info, [16TId],
            cn = ROW_NUMBER() OVER (PARTITION BY BankId, [16TId]
                                        ORDER BY [88TId])
     FROM   #test --ORDER BY [16TId], [88TId]
) AS SourceTable
PIVOT
(
    MAX (Info)
    FOR [cn] IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
                 [11], [12], [13], [14], [15])
) AS ptable;


text:
Q: Why is my function inside componentDidMount not being fired? In the following snippet, why is this.setInterval not being fired when the component mounts?
class MyComponent extends React.Component {

  constructor(props) {
    super(props);
    this.setInterval = this.setInterval.bind(this);
  }

  setInterval = () => {
    console.log('Set Interval');
    setTimeout(function () {
        console.log('Test');
    }, 2000);
  }

  componentDidMount() {
    this.timer = this.setInterval;
  }
}

A: You should call the function all the while passing the reference.
  componentDidMount() {
    this.timer = this.setInterval;
  }

should be
  componentDidMount() {
    this.timer = this.setInterval();
  }

A:  setInterval = () => {
    console.log('Set Interval');
    setTimeout(function () {
        console.log('Test');
    }, 2000);
  }

  componentDidMount() {
    this.timer = this.setInterval();
  }

You need to invoke setInterval() like so. In componentDidMount it gets executed only once during the initial load of the component.


text:
Q: Redis Perl Library: how to use sorted sets? I have a data structure in redis that uses sorted sets for a "top items" system that I plan to use on my webpage. I am basically using the redis-cli commands like ZRANGE to get my top items out of redis.
Now I want to access this data programmatically in Perl. I have seen the Redis.pm library, but I could not find any signs of these Z* methods there.
Can I use the Redis.pm library to work with sorted sets in redis or do I have to use another library?

A: Yes, you can use the Z* commands with Redis.pm
Actually, all the Redis commands are mapped in the Perl API, even if some of them are not documented. This is done through the AUTOLOAD feature of Perl.
The definition of the parameters of the commands follows the Redis documentation, except if the Redis.pm documentation states otherwise.
See this example in the non-regression testing scripts:
https://github.com/melo/perl-redis/blob/master/t/01-basic.t#L195


text:
Q: How many fields is normal to have in one table? Ok, I am creating a game, I have one table where I save a lot of information about a member, so I have many field in it. How many fields is normal to have in one table? Does it matter? Maybe I should split that info into two-three-four tables? What do you think?

A: Normalize the Database
If you feel you have too many columns, you probably have repeating groups, which suggests you should normalize the database. See an example here: Description of the database normalization basics
Hard MySQL Limits
MySQL 5.5 Column Count Limit

Every table has a maximum row size of 65,535 bytes.
There is a hard limit of 4096 columns
  per table

A: Splitting of data into tables should generally not be dictated by the number of columns, but by the nature of the data. The process of splitting a large table into smaller ones is called normalization.
The only other reason I can think of to split a table is, if you may need data in clusters, i.e. you often need columns A-D together or columns E-L, but never all columns or columns D-F, then you can split the table into two tables, one containing columns A-D and the primary key, the other one containing columns E-L and the primary key.

A: Speaking about limits, MySQL says it's 4096 (source).
Yet I haven't seen so big tables yet, even those huge data mining tables don't come close.
You shouldn't be concerned about it as long as your database is normalized. As soon as you can spot same data being stored twice (for example, player table might have player_type column storing some fixed values), it's worth moving such data to separate table, instead od duplicating information in other tables and hence reducing columns count (but that's only "side effect" of normalization, not something that drives it).

A: I've never personally encountered one with more than 500 columns in it, but short of the maximum sizes there's no reason to have any fewer than the design demands. Beware of doing SELECT * FROM it though.

A: "information about a member" - umm always difficult, but I always separate identifiable information into another table and use a salt key to link the 2 together.  That way it is not as easy to "hijack" usernames and passwords etc.  And you can always use the SALT as a session variable rather than username/password/userId or whatever.
Typically I only store a ID, salt and joining date in 1 table. As I said, the rest I try to "hide" so that they cannot be "linked/hijacked".
Hope helps


text:
Q: How to create Azure VM without NSG? I want to create a VM without nsg. In the New-AzVm cmdlet, I specify $null in the PublicIP parameter - and it works (i.e. it does not create a Public IP). But this does not work with nsg. Here is my code:
$Date = Get-Date -Format "MMddyymm"
$user = "Sitecore"
$password = ConvertTo-SecureString "Qwerty123456" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password
$RGroup = 'test'
$Location = "Westus3"
$VMName = "vmtest$date"
$image = "vmtest-image-20220805165444"
$vnet = "vnet1"
$NSG = "nsg$date"
$SizeVM = "Standard_b4ms"
$NIC = "$VMName$date"
$Subnet = "default"
$tags = @{'xxx' = 'yyy'}

New-AzVM -ResourceGroupName $RGroup `
    -Name $VMName `
    -Image $image `
    -Location $Location `
    -VirtualNetworkName $vnet `
    -SubnetName $Subnet `
    -SecurityGroupName $null `
    -PublicIpAddressName $null `
    -Credential $credential `
    -Size $SizeVM

A: First of all, you should know, that it is highly not recommended using no NSG. But if you need to do so, the only way to do it with Azure Powershell is (like @SaiSakethDuduru already said) with -nsg "". So need to use the stop-parsing affects variables.
For additional information on parsing take a look in here:
MS DOC about Parsing

A: When we use new-azvm cmdlet, it doesn't work. Instead, create a VM without NSG. Only the Azure CLI can do this:
az vm create --nsg '""'


text:
Q: How to access NSWindow from @main App using only SwiftUI? At this answer the solution work for Scene plus swiftUI.
However using @main like:
@main
struct MyApp: App {
    @StateObject private var model = MyModel()

    var body: some Scene {
        WindowGroup {
            Router {
                AppContent()
            }.environmentObject(self.model)
        }
    }
}

I also tried to get the main window by using
var window: NSWindow? {
        let window = NSApplication.shared.mainWindow
        return window
    }

Nevertheless, the mainWindow always return nil
Update:
I need the NSWindow due to the need of conforming with ASWebAuthenticationPresentationContextProviding which obligates to return a NSWindow. Basically, I'm trying to do something like:
LoginView(store: AuthStore(window: window))

Where AuthStore uses the AuthenticationServices to perform an authentication.

A:
Basically, I'm trying to do something like:
LoginView(store: AuthStore(window: window))

Here is a demo of possible approach (with some replicated entities)

class AuthStore {
    var window: NSWindow

    init(window: NSWindow) {
        self.window = window
    }
}

struct DemoWindowAccessor: View {
    @State private var window: NSWindow?   // << detected in run-time so optional
    var body: some View {
        VStack {
            if nil != window {
                LoginView(store: AuthStore(window: window!))    // << usage
            }
        }.background(WindowAccessor(window: $window))
    }
}

struct WindowAccessor: NSViewRepresentable {
    @Binding var window: NSWindow?

    func makeNSView(context: Context) -> NSView {
        let view = NSView()
        DispatchQueue.main.async {
            self.window = view.window   // << right after inserted in window
        }
        return view
    }

    func updateNSView(_ nsView: NSView, context: Context) {}
}

struct LoginView: View {
    let store: AuthStore

    var body: some View {
        Text("LoginView with Window: \(store.window)")
    }
}

A: Many ways but there is a gotcha:
NSApplication.shared.keyWindow, NSApp.keyWindow,
NSApp.mainWindow,

Sometimes, these can return nil especially during launch or if the app is inactive.
I think it is because setting these properties may not be instantaneous from the Appkit side of things
The best way is to access all windows:
NSApp.windows.first

This will return all windows but in an unpredictable order.
If you have multiple windows you can do further filtering to find the required window but this method avoids that crazy behaviour where the other methods return nil.


text:
Q: How to correctly use WixAppFolder for install without UAC? I have created a minimal installer with "WixAppFolder" set to "WixPerUserFolder". Application installs in
HOME\AppData\Local\Apps\APPNAME as expected, but installer shows same UAC prompt for both per-user and per-machine install (under normal user this prompt has 'enter administrator password'). I'm using Windows 7 Ultimate 64-bit. The installer GUI for "Install just for you" says thet "you do not need local administrator privileges'. But it is not true - local administrator priviliges are required. What i'm doing wrong? Installer source code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="Test" Language="1033" Version="1.0.0"
           Manufacturer="Me"
           UpgradeCode="bb39686c-d77a-4bc4-bbd8-f13b1e0ec26c">
  <Package InstallerVersion="200" Compressed="yes" />
  <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
    <UIRef Id="WixUI_Advanced" />
    <Property Id="ApplicationFolderName" Value="test_app" />
    <Property Id="WixAppFolder" Value="WixPerUserFolder" />
  <Directory Id="TARGETDIR" Name="SourceDir">
   <Directory Id="ProgramFilesFolder">
        <Directory Id="APPLICATIONFOLDER" Name="test_app">
          <Component Id="c_test" Guid='*'>
            <File Id='test_txt' Name="test.txt" />
          </Component>
        </Directory>
   </Directory>
  </Directory>
    <Feature Id='f_test' Title="Test" Level='1' >
      <ComponentRef Id='c_test' />
    </Feature>
  </Product>
</Wix>

A: First, set your Package/@InstallScope="perUser". Then you'll not want to default your application folder to ProgramFilesFolder because that is a per-machine location (pick a per-user location like LocalAppDataFolder). After that, it seems like things should work.

A: After long conversations with Wix team i found following:

*

*Until windows 7 it is not possible for windows installer to have a single installation that can install both per user or per machine.

*The UI text is a bug.


text:
Q: Getting thumbnail from YouTube JSON Data Objective C I would like to display the thumbnail of a youtube video in my custom cell. I have the JSON link but I am not sure how I go about getting the actual image? My code is below!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

*)indexPath
{
    static NSString *CellIdentifier = @"RemedyYouTubeTableViewCell";
    RemedyYouTubeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RemedyYouTubeTableViewCell" owner:nil options:nil];
        for(id obj in topLevelObjects) {
            if([obj isKindOfClass:[UITableViewCell class]]) {
                cell = obj;
                break;
            }
        }

    }

    // Configure the cell...

   // cell.videoThumbnail.image = [UIImage imageNamed:[thumbNailArray objectAtIndex:indexPath.row]];

    NSArray *subArray = [subDict objectForKey:@"items"];
    if ([subArray count]) {
        for (NSDictionary *dictItem in subArray) {
            cell.titleLabel.text = [dictItem objectForKey:@"title"];

            NSNumber *totalSeconds = [dictItem objectForKey:@"duration"];
            int *minutes = totalSeconds.intValue/60;
            int *seconds = totalSeconds.intValue%60;
            NSString *finalDuration =[NSString stringWithFormat:@"%im %is", minutes,seconds];
            cell.durationLabel.text = finalDuration;

            NSString *separatorString = @"T";
            NSString *firstUploadString = [dictItem objectForKey:@"uploaded"];
            NSString *uploadString = [firstUploadString componentsSeparatedByString:separatorString].firstObject;
            cell.dateUploadLabel.text = uploadString;

            NSString *viewCount = [NSString stringWithFormat:@"%@",[dictItem objectForKey:@"viewCount"]];
            cell.viewsLabel.text = viewCount;

            NSString *thumbnailURL = [dictItem objectForKey:@"thumbnail"];

        }
    }

    return cell;
}

Everything else is working great but what do I do with the thumbnail URL? Thanks!
My code now looks like this...
NSString *viewCount = [NSString stringWithFormat:@"%@",[dictItem objectForKey:@"viewCount"]];
            cell.viewsLabel.text = viewCount;

            NSDictionary *thumbnailDict = [dictItem objectForKey:@"thumbnail"];
            //NSString *thumbnailURl = [thumbnailDict objectForKey:@"sqDefault"];
            //UIImage *thumbNailImage = nil;

            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                NSString *thumbnailURL = [thumbnailDict objectForKey:@"sqDefault"];
                NSLog(thumbnailURL);
                NSURL *url = [NSURL URLWithString:thumbnailURL];
                NSData *imageData = [NSData dataWithContentsOfURL:url];
                UIImage *thumbNailImage = [UIImage imageWithData:imageData];

                dispatch_async(dispatch_get_main_queue(), ^{
                    // Here in main thread set image to your cell imageView.
                    // e.g.
                    [cell.videoThumbnail setImage:thumbNailImage];
                });
            });

        };
    }

    return cell;
}

A: You just need to get NSData from that url. Make sure url is valid and available.
@try {

    UIImage *thumbNailImage = nil;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSString *thumbnailURL = [dictItem objectForKey:@"thumbnail"];
        NSURL *url = [NSURL URLWithString:thumbnailURL];
        NSData *imageData = [NSData dataWithContentsOfURL:url];
        UIImage *thumbNailImage = [UIImage imageWithData:imageData];

        dispatch_async(dispatch_get_main_queue(), ^{
            // Here in main thread set image to your cell imageView.
            // e.g.
            [cell.imageView setImage:thumbNailImage];
        });
    });

}
@catch (NSException *exception) {
    NSLog(@"Exception :%@",exception.debugDescription);
}


text:
Q: Regexp Matching Hex Color Syntax (and Shorten form) Well, I'm pretty new on regex and in particular on JavaScript regexp.
I'm looking for making a regexp that match the hex color syntax (like #34ffa6)
Then I looked at the w3school page: Javascript RegExp Object
Then that's my regexp:
/^#[0-9a-f]{6}/i

It seems to work but, if I want it to match also the "short hex color syntax" form? (like #3fa), it's possible? I've tried using the character | but maybe I'm wrong with the syntax.

A: /^#[0-9a-f]{3,6}$/i

would match #abc, #abcd, #abcde, #abcdef
/^#([0-9a-f]{3}|[0-9a-f]{6})$/i

would match #abc and #abcdef but not #abcd
/^#([0-9a-f]{3}){1,2}$/i

would match #abc and #abcdef but not #abcd
/^#(?:[0-9a-f]{3}){1,2}$/i

would match #abc and #abcdef but not #abcd
Have a look at RegExp - MDN to learn more about regular expressions in javascript.

A: Try this :
/^#([0-9a-f]{6}|[0-9a-f]{3})$/i

[0-9a-f]{6} = 6 characters
[0-9a-f]{3} = 3 characters
$ = end

A: this should work
/#[0-9a-f]{6}|#[0-9a-f]{3}/gi
and for trying out regular expressions on the fly and learning it you can use this site
http://gskinner.com/RegExr/

A: You might want to incorporate 4 and 8 digit hex for #RGBA and #RRGGBBAA. I am doing this in a different setting where I'm using match() and split() to generate arrays.  I could not get all the variations posted by @rodneyrehm to work with the g flag and match, but the first (and most verbose) solution works if I list the character count in high to low order: 8, 6, 4, 3.
let rx  = /(?:#)[0-9a-f]{8}|(?:#)[0-9a-f]{6}|(?:#)[0-9a-f]{4}|(?:#)[0-9a-f]{3}/ig
let s   = "123 #AA22CC 100% #12F abc #A2Cd #aa11cc44 test 236px";
let arr = s.match(rx); // arr == ["#AA22CC", "#12F", "#A2Cd", "#aa11cc44"]

The MDN docs say that (?:#) should forget "#", but it does not, and (?=#) simply fails.  What am I misunderstanding?
My final goal is to include the other numeric values in the array returned from match().  I'm almost there...

A: The possible Hex Colors are -

Format
Example

#RGB
#F00

#RGBA
#F005

#RRGGBB
#FF7C00

#RRGGBBAA
#FF7C0016

Regexp to match color without alpha
let regex = /^#([A-F0-9]{3}|[A-F0-9]{6})$/i

Regexp to match color with alpha
let regex = /^#([A-F0-9]{3,4}|[A-F0-9]{6}|[A-F0-9]{8})$/i


text:
Q: Remove matching words from the string using Perl I want to remove the words Z or ZN and LVT from the strings present in my file but I couldn't get it. Can someone check my code.
Input
abchsfk/jshflka/ZN                       (cellLVT)
asjkfsa/sfklfkshfsf/Z                    (mobLVT)
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z        (celLVT)
asjhdjs/jhskjds/ZN                       (abcLVT)
shdsjk/jhskd/ZN                          (xyzLVT)

Output
abchsfk/jshflka                     cell
asjkfsa/sfklfkshfsf                 mob
asjhfdjkfd/sjfdskjfhdk/hsakfshf     cel
asjhdjs/jhskjds                     abc
shdsjk/jhskd                        xyz

CODE:
     if ($line =~ /LVT/ && ($line =~ /ZN/ || $line =~ /Z/) )

        ####  matches the words LVT and ( Z or ZN)

        {
             my @names = split / /, $line;      ##### splits the line

                $names[2] =~ s/\/Z|/ZN//g;      #### remove Z or ZN
                $names[3] =~ s/\(|LVT\)//g ;  #### remove LVT & braces

                print OUT " $names[2] $names[3] \n";    #### print

         }

A: The problem is the order of matching: s/\/Z|\/ZN//g (the second backslash is missing in your code!). You should match the longer string first, otherwise Z will match and N won't be deleted.
There's even easier way, though: Just use \/ZN?:
#!/usr/bin/perl
use warnings;
use strict;

while (my $line = <DATA>) {
    if ($line =~ /LVT/ && $line =~ /ZN?/) {

        my @names = split ' ', $line;
        $names[0] =~ s/\/ZN?//g;
        $names[1] =~ s/\(|LVT\)//g;
        print "$names[0] $names[1]\n";
    }
}
__DATA__
abchsfk/jshflka/ZN                       (cellLVT)
asjkfsa/sfklfkshfsf/Z                    (mobLVT)
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z        (celLVT)
asjhdjs/jhskjds/ZN                       (abcLVT)
shdsjk/jhskd/ZN                          (xyzLVT)


text:
Q: Birt Report Indian Rupee formatting I want to format numbers based on Indian Rupee/Number format (basically commas) in Birt through scripting (for some conditional reasons).
if I use:
this.getStyle().numberFormat="#,##,##,##0.000";

It still adds commas after every 3 characters .. as in 12,345,678.000 but I want the number to be 1,23,45,678.000 in this format
Can you please advise
EDIT: Bug with BIRT raised as : https://bugs.eclipse.org/bugs/show_bug.cgi?id=432211

A: EDIT: set a custom format number
Here is a possible workaround, forcing BIRT to make use of com.ibm.icu.text.DecimalFormat class. I don't know why indian format is not natively supported, you could report this in bugzilla of eclipse.org site.

*

*Edit your dataset

*Create a new computed column, select "String" datatype

*Enter as expression: (in the first line, replace "value" with the actual name of the numeric column containing values)
var columnvalue=row["value"], customformat="#,##,##,##0.000"; //we can add here a test for conditional formatting
if (columnvalue!=null){
  var symbols=Packages.com.ibm.icu.text.DecimalFormatSymbols(new Packages.java.util.Locale("en","IN"));
  var formatter=Packages.com.ibm.icu.text.DecimalFormat(customformat,symbols);
  var value=new Packages.java.math.BigDecimal(columnvalue.toString());
formatter.format(value);
}else{
  "-"
}

*Click "Preview results" in the dataset editor, a new column should be added at the end with the expected format.

A: You can use NumberFormat by setting the locale to Indian setting.
Locale locale = new Locale("en","IN");
String str = NumberFormat.getNumberInstance(locale).format(<your number>);

That's if you are looking for JAVA code to resolve your problem.

A: **you can use following javascript currency format and call it from BIRT.

function getSouthAsianCurrencyFormat(amount)
{
var l,ftemp,temp,camount,k,adecimal;
var decimals=2;
var ptrn="##,##,###,##,##,###.##";
var ptrnLength=0;
var adecimal=0;
var counts = {};
var ch, index, len, count;
amount= Number(Math.round(amount+'e'+decimals)+'e-'+decimals);
amount=amount.toFixed( decimals );
for (index = 0, len = ptrn.length; index < len; ++index) {
ch = ptrn.charAt(index);
count = counts[ch];
counts[ch] = count ? count + 1 : 1;
}
for (ch in counts) {
if(ch=="#"){
ptrnLength=counts[ch];
console.log(ch + " count: " + ptrnLength+"("+ptrn.length+")");
console.log( "amount length: " + amount.toString().length);
//console.log("decimalLength: "+decimalLength.toString().length);
}
}
if(counts['.']=0){
amount=amount+".00";
}

k=ptrn.toString().length;
l=amount.toString().length;
 ftemp=amount.toString();
 temp="";
 camount="";
 if(ptrnLength<(amount.toString().length-1)) return 0;
 else {
        k=k-1;
        l=l-1;
        for(i=l;i>-1;i--){
        if(ptrn.charAt(k)=="#" || ptrn.charAt(k)=="." ){
        camount=ftemp.charAt(i)+camount;
        }
        else{
        camount=ptrn.charAt(k)+camount;
        k=k-1;
        if(ptrn.charAt(k)=="#"){
        camount=ftemp.charAt(i)+camount;
        }
        }
        k=k-1;
     }
     return (camount);
 }
 }


text:
Q: Could gzip compression cause data corruption? I'm trying to come up with a solution to compress few petabytes of data I have which will be stored in AWS S3. I was thinking of using gzip compression and was wondering if compression could corrupt data. I tried searching but was not able to find any specific instances where gzip compression actually corrupted the data such that it was no longer recoverable.
I'm not sure if this is the correct forum for such question, but do I need to verify if data was correctly compressed? Also, any specific examples/data points would help.

A: I would not recommend using gzip directly on a large block of data in one shot.
Many times I have compressed entire drives using something similar to
dd if=/dev/sda conv=sync,noerror | gzip > /media/backup/sda.gz
and the data was unusable when I tried to restore it. I have reverted to not using compression

A: gzip is constantly being used all around the world and has gathered a very strong reputation for reliability.  But no software is perfect.  Nor is any hardware, nor is S3.  Whether you need to verify the data ultimately depends on your needs, but I think a hard disk failure is more likely than a gzip corruption at this point.

A: GZIP compression, like just about any other commonly-used data compression algorithm, is lossless. That means when you decompress the compressed data, you get back an exact copy of the original (and not something kinda sorta maybe like it, like JPEG does for images or MP3 for audio).
As long as you use a well-known program (like, say, gzip) to do the compression, are running on reliable hardware, and don't have malware on your machine, the chances of compression introducing data corruption are basically nil.

A: If you care about this data, then I would recommend compressing it, and the comparing the decompression of that with the original before deleting the original. This checks for a bunch of possible problems, such as memory errors, mass storage errors, cpu errors, transmission errors, as well as the least likely of all of these, a gzip bug.
Something like gzip -dc < petabytes.gz | cmp - petabytes in Unix would be a way to do it without having to store the original data again.
Also if loss of some of the data would still leave much of the remaining data useful, I would break it up into pieces so that if one part is lost, the rest is recoverable. Any part of a gzip file requires all of what precedes it to be available and correct in order to decompress that part.


text:
Q: How to get a calendar-style DatePicker in Android? I want to add a calendar-style date picker in Android, where the user will be able to select a date from a display that shows a calendar for one month.
I googled many topics, but haven't found a solution, so I'm trying to create one myself. I tried getting the dates and displaying them like a calendar, but I wasn't successful.


text:
Q: Solving an equation in which the variable appears as both an exponent and a base I am currently playing around with exponential and logarithmic functions, and am now trying to solve the following: $2^x = x^2$.
My problem is that whenever I'm exponentiating or taking the logarithm of both sides, I realize that I'm going around in circles.
Is there any way on how you can isolate the $x$ for this equation, or any other equation in which the variable appears as both an exponent and a base?
Looking at the graphs, I can see that there are three intersections between the functions and the two rational solutions are $x=2$ and $x=4$ but I can't seem to be able to arrive at those answers algebraically.

A: As percusse and GEdgar point-out in there comments that the reason this seemingly simple equation is not solvable using simple algebra lies in the fact that that the LHS of $2^x = x^2$ is a transcendental function. i.e. it cannot be expressed as a polynomial. Actually the closest it can come to in a "polynomial" form is its Maclaurin series form (see below).
Using pre-calculus techniques you can show, for instance, that you can take log of both sides as in
$$2^x = x^2$$
$$\implies ln(2^x) = ln(x^2) \quad \forall x \ne 0 $$
$$\implies x ln(2) = 2 ln(x) $$
$$\implies ln(x) = {2x \over ln(2)}  \quad \textbf {(A)}$$
So the solution to our problem are all values of $x$ that are the roots of equation $\textbf{(A)}$ ... Pre-calculus you can use graphing techniques to determine the answer.
Solving transcendental functions, in general, requires a lot of different calculus techniques, that are probably beyond the scope of this answer.
Infinite Series for ${2^x}$
Using Taylor's Theorem (which is part of calculus) we can show that:
$$e^u = \sum_{n=0}^{ \infty } {u^n \over n!} = 1 + {u^1 \over 1!} + {u^2 \over 2!} + {u^3 \over 3!} + {u^4 \over 4!} + \cdots  \quad \textbf{(B)}$$
For considerable historical reasons $\textbf{(B)}$ is called Maclaurin series for $e^u$. You can find Maclaurin series for a large number of functions that have certain properties.
For purpose of this discussion, assume that (B) is provable. We can use it to express the infinite series for $2^x$ by noting that $2 \equiv e^{ln(2)}$, and that $(a^x)^y = (a)^{xy}$.
$$ [2]^x = [e^{ln(2)}]^x = [e^{ln(2) \dot x}]$$
Substituting $u$ with $2^x$ in $\textbf{(B)}$ power-series we get:
$$2^x = ln(2) \sum_{n=0}^{ \infty } {x^n \over n!} = ln(2) \left( 1 + {x^1 \over 1!} + {x^2 \over 2!} + {x^3 \over 3!} + {x^4 \over 4!} + \cdots \right)$$
As you can see solving (A) without knowing some more properties about behavior of $e^x$ becomes intractable. That is what calculus is all about ;) once you get into it, you wil see that these problems become solvable.  Although, the solutions are, by no means, trivial.

A: For your actual problem you can easily see that as well as $x=2$ and $x=4$, there is another solution in $[-1,0]$ and numerical methods will help you find it is about $x\approx -0.76666469596$.  Looking at the two curves $y=x^2$ and $y=2^x$, there are no other real solutions. That might be a good place to stop.
Alternatively, there is the Lambert W function or product logarithm with $z = W(z)\exp(W(z))$. With some manipulation, using $2^x=\exp(x\log(2))$ and $x^2=\exp(2\log(x))$ you can turn your original equation into $\left(- \frac{\log(2)}{2}x\right) \exp\left(- \frac{\log(2)}{2}x\right)   =  -
 \frac{\log(2)}{2}$ and so a solution is $- \frac{2}{\log(2)}W\left(-
 \frac{\log(2)}{2}\right)$, which Wolfram Alpha gives as 2.
But for negative real numbers $x^2=\exp(2\log(-x))$, and so with similar manipulation you should also look at solutions of the form  $- \frac{2}{\log(2)}W\left(
 \frac{\log(2)}{2}\right)$, which Wolfram Alpha gives as -0.76666...
To make life more complicated, the Lambert W function is multi-branched, so there can be more solutions, such as 4.  There are infinitely many complex solutions.


text:
Q: Thread stops executing I have a Thread that is running a shell script in an external process, and I'm using Apache's IOUtils to read in the stderr and stdout streams from this external process as follows:
Thread t = new Thread(()-> {
        ProcessBuilder pb =  new ProcessBuilder("sh");
        Process p = null;
        try {
            p = pb.start();
            OutputStream os = p.getOutputStream();
            os.write("sleep 30 ; echo test".getBytes());
            os.flush();
            os.close();
            InputStream is = p.getInputStream();
            InputStream es = p.getErrorStream();
            String stdout = IOUtils.toString(is,"UTF-8");
            String stderr = IOUtils.toString(es,"UTF-8");
            int retval = p.waitFor();
        } catch (Exception e) {
            System.out.println("Got exception: "+e.toString());
        } finally {
            System.out.println("Done now!");
        }
    });
t.start();
Thread.sleep(7000);
t.interrupt();

For some reason, when I run this test case, the exception is never thrown (the catch block never runs), and the finally block never runs. Is there some problem that I'm not catching? Should stdout and stderr be collected by a different thread?

A: If the buffer for stderr fills up your program will stop. Unless you need them to be in different Strings I would redirect one to the other.
I would use ProcessBuidler.redirectErrorStream to combine the outputs so you don't need an additional thread to read the stderr
waitFor(long, TimeUnit) has a timeout so you don't need to start a background thread.
I suggest you printout your stderr and stdout so you can see them as they might give an indication of what is wrong.

A: Looks correct, apart from the fact that the thread is killed (interrupted) before it could process any output from the shell. The issue is that the shell sleeps for 30 seconds and the thread is interrupted in 7 seconds.
The fact you don't see any message from catch or finally block could be caused by exiting the program from the main() method before the "shell" thread is actually activated.


text:
Q: flask-sqlalchemy intellisense/autocomplete I'm searching for a way to actually get intellisense for flask-sqlalchemy. All the answers I have found online seem to tell us how to suppress the errors (no Column or query instance members)(switch linters, ignore the class in pylintrc, etc...), but I find it very hard to belive that the most widely used ORM in python does not actually have linting support.
I am open to using pycharm or intellij community editions, but I'd rather stick with vs code, since I am a js developer who recently decided to learn python, and I'd like to stick with the tools I know and love. I hear that vs code has great python support, but sqlalchemy linting is a must!


text:
Q: difference between sizeof and strlen in c
Possible Duplicate:
Different answers from strlen and sizeof for Pointer & Array based init of String

Can anybody help me in understanding difference between sizeof method and strlen method in c programming?

A: strlen() is used to get the length of a string stored in an array.
sizeof() is used to get the actual size of any type of data in bytes.
Besides, sizeof() is a compile-time expression giving you the size of a type or a variable's type. It doesn't care about the value of the variable.
strlen() is a function that takes a pointer to a character, and walks the memory from this character on, looking for a null character. It counts the number of characters before it finds the null character. In other words, it gives you the length of a C-style null-terminated string.
The two are quite different. In C++, you do not need either very much, strlen() is for C-style strings, which should be replaced by C++-style std::strings, whereas the primary application for sizeof() in C is as an argument to functions like malloc(), memcpy() or memset(), all of which you shouldn't use in C++ (use new, std::copy(), and std::fill() or constructors).

A: sizeof is not a method. It is a compile-time construct that determines the amount of memory a particular type or a variable occupies. strlen, on the other hand, is a function that counts the number of consecutive non-zero char values starting at the specified location in memory (which happens to be the same as determining the length of a zero-terminated C string).


text:
Q: azure java SDK interactive login support Does Azure Java SDK support interactive login?
I mean like the Azure CLI's "azure login" command.
azure login
info:    Executing command login
info:    To sign in, use a web browser to open the page http://aka.ms/devicelogin. Enter the code XXXXXXXXX to authenticate.

I was unable to find any reference in the documentation.
Thanks!

A: No, currently there is no support afaik.

A: Yes, this is supported in the latest Azure SDK for Java. You can read more about the functionality here and download the libraries from here


text:
Q: Converting two lists to json I'm attempting to convert two lists to json.
For example :
l1 = ['a','b','a']
l2 = ['q','r','s']

should be converted to :
[{
    "name": "g",
    "children": [{
            "name": "a",
            "children": [{
                "name": "q"
            }, {
                "name": "s"
            }]
        },
        {
            "name": "b",
            "children": [{
                "name": "r"
            }]
        }
    ]
}]

Closest I have is :
l1 = ['a','b','a']
l2 = ['q','r','s']

nameDict = {}
childrenDict = {}

l1 = l1.map(x => {
  return({name: x});
});
console.log(l1);

l2 = l2.map(x => {
  return({children: x});
});
console.log(l2);

var c = l1.map(function(e, i) {
  return [e, l2[i]];
});

console.log(JSON.stringify(c))

which produces :
[[{"name":"a"},{"children":"q"}],
[{"name":"b"},{"children":"r"}],
[{"name":"a"},{"children":"s"}]]

How to combine the elements produce ? :
[{
    "name": "g",
    "children": [{
            "name": "a",
            "children": [{
                "name": "q"
            }, {
                "name": "s"
            }]
        },
        {
            "name": "b",
            "children": [{
                "name": "r"
            }]
        }
    ]
}]

A: Disclaimer: Since we don't know where the g comes from, I will only build the root children array.
Since your arrays have the same length, you can use a plain for and use with the index to play with both arrays. Just build an array and check each iteration if the "child" already exists. If not, create it.

l1 = ['a','b','a']
l2 = ['q','r','s']

let gChildren = []
for(let i = 0; i < l1.length; i++){
  let group = gChildren.find(c => c.name === l1[i])
  if(!group){
    group = { name: l1[i], children: [] }
    gChildren.push(group)
  }

  group.children.push({ name: l2[i] })
}

console.log(gChildren)

A: Here is working code that accounts for your pre-existing structure that accomplishes the result you are looking for.
let data1 = ["a","b","a"];
let data2 = ["q","r","s"];

let outputData = [{name: "g", children: []}];

for (let i=0;i < data1.length;i++) {
        let found = false;
    for (let j=0;j < outputData[0].children.length;j++) {
        if (outputData[0].children[j].name === data1[i]) {
            outputData[0].children[j].children.push({name: data2[i]});
        found = true;
        }
      }
      if (found === false) {
            outputData[0].children.push({name: data1[i], children: [{name: data2[i]}]});
        }

}

console.log(JSON.stringify(outputData));

A: This is a good use case for a Array.prototype.reduce, where you want to iterate over an array but end up with a single value.
l1.reduce((acc, val, i) => {
  const l2Val = l2[i]
  const foundObj = acc.find(o => o.name === val)
  if (foundObj) {
    foundObj.children.push({name: l2Val})
  } else {
    acc.push({
      name: val,
      children: [{name: l2Val}]
    })
  }

  return acc
}, [])

Here, on each iteration I'm just adding the child to the children array for that item, or creating the value for the item if it doesn't already exist.
I have no idea what g corresponds to so I've left it out, but you can add the array created from reduce to another object or array if you want.

A: You could transpose the array and use the information as path to the final child object
l1 = ['a', 'b', 'a']
l2 = ['q', 'r', 's']

transposes to
[
    ['a', 'q'], // a -> q
    ['b', 'r'], // b -> r
    ['a', 's']  // a -> s
]

which is now works with reduce.
The advantage is to use it with longer pathes to the final children, like
[
    ['a', 'x', 'y', 'z'],
    ...
]

which returns a nested object with the given relation to each other.

const
    transpose = array => array.reduce((r, a) => a.map((v, i) => [...(r[i] || []), v]), []);

var l1 = ['a', 'b', 'a'],
    l2 = ['q', 'r', 's'],
    result = transpose([l1, l2]).reduce((r, a) => {
        a.reduce((q, name) => {
            var temp = (q.children = q.children || []).find(o => o.name === name);
            if (!temp) q.children.push(temp = { name });
            return temp
        }, r);
        return r;
    }, { name: 'g' });

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

A: A bit shorter with filter on the distinct keys :

var l1 = ['a','b','a'], l2 = ['q','r','s']

var children = [...new Set(l1)].map(k => ({ name: k, children:
        l2.filter((v, i) => l1[i] == k).map(v => ({ name: v })) }))

console.log( [{ name: 'g', children }] )

Or more efficient with intermediate object of the groups :

var l1 = ['a','b','a'], l2 = ['q','r','s']

var children = Object.entries(
                       l1.reduce((o, k, i) => ((o[k] = o[k] || []).push(l2[i]), o), {})
                     ).map(([k, v]) => ({ name: k, children: v.map(v => ({ name: v})) }))

console.log( [{ name: 'g', children }] )


text:
Q: "-" is getting replaced by characters %2D1? i entered below url in IE
https://localhost/myApp/4117-1Space/WebHome
when i do context.getURL().toString() in  my java class, i get string url as
https://localhost/myApp/4117%2D1Space/WebHome .
So here instead of character "-" i get %2D1. Is there a way i get the exact word i.e 4117-1Space not 4117%2D1Space?  Here i can replace programmatically
%2D1 with "-" for quick fix but there will other spcial characters also which will be replaced with  these kind of characters.

A: You can always do a
URLDecoder.decode(context.getURL().toString(), "UTF-8");

But you might be able to get the correct path directly through some other context method.

A: Try using URLDecoder like this
String result = URLDecoder.decode(context.getURL().toString(),"UTF-8");