Setup of HP ProCurve 2810-24G for iSCSI?

Question: I have a pair of ProCurve 2810-24G that I will use with a Dell Equallogic SAN and Vmware ESXi.
Since ESXi does MPIO, I am a little uncertain on the configuration for links between the switches. Is a trunk the right way to go between the switches?
I know that the ports for the SAN and the ESXi hosts should be untagged, so does that mean that I want tagged VLAN on the trunk ports?
This is more or less the configuration:
trunk 1-4 Trk1 Trunk
snmp-server community "public" Unrestricted
vlan 1
    name "DEFAULT_VLAN"
    untagged 24,Trk1
    ip address 10.180.3.1 255.255.255.0
    no untagged 5-23
exit
vlan 801
    name "Storage"
    untagged 5-23
    tagged Trk1
    jumbo
exit
no fault-finder broadcast-storm
stack commander "sanstack"
spanning-tree
spanning-tree Trk1 priority 4
spanning-tree force-version RSTP-operation

The Equallogic PS4000 SAN has two controllers, with two network interfaces each. Dell recommends each controller to be connected to each of the switches.
From vmware documentation, it seems creating one vmkernel per pNIC is recommended. With MPIO, this could allow for more than 1 Gbps throughput.
Answer: There has been some debate in the comments to Chopper3's answer that is not well informed because of some poorly understood aspects of Equallogic's networking requirements and multipathing behaviour.
First the VMware side:
For starters on the ESXi side the current recommendation, when using the iSCSI Software Initiator, from VMware (for ESX\ESXi 4.1) and Dell is that you should have a single physical Nic mapped to each VMkernel Port that will be used for iSCSI. The binding process that is now recommended enforces this. It requires that you have only one active physical nic and no standby nics for each VMkernel port. No bonding allowed. Now you can cheat this and go back afterwards and add a failover nic but the intention is that MPIO will handle the failover so this serves no useful purpose (at least when everything is working as intended by VMware).
The default multipathing policy will allow active, active connections to an Equallogic array using round robin.
Second the Equallogic side:
Equallogic arrays have dual controllers that act in an active\standby mode. For the PS4000 these have two Gigabit Nics on each controller. For the active controller both of these nics are active and can receive IO from the same source. The network configuration recommends that the array's nics should be connected to separate switches. From the server side you have multiple links that should also be distributed to separate switches. Now for the odd part - Equallogic arrays expect that all initiator ports can see all active ports on the arrays. This is one of the reasons you need a trunk between the two switches.  That means that with a host with two VMkernel iSCSI ports and a single PS4000 there are 4 active paths between the initator and the target - two are "direct" and two traverse the ISL.
For the standby controller's connections the same rules apply but these nics will only become active after a controller failover and the same principles apply. After failover in this environment there will still be four active paths.
Third for more advanced multipathing:
Equallogic now have a Multipath Extension Module that plugs into the VMware Plugable Storage Architecture that provides intelligent load balancing (using Least queue depth, Round Robin or MRU) across VMkernel ports. This will not work if all vmkernel uplink nics are not able to connect to all active Equallogic ports. This also ensures that the number of paths actually used remains reasonable - in large Equallogic environments the number of valid paths between a host and an Equallogic Group can be very high because all target nics are active, and all source nics can see all target nics.
Fourth for larger Equallogic Environments:
As you scale up an Equallogic environment you add additional arrays into a shared group. All active ports on all member arrays in a group must be able to see all other active ports on all other arrays in the same group. This is a further reason why you need fat pipes providing inter switch connectiongs between all switches in your Equallogic iSCSI fabric. This scaling also dramatically increases the number of valid active paths between initiators and targets. With an Equallogic Group consisting of 3 PS6000 arrays (four nics per controller vs 2 for the PS4000), and an ESX host with two vmkernel ports, there will be 24 possible active paths for the MPIO stack to choose from.
Fifth Bonding\link aggregation and Inter Switch links in an Equallogic Environment:
All of the inter array and initator<->array connections are single point to point Gigabit connections (or 10Gig if you have a 10Gig array). There is no need for, and no benefit to be gained from, bonding on the ESX server side and you cannot bond the ports on the Equallogic arrays. The only area where link aggregation\bonding\whatever-you-want-to-call it is relevant in an Equallogic switched ethernet fabric is on the interswitch links. Those links need to able to carry concurrent streams that can equal the total number of active Equallogic ports in your environment - you may need a lot of aggregate bandwidth there even if each point to point link between array ports and iniatator ports is limited to 1gbps.
Finally:
In an Equallogic environment traffic from a host (initiator) to an array can and will traverse the interswitch link. Whether a particular path does so depends on the source and destination ip-address for that particular path but each source port can connect to each target port and at least one of those paths will require traversing the ISL. In smaller environments (like this one) all of those paths will be used and active. In larger environments only a subset of possible paths are used but the same distribution will happen. The aggregate iSCSI bandwidth available to a host (if properly configured) is the sum of all of its iSCSI vmkernel port bandwidth, even if you are connecting to a single array and a single volume. How efficient that may be is another issue and this answer is already far too long.
Comment: You need to follow this advice! I work for the largest EQL reseller in the midwest, I put in these systems daily. Tagging/trunks is the way to go and let the MEM plugin create you vswitches for you. Your ISL should be as large as you can afford it to be connection wise. We typically use stackable switches. Juniper EX4200's are AWESOME for iSCSI.
Comment: Wow, awesome answer. Didnt see this message until just now, but I did manage to get it all up and working as expected, and iometer results shows it performs as good as it gets. Still have to check all redundancy. Thanks a lot for your extremely informative answer!
Answer: Since ESXi does MPIO, I am a little uncertain on the configuration for links between the switches. Is a trunk the right way to go between the switches?

ESX/i does its own path management - it won't go active/active on its links unless two or more of its links are either going to the same switch or the switches are in a CAM-sharing mode such as Cisco's VSS - anything else will be an active/passive configuration.
By all means trunk between switches if you want but presumably they both have uplinks to some core switch or router? if so then I'm not entirely sure why you'd trunk between just two switches in this manner as the ESX/i boxes will just switch to the second switch if the first one goes down (if configured correctly anyway).
I know that the ports for the SAN and the ESXi hosts should be untagged, so does that mean that I want tagged VLAN on the trunk ports?

I don't know where this assumption comes from, ESX/i is just as comfortable working in a tagged or untagged setup, whether for guest or iSCSI traffic. That said I have had problems with mixing tagged and untagged when using default vlans so I always tag everything now and have no default vlan, it's a very flexible setup and has no discernible performance hit in my experience.
Comment: The reasoning for using tagged ports is if you need to carry more than one VLAN down it. Tagging the VLANs gives you the ability to distinguish between them. You also don't need to use LACP to create a link aggregation (trunk for HP, Etherchannel for Cisco) bundle. You can set a static aggregation group and benefit from the switch side balancing and fail over. That said, it's also common to leave the switch side alone and let ESX handle the traffic decision making.
Comment: The LAG works as expected. I have two 1 Gbit links and the EQ is connected to one switch each. I get up to 235 MB/s sequential reads and writes. Either we didnt understand each other at all, or I was correct in my statements about the setup. Btw, its round-robin but it states active/active.
Comment: I'm pretty sure the ESXi documentation for SAN storage states that one should not bond nics, but instead rely on MPIO both for increased performance and benefits of redundancy (no matter if links go to the same switch or not). Of course there will be no uplinks to core switches, this is a pair of switches for storage only. I also state that I intend to use untagged vlans to hosts and SAN, so that still makes my question valid; should I or should I not use TAGGED in the trunk links?
Comment: mcmeel, please consider writing a real answer. Its easier to comment. Not sure how the inter-switch configuration would be, if I would let ESXi do the decision making?
Comment: -1 chopper, I feel you either don't know enough about the subject or you didn't quite read my question.
Comment: I'm sorry 3molo but you're wrong - you also seem confused by how 'bonding' and 'MPIO' are related. We have over 8,000 ESXi 4.1 hosts, I'm a VCP and VCAP trained and bonding of NICs is not only supported but significantly encouraged with bonding able to play an important role in an MPIO configuration. As for "of course there will be no uplinks" how is this apparent from your question? Even without uplinks I don't see how an cross-switch trunk would help unless you only connect the Equalogic box into a single switch? mcmeel is also a) correct and b) trying to help you here - don't be so abusive.
Comment: I think it's apparent from my configuration. The EQ will be connected to both switches, each controller to both even. The ESXi hosts will use two pNICs for storage, one connected to each switch. Is bonding still valid in this scenario?
Comment: Will a pair of aggregated links on my procurves not help me at all? From EQ PS4000 manual: "For Maximum network bandwidth and availability. Dell recommends that you use four network cables to connect Ethernet 0 and Ethernet 1 on each control module to a different network switch. The switches must be connected with interswitch links that have sufficient bandwidth.". The picture shows two links between the switches.
Comment: You're wrong, nothing in your question implies that, and needlessly rude. As for the cabling scenario you finally grace us with, no bonding won't help in this situation as your switches don't support VSS/VSL or similar modes - you're stuck with only 1Gbps of throughput per server.
Comment: Aggregated links could help you, if you wired it that way - you'd need two or more links from one server to one switch, not the way you describe above. So for a bonded 2 x 1Gbps link with resilience you'd need 4 NICs, two going to each switch.
As for me "not knowing enough about the subject" or not "quite reading your question", I don't know why I'm trying to help - you're the one who doesn't know how to do this or how to write clear questions - you're not exactly helping yourself here.
Comment: Im sorry. I didnt mean to sound rude, and I am greatful for any help. Updated the question with a crude sketch. I realize that you know what you are talking about. Would I not benefit at all performance wize, if having one vmkernel per pNIC connected to one switch each? Th vmware documentation states that one session per pNIC will be established to the SAN. Seems to me that would allow me to utilize more than 1 Gbps? Would the link aggregation in this case not help me at all?
Comment: The scenario you're outlining is not link aggregation and has nothing to do with ethernet, it solely relies on ESXi doing the load-balancing across two independent vmkernel-configured vSwitches. I don't believe their is a policy to allow for this, it would mean the same LUN being opened by two vmkernels on the same host - I'm actually 'lab'ing this right now and will let you know my findings later.
Comment: Okey chopper, you don't need to do that. It's more likely that I missunderstood it and I am only able to utilize 1 Gbps. How is it not link aggregation between the switches btw?
Comment: Right, in my lab, admitted only using the software iscsi initator I can't get the build in multi-pathing of ESXi 4.1u1 to go over two adapters in an active/active manner - round-robin yes but not active-active. This may be different with hardware iscsi but I don't have the time right now to try that sorry.
Comment: Link aggregation required two or more ports to go to either the exact same switch or to a pair of switches that support VSS/VSL - the reason being that L2 expects a single switch to 'own' a given MAC, aggregation creates a trunk with a single MAC, so that's easy for a single switch to say "these two are actually that MAC" but try doing that across two regular switches - doesn't work, so you need switches that can work as a pair such as Cisco Cat 65xx VSS models. Really not sure what the cross-switch trunk is for you know, no idea at all.
Answer: It's the SAN array controller that defines how you should connect this. Is it providing the same LUN on both ports on the same controller? Then port0 goes to switchA, port1 to switchB and same with the next controller.
Why would you want to use LACP/etherchannel against a iSCSI SAN with 1gbit uplink ports? It doesnt help you in any way. Create 2 vswitches with a single pNic in each vSwitch, and connect the first pNic to switchA, second pNic to switchB. This will give you full redundancy against controller/switch/nic failures.
Comment: Each initiator contacts the groups IP, which redirects to the IP of one of the NICs in the group. There is nothing stopping an initiator on Switch A connecting to the array on it's NIC connected to Switch B.  Based on the number of connections, a 4GB LACP link between switches should be sufficient to avoid any troubles. I personally prefer to connect all the ports on a controller to one switch. When you split them, you halve your bandwidth at the array in a failure situation.
Comment: The etherchannel/LACP is inter switches only, but that doesnt help me at all? I imagined that connections could traverse between the switches because of MPIO, in case say a port on the switch where one of the controller is connected to.
Comment: Why would connections traverse between the switches? It makes no sense.
Comment: Great answer SpacemanSpiff, I went with 2 LACP links.


