text:
Q: How to query based off another table`s field? I have a table that has two columns.
  FirstTable
     UID, TID
And another table that has:
   SecondTable
     UID, TID, DiffColumn
I need to query if the UID OR TID of a user is in the FirstTable, given his UID and DiffColumn.
So I would need to join with the SecondTable to get the TID.
I tried using the following query:
     SELECT F.UID, F.TID FROM
      FirstTable F
     INNER JOIN
     SecondTable S
     ON  F.UID = S.UID
     UNION
     SELECT F.UID, F.TID FROM
     FirstTable F
     INNER JOIN
     SecondTable S ON  F.TID = S.TID
     WHERE S.DiffColumn= ''
     AND S.UID = ''

But I think I am overcomplicating this query and the where clause would apply to the second select statement only.
How would I best simplify this?

A: You can use OR in the ON clause to merge both sub subqueries. You can also move the WHERE clause's content to the  ON.
SELECT DISTINCT
    f.uid,
    f.tid
FROM
    firsttable f
INNER JOIN
    secondtable s ON s.uid = f.uid
                  OR s.tid = f.tid
                  AND s.tid = ''
                  AND s.uid = '';

A: If you want a prioritization where the match on uid takes precedence over the match on tid, then use two left joins:
select f.uid, f.tid,
       coalesce(su.?, st.?) as ?  -- ? is a column you might want from secondtable
from firsttable f left join
     secondtable su
     on su.uid = f.uid left join
     secondtable st
     on st.tid = f.tid and
        st.diffcolumn = '' and
        st.uid = ''
where st.uid is not null or st.tid is not null;

Alternatively you can just use exists if you don't want any columns from secondtable:
select f.*
where exists (select 1
              from secondtable su
              where su.uid = f.uid
             ) or
      exists (select 1
              from secondtable st
              where st.tid = f.tid and
                    st.diffcolumn = '' and
                    st.uid = ''
     );

Although you can use or in the correlation clause rather than two existss, I strongly discourage it.  or in on clauses and correlation clauses and be a performance killer.


text:
Q: Unsupported major.minor version 51.0 on maven I'm working on a java module using maven to build, all of my code builds successfully on main/java, but when I try to start creating the tests and I instantiate a class from the test/java folder the build fails with the following error:
java.lang.UnsupportedClassVersionError: javax/servlet/jsp/tagext/TryCatchFinally : Unsupported major.minor version 51.0

I'm using intelliJ in a mac, and when I check my (only) java version installed I get this:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Same for javac.
I've tried the following:

*

*Invalidate Cache and restart IntelliJ

*Check the java compiler settings on IntelliJ (everything is set to 1.6)

*Delete the javax folder on my .m2 directory so maven downloads it again

*Double checked the versions on my pom

I can't build with java 7 because then it will break a huge deal of code because Im working on a module that will interact with a java 6 built project.
It makes no sense to me because this happens only when the code is in a jUnit test case, otherwise it works!
Your help is very appreciated, thanks.
EDIT: This is not a duplicate question... because none of the existing questions talks about the version of the TryCatchFinally version. Some people are just trying to earn badges or something...

A: This error means that the javax.servlet.jsp.tagext.TryCatchFinally class that you have in dependencies has been compiled with Java 7 while you're only on 6.
I suspect the reason is that your servlet, JSP or taglib dependency is on a version built for Java 7 and you'd have to downgrade it.
What dependencies do you have in there?
EDIT: It looks like JSP 2.3 is part of Java EE 7: http://en.wikipedia.org/wiki/Java_EE_version_history. I think you're out of luck here and the only options are using Java EE 6 (downgrading the JSP dependency to 2.1 or 2.2) or upgrading to Java 7.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Exception Correlation failed with Okta and asp.net.core I have an ASP.NET Core 2.2 application with Okta identity. Everything works well except for when a new user signs up. Okta then sends a verification email to the user with an activation link and when that link is clicked I get the following exception:
System.Exception: Correlation failed.
Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I tried to clone the asp net core sample app provided by Okta, but get the same error. I setup a new OIDC application in Okta for this purpose with the following parameters:
Login redirect URI: https://localhost:44314/authorization-code/callback
Logout redirect URI: https://localhost:44314/signout/callback
Nothing else changed from default settings.


text:
Q: Bind DDNS change receiving `update failed: NOTAUTH`, how to fix that authorization issue? I have the following zone definition:
zone "madetoorder.software" {
  type master;
  file "/var/lib/bind/example.com.zone";
  allow-transfer { trusted-servers; };
  check-names warn;
  update-policy {
    grant local-ddns zonesub any;
    grant letsencrypt_wildcard. name _acme-challenge.example.com. txt;
  };
  max-journal-size 2M;
};

As shown, it is expected to allow me to add and remove sub-domains (a.k.a. foo.example.com) using nsupdate. I tried the following but I'm getting a NOTAUTH error:
$ sudo nsupdate
> local 165.232.146.181
> zone madetoorder.software
> update delete ve-vlc.madetoorder.software.
> send
NOTAUTH
> update add ve-vlc.madetoorder.software. 60 A 165.232.146.181
> send
NOTAUTH
> quit

As we can see, the send command fails with a NOTAUTH.
I know the local-ddns key is loaded successfully since when I try without sudo I get the following error:
$ nsupdate -l
19-Apr-2022 21:50:16.831 open: //run/named/session.key: permission denied
can't read key from //run/named/session.key: permission denied

Looking at the file, it does look like a valid key. Just as expected.
Also, the letsencrypt changes to a TXT field work as expected. So what is wrong in:
grant local-ddns zonesub any

Note:
As shown in the zone definition, the .zone file is under /var/lib/bind. And the directory is owned by root:bind with permissions -rwxrwxr-x. The file itself has permissions -rw-------. So named (which runs as bind) has access to the files.

A: I found a solution to my issue.
I restarted named.
I'm not too sure what is happening. It looks like it is running:
$ systemctl status named
● named.service - BIND Domain Name Server
     Loaded: loaded (/lib/systemd/system/named.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-04-20 14:25:48 UTC; 9h ago
       Docs: man:named(8)
   Main PID: 2334296 (named)
      Tasks: 14 (limit: 9508)
     Memory: 44.3M
     CGroup: /system.slice/named.service
             └─2334296 /usr/sbin/named -f -u bind

But I can't access anything. It took me a little time to notice that the system was actually dead.
When I test using dig @ns1.example.com www.example.com it fails when it's in that state. Yet the UDP port is open and as shown above, the status says OKAY (the bullet point is green in my console).
I hope this helps someone else because it is a strange state.


text:
Q: replace NA with 0 and all other values/text as 1 airquality

    Ozone Solar.R Wind Temp Month Day
1      41     190  7.4   67     5   1
2      36     118  8.0   72     5   2
3      12     149 12.6   74     5   3
4      18     313 11.5   62     5   4
5      NA      NA 14.3   56     5   5
6      28      NA 14.9   66     5   6
7      23     299  8.6   65     5   7
8      19      99 13.8   59     5   8
9       8      19 20.1   61     5   9

Hi there,
How do I replace values in Ozone to be binary?  If NA then 0 and if a value then 1.
Thanks
H

A: Assuming your dataframe is called airquality
airquality$Ozone <- ifelse(is.na(airquality$Ozone), 0, 1)

A: airquality$Ozone <- as.integer(!is.na(airquality$Ozone))

A: Alternatively
airquality$Ozone[!is.na(airquality$Ozone)] <- 1L
airquality$Ozone[is.na(airquality$Ozone)] <- 0L


text:
Q: Multithreaded removal of HttpRuntime.Cache items upon expiration Even if I use lock with static locker object to lock my code from accessing the same item at the same time, how can I guarantee that this item is not removed by HttpRuntime from another thread during my lock ? I don't see any SyncRoot property in HttpRuntime or HttpRuntime.Cache.
If I specify expiration callback and lock my static locker object inside that callback, would it be proper to do that ?
Is it bad to lock HttpRuntime.Cache expiration thread inside callback ?

A: Looking for a "SyncRoot" property suggests that you use the SyncRoot property when using locking in combination with a collection. There's a reason why, although it is supported by later collections for backwards-compatibility, it tends to be hidden through implementing the interface explicitly. Really, the SyncRoot  idea wasn't a very good one.
In this case, you're talking about a thread-safe collection, so there's even less need. System.Web.Caching.Cache does its own locking (or other mechanisms, it's specified to be threadsafe rather than to be threadsafe through a particular approach), so adding, accessing and removing an item from the collection across several threads won't corrupt it.
The only remaining risk, is if either the object itself isn't threadsafe, or if you access it from the collection several times in the same thread.
The second is easily avoided by not doing so. If you do:
(HttpRuntime.Cache.Get(someKey) as SomeType).SomeMethod();
(HttpRuntime.Cache.Get(someKey) as SomeType).SomeOtherMethod();

This only makes sense if you want to possibly be dealing with a different object in the second call than the first. Otherwise, it's easily resolved:
SomeType obj = HttpRuntime.Cache.Get(someKey) as SomeType;
obj.SomeMethod();
obj.SomeOtherMethod();

(You also get a slight performance improvement by not calling the Get method repeatedly.
If you need to worry about different threads calling SomeMethod() and SomeOtherMethod() at the same time you need to either ensure that those methods are threadsafe, or lock on an object that relates to the object in question. Most of the time the most obvious choice for an object that relates to an object, is that object itself. Hence:
SomeType obj = HttpRuntime.Cache.Get(someKey) as SomeType;
lock(obj)
{
  obj.SomeMethod();
  obj.SomeOtherMethod();
}

(Note that even if SomeMethod() and SomeOtherMethod() were threadsafe, we might still need to do this if the combination of them wasn't thread-safe. E.g. if the first reported on the objects state and we decided on the basis of that whether or not to perform the second, then we'd normally need to lock around that to prevent the state changing between the first and the second method call).
Of course, all other operations on the object would need to be locked in the same manner. It gets more complicated if we've multiple objects we need to synchronise as a unit. Then we need a more complicated rule about what object we lock on that simply locking on the object in question; because there's no single "object in question".

A: The cache is a private cache for your application.  The only time the runtime does anything to it is when the application is restarted (i.e. it clears the cache).  When you add an item to the cache, you can provide a callback to be informed of removals if you really want to be sure nothing else is messing with your cache.
I think it would be better to design the application and what is in the cache in such a ways as to minimize the need for two things to be accessing the same item in the cache though.  Having a need for two threads to be accessing the same item in the cache suggests there's a design issue.


text:
Q: What is androidx version of library for Media Style NotificationCompact? I have to create Media Notifications, What is the equivalent androidx library to implementation 'com.android.support:support-media-compat:27.1.1' support library?
I used the following androidx library but ended with an error...
implementation 'androidx.android.support.v4.media.app'

ERROR: Supplied String module notation
  'androidx.android.support.v4.media.app' is invalid. Example notations:
  'org.gradle:gradle-core:2.2',
  'org.mockito:mockito-core:1.9.5:javadoc'.

A: Use androidx.media:media:1.0.0
To get all dpendencies of android X use the below link
Migrating to AndroidX


text:
Q: how to upload files via FileZilla google compute engine I am new to Google Compute Engine. I already installed Apache and MySQL, but I have been unable to to find a way to connect to the server in FileZilla. How do I do that? Also, how can I get access to phpMyAdmin?

A: With FileZilla, you should use sftp as described on the FileZilla wiki. See also a related question on alternative methods for uploading files to your instance and make sure that port 22 is open in your firewall as described in this answer.
For phpMyAdmin, consider using an ssh tunnel. To create a tunnel, you just need to pass the right args to ssh via gcutil, where $A is the local port (must be unused on your local machine) and $B is the remote port (i.e., the port phpMyAdmin is listening to on the remote host):
gcutil --project=[...] ssh --ssh_arg -L$A:localhost:$B <instance-name>

Then, you can connect to localhost:$A and it will work.

A: Maybe you already have a Private key(.ppk) for connecting SSH.
For connect to Filezilla you have to change Private key to Public key.
1. launch Filezilla and select Edit->Settings->SFTP
2. Select Add key file.
3. Select your Private Key and Filezilla will make new public key by using your private key.
4. Now You can connect your server by SFTP in Filezilla


text:
Q: Update with Incrementing column Example table:
Sample
------
id (primary key)
secondaryId (optional secondary key)
crtdate (created date)
... (other fields)

*

*Some users use secondaryId for identifying rows (i.e., should be unique)

*When the rows were created, secondaryId did not get a value, and was defaulted to 0.

*Subsequently, rows were given a secondaryId value as they were used.

*I need to update all rows with value 0 to be the next available number.

Desired result (w/ simplified values):
   From:               To:

id secondaryId     id secondaryId
 1    0             1    7  // this is the max(secondaryId)+1
 2    0             2    8  // incrementing as we fill in the zeroes
 3    5             3    5  // already assigned
 4    0             4    9  // keep incrementing...
 5    6             5    6  // already assigned

This query would accomplish what I want to do; but alas, CTE + UPDATE is not supported:
with temp(primary, rownumber) as (
     values (
         select
             id,
             row_number() over (partition by secondaryId order by crtdate)+6 --6 is max secondaryId
         from Sample
         where secondaryId='0'
     )
update Sample set secondaryId=temp.rownumber where Sample.id=temp.id

Does anyone have suggestions for a different way to approach this problem? I'm now suffering from tunnel vision...

A: You can use MERGE statement as id is primary key and there won't be any duplicates.
MERGE INTO Sample as trgt
Using (
select id,
       row_number() over (partition by secondaryId order by crtdate)+6  secondaryId
          --6 is max secondaryId
       from Sample where secondaryId='0'
     ) as src
ON( src.id= trgt.id)
WHEN MATCHED THEN UPDATE SET trgt.secondaryid = src.secondaryId

A: For a Template method (not necessary to know max value), you can try this:
create table tmptable as (
    select f1.id, row_number() over(order by f1.crtdate) + ifnull((select max(f2.secondaryId) from Sample f2), 0) newsecondary
    from Sample f1 where f1.secondaryId='0'
) with data;

update Sample f1
set f1.secondaryId=(
                    select f2.newsecondary
                    from tmptable f2
                    where f2.id=f1.id
                   )
where exists
(
    select * from tmptable f2
    where f2.id=f1.id

);

drop table tmptable;

A: You can also UPDATE a SELECT (well "fullselect"), which is probably the neatest solution here
create table sample (
    id int not null primary key
,   secondaryId int not null
,   crtdate date not null
)
;
INSERT INTO sample VALUES
 ( 1  ,  0   , current_date)
,( 2  ,  0   , current_date)
,( 3  ,  5   , current_date)
,( 4  ,  0   , current_date)
,( 5  ,  6   , current_date)
;
UPDATE (
    SELECT id, secondaryId
,      ROW_NUMBER() OVER(ORDER BY secondaryId Desc)
            + (SELECT MAX(id) from sample)      as new_secondaryId
    FROM
        sample s
    WHERE secondaryId = 0
    )
SET secondaryId = new_secondaryId
;

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001022.html


text:
Q: Is power law distribution for extreme event special like normal distribution? The power-law distribution is defined as below in Wikipedia article:

The most extreme case of a fat tail is given by a distribution whose
tail decays like a power law.
$$ \mathrm{Pr}[X>x] \sim x^{-\alpha} \ \ \mathrm{as} \ \  x  \rightarrow \infty, \ \ \alpha > 0  $$
then the distribution is said to have a fat tail if $\alpha$  is
small.

I read numerous articles on power-law distribution to explain extreme events. Especially, the power-law distribution is ubiquitous in finance and economy.
I understand that normal distribution can be ubiquitous because of the central limit theorem(CLT). The combined effects consisting of many stochastic sub-effects might follow a normal distribution from CLT. However, I don't know if there is any universal theorem like CLT for the power-law distribution.
It seems nature favors power-law when it decides to make an extreme event. Is power-law distribution special like CLT? Or is the power-law just an artificial convenient concept to approximate the true distribution which is not power-law?

A: With respect to the first question, whether there is a convergence theorem leading to power-law distributions, the Extremal Types Theorem should be mentioned (Fisher and Tippett, 1928, Gnedenko 1934), leading to the three max-stable Extreme Value Distributions (Type I to III, also known as Gumbel, Fréchet and Weibull distributions). The Fréchet distribution or the Generalised Extreme Value (GEV) distribution with shape parameter $\xi>0$ is characterised by a fat tail. Maxima of long (asymptotically) sequences of e.g. the Cauchy, Student, or Pareto (power-law) distribution are Fréchet distributed, and it can also be shown that the Fréchet distribution is the so-called Penultimate distribution for maxima of the Gaussian distribution, even though the latter are asymptotically Gumbel (light tailed) distributed. So there is a general theorem related to the power-law distribution.
With respect to the second question, I can point you to the book of Prof. Didier Sornette, "Critical Phenomena in Natural Sciences", where he provides extensive motivation from statistical physics for fat-tailed natural phenomena.
PS: This is my first answer on a StackExchange site, in case you have tips or criticism, I'm happy for feedback!

A: $\bullet$ First, heavy-tailed/Pareto distributions (aka power laws) frequently occur outside of finance and economy. They are used to describe the size/height/magnitude/severity distribution of countless natural phenomena.
A few examples are ocean waves, volcanic eruptions, asteroid impacts (a well-known example is the size of the craters on the moon), tornadoes, forest fires, streamflow and floods, solar flares, landslides, rainfall...
Other interesting human-related examples are the size of human settlements, size of files transferred on the web, Google's PageRank numbers of webpages...
This is closely related to the field of extreme value analysis (hundred-year floods, rogue waves...) - see the answer by Joel listing some famous extreme value distributions.
It is also to be noted that the empirical distributions (histograms, KDEs) of the phenomena above are heavy-tailed. In other words, we already observe the power-law naturally emerging in these phenomena. So yes, we do use parametric models to approximate the naturally occurring distributions, simulate values, etc., but I don't think we can say that it is artificial. (The paper Clauset et al. 2009 linked to by Sycorax in the comments above seems to be a good reference here.)
$\bullet$ Second, as far as your question, while power-law distributions are frequently observed, the underlying physical processes by which they arise are still mostly unknown. Indeed, natural phenomena are complex. E.g., floods are produced by the interplay between meteorological and hydrological processes, but are also influenced by infrastructure (e.g., dams) and human activities (e.g., land use). Nevertheless, there are many underlying processes that are believed to generate fat tails in the distributions of natural and other human-related phenomena, such as:

*

*multiplicative processes (El Adlouni et al. 2008, Mitzenmacher 2004).

*random walks, the Yule process, self-organized criticality, inverses of quantities (Newman 2005).

References
Newman, Mark EJ. "Power laws, Pareto distributions and Zipf's law." Contemporary physics 46.5 (2005): 323-351.
El Adlouni, S., B. Bobée, and T. B. M. J. Ouarda. "On the tails of extreme event distributions in hydrology." Journal of Hydrology 355.1-4 (2008): 16-33.
Mitzenmacher, Michael. "A brief history of generative models for power law and lognormal distributions." Internet mathematics 1.2 (2004): 226-251.
Clauset, Aaron, Cosma Rohilla Shalizi, and Mark EJ Newman. "Power-law distributions in empirical data." SIAM review 51.4 (2009): 661-703.


text:
Q: StringEnd() raises exception when match fails - PyParsing The following prints 'pass':
pattern = Word(alphanums) + StringEnd()
str=" bar "
results = pattern.parseString(str)
if 1 == len(results) && "bar" == results[0] :
    print("pass")
else:
    print("fail")

but this throws and exception in parseImpl of class StringEnd (when the char following 'r' in 'bar' is not a string end):
pattern = Word(alphanums) + StringEnd()
str=" bar foo "
results = pattern.parseString(str)  # <-- exception raised

as does this:
pattern = Word(alphanums)
str = " bar foo"
results = pattern.parseString(str,parseAll=True)

I would expect the 2nd/3rd parseString calls to just return an empty array, as it would obviously not satisfy the grammer.
Can anyone help me understand why?
(should be obvious, but to run you'll need 'from pyparsing import *'; also I'm on python3.2 and pyparsing 1.5.6)

A: When you call parseString on a grammar, you are telling it "parse this string using this grammar, starting at the beginning".  It has to match something, or it will raise an exception.  This is doubly true when you use parseAll=True.  You are saying "match this entire string against this grammar".  If it doesn't all match, it's an error.  parseString is not an "optional" sort of match where it will just silently fail if you try to match the wrong grammar.  If something "obviously does not match the grammar", that's.exactly when it's supposed to raise an error.
You might want to try searchString instead.  This will just look for all matches within the string, wherever they are:
>>> pattern = pyp.Word(pyp.alphanums)
>>> pattern.searchString(" bar foo ")
([([u'bar'], {}), ([u'foo'], {})], {})

A: Returning an empty list on a failed match is ambiguous - did the grammar match and just return an empty match, or did it not match at all?
>>> from pyparsing import *
>>> integer = Word(nums)
>>> expr = Suppress("data:") + ZeroOrMore(integer) + StringEnd()

Parse some data:
>>> expr.parseString("data: 1 2 3").asList()
['1', '2', '3']

Successful parse, there just weren't any numbers here:
>>> expr.parseString("data:").asList()
[]

Exception tells you this match failed:
>>> expr.parseString("data: 4 Z 6 7").asList()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python26\lib\site-packages\pyparsing-1.5.6-py2.6.egg\pyparsing.py", line 1032, in parseString
    raise exc
pyparsing.ParseException: Expected end of text (at char 12), (line:1, col:13)


text:
Q: Detect another host with the same MAC address How can I detect if another host is using the same MAC address as the current host, e.g. because the other host is spoofing?
I'm working in an embedded environment, so looking for answers on a protocol level, rather than "use such and such a tool".
Edit: RARP does not solve this problem. For RARP to get any reply at all, there has to be at least one host on the segment which supports RARP. Since RARP is obsolete, modern operating systems don't support it. Furthermore, all RARP can do is tell you your own IP address - the response won't be any different if there's another host on the segment with the same MAC, unless that host has itself used a different IP address.

A: You could send an ARP request for each possible ip in the subnet.
Of course the source address of the ARP request must be ff:ff:ff:ff:ff:ff, otherwise you might not see the response.
I forged a packet like this with bittwiste and replayed it with PReplay and all the hosts on the network got the response. (I don't know if these forged ARP packets are legal or not... some OSes might ignore them)
Here is what the forged package looked like:

Here is what the reply looked like:

If you watch the responses and see your MAC address in one of the packets (in the red rectangle) , than someone has the same MAC address as you do...
Unfortuantely I couldn't test the theory fully because none of my (Windows) machines care about me trying to set the nic's MAC address...

A: This question is too interesting to put down!  After several false starts I started thinking about the essential components of the problem and scoured the RFCs for advice.  I haven't found a definitive answer, but here's my thought process, in the hope that it helps:

*

*The original question asks how to detect another device with your MAC address.  Assuming you're on an IP network, what's required to accomplish this?

*The passive method would be simply to listen to traffic and look for any packets that you didn't transmit but have your MAC address.  This may or may not occur, so although it can tell you definitively if a duplicate exists, it cannot tell you definitively that it doesn't.

*Any active method requires you to transmit a packet that forces an impostor to respond.  This immediately eliminates any methods that depend on optional protocols.

*If another device is spoofing you, it must (by definition) respond to packets with your MAC address as the destination.  Otherwise it's snooping but not spoofing.

*The solution should be independent of IP address and involve only the MAC address.

*So the answer, it seems, would be to transmit either a broadcast (ethernet) packet or a packet with your MAC address as its destination, that requires a response.  The monkeywrench is that an IP address is usually involved, and you don't know it.
What sort of protocol fits this description?
Easy Answer:

*

*If your network supports BOOTP or DHCP, you're done, because this authoritatively binds a MAC address to an IP address.  Send a BOOTP request, get an IP address, and try to talk to it.  You may need to be creative to force the packet onto the wire and prevent yourself from responding (I'm thinking judicious use of iptables and NAT).

Not-so-easy Answers:

*

*A protocol that's independent of IP: either one that doesn't use the IP layer, or one that allows broadcasts.  None comes to mind.

*Send any packet that would normally generate a response from you, prevent yourself from responding, and look for a response from another device.  It would seem sensible to use your IP address as the destination, but I'm not convinced of that.  Unfortunately, the details (and, therefore the answer) are left as an exercise for the OP ... but I hope the discussion was helpful.
I suspect the final solution will involve a combination of techniques, as no single approach seems to guarantee a dependable determination.
Some information is available at http://en.wikipedia.org/wiki/ARP_spoofing#Defenses
If all else fails, you may enjoy this: http://www.rfc-editor.org/rfc/rfc2321.txt
Please post a follow-up with your solution, as I'm sure it will be helpful to others.  Good luck!

A: Two hosts using same MAC address on a single network segment would probably make switches go nuts and you could probably detect it by having an extremely unreliable network connection (as the switches would send some portion of packets that belong to your host to the second one, depending on which one of you sent the last packet in their direction).

A: This is very late, and a non-answer, but I wanted to follow up with exactly what I did in case anyone else is interested.
I was working with some very weird embedded hardware that doesn't have a MAC address assigned at manufacture. That means we needed to assign one in software.
The obvious solution is to have the user pick a MAC address that they know is available on their network, preferably from the locally-administered range, and that's what I did. However, I wanted to pick a reasonably safe default, and also attempt to warn the user if a conflict occurred.
In the end I resorted to picking a random-ish default in the locally-administered range, chosen by making some hardware readings that have moderate entropy. I deliberately excluded the beginning and end of the range on the assumption that those are moderately more likely to be chosen manually. The chances are that there will only be one of these devices on any given network, and certainly less than 20, so the chances of a conflict are very low, albeit not as low as they could be due to the somewhat predictable random numbers.
Given the low chances of there being a problem, and despite the excellent answers above, I decided to dispense with the conflict detection and make do with a warning to the user to look out for MAC conflict problems.
If I did decide to implement conflict detection, then given that I control the whole network stack, I would probably look out for excessive unknown or missing packets, and then trigger a change of MAC address or warn the user when that happens.
Hopefully that will help someone else somewhere – but probably not!


text:
Q: Char conversion in gcc What are the char implicit typecasting rules? The following code gives an awkward output of -172.
char x = 200;
char y = 140;
printf("%d", x+y);

My guess is that being signed, x is casted into 72, and y is casted into 12, which should give 84 as the answer, which however is not the case as mentioned above. I am using gcc on Ubuntu.

A:
The following code gives an awkward output of -172.

The behavior of an overflow is implementation dependent, but visibly in your case (and mine) a char has 8 bits and its representation is the complement by 2. So the binary representation of the unsigned char 200 and 140 are 11001000 and 10001100, corresponding to the binary representation of the  signed char -56 and -116, and -56 + -116 equals -172 (the char are promoted to int to do the addition).
Example forcing x and y to be signed whatever the default for char:
#include <stdio.h>

int main()
{
  signed char x = 200;
  signed char y = 140;

  printf("%d %d %d\n", x, y, x+y);
  return 0;
}

Compilation and execution :
pi@raspberrypi:/tmp $ gcc -Wall c.c
pi@raspberrypi:/tmp $ ./a.out
-56 -116 -172
pi@raspberrypi:/tmp $

My guess is that being signed, x is casted into 72, and y is casted into 12

You supposed the higher bit is removed (11001000 -> 1001000 and 10001100 -> 1100) but this is not the case, contrarily to the IEEE floats using a bit for the sign.


text:
Q: Overloading a templated member function through enum Suppose I have an EventHandle class which is uniquely enumed by READ, WRITE, and SIGNAL, and I am implementing a member template which should return different data type with respect to different enums.
enum class EventType {
  READ,
  WRITE,
  SIGNAL
};

class EventHandle {

public:

  template <EventType type, typename = enable_if_t<is_same<type, READ>::value>>
  ReadEventHandle* cast () { return static_cast<ReadEventHandle>(this); }

  template <EventType type, typename = enable_if_t<is_same<type, WRITE>::value>>
  WriteEventHandle* cast () { return static_cast<WriteEventHandle>(this); }

  template <EventType type, typename = enable_if_t<is_same<type, SIGNAL>::value>>
  SignalEventHandle* cast () { return static_cast<SignalEventHandle>(this); }
};

And I have three derived classes from EventHandle.
class ReadEventHandle : public EventHandle {...}
class WriteEventHandle : public EventHandle {...}
class SignalEventHandle : public EventHandle {...}

Apprently what I wrote doesn't compile. Is there any way to achieve this type cast overload on "compile" time (e.g., no switch on enum)?

A: I can't say I fully understand what you are trying to do, but you certainly are not using SFINAE correctly. Here is compilable code which I hope could serve as guidance:
#include <type_traits>

enum class EventType {
  READ,
  WRITE,
  SIGNAL
};

class ReadEventHandle { };
class WriteEventHandle { };
class SignalEventHandle { };

ReadEventHandle re;
WriteEventHandle we;
SignalEventHandle se;

class EventHandle {

public:

  template <EventType type,  std::enable_if_t<type == EventType::READ>* = nullptr >
  ReadEventHandle* cast () { return &re; }

  template <EventType type, std::enable_if_t<type == EventType::WRITE>* = nullptr >
  WriteEventHandle* cast () { return &we; }

  template <EventType type, std::enable_if_t<type == EventType::SIGNAL>* = nullptr>
  SignalEventHandle* cast () { return &se; }
};

void* check() {
  return EventHandle().cast<EventType::READ>(); // Depending on cast argument, different pointers returned
}

A: An alternative with some traits and specialization:
enum class EventType {
  READ,
  WRITE,
  SIGNAL
};

class ReadEventHandle;
class WriteEventHandle;
class SignalEventHandle;

template <EventType E> struct EventHandleType;

template <> struct EventHandleType<EventType::READ> { using type = ReadEventHandle; };
template <> struct EventHandleType<EventType::WRITE> { using type = WriteEventHandle; };
template <> struct EventHandleType<EventType::SIGNAL> { using type = SignalEventHandle; };

And then:
class EventHandle {
public:

  template <EventType E>
  typename EventHandleType<E>::type* cast();
};

template <EventType E>
typename EventHandleType<E>::type*
EventHandle::cast() { return static_cast<typename EventHandleType<E>::type*>(this); }

Demo


text:
Q: How to solve "ActionView::Template::Error (invalid byte sequence in UTF-8):" experts,
I was following a book's example to build my first Blog system on RoR.  My OS is Win10, Ruby is 2.4.2p198 and Rails is 5.1.4.  After activating Rails Server, I connected to localhost:3000/users.  Then I encounter below error:
ArgumentError in Users#index
Showing C:/Users/joeychou/hello_rails/app/views/layouts/application.html.erb where line #7 raised:
invalid byte sequence in UTF-8
And it highlights the error line as below:

On rails server, the error messages are as below:

ActionView::Template::Error (invalid byte sequence in UTF-8):
      4:     HelloRails
      5:     <%= csrf_meta_tags %>
      6:
      7:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
      8:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
      9:       10:
app/views/layouts/application.html.erb:7:in
  `_app_views_layouts_application_html_erb___655117387_94495480'

