text:
Q: Horizontal fling with list view: lag problems I implemented my gesture listener according to this topic: ListView Horizontal Fling Gesture
however, I can see that list scrolling is slower, sometimes (when you scroll very slowly) it blocks too.
I think the problem is in the listener: it takes time to compute values and so get the actual "left to right" fling I'm searching for...isn't there a more efficient way?
edit
Problem is here:
@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
            return false;
        }

        // right to left swipe
        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            System.out.println("right to left");
            animatedStartActivity(0);

            // right to left swipe
        }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            System.out.println("left to right");
            animatedStartActivity(1);
        }

        return false;
    }

evaluation of this method takes time
edit2:
I guess problem is because listview already has its own gesture listener and attaching mine overrides it. It is a problem because listview gesture listener takes in account speed and acceleration too, to give a nice moving effect. My listener is pretty raw, so list scrolling is not smooth anymore..
Even if my onFLing method always returns false (so it does not consume the event) list scrolling is affected...
edit3:
Ok maybe I found the solution but I need your help!
I can set the onTouchListener on the container layout, problem is that listview actually overrides parent's onTouch so I need to reverse the situation: onTouchEvent on listview has to be intercepted by the parent, so that returning false it is brougth to listview

A: SOLVED!!!
Problem was that ListView's onTouchEvent performed some other operations! So I extended ListView:
public class FlingListView extends ListView{

private GestureDetector detector; //this is my detector

public void setDetector(GestureDetector detector){
    this.detector = detector;
}

public FlingListView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public FlingListView(Context context,AttributeSet set) {
    super(context,set);
    // TODO Auto-generated constructor stub
}

public FlingListView(Context context,AttributeSet set, int a) {
    super(context,set,a);
    // TODO Auto-generated constructor stub
}

     //here I do the magic
@Override
public boolean onTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    super.onTouchEvent(ev); //I always do the list on touch event
    return(detector.onTouchEvent(ev)); //..but I return the detector!

}
 }

I don't know if this is the best solution but still...it works!


text:
Q: Magento REST API OAuth for mobile app I'm developing an iOS app that uses the Magento REST API, I'm following the documentation provided by Magento for the OAuth authentication (http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html)
I use the initiate endpoint to get the request token but then when I want to authorize this token I need to use the "authorize" endpoint and there I get redirected to a URL where I have to provide customer credentials to authorize the request token. This is not the behaviour that I was expecting since the user would be already logged in using the app's login (not implemented yet). Is there a way of making this "authorization" step transparent for the user? Like calling some service passing it the user's credentials provided in the login screen of my app?
If there is no way I'll use the Magento's SOAP API

A: I did that too really really painful Magento use OAuth1.x, basically you've got three options:

*

*Do it yourself

*Use some oAuth consumer lib, you can find them on github

*Use MKNetworkKit with this add-on
I used the 3rd because oaf MKNetworkKit, and anyway there was still a lot of work to do, if you want to hide some passages injecting js.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Use SourceTree to move git branch pointer for non-active branches I've found this question on moving branch pointers without doing a checkout. Basically I want to know how to do exactly that, in SourceTree.
So for example, suppose I'm on a local branch feat/foo. I've got master too, and can fetch a few new commits from origin/master. Here's a screenshot:

I want to set my local master pointer from 77f97cf to 85c2fd7, where origin/master is pointing to as well, without switching branches or changing my working copy.
I've tried:

*

*the context menu for the origin/master commit

*the context menu for the master commit

*looking through the menus

*the extra options in the Fetch dialog

*Google-fu that combines the info from aforementioned question and "sourcetree"

To no avail.
Is this possible in SourceTree?

A: *

*Stash your changes in your branch foo

*checkout master (right click on master)

*In master branch, right click to commit which you want to reset your local repo

*click "reset master to this commit"

*choose your using mode. (if you have changes and you want to reset all choose 'hard')

*click ok

*change to your branch foo (right click on foo and checkout)

*merge master into foo (right click on master)

Your master will be changed to that commit and sourcetree will show you that you need to pull. After that you can merge your local master to your local repo.

A: I don't think it's possible in SourceTree, but it's possible in one command after clicking on the Terminal button. I often need this for submodules that I modify without first remembering to checkout a branch. See this answer:
https://stackoverflow.com/a/5471197/47078


text:
Q: Multiple terraform project sharing infrastructure I have two terraform projects.  For both projects I am using same credentials and state is stored in S3 bucket.  In the first project I create the vpc and the subnets.  In the 2nd project I am creating an RDS.  I want to put the RDS in the vpc and subnets created in the 1st terraform project.  How do I do that?
Thanks!

A: In the RDS project, pull in the VPC and subnets as data resources. You can pull in the VPC like so:
data "aws_vpc" "my_vpc" {
    id = var.vpc_id
}

And you can reference that as data.aws_vpc.my_vpc.
Depending on your use case, you might want the subnet_ids or subnets data resources to reference subnets as a group.
Data resources are a powerful way to bridge this kind of gap, but if you're not careful with them it can lead to some nasty dependency issues in your build. Keeping networking away from application resources is a sensible division, but consider merging the projects if you expect the networking to change frequently.


text:
Q: I get this undefined reference error when I try to install this Perl module I am using msys2 for mingw and am trying to download this Params::Validate module.  I get this error, but can't find online what the problem is.  I would really appreciate it if you could tell me what's wrong and how to fix it.
Thanks!
cpan[1]> install Params::Validate
lib/Params/Validate/XS.o:XS.c:(.text+0x34c): undefined reference to  'Perl_hv_common_key_len'
lib/Params/Validate/XS.o:XS.c:(.text+0x34c): relocation truncated to fit:
R_X86_64_PC32 against undefined symbol 'Perl_hv_common_key_len'
collect2: error: ld returned 1 exit status
error building blib/arch/auto/Params/Validate/XS/XS.dll from
lib/Params/Validate/XS.o at /usr/share/perl5/core_perl/ExtUtils/CBuilder/Base.pm line 320.
  DROLSKY/Params-Validate-1.19.tar.gz
  ./Build -- NOT OK
Failed during this command:
 DROLSKY/Params-Validate-1.19.tar.gz          : make NO

A: You have a very old installation of perl. The Perl_hv_common_key_len was added in Perl v5.8.9 which is nearly seven years ago, so you are running an even earlier release of v5.8. Much of the world is now running v5.22 so I suggest that you update


text:
Q: Cannot use string offset as an array breaks in php5.2, not in php5.4 I've got this problem with php, and I guess the worst part is that it's working fine on my dev environment (php v5.4) but breaks on the test/live site on the webserver (php v5.2).
So when I var_dump my $_POST["formData"] I get an array that looks like this:
array(42) {
    [0] => array(2) {
        ["name"] => string(2) "id";
        ["value"] => string(4) "3972";
    }
    [1] => array(2) {
        ["name"] => string(2) "action";
        ["value"] => string(4) "edit";
    }
...
}

To separate this, I use this (or some variation of this):
for($i=0;$i<count($_POST["formData"]);$i++) {
    $data[$_POST["formData"][$i]["name"]] = $_POST["formData"][$i]["value"];
}

So I end up being able to access everything with:
foreach($data as $key => $value) {
    echo $key . " = " . $value . "<br />";
}

which outputs:
id = 3972
action = edit
...

So, again, this works just fine on my dev server, but breaks on the live site.  I've looked around here and found a lot of examples, but it seems a lot of them are using examples that aren't working quite the same.
What's causing this? Is it some setting? Is it a change between the two versions? I've tried a couple other things but none of them have worked and it's kinda a pain testing on the testing server (uploading files one at a time...yay...).  Any easy solution or do I have to rebuild my script?

A: That error suggests you're using a string as if it were an array. I'll assume it's your for loop. I'm not entirely sure, but $data could be being implicitly initialised to an empty string, which you are then trying to dereference and assign to. Does rewriting it like this help?
$data = array();
foreach($_POST['formData'] as $kvp) {
    $data[$kvp['name']] = $kvp['value'];
}

This code is also faster, because you're not calling count() in a loop.

A: It turns out this is indeed a difference between PHP versions, as demonstrated by this handy comparison tool.
For reference, the somewhat confusing error comes about (prior to PHP 5.4) from the following two steps:

*

*You take a variable that you think is an array, but is actually a string, and you access an "element" of it, e.g. $foo[1] or $foo['bar']. PHP takes this to mean "get the Nth character of the string" - $foo[1] means the 2nd character of $foo, and $foo['bar'] means the first, because the bar gets converted to 0.

*You then access that as though it's an array. Newer versions of PHP just repeat step 1 on the 1-character string you ended up with, but until PHP 5.4 this caused the ugly error.

So in some situations, your $_POST["formData"] is not an array, but a string. This is probably happening sometimes on both environments, but the difference in error handling is masking it in one environment and not the other.


text:
Q: Lining up the boxes with negative entries in a Young tableau Given the partition (5,2), I would like the boxes in the following Young tableau to line up:
\documentclass{article}
\usepackage[enableskew]{youngtab}
\begin{document}
$\young({-3}{-2}{-1}01,:23)$
\end{document}

More specifically, the box containing 2 should be below the box containing -2 and the box containing 3 should be below the box containing -1, and I would like the boxes to all have the same size.

A: You could use a different package called ytableau, where it seems to be easer to achieve what you want, since the syntax is more "tabular-like". \none is used to have no box at the first place of the second line. Set the boxsize to a value you like.
MWE
\documentclass{article}
\usepackage{ytableau}
\begin{document}
\ytableausetup{mathmode, boxsize=2em}
\begin{ytableau}
-3 & -2 & -1 & 0 & 1\\
\none & 2 & 3\\
\end{ytableau}
\end{document}


text:
Q: Repaint UILabel UPDATE: As I'm not able to solve this issue, I've done a ugly workaround (added another label).
I'm currently trying to set the position of an UILabel within the following steps:
1) Update Text of the Label
lblFirstWheelDescription.text = @"Select the tooth shade";

2) Set new position for the UILabel
CGRect newframe = lblFirstWheelDescription.frame;
newframe.origin.y += 100;
lblFirstWheelDescription.frame = newframe;

Now what's confusing me. When the method is called the first time, nothing happends (UILabel doesn't move like set before). On the second call (same method), the initial y-value of lblFirstWheelDescription.frame hasn't been increased by 100. After the y-value is set another time while second method call, the label moves and y-value is increased.
I tried to force a repaint as follows - doesn't change anything:
[self.superview setNeedsLayout];

Does anybody know this behavior or knows whats wrong here ?
ihkawiss

A: Maybe you're assuming your function is being called when in fact it isn't? Try adding a logging statement NSLog("TESTING"); to see when and how many times your function is being called.
Also, what is calling this function?

A: you have to redraw the label. the viewwillappear call when viewcontroller redraw its view. You have to force redraw your label on the view.

A: I've noticed in the past that changing the properties of a CGRect doesn't make the UI element update:
UILabel *label = [UILabel alloc] initWithFrame:CGRectMake(0,0,100,20)];
label.frame.size.width += 100; // does nothing

To make this work correctly, you need to create a new CGRect and assign it to the frame property instead of trying to modify the value of the existing frame object (which is what you original code is doing).
label.frame = CGRectMake(0, 0, 200, 20);

You can animate this change if you like using [UIView animateWithDuration:animations] easily enough, going from CGRect instance 1 to CGRect instance 2... you cannot just modify the properties of the existing frame.

A: You can update the label according to your need but you have to redraw label in this loop  which you want to show from this link
Check the Mert answer

A: You need to call setNeedsDisplay from your view controller
[ViewController.view setNeedsDisplay];

That will force your view and its subviews to update/repaint


text:
Q: DLLMain The value of ESP was not properly saved across a function call When I try injecting the C++ dll into the process I end up getting the following error
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function pointer declared with a different calling convention."
I'm certain that the cause of the error is because of the DLLMain I very well could be wrong.
BOOL WINAPI DllMain (HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
    switch( dwReason )
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Inject, 0, 0, 0);
        break;
    }
    return TRUE;
}