Range with alphabets Python

Question: Suppose I have a list like this string = ['A1', 'A5'], I want to create a new list which should start from A1 and end at A5.
E.g ['A1','A5'] -> ['A1','A2','A3','A4','A5']
Similarly for this case ['A1', 'C1'] -> ['A1','B1','C1'].
My approach was to create a LinkedList node for A1 and then increment the integer constant with every new creation of node and then append them together.
How can this be done?
Comment: What is the sequence between e.g. `'A1'` and `'C3'`? `A1,A2,A3,B3,C3`, `A1,B1,C1,C2,C3`, `A1,A2,A3,B1,B2,B3,C1,C2,C3`? If you know the pattern than you can just use e.g. `map('A{}'.format, range(1, 3+1))`.
Comment: The sequence are only row-wise or column-wise as in excel.
Answer: You cloud us an simple generator called customRange():
def customRange(lst):
    if lst[0][0] != lst[1][0]:
        for c in range(ord(lst[0][0]), ord(lst[1][0])+1):
            yield chr(c) + lst[0][1]
    else:
        for n in range(int(lst[0][1]), int(lst[1][1])):
            yield lst[0][0] + str(n)

Usage:
for value in customRange(['A1', 'A5']):
    print(value)

A1
A2
A3
A4

or
for value in customRange(['A1', 'D1']):
    print(value)

A1
B1
C1
D1

Answer: Answer for the first case
This works well for your given pattern but not for changes like "a" instead of "A" I leave that to you
string = ['A1', 'A5']
if string[0][0]==string[1][0]:
    string=[string[0][0]+str(d) for d in range(int(string[0][1]),int(string[len(string)-1][1]))]
else:
    string=[chr(d)+string[0][1] for d in range(ord(string[0][0]),ord(string[len(string)-1][0])+1)]

In the else part you can try the second case :
Answer: Extract the characters and digits from the substrings:
ch = "".join(c for c in l[0] if c.isalpha())

start, end = int("".join(c for c in l[0] if c.isdigit())), int("".join(c for c in l[-1] if c.isdigit()))
print(["{}{}".format(ch,i) for i in range(int(start),int(end)+1)])
['A1', 'A2', 'A3', 'A4', 'A5']

If the range always starts at 1 you don't need to extract the start.
Comment: Please put `start =` and `end = ` in two lines. The scollbar hurts the readability

Range with alphabets Python


WebApi DateTime formatting

Question: My understanding is that WebApi V2+ uses JSON.Net formatter that uses IsoDateFormatter by default. But it does not seem to be working as expected. Here is example of HTTP GET that I tried.
http://www.mydomain.com/api/ServerTime?RequestTime="2014-07-17T15:20:09.747Z"
RequestTime parameter is populated by getting UTC time on client. When request gets to server side, RequestTime gets deserialized into DateTime.Min value i.e. 01/01/0001 .....
This is not what I was expecting.
I am aware of adding custom DateTime formatter in configuration to probably get around this. That would be my last option if WebApi is supposed to support ISO dates.
Thanks
Comment: Remove the double quotes?
Answer: JSON.NET is used for binding the body and that's where media formatters come into play. For a query string like yours, binding is same as MVC model binding and JSON.NET is not used.
Comment: Perfect. I changed the signature to form the request data object using [FromBody]. Now everything is happy.

WebApi DateTime formatting


Unable to show and hide div in an each loop

Question: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

        <title></title>

Where is everyone?

there

Where is the closest Starbucks

there

Where are my glasses?

there

After clicking the question I want the ability to show and hide the repesctive answer. If possible, close other answers that are open.
Im stuck at this point, and don't know what to do.
Answer:   $(document).ready(function() {
    $('.a_faq .question').click(function() {
      $(this).parent().find('.answer').toggle();
    });
  });

That's your click handler and all. No need for a loop.
Comment: Also, you don't need a `style="display:none;"` for every answer. Just add it to your `answer` class in css.
Answer: This will do what you want and also hide the other answers:
$('.question').click(function() {
  var $answer = $(this).parent().find('.answer');
  if(!$answer.is(":visible"))
     $(".answer").hide();  //Hides the rest of the answers
  $answer.toggle();
});

Hope this helps. Cheers


Dynamics CRM 2011 On-Premise & Security Certifications (ISO 27001, SAS70, etc)

Question: I'm unclear on how to properly word our security status. The data center our hosted IFD CRM instance is running on has not paid for these audits. However, the Microsoft literature suggests that CRM Online (which is hosted on MS servers) has these certifications and the certifications are growing with each service update.
If our CRM on-premise software is up-to-date, is it safe to say that the CRM on-premise software itself meets the standards outlined in here, but the data center has not been "certified" by an auditor?

ISO 27001
SAS70 Type II
Sarbanes–Oxley
Microsoft Dynamics CRM Online Service Safe Harbor
ISO 27001
SSAE 16 SOC1 (Type II)
Data Processing Agreement (DPA)
EU Model Clauses
Business Associates Agreement - enables a company to be  Health Insurance Portability and Accountability Act (HIPAA) compliant
Answer: This is a tricky question that's not always taken for granted by many vendors (sometimes at their own peril).
Many of the audits listed are validation against management practices and controls.  Specifically, ISO 27001, SAS70/SSAE16, SOX 404, and HIPAA are more controls based than technology based (i.e. FIPS 140-2, CC EAL, ICSA Labs product certifications).  Fundamentally, when you take a piece of software and move it to another environment, you'd have to have the entire environment re-audited to be able to assert that you have controls in place and that you practice management according to acceptable practices.
With that said, I'd suggest you consult with an attorney/accredited auditor to determine what claim you can make relative to the standards.  I say "accredited auditor" because many of the compliance programs require auditors maintain specific qualifications (i.e. ISO auditors have to be "Accredited Registrars," SOX auditors are often accounting firms).


Implementing NSCoding for NSKeyedArchiver and memory leaks

Question: I have a custom object that I am using NSKeyedArchiver to convert to NSData so my custom object implements the NSCoding protocol. But when I run the Instruments tool, it tells me that my initWithCoder method has a number of leaked NSCFString objects inside initWithCoder.
What is the correct way to implement the NSCoding protocol?
My class:
<code>@interface EventProfile : NSObject <NSCoding>
    NSString *eventTitle;
    NSString *groupName;
@end
@implementation EventProfile

// NSCoding methods
-(id) initWithCoder:(NSCoder *)decoder
{
    if (self = [super init])
    {
        eventTitle = [[decoder decodeObjectForKey:@"eventTitle"] retain];
        groupName = [[decoder decodeObjectForKey:@"groupName"] retain];
    }

    return self;
}
-(void) encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.eventTitle forKey:@"eventTitle"];
    [encoder encodeObject:self.groupName forKey:@"groupName"];
}
// Memory management
- (void)dealloc
{
    [eventTitle release];
    [groupName release];

    [super dealloc];
}

@end
</code>
Comment: What are the definitions of the `eventTitle` and `groupName` properties? If they are `copy`, things look Ok to me. But if they are accidentally `assign` you might have a problem there. Could you also test run the code with `self.eventTitle` and `self.groupName` in the `initWithCoder:` method? Apart from that it might be that the leak is at the place that uses the `EventTitle` class at a different place.
Comment: Yes your interface shows no property definitions but you are using `self.eventTitle` and `self.groupName` inside `encodeWithCoder:` ??
Answer: To implement encodeWithCoder: you should go through all of the essential properties of your object and use the various methods on NSCoder to encode them. For object properties, just use encodeObject:forKey:. The key can just be a short string that describes the property being encoded:
<code>class Book: NSObject, NSCoding {
var title: String
var author: String
var pageCount: Int
var categories: [String]
var available: Bool

// Memberwise initializer
init(title: String, author: String, pageCount: Int, categories: [String], available: Bool) {
    self.title = title
    self.author = author
    self.pageCount = pageCount
    self.categories = categories
    self.available = available
}

// MARK: NSCoding

required convenience init?(coder decoder: NSCoder) {
    guard let title = decoder.decodeObjectForKey("title") as? String,
        let author = decoder.decodeObjectForKey("author") as? String,
        let categories = decoder.decodeObjectForKey("categories") as? [String]
        else { return nil }

    self.init(
        title: title,
        author: author,
        pageCount: decoder.decodeIntegerForKey("pageCount"),
        categories: categories,
        available: decoder.decodeBoolForKey("available")
    )
}

func encodeWithCoder(coder: NSCoder) {
    coder.encodeObject(self.title, forKey: "title")
    coder.encodeObject(self.author, forKey: "author")
    coder.encodeInt(Int32(self.pageCount), forKey: "pageCount")
    coder.encodeObject(self.categories, forKey: "categories")
    coder.encodeBool(self.available, forKey: "available")
}
</code>
}
As you can see, NSCoding is mostly boilerplate. Each property is encoded or decoded as an object or type, using the name of the property of as the key each time. (Some developers prefer to define NSString * constants for each keypath, but this is usually unnecessary).


Real non-trivial zeros of Riemann zeta function inside critical strip