Please advise how to solve this issue so that I can move on.  Any help is deeply appreciated!
Regards,Joey

A: I found the answer!
coffee-script source >= 1.9.0 don't work properly under Windows. You can do this: gem 'coffee-script-source', '1.8.0' to force 1.8.0 and then issue bundle update coffee-script-source
Please refer to below link for details.
Rails ExecJS::ProgramError in Pages#home?


text:
Q: ASP.NET Core with Swashbuckle using inheritance and collections I am working on an ASP.NET Core REST controller that uses Swashbuckle. My API response models use inheritance, and have associated SwaggerSubType and SwaggerDiscriminator attributes configured.
The API response will serialize to a derived class if I return a single object, but if I have a wrapper object that contains a collection of base class objects, then only the properties from the base class are returned in the response
public enum MyObjType { T1 }

[SwaggerDiscriminator("type")]
[SwaggerSubType(typeof(Sub1), DiscriminatorValue = nameof(MyObjType.T1))]
public abstract class Base
{
    MyObjType Type { get;set;}
}

public class Sub1
{
   public string? Name { get; set; }
}

public class BaseCollection
{
   public IEnumerable<Base> Items { get; set; }
}

So if I have an API that returns just a single object with type Base and it is a Sub1 object type, then I get the Name property. But if I return an object of type BaseCollection and the Items property contains an item of Sub1 type, the Name property is not returned in the response.
Swagger has been configured with:
services.AddSwaggerGen(c =>
                {
                   c.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: true);
                }