This is the inject function
VOID Inject() {
    QWORD time;
    DWORD id, pid;
    HANDLE hSs, hThread;
    HMODULE hMono;
    THREADENTRY32 t;
    FILETIME CreationTime, ExitTime, KernelTime, UserTime;
    CONTEXT context = { CONTEXT_CONTROL };
    // poll for mono

    while ((hMono = GetModuleHandle("mono.dll")) == NULL) Sleep(10);

    mono_security_get_mode = (DWORD (__cdecl *)(void))GetProcAddress(hMono, "mono_security_get_mode");
    mono_security_set_mode = (void (__cdecl *)(DWORD))GetProcAddress(hMono, "mono_security_set_mode");
    mono_domain_get = (PVOID (__cdecl *)(void))GetProcAddress(hMono, "mono_domain_get");
    mono_domain_assembly_open = (PVOID (__cdecl *)(PVOID,PCHAR))GetProcAddress(hMono, "mono_domain_assembly_open");
    mono_assembly_get_image = (PVOID (__cdecl *)(PVOID))GetProcAddress(hMono, "mono_assembly_get_image");
    mono_class_from_name = (PVOID (__cdecl *)(PVOID,PCHAR,PCHAR))GetProcAddress(hMono, "mono_class_from_name");
    mono_class_get_method_from_name = (PVOID (__cdecl *)(PVOID,PCHAR,DWORD))GetProcAddress(hMono, "mono_class_get_method_from_name");
    mono_runtime_invoke = (PVOID (__cdecl *)(PVOID,PVOID,PVOID *,PVOID))GetProcAddress(hMono, "mono_runtime_invoke");

    // mono executes with thread local data, get the main thread.
    id = NULL;
    pid = GetCurrentProcessId();
    hSs = CreateToolhelp32Snapshot(TH32CS_SNAPALL, pid);

    t.dwSize = sizeof(THREADENTRY32);

    if (hSs) {
        // set time to max value so we can find the oldest thread
        time = 0xFFFFFFFFFFFFFFFF;
        if (Thread32First(hSs, &t)) {
            do {
                if (t.th32OwnerProcessID == pid) {
                    hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, t.th32ThreadID);
                    if (hThread) {
                        if (GetThreadTimes(hThread, &CreationTime, &ExitTime, &KernelTime, &UserTime)) {
                            // nasty casting lol
                            if (time > *(PQWORD)&CreationTime) {
                                time = *(PQWORD)&CreationTime;
                                id = t.th32ThreadID;
                            }
                        }
                        CloseHandle(hThread);
                    }
                }
            } while (Thread32Next(hSs, &t));
        }
    }
    else {
        Deject("Couldn't acquire the main thread.");
        return;
    }

    if (id) {
        // hijack the main thread and have it inject our c# code
        hThread = OpenThread(THREAD_QUERY_INFORMATION | THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, FALSE, id);
        if (hThread) {
            SuspendThread(hThread);
            if (GetThreadContext(hThread, &context)) {
                dwReturn = context.Eip;
                context.Eip = (DWORD)MonoInject;
                SetThreadContext(hThread, &context);
            }
            ResumeThread(hThread);
            CloseHandle(hThread);
        }
        else {
            Deject("Couldn't hijack the main thread, BALLS!");
            return;
        }
    }
}


text:
Q: Is Sam Tarly the only person in the current age to have killed a White Walker? Sam Tarly, a brother of the Night's Watch, bravely stabbed a White Walker to protect Gilly and her "little monster" (unnamed in the books, if I recall).  Sam's weapon of choice was a dragonglass dagger given to him by Jon Snow from a cache of weapons north of the Wall.
Since the Battle of Dawn, has no one else encountered a White Walker and survived?  Has no other character been given the opportunity to try a dragonglass or Valyrian steel weapon?
I use only the books tag, I know in the show Lord Snow killed two (one at Hardhome and one in the wight hunting expedition) and Meera killed one with a dragonglass spear in the Three-Eye Raven cave.

A: Yes
In fact the Others haven't been seen in centuries, the first time they resurface is in the prologue of A Game of Thrones and even then Gared is seen as a mad man rather than taken seriously.
Most people in Westeros don't believe they ever existed and they are placed into the same sort of category as grumpkins.

Unique in the Seven Kingdoms is the Night's Watch, the sworn brotherhood that has defended the Wall over centuries and millennia, born in the aftermath of the Long Night, the generation-long winter that brought the Others down on the realms of men and nearly put an end to them.
The history of the Night's Watch is a long one. Tales still tell of the black knights of the Wall and their noble calling. But the Age of Heroes is long done, and the Others have not shown themselves in thousands of years, if indeed they ever existed.
The World of Ice and Fire, The Wall and Beyond: The Night's Watch


text:
Q: How do I set a caption for my generated code block in sphinx Currently I am using the following code to generate a code block and show some information in it.
I'd like to set a caption like with the following rst directive.
.. code-block:: python
   :caption: my_file.py

Currently I am using the following code but it
from docutils import nodes
from docutils.parsers.rst import Directive, directives

class ExecuteCode(Directive):

    def run(self):
        output = []
        input_code = nodes.literal_block(shown_code, shown_code)

        # This creates a normal text directly above the code block
        output.append(nodes.caption(text=self.options['header_code']))

        # This doesn't do anything at all
        input_code['caption'] = nodes.caption('asdf', 'asdf')

        return output

How can I set the caption on the literal_block?


text:
Q: Titleize Jekyll category I'd like to convert the printed category names of my posts into title case. I couldn't find a Liquid filter that would work. I tried using dashes and the camelcase filter, but no dice.
Alternatively, I'd like to print the category name as it's written in the YAML frontmatter.
For instance, for a post with:
category: Here's the Category

When I reference the name:
{% for cat in site.categories %}

{{ cat[0] }}

{% endfor %}

I see "here's the category" on the page. I would like to see "Here's the Category" or even "Here's The Category," and I could replace (replace: 'The', 'the') the few articles that I wanted to be downcase.
EDIT
For anyone as desperate as I am, this disgusting hack works, where n is the max number of words you have in a category title.
{% for cat in site.categories %}
    {% assign words = cat[0] | split: ' ' %}

{{ words[0] | capitalize | replace:'The','the'}} {{ words[1] | capitalize }} {{ words[2] }} {{ words[3] | capitalize }} {{ words[4] | capitalize }} {{ words[n] | capitalize }}

{% endfor %}

I'm going to leave the question unanswered in case someone knows a more elegant method.

A: You can achieve a part of what you want by using the capitalize filter:
Input
{{ 'capitalize me' | capitalize }}

Output
Capitalize me

Source.
Another possibility, which I didn't test for its edge cases, is to use join and camelize:
{{ "here's the category" | join: '-' | camelize }}

It should print "Here's The Category", but camelize might have a problem with here's.

A: Just use {{ category.first | capitalize }} is OK for my case, without additional '' on category.

A: Instead of manually stepping through words 0 to n, one can use another for loop as follows:
{% for category in site.categories %}
  {% assign words = category | first | split: ' ' %}
  {% for word in words %}
    {{ word | capitalize | replace: 'The','the' }}
  {% endfor %}
{% endfor %}

A: I know that this is old but it helped me to solve my problem and it could help others.
The solution I came was:
{% for category in site.categories %}

    {{category[0]}}

{% endfor %}

This list all the blog categories (most used for building a menu)
It turns into:

  Dicas

  Diário de bordo

Thank you for giving me a clue.
You can check another filters in: http://jekyllrb.com/docs/templates/#filters

A: Name pages in Kabab-case as you want them to appear, then use replace:
{{ category.name | replace: '-', ' '}}

Don't-Capitalize-the becomes Don't Capitalize the and Capitalize-The becomes Capitalize The

A: This solutions is a little more overwrought, but you can adapt the author data file solution from the Jekyll site to work with categories.
In your _data folder, make a file called categories.yml. Put in something like this:
my-first-category:
  name: My First Category

another-category:
  name: Another Category

Then, you can loop through your categories like this:
{% for category in site.categories %}
    {% assign category_slug = category[0] %}
    {% assign category_data = site.data.categories[category_slug] %}
    {% if category_data %}
        {{ category_data.name }}
    {% endif %}
{% endfor %}

Side note: I'm not sure why I needed the category_slug assign. I didn't need it when looping through post.categories.
This increases overhead by adding an extra file, but opens the door for other data that can get attached to objects like a category image or description. You can be more granular over your names. This is a pretty readable solution too, which is nice.

A: I went the other way around. I hard coded my page title in Title case and use downcase, upcase and capitalize liquid filter in other pages.


text:
Q: Watir Webdriver - Cucumber - Grid Execution I have few stories written in Cucumber feature file and i have step definitions for those as well. Right now the feature files are running sequentially and  the execution is taking more time. I have used Selenium Webdriver grid and i know the set up for the same. Is there anyway to integrate Grid with Cucumber ? I am using page Object model in my framework.

A: There is an articles written by continuousqa on his site - http://sdet.us/selenium-grid-with-watir-and-cucumber-browser-automation/ that will provide you with all you need.
Also you can check this gem - parallel_tests for more lightweight solution.


text:
Q: Dragging in processing.js I am a physics teacher in London and I am trying to learn processing.js
To make teaching resources a very important technique is to be able to drag shapes around.  Although I know how to do this in PJS, I have found that the code for having several draggable objects quickly gets messy.  (especially if the object is "locked", so that it does not matter if the cursor goes off the object)
Does anybody know how to run the dragging spript from a separate file?  i.e. so that the main script calls the dragging script for objects?  The idea is that you would draw shapes and simply make them draggable, with the dragging code in a separate file?  This would make the creation of teacher resources a lot easier.
It would be great if people could provide some ideas on this.  I have seen the drag demos on the main PJS website, but I am looking for something quicker/easier.
Many thanks
Matt Klein
ruby_murray1[AT]hotmail.com

A: Well, I do processing.js in pure javascript code without bothering with the Processing syntax but it should go something similar:

*

*Make the objects that you want draggable adhere to a Draggable interface, the draggable interface indicates what is draggable and provides a method to move an object

*When drag starts, see if there is a Draggable object under the mouse that you want to drag, store it locally and use the Draggable interface method to move the object around. This way your local dragging code is generic to any Draggable object and objects handle their own movement.

*On drag end, remove the Draggable object from your local store (and stop calling its move method).

You could pull out this entire dragging logic into an external file as well, as long as you hook it into the correct mouse events.
About Interfaces: http://forum.processing.org/topic/class-interface-block-example


text:
Q: How do I configure opensearch as a logstash output properly, I am getting a host unreachable error so I am currently connected to a contabo hosted kubernetes cluster. On there I have running kafka and opensearch/opensearch dashboards deployements. I am trying to run logstash so that I can get the data from a kafka topic to opensearch, https://hub.docker.com/r/opensearchproject/logstash-oss-with-opensearch-output-plugin this is the image that I use for logstash (https://justpaste.it/47676 this is my logstash configuration). And the following is my opensearch configuration  https://justpaste.it/a090p
When I deploy logstash, I successfully get the data from the kafka topic, so my input plugin is working as expected, but the output is not, I am failing to output data to opensearch from logstash. The following is the logs from the logstash pod: https://justpaste.it/620g4 .
This is the output of "kubectl get services"
NAME                                  TYPE           CLUSTER-IP       EXTERNAL-IP
PORT(S)                               AGE
dashboards-opensearch-dashboards      ClusterIP      10.96.114.252    <none>        5601/TCP                              5d20h
grafana                               ClusterIP      10.107.83.28     <none>        3000/TCP                              44h
logstash-service                      LoadBalancer   10.102.132.114   <pending>     5044:31333/TCP                        28m
loki                                  ClusterIP      10.99.30.246     <none>        3100/TCP                              43h
loki-headless                         ClusterIP      None             <none>        3100/TCP                              43h
my-cluster-kafka-0                    NodePort       10.101.196.50    <none>        9094:32000/TCP                        53m
my-cluster-kafka-1                    NodePort       10.96.247.75     <none>        9094:32001/TCP                        53m
my-cluster-kafka-2                    NodePort       10.98.203.5      <none>        9094:32002/TCP                        53m
my-cluster-kafka-bootstrap            ClusterIP      10.111.178.24    <none>        9091/TCP,9092/TCP,9093/TCP            53m
my-cluster-kafka-brokers              ClusterIP      None             <none>        9090/TCP,9091/TCP,9092/TCP,9093/TCP   53m
my-cluster-kafka-external-bootstrap   NodePort       10.109.134.74    <none>        9094:32100/TCP                        53m
my-cluster-zookeeper-client           ClusterIP      10.98.157.173    <none>        2181/TCP                              54m
my-cluster-zookeeper-nodes            ClusterIP      None             <none>        2181/TCP,2888/TCP,3888/TCP            54m
opensearch-cluster-master             ClusterIP      10.98.55.121     <none>        9200/TCP,9300/TCP                     19h
opensearch-cluster-master-headless    ClusterIP      None             <none>        9200/TCP,9300/TCP                     19h
prometheus-operated                   ClusterIP      None             <none>        9090/TCP                              25m
prometheus-operator                   ClusterIP      None             <none>        8080/TCP                              50m