Question: Could someone please tell me what is known about the real non-trivial zeros of Riemann zeta function inside critical strip? Do we know there is none?
I want to know what is known about the above questions without the assumption of Riemann hypothesis.
Any hint or help would be appreciated. Thanks in advance.
Comment: Yes, we do know that there are no nontrivial zeros on the real line. You might want to see https://arxiv.org/abs/2004.09765 which shows that there is no nontrivial zeros $s=\sigma+it$ off of the critical line for $\vert t\vert\leq 3\times 10^{12}$
Comment: Perhaps, there should also be a more general comment here that for a general Dirichlet $L$ series $L(s,\chi)$ where $\chi$ is a Dirichlet character, the question of a real zero (known as a Siegel zero) is a difficult unresolved problem.
Comment: So, we know that $L(s,\chi)$ has no Siegel/exceptional zero, when $\chi=\chi_{0}$, right?But we don't know answer to this question for a character $\chi\neq \chi_{0}$.
Comment: Assuming that by $\chi_0$ you mean the trivial Dirichlet character then you are correct; however, for other characters we do know some things. For example for $\chi$ is a complex character (that is it takes values outside of $\mathbb{R}$, then there will not be any Siegel zeros. But if $\chi$ is real (say a quadratic character), then the existence of Siegel zeros is still open. But one could then talk about general $L$-series attached to other objects such as autommorphic forms
Comment: Got it. Thanks.
Answer: There are no real nontrivial zeroes of $\zeta(s)$ in $(0,1)$.
This can be easily shown as follows. Let $\eta(s)=\sum_{n=1}^\infty(-1)^n/n^s$, which converges in $\mathop{\rm Re}s>0$. When $\mathop{\rm Re}s>1$, we have that
$$\eta(s)=\sum_{n=1}^\infty\frac1{n^s}-2\sum_{n=1}^\infty\frac1{(2n)^s}=\left(1-\frac1{2^{1-s}}\right)\zeta(s).$$
Since $\eta(s)$ is holomorphic on $\mathop{\rm Re}s>0$, by analytic continuation this equality holds on $\mathop{\rm Re}s>0$ as well. Now, when $s$ is real and $0<s<1$, $\eta(s)=\sum_{n=0}^\infty1/(2n+1)^s-1/(2n+2)^s$ and each term is positive, so $\eta(s)>0$, in particular $\eta(s)\ne0$, thus $\zeta(s)$ cannot vanish.


Problem when deploying PF 11 app with CDI (weld) on Tomee Plume 8.0.9

Question: I'm trying to migrate a PF6 app to PF11, and, after deploying it on tomee 8.0.9, I've got the following error:
<code>            Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
                at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
                ... 37 more
        Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type GeronimoOpenAPIExtension with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private org.apache.geronimo.microprofile.openapi.jaxrs.OpenAPIFilter.extension
  at org.apache.geronimo.microprofile.openapi.jaxrs.OpenAPIFilter.extension(OpenAPIFilter.java:0)
  Possible dependencies:
  - Extension [class org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension] with qualifiers [@Default]; jar:file:/home/chiritda/Software/ntv_3.0/apache-tomee-plume-8.0.9/lib/geronimo-openapi-impl-1.0.12.jar!/META-INF/services/javax.enterprise.inject.spi.Extension@1[org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension@10c433f7],
  - Extension [class org.apache.tomee.microprofile.config.TomEEOpenAPIExtension] with qualifiers [@Default]; jar:file:/home/chiritda/Software/ntv_3.0/apache-tomee-plume-8.0.9/lib/mp-common-8.0.9.jar!/META-INF/services/javax.enterprise.inject.spi.Extension@17[org.apache.tomee.microprofile.config.TomEEOpenAPIExtension@a21441e]

                at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:386)
                at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
                at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
                at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
                at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
                at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
                at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
                at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
                at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
                at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
                at java.base/java.lang.Thread.run(Thread.java:833)
</code>
Both Geronimo and TomeeOpenApi extensions are present in the tomee's lib directory.
I'm using a standalone tomee plume server, java 17.0.1, PF11, WELD 3.1.4.
Any ideas would be appreciated.
Thanks!
Comment: You should not be using Weld as TomEE includes OpenWebBeans. You now have two implementations of the same thing and likely that is causing strange issues.
Comment: Yes, I've figured that out, I've removed weld and it seems to be working. Thanks!
Answer: Moving this to an answer :)
You should not be using Weld as TomEE includes OpenWebBeans. You now have two implementations of the same thing (CDI) and likely that is causing strange issues.


Mann-Whitney test W statistics

Question: Below is Mann-Whitney test result from Minitab. At the end of result, there is no p-value but "Cannot reject since W is < 363.0". What does it mean? I cannot reject H0? But the median looks significantly different here.
========================================================================
Mann-Whitney Test and CI: 20_C_or_Better_Grade_2013, 2124_C_or_Better_Grade_201

                              N  Median
20_C_or_Better_Grade_2013    22   5.500
2124_C_or_Better_Grade_2013  10  10.500

Point estimate for ETA1-ETA2 is -5.000
95.1 Percent CI for ETA1-ETA2 is (-9.000,-0.001)
W = 315.5
Test of ETA1 = ETA2 vs ETA1 > ETA2

Cannot reject since W is < 363.0

Answer: The Mann-Whitney U-test isn't actually a test of the median, although that is often the way it is explained.  (If you literally wanted a test of the equality of the median, you could do that by bootstrapping or using a permutation test.)
In truth, MW is a test for stochastic dominance.  That is, it is a test of whether, if you drew one value at random from each group, is the value from one group typically higher than the value from the other?  If the shapes of the distributions for the two groups differ, it is quite possible that the medians could differ without one stochastically dominating the other significantly, and it is very possible for one to significantly stochastically dominate the other even if the medians are identical.

I have never used Minitab, but it appears to me that you may have run a one-tailed test and selected the wrong tail by mistake.  I notice the output says:
...
... ETA1-ETA2 is -5.000
...
Test of ETA1 = ETA2 vs ETA1 > ETA2
...

If you tested Test of ETA1 = ETA2 vs ETA1 < ETA2 instead, you might get a significant result.
Comment: @Glen_b; for information, Minitab seems to make those assumptions. Its help text says "An assumption for the Mann-Whitney test is that the data are independent random samples from two populations that have the same shape and a scale that is continuous or ordinal (possesses natural ordering) if discrete."
Comment: Nice answer; you can also use a M-W to test for differences in the median if you add sufficient assumptions to make it one (e.g. assuming that the distributions will be identical under the null and that the medians will differ under the alternative, which - while it narrows the scope of what a M-W can test - is usually the kind of assumption people have in mind, at least implicitly, when they use it). I agree, it looks like a one-tailed test was probably done; it's a pity that sufficient information was not supplied to be sure

Mann-Whitney test W statistics


É mais rapido delete + insert ou select + update

Question: Estou construindo um aplicativo que irá receber dados de diversos ERP's diferentes todos os dias.
Mas estou com o seguinte problema, no dia seguinte o ERP pode me mandar os mesmos dados que tiveram ou não alterações + alguns dados novos.
E eu preciso inserir estes novos dados e atualizar os demais caso haja alguma mudança, e excluir os dados antigos que não serão mais utilizados.
São cerca de 15 mil registros por dia de cada empresa, e pretendo que este aplicativo seja usado por +- umas 200 empresas em media.
Pensando nisso, quando receber essas informações diariamente é melhor eu ir verificando uma a uma para ver se teve alguma alteração e caso sim atualiza-las( select + update ).
Ou todo dia eu deleto todas as informações e insiro novamente ( delete + insert ).
Qual a maneira mais rapida de tratar grandes informações todos os dias?
Caso alguém tenha alguma experiencia semelhante e saiba de uma solução diferente, também estou interessado.
Obrigado!
Comment: Acho que o mais adequado é implementar as duas alternativas e testar o desempenho. Pode ser que uma solução seja mais adequada em uma situação mas não em outra.
Comment: Estes +- 15mil registros são todos recebidos em um determinado momento ou isso ocorrerá ao longo do dia? Durante a atualização o sistema ficará acessível? A atualização poderá ser realizada fora do horário de expediente? Na minha vivência os 15mil registros não são um problema a ser considerado, mas o tamanho da base de dados que você atualizará e sua expectativa de crescimento desta base sim! Acho que você poderia explicar mais detalhadamente o contexto do seu problema para que seja possível oferecer uma resposta/sugestão.
Comment: Em vez de fazer um select para depois um update, usar o método **ON DUPLICATE KEY UPDATE** não seria melhor?? Acho que deveria fazer um teste de desempenho antes, mas creio que ganharia mais velocidade sem precisar fazer o select. Pois desse modo ele tentaria inserir sempre novos registros, e iria atualizar somente aqueles que ja existir no banco de dados. Da uma olhada: https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
Comment: Também estou fazendo uma sistema assim e gostaria de saber qual é o mais eficiente para amanha não ter problemas, já vi que o delete pode ter um alto custo para tabelas indexadas, estava pensando em colocar um flag N/C Registro Normal e Cancelado e dar update na tabela toda ao invés de excluir, mas aí caio em outras duas questões, será que o Update é mais rápido, e o inchaço nas tabelas, por manter registros sem uso, não afetara o select? Pensei nessa solução levando em conta que existem tabelas com milhões de registros e a performance é boa.
Comment: Use o `INSERT ... ON DUPLICATE KEY UPDATE` que faz esse trabalho por si.
Answer: Meu caro, tenho algumas observações para você:

Não recomento excluir os dados, pois, se algum dia houver falha ou atraso no envio dos dados pela empresa, você ficará com uma janela de dados indisponíveis ou inconsistentes com as informações do dia anterior.
Acho que você precisa especificar melhor como você sabe que os novos dados que chegam são novos ou repetidos. Ou seja, qual o identificador do dado. Ex: id_empresa + id_tipo_informacao + data_informacao.
Após responder à pergunta anterior, você pode fazer UM TESTE e mudar a chave primária da tabela para uma chave composta usando a combinação de campos que resulte em uma combinação única e utilizar o comando REPLACE do MySQL, que irá fazer essa tarefa de INSERT ou UPDATE automaticamente pra você.
Comment: Isto não fornece uma resposta à pergunta. Para criticar ou solicitar esclarecimento de um autor, deixe um comentário abaixo da publicação dele. - [Da Revisão](/review/low-quality-posts/250294)
Comment: Obrigado pelo feedback. O que devo fazer nesse momento então? Posso excluir minha resposta?
Comment: Márcio tudo bem? Não é necessário remover sua resposta. Esse foi um posicionamento meu da revisão, mas outros usuários também irão analisar sua resposta. Se for satisfatória, ela permanecerá, se não for, ela será automaticamente removida.
Answer: Este é um procedimento muito comum utilizado por escritórios de cobrança, para transmissão de grandes listas de clientes. Chamamos isto de "Carga".
Diariamente dois sistemas diferentes podem se conversar enviando e recebendo estes dados pois um deles está executando uma tentativa de sincronia com o banco de dados de origem. O processo consiste da seguinte forma:
O banco de dados que tenta fazer a sincronia, deve possuir duas tabelas idênticas no seu layout, uma para dados de entrada e outra para dados de histórico. Ambas devem possuir todos os campos necessários para as informações e mais dois campos de controle: O primeiro é o nome da origem dos dados, exemplo: "empresa_origem". O segundo campo é a data da entrada dos dados, exemplo: "data_entrada". O campo data irá funcionar como parâmetro de comparação entre os dados da tabela de histórico e os novos dados com dados.
A rotina que deve ser empregada é a inserção dos registros na tabela de entrada "tabela de histórico", para em seguida executar uma comparação com a tabela de histórico afim de separar o conteúdo novo. Desta forma será possível diferenciar os registros.
Os dados que forem localizados diferentes devem ser inseridos dentro da tabela de histórico e após o procedimento a tabela de entrada deve ser limpa para uma nova carga de dados.
Utilizando os campos "nome_empresa" e "data_entrada" é possível diferenciar os dados de todas as origens e assim obter maior integridade das informações que forem recebidas. Assim você obtém um relatório de  "Carga" através das quantidades de registros que forem recebidas diariamente por cada origem e data.