services.AddJsonOptions(options =>
                {
                    options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                })

What do I need to do to get my REST API that returns an object of type BaseCollection to include all of the properties of the subclasses of Base class?


text:
Q: Given a polynomial $P$ with integer coefficients, find $P(2)$ Question:
$P(x)$ be a polynomial with non-negative integer coefficients such that $P(0)=33$ , $P(1)=40$ and $P(9)=60000$.
Find $P(2)$.
My attempt:
Suppose $P(x) = a_nx^n + \dotsb + a_1x + a_0$.
Now, $P(0) = 33$ implies $a_0 = 33$.
$P(1)=40$ implies that the sum of the coefficients other than constant term is $7$. Also,
$$P(9)-P(0)=3(2^5\times5^4-11)=3^2a_{1}+3^4a_{2}+\dotsb+a_n3^{2n}.$$
Dividing both sides by $3^3$ we can easily infer $a_{1}=3$.  After solving it further, I ended up with
$$a_{2}+3a_{3}+\dotsb a_{n}3^{2n-3}=740,$$
but I can't find $P(2)$.
There are few more coefficients remaining other than $a_{1}$ whose sum is $4$, and I think casework can give a solution... like assuming consecutive $4$ coefficients $1$, $1$, $1$, $1$; $1$, $2$, $1$ etc., but I don't want to go that way.