What am I doing wrong and how do I establish this connection?

A: I figured it out. I think that it was expecting an ssl certificate and that is why it was refusing the connection. The way that I "fixed" this (because I don't need the ssl certification for this project for now) is that I changed the logstash configuration in this way.
  logstash.conf: |
    input {
        kafka{
          codec => json
          bootstrap_servers => "10.111.178.24:9092"
          topics => ["t_events"]
        }
    }
    output {
       opensearch {
          hosts       => ["https://10.102.102.109:9200"]
          ssl_certificate_verification => false
          user        => "admin"
          password    => "admin"
          index       => "logstash-logs-%{+YYYY.MM.dd}"
        }
    }

So I have added the "ssl_certificate_verification => false" line to the config and that enabled me to connect from logstash to opensearch and send the data. Now I have the data encryption aspect by using a https protocol but I am lacking the ssl authentication which I am fine with for this project.


text:
Q: In Python 3, how do I convert a file:// URL to an OS path with code that works in both Linux and Windows? Here is code that demonstrates the problem when converting a file:// URL to an OS path.
import os
import pathlib
import sys
import urllib.parse

print ("sys.argv[0]      = {0}".format(sys.argv[0]))

varFilename = sys.argv[0]
varFilename = os.path.abspath(varFilename)
print ("abs varFilename  = {0}".format(varFilename))

varMainFolder = os.path.dirname(varFilename)
print ("varMainFolder    = {0}".format(varMainFolder))

varTarget = os.path.join(varMainFolder,"test test.py")
print ("varTarget        = {0}".format(varTarget))

varURL = pathlib.Path(varTarget).as_uri()
print ("varURL           = {0}".format(varURL))

varPathRaw = urllib.parse.urlparse(varURL).path
print ("varPathRaw       = {0}".format(varPathRaw))

varPathDecode = urllib.parse.unquote(varPathRaw)
print ("varPathDecode    = {0}".format(varPathDecode))

varOSPath = os.path.normpath(varPathDecode)
print ("varOSPath        = {0}".format(varOSPath))

In Linux, this code prints:
sys.argv[0]      = test.py
abs varFilename  = /home/ldbader/test.py
varMainFolder    = /home/ldbader
varTarget        = /home/ldbader/test test.py
varURL           = file:///home/ldbader/test%20test.py
varPathRaw       = /home/ldbader/test%20test.py
varPathDecode    = /home/ldbader/test test.py
varOSPath        = /home/ldbader/test test.py

Notice the varOSPath is a perfectly valid absolute path.  But in Windows, the code prints:
sys.argv[0]      = test.py
abs varFilename  = C:\mli\Junk\test.py
varMainFolder    = C:\mli\Junk
varTarget        = C:\mli\Junk\test test.py
varURL           = file:///C:/mli/Junk/test%20test.py
varPathRaw       = /C:/mli/Junk/test%20test.py
varPathDecode    = /C:/mli/Junk/test test.py
varOSPath        = \C:\mli\Junk\test test.py

Notice that varOSPath has an absolute path preceded by an invalid backslash. Attempting to open a file with this path will fail.  I would have expected os.path.normpath() to discard a slash to the left of a drive specification, but it doesn't.
What should I do so the same logic gives me a valid absolute path on both platforms?

A: Well, this is my answer.  It appears to work for my scenarios, but I am not sure what will happen if a Linux user creates a folder named /C: (or any other name that looks like a Windows drive letter).
import os
import pathlib
import sys
import urllib.parse

print ("sys.argv[0]      = {0}".format(sys.argv[0]))

varFilename = sys.argv[0]
varFilename = os.path.abspath(varFilename)
print ("abs varFilename  = {0}".format(varFilename))

varMainFolder = os.path.dirname(varFilename)
print ("varMainFolder    = {0}".format(varMainFolder))

varTarget = os.path.join(varMainFolder,"test test.py")
print ("varTarget        = {0}".format(varTarget))

varURL = pathlib.Path(varTarget).as_uri()
print ("varURL           = {0}".format(varURL))

varPathRaw = urllib.parse.urlparse(varURL).path
print ("varPathRaw       = {0}".format(varPathRaw))

varPathDecode = urllib.parse.unquote(varPathRaw)
print ("varPathDecode    = {0}".format(varPathDecode))

varOSPath = os.path.normpath(varPathDecode)
print ("varOSPath        = {0}".format(varOSPath))

varFixedPath = varOSPath
varDrive = os.path.splitdrive(varFixedPath[1:])[0]
print ("varDrive         = {0}".format(varDrive))
if varDrive:
    varFixedPath = varFixedPath[1:]
print ("varFixedPath     = {0}".format(varFixedPath))

The trick is to use os.path.splitdrive() on the absolute path after removing the first character.  For a Windows absolute path, it will return the drive specification.  For a Linux absolute path, it will return an empty string.  If the drive specification is an empty string, use the absolute path as is.  If the drive specification is not an empty string, remove the first character from the absolute path and use the result.
I still believe that the os.path.normpath() method should not return an absolute Windows path with a leading backslash.


text:
Q: Google App Engine Entity Ownership I am writing an app for GAE in Python which stores recipes for different users. I have an entity called User in the datastore and an entity called Recipe. I want to be able to set the owner of each Recipe to the User who created it. Also, I want each User entity to contain a list of all Recipes belonging to that User as well as being able to query the Recipe database to find all Recipes owned by a particular User.
What is the best way to go about creating this parent/child type relationship?
Thanks

A: There are two main ways.  (I am going to assume your using python which defines examples)
Option 1. Make the User the ancestor of all of their recipes
recipe = Recipe(parent=user.key)

Option 2.  Use key property
class Recipe(ndb.Model):
    owner = ndb.KeyProperty()

recipe = Recipe(owner=user.key)

all recipes for user with option 1
recipes = Recipe.query(ancestor=user.key)

all recupes for user with option 2
recipes = Recipe.query().filter(Recipe.owner == user.key)

Which one you use really depends a lot on what you plan to do with the data after creation, transaction patterns etc....  You should elaborate on your use cases.  Both will work.
Also you should read up on transactions entity groups and understand them to really determine if you want to use ancestors https://developers.google.com/appengine/docs/java/datastore/transactions?hl=en .

A: If you use db.Model, to model one-to-many relationship, you can use the RefernenceProperty constructor and specify a collection_name. For example, one book may have many reviews.

    class Book(db.Model):
    title = db.StringProperty()
    author = db.StringProperty()

    class BookReview(db.Model):
        book = db.ReferenceProperty(Book, collection_name='reviews')

    b = Book()
    b.put()
    br = BookReview()
    br.book = b # sets br's 'book' property to b's key

    for review in b.reviews:# use collection_name to retrieve all reviews for a book
        ....

see https://developers.google.com/appengine/docs/python/datastore/datamodeling#references
Alternatively, you can use ndb's KeyProperty as in Tim's answer.
Also see
db.ReferenceProperty() vs ndb.KeyProperty in App Engine


text:
Q: Differences between ActionExecutingContext and HttpActionContext When I add a filter attribute to an api controller it doesn't work because of using ActionExecutingContext. When I find the solution which is I have to use HttpActionContext it works fine. So what is the major differences between them ?

A: I can see that in one of my earlier MVC solutions, my custom filter used ActionExecutingContext. In that solution, the packages.config says:
package id="Microsoft.AspNet.Mvc" version="4.0.20710.0"

In a newer MVC solution, when I create a similar custom attribute / filter, the override for OnActionExecuting wants me to now pass in a HttpActionContext.. and that NuGet is:
package id="Microsoft.AspNet.Mvc" version="5.2.3"

I'm still researching what the difference is, too. But, I can definitely see they changed this up between versions of AspNet.Mvc


text:
Q: (34, 'Numerical result out of range') calculating Annual Percentage Rate with scipy I am trying to solve Annual Percentage Rate in Python using scipy library and newton method. At some point Python reaches max Pythonic float range solving this equation:

Here is example code with data that fails. Is there anything that I can use (interval etc.) that is able to solve this equation?
from scipy.optimize import newton

class ARP:
    def __init__(self):
        self.year_days = 365
        self.table = [[0, 416.0, '2022-04-01', 0, 0, 0, 0, 0], [1, 75.92, '2022-04-02', 1, 1, 0, 0, 0], [2, 75.92, '2022-05-02', 30, 1, 0, 1, 0], [3, 90.92, '2022-06-02', 31, 1, 0, 2, 0], [4, 75.92, '2022-07-02', 30, 1, 0, 3, 0], [5, 75.92, '2022-08-02', 31, 1, 0, 4, 0], [6, 90.92, '2022-09-02', 31, 1, 0, 5, 0], [7, 75.92, '2022-10-02', 30, 1, 0, 6, 0], [8, 90.92, '2022-11-02', 31, 1, 0, 7, 0], [9, 75.92, '2022-12-02', 30, 1, 0, 8, 0], [10, 75.92, '2023-01-02', 31, 1, 0, 9, 0], [11, 90.92, '2023-02-02', 31, 1, 0, 10, 0], [12, 75.92, '2023-03-02', 28, 1, 0, 11, 0], [13, 90.92, '2023-04-02', 31, 1, 0, 12, 0], [14, 782.9, '2023-05-02', 30, 1, 0, 13, 0], [15, 732.9, '2023-06-02', 31, 1, 0, 14, 0], [16, 732.9, '2023-07-02', 30, 1, 0, 15, 0], [17, 732.9, '2023-08-02', 31, 1, 0, 16, 0], [18, 732.9, '2023-09-02', 31, 1, 0, 17, 0], [19, 732.9, '2023-10-02', 30, 1, 0, 18, 0], [20, 732.9, '2023-11-02', 31, 1, 0, 19, 0], [21, 732.9, '2023-12-02', 30, 1, 0, 20, 0], [22, 732.9, '2024-01-02', 31, 1, 0, 21, 0], [23, 732.9, '2024-02-02', 31, 1, 0, 22, 0], [24, 732.9, '2024-03-02', 29, 1, 0, 23, 0], [25, 732.9, '2024-04-02', 31, 1, 0, 24, 0], [26, 782.9, '2024-05-02', 30, 1, 0, 25, 0], [27, 732.9, '2024-06-02', 31, 1, 0, 26, 0], [28, 732.9, '2024-07-02', 30, 1, 0, 27, 0], [29, 732.9, '2024-08-02', 31, 1, 0, 28, 0], [30, 732.9, '2024-09-02', 31, 1, 0, 29, 0], [31, 732.9, '2024-10-02', 30, 1, 0, 30, 0], [32, 732.9, '2024-11-02', 31, 1, 0, 31, 0], [33, 732.9, '2024-12-02', 30, 1, 0, 32, 0], [34, 732.9, '2025-01-02', 31, 1, 0, 33, 0], [35, 732.9, '2025-02-02', 31, 1, 0, 34, 0], [36, 732.9, '2025-03-02', 28, 1, 0, 35, 0], [37, 732.9, '2025-04-02', 31, 1, 0, 36, 0], [38, 782.9, '2025-05-02', 30, 1, 0, 37, 0], [39, 732.9, '2025-06-02', 31, 1, 0, 38, 0], [40, 732.9, '2025-07-02', 30, 1, 0, 39, 0], [41, 732.9, '2025-08-02', 31, 1, 0, 40, 0], [42, 732.9, '2025-09-02', 31, 1, 0, 41, 0], [43, 732.9, '2025-10-02', 30, 1, 0, 42, 0], [44, 732.9, '2025-11-02', 31, 1, 0, 43, 0], [45, 732.9, '2025-12-02', 30, 1, 0, 44, 0], [46, 732.9, '2026-01-02', 31, 1, 0, 45, 0], [47, 732.9, '2026-02-02', 31, 1, 0, 46, 0], [48, 732.9, '2026-03-02', 28, 1, 0, 47, 0], [49, 732.9, '2026-04-02', 31, 1, 0, 48, 0], [50, 782.9, '2026-05-02', 30, 1, 0, 49, 0], [51, 732.9, '2026-06-02', 31, 1, 0, 50, 0], [52, 732.9, '2026-07-02', 30, 1, 0, 51, 0], [53, 732.9, '2026-08-02', 31, 1, 0, 52, 0], [54, 732.9, '2026-09-02', 31, 1, 0, 53, 0], [55, 732.9, '2026-10-02', 30, 1, 0, 54, 0], [56, 732.9, '2026-11-02', 31, 1, 0, 55, 0], [57, 732.9, '2026-12-02', 30, 1, 0, 56, 0], [58, 732.9, '2027-01-02', 31, 1, 0, 57, 0], [59, 732.9, '2027-02-02', 31, 1, 0, 58, 0], [60, 732.9, '2027-03-02', 28, 1, 0, 59, 0], [61, 732.9, '2027-04-02', 31, 1, 0, 60, 0], [62, 782.9, '2027-05-02', 30, 1, 0, 61, 0], [63, 732.9, '2027-06-02', 31, 1, 0, 62, 0], [64, 732.9, '2027-07-02', 30, 1, 0, 63, 0], [65, 732.9, '2027-08-02', 31, 1, 0, 64, 0], [66, 732.9, '2027-09-02', 31, 1, 0, 65, 0], [67, 732.9, '2027-10-02', 30, 1, 0, 66, 0], [68, 732.9, '2027-11-02', 31, 1, 0, 67, 0], [69, 732.9, '2027-12-02', 30, 1, 0, 68, 0], [70, 732.9, '2028-01-02', 31, 1, 0, 69, 0], [71, 732.9, '2028-02-02', 31, 1, 0, 70, 0], [72, 732.9, '2028-03-02', 29, 1, 0, 71, 0], [73, 732.9, '2028-04-02', 31, 1, 0, 72, 0], [74, 782.9, '2028-05-02', 30, 1, 0, 73, 0], [75, 732.9, '2028-06-02', 31, 1, 0, 74, 0], [76, 732.9, '2028-07-02', 30, 1, 0, 75, 0], [77, 732.9, '2028-08-02', 31, 1, 0, 76, 0], [78, 732.9, '2028-09-02', 31, 1, 0, 77, 0], [79, 732.9, '2028-10-02', 30, 1, 0, 78, 0], [80, 732.9, '2028-11-02', 31, 1, 0, 79, 0], [81, 732.9, '2028-12-02', 30, 1, 0, 80, 0], [82, 732.9, '2029-01-02', 31, 1, 0, 81, 0], [83, 732.9, '2029-02-02', 31, 1, 0, 82, 0], [84, 732.9, '2029-03-02', 28, 1, 0, 83, 0], [85, 732.9, '2029-04-02', 31, 1, 0, 84, 0], [86, 782.9, '2029-05-02', 30, 1, 0, 85, 0], [87, 732.9, '2029-06-02', 31, 1, 0, 86, 0], [88, 732.9, '2029-07-02', 30, 1, 0, 87, 0], [89, 732.9, '2029-08-02', 31, 1, 0, 88, 0], [90, 732.9, '2029-09-02', 31, 1, 0, 89, 0], [91, 732.9, '2029-10-02', 30, 1, 0, 90, 0], [92, 732.9, '2029-11-02', 31, 1, 0, 91, 0], [93, 732.9, '2029-12-02', 30, 1, 0, 92, 0], [94, 732.9, '2030-01-02', 31, 1, 0, 93, 0], [95, 732.9, '2030-02-02', 31, 1, 0, 94, 0], [96, 732.9, '2030-03-02', 28, 1, 0, 95, 0], [97, 732.9, '2030-04-02', 31, 1, 0, 96, 0], [98, 782.9, '2030-05-02', 30, 1, 0, 97, 0], [99, 732.9, '2030-06-02', 31, 1, 0, 98, 0], [100, 732.9, '2030-07-02', 30, 1, 0, 99, 0], [101, 732.9, '2030-08-02', 31, 1, 0, 100, 0], [102, 732.9, '2030-09-02', 31, 1, 0, 101, 0], [103, 732.9, '2030-10-02', 30, 1, 0, 102, 0], [104, 732.9, '2030-11-02', 31, 1, 0, 103, 0], [105, 732.9, '2030-12-02', 30, 1, 0, 104, 0], [106, 732.9, '2031-01-02', 31, 1, 0, 105, 0], [107, 732.9, '2031-02-02', 31, 1, 0, 106, 0], [108, 732.9, '2031-03-02', 28, 1, 0, 107, 0], [109, 732.9, '2031-04-02', 31, 1, 0, 108, 0], [110, 782.9, '2031-05-02', 30, 1, 0, 109, 0], [111, 732.9, '2031-06-02', 31, 1, 0, 110, 0], [112, 732.9, '2031-07-02', 30, 1, 0, 111, 0], [113, 732.9, '2031-08-02', 31, 1, 0, 112, 0], [114, 732.9, '2031-09-02', 31, 1, 0, 113, 0], [115, 732.9, '2031-10-02', 30, 1, 0, 114, 0], [116, 732.9, '2031-11-02', 31, 1, 0, 115, 0], [117, 732.9, '2031-12-02', 30, 1, 0, 116, 0], [118, 732.9, '2032-01-02', 31, 1, 0, 117, 0], [119, 732.9, '2032-02-02', 31, 1, 0, 118, 0], [120, 732.9, '2032-03-02', 29, 1, 0, 119, 0], [121, 732.9, '2032-04-02', 31, 1, 0, 120, 0], [122, 782.9, '2032-05-02', 30, 1, 0, 121, 0], [123, 732.9, '2032-06-02', 31, 1, 0, 122, 0], [124, 732.9, '2032-07-02', 30, 1, 0, 123, 0], [125, 732.9, '2032-08-02', 31, 1, 0, 124, 0], [126, 732.9, '2032-09-02', 31, 1, 0, 125, 0], [127, 732.9, '2032-10-02', 30, 1, 0, 126, 0], [128, 732.9, '2032-11-02', 31, 1, 0, 127, 0], [129, 732.9, '2032-12-02', 30, 1, 0, 128, 0], [130, 732.9, '2033-01-02', 31, 1, 0, 129, 0], [131, 732.9, '2033-02-02', 31, 1, 0, 130, 0], [132, 732.9, '2033-03-02', 28, 1, 0, 131, 0], [133, 732.9, '2033-04-02', 31, 1, 0, 132, 0], [134, 782.9, '2033-05-02', 30, 1, 0, 133, 0], [135, 732.9, '2033-06-02', 31, 1, 0, 134, 0], [136, 732.9, '2033-07-02', 30, 1, 0, 135, 0], [137, 732.9, '2033-08-02', 31, 1, 0, 136, 0], [138, 732.9, '2033-09-02', 31, 1, 0, 137, 0], [139, 732.9, '2033-10-02', 30, 1, 0, 138, 0], [140, 732.9, '2033-11-02', 31, 1, 0, 139, 0], [141, 732.9, '2033-12-02', 30, 1, 0, 140, 0], [142, 732.9, '2034-01-02', 31, 1, 0, 141, 0], [143, 732.9, '2034-02-02', 31, 1, 0, 142, 0], [144, 732.9, '2034-03-02', 28, 1, 0, 143, 0], [145, 732.9, '2034-04-02', 31, 1, 0, 144, 0], [146, 782.9, '2034-05-02', 30, 1, 0, 145, 0], [147, 732.9, '2034-06-02', 31, 1, 0, 146, 0], [148, 732.9, '2034-07-02', 30, 1, 0, 147, 0], [149, 732.9, '2034-08-02', 31, 1, 0, 148, 0], [150, 732.9, '2034-09-02', 31, 1, 0, 149, 0], [151, 732.9, '2034-10-02', 30, 1, 0, 150, 0], [152, 732.9, '2034-11-02', 31, 1, 0, 151, 0], [153, 732.9, '2034-12-02', 30, 1, 0, 152, 0], [154, 732.9, '2035-01-02', 31, 1, 0, 153, 0], [155, 732.9, '2035-02-02', 31, 1, 0, 154, 0], [156, 732.9, '2035-03-02', 28, 1, 0, 155, 0], [157, 732.9, '2035-04-02', 31, 1, 0, 156, 0], [158, 782.9, '2035-05-02', 30, 1, 0, 157, 0], [159, 732.9, '2035-06-02', 31, 1, 0, 158, 0], [160, 732.9, '2035-07-02', 30, 1, 0, 159, 0], [161, 732.9, '2035-08-02', 31, 1, 0, 160, 0], [162, 732.9, '2035-09-02', 31, 1, 0, 161, 0], [163, 732.9, '2035-10-02', 30, 1, 0, 162, 0], [164, 732.9, '2035-11-02', 31, 1, 0, 163, 0], [165, 732.9, '2035-12-02', 30, 1, 0, 164, 0], [166, 732.9, '2036-01-02', 31, 1, 0, 165, 0], [167, 732.9, '2036-02-02', 31, 1, 0, 166, 0], [168, 732.9, '2036-03-02', 29, 1, 0, 167, 0], [169, 732.9, '2036-04-02', 31, 1, 0, 168, 0], [170, 782.9, '2036-05-02', 30, 1, 0, 169, 0], [171, 732.9, '2036-06-02', 31, 1, 0, 170, 0], [172, 732.9, '2036-07-02', 30, 1, 0, 171, 0], [173, 732.9, '2036-08-02', 31, 1, 0, 172, 0], [174, 732.9, '2036-09-02', 31, 1, 0, 173, 0], [175, 732.9, '2036-10-02', 30, 1, 0, 174, 0], [176, 732.9, '2036-11-02', 31, 1, 0, 175, 0], [177, 732.9, '2036-12-02', 30, 1, 0, 176, 0], [178, 732.9, '2037-01-02', 31, 1, 0, 177, 0], [179, 732.9, '2037-02-02', 31, 1, 0, 178, 0], [180, 732.9, '2037-03-02', 28, 1, 0, 179, 0], [181, 732.9, '2037-04-02', 31, 1, 0, 180, 0], [182, 782.9, '2037-05-02', 30, 1, 0, 181, 0], [183, 732.9, '2037-06-02', 31, 1, 0, 182, 0], [184, 732.9, '2037-07-02', 30, 1, 0, 183, 0], [185, 732.9, '2037-08-02', 31, 1, 0, 184, 0], [186, 732.9, '2037-09-02', 31, 1, 0, 185, 0], [187, 732.9, '2037-10-02', 30, 1, 0, 186, 0], [188, 732.9, '2037-11-02', 31, 1, 0, 187, 0], [189, 732.9, '2037-12-02', 30, 1, 0, 188, 0], [190, 732.9, '2038-01-02', 31, 1, 0, 189, 0], [191, 732.9, '2038-02-02', 31, 1, 0, 190, 0], [192, 732.9, '2038-03-02', 28, 1, 0, 191, 0], [193, 732.9, '2038-04-02', 31, 1, 0, 192, 0], [194, 782.9, '2038-05-02', 30, 1, 0, 193, 0], [195, 732.9, '2038-06-02', 31, 1, 0, 194, 0], [196, 732.9, '2038-07-02', 30, 1, 0, 195, 0], [197, 732.9, '2038-08-02', 31, 1, 0, 196, 0], [198, 732.9, '2038-09-02', 31, 1, 0, 197, 0], [199, 732.9, '2038-10-02', 30, 1, 0, 198, 0], [200, 732.9, '2038-11-02', 31, 1, 0, 199, 0], [201, 732.9, '2038-12-02', 30, 1, 0, 200, 0], [202, 732.9, '2039-01-02', 31, 1, 0, 201, 0], [203, 732.9, '2039-02-02', 31, 1, 0, 202, 0], [204, 732.9, '2039-03-02', 28, 1, 0, 203, 0], [205, 732.9, '2039-04-02', 31, 1, 0, 204, 0], [206, 782.9, '2039-05-02', 30, 1, 0, 205, 0], [207, 732.9, '2039-06-02', 31, 1, 0, 206, 0], [208, 732.9, '2039-07-02', 30, 1, 0, 207, 0], [209, 732.9, '2039-08-02', 31, 1, 0, 208, 0], [210, 732.9, '2039-09-02', 31, 1, 0, 209, 0], [211, 732.9, '2039-10-02', 30, 1, 0, 210, 0], [212, 732.9, '2039-11-02', 31, 1, 0, 211, 0], [213, 732.9, '2039-12-02', 30, 1, 0, 212, 0], [214, 732.9, '2040-01-02', 31, 1, 0, 213, 0], [215, 732.9, '2040-02-02', 31, 1, 0, 214, 0], [216, 732.9, '2040-03-02', 29, 1, 0, 215, 0], [217, 732.9, '2040-04-02', 31, 1, 0, 216, 0], [218, 782.9, '2040-05-02', 30, 1, 0, 217, 0], [219, 732.9, '2040-06-02', 31, 1, 0, 218, 0], [220, 732.9, '2040-07-02', 30, 1, 0, 219, 0], [221, 732.9, '2040-08-02', 31, 1, 0, 220, 0], [222, 732.9, '2040-09-02', 31, 1, 0, 221, 0], [223, 732.9, '2040-10-02', 30, 1, 0, 222, 0], [224, 732.9, '2040-11-02', 31, 1, 0, 223, 0], [225, 732.9, '2040-12-02', 30, 1, 0, 224, 0], [226, 732.9, '2041-01-02', 31, 1, 0, 225, 0], [227, 732.9, '2041-02-02', 31, 1, 0, 226, 0], [228, 732.9, '2041-03-02', 28, 1, 0, 227, 0], [229, 732.9, '2041-04-02', 31, 1, 0, 228, 0], [230, 782.9, '2041-05-02', 30, 1, 0, 229, 0], [231, 732.9, '2041-06-02', 31, 1, 0, 230, 0], [232, 732.9, '2041-07-02', 30, 1, 0, 231, 0], [233, 732.9, '2041-08-02', 31, 1, 0, 232, 0], [234, 732.9, '2041-09-02', 31, 1, 0, 233, 0], [235, 732.9, '2041-10-02', 30, 1, 0, 234, 0], [236, 732.9, '2041-11-02', 31, 1, 0, 235, 0], [237, 732.9, '2041-12-02', 30, 1, 0, 236, 0], [238, 732.9, '2042-01-02', 31, 1, 0, 237, 0], [239, 732.9, '2042-02-02', 31, 1, 0, 238, 0], [240, 732.9, '2042-03-02', 28, 1, 0, 239, 0], [241, 732.9, '2042-04-02', 31, 1, 0, 240, 0], [242, 782.9, '2042-05-02', 30, 1, 0, 241, 0], [243, 732.9, '2042-06-02', 31, 1, 0, 242, 0], [244, 732.9, '2042-07-02', 30, 1, 0, 243, 0], [245, 732.9, '2042-08-02', 31, 1, 0, 244, 0], [246, 732.9, '2042-09-02', 31, 1, 0, 245, 0], [247, 732.9, '2042-10-02', 30, 1, 0, 246, 0], [248, 732.9, '2042-11-02', 31, 1, 0, 247, 0], [249, 732.9, '2042-12-02', 30, 1, 0, 248, 0], [250, 732.9, '2043-01-02', 31, 1, 0, 249, 0], [251, 732.9, '2043-02-02', 31, 1, 0, 250, 0], [252, 732.9, '2043-03-02', 28, 1, 0, 251, 0], [253, 732.9, '2043-04-02', 31, 1, 0, 252, 0], [254, 782.9, '2043-05-02', 30, 1, 0, 253, 0], [255, 732.9, '2043-06-02', 31, 1, 0, 254, 0], [256, 732.9, '2043-07-02', 30, 1, 0, 255, 0], [257, 732.9, '2043-08-02', 31, 1, 0, 256, 0], [258, 732.9, '2043-09-02', 31, 1, 0, 257, 0], [259, 732.9, '2043-10-02', 30, 1, 0, 258, 0], [260, 732.9, '2043-11-02', 31, 1, 0, 259, 0], [261, 732.9, '2043-12-02', 30, 1, 0, 260, 0], [262, 732.9, '2044-01-02', 31, 1, 0, 261, 0], [263, 732.9, '2044-02-02', 31, 1, 0, 262, 0], [264, 732.9, '2044-03-02', 29, 1, 0, 263, 0], [265, 732.9, '2044-04-02', 31, 1, 0, 264, 0], [266, 782.9, '2044-05-02', 30, 1, 0, 265, 0], [267, 732.9, '2044-06-02', 31, 1, 0, 266, 0], [268, 732.9, '2044-07-02', 30, 1, 0, 267, 0], [269, 732.9, '2044-08-02', 31, 1, 0, 268, 0], [270, 732.9, '2044-09-02', 31, 1, 0, 269, 0], [271, 732.9, '2044-10-02', 30, 1, 0, 270, 0], [272, 732.9, '2044-11-02', 31, 1, 0, 271, 0], [273, 732.9, '2044-12-02', 30, 1, 0, 272, 0], [274, 732.9, '2045-01-02', 31, 1, 0, 273, 0], [275, 732.9, '2045-02-02', 31, 1, 0, 274, 0], [276, 732.9, '2045-03-02', 28, 1, 0, 275, 0], [277, 732.9, '2045-04-02', 31, 1, 0, 276, 0], [278, 782.9, '2045-05-02', 30, 1, 0, 277, 0], [279, 732.9, '2045-06-02', 31, 1, 0, 278, 0], [280, 732.9, '2045-07-02', 30, 1, 0, 279, 0], [281, 732.9, '2045-08-02', 31, 1, 0, 280, 0], [282, 732.9, '2045-09-02', 31, 1, 0, 281, 0], [283, 732.9, '2045-10-02', 30, 1, 0, 282, 0], [284, 732.9, '2045-11-02', 31, 1, 0, 283, 0], [285, 732.9, '2045-12-02', 30, 1, 0, 284, 0], [286, 732.9, '2046-01-02', 31, 1, 0, 285, 0], [287, 732.9, '2046-02-02', 31, 1, 0, 286, 0], [288, 732.9, '2046-03-02', 28, 1, 0, 287, 0], [289, 732.9, '2046-04-02', 31, 1, 0, 288, 0], [290, 782.9, '2046-05-02', 30, 1, 0, 289, 0], [291, 732.9, '2046-06-02', 31, 1, 0, 290, 0], [292, 732.9, '2046-07-02', 30, 1, 0, 291, 0], [293, 732.9, '2046-08-02', 31, 1, 0, 292, 0], [294, 732.9, '2046-09-02', 31, 1, 0, 293, 0], [295, 732.9, '2046-10-02', 30, 1, 0, 294, 0], [296, 732.9, '2046-11-02', 31, 1, 0, 295, 0], [297, 732.9, '2046-12-02', 30, 1, 0, 296, 0], [298, 732.9, '2047-01-02', 31, 1, 0, 297, 0], [299, 732.9, '2047-02-02', 31, 1, 0, 298, 0], [300, 732.9, '2047-03-02', 28, 1, 0, 299, 0], [301, 732.9, '2047-04-02', 31, 1, 0, 300, 0], [302, 782.9, '2047-05-02', 30, 1, 0, 301, 0], [303, 732.9, '2047-06-02', 31, 1, 0, 302, 0], [304, 732.9, '2047-07-02', 30, 1, 0, 303, 0], [305, 732.9, '2047-08-02', 31, 1, 0, 304, 0], [306, 732.9, '2047-09-02', 31, 1, 0, 305, 0], [307, 732.9, '2047-10-02', 30, 1, 0, 306, 0], [308, 732.9, '2047-11-02', 31, 1, 0, 307, 0], [309, 732.9, '2047-12-02', 30, 1, 0, 308, 0], [310, 732.9, '2048-01-02', 31, 1, 0, 309, 0], [311, 732.9, '2048-02-02', 31, 1, 0, 310, 0], [312, 732.9, '2048-03-02', 29, 1, 0, 311, 0], [313, 732.9, '2048-04-02', 31, 1, 0, 312, 0], [314, 782.9, '2048-05-02', 30, 1, 0, 313, 0], [315, 732.9, '2048-06-02', 31, 1, 0, 314, 0], [316, 732.9, '2048-07-02', 30, 1, 0, 315, 0], [317, 732.9, '2048-08-02', 31, 1, 0, 316, 0], [318, 732.9, '2048-09-02', 31, 1, 0, 317, 0], [319, 732.9, '2048-10-02', 30, 1, 0, 318, 0], [320, 732.9, '2048-11-02', 31, 1, 0, 319, 0], [321, 732.9, '2048-12-02', 30, 1, 0, 320, 0], [322, 732.9, '2049-01-02', 31, 1, 0, 321, 0], [323, 732.9, '2049-02-02', 31, 1, 0, 322, 0], [324, 732.9, '2049-03-02', 28, 1, 0, 323, 0], [325, 732.9, '2049-04-02', 31, 1, 0, 324, 0], [326, 782.9, '2049-05-02', 30, 1, 0, 325, 0], [327, 732.9, '2049-06-02', 31, 1, 0, 326, 0], [328, 732.9, '2049-07-02', 30, 1, 0, 327, 0], [329, 732.9, '2049-08-02', 31, 1, 0, 328, 0], [330, 732.9, '2049-09-02', 31, 1, 0, 329, 0], [331, 732.9, '2049-10-02', 30, 1, 0, 330, 0], [332, 732.9, '2049-11-02', 31, 1, 0, 331, 0], [333, 732.9, '2049-12-02', 30, 1, 0, 332, 0], [334, 732.9, '2050-01-02', 31, 1, 0, 333, 0], [335, 732.9, '2050-02-02', 31, 1, 0, 334, 0], [336, 732.9, '2050-03-02', 28, 1, 0, 335, 0], [337, 732.9, '2050-04-02', 31, 1, 0, 336, 0], [338, 782.9, '2050-05-02', 30, 1, 0, 337, 0], [339, 732.9, '2050-06-02', 31, 1, 0, 338, 0], [340, 732.9, '2050-07-02', 30, 1, 0, 339, 0], [341, 732.9, '2050-08-02', 31, 1, 0, 340, 0], [342, 732.9, '2050-09-02', 31, 1, 0, 341, 0], [343, 732.9, '2050-10-02', 30, 1, 0, 342, 0], [344, 732.9, '2050-11-02', 31, 1, 0, 343, 0], [345, 732.9, '2050-12-02', 30, 1, 0, 344, 0], [346, 732.9, '2051-01-02', 31, 1, 0, 345, 0], [347, 732.9, '2051-02-02', 31, 1, 0, 346, 0], [348, 732.9, '2051-03-02', 28, 1, 0, 347, 0], [349, 732.9, '2051-04-02', 31, 1, 0, 348, 0], [350, 782.9, '2051-05-02', 30, 1, 0, 349, 0], [351, 732.9, '2051-06-02', 31, 1, 0, 350, 0], [352, 732.9, '2051-07-02', 30, 1, 0, 351, 0], [353, 732.9, '2051-08-02', 31, 1, 0, 352, 0], [354, 732.9, '2051-09-02', 31, 1, 0, 353, 0], [355, 732.9, '2051-10-02', 30, 1, 0, 354, 0], [356, 732.9, '2051-11-02', 31, 1, 0, 355, 0], [357, 732.9, '2051-12-02', 30, 1, 0, 356, 0], [358, 732.9, '2052-01-02', 31, 1, 0, 357, 0], [359, 732.9, '2052-02-02', 31, 1, 0, 358, 0], [360, 732.9, '2052-03-02', 29, 1, 0, 359, 0], [361, 732.9, '2052-04-02', 31, 1, 0, 360, 0], [362, 782.9, '2052-05-02', 30, 1, 0, 361, 0], [363, 732.9, '2052-06-02', 31, 1, 0, 362, 0], [364, 732.9, '2052-07-02', 30, 1, 0, 363, 0], [365, 732.9, '2052-08-02', 31, 1, 0, 364, 0], [366, 732.9, '2052-09-02', 31, 1, 0, 365, 0], [367, 732.9, '2052-10-02', 30, 1, 0, 366, 0], [368, 732.9, '2052-11-02', 31, 1, 0, 367, 0], [369, 732.9, '2052-12-02', 30, 1, 0, 368, 0], [370, 732.9, '2053-01-02', 31, 1, 0, 369, 0], [371, 732.9, '2053-02-02', 31, 1, 0, 370, 0], [372, 732.9, '2053-03-02', 28, 1, 0, 371, 0], [373, 732.9, '2053-04-02', 31, 1, 0, 372, 0], [374, 726.66, '2053-05-02', 30, 1, 0, 373, 0]]
        self.drawing_calendar = [[0, '50000', '2022-04-01', 0, 0, 0, 0, 0], [1, '45000', '2022-06-13', 73, 30, 0, 5, 0], [2, '45000', '2022-08-25', 73, 72, 0, 6, 0], [3, '40000', '2022-11-06', 73, 72, 0, 7, 0], [4, '40000', '2023-01-18', 73, 72, 0, 8, 0], [5, '20000', '2023-04-01', 73, 72, 0, 9, 0]]

    def calculate_arp(self):

        try:
            result = newton(self.arp_general, 0)
            print("ARP result: ", result)
        except Exception as e:
            print(f"Calculation failed! Exception: {e}")

    def arp_general(self, x):

        left_sum = 0
        right_sum = 0

        for i in range(len(self.drawing_calendar)):
            amount = float(self.table[i][1])
            day_part = float(self.table[i][4] / self.year_days)
            week_part = float(self.table[i][5] / 52)
            month_part = float((self.table[i][6]) / 12)
            year_part = self.table[i][7]

            coef_pow = year_part + month_part + week_part + day_part
            left_sum += amount / ((1 + x) ** coef_pow)

        for i in range(len(self.table)):
            amount = float(self.table[i][1])
            day_part = float(self.table[i][4] / self.year_days)
            week_part = float(self.table[i][5] / 52)
            month_part = float((self.table[i][6]) / 12)
            year_part = self.table[i][7]

            coef_pow = year_part + month_part + week_part + day_part
            right_sum += amount / ((1 + x) ** coef_pow)

        return left_sum - right_sum

a = ARP()
a.calculate_arp()

A: I found a bug with help of my friend. The problem was that left_sum used wrong data. It should use data from self.drawing_calendar instead of self.table.


text:
Q: What is time complexity when power involed?  def f1(lst):
     i=3
     while i<len(lst):
        print(lst[i])
        i **= 3

What is the time complexity of this code? the answer says O(loglogn), why?

A: Take a look at how i grows with loop (^ means power here) :
i_0 = 3
i_1 = i_0^3 = 3^3
i_2 = i_1^3 = (3^3)^3 = 3^(3*3)
i_3 = i_2^3 = (3^(3*3))^3 = 3^(3*3*3)
...
i_n = 3^(3^n)

This is called iterated powers but it is not Tetration. As you can see, it is a nested exponentation so the time complexity would be the inverse function : O(log3(log3(n))).


text:
Q: Java: same strings got with StringBuilder are not equals in the end Out product is integrated with Drools and user can add/edit/deletd Drools functions from/to a package by loading the entire package in a simple long scrolling JTextArea and literally directly editing some DRools functions; or, better, copy and paste the whole package after editing it with another instrument (like Notepad++).
When the new package is persisted, I have to parse it with its previous version stored in a DB and audit differences in existing functions, or inserted/deleted ones. I already had a class which splits a Drools functions into its component, to which I added this method to recover a snapshot of the function to be stored:
public String getFunctionCode() {
    StringBuilder strBld = new StringBuilder("function ");

    if (this.returnType == null)
        strBld.append("void");
    else
        strBld.append(this.returnType);

    strBld.append(" ");
    strBld.append(this.name);
    strBld.append("(");

    if (this.paramNames != null && !this.paramNames.isEmpty()) {
        int parametersSize = this.paramTypes.size();
        for (int i = 0; i < parametersSize; i++) {
            strBld.append(this.paramTypes.get(i).getName());
            strBld.append(" ");
            strBld.append(this.paramNames.get(i).getName());
            if (i < parametersSize - 1)
                strBld.append(",");
        }
    }

    strBld.append(") {");

    if (this.text == null || this.text.trim().isEmpty())
        strBld.append(" ");
    else
        strBld.append(this.text);

    strBld.append("}\r\n");

    return strBld.toString();
}

where  paramNames and  paramTypes are simply a List<String> containing the signature of the function, while text contains the body of the function between the two main { } after the signature.
It happens only sometimes that all the other functions of package are detected as edited, even if user added or deleted another one. Why this? It this because of some not printable character?
If I compare the two snapshots stored on DB with a text diff tool, nothing is detected.
To get changed functions, in a for loop I do:
for (FunctionInfo functionInfo : updatedFunctions) {
    FunctionInfo oldFunction = oldPackageInfo.getFunction(functionInfo.getName());

    String oldFunctionBody = oldFunction.getFunctionCode();
    String newFunctionBody = functionInfo.getFunctionCode();

    if (!newFunctionBody.equals(oldFunctionBody)) {
      /* persist an audit record */
    }
}

where updatedFunctions is a List<FunctionInfo> got by retrieving all functions in common between old persisted package and the one arriving from front end, after sorting them by name.
Which could be the cause?
UPDATE
I started Wildfly in debug mode and I on Eclipse a breakpoint inside the if statement in the previous loop. Than, using this online tool for text diff I compared oldFunctionBody and newFunctionBody of a function I did not edited from the frontend window.
It turns out that old untouched functions coming from front end were added with some unprintable characters, overall with many \r. Why this happens?
Old function:
function void disableTestOnDevice(SampleBuilder sample,String devices,String[] devTestCode) {\r\n\t\t   if(devices == null)\r\n\t\t\t   return;\r\n\t       if(sample.getListTransc() != null && sample.getListTransc().size() > 0){\t\r\n\t\t\t\tfor(int i = sample.getListTransc().size()-1; i >= 0; i--){\r\n\t\t\t\t\tViewWorklistBuilder j = (ViewWorklistBuilder)sample.getListTransc().get(i);\r\n\t\t\t\t\tif(j.getDeviceId() == null || j.getDeviceTestCode() == null || j.getDeviceSpecimenCode() == null){\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(j.getDeviceId().equals(devices)){\r\n\t\t\t\t\t\tif(devTestCode != null){\r\n\t\t\t\t\t\t\tfor(int k = 0;  k < devTestCode.length; k++){\r\n\t\t\t\t\t\t\t\tif(j.getDeviceTestCode().equals(devTestCode[k])){\r\n\t\t\t\t\t\t\t\t\tj.setEnabled(0);\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\t\r\n\t\t\t\t}\r\n\t       }\r\n\t\r\n

New function:
function void disableTestOnDevice(SampleBuilder sample,String devices,String[] devTestCode) {\n\t\t   if(devices == null)\n\t\t\t   return;\n\t       if(sample.getListTransc() != null && sample.getListTransc().size() > 0){\t\n\t\t\t\tfor(int i = sample.getListTransc().size()-1; i >= 0; i--){\n\t\t\t\t\tViewWorklistBuilder j = (ViewWorklistBuilder)sample.getListTransc().get(i);\n\t\t\t\t\tif(j.getDeviceId() == null || j.getDeviceTestCode() == null || j.getDeviceSpecimenCode() == null){\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(j.getDeviceId().equals(devices)){\n\t\t\t\t\t\tif(devTestCode != null){\n\t\t\t\t\t\t\tfor(int k = 0;  k < devTestCode.length; k++){\n\t\t\t\t\t\t\t\tif(j.getDeviceTestCode().equals(devTestCode[k])){\n\t\t\t\t\t\t\t\t\tj.setEnabled(0);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t}\n\t       }\n\t\r\n

A: You need to rewrite the default .equals() method to specify how you think it's equal in your classes where you compare objects, if the default comparison is not working for you.
Edit: See the documentation for Java 7 and the tutorial for javase for more information. Also see this post on when to use StringBuilder.

A: According to your last update. The main difference between the "old function" and the "new function" results are the carry return characters (I think that there is a tab character missing there, too). Anyway, to avoid this kind of issues I recommend you use System.lineSeparator(), introduced in JDK7:

Returns the system-dependent line separator string. It always returns the same value - the initial value of the system property line.separator.
  On UNIX systems, it returns "\n"; on Microsoft Windows systems it returns "\r\n".
  Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#lineSeparator()

Additionally, I recommend you use fixing space size instead of \t due to different application replace it in different ways. I mean in different tab size. So, for example a clean solution could be create a constant called TAB : "  " and replace it everywhere you use \t.
final String TAB = "  ";

Finally, I notice that you are returning the value of the StringBuilder as string, then, I guess that when you are doing the comparison you have the text stored in some String variable. Which could be useful if you are initializing as UTF-8 encoding (just for say one).


text:
Q: value is not being assigned to the variable after evaluating the expression every time i input in Temp the value of Cel remains zero, why expression is not storing value in it?
#include<iostream>

using namespace std;

int main(){
    float Far, Cel, Temp;
    char choice;

    cout << " To convert from Celcius to Farenheit, press 'f' for opposite 'c': "<<endl;
    cin >> choice;

    cout << "Enter Temperature: " << endl;
    cin >> Temp;

    if(choice == 'f' || choice == 'F'){
            Far = (Temp*(9/5))+32;
            cout <<  "Temperature in Farenheit is: " << Far << endl;
    }
    else if(choice == 'c' || choice == 'C'){
            Cel = (Temp - 32) * (5/9);
            cout << "Temperature in Celcius is: " << Cel << endl;
    }

    return 0;
}


text:
Q: Chef client waiting to finish When there are problems while running a recipe and the client run is hanging half way, the installed Chef client will be unusable.
You can then exit the machine, reboot, clean up chef pid files and so forth but each time the Chef client is started the following message is shown:

Chef client  is running, will wait for it to finish and then run.

Chef should be able to recover from this when a reboot is performed but this is not the case.
What is the best way to recover from a client run that hangs half way? Currently I delete the VM and create a new one but that is not a real solution.
Is it possible to recover when it hangs half way?

A: Stop the service if any running : sudo service chef-client stop
if the issue persists

*

*find out if nay chef client process/service is running: ps aux | grep chef

*kill the process

if the issue persists

*

*look up your chef client settings under /etc/chef/client.rb and/or your etc/init.d/chef-client

*then locate the pid_file and lockfile path

*delete the files

if the issues persists, you might run like me a old version of chef-client
you need to look in your chef cache folder
I had to delete /var/chef/cache/chef-client-running.pid

A: If it timeout takes place - converging should work fine over and over again. Well, if you need to remove client - you can run sudo rm -rf /etc/chef on client machine. All the options are described here in details.

A: I ran into the same issue where the kitchen converge process would get hung, typically due to an improper msi installation in my case.  I would then have to reboot the kitchen machine.
I noticed that an elevated scheduled task was running which when stopping, it would kill the process, but the issue returned when I ran it again ("chef client 2092 is running, will wait for it to finish and then run").
It then occurred to me that the last attempt to reboot, which normally resolves the issue, didn't succeed because of an open file preventing the reboot.  Rebooting the machine did resolve the issue in my case.  It's not a perfect solution but it does work as a work-around in my case.


text:
Q: Lazy Loading on a Collection of Objects i have a sql query that can bring back a large number of rows via a DataReader. Just now I query the DB transform the result set into a List(of ) and data bind the Grid to the List.
This can result occasionally in a timeout due to the size of Dataset.
I currently have a three teir setup where by the UI is acting on the List of objects in the business layer.
Can anyone suggest the best approach to implementing lazy loading in this scenatrio? or is there some other way of implementing this cleanly?
I am currently using Visual Studio 2005, .NET 2.0
EDIT: How would paging be used in this instance?

A: LINQ to SQL seems to make sense in your situation.
Otherwise if for any reason, you don't want to use LINQ to SQL (e.g. you are on .NET 2.0), consider writing an iterator that reads the DataReader and converts it to the appropriate object:
IEnumerator<MyObject> ReadDataReader() {
  while(reader.MoveNext())
    yield return FetchObject(reader);
}

A: Do you need to bring back all the data at once?  You could considering paging.

A: Paging might be your best solution.  If you are using SQL Server 2005 or greater there was new feature added. ROWNUMBER():
WITH MyThings AS
(
    SELECT ThingID, DateEntered,
    ROW_NUMBER() OVER (ORDER BY DateEntered) AS 'RowNumber'
    FROM dbo.Things
)
SELECT *
FROM ThingDetails
WHERE RowNumber BETWEEN 50 AND 60;

There is an example by David Hayden which is very helpful in demonstrating the SQL .
This method would decrease the number of records returned, reducing the overall load time.  It does mean that you will have to do a bit more to track where you are in the sequence of records, but it is worth the effort.
The standard paging technique requires everything to come back from the database and then be filtered at the middle tier, or client tier (code-behind) this method reduces the records to a more manageable subset.


text:
Q: Pay my visit to some place "Pay a visit to" is regarded as an idiomatic expression. My question: Is it correct to say "pay my/your visit to some place"? Is the sentence "I should pay my first visit to your work place" correct?

A: Here's an example from a fiction book (Ne'er Do Well, by Dornford Yates - House of Stratus, 2011, UK):

... I visit the patients myself. I usually pay my visits between five and
  six in the evening...

A: pay a visit

Frequently in the phrases to make, or pay (also †give) a visit, to
  return a visit. OED

Your question:

Can I say "I should pay my visit to your house"

Better would be:
"I should pay a visit to your house"

A: Saying "pay my visit" isn't incorrect, but it doesn't mean the same thing as "pay a visit".
In particular, saying "pay my visit" only makes sense when the listener is already aware of some visit, and you want to talk about that visit.
These examples of "my visit" are okay because the listener's attention has already been brought to some visit:

*

*I visit the patients myself. I usually pay my visits in the evening. = When I make those visits, I usually do it in the evening.

*I am going to visit a bunch of office buildings. I should pay my first visit to your workplace. = When I make the first of those visits, it should be at your workplace.

*I am visiting the house of everyone in the neighborhood. Tomorrow I should pay my visit to your house. = When I make the visit to your house, it should be tomorrow.

Generally, you can't say "pay my visit" if you haven't previously mentioned the visit that you're talking about (or brought the visit to the listener's attention in some other way).


text:
Q: What is the Timeline "closure" event? Upon looking at the Timeline CSS, I noticed an interesting class:
.post-timeline-v2 .post-timeline .event-type>span.closure {
    background-color: #9D81B3;
    color: #fafafb
}

I've never seen the Closure reason actually used, especially for, well, the seemingly obvious question closure. Instead, this is listed under the history event:

It's also not used for close votes, so what possible purpose does it have? Will it have a purpose?

A: It's used to style close (and reopen) votes in the moderator version of the timeline.


text:
Q: How to get a list of current Oracle CDBs on server If I have a server with one or more CDBs, what command can I run on the server in order to obtain a list where each item uniquely identifies one of the CDBs?
(a "CDB" is an Oracle Container Database)
Note 1:
I realize that it is rare to have more than one CDB on a server.  But in that case I would still want to obtain the unique CDB name of that one CDB.
Note 2: I know that the command cat /etc/oratab will list a bunch of DB installations on the server.  But this includes installations that no longer exist.  I want a list of only the currently existing CDB installations.

A: This is how I list running database instances. Container-databases or non-container databases:
  cat >> ~/.bash_profile <<EOF
  oinst() {
      /bin/ps -ef | grep ora_lgw[r] | awk '{print $8}' | sed -e 's/ora_lg[w]r_//'
  }
  EOF

  $oinst
  CDB1
  CDB2
  CDB3

If database instances are not running you are left with information from  /etc/oratab, init<SID>.ora, orapw<SID> or database-files on ASM, filesystem or RMAN.


text:
Q: How to test model where variable moderates relationship via a mediating variable? (in lavaan) Say you have variables X, Y, Z, and W.
I hypothesize that X impacts Y and this relationship is moderated by Z. Moreover, W impacts Z. Therefore, W moderates the relationship between X and Y via its impact on Z.
I am implementing this in lavaan with the following code:
model_definition <- '
Y ~ X + Z + X:Z
Z ~ W
'
fit <- sem(model_definition, data = df)
summary(fit, standardized=TRUE, rsq=TRUE)

Is this the correct implementation? Is there a way I can test if W moderates Y ~ X via Z? It's almost like a mediation model except the outcome is a moderating effect.

A: I found the solution by translating the diagram on page 461 of Hayes 2015. It is the same as if you were conducting a mediation model where Z is a mediator, and the interaction term of X:W is like the "a" variable of a traditional mediation and X and W are like covariates.
model_definition <- '
Z ~ a1*X:W + a2*X + a3*W
Y ~ c1*X + c2*W + c3*X:W + b*Z
indirect := a3*b
total := c3 + indirect
'
fit <- sem(model_definition, data = df)
summary(fit, standardized=TRUE, rsq=TRUE)


text:
Q: Epson WF-7525 makes noise when plugging in USB device My Epson WF-7525 works perfectly with Ubuntu 15.04, but I have a very specific annoyance: whenever I resume my machine or plug in a USB device, the scanner comes alive as if it's briefly scanning, then stops.
It's rather noisy, and plugging in a phone nearly always triggers it. The printer-scanner seems to come out of its low power state, and I've found that I can only stop it by turning the WF-7525 off completely. This also happens for other Ubuntu machines that have the printer installed, but not for Windows or Mac machines.
I get the impression that Ubuntu is polling devices, and this is how the Workforce happens to respond to it, but I couldn't figure out which process is responsible or how to prevent it from doing so.
Is there any way to troubleshoot what's causing this, or how to disable it?

A: This question was also asked on Ask Ubuntu, which has some instructions to diagnose the problem.
For posterity, the recommendation from the only answer is:

I had a similar problem with an Epson network printer. To find out what was causing it, I used netstat to monitor the network connections while inserting a USB device:
sudo netstat -t -u -a -p -c
One connection appeared a few moments after the device was inserted: a UDP connection by colord-sane. This binary is part of colord, a "system service to manage device colour profiles".
Unfortunately, disabling this service (at least on 15.04) is more difficult than it would seem. colord is not started directly by the init system systemd. Instead, dbus starts colord, or is asked to start colord by some other service (at least not the printer service cupsd). One way to prevent this is by renaming the relevant service file:
cd /usr/share/dbus-1/system-services/
sudo mv org.freedesktop.ColorManager.service org.freedesktop.ColorManager.service.disabled

I don't know what side-effects this action might have. Another possibility is to uninstall colord completely, using
sudo apt-get remove colord

As I don't really need colour profile functionality on my Ubuntu device, I didn't investigate what exactly colord does to "activate" the printer, or how to teach it not to do so.


text:
Q: C Programming, Sorting array What am I doing wrong? the program run but the output isn't in the right order.
#include <stdio.h>
int main () { /*program to ask user to input array values and sort them in ascending order.*/
    int n,j,i,temp;
    printf ("how many numbers?\n");
    scanf ("%d",&n);
    int a[n];
    for (i=0;i<n;i++){
        printf ("enter number");
        scanf ("%d",&a[i]);
    }
    for (i=0;i<n;i++); {
     for (j=i+1;j<n;j++){
            if (a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp; }
    } }
    printf("The numbers arranged in ascending order are given below \n");
    for (i = 0; i < n; ++i)
        printf("%d\n", a[i]);
}

A: Change
for (i=0;i<n;i++); {

To
for (i=0;i<n-1;i++) {

Semicolon was executed instead of following błock {}

A: Element form right/end cant propagate to left, because for example first element of array can be swapped only at first check with second element.


text:
Q: Operations in multi index dataframe pandas I need to process geographic and statistical data from a big data csv. It contains data from geographical administrative and geostatistical. Municipality, Location, geostatistical basic division and block constitute the hierarchical indexes.
I have to create a new column ['data2'] for every element the max value of the data in the geo index, and divide each block value by that value. For each index level, and the index level value must be different from 0, because the 0 index level value accounts for other types of info not used in the calculation.
                       data1  data2
mun  loc  geo  block
1    0    0    0       20     20
1    1    0    0       10     10
1    1    1    0       10     10
1    1    1    1       3      3/4
1    1    1    2       4      4/4
1    1    2    0       30     30
1    1    2    1       1      1/3
1    1    2    2       3      3/3
1    2    1    1       10     10/12
1    2    1    2       12     12/12
2    1    1    1       123    123/123
2    1    1    2       7      7/123
2    1    2    1       6      6/6
2    1    2    2       1      1/6

Any ideas? I have tried with for loops, converting the indexes in columns with reset_index() and iterating by column and row values but the computation is taking forever and I think that is not the correct way to do this kind of operations.
Also, what if I want to get my masks like this, so I can run my calculations to every level.
mun  loc  geo  block
1    0    0    0     False
1    1    0    0     False
1    1    1    0     True
1    1    1    1     False
1    1    1    2     False
1    1    2    0     True
1    1    2    1     False
1    1    2    2     False

mun  loc  geo  block
1    0    0    0     False
1    1    0    0     True
1    1    1    0     False
1    1    1    1     False
1    1    1    2     False
1    2    0    0     True
1    2    2    0     False
1    2    2    1     False

mun  loc  geo  block
1    0    0    0     True
1    1    0    0     False
1    1    1    0     False
1    1    1    1     False
1    1    1    2     False
2    0    0    0     True
2    1    1    0     False
2    1    2    1     False

A: You can first create mask from MultiIndex, compare with 0 and check at least one True (at least one 0) by any:
mask = (pd.DataFrame(df.index.values.tolist(), index=df.index) == 0).any(axis=1)
print (mask)
mun  loc  geo  block
1    0    0    0         True
     1    0    0         True
          1    0         True
               1        False
               2        False
          2    0         True
               1        False
               2        False
     2    1    1        False
               2        False
2    1    1    1        False
               2        False
          2    1        False
               2        False
dtype: bool

Then get max values by groupby per first, second and third index, but before filter by boolean indexing only values where are not True in mask:
df1 = df.ix[~mask, 'data1'].groupby(level=['mun','loc','geo']).max()
print (df1)
mun  loc  geo
1    1    1        4
          2        3
     2    1       12
2    1    1      123
          2        6

Then reindex df1 by df.index, remove last level of Multiindex by reset_index, mask values where no change by mask (also is necessary remove last level) and fillna by 1, because dividing return same value.
df1 = df1.reindex(df.reset_index(level=3, drop=True).index)
         .mask(mask.reset_index(level=3, drop=True)).fillna(1)
print (df1)
Name: data1, dtype: int64
mun  loc  geo
1    0    0        1.0
     1    0        1.0
          1        1.0
          1        4.0
          1        4.0
          2        1.0
          2        3.0
          2        3.0
     2    1       12.0
          1       12.0
2    1    1      123.0
          1      123.0
          2        6.0
          2        6.0
Name: data1, dtype: float64

Last divide by div:
print (df['data1'].div(df1.values,axis=0))
mun  loc  geo  block
1    0    0    0        20.000000
     1    0    0        10.000000
          1    0        10.000000
               1         0.750000
               2         1.000000
          2    0        30.000000
               1         0.333333
               2         1.000000
     2    1    1         0.833333
               2         1.000000
2    1    1    1         1.000000
               2         0.056911
          2    1         1.000000
               2         0.166667
dtype: float64


text:
Q: Seeing default fulfillment code instead of the one hat it's used for the chatbot I'm developing a chatbot with Dialogflow ES for a client.

Situation:

*

*The first phase of the chatbot is already developed (months ago)

*For the first phase I was using the fulfillment feature (through Inline editor) with quite a lot of custom code

*Now, after couple of months, I started implementing some updates to the chatbot

Issue:
If I go and try to see and update the fullfilment code, I see the deafult code in Inline editor instead of my custom code.

Questions:

*

*Has anyone experienced this?

*I'm thinking that one of the possible reasons could be the Dialogflow plan/version which is currently a "Free" one - although the free plan is basically just about the limits which we currently do not exceed. Could this be true?

*Or the other, more likely the right reson: I checked the settings in the Google Cloud Console and saw that the project's billing account is closed. As far as I can remember the client had to set up billing couple of months ago when we started with the chatbot development, for us to be able to use the fulfillment feature. Am I thinking correctly? Could setting up a billing again solve the issue?

Additional question: does anyone know if the old custom code will be available after I somehow
solve the issue above? I'm going to cry if I can't get the old code back:(

Thanks,
Boštjan

A: As per the docs of Dialogflow the inline editor deploys your code to the Cloud Functions. You can refer to the below mentioned steps to retrieve the last deployed code.
Steps:

*

*Go to your GCP Project

*Navigate to Cloud Functions in the GCP console

*Search for your Dialogflow inline editor function which will be named by dialogflowFirebaseFulfillment. This is the default name to be used if you are using an inline editor

*Click on the function

*Check for the  version. If you have not deployed the default code again, you can retrieve your last deployed code only

*Click on the source and then click on the Download as Zip option

This way you can retrieve your last deployed code.

A: Answer: the issue was indeed the billing which was closed. The billing is now set again and the fulfillment works as expected.


text:
Q: TypeError: object of type 'function' has no len(), function called correctly? I am trying to write a simple code to translate a strand of DNA into RNA and return the corresponding proteins. I am receiving a TypeError on line 19 ("for i in range(len(y))"). The variable y will be a list. I have tried looking at other questions but none of their solutions are applicable to my code. I am confused because I thought the variables were called correctly. Can someone offer some insight?
Here is my code:
dna = 'ATGCTAGCTAGCTAGCTAGTATTATATAGCGCGATCGATCGATA'
dna_list = []

for char in dna:
    dna_list.append(char)

def rev_dna(x):
    rev_dna = []
    for char in x:
        rev_dna.append(x[len(x)-1])
        del(x[len(x)-1])
        return rev_dna

def translate(y,z):
    for i in range(len(y)):
        if y[i] == 'T':
            y[i] == 'U'
        z = "".join(y)
        return z

rna1 = ""
print translate(dna_list,rna1)


text:
Q: How to combine 2 results from SQL procedure I wrote a SQL query, it is 300+ line and I made this as a procedure.
I want to run two times this procedure with different parameters and then want to see all result in one table.
For example:
exec sp_xxxxx 4652,'2022-02-07 00:00:00.000',1
// Returns 2 columns, number of rows can vary

exec sp_xxxxx 4652,'2022-02-14 00:00:00.000',1
// Returns 2 columns, number of rows can vary

I run these together, then I hope to get a result of 4 columns
// 4 column,number of rows can vary
I tried openrowset but SQL blocked.
How can I do this, I would be very happy if you can help.

A: There's not enough information to provide a demonstrable solution, but the approach should be:
Create temp table #T1(col1, col2)
Create temp table #T2(col1, col2)

Insert into #T1(col1, col2) exec proc
Insert into #T2(col1, col2) exec proc

select t1.col1, t1.col2, t2.col1, t2.col2
from #T1 inner/left/full join #T2 on<criteria>

Also note that prefixing procedures with "sp" is not recommended, this is reserved by MS and indicates a Special Procedure. Choose a different prefix - or no prefix.

A: Start with creating a table type than matches the output of your procedure.
For example:
CREATE TYPE XxxxxTblType AS TABLE(
 Col1 varchar(10) not null,
 Col2 decimal(8,2) not null
);

This table type could also be used by your procedure.
Then use a variable with that table type to collect the results from the procedures. Then create a temporary table from that table variable.
declare @Xxxxx XxxxxTblType;
insert into @Xxxxx exec sp_xxxxx 4652,'2022-02-07 00:00:00.000',1;
insert into @Xxxxx exec sp_xxxxx 4652,'2022-02-14 00:00:00.000',1;

select * into #tmpXxxxx from @Xxxxx;

Now you can query the temporary table.
select * from #tmpXxxxx;


text:
Q: Android EditText unlimited text length is there a device specific limitation (other then total free memory size) to text length or line count in scrollable multiline EditText when android:maxLength and android:maxLines is NOT set? I have an EditText:
<EditText
  android:editable="false"
  android:id="@+id/sip_log_log"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight = "1"
  android:text=""
  android:gravity = "top"
  android:textColor="#00FF00"
  android:background="#000000"
  android:scrollbars="vertical"
  android:focusable="true"
  />

and when I call
mEditText.setText("some very very loooong string....");

only the first part of the text is shown. The issue is device specific. Everything works well on HTC Sensation or in emulator, but Samsung Galaxy S 2 does never show more than about 20 pages of the text. Can I fix it in some way? Or is there an alternative way to show extremely long texts (SIP log in our SIP client) in some other standard view with scroll bar?
Thanks to all replies.

A: Adding android:maxLength="99999999" to your layout file fixes this!

A: I had this same problem, and setting android:maxLength="999999 in the XML didn't fix this. But programmatically setting the length filter worked, like this:
    EditText mPrimaryPhoneField = (EditText) findViewById(R.id.primary_phone);
    InputFilter[] phoneFilterArray = new InputFilter[1];
    //This needs to be a large number to fix a bug on Samsung Galaxy tablet where it would have a default limitation on numeric fields if you had no length filter at all.
    phoneFilterArray[0] = new InputFilter.LengthFilter(100);
    mPrimaryPhoneField.setFilters(phoneFilterArray);

A: Removing at all the maxLength property and adding android:inputType="textLongMessage|textMultiLine" to the layout file fixed it for me.


text:
Q: Randomize order of  links on page using jQuery I have a list of links sitting inside a  tag right now. I would like for the page to 'reorganize' the order of each link on page reload (page view) and display the results.
For example:

     1
     2
     3
     4
     5

On page reload, the soure code would look like:

     5
     1
     3
     4
     2

or some other random order
Is there a very basic jQuery DOM manipulation script to accomplish this? If it helps, the page is built on PHP as well.

A: If simplicity is more important than randomness:
You can use get to convert the jQuery object to an array, then use the native sort with a function designed to randomize it.  Then put the randomly arranged array back into the DOM.
var array = $("#testgroup").children().get().sort( function() {
    return 0.5 - Math.random();
});
$("#testgroup").append(array);

Demo: http://jsfiddle.net/4e7cs/
If you are looking for true shuffling:
You can utilize the Fisher-Yates shuffle:
var array = $("#testgroup").children().toArray();
var i = array.length,
    j, temp;
while (--i) {
    j = Math.floor(Math.random() * (i + 1));
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
}

$("#testgroup").append(array);

Demo: http://jsfiddle.net/4e7cs/3/
Here is a writeup on why the first is bad, but I'll leave it here for completeness.

A: PHP has a shuffle() function to randomize arrays.  You can do the randomization on the server side.
<?php
$links = array(
    1 => '1.html',
    2 => '2.html',
    3 => '3.html',
    4 => '4.html',
    5 => '5.html'
);
$shuffledLinks = shuffle_assoc($links);

foreach ($shuffledLinks as $value=>$key) {
    echo ''.$value.'
';
}
function shuffle_assoc($list) {
    if (!is_array($list)) return $list;

    $keys = array_keys($list);
    shuffle($keys);
    $random = array();
    foreach ($keys as $key)
        $random[$key] = $list[$key];

    return $random;
}
?>

Ok...this is now fixed and tested.  Actually shuffle() did not work on associative arrays so I borrowed andjones at gmail dot com's shuffle_assoc() function for that.
I also mixed up my concatenation where I was using '+' instead of '.' O.o  Mixing up my JavaScript and PHP syntax.  I apologize about that.
Allen

A: I'm using a plugin that actualy does that : http://james.padolsey.com/javascript/sorting-elements-with-jquery/
But if you are using PHP you could sort it directly on the server?


text:
Q: Symfony bundle config parameters not available in listener? I have a bundle that has a listener which I have configured:
class Configuration implements ConfigurationInterface
{

    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder ()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('mybundle_name');

        $rootNode
          ->children()
            ->scalarNode('name')->defaultValue('value')
          ->end()
        ;

        return $treeBuilder;
    }

}

I also have a listener which has a few services injected into, primarily doctrine and the container parameters:
services:
    app.router_subscriber:
        class: MyBundle\EventSubscriber\RequestSubscriber
        calls:
            - [setEntityManager, ['@doctrine.orm.entity_manager']]
            - [setContainer, ['@service_container']]
        tags:
            - { name: kernel.event_subscriber }

When I dump the $this->container I can see the parameters except my own defined above.
When I run
bin/console config:dump-reference MyBundle
I do see what I am expecting
What am I missing to have my bundle parameters get merged into the application parameters? I am seeing third party bundles listed but not my own bundle. I followed the docs as verbatim as I could so the conventions have been followed as far as I am aware...
EDIT | I haven't created a bundle config.yml file - I assumed the Configuraiton object did that for me - setting the schema and default values - which could be overridden by application configs (if desired). Do I need to specifcy a bundle config.yml and import into application something like this (Merge config files in symfony2)?
Ideas?

A: I wrote a couple blog posts showing how you can set bundle configuration defaults using YAML files, and a follow-up on how to automatically set bundle configuration values as container parameters.  This was for Symfony2 and written in 2014, and the particular section of the Symfony documentation I link to disappeared from Symfony 2.3 onward, but the same concept still applies.
The main takeaway from those posts is that you can set your configuration values as container parameters in your bundle's Extension class via the load() method manually like so:
public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();
    $config = $this->processConfiguration($configuration, $configs);

    $container->setParameter($this->getAlias().'.name', $config['name']);
}

Notice that you can call $this->getAlias() to get the bundle's root name (mybundle_name).  Using the above call you would then have a parameter defined as mybundle_name.name which you could then override in your application's config.yml if need be.


text:
Q: Как удалить беседу (delete conversation) через Telegram API BOT В приложение Telegram есть кнопка Delete conversation.
В TELEGRAM API есть возможность удалить беседу?

A: В Bot API такой возможности нет. В Telegram API есть возможность очистить историю сообщений с помощью метода messages.deleteHistory, но удалить диалог - нет.


text:
Q: mixed up transaction on unlock table mysql i have some trouble with a mysql table that mixup the flow of an incremental primary key id in time line after an unlock table, due to backup process in plesk.
the table is structured as follow:
CREATE TABLE `transactions` (
  `id` int(11) NOT NULL,
  `sessionid` int(11) NOT NULL DEFAULT 0,
  `tipo` varchar(50) NOT NULL,
  `meta_table` varchar(255) DEFAULT NULL,
  `meta_id` int(11) DEFAULT 0,
  `row_data` varchar(4000) DEFAULT NULL,
  `tx_timestamp` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1
ALTER TABLE `transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `sessionid` (`sessionid`),
  ADD KEY `tx_timestamp` (`tx_timestamp`);
ALTER TABLE `transactions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

when the backup start, it lock this table that have about 13Millions rows, so it take likely 2/3 minutes to backup.
Meanwhile some INSERT ROW request is generated from a php script but, due to table lock, is not processed.
When the table is unlocked, all the inserts query in queue is executed, but not in the same order that it was generated so the result i got is this:
| id | timestamp |
| -------- | -------------- |
| 13634107| 2022-09-02 02:06:53|
| 13634108| 2022-09-02 02:10:23|
| 13634109| 2022-09-02 02:05:53|
| 13634110| 2022-09-02 02:08:03|
the request of 02:05:53 it was insered after the request genereted at 02:10:23
It seems that mysql sql put all the pending request in a "queue buffer" but when the lock is removed it doesnt keep the timeline of the request but it process in paralle way.
ho can i grant the flow between request made during a table lock and the effective insert flow after the unlock action?