Cardinality of ultraproduct

Question: Let $\mathcal{U}$ be a non-principal ultrafilter on $\omega$. Let $S:\omega\rightarrow\omega$ be monotone and unbounded. Let $T_{\mathcal{U},S}=\prod\limits_{\mathcal{U}}S(n)$ the ultraproduct as set. What is the supremum and infimum of $|T_{\mathcal{U},S}|$ as $\mathcal{U}$ and $S$ change.
Trivially, $\aleph_{0}\leq|T_{\mathcal{U},S}|\leq 2^{\aleph_{0}}$. That's all I can do, don't know how to proceed. I am guessing that these are indeed infimum and supremum, but can't prove neither.
(I added the context, but apparently some people still think it is not a good question, so whatever)
Also, to add in the comment above, apparently the new bound is $\aleph_{1}\leq|T_{\mathcal{U},S}|\leq 2^{\aleph_{0}}$ now. Thanks.
I proved the bound of $\aleph_{1}$, can this question be reopened or not? I can't figure out what would make you people happy now.
(this is not a homework question) Also, I solved it, the answer is that the only possibility is $2^{\aleph_{0}}$.
Comment: What have you tried? Where did you get stuck? Don't just ask us to do your homework for you.
Comment: You can improve that lower bound: recursively construct a family of $\omega_1$ pairwise almost disjoint functions in $\prod_nS(n)$.
Comment: Saharon Shelah. *On the cardinality of ultraproduct of finite sets*, J. Symbolic Logic, **35 (1)**, (1970), 83-84.
Comment: (The specific case in this exercise is easier than the result in Shelah's paper. A proof and references can be found in the monograph by Comfort and Negrepontis.)
Comment: Relaying a comment from an anonymous user who tried to post it as an edit: "@Adres Caicedo: I looked up the paper on JSTOR, and I am not sure why this is any easier than the one on JSTOR (and assuming that I am correct in my proof, I got stronger result). I can't look up the one in the other monograph, so I don't know what result was proved there. Can you clarify for me the difference between the one here, the one in the paper, and the one in the monograph? (sorry I can't post comment)"
Comment: @AndresCaicedo There is a comment addressed to you that you may not be notified of, due to some spelling mistake.
Answer: I saw the following answer once in a post of Andres E Caicedo, but I could not find it this time.
If $M=\prod_\mathcal{U} M_i$ is an ultraproduct of finite structures with $|M_i|\rightarrow_{\mathcal{U}} \infty$, then $|M|=2^{\aleph_0}$
Note that
$$\left|\prod_\mathcal{U}M_i\right|\leq \left|\prod_{i\in I} M_i\right|\leq |\mathbb{N}^{\mathbb{N}}|=|\mathbb{R}|,$$
so it suffices to show that $|\mathbb{R}|\leq|\prod_\mathcal{U} M_i|.$
We will need the following combinatorial lemma:

There exists a family $\mathcal{F}$ of functions
  $f:\mathbb{N}\rightarrow\mathbb{N}$ such that:

$|\mathcal{F}|=2^{\aleph_0},$
For any $f\in\mathcal{F}$ and any $n\in\mathbb{N}$, $f(n)<2^n$,
If $f\neq g$ are in $\mathcal{F}$, then $\{n\in \mathbb{N}: f(n)=g(n)\}$ is finite.

Proof of the lemma: Given a set $A\subseteq \mathbb{N}$ let $f_A:\mathbb{N}\rightarrow\mathbb{N}$ be given by
$$f_A(n)=\sum_{k<n}\chi_A(k)2^k,$$
where $\chi_A$ is the characteristic function of $A$. Then the family $\mathcal{F}=\{f_A:A\subseteq \mathbb{N}\}$ satisfies the three conditions. End of proof of Lemma
Let $A_n=\{k\in\mathbb{N}:2^n\leq |M_k|<2^{n+1}\}$, so the sets $A_n$ are all finite and partition $\mathbb{N}$. For each $k\in A_n$ let $\{a_{k,j}: j<2^n\}$ be a list of $2^n$ distinct elements of $M_k.$
Let $\mathcal{F}$ be a family as in the Lemma. For $f\in \mathcal{F}$, let $h_f: \mathbb{N}\rightarrow\bigcup_k M_k$ be given by $h_f(k)=a_{k,f(n)},$ where $n$ is such that $k\in A_n.$
Note that if $f\neq g$ are in $\mathcal{F}$, then
$$\{k\in\mathbb{N}: h_f(k)=h_g(k)\}=\bigcup\{ A_n: n\in\mathbb{N},f(n)=g(n)\}$$
is a finite union of finite sets and therefore finite. Hence, $[h_f]_\mathcal{U}\neq [h_g]_\mathcal{U},$ and we are done.
Is this a correct answer?

Cardinality of ultraproduct


LWJGL installation not working

Question: I am trying to install LWJGL 3.0.0b build 9 on Eclipse, and have followed multiple tutorials, but when I try to use the classes it cannot find them.
These images show a program copied from the official tutorial, and the 3 LWJGL folders, then the project properties, configured as instructed.
https://i.stack.imgur.com/1a22u.png
If you can offer help, I would be very appreciative, thanks!
Comment: Slightly off topic: In my older days of Java(I have grown up since then and moved on to better, well built languages), I found Eclipse to be absolute trash. You should be using IntelliJ.
Answer: Right-click on your project, select "properties", then select "Java build path", add a reference to your jar there and it should work.
Comment: That is done, there are two imgur images and the second one displays that configuration, but thanks

LWJGL installation not working


In standardized regression with same number of samples, can one X variable have higher beta but lower T-stat than another

Question: Lets say I have $n$ observations of $Y$, $X_1$, and $X_2$. All three are normalized (mean 0, variance 1). I run two regressions:

$Y=\beta_1X_1$
$Y=\beta_2X_2$

Given these $n$ observations, is it possible for $\beta_1 > \beta_2$, but $tstat(\beta_1) < tstat(\beta_2)$ or for $\beta_1 < \beta_2$, but $tstat(\beta_1) > tstat(\beta_2)$?
Answer: If you allow for different signs, then yes.  If the standardized slopes (i.e., the correlations) have the same sign, then assuming you are using the same data set (and same sample size), no...it would not be possible for the t-ratios to go in the other direction.


Laravel 5.5: Pegar nome de cada tabela no select union

Question: Preciso fazer um select em duas tabelas e juntar elas com o union, até aí certo, mas preciso pegar também o nome das duas para poder identificar lá na View.
Já tentei utilizar o getTable() em cada select, mas me retorna o erro:

Non-static method Illuminate\Database\Eloquent\Model::getTable() should not be called statically

Também tentei pegar direto no select, pois já fiz desse jeito uma vez sem usar o Laravel: select('tabela1 as table') e me retorna um erro de sintaxe.
Qual a forma correta de fazer isso?
Código:
$first = Lista::where('serie_id', $serie->id)
        ->select('descricao as result1');

$atividades = Avaliar::where('serie_id', $serie->id)
        ->select('nota as result1')
        ->union($first)
        ->get();

Comment: Teu exemplo ali funcionou bem.
Comment: Você deseja pegar os nomes da tabelas no UNION? eu acabei não entendendo.?
Comment: Exato, pois vou precisar identificar elas na view.
Comment: Na `View` com assim??? se fala o arquivo blade?
Comment: Sim. Simplificando, digamos que os resultados vindo da tabela lista, ficarão na cor vermelha e os que vierem da tabela avaliar, ficarão na cor azul.
Comment: Entendi @Diego, e se for identificado na própria `SQL`?
Comment: Não entendi, como assim?
Comment: Eu posso identificar na própria SQL o nome da tabela de forma explicita!
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/70735/discussion-between-virgilio-novic-and-diego-vieira).
Answer: Na própria SQL crie a identificação de cada SELECT, exemplo:
$first = Lista::where('serie_id', $serie->id)
        ->select('descricao as result1')
        ->selectRaw("'Lista' as tabela");

$atividades = Avaliar::where('serie_id', $serie->id)
        ->select('nota as result1')
        ->selectRaw("'Avaliar' as tabela");
        ->union($first)
        ->get();


Java. como exibir um vetor de string a partir da opção de um menu?

Question: Eu criei 3 vetores, um para nome, e os outros para dia e mês de nascimento.
Eu preencho os 3 através da primeira opção do menu que fiz com o switch case, a segunda opção seria para exibir apenas os nomes de quem está cadastrado (inserido) no vetor de nomes: agenda, mas não dá certo, porém quando está fora da estrutura condicional dá certo.
Quando ponho em qualquer estrutura o vetor não é exibido, como se estivesse vazio. O que faço?
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author lab1
 */
import java.util.Scanner;
public class q3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
          int tecla = 1;
          while (tecla != 27){

          System.out.println("**********Agenda de aniversariantes**************");

        System.out.println("1.Cadastrar pessoa na agenda");
        System.out.println("2.Excluir pessoa a partir do nome");
        System.out.println("3.Consultar aniversariantes de uma data (dia e mês)");
        System.out.println("4.Consultar aniversariantes por mês");
        System.out.println("5.Consultar aniversariantes pela letra inicial do nome");
        System.out.println("6.Mostrar toda a agenda ordenada pelo nome");
        System.out.println("7.Mostrar toda a agenda ordenada pelo mes");
        System.out.println("8.Sair");
        System.out.println("A agenda pode suportar até 10 pessoas");

        String agenda[] = new String[10];
        int dia[] = new int[10];
        int mes[] = new int[10];
        System.out.print("Digite uma opção:");
        int opcao = scan.nextInt();

        switch(opcao){
            case 1:
                int i = 0;

               // if(i < 10){
                    System.out.print("Digite o nome: ");
                    agenda[i] = scan.next();
                    System.out.print("Digite o dia do aniversario: ");
                    dia[i] = scan.nextInt();
                    System.out.print("Digite o mes do aniversario: ");
                    mes[i] = scan.nextInt();
                i++;
                //}
               // else
                 //   System.out.println("Agenda cheia");
            break;
            case 2:
                int j;
                for (j=0;j<agenda.length;j++)
                if(agenda[0] == null)
                    System.out.println("Agenda vazia");
                else{
                    System.out.println("Agenda de aniversários");
                    for (j=0;j<agenda.length;j++){
                        System.out.println(agenda[j]);
                        System.out.println(dia[j]);
                        System.out.println(mes[j]);
                }
                }
            break;
    }

}
}
}