A: As mentioned earlier, the sum of all coefficients is $40$,  and the first coefficient is $33$. So the sum of the rest of the coefficients is $7$. All we can do is go modulo powers of $9$, since for each $n$ we have $\sum_{k=0}^n a_k9^k \equiv P(9) \mod 9^{n+1}$.
Of this, we go mod $81$ :  $60000$ leaves remainder $60$ upon division by $81$. So, $9a_1 + 33$ leaves the same remainder upon division by $81$. This of course gives $a_1 = 3$ by uniqueness.
Next go mod $729$ : $60000$ leaves remainder $222$, so $81a_2 + 60  = 222$ by uniqueness, giving $a_2 = 2$.
Go mod $6561$ : $60000$ leaves remainder $951$, so $222 + 729a_3 = 951$ giving $a_3 = 1$.
Finally $59049$, gives the same remainder , so $a_4 = 0$.
Go modulo $9^6 > 60000$ : this simply gives $a_5 = 1$, since the remainder is $60000$. No more coefficients can be non-zero : they add up to $40$ now.
So the polynomial is $x^5 + x^3 + 2x^2+3x+33$. One checks that the conditions are satisfied and all coefficients are non negative.
Finally the answer is  when you substitute $2$ in here : $32+8+8+6+33 = 87$.

A: The polynomial can be at most of degree $4$ because
$9^5=59409$
so
$p(x)=33+a_1x+a_2x^2+a_3x^3+a_4x^4+a_5x^5$
and
$a_1+a_2+a_3+a_4+a_5=7$
It is clear that $a_5=1$ otherwise
if $a_5=0$ then $p(9)<60000$
while if $a_5>1$ then $a_59^5>60000$
If $a_4\neq 0$  then $p(9)>60000$ so $a_4=0$. If $a_3=0$ we have
$a_1+a_2=6$
$9a_1+81a_2=918$
that it has not solutions
So We must suppose $a_3\neq 0$ and We  must compute
$a_1+a_2+a_3=6$
$9a_1+81a_2+729a_3=918$
This means $a_3=1$ and so
$a_1+a_2=5$
So is clear that We must have $a_1=3$ and $a_2=2$. So the polinomial is
$p(x)=33+3x+2x^2+x^3+x^5$


text:
Q: Yandex Map серверная кластеризация по координатам На основе готового решения по серверной кластеризации: ( https://github.com/dimik/geohosting-server ), которое принимает координаты области в виде titles мне нужно сделать, чтобы сервер принимал не titles, а обычные GPS координаты области.
Предпринимал попытки преобразовать координаты в titles - ничего не вышло: (coordinatesToGlobalPixels, coordinatesToTileNumber, coordinatesToQuadKey) - в результате этих конвертаций получал либо 1 title либо несколько сотен миллионов titles в области 50x50км.
У кого есть опыт работы с Yandex Maps, помогите, пожалуйста, с этой проблемой, не смогу найти адекватных примеров и документации.


text:
Q: Bootstrap modal on another modal I just want to show modal on another modal. (Close current one and needs to open new one) So I used
Register here

data-dismiss="modal" I try with this attribute end of link and it's woking fine. The problem is that the second modal height is bit higher. I can't scroll down to see it's upper content. and input fields looking weird. Please see this image.

Is there any other way to show modal when another modal by closing first modal?

A: try this
$('#myModal-1').on('hidden.bs.modal', function (e) {
        $('#myModal-2').modal('show');
});

https://jsfiddle.net/princesodhi/ru2rz404/


text:
Q: need a bootstrap progress bar. Can anyone help me? Please provide sample links to implement simple bootstrap progress bar. Please help me out.

A: Bootstrap if your scroll down you will see a progress bar section or you can select it from the menu on the right just choose progress bar and it will show you all progress bar examples bootstrap has to offer.
Hope this helped :)


text:
Q: Sort Algorithm proplem - template I have a class of books, and I'm trying to sort out the books in any parameters before printing the books ..
The books are in any container.
When I run the program without the merge line is working normally, but when I leave her, that problem goes:
"| Error: assignment of read-only location 'first . gnu_cxx :: __ normal_iterator <_Iterator, _Container> :: operator * >> () |
And it brings me to the class : stl_algo.h
Can anyone help me with this!?
    operator std::string() const
    {
        int counter = books.size();
        if(counter == 0)
            std::cout << "Empty Book List." ;
         std::string s;
         std::string s1;
         std::stringstream oss1;
         oss1 << counter;
         s1 = "There are " + oss1.str() + " in the list." ;
         std::cout << s1 << "\n";
         /** Sorting the List by the requests **/
         std::sort(books.begin(), books.end(), Compare_as_books());
         std::for_each(books.begin(),books.end(), String1(s));
         return s;
    }

class Compare_as_books {
public:
     Compare_as_books() {}
     bool operator() ( const Book* b1, const Book* b2)
    {
      if(b1->getTitle() > b2->getTitle())
            return true;
        if(b1->getTitle() < b2->getTitle())
            return false;
        else

.
.
.
}

A: You do not show the definition of books but I presume it is a member of whatever class is implementing that operator std::string. std::sort modifies the sequence being sorted. Because you declared this operator with the const qualifier, this is const and so are all the members, so books cannot be sorted with std::sort.
You could:

*

*(Not recommended) Remove the const from operator std::string, but having an implicit conversion which modifies the converted object is going to cause you to write a subtle bug somewhere else, I'd almost guarantee.

*Copy the contents of books into another sequence declared as a local variable. Sort the copy instead.

*(My choice) Separate out sorting from conversion. Move the sort into a separate function not marked as const.

*Change books to another container type which is implicitly sorted, such as std::set. This has other implications, of course, butif you want it always sorted this may be the right answer.


text:
Q: Question on infinite products and normal convergence of series of function So I have a question:
Let $U \subseteq \mathbb{C}$ be an open set and let $f_{j} : U \rightarrow \mathbb{C}$, $j \in  \mathbb{N}$ be a sequence of holomorphic functions. Prove or Disprove: if $\sum_{j = 0}^{\infty} |f_{j}|$ converges normally on $U$, then $\prod_{j = 1}^{\infty} (1 + f_{j}(z))$ converges normally on $U$.
So I think this is false. I tried considering a sequence of holomorphic functions on the unit disc. The only functions I know is $f_{j}(z) = z^{j}$. Am I on the right track? Please give not hints!
Thank you very much

A: $\prod (1+f_n(z))$ converges uniformly on some set iff $\sum |f_n(z)|$ converges uniformly on that set. This is a well known fact and you can find a proof in Rudin's RCA. Applying this to compact subsets of $U$ we get the result.


text:
Q: Asp.Net Core Unauthorized login - C# I don't know if my title is correct. But I have a simple problem.
I can't login. And is this because the encrypted data i cannot decrypt it properly?
Basically, I have a register method.
And this is my AuthRepository
public class AuthRepository : IAuthRepository
    {
        private readonly DataContext _context;

        public AuthRepository(DataContext context)
        {
            _context = context;
        }

        public async Task<User> Login(string username, string password)
        {
            var user = await _context.Users.FirstOrDefaultAsync(x => x.Username == username);

            if (user == null)
                return null;

            if (!VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
                return null;

            return user;
        }

        private bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt)
        {
            using (var hmac = new System.Security.Cryptography.HMACSHA512())
            {
                var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));

                for (int i = 0; i < computedHash.Length; i++)
                {
                    if (computedHash[i] != passwordHash[i])
                        return false;
                }
            }
            return true;
        }

        public async Task<User> Register(User user, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await _context.Users.AddAsync(user);
            await _context.SaveChangesAsync();

            return user;
        }

        private void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt)
        {
            using (var hmac = new System.Security.Cryptography.HMACSHA512())
            {
                passwordSalt = hmac.Key;
                passwordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
            }
        }

        public async Task<bool> UserExists(string username)
        {
            if (await _context.Users.AnyAsync(x => x.Username == username))
                return true;
            return false;
        }
    }

My register is working. I tested it using Postman
But why i can't login?
Is there any wrong with my decrpyting the encrypted data when the user is registered I've been trying to solve for hours now. But i can't make it work. I am following a video tutorial. But i can't find the difference with the one in the tutorial and mine.
[Route("api/[controller]")]
    [ApiController]
    public class AuthController : ControllerBase
    {
        private readonly IAuthRepository _repo;
        private readonly IConfiguration _config;

        public AuthController(IAuthRepository repo, IConfiguration config)
        {
            _repo = repo;
            _config = config;
        }
        [HttpPost("register")]
        public async Task<IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

            if (await _repo.UserExists(userForRegisterDto.Username))
                return BadRequest("Username already exist");

            var userToCreate = new User
            {
                Username = userForRegisterDto.Username
            };

            var createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            return StatusCode(201);
        }

        [HttpPost("login")]
        public async Task<IActionResult> Login(UserForLoginDto userForLoginDto)
        {
            var userFromRepo = await _repo.Login(userForLoginDto.Username.ToLower(), userForLoginDto.Password);

            if (userFromRepo == null)
                return Unauthorized();

            return Ok();
        }
    }

I'm really stuck into this part. Please help me. Thank you.
I didn't encountered any error.
But i noticed this when i debug the program