Answer: O erro acontece por que você instancia os vetores toda vez que roda o while.
Segue a correção, feita trazendo as linhas dos vetores acima no código:
package br.com.alura.teste;

import java.util.Scanner;

public class q3 {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
        int tecla = 1;

        //Preste atenção aqui:
        String agenda[] = new String[10];
        int dia[] = new int[10];
        int mes[] = new int[10];
        while (tecla != 27) {

            System.out.println("**********Agenda de aniversariantes**************");

            System.out.println("1.Cadastrar pessoa na agenda");
            System.out.println("2.Excluir pessoa a partir do nome");
            System.out.println("3.Consultar aniversariantes de uma data (dia e mês)");
            System.out.println("4.Consultar aniversariantes por mês");
            System.out.println("5.Consultar aniversariantes pela letra inicial do nome");
            System.out.println("6.Mostrar toda a agenda ordenada pelo nome");
            System.out.println("7.Mostrar toda a agenda ordenada pelo mes");
            System.out.println("8.Sair");
            System.out.println("A agenda pode suportar até 10 pessoas");

            System.out.print("Digite uma opção:");
            int opcao = scan.nextInt();

            switch (opcao) {
            case 1:
                int i = 0;

                // if(i < 10){
                System.out.print("Digite o nome: ");
                agenda[i] = scan.next();
                System.out.print("Digite o dia do aniversario: ");
                dia[i] = scan.nextInt();
                System.out.print("Digite o mes do aniversario: ");
                mes[i] = scan.nextInt();
                i++;
                // }
                // else
                // System.out.println("Agenda cheia");
                break;
            case 2:
                int j;
                for (j = 0; j < agenda.length; j++)
                    if (agenda[0] == null)
                        System.out.println("Agenda vazia");
                    else {
                        System.out.println("Agenda de aniversários");
                        for (j = 0; j < agenda.length; j++) {
                            // E aqui também fiz uma pequena alteração
                            if(null != agenda[j]) {
                                System.out.println(agenda[j]);
                                System.out.println(dia[j]);
                                System.out.println(mes[j]);
                            }
                        }
                    }
                break;
            }

        }
    }
}

Comment: Deu certo, mas quando adiciono outra pessoa, a mesma ocupa o lugar da pessoa anteriormente cadastrada
Comment: `int i = 0;`. É erro do seu código, não da sua duvida, mude essa linha para algum integer que conte a quantidade de usuarios inseridos.


Select hibernate criteria com entidade nao mapeada

Question: tem como eu fazer um select, usando o criteria e trazer uma entidade não mapeada, seriam vários joins, e as vezes trazer determinados campos e outros não.
Answer: Criteria você não pode fazer sem uma entidade, mas você pode usar o Native Query para executar queries.
<code>Query query = session.createSQLQuery("select s.stock_code from stock s where s.stock_code = :stockCode").setParameter("stockCode", "7277");
List result = query.list();
</code>
Você pode ver mais em: https://www.mkyong.com/hibernate/hibernate-native-sql-queries-examples/
Comment: Com criteria você consegue trás classes não mapeadas, procure na documentação do hibernate 5.2 que usa o criteriabuilder do entitymanager que lá mostra como fazer.


Java BufferedFileReader skips first line

Question: I'm trying to use the BufferedFileReader to read a Document with saved Information. It's working good, but it always skips the first line of the code. Is it because I'm calling readLine() in the for loop? If so how could I change it?
private void createViewUser() {

    String[] stringFirstName = new String[10];
    String[] stringName = new String[10];
    String[] stringAge= new String[10];

    try {
        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);

        for (int i = 0; br.readLine() != null; i++) {

            stringFirstName[i] = br.readLine();
            stringName[i] = br.readLine();
            stringAge[i] = br.readLine();

            firstname[i] = new JTextField();
            firstname[i].setBounds(100, 100 + 50 * i, 100, 30);
            view.add(firstname[i]);

            name[i] = new JTextField();
            name[i].setBounds(200, 100 + 50 * i, 100, 30);
            view.add(name[i]);

            age[i] = new JTextField();
            age[i].setBounds(300, 100 + 50 * i, 100, 30);
            view.add(age[i]);

            firstname[i].setText(stringFirstName[i]);
            name[i].setText(stringName[i]);
            age[i].setText(stringAge[i]);

        }
        fr.close();
        br.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

Comment: Unrelated to your question, but your component positioning, using null layout and `setBounds` is a very bad thing to do as by doing so, you create a rigid, hard to debug or enhance program, one that appears bad on computers with different resolutions and one that fights against the GUI library that you're using. If this were my program and I were trying to display tabular data as you are doing, why not more simply create and display this information in a JTable?
Comment: Also you're using parallel arrays, a bad design choice, and instead should consider creating a class to hold the first and last names as well as the age in a single object. Then create an ArrayList of these objects.
Comment: Yes you're right, but it was just my first idea and I wanted to complete it and then maybe change it. Thanks anyways I'll try it soon. And I'm just starting and never worked with ArrayLists so I tried to avoid them
Answer: Exactly,  each time  before going  into the for loop  your program  reads a line and checks if it is not null.
More you will also skip a line because of this condition. (not sure if it's desired or not)
You kinda got the answer yourself ;)
Comment: Okay and what can I use instead?
Answer: you're reading first line in the for loop:
for (int i = 0; br.readLine() /* HERE*/ != null; i++) {

You could do something like this:
String line = br.readLine();
for(int i = 0; line != null ; i++){
       stringFirstName[i] = line;
       line = br.readLine();
}

Answer: Hello you can init String var to fix it:
String line = br.readLine();

for (int i = 0; line != null; i++) {
    stringFirstName[i] = line;
    stringName[i] = br.readLine();
    stringAge[i] = br.readLine();

It's doesn't work because it's load first line on for loop verification for (int i = 0; br.readLine() != null; i++) {
Good luck.
Answer: Your question involves several steps, but the most important issue for your purposes is how to efficiently and safely read data held in a text file when the data is presented in groups of three lines, something like:
first_name_1
last_name_1
age_1
first_name_2
last_name_2
age_2
first_name_3
last_name_3
age_3
first_name_4
last_name_4
age_4

where of course the names are replaced with real names, and likewise the age_? is replaced with a real number.
If you're going to go the BufferedReader route, I think that the safest thing to do is get all three Strings in each grouping within the while loop's boolean condition, something like:
BufferedReader reader = new BufferedReader(....);

// declare empty Strings first
String firstName = "";
String lastName = "";
String ageString = ""; // need to get age *first* as a String

while ((firstName = reader.readLine()) != null         // get all 3 Strings here
        && (lastName = reader.readLine()) != null
        && (ageString = reader.readLine()) != null) {  // boolean condition ends here
    int age = Integer.parseInt(ageString.trim());    // NumberFormatException risk here

    // ....

}

This way, if any of the Strings in the text file are missing, the whole while loop ends, and bad data is not obtained.
Other recommendations, create a plain-old Java object to hold your Person data, the names and the age, a class with 3 fields, 2 that are Strings for the names, and one int field for the age. Give it a decent constructor, getter methods.... For example:
public class Person {
    private String firstName;
    private String lastName;
    private int age;

    public Person(String firstName, String lastName, int age) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Person [firstName=" + firstName + ", lastName=" + lastName + ", age=" + age + "]";
    }

}

This way, the while loop above could be used to simply create Person objects:
List<Person> persons = new ArrayList<>();  // an ArrayList of Person to hold the data

while ((firstName = reader.readLine()) != null              // get all 3 Strings here
        && (lastName = reader.readLine()) != null
        && (ageString = reader.readLine()) != null) {       // the while loop ends here
    int age = Integer.parseInt(ageString.trim());

    Person person = new Person(firstName, lastName, age);   // create a new Person object
    persons.add(person);                                    // put it into the arraylist
}

OK, how about displaying this information into a JTable -- that's easy.
Create a DefaultTableModel with the correct column names:
private static final String[] COL_NAMES = { "First Name", "Last Name", "Age" };
private DefaultTableModel model = new DefaultTableModel(COL_NAMES, 0);

and then create a JTable with this model:
private JTable table = new JTable(model);

Then iterate through the ArrayList<Person> and fill our model with data:
for (Person person : personList) {
    Vector<Object> rowData = new Vector<>();
    rowData.add(person.getFirstName());
    rowData.add(person.getLastName());
    rowData.add(person.getAge());
    model.addRow(rowData);
}

and the JTable is created and filled with data, just like that.
OK, assuming a data file called PersonData.txt that is located in the same directory as our class files, like so:

And assuming that this file  holds our data like so:
John
Smith
21
Fred
Flinstone
53
Barny
Rubble
52
Mary
Contrary
22
Bo
Peep
12
Donald
Trump
75
Donald
Duck
40
Mickey
Mouse
45
Minnie
Mouse
41
Ebenezer
Scrooge
80
Bob
Cratchit
33
Ralph
Kramden
55
Alice
Kramden
48
Ed
Norton
54

Then using our Person.java class, we can create a GUI to hold and display our data like so:
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

@SuppressWarnings("serial")
public class PersonDisplay extends JPanel {
    private static final String[] COL_NAMES = { "First Name", "Last Name", "Age" };
    private static final String PERSON_DATA_PATH = "PersonData.txt";
    private DefaultTableModel model = new DefaultTableModel(COL_NAMES, 0);
    private JTable table = new JTable(model);

    public PersonDisplay(List<Person> personList) {
        for (Person person : personList) {
            Vector<Object> rowData = new Vector<>();
            rowData.add(person.getFirstName());
            rowData.add(person.getLastName());
            rowData.add(person.getAge());
            model.addRow(rowData);
        }

        setLayout(new BorderLayout());
        add(new JScrollPane(table));
    }

    private static void createAndShowGui(List<Person> personList) {
        PersonDisplay mainPanel = new PersonDisplay(personList);

        JFrame frame = new JFrame("Person Display");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static List<Person> readInPersons(InputStream is) throws IOException {
        List<Person> persons = new ArrayList<>();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String firstName = "";
        String lastName = "";
        String ageString = "";

        while ((firstName = reader.readLine()) != null
                && (lastName = reader.readLine()) != null
                && (ageString = reader.readLine()) != null) {
            int age = Integer.parseInt(ageString.trim());
            Person person = new Person(firstName, lastName, age);
            persons.add(person);
        }

        return persons;
    }

    public static void main(String[] args) {
        try {
            InputStream inputStream = PersonDisplay.class.getResourceAsStream(PERSON_DATA_PATH);
            List<Person> personList = readInPersons(inputStream);
            SwingUtilities.invokeLater(() -> createAndShowGui(personList));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

and when displayed, it would look like:


Interpreting coefficient of log transformed independent variable in negative binomial regression

Question: My problem is...
...how to interpret coefficients associated with log-transformed independent variables. I know that now I have log units, which depend on the choice of basis for the logarithm. For natural log as in your example, an e
e-fold change in Independent_var_1 is associated with the indicated change in the dependent variable.
for example: y= a + aln(X) + e, where y is count data.
Therefore, a e-fold change in X associates with a change in y.
Q1: Is this interpretation correct? Q2: is the change in y in units or percentages?
Thank you.
Answer: First, I am not sure if negative binomial regression restricts your intercept and slope to be both $a$. I am assuming that is not the case.
Given two scenarios, where $x$ differs by $k$ time:
$$\ln(E(y)) = \beta_0 + \beta_1 \ln{x}$$
and
$$\ln(E(y')) = \beta_0 + \beta_1 \ln{kx}$$
Subtract the first one from the second:
$$\ln(E(y')) - \ln(E(y)) = \beta_1 (\ln{kx} - \ln{x})$$
$$\ln \frac{E(y')}{E(y)} = \beta_1 (\ln{\frac{kx}{x}})$$
$$\frac{E(y')}{E(y)} = \exp^{\beta_1 (\ln{k})}$$
So, if $x$ changes by $k$ times, average of $y$ changes by $\exp^{\beta_1(\ln{k})}$ times.
Suppose $x$ increases by 20% and $\beta_1$ is 0.79, then $y$ changes by $\exp^{0.79(\ln{1.2})} = 1.155$ times, a 15.5% increase. Predicted change in $y$ is expressed in percentage or factor, not in its own unit.


Passing Multiple Values to Parameter in iReport 4.01

Question: Am working on iReport 4.0.1
Can I pass multiple values to parameter like:
select name,id from temp where name in (xxx,zzz,yyy)

Can I implement using iReport 4.0.1. I even tried by using $X{In, column name, parameter name} this syntax but am unsuccessful.
Could anyone help, how can I achieve it?
Answer: I solved the same problem as follows:
select name,id from temp where name in ($P!{parameter_name})

Answer: Create a parameter with parameter class java.util.Collection. Lets assume that the parameter name is tmpNames. ($P{tmpNames})
And put your parameter into the query like below :
select name,id from temp where $X{IN,name,tmpNames};

Do not forget to pass a collection of names to the tmpNames parameter.
tpNames=new ArrayList<String>(Arrays.asList("abc","acd","ade"));

...

map.put("tmpNames",tpNames);

...

Answer: Follow these steps:

Create a String parameter in your Jasper Report, like customers

Prepare a query in Jasper Designer, like pass parameter as $P!{customers}, enter ! after $P
SELECT
     *
FROM
     tblInvoice
WHERE
     date BETWEEN $P{startDate} AND $P{endDate}
AND
     cust_name IN ($P!{customers})

Finally, pass the string from java code as like:
String customers = "\'xxx\',\'zzz\',\'yyy\'";
Map<String, Object> parameter = new HashMap<>();
parameter.put("customers", customers);


Pre-create application environment in Argo CD

Question: I need some hints how can one handle precreation of application needed resources. I.e. namespace the application will be running in. I know we can auto-create the namespace, but we don't want that and also we have another set of resources that we need to prepare for the app. Not to mention some task outside of the cluster.
I suppose the way is to use "app of apps", but not sure how these use cases are handled there. Is it possible to use it not only for Application CRD creation, but also for another resouces creation?(i.e. secrets, config map, even some external Azure ACR tokens).
It is actually about the whole app onboarding process utilizing ArgoCD's GitOps approach.
Comment: Inside one App, you can use **sync waves**: https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/
Comment: Aren't they just for upgrades of application. Some steps can be run only once can you handle this with sync waves? Maybe the problem is I am trying to use gitops to setup the app, maybe such one-time task is better suited for some TF pipeline.
Comment: Aaah I hadn't understood your goal. Yes, definitely it's not for GitOps if these are one time task to do before deploying very first time. Do it in your setup pipeline. Optionally Helm can do things with hook but given your need I think it has to be managed outside of Kubernetes.
Comment: So you think to run ten setup task and then use "app of apps". The question is should I go full gitops or should I mix it.  We are fully terraformed now, but considering ArgoCD or other Gitops tooling. Thing is, if the required additional knowledge is worth it.
Answer: If you have a resource dependency, you should leverage sync-waves. More info here https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/#how-does-it-work
Comment: forgot to read the comments before posting answer, someone else deserves the credit here.
Comment: FWIW - if you have a dependency on another application, then you can handle this with initContainers or readiness probes for your application - K8s is all about eventual consistency
Comment: I have dependency on resources outside of k8s stack.
Comment: if you have network access, then you should consider a PreSync Hook from ArgoCD or an initContainer for your pod
Answer: @Zveratko
I think I almost have an identical case to yours. I am trying to deploy a SaaS app from a web page and I want to use a pure argocd gitops flow. Or a mix of some other tooling. Basically I want to start a tenant provisioning on a cluster with shared application (that already exists) and I want to add ingress for tenant's subdomain and possible DB instance if he wants data isolation and in the process I have to call my application tenant management api to register this tenant with this local application to enable domain name to tenant name resolution. So I first want to start with namespace deployment, intercept that and call my api with tenant registration data: adminemail, subdomain, isolateddbwanted, premiummoduleslist [m1,m2] and continue with ingress and possibly db deployment.
I have found several solutions. Maybe we can connect and explore these.
 1. keptn-lifecycle-toolkit
https://isitobservable.io/observability/kubernetes/what-is-the-keptn-lifecycle-toolkit
it provides a way to add pre and post application (a custom crd which groups your workloads/deployments) installation hooks  and also pre and post hooks for your individual deployments
It can also do evaluation of your metrics and only install your workloads if the certain metrics is satisfied)
 2. Write Custom Operator (Argo cd has a way to introspect your custom crd with lua script to check for Healthy status)
 3. Write Custom web hook (your deployment can expose a web hook where you can do some things when you create some resource.
 4. You can do helm or argo presync hooks to run a job
Argo: argocd.argoproj.io/hook: PreSync and run some job
Helm:
apiVersion: v1
kind: Pod
metadata:
name: hook-preinstall
annotations:
"helm.sh/hook": "pre-install"
It is not easy to explain these here, but what I am saying is that you can still use pure argo cd approach and hook into synchronization flow at the right time and execute your preparation steps using custom code, script
(like in keptn lifecycle toolkit you can execute Deno script (runtime similar to nodejs) or python script


Proving that if $M$ is a finitely generated and projective $R$ module, then $M$ is also finitely presented.

Question: Since $M$ is finitely generated $R$ module, we have an epimorphism $\pi : F \to M$, such that $F= R^{(n)}$ where $n$ is a positive integer. On the other hand, since $M$ is a projective $R$ module we have by a well known property of projective modules that $M$ is isomorphic to some direct summand of $F$, that is, $M \cong F_{2}$ where $F= F_{1} \oplus F_{2}$. So we consider the following  canonical short exact sequence:
$$0 \to F_{1} \to F_{1} \oplus F_{2} \to F_{2} \to 0.$$
In order to prove that $M$ is a finitely presented $R$ module we need to show that $F=F_{1} \oplus F_{2}$ is a free and finitely generated module (we already know this is true since $F = R^{(n)}$), and we also need to show that $F_{1}$ is just finitely generated. Still I'm run out of ideas in order to argue that $F$ is finitely generated if $F$ is Noetherian we are done but its not the case. Is my train of thought for this proof OK? How can I argue $F_{1}$ being a submodule (direct summand) of $F$ is finitely generated?  Thanks!
Comment: Right! Havent see it but yes, since we have a canonical epimorhism $\pi: F \to F_{1}$ where $F$ is already finitely generated, then $F_{1}$ is also finitely generated, correct? @FabioLucchini
Comment: Note that $F_1$ is an homomorphic image of $F$, hence is finitely generated.
Answer: Consider $P$ a finitely generated projective module. This means there exists a surjection $\pi :R^n\to P$ for some finite $n$.
Since $P$ is projective, this surjection splits, that is, there exists a map  $j: P\to R^n$ such that $\pi j = 1_P$, and the splitting lemma guarantees that the short exact sequence
$$0\longrightarrow K \longrightarrow R^n \longrightarrow P \longrightarrow  0$$
is isomorphic to the canonical short exact sequence
$$0\longrightarrow K \stackrel{j_1}\longrightarrow K\oplus P
\stackrel{\pi_2}\longrightarrow P \longrightarrow  0.$$
In particular, there exists a projection $\pi_1 : R^n\cong K\oplus P\to K$, exhibiting the kernel of $\pi$ as a finitely presented module.


Como ler um arquivo com Kotlin?

Question: Tenho um arquivo .txt com algumas informações que eu gostaria de ler para uma string através do Kotlin.
Sou iniciante na linguagem e gostaria de saber como faço para ler um arquivo com Kotlin.
Comment: Igual ao Java :P
Comment: @bigown eu não sei como é no Java :p
Answer: A maior parte da biblioteca de Kotlin é a mesma existente para o Java, um dos trunfos da linguagem já foi nascer com toda essa biblioteca disponível.
É possível ler todo o arquivo e depois manipulá-lo, ler linhas dele, ou ler do jeito que achar melhor, ou ainda ler por streams. Toda documentação do que pode fazer das mais variadas formas.
Enfim depende da necessidade. Exemplos.
Stream
import java.io.File
import java.io.InputStream

fun main(args: Array<String>) {
    val inputStream: InputStream = File("kotlination.txt").inputStream()

    val inputString = inputStream.bufferedReader().use { it.readText() }
    println(inputString)
}

Linha por linha
import java.io.File
import java.io.InputStream

fun main(args: Array<String>) {
    val inputStream: InputStream = File("kotlination.txt").inputStream()
    val lineList = mutableListOf<String>()

    inputStream.bufferedReader().useLines { lines -> lines.forEach { lineList.add(it)} }
    lineList.forEach{println(">  " + it)}
}

BufferedReader
import java.io.File
import java.io.BufferedReader

fun main(args: Array<String>) {
    val bufferedReader: BufferedReader = File("kotlination.txt").bufferedReader()

    val inputString = bufferedReader.use { it.readText() }
    println(inputString)
}

Linha por linha
import java.io.File
import java.io.BufferedReader

fun main(args: Array<String>) {
    val bufferedReader = File("kotlination.txt").bufferedReader()
    val lineList = mutableListOf<String>()

    bufferedReader.useLines { lines -> lines.forEach { lineList.add(it) } }
    lineList.forEach { println(">  " + it) }
}

Coloquei no GitHub para referência futura.
Answer: (Quase) igual ao Java
É possível usar as bibliotecas do Java pra isso. Aliás, não só pra isso, boa parte da biblioteca da Kotlin é a do Java.
Obviamente existem diversas formas de trabalhar com arquivos. Um exemplo simples de como ler todas as linhas de um arquivo .txt é:
import java.io.File
import java.io.InputStream

fun main(args: Array<String>) {
    val stream: InputStream = File("wallace.txt").inputStream()

    val str = stream.bufferedReader().use { it.readText() }
    println(str)
}

Ou, então, ler linha por linha
import java.io.File
import java.io.InputStream

fun main(args: Array<String>) {
    val stream: InputStream = File("wallace.txt").inputStream()
    val linhas = mutableListOf<String>()

    stream.bufferedReader().useLines { l -> l.forEach { linhas.add(it)} }

    linhas .forEach { println(">  " + it) }
}

Obs: Note que it é o nome padrão (implícito) do parâmetro de uma função anônima.
Peguei os exemplos do Kotlination.

Como ler um arquivo com Kotlin?


Why is gridview.selectedColumns nothing?

Question: I want to run a code like this, but it always jumps over the loop, so I see no line in the console.
That means that selectedColumns is empty. My assumption was that I (or the user) select a cell from a Column and then, selectedColummns are +1. But as it looks, it doesnt work.  Then I tried to set proberties of selectionMode to select full columns, but then  an exception is thrown:

"System.InvalidOperationException" Additional Information: the SortMode cannot be Automatic, if full Column selection is selected.

I don't know what SortMode is.
 For Each col As DataGridViewColumn In datagridview2.SelectedColumns

        Console.Write(datagridview2.SelectedColumns.Count)
        Console.Write("1")

    Next

Any Ideas how to get that the columns into selectedColumns?
Here my code that solved my problem, but I guess it is not the smartest one:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim body As String = ""

    Dim myWriter As New StreamWriter("H:\downloads\test.csv", True)
    Dim list As List(Of Integer) = New List(Of Integer)

    For Each cell As DataGridViewCell In datagridview2.SelectedCells

        If list.Contains(cell.ColumnIndex) = False Then
            list.Add(cell.ColumnIndex)
        End If

    Next

    For i = 0 To datagridview2.Rows.Count - 1

        For ix = 0 To datagridview2.Columns.Count - 1

            If list.Contains(ix) Then

                If datagridview2.Rows(i).Cells(ix).Value IsNot Nothing Then

                    body = body + datagridview2.Rows(i).Cells(ix).Value.ToString + ";"
                Else
                    body = body + ";"
                End If

            End If

        Next
        myWriter.WriteLine(body)
        body = ""

    Next

    myWriter.Close()

End Sub

Answer: You need to do this after the selected changed event has fired.
For example:
Private Sub Mydg_ColSelected(sender As Object, e As SelectionChangedEventArgs) Handles datagridview2.SelectionChanged

   For Each col As DataGridViewColumn In datagridview2.SelectedColumns

    Console.Write(datagridview2.SelectedColumns.Count)
    Console.Write("1")

    Next

End Sub

Or if this isn't what you are after, then try handling the ColumnHeaderMouseClick event instead. I'm not sure what technology you are using, e.g Winforms, WPF, silverlight
Comment: ColumnHeaderMouseClick or ColSelected change event will not work, because I need to write the selected columns into a .csv file. Nevertheless, now I managed it through selectedcell.columnindex Look my Edit in 1 minute :)


Mentally Estimating the Normal CDF

Question: More than once I have seen this sort of frustrating question on a Mathematics GRE practice test:
A fair die is tossed 360 times. The probability that a six comes up on 70 or more tosses is...
a) greater than .50
b) between .16 and .50
c) between .02 and .16
d) between .01 and .02
e) less than .01
I think the question wants me to approximate the binomial distribution with a normal distribution centered around $360/6 = 60$ with standard devation $\sqrt{360*1/6*5/6} = 17.3...$ Even with this approximation, how would I mentally (or quickly using pen and paper) be able to estimate the CDF to the degree of accuracy that this question asks for?
Answer: The standard deviation is $\sqrt{50}$, a little bit over $7$. So $70$ is $1.4$ standard deviation units up from the mean.
If one recalls some calculations with tables of the standard normal, one may remember that the probability that $Z\gt 1$ is about $0.16$,  and the probability that $Z\gt 1.645$ is about $0.05$. That is enough information to make the right choice among those offered. Even if we do not remember about $1.645$, the more commonly occurring $1.96$ ($95\%$ confidence interval) shows that the tail probability cannot, in our case, be less than $0.025$.
Comment: Wow so the test makers contrived to make a question to test my knowledge of specific values of the normal distribution? I will be sure to memorize the values that you mentioned. Thanks!
Comment: I do not think this is a particularly good question, except in a Stats subject exam, where one can be confident that there has been sustained exposure. One can of course immediately eliminate (a), and probably (d) and (e), but one bumps into $1$ standard deviation unit less often, since it does not come up in standard estimation problems.

Mentally Estimating the Normal CDF


Counterpoint (Fux): 3rd species, 3 voices, closing formulas

Question: I am working my way through Gradus ad Parnassum (Mann translation). The chapter is: third species in three voices.
At page 92, I see an example (Fig. 130) that ends like this:

I cannot understand the closing formula of the Counterpoint. It is 6M 4 5 6M from the Cantus Firmus, but earlier in the book (two voices) we were told that the closing formulas in third species (with Cantus Firmus on the lower part) were (p. 52):

8 7 5 6M or
3 4 5 6M

I feel I am missing something.
Answer: The key point is that you are now in three voices as opposed to just two. You're correct that page 52 lists Fux's recommended cadential formulas in two voices. But recall one of the main points of three-voice counterpoint as mentioned by Aloys on page 51:

Here it is to be observed first of all that the harmonic triad should be employed in every measure if there is no special reason against it.

The cadential formulae in three-voice counterpoint are a bit different than those in two voices because, with three voices, you can make the harmonic context more clear. Notice, for instance, that your penultimate bar is just an A-major triad, which is the dominant will later become known as the dominant of D, the tonic final.
Comment: Just to clarify for those who might be reading, Richard is alluding to the voice underneath the Cantus Firmus filling out the remaining member of the A triad, notably the root, before resolving to the final. On an unrelated note, I think that if the lower voice were an octave lower in the penultimate measure, the voice-leading would be more pleasing to the ear.


How to load jQuery from a module

Question: Drupal 7.x, Garland theme.
I am writing a module that depends on jQuery.  I am seeing that when an anonymous visitor comes by that jQuery isn't being loaded.  How do I load jQuery from my module?
I am not really a Drupal developer.  This is my first module.  I want to maintain Core as is (no hacking) for easy updates and I don't want to change themes from Garland, so I don't really want to edit the theme to force jQuery.
Thanks.
Answer: jQuery should be available to you right out of the box in D7 if I remember correctly. But you need to use jQuery(...) instead of $(...). If jQuery is not being included for some reason, try using drupal_add_js().
See Drupal 7 JavaScript API documentation for more information.
Comment: You can use `$` as long as it is passed into the function.
Comment: Yes, I am using jQuery().
Answer: See Added methods to avoid loading jQuery and related JavaScript libraries on all pages when they are not needed.
Starting from Drupal 7.36, Drupal could not load jQuery to the page.
If you are adding JavaScript from your module, it means you are doing one of the following:

Calling drupal_add_js()
Adding #attached to a render array

In both the cases, you can force Drupal to load jQuery.
drupal_add_js('path/to/some/javascript-library-needing-jquery.js', array('requires_jquery' => TRUE));

$build['#attached']['js'][] = array(
  drupal_get_path('module', 'mymodule') . '/javascript-library-needing-jquery.js' => array('requires_jquery' => TRUE)
);

Notice that, normally, calling drupal_add_js() or adding $build['#attached']['js'] is sufficient for making Drupal load jQuery, but if another module set 'requires_jquery' to FALSE, or if the settings.php file contains a  $conf['javascript_always_use_jquery'] = FALSE; line, then jQuery will not be loaded. Only when your module is setting 'requires_jquery' to TRUE with one of the methods I described, you are sure the jQuery library is loaded from Drupal.
Notice that, in either cases, if none of the modules (or the theme) is adding JavaScript code to the page through drupal_add_js(), #attached, or the scripts directive in a .info file, Drupal will not load the jQuery library. This means that, if you are hard-coding the link to an external JavaScript file in a template file, Drupal will not know JavaScript code is being used, and it will not load the jQuery library found in the misc directory of the Drupal root directory.
Comment: Thank you, I discovered drupal_add_js() on my own yesterday afternoon.  I have it working.

How to load jQuery from a module


Diferença em horas entre dias utilizando carbon

Question: Ao verificar a diferença em horas entre hoje e amanhã recebo o valor de 6 que é referente a quantidade de horas até às 00:00 do dia de hoje;
$t = \Carbon\Carbon::tomorrow();
$n = \Carbon\Carbon::now();
$n->diffInHours($t); // 6

Porém quando tento verificar com datas no passado recebo um numero ainda maior;
$y = \Carbon\Carbon::yesterday();
$n->diffInHours($n) // 41

Porque os valores tem essa diferença e porque a data de "ontem" tem diferença positiva maior que de amanha?
Comment: não deu certo a resposta?
Comment: @VirgilioNovic desculpe por não ter marcado.
Answer: Vamos criar um exemplo minimo, para exemplificar e mostrar o que acontece:
No primeiro resultado que é o código print_r( \Carbon\Carbon::yesterday() );
Carbon\Carbon Object
(
    [date] => 2018-01-14 00:00:00.000000
    [timezone_type] => 3
    [timezone] => America/Sao_Paulo
)

e no seu resultado que é o código: print_r( \Carbon\Carbon::now() );
Carbon\Carbon Object
(
    [date] => 2018-01-15 16:51:15.992829
    [timezone_type] => 3
    [timezone] => America/Sao_Paulo
)

a diferença em horas desses dois resultados pelo código:
print_r( \Carbon\Carbon::now()->diffInHours( \Carbon\Carbon::yesterday() ) );

é o valor de 40, porque, o primeiro resultado para chegar no dia 15 tem 24 horas + 16 horas da segunda é o valor de 40 horas de diferença.
No outro que o código geral como exemplo minimo:
print_r( \Carbon\Carbon::tomorrow() );
print_r( \Carbon\Carbon::now() );
print_r( \Carbon\Carbon::now()->diffInHours( \Carbon\Carbon::tomorrow() ) );

Saída:
Carbon\Carbon Object
(
    [date] => 2018-01-16 00:00:00.000000
    [timezone_type] => 3
    [timezone] => America/Sao_Paulo
)
Carbon\Carbon Object
(
    [date] => 2018-01-15 16:56:28.216548
    [timezone_type] => 3
    [timezone] => America/Sao_Paulo
)

tem uma diferença de 7 horas porque o dia 15/01/2018 16:56:28.216548 para chegar no dia 16/01/2018 faltam 7 horas.

Para saber se uma data e hora é maior que a outra:
\Carbon\Carbon::setLocale('pt_BR');

$result = \Carbon\Carbon::create(2012, 9, 6, 0, 0, 0)
            ->gt( \Carbon\Carbon::create(2012, 9, 6, 0, 0, 0) );

var_dump($result); // saída bool(false)

Comment: Se os resultados sempre pegaram o "menor para maior" como faço para saber quanto tempo já passou? Atualmente eu tenho um tempo em `microtime` e preciso saber se essa data que esta nesse `microtime` já passou ou não...
Comment: @RFL veja, isso que você relatou no comentário é outra coisa porém, exemplo: `microtime e preciso saber se essa data que esta nesse microtime já passou ou não` já passou onde? em relação o que?. No relato da sua pergunta está explicado o que perguntou inclusive é bem visível a diferença, mas, por favor tente colocar na sua pergunta o que precisa, e não o que o código faz somente! fico no aguardo.
Comment: quando disse "passar" me referi ao tempo mesmo...
com um microtime como posso fazer para saber se a data atual já é maior que a data do microtime.
Comment: @RFL se pode colocar isso como exemplo na sua pergunta? pra ficar como referencia!
Comment: @RFL o método para saber se uma data é maior que a outra é `gt` está editada a resposta, fiz de acordo pergunta utilizando `Carbon`


Enforcing that inputs sum to 1 and are contained in the unit interval in scikit-learn

Question: I have three inputs: x=(A, B, C); and an output y. It needs to be the case that A+B+C=1 and 0<=A<=1, 0<=B<=1, 0<=C<=1. I want to find the x that maximizes y. My approach is to use a regression routine in scikit-learn to train a model f on my inputs x and outputs y, and then use numpy.argmax on f to find x_best. How can I ensure that x_best=(A,B,C) sum to 1 and are all within the unit interval? Is there some special encoding I can use?
Answer: If I understand your question correctly, then it is simply quadratic programming - all the constraints you mentioned (both equalities and inequalities) are linear.
Comment: Hi, thanks for your answer, can you please see my edit? I forgot to mention that all of the values have to be within the unit interval, which I think breaks your solution.


Android stop permission promt for screen recording

Question: I am running some experiments where I need my workflow to be automated.
One of the tasks involves launching an android application I've made. This app records the display of the device and then after a minute or so, the app is killed via ADB.
Because the app is recording the screen, it prompts the user, saying:

I get that it is a security feature, but for testing or experimental purposes, is there any way to disable it or perhaps simulate the "Start now" click?
I've tried <uses-permission android:name="android.permission.PROJECT_MEDIA"/> but it has no effect.
Answer: You can disable it using the following adb command:
adb shell appops set com.your.app.id PROJECT_MEDIA allow

To revert, set it to ignore.
Comment: Great. This works for Anydesk. (First get list of the app id with `./adb shell pm list packages anyd`, then applied it for `./adb shell appops set com.anydesk.anydeskandroid PROJECT_MEDIA allow` and `./adb shell appops set com.anydesk.adcontrol.ad1 PROJECT_MEDIA allow`
Answer: Solved. Can't get rid of the dialog, but I can simulate a tap event at the location of the "Start now" button.
To do this, go to Developer Options and enable Pointer Location. This will show the coordinates of touch events in the top menu bar.
Open the app showing the dialog, tap the "Start now" button and note the coordinates of the touch event.
Now when you need to automatically accept the permissions, run the following ADB command:
adb shell input tap x y where x and y are the coordinates of the touch event.
Comment: how can we make it generic for all other device? and does adb commands works for you?
Comment: @ImtiyazKhalani I don't know - it worked for my needs so I did not look for  a generic way. I didn't try the adb commands since that answer cam 5 months after my question, so by that time I had already solved my problem. Try the adb commands and please let us know if they work.


Strategy for animating a large mesh in three.js?

Question: I am relatively new to three.js but not OpenGL (though it has been a while :-).  I am working my way though a bunch of examples to familiarize myself with three.js.  I decided to port some of the NeHe demos.  Most are easy enough (though educational).  Demo 11, however, is essentially creating a large (45x45) mesh of GL_Quads (in the old OpenGL) and mapping a texture to each set of vertices.  Then on each animation frame, then mesh's Z values are changed and the mesh re-created to cause it to ripple.
In OpenGL 1.x with C++ or Java, no big deal.  It works well to simply recreate the vertices and the texture mapping.  In three.js it was easy enough to code (changing each set of vertices to a pair of triangular faces, but the performance is abysmal.
I saw the demo of the waving cloth on the three.js site (http://threejs.org/examples/webgl_animation_cloth.html) which looks like it uses the shaders directly t o do the work.  So my question is, am I missing something (like there is an efficient way to do this without descending to the shader level) or is time for me to learn more about shaders?
Answer: A dynamic vertex update in js I threw together for you...
It runs pretty good on my machine... Is this similar to what you tried to implement?
Building terrain entirely on the GPU is feasible but pretty complicated, and for most cases involving terrain, you still need to have the actual mesh on the CPU side to interact with it/perform collision, etc. so you'll end up implementing both a GPU and CPU version.
Another approach is to generate the geometry on the CPU like in this example, but then use a custom shader to perform just texturing and lighting based on the information in the mesh.

var renderer = new THREE.WebGLRenderer();
var w = 300;
var h = 200;
renderer.setSize(w, h);
document.body.appendChild(renderer.domElement);

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
  45, // Field of view
  w / h, // Aspect ratio
  0.1, // Near
  10000 // Far
);
camera.position.set(15, 10, 15);
camera.lookAt(scene.position);
controls = new THREE.OrbitControls(camera, renderer.domElement);

var light = new THREE.PointLight(0x808080);
light.position.set(20, 20, 20);
scene.add(light);
var light1 = new THREE.AmbientLight(0x808080);
light1.position.set(20, 20, 20);
scene.add(light1);
var light2 = new THREE.PointLight(0x800000);
light2.position.set(-20, 20, -20);
scene.add(light2);
var light3 = new THREE.PointLight(0x0000FF);
light3.position.set(-20, -20, -20);
scene.add(light3);

var material = new THREE.MeshPhongMaterial({
  color: 0x808080
});
var planeGeom = new THREE.PlaneGeometry(10, 10, 45, 45);

var mesh = new THREE.Mesh(planeGeom, material);
scene.add(mesh);
renderer.setClearColor(0xdddddd, 1);

(function animate() {
  var t0 = performance.now() * 0.01;
  var t1 = t0 * 0.7;
  requestAnimationFrame(animate);
  controls.update();

  var sinm = (v, m) => {
    return Math.sin(v) * m
  }
  var noisefn = (x, y) => {
    return sinm((x * 0.2) + (y * 0.7) + t0, 1) + sinm((x * 0.9) + (y * 1.2) + t1, 0.3) + sinm((x * -0.9) + (y * 2.2) + t1, 0.4)
  }
  for (var i = 0; i < planeGeom.vertices.length; i++) {
    var v = planeGeom.vertices[i];
    v.z = noisefn(v.x, v.y);
  }
  planeGeom.verticesNeedUpdate = true;
  planeGeom.computeFaceNormals();
  planeGeom.computeVertexNormals();

  renderer.render(scene, camera);
})();

Answer: The answer in this case is that I can solve my problem with the ParametricGeometry since the shape and its variance is very simple.  A more complex surface (like a real 3D terrain) probably will require learning about shaders.  Sounds like fun, but think I'll walk before running.
UPDATE:  Using a ParametricGeometry works, and is faster but the performance is still poor.  So I'll look at other solutions, such as descending to the shader level.
Comment: With a bit more work I created this http://www.geofx.com/graphics/nehe-three-js/lessons09-16/lesson11/lesson11.html.  Works pretty well.
Answer: Yes you should use a shader for that.
If it doesn't need to be all dynamic from code but you could use pre-made data, using morph targets and the already existing shader for displaying those would work fine I think.
But for a fully dynamic thing like a water where you can throw stones I think you need your own  (similar) shader. Hopefully is easy enough with the examples etc., do share when get it done if you can :)


Get title attribute from string with regular expression

Question: string asd = "<area href='#' title='name' shape='poly' coords='38,23,242'/>"

how extract text from title atribute in c#
and then insert another atribute after title?
Answer: search : (?<=title=')[^']+
replace: something
demo here : http://regex101.com/r/nR3vQ8
something like this in your case:
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
    // This is the input string we are replacing parts from.
    string input = "<area href='#' title='name' shape='poly' coords='38,23,242'/>";

    // Use Regex.Replace to replace the pattern in the input.
    // ... The pattern N.t indicates three letters, N, any character, and t.
    string output = Regex.Replace(input, "(?<=title=')[^']+", "something");

    // Write the output.
    Console.WriteLine(input);
    Console.WriteLine(output);
    }
}

update
for taking out the title attribute as match use this:
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
    // First we see the input string.
    string input = "<area href='#' title='name' shape='poly' coords='38,23,242'/>";

    // Here we call Regex.Match.
    Match match = Regex.Match(input, @"title='(\w+)'",
        RegexOptions.IgnoreCase);

    // Here we check the Match instance.
    if (match.Success)
    {
        // Finally, we get the Group value and display it.
        string key = match.Groups[1].Value;
        Console.WriteLine(key);
    }
    }
}

output
name

Comment: I need replace the text after get title value, how get value of  title,. thanks in advance
Comment: @Alex which value are you talking about ? can you give an example
Comment: I need value from title attribute,.. in my example the value is 'name'
Comment: then dont replace it, just keep it in a capture group, wait i will update my answer
Comment: i just gave you a code sample, you can build upon the regex
Comment: I solve like this string matchString = Regex.Match(item, "", RegexOptions.IgnoreCase).Groups[1].Value;
Answer: Try this: In particular you may be interested in the HTMLAgilityPack answer.
Regex reg = new Regex("]*?title=\"([^\"]*?\"[^>]*?>");

A couple of gotchas:
This will match is case-sensitive, you may want to adjust that
This expects the title attribute both exists and is quoted
        Of course, if the title attribute doesn't exist, you probably don't want the match anyway?
To Extract, use the groups collection:
reg.Match("Howdy").Groups[1].Value

Comment: parses "] *? title =" ([^ "] *?" [^>] *?> "- No paired closing brackets).