The array result is not the same. Is this the reason of the Unauthorized login
If so. How can i properly validate the username and password.
I also checked if the username and password i passed in the web api is correct (plain text).

A: I have checked the problem is when you are creating and comparing the object of System.Security.Cryptography.HMACSHA512() because of this it always generate a different hash. Solution for this is to declare a global object for this class and you have to use the object when you are creating and verifying the hash. I have checked it. It working fine in my case after declaring globally.


text:
Q: Android App without a Main Activity? I would like for my application to not show any activity except on launch or specifically requested by the widget it contains. In other words I want it to find and launch the main activity on Launching the app, but otherwise I don't want any Activity at all to show unless an intent specifically requests it.  I don't want the app coming to the foreground to mean that the main activity always displays.  How can the main activity be supressed except on launch? thanks

A: Based on Feedback the Answer is that no main activity is required for an Android application.


text:
Q: Eaten by the net? Crawler survival under this website using python I am making web-crawler to get information from http://www.caam.org.cn/hyzc, but it showed me HTTP Error 302, and I cannot fix it.
https://imgur.com/a/W0cykim
The picture gives you a rough idea about the special layout of this website in that when you are browsing it, it will pop out a window, telling you that the website is accelerating, for the reason that there are so many people online, and then direct you to that website. As a result, when I use web-crawler, all I get is the information on this window, but nothing on this website. I think this is a good way for the website keeper to get rid of our web crawlers. So I want to ask for your help to get useful information from this website
At first, I used requests of python for my web crawler, and I only got information on that window, the results are shown here: https://imgur.com/a/GLcpdZn
And then I forbad website redirect, I got HTTP Error 303, shown:
https://imgur.com/a/6YtaVOt
This is the latest code I used:
python
import requests
def getpage(url):
    try:
        r= requests.get(url, headers={'User-Agent':'Mozilla/5.0'}, timeout=10)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return "try again"
url = "http://www.caam.org.cn/hyzc"
print(getpage(url))

The expected outcome of this question is to get useful information from the website http://www.caam.org.cn/hyzc. We may need to deal with the window popped out.

A: Looks like this website have some kind of protection against crawlers using requests, the page is not entirely loaded when you send a get request.
You can try to emulate a browser using selenium:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.caam.org.cn/hyzc')
print(driver.page_source)
driver.close()

driver.page_source will contain the page source.
You can learn how to setup selenium webdriver here.

A: I added something to delay the closure of my web crawl and this worked. So I want to share my lines in case you meet similar problem in the future:
python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = Options()
driver = webdriver.Chrome(chrome_options=options)
driver.get('http://www.caam.org.cn')
body = driver.find_element_by_tag_name("body")
wait = WebDriverWait(driver, 5, poll_frequency=0.05)
wait.until(EC.staleness_of(body))
print(driver.page_source)
driver.close()


text:
Q: What 'mythical creature' is David searching for? What 'mythical creature' is David, the child mecha, searching for in the movie Artificial Intelligence?

A: He is searching for the Blue Fairy (or the Fairy with the Turquoise Hair), the character from the Pinocchio story who first brought the puppet to life (in the Disney version of the story), and later turned it into a real boy (in both the original book by Collodi and the Disney version). David believes/hopes that the Blue Fairy can similarly turn him into a real boy too.


text:
Q: Comparing Parameter Types I have a method that is used to compare parameter types to the types of arguments given.
private boolean typesMatch(Class<?>[] one, Object[] two)
{
    if(one.length != two.length)
        return false;

    for (int i = 0; (i < one.length)&&(i < two.length); i++)
        if(!one[i].equals(two[i].getClass()))
            return false;

    return true;
}

For example, in one[], there might be String, boolean. However, in the second, there is String, Boolean. Do you see my issue? When it compares boolean and Boolean it returns false. How do I solve this so that I don't have to use 'if statements' for every primitive type to unwrap them?
Edit: I mean to unwrap the wrapper class in the second array so it's comparable to the primitive type in the first array.
Originally, the Boolean object in array two was added to it as primitive boolean.

A: This should resolve your problem:
private static boolean typesMatch(Class<?>[] one, Object[] two)
    {
        if(one.length != two.length) {
            return false;
        }

        for (int i = 0; (i < one.length)&&(i < two.length); i++){
            if ((one[i].isPrimitive() && two[i].getClass().getSimpleName().equalsIgnoreCase(one[i].getName())) ||
                    (two[i].getClass().isPrimitive() && one[i].getSimpleName().equalsIgnoreCase(two[i].getClass().getName()))) {
                return true;
            }
            if(!one[i].equals(two[i].getClass())) {
                return false;
            }
        }

        return true;
    }

A: You don't need if statement for every primitive.
Just check if two[i].getClass() is one of primitives, and then call function which will return it's wrapper class.
// safe because both Long.class and long.class are of type Class<Long>
  @SuppressWarnings("unchecked")
  private static <T> Class<T> wrap(Class<T> c) {
    return c.isPrimitive() ? (Class<T>) WRAPPERS_TO_PRIMITIVES.get(c) : c;
  }

  private static final Map<Class<?>, Class<?>> WRAPPERS_TO_PRIMITIVES
    = new ImmutableMap.Builder<Class<?>, Class<?>>()
      .put(Boolean.class, boolean.class)
      .put(Byte.class, byte.class)
      .put(Character.class, char.class)
      .put(Double.class, double.class)
      .put(Float.class, float.class)
      .put(Integer.class, int.class)
      .put(Long.class, long.class)
      .put(Short.class, short.class)
      .put(Void.class, void.class)
      .build();

The code above is taken from Simple way to get wrapper class type in Java


text:
Q: Is it possible to consume an EJB 3 Web Service form a Java client without first generating client stubs/proxies? In most tutorials that I have seen so far people are using wsconsume or something like that to create classes that clients can use to access an EJB 3 Web Service.
Is this the only possible option? As my EJB's interface is annotated with WebMethod, WebParam, etc. isn't it possible to create a dynamic proxy or use runtime bytecode enhancement to create the proxies, etc. on the fly? E.g.:
MyWebService webService = WebServiceEnhance.getWebService(MyWebService.class);
webService.webMethod("foo");

A link to good reference material is also highly appreciated.

A: One way is to deal with pure XML request/response.  You can trap sample request/response for the web service you want to consume using either SoapUI or Fiddler and then use these samples as templates within your client.


text:
Q: GSON, custom deserializer for multiple classes I need to implement a custom GSON deserializer (with Retrofit2) for my Android application in kotlin. This is how an example of how api gives me result:
example1:
 {
     "res": {
          "status": {
              "code": 0,
              "message": "some message",
          }
     },
     "somedata": {
         "someid" = "12345",
         "sometext" = "a text"
     }
 }

example2:
{
     "res": {
          "status": {
              "code": 0,
              "message": "another message",
          }
     },
     "anotherdata": {
         "anotherid" = "54321",
         "anothertext" = "b text"
     }
 }

this is relative kotlin classes for mapping data (i would use deserializer for extract data inside "res" object):
abstract class GenericResponse() {
    //abstract class for common fields
    constructor(status: Status?) : this()
}

class Status(
    val code: Int,
    val message: String
)

and this is specific response classes:
data class SomeData(
    val status: Status,
    val someid : String,
    val sometext : String
): GenericResponse(status)

data class AnotherData(
    val status: Status,
    val anotherid : String,
    val anothertext : String
): GenericResponse(status)

i've tryed to create a custom deserializer class  that implements JsonDeserializer, something like:
class CustomDeserializer : JsonDeserializer<GenericResponse> {
    override fun deserialize(
        json: JsonElement?,
        typeOfT: Type?,
        context: JsonDeserializationContext?
    ): GenericResponse {

    val rootElement = json!!.asJsonObject.getAsJsonObject("res")
    //further implementation, should return SomeData or AnotherData object
}

but it doesn't work. How can i do?

A: For your JSON response
{
"res": {
    "status": {
        "code": 0,
        "message": "some message"
    }
},
"somedata": {
    "someid": "12345",
    "sometext": "a text"
},
"anotherdata": {
    "anotherid": "54321",
    "anothertext": "b text"
}
}

The data model classes can be
Somedata
data class Somedata(
val someid: String,
val sometext: String
)

Status
data class Status(
val code: Int,
val message: String
)

Anotherdata
data class Anotherdata(
val anotherid: String,
val anothertext: String
)

These classes can be combined to parse the entire response
GenericResponse
data class GenericResponse(
val anotherdata: Anotherdata,
val res: Res,
val somedata: Somedata
)

In retrofit use like
@POST("url")
fun callingMethod(@Field("username") username: String, @Field("password")
password: String): GenericResponse


text:
Q: how to make a column's value match all the values from a subquery How to get the column's values which match all the values from a subquery?
Here my table :
Table P
p# - pname - color - city
1  -  nut  -  Red  - London
2  -  Bolt - Green - Paris
3  - Screw - Blue  - Rome
4  - Cam   - Blue  - Paris
...

For example, if I want the name of the cities which have the same color of piece (P)?
I was thinking about this query:
SELECT city
FROM P
WHERE city = 'blue';

Of course, it's cheating because I only have a few rows, so how do you write a query that can generalize it ?
*Maybe using EXISTS or NOT EXISTS ?

A: If I understand correctly, you want the name of cities where the colors are the same as a given city.  If so, you can use a join and aggregation:
select p.city
from P p join
     P p1
     on p1.city = 'Rome' and
        p1.city <> p.city and
        p1.color = p.color
group by p.city
having count(distinct color) = (select count(distinct color) from p where city = 'Rome');


text:
Q: Does sampling more frequently reduce variance? Suppose you are getting a stock's prices at hourly intervals and you want to use those to model the stock's returns (relative to the day's starting price). When you get the stock price, you are also getting some features measured at the same time as the price. Say you build a regression model from the computed returns and the features. Now, your boss tells you, "variance of regression coefficients decreases if you increase the sample size, so why not just sample at minute intervals rather than hourly intervals? You'll get 60x data". Is this sound advice?

A: This sounds like an example of Goodhart's law, where minimizing variance became aim by itself, rather than the metric.
The boss is technically correct, standard error is $\sigma/\sqrt n$, so the larger the sample, the smaller it would be. So the more data you have, the less the estimates would vary. You can achieve this by sampling your data more frequently, sure. You would achieve same effect with repeating every row in your data, to get ten-fold decrease. "Technically" this would work, but not necessary improve the results. For example, if you're are doing daily forecasts, than usually daily data would be enough for your, and having data in minute frequency would not help much. Moreover, such data would be likely autocorrelated, so the minutely rows would be very similar to each other. With repeating rows this should be even more obvious, since it does not add any new information at all. Always ask yourself in such cases if you gain new information with the additional rows, maybe not?

A: I agree with the previous answer, with some additions : your boss's advice is not unsound. As you are only increasing the number of observations, and not their nature (i.e. what you observe) or the sampling protocol, the variance of your estimator can only decrease. How it will decrease depends on the correlation structure of your observations :

*

*Best case scenario : all your observations are i.i.d., and the variance will tend to 0 as the number of observations $n$ increases (https://en.wikipedia.org/wiki/Effective_sample_size)

*Worst case scenario : your new observations are perfectly correlated with the previous ones, and thus do not bring any information. Then the variance of the estimator is left unchanged.

Intuitively, I guess that observations sampled with a short time interval will be highly correlated.
An interesting reference on how correlations are linked to the information content is the following one :
Moreno-Bote, R., Beck, J., Kanitscheider, I., Pitkow, X., Latham, P., & Pouget, A. (2014). Information-limiting correlations. Nature neuroscience, 17(10), 1410-1417.
One way to optimize your observation times so as to minimize the variance of your estimators is to perform Optimal Experiment Design (OED). Speaking of Goodhart's law, I was concerned that such an optimized protocol (in which you only try to reduce the variance of your estimates) might in return increase its bias. However, I could not come up with an example of a protocol that would reduce the variance of your estimates while increasing its bias : Biased estimator obtained by optimal experiment design


text:
Q: Is it possible to statically verify structure of c# expression tree arguments? I have a method
public static class PropertyLensMixins
{
    public static ILens<Source> PropertyLens<O,Source>
        ( this O o
        , Expression<Func<O, Source>> selector
        )
        where O: class, INotifyPropertyChanged
        where Source: class, Immutable
    {
        return new PropertyLens<O, Source>(o, selector);
    }
}

and the idea is to use it this way
this.PropertyLens(p=>p.MyProp)

however it is an error to create a nested expression even though the compiler will accept it
this.PropertyLens(p=>p.MyProp.NestProp)

now I can catch this at runtime by parsing the expression tree. For example
var names = ReactiveUI.Reflection.ExpressionToPropertyNames(selector).ToList();
if (names.Count > 1)
    throw new ArgumentException("Selector may only be depth 1", "selector");

I was wondering however, is there any clever way to detect this at compile time? I doubt it because the compiler is happy with the type signature but I thought I might ask anyway.
I have also tried a Resharper pattern to match it as an error
$id0$.PropertyLens($id1$=>$id1$.$id2$.$id3$)

with all placeholders being identifiers but Resharper can't seem to match it.

A: There is no way to make the compiler reject such code.
One possible alternative would be to create a custom diagnostic using Roslyn. That way, all such errors will be marked by VS. Though it might be too much work for something like this.


text:
Q: How safe is to use BACKUP LOG WITH TRUNCATE_ONLY As per the title, how much is it safe to use BACKUP LOG db_name WITH TRUNCATE_ONLY in last STEP of any SQL-job execution? Randomly found on google that this Code line can be very harmful in use. But how?
I am using my code as below in one of my SQL-job's last STEP.
BACKUP LOG  my_database with Truncate_Only
DBCC SHRINKFILE (N'my_database_Data')
DBCC SHRINKFILE (N'my_database_Log')

Let me simplify the question with below aspects:

*

*What actually doing this code in the SQL-Job? Does it really help?

*Is there anything related performance of the DB-Server?

*If I remove first line of code (BACKUP LOG), how it can get effect?

*Currently I am not able see SQL-Job history of same SQL-Job, is this the reason that it clears all logs?

This could be opinion based question but still let's discuss if you can share some Ideas on it.

A:

*

*What actually doing this code in the SQL-Job? Does it really help?

SQL is backing up the log to nowhere and then trying to shrink the data and log files of your database. All of these are bad ideas. Backing up the log to nowhere means you lose point-in-time recovery of your database because you cannot restore these portions of the log. See this link for more info.

*Is there anything related performance of the DB-Server?

Constantly shrinking your log and data files can cause performance issues because SQL Server has to regrow these files as needed, which causes waits on your queries that require the additional space.

*If I remove first line of code (BACKUP LOG), how it can get effect?

Before you can reclaim space in the log, you need to backup the data in the log. Removing this would mean your shrinking wouldn't likely free much space, however, as stated before shrinking the log is a bad idea anyway.

*Currently I am not able see SQL-Job history of same SQL-Job, is this the reason that it clears all logs?

No, this is unrelated. Most likely your SQL Agent history is limited and you have a high-frequency job filling the job history tables. See this link.


text:
Q: A Markov chain indexed by the integers My definition of a markov chain (in discrete time with countable state space), is the following:
Let $S$ be a countable set, $P$ be a stochastic matrix indexed by $S$ and , $\lambda$ a distribution probability on $S$.
A sequence of random variables $\{X_n\}_{n \geq 0}$ is a markov chain Markov$(\lambda, P)$ if $X_0\sim \lambda$ and given any $i_0,i_1,..., i_{n+1} \in S$ it is true that
$$P(X_{n+1} = i_{n+1}|X_0=i_0,...,X_n = i_n) = P(X_{n+1}=i_{n+1}|X_n = i_n) = p_{i_n,i_{n+1}}$$
where $p_{i_n,i_{n+1}}$ is an entry of the matrix $P$.
Now, my markov chain is indexed by the natural numbers ($n\geq 0$). Is there a way to formally define a markov chain indexed by the integers $\mathbb{Z}$? There's no longer an initial value of the markov chain, so how could it work?

${\color{red}{\mbox{Thought:}}}$
Suppose we take a stochastic matrix $P$ that is irreducible and positive recurrent, so that there exists an invariant distribution $\pi$.
Given any $k \in \mathbb{N}$, if I take $\{X_n\}_{n \geq 0}\sim Markov(\pi,P)$ and $\{Y_n\}_{n \geq -k} \sim Markov(\pi,P)$ (in this case we begin the $Y$ chain at $n=-k$, so $Y_{-k}\sim \pi$)
Then we have $X_n \overset{d}{=}Y_n \forall n\geq 0$.
Does it make sense then to think about a "doubly infinite Markov chain" $\{X_n\}_{n \in \mathbb{Z}}\sim Markov(P)$  as a sequence of random variables such that
$$P(X_{n+1}=i_{n+1}|X_n = i_n,... X_0=i_0,...X_{-n} = i_{-n},...) = P(X_{n+1} = i_{n+1}|X_n=i_n) = p_{i_n,i_{n+1}}$$
and such that $P(X_n = j) = \pi_j \forall n$ where $\pi_j$ is the invariant distribution of the matrix $P$?
Is there a correct/standard way to define this object (if it exists)?

Any information or references about the subject would be appreciated. Thanks in advance.

A: Yes.  Suppose $\{X_n\}_{n=0}^{\infty}$ is DTMC on a finite or countably infinite state space $S$ with transition probabilities $(P_{ij})$. Suppose it is irreducible and it has a stationary mass function $\pi = (\pi(s))_{s \in S}$, so that
$$ \pi(j) = \sum_{i \in S} \pi(i) P_{ij} \quad \forall j \in S $$
Since the DTMC is irreducible it can be shown that $\pi(j)>0$ for all $j \in S$.
Suppose that $X_0$ starts in this stationary distribution:
$$ P[X_0=s] = \pi(s) \quad \forall s \in S$$
Now define a "backwards" DTMC $\{Z_n\}_{n=0}^{\infty}$ with some transition probabilities $\tilde{P}_{ji}$ (defined below) such that $Z_0=X_0$, and where all transitions in $Z_n$ are conditionally independent of $\{X_n\}_{n=0}^{\infty}$ (given $X_0$):
$$ \tilde{P}_{ji} = P[Z_{n+1} = i | Z_n=j] = \frac{\pi(i)P_{ij}}{\pi(j)} \quad \forall i, j \in S$$
You can verify these are valid transition probabilities (nonnegative, and sum to 1).
Define $\{Y_n\}_{n=-\infty}^{\infty}$ by
$$ Y_n = \left\{\begin{array}{cc}
X_n & \mbox{ if $n \in \{0, 1, 2, ...\}$} \\
Z_{-n} & \mbox{ if $n \in \{-1, -2, -3, ...\}$}
\end{array}\right.$$
You can verify that
$$P[Y_n=s] = \pi(s) \quad \forall n \in \mathbb{Z}, \forall s \in S$$
and for all $n \in \mathbb{Z}$:
$$P[Y_{n+1}=j|Y_n=i, Y_{n-1}=i_{n-1}, Y_{n-2} = i_{n-2}, ...] = P_{ij} \quad \forall i, j \in S$$


text:
Q: CSS fixing of search box Height of submit field is slightly smaller than the text input field. How do I fix it?
HTML code:
<form name="searchBox" id="searchBox" action="#" method="post"> <input type="text" name="query" id="query"/>
<input type="submit" name="sub" id="sub" value="Search"/> </form>

CSS code:
form input[type="text"] {
height: 28px;
width: 300px;
margin: 0;
padding: 0;
font-size: 15px;
border: 1px solid #CCCCCC;
}

form input[type="submit"] {
height: 28px;
width: 80px;
margin: 0;
padding: 0;
font-size: 15px;
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
}

A: you can increase or decrease height of the text/submit fields to align properly.
Example http://jsfiddle.net/2DdA3/


text:
Q: Show that $\frac{1}{a^2+b^2+1}+\frac{1}{b^2+c^2+1}+\frac{1}{c^2+a^2+1}\leq 1$. Let $a, b, c>0$ s.t. $abc (a+b+c)=3$.
Show that $\frac{1}{a^2+b^2+1}+\frac{1}{b^2+c^2+1}+ \frac{1}{c^2+a^2+1}\leq 1$.
I have no idea how to start.

A: By C-S we obtain:
$$\sum_{cyc}\frac{1}{a^2+b^2+1}=\sum_{cyc}\frac{2+c^2}{(a^2+b^2+1)(1+1+c^2)}\leq\sum_{cyc}\frac{2+c^2}{(a+b+c)^2}.$$
Can you end it now?

A: Firstly, we have $abc(a+b+c)=3$, which means that the known inequality $abc \le \frac{(a+b+c)^3}{27}$ gives $\frac{3}{a+b+c}\le\frac{(a+b+c)^3}{27}$, giving further $a+b+c \ge 3$.
And, therefore, $abc = \frac{3}{a+b+c} \le 1$, which we shall call inequality (1)
We know $ \sum_{cyc}{a^2} \ge \frac{(a+b+c)^2}{3} \ge 3 $, which we shall call inequality (2)
Making it such that you have the same denominator everywhere, the inequality will become equivalent to
$$2 \sum {a^2} +2 \le \sum {a^2b^2(a^2+b^2)} + 2a^2b^2c^2 $$
$$\text {or, equivalently,}$$ $$2 \sum_{cyc} {a^2} +2 + a^2b^2c^2 \le (\sum_{cyc}{a^2})(\sum_{cyc} {(ab)^2})   $$ which is true since,$$\text{ by} \sum_{cyc}{x^2} \ge \sum_{cyc}{xy} \text{ applied for the last cyclical sum, where } (x,y,z)=(ab,bc,ac) \text{ we have}$$
$$\sum_{cyc}{a^2}\sum_{cyc}{(ab)^2} \ge (\sum_{cyc}{a^2})[abc(a+b+c)] = 3\sum_{cyc}{a^2} = 2\sum_{cyc}{a^2} + \sum_{cyc}{a^2} \ge $$ $$ 2\sum_{cyc}{a^2}+3 \ge 2\sum_{cyc}{a^2}+ 2 + a^2b^2c^2 $$ The two last steps were made using inequality (1), respectively (2), which we know to be true. Q.E.D.


text:
Q: who can change pdfmake header size image is too small? I want to make the header part of the pdf file as in the figure, but the logo image is too small. When you want to increase its width, the picture disappears. can you help me.
http://live.datatables.net/jatobaqi/227/edit  there is my code
enter image description here  there is result
$(document).ready( function () {
       var table = $('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [

        {
            extend: 'pdfHtml5',
           className: 'pdf-buton',
            customize: function ( doc ) {

             var now = new Date();
             var jsDate = now.getDate()+'/'+(now.getMonth()+1)+'/'+now.getFullYear();

              doc['header']=(function() {
                    return {
                      columns: [
                        {
                          alignment: 'left',
                          italics: false,
                          bold: true,
                          text: ['RAPOR'],
                          fontSize: 25,
                          margin: [27,0,0,0]
                        },
                        {
                          image: 'image'
                          width: 30

                        }
                      ],
                      margin: 10
                    };
                  });

              doc['footer']=(function(page,pages) {
                    return {
                      columns: [
                        {
                          alignment: 'left',
                          text: ['www.---------.com']
                        },

                        {
                          alignment: 'right',
                          text: ['Sayfa ', { text: page.toString() }, ' / ',  { text: pages.toString() }]
                        }
                      ],
                      margin: 20
                    };
                  });

              doc.content.splice( 0, 1, {
                    margin: [ 0, 0, 0, 5 ],
                    alignment: 'left',
                  text:  'Firma/Şahıs:' + ' firma ',
                  fontSize: 12,
                },{
                    margin: [ 0, 0, 0, 5 ],
                    alignment: 'left',
                  text:  ['Tarih: ', { text: jsDate.toString() }],
                  fontSize: 12,
                },
                                  );
                console.log(doc.content)
            }
        },
    ]

});
} );

A: You have to adjust marigns. It will work like that:
          doc['header']=(function() {
                    return {
                      columns: [
                        {
                          alignment: 'left',
                          italics: false,
                          bold: true,
                          text: ['RAPOR'],
                          fontSize: 25,
                          marginTop: 10,
                          marginLeft: 30,
                          width:500

                        },
                        {
                          image: 'data:image/png;base64,[encoded data, 10240 characters]',
                          width: 62,
                          marginTop: 2,

                        }
                      ],

                    };
                  });


text:
Q: PHP select text from a complex string I am getting output from my linux box running the ifconfig command. I do so by running the shell_exec command. I found an example but I can't seem to work further with it.
This is my current code.
public function get_network_interfaces() {

    // Run the command.
    $cmd_exec = shell_exec("/sbin/ifconfig");

    // Get the pattern.
    $pattern = '/inet addr:([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})/';

    if (preg_match_all($pattern, $cmd_exec, $matches)) {
        $interfaces = $matches[1];
        return $interfaces;
    }

}

The output of this (after foreach'ing) is simply; 192.168.1.1/127.0.0.1 because it has two network adapters, the output of ifconfig is;
eth0      Link encap:Ethernet  HWaddr 00:16:3e:38:b8:1c
      inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: 2a02:2308::216:3eff:fe38:b81c/64 Scope:Global
      inet6 addr: fe80::216:3eff:fe38:b81c/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:10612623 errors:0 dropped:0 overruns:0 frame:0
      TX packets:151855 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:539434883 (514.4 MiB)  TX bytes:37861938 (36.1 MiB)
      Interrupt:30
lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:16436  Metric:1
      RX packets:6662 errors:0 dropped:0 overruns:0 frame:0
      TX packets:6662 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:768641 (750.6 KiB)  TX bytes:768641 (750.6 KiB)

What I am trying to get is like, the names of the interfaces (eth0 and lo), along with the inet adds (which is working already) followed by RX bytes and TX bytes.
If the name is too hard to get, so be it. But can anyone explain me how to get the RX bytes and TX bytes?
Thanks.

A: For the names of the interfaces, this should work:
$pattern = '/^(\w*)\s*Link encap.*$/';

For the RX and TX bytes:
$pattern = '/RX packets:(\d*) /';
$pattern = '/TX packets:(\d*) /';

And you should test in order to be sure you have all the information for every interface:

*

*Test for the name of the interface.

*Test for the IP number.

*Test for the RX byte.

*Test for the TX byte.

and when you have the four of them, then go for another cycle (for example with continue).
P.S. Be careful about the language you're using in your system, because with spanish you get "Paquetes RX:". Just to be sure, and in order to make your code more robust, you should try to make shell_exec to set environment variable LC_MESSAGES to en_us.utf-8 for example.


text:
Q: Connecting two IPs like an URL I haven't found answer anywhere, so here comes the question.
My ISP connected me to a router with thousands of other clients, so my public IP is the same as many others. And I want to make a small private server which can be accessible across whole web.
So my home router shows me IP 10.x.x.x and actually my public IP is 89.x.x.x. Is there any way to reach the IP 10.x.x.x from the Internet?
Yeah I thought the same about IPv6 but it's still not accessible for me ;[

A: You appear to be in a country where IP addresses are in very short supply. This is the only reason that an ISP would deploy large-scale NAT at its customers. Hopefully your ISP is also smart and is planning to deploy IPv6 as quickly as possible.
You won't be able to accept incoming connections and run a home server at all in a scenario in which the ISP uses large-scale NAT. And many other applications may not work 100% reliably, such as instant messaging, Skype, etc.
If you want to be able to run services on your connection, you will probably have to pay for business-class service with a static IP (IPv4) address. Be prepared to pay a high premium for this.
If you just want to run a small server for some little project, your best and cheapest option is probably to just lease a virtual server from a company in the US or EU. You can often find these for just a few dollars/euros a month at places like lowendbox.com. This will almost certainly be cheaper than trying to run it at home on a business ADSL/cable connection, though you'll have to shop carefully as low-end providers vary greatly in the quality of service they provide.


text:
Q: How can I do image manipulation on a very large BMP? I am trying to do some manipulation (specifically, conversion to a different type of splitting into tiles) on a set of very large (a few GB) BMP image files.
I'm not sure I understand the BMP file format, but is it necessary to load the entire file into memory? I was unable to find any API that didn't require loading the entire file at some point. ImageMagick wasn't able to do it either.
Java would be the best tool of choice for me, but any other solution including command line tools or desktop software would be acceptable.

A: Based on this, it should be reasonably apparent that you can use the fact that it's row-packed.  You should be able to read part of a row, store it, advance to the same position in the next row and repeat until you have completed a tile of the desired size.  Obviously you may be able to do multiple tiles at once if you can store an entire row worth of tiles in memory all at once.
It is not necessary to load more than the header of the file at once.  The header format is describe in the linked Wikipedia entry.  It's probably worth paying attention to any compression schemes being used - compression is likely to make this task a bit harder (though still not impossible) :)

A: Not sure about 2011 year of this questing, but Java 7 (and possibly 6) has good approach for such pleasure.
Use ImageReader and ImageReadParam classes, they allow to read any rectangular part of source image if needed. Set source rectangle and read
... // initialization

private javax.imageio.ImageReadParam m_params;
private javax.imageio.ImageReader m_reader;

... // reading

m_params.setSourceRegion( readRect );
BufferedImage rdImg = m_reader.read( i, m_params );

... // processing/displaying etc

As BMP (it works too for any standard Java image type) is very planar format without any compression in 99.99% cases, to read any its part such way is very fast process with low memory consumption except resulted BufferedImage. Or you can even reuse previous BufferedImage on consequent request with the rect of same dimensions. See ImageReadParam.setDestination(BufferedImage destination). But I didn't test this option.
Also I found one small reading bug namely in BMP reader class implementation of Java runtime lib. If somebody be  interested in this, I'll show simple way to correct it.


text:
Q: Polygon to polygon spatial join without double counting join features using ArcGIS Desktop I am a new GIS user trying to aggregate local ward-level voting data up to a broader county-level using a Spatial Join.
Generally a given ward is within only one county, so a JOIN_ONE_TO_ONE for the join_operation with a sum Merge Rule and CONTAINS as the match_option should work. The problem is that the ward and county boundaries aren't always coincident, and some wards are partially within two adjacent counties.
In this case a CONTAINS Match Option results in undercounting because some wards aren't included anywhere in the out_feature_class. I tried using INTERSECT as the Match Option instead but this results in some double counting in the Output Feature Class.
Is there a simple way to ensure that a join feature is included in only one target feature?
Perhaps with a "if > 50% of the join feature is within the target feature" or similar expression.
I'm using ArcGIS Desktop 10.6.


text:
Q: Convert 16 bit color pallete index to 32 bit color I have a file that contans 16 bit indicies for a "pallete". The "pallete" is not defined in the file. (The size of the image is known, that's not imporant though) I need to convert from an index (16 bit) to a 32 bit color (ARGB, 1 byte per channel). It would be nice to have
a little function like this:
Color GetColorFromIndex(short idx)
{
   return Color.FromArgb(...); // C#, but it doesn't matter that much.
}

(I know that because the index is 16 bit, number of all colors is 65536 (2^16) and that not all colors will be avaliable).

Also, a solution for any number of bits for an index (eg. 32, 16, 8, 4, 2, 1) that will make a 32 bit color would nice :)


text:
Q: Improving probability calibration of Random Forest for multiclass problem I am working on getting good probability from Random Forest algorithm for better decision making. Currently, I have trained the RF model with default parameters and then applied isotonic regression using CaliberatedCV sklearn library. Although I was able to get some improvement in terms of log loss, the brier score has not changed. I would like to request to help me find how I can get nearly perfect probability calibration for a multiclass problem from my Random Forest algorithm.
The dataset is highly imbalanced, therefore, I have set class weight parameter of RF to "balanced".

A: I'll bring over my comments from the Stackoverflow question.
(1) RF outputs are votes, not proportions. My advice is to try to set parameters for RF or just use a different kind of tree or different model altogether to get at least proportion of positive examples in each leaf. Starting from votes is just setting your starting position farther away from the goal.
(2) Since the cases are highly imbalanced, consider constructing generative models, one for positive, one for negative cases, then combine them via Bayes rule (which brings the base rates into play). If there is anything you know specifically about the minor class, try to build that into the generative model.
Whatever you know about how the data are generated is very relevant, especially in the case of building a generative model. So any further information about that will help others help you.


text:
Q: Create table from another tablo column that have pipeline strings I have a table. It contains 2 columns (id,value). Value columns holds date and status.(a:active,s:suspend,d:deactive)
id | value
1  | 220325a|220608s
2  | 220325a|220325d|220822a|220822d
3  | 220325a
4  | 220325a|220329d

What i want to do is to parse value columns like that
My new table :

 id | start_date | end_date
 1  | 25.03.2022 | 08.06.2022
 2  | 25.03.2022 | 25.03.2022
 2  | 22.08.2022 | 22.08.2022
 3  | 25.03.2022
 4  | 25.03.2022 | 29.03.2022

I think I have to use nested loop but how do i find dates one by one?

A: You can use a recursive query and simple string functions:
WITH bounds (id, value, spos, mpos, epos) AS (
  SELECT id,
         value,
         1,
         INSTR(value, '|', 1, 1),
         INSTR(value, '|', 1, 2)
  FROM   table_name
UNION ALL
  SELECT id,
         value,
         epos + 1,
         INSTR(value, '|', epos + 1, 1),
         INSTR(value, '|', epos + 1, 2)
  FROM   bounds
  WHERE  epos > 0
)
SEARCH DEPTH FIRST BY id SET order_id
SELECT id,
       TO_DATE(SUBSTR(value, spos, 6), 'RRMMDD') AS start_date,
       CASE
       WHEN mpos = 0
       THEN NULL
       ELSE TO_DATE(SUBSTR(value, mpos + 1, 6), 'RRMMDD')
       END AS end_date,
       SUBSTR(value, spos + 6, 1) AS start_status,
       CASE
       WHEN mpos = 0
       THEN NULL
       ELSE SUBSTR(value, mpos + 7, 1)
       END AS end_status
FROM   bounds;

Which, for the sample data:
CREATE TABLE table_name (id, value) AS
SELECT 1, '220325a|220608s' FROM DUAL UNION ALL
SELECT 2, '220325a|220325d|220822a|220822d' FROM DUAL UNION ALL
SELECT 3, '220325a' FROM DUAL UNION ALL
SELECT 4, '220325a|220329d' FROM DUAL;

Outputs:

ID
START_DATE
END_DATE
START_STATUS
END_STATUS

1
2022-03-25 00:00:00
2022-06-08 00:00:00
a
s

2
2022-03-25 00:00:00
2022-03-25 00:00:00
a
d

2
2022-08-22 00:00:00
2022-08-22 00:00:00
a
d

3
2022-03-25 00:00:00
null
a
null

4
2022-03-25 00:00:00
2022-03-29 00:00:00
a
d

fiddle


text:
Q: How to analyze my Likert-scale data I am collecting data from a group of about 189 police officers on a 5-point Likert-Scale (measuring how much the police officers accept rape myths).  I have no idea which tests to use to analyse my data.  In the end I want to divide the group into male officers versus female officers and compare their acceptance of rape myths to determine if there is a difference between the two groups.  I will also gather other geographical data (e.g. years of service), but I have no idea how that can be valuable.

A: It depends on whether you have a single Likert scale question(which, given your research question, seems unlikely) or multiple scales. If the latter, you then have to decide how you want to combine them.
Although, technically, adding Likert scale questions is invalid (because adding numbers assumes they are at least interval scaled) people do it all the time. It is also possible to do factor analysis of Likert scale items, although some care must be taken. See e.g Joreskog and Sorbom

A: Other than the likert question, If you have all your variables as categorical e.g. Region(East, West, North, South), Education(Some College, College Degree, Masters Degree, Phd) and so on, you can use MANOVA technique.
"Rape as a myth" as dependent variable. Gender(Male/Female) as fixed factor
Looking at your question, you have "Age" as a continuous variable. you can actually segment age into diffeent defined groups to make it categorical variable and make it useful for MOANOVA. For example you can have age categories as "18 to 25", "26 to 30", "30 to 35" and so on. So now if a respondent stated their age as 23, it will fall under "18 to 25".
This is an youtube SPSS tutorial on how to do MANOVA and how to interpret the output


text:
Q: Is it possible to connect to multiple masstransit queues directly from startup? services.AddMassTransit(config =>
        {
            config.AddConsumer<Consumer1>();
            config.UsingRabbitMq((ctx, cfg) => {
                cfg.Host("amqp://guest:guest@localhost:5672");

                cfg.ReceiveEndpoint("firstqueue", c => {
                    c.ConfigureConsumer<Consumer1>(ctx);
                });

            });

I need to take some requests from one queue and then publish them to another queue. This is how I connect to one of them, I tried to add it directly but I wasn't succesful since i can't have 3 arguments

A: You don't need to connect to any queue when publishing messages. You just publish to an address as described in the docs using the IPublishEndpoint. You do not publish to a queue, that's why it's called publish. If you need to Send, you use the ISendEndpoint instance. The Send method needs an address.
You connect to a queue (and exchange) only when you need to consume messages.
With MassTransit, it is recommended to use the ConsumeContext if you send or publish inside a consumer. You can use context.Publish and context.GetSendEndpoint.


text:
Q: Backbone subview containing view template Our project uses Backbone and Chaplin, and it contains a bunch of components with models, views and sometimes multiple templates for each component depending of the case. We are refactoring the most basic ones into smaller components that provide event handling and a basic template, and for modals this would be a general dialog without any content inside it.
This basic version should be called into the modal view as a subview, and then one of the possible modal templates should be rendered inside the basic template. Currently all of the modal templates share this basic structure:

      ...

      ...

      ...

As every modal template shares the same basic structure, that is .modal > .modal-container > .modal-content, I want to split it up like this:
modalContainer

modalTemplates

    ...

    ...

    ...

The main idea is that the modal templates are inserted inside the modalContainer template, and the container must be a subview of the modal view. Which would be the best way to implement this taking into account performance?


text:
Q: Maven properties set by plugins are 'too late' for the reactor build plan I'm in the process of migrating some Maven projects from Perforce to git. With Perforce, these projects were configured with a build.number Maven property, that was passed in as a JVM arg as part of the build process. With git, I'm exploring the jgit-buildnumber plugin that sets properties based on git repo metadata.
The plugin works wonderfully, but even if I run it early in the Maven lifecycle (validate or initialize), this happens after the Reactor build plan is generated. This is a problem because the projects use exec-maven-plugin and maven-antrun-plugin. The build plans for these plugins seem to take a snapshot of all Maven properties at time of plan construction, e.g. a snippet from the Reactor build plan's debug output for one of these plugins:
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal:          org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (RPMbuilderScript)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <basedir default-value="${basedir}"/>
  <classpathScope default-value="runtime">${exec.classpathScope}</classpathScope>
  <commandlineArgs>product=jas_etl
                        dir=/Users/dev/project
                        team=sanctuary
                        version=${git.buildnumber}
                        artifact=/Users/dev/project/target/project-${git.buildnumber}.zip
                        </commandlineArgs>
  <executable>../parent/devops_scripts/mavenRpmBuilder.sh</executable>
  <longClasspath default-value="false">${exec.longClasspath}</longClasspath>
  <outputFile>${exec.outputFile}</outputFile>
  <project default-value="${project}"/>
  <session default-value="${session}"/>
  <skip default-value="false">true</skip>
  <sourceRoot>${sourceRoot}</sourceRoot>
  <testSourceRoot>${testSourceRoot}</testSourceRoot>
  <workingDirectory>${exec.workingdir}</workingDirectory>
</configuration>

git.buildnumber is set as part of the initialize phase by the jgit-buildnumber plugin, but it's done too late to affect the reference in the exec plugin's build plan.
Is there a way to run the jgit-buildnumber plugin ahead of the generation of the build plan? Alternatively, is there a way to configure the Ant and exec plugins to read property values only at the start of the phase they execute in, rather than at time of build plan generation?


text:
Q: Why does running gclient produce update errors? I cloned depot_tools according to http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up.
Then when I run "gclient" I get this error:
depot_tools update failed. Conflict in /usr/v8-7.7/depot_tools
fatal: Unable to create '/usr/v8-7.7/depot_tools/.git/index.lock': Permission denied
Errors:
  failed to resolve infra/3pp/tools/git/linux-ppc64le@version:2.24.1.chromium.5 (line 27): no such package
  failed to resolve infra/3pp/tools/cpython/linux-ppc64le@version:2.7.17.chromium.22 (line 21): no such package
/usr/v8-7.7/depot_tools/bootstrap_python3: line 32: bootstrap-3.8.0.chromium.8_bin/python3/bin/python3: No such file or directory
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Usage: gclient.py <command> [options]

Meta checkout dependency manager for Git.

I'm running on a ppc64le linux machine set with RHEL 8. I have the goal of trying to install v8 on the machine but first gclient needs to work.
I do have python 2.7.15 installed on the machine.

A: I had the same error when python3 was my default python.
gclient is likely running under python3 and not python2, which causes these errors
You can use pyenv to manage multiple parallel installations of python.

A: It was a permissions issue. I just had to adjust the permissions of the folder I was in.


text:
Q: How do I count the number of times a character "x" is reported in column "ID", and report a weight measure for each row? > head(mini)
   ID        sequence class
1:   3930271        0  A63B
2:   3930272        0  A47D
3:   3930272        1  Y10T
4:   3930273        0  A61G
5:   3930273        1  A61G
6:   3930274        0  B63B

I would like to compute the weight of each class to the respective ID. Therefore, I'd need a count of the number of classes per ID and then assign a simple value weight to each class. For example, ID 3930272 has two classes and I would like to have a new column that reports 0.5 as the class weight on ID.
Visualization here below:
   ID        sequence class  weight
1:   3930271        0  A63B       1
2:   3930272        0  A47D     0.5
3:   3930272        1  Y10T     0.5
4:   3930273        0  A61G     0.5
5:   3930273        1  A61G     0.5
6:   3930274        0  B63B       1

Please note that ID 3930273 has two identical classes, but I still want to see a weight of 0.5 for that class. Thank you!

A: With dplyr you'd group by ID and then calculate the weight by dividing 1 by the number of rows of that ID:
library(dplyr)
mini = mini %>%
  group_by(ID) %>%
  mutate(weight = 1/n()) %>%
  ungroup()

A: Since you're using data.table, here's a quick one-liner:
mini[, weight := 1/.N, by = "ID"]
mini
#         ID sequence class weight
# 1: 3930271        0  A63B    1.0
# 2: 3930272        0  A47D    0.5
# 3: 3930272        1  Y10T    0.5
# 4: 3930273        0  A61G    0.5
# 5: 3930273        1  A61G    0.5
# 6: 3930274        0  B63B    1.0

Data:
mini <- read.table(header=T, stringsAsFactors=F, text='
   ID        sequence class
1:   3930271        0  A63B
2:   3930272        0  A47D
3:   3930272        1  Y10T
4:   3930273        0  A61G
5:   3930273        1  A61G
6:   3930274        0  B63B   ')
data.table::setDT(mini)