Hudson Mercurial checkout throws exception on Debian

Question: I'm trying to configure Hudson to checkout my site's sources from Mercurial but it throws an exception. The /var/lib/hudson/jobs/jobname directory does exist, and I can create a workspace directory in there (even after su hudson), but as soon as I run the Hudson job again this directory disappears and the job ends with the same error:
<code>java.io.IOException: Cannot run program "hg" (in directory "/var/lib/hudson/jobs/jobname/workspace"): java.io.IOException: error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at hudson.Proc$LocalProc.<init>(Proc.java:192)
    at hudson.Proc$LocalProc.<init>(Proc.java:164)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:639)
    at hudson.Launcher$ProcStarter.start(Launcher.java:274)
    at hudson.Launcher$ProcStarter.join(Launcher.java:281)
    at hudson.plugins.mercurial.MercurialSCM.joinWithPossibleTimeout(MercurialSCM.java:298)
    at hudson.plugins.mercurial.HgExe.popen(HgExe.java:191)
    at hudson.plugins.mercurial.HgExe.tip(HgExe.java:171)
    at hudson.plugins.mercurial.MercurialSCM.calcRevisionsFromBuild(MercurialSCM.java:254)
    at hudson.scm.SCM._calcRevisionsFromBuild(SCM.java:304)
    at hudson.model.AbstractProject.calcPollingBaseline(AbstractProject.java:1183)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1172)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:499)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:415)
    at hudson.model.Run.run(Run.java:1362)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:145)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
    at java.lang.ProcessImpl.start(ProcessImpl.java:65)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
</code>
Running on Debian 6.0.1
I wonder if anyone has ran into this before, and hopefully solved it?
Answer: Duh, I overlooked this message in the output:
<code>$ hg clone --rev default http://frodo/cgi-bin/hgwebdir.cgi/projectname "/var/lib/hudson/jobs/jobname/workspace" abort: unknown revision 'default'!
</code>
I had run hg init on the project, but not hg add and hg commit, so there was nothing to clone!
After adding and committing the files all went well....


Scalability in Scala

Question: I am going through Scala book by Martin Odersky.
It states that Scala language is highly scalable,reason being that it allows users to add new features which can be utilised as native language support.
It has got me confused with the term 'Scalability'.
I understand that scalability means ability of a software to handle huge amount of data.
So what's the difference here?
Comment: You can apply the word "Scalability" to a variety of topics, not just throughput.
Comment: ...so in context of Scala scalability means ability to add more features more easily, and it has nothing to do with throughput.  Thanks.
Answer: In the context of Scala, Odersky usually means that it is scalable in the sense that it can be used for a wide range of tasks, from simple scripting to large libraries to behemoth enterprise applications.
It's good for scripting because of its type inference, relatively low verbosity (compared to Java), and functional style (which generally lends itself to more concise code).
It's good for medium size applications and libraries because of its powerful type system, which means it is possible to write code that mostly or only produces errors at compile time rather than runtime (to the extent that is possible). The Play! framework in particular is founded on this philosophy. Furthermore, Scala runs on the JVM and therefore can harness any of the many, many Java libraries out there.
And it's good for enterprise software because it compiles to JVM bytecode, which already has a great track record in enterprise software; further, the fact that it's statically typed makes the maintenance of very large codebases much easier.
Scala is also applicable to a number of other areas, making it even more "scalable": concurrency/parallelism and domain-specific languages come to mind.
Here is a presentation by Odersky, if you start at slide 6 and go forward, you'll see him explain some other uses of Scala as well.
Comment: It's also scalable in the sense that you can add what looks like new syntax in library code that in other languages would have to be built into the language itself.
Comment: Thanks a ton for such a detailed reply.
Comment: @Jasper-M isn't that what's meant by a domain specific language?
Comment: It's what enables the creation of expressive DSLs.

Scalability in Scala


How is styling of the UI for an IOS Apps done?

Question: So with websites on the web we use HTML, CSS and Javascript.

What do we actually use to build the UI for an IOS App?
Is there a CSS/HTML/JS equivalent use for building IOS Apps?
What is the most common way use to design, style the UI of an IOS App?

The reason I ask is because I'm spending longer than expected learning core graphics and would like to move on with the book I'm studying from. I was under the impression core graphics was used for styling of apps and it was like an IOS equivalent of CSS.
Hoping someone could help clear things up thanks.
Regards
Answer: In many cases, images are used for styling in iOS.
For simple things like just changing background and text colors, UIView and its subclasses have direct accessors.
For most things, you won't need core graphics just for styling purposes. It would be easier to help you if we knew more concretely what you want to achieve, though.
The closest thing to a CSS equivalent is appearance proxies, which allow you to specify things like "all instances of UITextField should look have this font, colors and shadow when contained inside a NavigationController". You can override this for specific instances by just setting the desired values on the instance.
Comment: I'll be building an app for a book club and a large group of people who debate, we will have profiles, groups, news feeds etc. The app will have a UI like linked-in/facebook.
Comment: That's not really a *concrete* example.
Comment: I'm far from the stage where the UI will be designed. I'm still teaching myself cocoa-touch. What I do know is that the app will have feel similar to linked in, facebook. Background colour of my choice, small image icons for links, spinners, loaders, flat style UI. I can't really be too specific at this stage because I just don't know exactly how my UI will look but it will definitely be similar to sites I referenced above. You answered most of my questions. I was concerned about font management also but appearance proxies looks like it will take care of my concerns.
Comment: You'll get quite far with those, and you can of course create your own view classes for more specialized and fancy things. Smaller apps with only standard UI concepts (not necessarily looks) can get by entirely without creating their own view classes just by styling the standard UIKit classes. Remember: Images are your friend, especially `UIImage resizableImage...`.
Comment: I was under the impression that images would slow down the app. I think I'm comparing the way apps run a little too much to the way a website does. I normally like to use as much CSS as possible when designing websites and then images here and there when needed for logos, icons etc.
Comment: Images for buttons etc. are very very fast in iOS. Also, the simulator won't give you a realistic picture regarding performance. So not assume, measure speed, and don't optimize prematurely.


How to export/import object and collection types using expdp - Oracle

Question: I'm trying to export a schema using expdp command. All schema objects are imported, except object and collections types.
Do i need to set specific parameter for this?
--Commands
--Export
expdp system/pass@localhost:1521/orcl directory=my_dir schemas = tony_hr
dumpfile=tony_hr.dmp logfile=tpny_hr.log
--Import
impdp system/pass@localhost:1521/orcl directory=my_dir dumpfile=hr_tony.dmp
logfile=hr_tony_imp.log remap_schema=tony_hr:hr2

I simulated the error in a test schema named tony_hr. This is a picture of all of its objects:

The export is executed successful, but when i'm trying to import(using remap_schema to hr2) i get some errors. This is the part where import fails.
ORA-39083: Fallo de creación del tipo de objeto TYPE:"HR2"."O_SEAT" con el error:
ORA-02304: literal de identificador de objeto no válido
El sql que falla es:
CREATE EDITIONABLE TYPE "HR2"."O_SEAT"   OID '02C3315E969E44D6BC7D797EDD9F2D96' IS OBJECT
(
    seat_id VARCHAR2 (8 BYTE),
    seat_category_name VARCHAR2 (32 BYTE)
ORA-39083: Fallo de creación del tipo de objeto TYPE:"HR2"."M_SEATS" con el error:
ORA-02304: literal de identificador de objeto no válido
El sql que falla es:
CREATE EDITIONABLE TYPE "HR2"."M_SEATS"   OID '0A71AFB95CCE4CC78558B571199AF83F' IS TABLE OF o_seat;

Sorry, because error messages are in spanish. Please ask if you have any doubt.
Comment: It's not about having full access to the schema; are you sure the missing objects aren't in another schema and accessed through a synonym? Can you check `all_objects` for the owner and type based on the names of things you are missing?
Comment: Please, add to the question an exact error message from `impdp` which you got while trying to import `scott.dmp`.
Comment: Is the problem on export or import? If on import, are you using the `REMAP_SCHEMA` option, and are you importing back into the same database? Are there any errors in the export or import logs?
Comment: which oracle version?
Comment: are you sure the objects and collections are in a schema that was exported?
Comment: Yes i'm sure. I have full access to the schema i'm trying to export.
Comment: @AlexPoole Yes Alex, problem looks to be on import. I updated the question with the errors i'm giving.
Comment: @ThinkJet i updated the question with import errors.
Answer: Please use the following parameters in your impdp command, it should import your other collection type objects too,
REMAP_SCHEMA=Old_username:New_Username (in case of different schema names )
REMAP_TABLESPACE=Old_tablespace_name:New_tablespace_name ( in case of diff tablespace name)
TRANSFORM=SEGMENT_ATTRIBUTES:n
TRANSFORM=OID:n


How to get the user input in an incomplete Django form field?

Question: I have a "survey" form which has fields - name, id and age. I would like to capture the user entry in the "id" field before the user submits the form for scanning the entered "id" in my database table. How can I capture this entered data and use it in my view function for scanning the database? Can I use javascript to pass the user input to my view function? How would that look like? I am a newbie in Django development so any suggestions would help me big time!
Here is the view function I am trying to design that scans the "id" from my survey table and if there is a match in the past 30 days, then it returns an alert pop up to the user to take the survey or not.
def search(request):
if request.method == 'POST': # If the form has been submitted...
    form = TopicForm(request.GET) # A form bound to the POST data
    if form.is_valid():
        x = form.cleaned_data['id']
    else:
        x = form.cleaned_data['id']
x = request.POST.get('url')

posts = survey.objects.filter('id'=x)
posts1 = survey.objects.filter(date=posts)
delta= date.today - posts1

if delta.days <=30:
    return HttpResponse('Survey NOT required')

else:
    return HttpResponse('Survey required')

SURVEY TEMPLATE FORM.HTML
  <form action="{% url 'FCR1' %}" method='post' id="form" class="table">

    {% csrf_token %}
    {% crispy form %}

     <button> SAVE RECORD ›</button>
</form>

Answer: from datetime import date, timedelta

def search(request):
    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            # Get user id from form data (maybe this is named 'user_id'?)
            id = form.cleaned_data['id']
            # Get the past 30 from today
            past_30_days = date.today() - timedelta(days=30)
            # Create the query, but not evaluate yet
            posts = Survey.objects.filter(id=id, date__gte=past_30_days)

            # Proper way to check if something exists or not
            if post.exists():
                return HttpResponse('Survey NOT required')
            return HttpResponse('Survey required')
        else:
            # form is not valid. Handle this approprietly.
            pass


Label TextColor Binding in DataTamplate xaml Xamarin

Question: I do have a CollectionView with a binding for the text in the labels. This works without a problem.
But now I want to add a binding for the Text Color and I don't know how to do it.
my xaml:
<CollectionView ItemsSource="{Binding List}" SelectionMode="None">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <ScrollView>
                <Grid Padding="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <
                </Grid>
            </ScrollView>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

I have set the bindingcontext in the codebehind.
In a normal label without the DataTemplate, the binding TextColor is working.
How can I tell the xaml that it should use the bindingcontext of the page for the TextColor?
Thanks for your help!
Comment: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/relative-bindings
Comment: @json thanks, found the answer there
Answer: @Json comment had the answer.
Needed to add the following
xmlns:ViewModels="clr-namespace:AppName.ViewModels"

TextColor="{Binding Source={RelativeSource AncestorType={x:Type ViewModels:MyViewModel}}, Path=TextColor}"


I'm trying to access an AWS API Gateway inside of a VPC, but keep getting timeout errors

Question: I have an AWS API gateway that I created with zappa and an ECR docker image. I assigned the lambda function to a VPC but can no longer access the API.
I created an internet gateway and have the route table routing 0.0.0.0/0 and ::/0 to it.
I have all traffic allowed on all ports on the security group as well.
However, whenever I try to access any endpoints I get a timeout error. If I take the lambda function out of the VPC I am able to access all the endpoints.
Comment: Any findings on this issue?
Answer: You cannot access API gateway from lambda directly, if your lambda inside VPC. In this case you have to use VPC endpoint.

You can use Lambda functions to proxy HTTP requests from API Gateway to an HTTP endpoint within a VPC without Internet access. This allows you to keep your EC2 instances and applications completely isolated from the internet while still exposing them via API Gateway. By using API Gateway to front your existing endpoints, you can configure authentication and authorization rules as well as throttling rules to limit the traffic that your backend receives.

Reference: https://aws.amazon.com/blogs/compute/using-api-gateway-with-vpc-endpoints-via-aws-lambda/#:~:text=Conclusion,exposing%20them%20via%20API%20Gateway
Comment: This link does not address the OP's question. OP does not want to route requests from API Gateway to a private VPC, but rather they want to access an API Gateway resource (I'm assuming via HTTP) FROM a Lambda living inside a private VPC that has a configured IG for public access. Our group is facing the same timeout issue.


Views programmatically limit results

Question: I'm trying to programmatically include a view in a module and need to limit the number of results displayed. I tried something like this, but it doesn't work:
<code>$view->display[$display_id]->handler->options['items_per_page'] = 2;
</code>
I also tried, but neither this worked:
<code>$view->display[$display_id]->display_options['items_per_page'] = 2;
</code>
Any ideas? Or at least some links to Views 2 programmatically implementation?
Thanks
Answer: You are looking for set_items_per_page()(6), set_items_per_page()(7). Essentially the function does what you are already trying to do, but probably you are calling it on the wrong object, so use the function instead, and Views will ensure it's the right object. :)

Views programmatically limit results


Do I need to re-install .NET (or something) after mscorlib.dll chkdsk error?

Question: After noticing that some periodic hanging behavior on my Dell XPS 210 (running Vista 32-bit) seemed correlated to disk activity, I ran chkdsk /r. The system seems much better, for now.
However, I still have a concern. It found and fixed a bunch of files but they were mostly just data such as pictures. Two of them were .NET DLLs, however, and I'm wondering if I'm going to see flakiness from .NET applications if I don't re-install .NET? Here are the relevant error lines. I'm not sure how to interpret them; was chkdsk able to successfully recreate the DLLs, or not?

Windows replaced bad clusters in file 225726 of name
\Windows\MICROS~1.NET\assembly\GAC_32\mscorlib\V40_40~1.0__\mscorlib.dll.
Read failure with status 0xc0000185 at offset 0x275cbce000 for 0x10000 bytes.
[blah blah blah]
Read failure with status 0xc0000185 at offset 0x275cbe9000 for 0x1000 bytes.
Windows replaced bad clusters in file 225906 of name
\Windows\MICROS~1.NET\assembly\GAC_MSIL\SYSTEM~3.SER\V40_40~1.0__\SYSTEM~1.DLL.
Read failure with status 0xc0000185 at offset 0x272686c000 for 0x10000 bytes.
[blah blah blah]
Answer: That's .Net 4.0 which not many applications use (yet) so you probably haven't seen any issues.  I would uninstall .Net v4 and then re-install it just to be sure.
Answer: Use sfc /scannow which will perform a check of your system files and replace any corrupt files, including your .net DLLs.


JS - TEXT File GZIP'ed for UPLOAD (fixed: wrong callback)

Question: Browse Files, Upload and GZIP compression all work fine, but the GZIP'ed NewFile is ignored and the original file[i] is sent.
Instead of passing the file[i] object to Upload(), I create a new File object with the GZIP'ed data which is then passed to Upload(), that's the "<<< HERE <<<" comment below in the code:
<!DOCTYPE html>

<meta charset="UTF-8" />
<title>Demo</title>

Send new/updated text to the server:

<form id="upload" action="/?entity" method="POST"
      enctype="multipart/form-data">
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="3000000" />

 <input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />

Drop your TEXT
file(s) here!

 <button type="submit">Upload Files</button>

</form>

<fieldset><legend>Server Reply</legend>

</fieldset>

<fieldset><legend>Network Transfer</legend>

</fieldset>

<fieldset><legend>Dropped Files</legend>

</fieldset>

Yet, Upload() sends the original file[i] object rather than my newly-created object. I am certainly missing something obvious but I don't see what.
The whole HTML/JS code is posted so people can test it at home.
Answer: The GZIP payload was empty because the source file was not yet loaded after readAsText(file):
Output:

before read: EMPTY
after read : LOADING
onloadend  : DONE         <<<<<< onload[END]

qcm.txt 2.99 KB (read 2.99 KB, comp 0.8 KB) <<<<<< credible compression
Working code:
var rdSt = {};
rdSt[FileReader.EMPTY]   = 'EMPTY';
rdSt[FileReader.LOADING] = 'LOADING';
rdSt[FileReader.DONE]    = 'DONE';

function ParseFile(file)
{
  if(!file.type.indexOf("text")) // "text/plain"
  { var reader = new FileReader();
    reader.onloadend = function(e)
    { var data = e.target.result;
      var gzip = new Zlib.Gzip(data);
      var comp = gzip.compress();
      var newFile = new File([new Uint8Array(comp)], file.name,
                            {type:'text/plain'});

      Output('- onloadend  : '+rdSt[reader.readyState]+"
");
      Output(file.name +" "+ Math.round((file.size/1024)*100)/100
      + " KB
"
      + "(read " + Math.round((file.size/1024)*100)/100
      + " KB, comp "
      + Math.round((comp.length/1024)*100)/100 +" KB)
");

      UploadFile(newFile); // <<<<< MUST be done HERE!
    }

    Output('- before read: '+rdSt[reader.readyState]+"
");
    reader.readAsText(file);
    Output('- after read : '+rdSt[reader.readyState]+"
");
  }
}

So a callback was mandatory - I just did not have the right one (onload instead of onloadend).
Obviously, newFile was always uncompressed because compression did not even started! And ParseFile() could not return newFile because compression ends only with onloadend() (the callback calls UploadFile() now).
As a latest exercise the zlib.js "Gzip" compression does not respect the HTTP  GZIP standard (or I am misusing yet another JS library).
https://www.javascripture.com/ helped me a great deal to find relevant Javascript documentation (a scarce resource).
With a bit of luck, this painful hard work will help others...


What is the covariance/correlation between $X$ and $X^2$ (without assuming normality)?

Question: If $X \sim \text{N}(0, \sigma^2)$ then it is well-known that $X$ and $X^2$ are uncorrelated (i.e., they have zero covariance).  There are also certain distributions for which these random variables are independent.  However, uncorrelatedness does not hold in general --- it occurs for the normal distribution with zero mean and certain other cases.
What is the general formula for $\mathbb{C}(X,X^2)$ without assuming normality or zero mean?  What is the general formula for the corresponding correlation?
Answer: The general form of the covariance depends on the first three moments of the distribution.  To facilitate our analysis, we suppose that $X$ has mean $\mu$, variance $\sigma^2$ and skewness $\gamma$.  The covariance of interest exists if $\gamma < \infty$ and does not exist otherwise.  Using the relationship between the raw moments and the cumulants, you have the general expression:
$$\begin{equation} \begin{aligned}
\mathbb{C}(X,X^2)
&= \mathbb{E}(X^3) - \mathbb{E}(X) \mathbb{E}(X^2) \\[6pt]
&= ( \mu^3 + 3 \mu \sigma^2 + \gamma \sigma^3 ) - \mu ( \mu^2 + \sigma^2 ) \\[6pt]
&= 2 \mu \sigma^2 + \gamma \sigma^3. \\[6pt]
\end{aligned} \end{equation}$$
The special case for an unskewed distribution with zero mean (e.g., the centred normal distribution) occurs when $\mu = 0$ and $\gamma = 0$, which gives zero covariance.  Note that the absence of covariance occurs for any unskewed centred distribution, though independence holds for certain particular distributions.

Extension to correlation: If we further assume that $X$ has finite kurtosis $\kappa$ then using this variance result it can be shown that:
$$\mathbb{V}(X) = \sigma^2
\quad \quad \quad \quad \quad
\mathbb{V}(X^2) = 4 \mu^2 \sigma^2 + 4 \mu \gamma \sigma^3 + (\kappa-1) \sigma^4.$$
It then follows that:
$$\begin{align}
\mathbb{Corr}(X,X^2)
&= \frac{\mathbb{Cov}(X,X^2)}{\sqrt{\mathbb{V}(X) \mathbb{V}(X^2)}} \\[6pt]
&= \frac{2 \mu \sigma^2 + \gamma \sigma^3}{\sqrt{\sigma^2 \cdot (4 \mu^2 \sigma^2 + 4 \mu \gamma \sigma^3 + (\kappa-1) \sigma^4)}} \\[6pt]
&= \frac{2 \mu + \gamma \sigma}{\sqrt{4 \mu^2 + 4 \mu \gamma \sigma + (\kappa-1) \sigma^2}}. \\[6pt]
\end{align}$$
For the special case of a random variable with zero mean we have $\mu=0$ which then gives:
$$\mathbb{Corr}(X,X^2)
= \frac{\gamma}{\sqrt{\kappa-1}},$$
which is the scale-adjusted skewness parameter.
Comment: @AntoniParellada: Here $\sigma^2$ is the variance, so $\sigma^3 = (\sigma^2)^{3/2}$ is the variance to the power $3/2$.  The expression you give uses notation that is not in the post, but it appears to be giving the relationship between the skewness and the third central moment (see e.g., [definition of skewness](https://en.wikipedia.org/wiki/Skewness#Definition)).
Comment: Well, the skewness is *defined* as $\gamma \equiv \mathbb{E}((\tfrac{X-\mu}{\sigma})^3)$, so you then have $\gamma \sigma^3 = \mathbb{E}((X-\mu)^3) \equiv k_3$.
Comment: Independence occurs when we have a degenerate distribution (an interesting case of your covariance equation since we can have $\text{cov}(X,X^2)=0$ even when $\mu\neq0$ because now $\sigma =0$), or when we have a  scaled Rademacher distribution with $p=0.5$.
Comment: I probably missed the part on the Wikipedia link you provide, but can you remind me of what $\sigma^{\bf 3}$ represents, and how to get the expression $k_3 = \gamma \sigma^3$?
Comment: In terms of the notation, $k_3=\gamma \sigma^3$ comes from my assumption that $\gamma \sigma^3$ has to be the expression of the third cumulant.


How to load images into a page using a php file but wait for all images load before displaying

Question: This is the minimum code in order to demonstrate the effect.
https://replit.com/@computinginschools/imageload#index.php
This is a simple php file which loads image using an external script, image.php, and displays them on the page. The reason I have done this on my live site is because the images are stored outside the www folder and I need the image.php script to access them. To make it easier I have just put everything under the webroot.
In this example, all the images are located in a folder called images next to index.php.

    <title>Image Load</title>

    <?php
      $images = glob('images/*.png');
      foreach($images as $image){
        echo('');
      }
    ?>

This is the image.php file which loads the images.
<?php
  $path = urldecode($_GET['i']);

  if (file_exists($path)) {
    $extension = pathinfo($path)['extension'];
      header('Content-type:'.$extension);
      header('Cache-control:public, max-age=604800');
      header('Accept-ranges:bytes');
      header('Content-length:'.filesize($path));
      header('Last-Modified: '.date(DATE_RFC2822, filemtime($path)));
      header_remove('pragma');
      echo(file_get_contents($path));
  }
  else {
    echo("File not found: ".$file);
  }
?>

The script works fine to display the images however, the loading is often prolonged with all the images loading in a 'wave' as the image.php file renders them on the screen after index.php has loaded. The REPL is fast so this is not really noticeable, however, on my production site, this effect is quite pronounced.
I would like to know if there is a way of delaying the loading of the images in index.php until all the images rendered by images.php have loaded. My intention is to set the display attribute of the images to none by default and then, when the index.php document has loaded, apply an appear animation to all the images on the page to make them fade into view.
It would be even better if I could embed some kind of loading animation in the container for each image.
Please help?
Comment: The end desired result can be achieved with javascript. [link]https://stackoverflow.com/search?q=javascript+preload+images   .You could possible use the sleep function of php to maybe work, but I think this is better done with javascript. [link]https://www.php.net/manual/en/function.sleep.php in your loop on index.php
Answer: This can't really be done in PHP; the slowdown is from the browser going through the HTML and loading all of the images. If you would like to hide the page until everything is loaded, then you can set the HTML body to display: none, and the use JavaScript to remove that once all of the images are loaded. This has to be done from JavaScript because there isn't really any way to check on the browser's status from PHP.
If you must do this from PHP, then you can have all of the images inline using base64 encoding, although this is just about the least efficient way of serving images, and will probably cause major slowdowns. The format to do so is like this:
<img src="data:image/jpeg;base64,<?php echo base64_encode(file_get_contents($image)); ?>">

Comment: When I needed to do something similar, I used  a full page div with a centered Bootstrap spinner before the content, and then had another div with all of the content with `display: none;`. Once everything is loaded, I then hid the spinner and displayed the actual content.
Comment: Thank you - that's a really interesting way of handling it. I've currently done it by hiding the images and then adding an onload event to a clone of the image - I found it online and I've implemented it here...

https://replit.com/@computinginschools/imageload#index.php

If I were to wait and then display the whole page, how do I do a loading animation?
Comment: Thank you - I've not used Bootstrap before but I think I've implemented something similar now : https://the.computing.cafe/. Now I sometimes notice that the page 'grows' as the hidden content loads (mainly the pictures) but I don't think I can prevent that?


Como fazer upload de aquivos grandes para o google drive

Question: Estou tentando fazer o upload de arquivos de 1-4Gb para o google drive(v3) , usando phyton3.8, porém quando sempre tenho erros na execução:
TypeError: 'PreparedRequest' object is not callable
def uploaddearquivo(nome:str, caminho:str):
    size = os.path.getsize(caminho)
    access_token = "###"
    headers = {"Authorization": "Bearer " + access_token, "Content-Type": "application/json; charset:UTF-8","X-Upload-Content-Type":'application/octet-stream','X-Upload-Content-Length':str(size)}
    params = {
        "name": nome,
        "mimeType": "application/octet-stream"
    }
    http = requests.post(
        "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable",
        headers=headers,
        data=json.dumps(params)
    )

    file_metadata = {'name':nome}
    chunk = 10*(1024*256)
    fh = open(caminho,'rb',buffering=chunk)
    media = MediaIoBaseUpload(fh,chunksize=chunk,resumable=True,mimetype=FILESTYPE['default'])
    # media = MediaFileUpload(caminho,chunksize=chunk,resumable=True)
    file = DRIVECONTROLER.files().create(
        body=file_metadata,
        media_body=media
    ).execute(http=http,num_retries=3)
    media.stream()
    response = None
    while response is None:
        status, response = file.next_chunk()
        if status:
            print ("Uploaded {}%".format(int(status.progress() * 100)))
    print("File ID: {}".format(file.get('id')))

no que estou errando?
Em uploads menores não tenho problema utilizando apenas o MediaFileUpload
Answer: O problema tava em um conflito entre a google-api-python-client e a httplib2.
foi resolvido com o downgrade dos mesmos
pip install httplib2==0.15.0

pip install google-api-python-client==1.6

link pra consulta:
https://stackoverflow.com/questions/59815620/gcloud-upload-httplib2-redirectmissinglocation-redirected-but-the-response-is-m


One- vs two-sided credible interval for Poisson process with all zero counts

Question: In a related question, I asked about a confidence interval for the estimate of the mean of 50 observations of a Poisson random variable, for which all 50 observations had a count of zero. In the comments to an answer to that question by whuber, it was pointed out that you shouldn't use a one-sided confidence interval just because you have all zero counts. If you used a two-sided interval in situations where you observed non-zero counts and one-sided intervals when you observed all zero counts, your confidence intervals would no longer have their nominal level of coverage.
In that question a simulation of coverage convinced my that that was a bad strategy.
My question here is how would a Bayesian argue one way or the other for one- vs two-sided credible intervals for the same situation with all zero counts.
Consider a prior distribution of $gamma(1, 0)$, with a Poisson likelihood, that results in a posterior distribution of $gamma(1, 50)$, for data consisting of 50 observations of zero counts.
How would you argue against using a one-sided credible interval?
Comment: How could such a prior result in a nonsingular posterior if it assigns 0 probability mass to every possible rate parameter in the support ?
Answer: Interesting philosophical issues arise with very small Poisson rates. Also
with the choosing of appropriate prior distributions for Bayesian analysis
of low rates.
Hypthetical particle. Suppose I'm looking for evidence of a theoretically predicted, but never
observed G-particle. After 50 runs of my particle collider, I have seen
no traces of the kind G-particles should make. So in 50 runs I have seen
no evidence that G-particles exist.
According to your prior, I have two possible 95% credible intervals:
two-sided $(0.0005, 0.0738)$ and one-sided $[0, 0.0600)$ or "rate below 0.06."
<code>qgamma(c(.025,.975),1,50)
[1] 0.0005063562 0.0737775891
qgamma(.95,1,50)
[1] 0.05991465
</code>
On what grounds would you defend the two-sided interval with its lower bound
$0.0005?$ Certainly, I have no empirical evidence for existence of G-particles,
so that implied possibility of a non-zero rate relies altogether on (perhaps unintended) 'information' from
my "noninformative" prior.

You ask, "How would you argue against using a one-sided credible interval?"
In this scenario, I would not make such an argument. But as always, you might find someone with a different opinion.

Rare particle. How is it different if I am trying to figure out if my collider is capable
of observing H-particles, which are known to exist, but to be very rare?
Then I might choose a prior that focuses on the characteristics of my collider.
The lower limit of a two-sided credible interval might be interpreted
as a lower limit of my ability to detect H-particles.


The Cantor set is not strong measure zero

Question: $A \subseteq \mathbb R$ is strong measure zero if given any sequence $( \epsilon_n )_{n \in \mathbb N}$ of positive reals there is a sequence $( I_n )_{n \in \mathbb N}$ of open intervals such that $I_n$ has length at most $\epsilon_n$ for each $n$, and $A \subseteq \bigcup_{n \in \mathbb N} I_n$.
I have read that the Cantor set is an example of a null set which is not strong measure zero.
Can anyone explain why or direct me to a reference which contains a proof?
Answer:
Lemma. If $X \subseteq [0,1]$ is a strong measure zero set, and $f : [0,1] \to [0,1]$ is continuous, then $f[X]$ is also strong measure zero.
proof. Note that $f$ is uniformly continuous, so for each $\varepsilon > 0$ there is a $\delta ( \varepsilon ) > 0$ such that if $I \subseteq [0,1]$ is an interval of length $\leq \delta ( \varepsilon )$, then $f[I]$ has length $\leq \varepsilon$.  Given a sequencce $\{ \varepsilon_i \}_{i \in \mathbb{N}}$ of positive reals, we know we can cover $X$ by a sequence $\{ I_i \}_{i \in \mathbb{N}}$ of intervals such that $I_i$ has length $\leq \delta(\varepsilon_i)$. Then $f[X] \subseteq \bigcup_{i \in \mathbb{N}} f[I_i]$.

Recall now that the Cantor function is continuous, and the image of the Cantor set under this function is the unit interval $[0,1]$ which is clearly not strong measure zero (or even Lebesgue measure zero).
Comment: Perfectly clear. Thank you!
Answer: For a more direct approach:  Suppose that $I_1 , I_2 , \ldots$ are open intervals in $\mathbb{R}$ such that $I_n$ has length $3^{-n}$.
Note that $I_1$ must be disjoint from either $[ 0 , \frac 1 3 ]$ or $[ \frac 2 3 , 1 ]$ (or both, I guess, if $I_1$ was chosen particularly badly). Let us label one of these intervals disjoint from $I_1$ by $A_1$.
Now $I_2$ must be disjoint from at least one of the two closed intervals obtained from deleting the open middle third of $A_1$: let us label one of these $A_2$.
And we continue like this.  For each $n$ the open interval $I_{n+1}$ must be disjoint from one of the two closed intervals obtained from deleting the middle third of $A_n$, and we label one of these $A_{n+1}$.
So we have a decreasing sequence $A_1 \supseteq A_2 \supseteq \cdots$ of nonempty compact subsets of $\mathbb{R}$, and so their intersetion must be nonempty. It is clear that any point of this intersection (actually, there can only be one) must belong to the Cantor set, and is not in $\bigcup_{i=1}^\infty I_n$.  Thus the sequence of open intervals we began with cannot cover the Cantor set.
Comment: Thank you for this detailed direct proof!


problem in httpdelete request asp.net core 2

Question: Hello i am working on asp.net core 2.2 web api , my get request is working fine but i am having problem in HTTPDELETE request, my code for the delete request is as follows
 [Route("api/[controller]")]
[ApiController]
public class PatientController : ControllerBase
{
    IPatientManager _patientManager;
    IEnumerable<Patient> patientList;

    public PatientController(IPatientManager patientManager)
    {
        _patientManager = patientManager;
    }

    [HttpGet]
    public IEnumerable<Patient> Get()
    {
        return (patientList = _patientManager.GetAllPatients());
    }

    // DELETE api/values/5
    [HttpDelete("api/Patient/{id}")]
    public bool Delete(long id)
    {
        if (_patientManager.DeletePatient(id))
            return true;
        else
            return false;

    }
}

}
when i put the request in URL as localhost:3, n922/api/Patient/444373 it gives me HTTP ERROR 404 , my startup.cs file is using the below code for MapRoute
 app.UseMvc(opt =>
            {
                opt.MapRoute("Default",
                    "{controller=Patient}/{action=Get}/{id?}");
            });

to start the my PatientController instead of ValuesController, Please help what is problem where i am doing wrong? TIA
Answer: You have a route prefix defined on your controller as api/[controller], which translates to /api/Patient. Then, your route on your action is defined as api/Patient/{id}, which makes the entire route to this action: /api/Patient/api/Patient/{id}. That's obviously not right and is the source of your 404. Change the route to just {id}.
[HttpDelete("{id}")]
public bool Delete(long id)

Comment: Sorry but this is not working for me either when i put the request as /api/patient/5 it gives me 405 error :( in the browser


Apache 2.2 LDAP Authentication Error 500 - AuthLDAPURL

Question: I have an Apache server on RHEL 6 that uses our active directory for authentication and when we added a new "LocationMatch"
AuthLDAPURL ldap://ad.company.com/DC=ad,DC=company,DC=com?samaccountname?sub?(memberOf=CN=RnD,CN=Users,DC=domain,DC=com)

and on this location we get error 500
on other location matches :
AuthLDAPURL ldap://ad.company.com:389/OU=MA,DC=ad,DC=company,DC=com?samaccountname

it works flawlessly.
Answer: I am having exact same problem today, without a "ou=", AuthLDAPURL will return a 500 error.
Finally found a url: http://clabs.org/blog/RawStuff
It mentioned: "
If you need to authenticate against different OUs, then there are two options. Ideally, simply changing the ldap url to work from the root should work:
AuthLDAPURL "ldap://eiadserver1.einstruction.com:389/DC=einstruction,DC=com?sAMAccountName?sub?(objectClass=user)"

However, against Active Directory this doesn't seem to work, because in addition to the search results, it will also return referrals to other directory partitions, and Apache can't grok these or somesuch. A bug has been filed for this, and the report includes a patch.
But, if your Active Directory has a Global Directory configured, typically on port 3268, then you might be able to get the query you need to work:
AuthLDAPURL "ldap://eiadserver1.einstruction.com:3268/DC=einstruction,DC=com?sAMAccountName?sub?(objectClass=user)"

"
I checked our AD server and it's listening on port 3268, so I changed it, it did fix the problem.
Comment: Welcome to Server Fault! While this may theoretically answer the question, [it would be preferable to include the essential parts of the answer here](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/8259#8259), and provide the link for reference.
Comment: The problem with this, is that it gives access to all Active Directory users, I need a solution where I can give access to only certain PO.


App is Rejected: crashes on launch

Question: I have an app for iPhone, which is already in the App Store but i made some new features and tried to submit to the App Store.
On 1st time submission

We were unable to review your app, as it crashed on launch on the following device(s):
iPhone 4S running iOS 8.1- iPhone 5C running iOS 8.1- iPhone 5S
  running iOS 8.1- iPhone 6 running iOS 8.1- iPhone 6 Plus running iOS
  8.1- iPod Touch Fifth Generation running iOS 8.1
We have attached detailed crash logs to help troubleshoot this issue.

I already tested it with test flight in many devices, but i can't reproduce the error.
Theres any way i can simulate the environment that apple uses to test it, or maybe analyze the crash report any way?
Crash Report
https://www.dropbox.com/s/h60llp5zzkrodln/ezmall_2015-05-21-214647_p01a019-ph-4s-DN00AO6A-10.txt?dl=0
Comment: They will have provided a crash report. What does it say?
Comment: Just added the Crash report in the question
Answer: In the crash log it shows you why it is crashing...

reason: '*** -[__NSPlaceholderDictionary
  initWithObjects:forKeys:count:]: attempt to insert nil object from
  objects[2]'

You're best just pasting the crash log into the question. Makes it easier to read.
Anyway, you can't put nil into a dictionary. The result is that the app will terminate.
Without seeing any code it's pretty much impossible to determine why this is happening but it should give you something to look for.
In fact, it looks like you're attempting to create a dictionary with 3 or more items and the 3rd one is nil.
Comment: The problem is, in DEV ou with test flight i can't reproduce the error (the app just works fine).

Theres any way i can reproduce the environment that apple uses? Maybe that way the crash occurs
Comment: @ViniciusAlbino you could try to symbolicate the crash log. Might tell you the class that's crashing. How complex is your app startup though? Is it so complex that you can't find the bit that is creating a dictionary? Might be worth just looking through the code. Maybe post some here.

App is Rejected: crashes on launch


Como usar deep-learning para fazer parse de formulários com moradas?

Question: Tenho uma aplicação para a qual preciso importar dados pessoais. Recebo frequentemente ficheiros excel ou csv/txt com campos como nome, morada, email, telefone, etc... A formatação dos ficheiros varia, a ordem também, e às vezes há campos em branco. O que pode ajudar um algoritmo a perceber os campos é que em cada ficheiro que recebo com N entradas todas têm a mesma organização de colunas. O que varia é o formato de cada ficheiro, e não dentro de cada ficheiro.
Eu consigo fazer isto à mão, muitas vezes com algoritmos com RegExp mas que acabam por ter sempre uma componente grande de "custom made", ou seja preciso tratar os dados manualmente.
Como seria possível usar JavaScript e deep-learning para ensinar o programa a reconhecer os campos, formatá-los de maneira que possa consumir na minha aplicação e eventualmente indicar campos mal preenchidos tendo o programa certeza de que tipo de campo deveria ser?
Exemplo de input, onde cada linha é um exemplo de como as colunas podem ser num dado ficheiro:
// nome 1, nome 2, telefone, email, campos de morada
["joao", "pereira", "215548808", "email@example.com", "rua das peras", "2890", "campo alegre"]

// nome 1, nome 2, data de nascimento, email, codigo postal, morada, telefone
["maria", "conceição", "10051978", "email@example.com", "2400", "rua de porto alegre", "98337449"]

// nome completo, morada completa, mail pessoal, mail trabalho, telefone fixo, telemovel
["andreia pires", "rua do jardim nr10 3988 porto", "firstname.lastname@example.com", "firstname.lastname@example.com", "070234382", "013387484"]

E os campos que a minha aplicação usa são:
nome 1 | nome 2 | email | telefone | morada | codigo postal

Comment: Oi Sérgio. Eu temo que esse seu problema seja um pouquinho difícil. Campos alpha numéricos, em uma coluna ou mais, talvez possam ser tratados com [n-grams](https://www.youtube.com/watch?v=s3kKlUBa3b0) de forma a se obter a probabilidade de um conjunto de palavras formar um endereço (problema de categorização ou *tagging*). Mas vai ser bem difícil tratar os campos numéricos (telefone, data de nascimento sem `/`, código postal, etc). Eu tenho pouca experiência no processamento de linguagem, mas não enxergo variação estatística suficiente entre eles pra que se seja capaz de diferenciá-los.
Comment: Talvez seja mais fácil você usar um sistema especialista simples (um sistema baseado em regras): você cria um conjunto de regras IF-THEN que vão trabalhar em conjunto de forma a tentar gradualmente refinar o que é mais provável cada coluna ser (com base em medidas do conteúdo dos campos). O seu sistema faz uma pré-classificação e apresenta as colunas para o usuário com as sugestões automáticas, mas **o usuário sempre decide** como tratar as colunas. É importante o usuário decidir porque mesmo usando alguma tecnologia *state-of-the-art* o que vc vai obter são probabilidades, jamais certezas.
Comment: As medidas dos campos serão bastante individuais (número de caracteres, se tem alpha ou só dígitos, se tem a palavra "Rua", etc, etc, etc) e serão heurísticas que você como especialista do domínio vai criar. Aparentemente existem algumas engines de regras para Javascript. Vale dar uma olhada: http://stackoverflow.com/questions/3430885/lightweight-rules-engine-in-javascript Boa sorte! :)
Comment: Por nada, Sérgio. É até onde eu consigo ajudar com esse tipo de problema. Vamos esperar pra ver se alguém posta uma resposta mesmo. :) Quanto às tags eu não tenho uma opinião muito bem formada, mas tendo a achar que em inglês podem ser mais apropriadas. Deve ser mesmo melhor discutir isso no meta.
Comment: @LuizVieira obrigado pelas dicas! Apontaste-me caminhos e soluções que não tenho conhecimento para concluir sozinho, isso vai ajudar muito a pesquisa para este problema. Faz sentido usar _n-grams_, não sabia sequer o nome dessa linha de análise, esse video vai esclarecer. Dar pesos à strings, ou eventualmente tipos numéricos, é um dos caminhos que vou explorar. Obrigado! (Quanto a tags não sei se EN ou PT, talvez poste no meta sobre isso)
Answer: Essa pergunta é legal, mas a resposta seria quase um projeto grande de trabalho. Com deep learning é possível resolver o seu problema. Com javascript, eu não sei responder. Vou dar uma resposta em R que é facilmente adaptável para python e depois indico algumas libs que talvez você consiga fazer com javascript.
Vamos lá.
Coleta de dados
Como em qualquer projeto de aprendizado de máquina você precisará de um banco de dados com algumas informações já classificadas. Felizmente, no seu caso deve ser simples de obter um banco grande sem muito esforço.
Aqui, fiz um catadão de informações:

peguei uma lista de nomes de aprovados na FUVEST de 2014 e separei em nome e sobrenome
peguei uma lista como nome de ruas em SP

Criei um banco de dados que fica da seguinte forma:
# A tibble: 10 × 2
        tipo                              valor
       <chr>                              <chr>
1        rua rua doutor heitor pereira carrilho
2        rua               rua hipólito vieites
3  sobrenome                     fogaca galdino
4       nome                             rafael
5        rua             rua ida câmara stefani
6  sobrenome                       alves duraes
7  sobrenome                       keiko sonoda
8  sobrenome             barcellos mano rinaldi
9       nome                             victor
10       rua                rua angelo catapano

No final esse banco de dados tem 60k observações divididas entre nome, sobrenome e rua. Você pode adicionar outros tipos de dados que você desejar como telefone, CEP e etc. Aqui não fiz isso para simplificar.
Tratamento dos dados
Da forma com que os dados estão, eles não estão adequados para serem consumidos por um modelo de deep-learning. Precisamos de um array que vamos chamar de X. Esse array tem que ter 3 dimensões: (n, maxlen, len_char_tab) em que:

n é o número de observações que você possui
maxlen é o número máximo de caracteres que uma observação pode ter
len_char_tab é o número de caracteres distintos em todo banco de dados

Ou seja, transformo cada sequencia do tipo "abc" em uma matriz
de forma
1 0 0
0 1 0
0 0 1

Transformei um esse banco de dados nisso que eu preciso da seguinte forma:
library(purrr)
char_table <- stringr::str_split(df$valor, "") %>%
  unlist() %>%
  unique()

vec <- map(
  df$valor,
  ~unlist(str_split(.x, "")) %>%
    map_int(~which(.x == char_table))
)

maxlen <- max(map_int(vec, length))
vec <- pad_sequences(vec, maxlen = maxlen)
vec <- apply(vec, c(1, 2),function(x) as.integer(x == 0:64))
vec <- aperm(vec, c(2,3,1))

Aqui o meu objeto vec é o array x que eu estava discutindo e fica com as seguintes dimensões: 60023    58    65.
Precisamos também de uma matriz chamada de Y que terá a seguinte dimensão: (n, n_tipos). n é o tamanho da sua amostra e n_tipos é o número de tipos distintos. O conteúdo dessa matriz é 1 se a observação é do tipo i e 0 caso contrário.
Fiz isso dessa forma:
all_res <- unique(df$tipo)
res <- sapply(df$tipo, function(x) as.integer(x == all_res)) %>% t()

O objeto res é a matriz Y que comentei e tem dimensão:  60023, 3
Definição do modelo
Agora vamos usar o keras para definir uma LSTM.
Não vou tentar explicar o que é uma LSTM porque é muito difícil e o Colah já explicou 100x melhor do que qualquer pessoa explicaria. Leia masi aqui
O código para definir o modelo está abaixo:
library(keras)
model <- keras_model_sequential()
model %>%
  layer_lstm(units = 128, input_shape = c(58, 65)) %>%
  layer_dense(3) %>%
  layer_activation("softmax")

model %>% compile(
  optimizer = "adam",
  loss = "categorical_crossentropy",
  metrics = "accuracy"
)

Treino do modelo
Treinar o modelo é a parte masi fácil:
model %>% fit(
  x = vec, y = res,
  validation_split = 0.1,
  shuffle = TRUE,
  batch_size = 32
)

Resultado:
Train on 54020 samples, validate on 6003 samples
Epoch 1/10
54020/54020 [==============================] - 372s - loss: 0.0966 - acc: 0.9707 - val_loss: 0.0070 - val_acc: 0.9992

Em uma só epoch o modelo conseguiu acertar praticamente todos as observações que deixei como validação. Claro que meu banco de dados é muito mais simples do que o seu, ele está bonitinho, e a maioria das ruas estão com "rua" na frente. O que ajuda bastante. Espere resultados piores do que isso, mas talvez não tão piores.
Uso
No seu caso, após treinar o modelo em um banco de dados, eu aplicaria as previsões em cada uma das colunas e veria qual é o resultado que masi aparece, se é nome, sobrenome ou endereço e marcaria que essa coluna é deste tipo.
Mas e o javascript?

tem como traduzir modelos treinados no keras para javascript (apenas para aplicar) usando essa lib: https://github.com/transcranial/keras-js
Nunca usei então não sei se é boa.
tem essa daqui também: http://cs.stanford.edu/people/karpathy/convnetjs/
mas acho que não treina LSTM's.

Banco de dados
Deixei o banco de dados disponível aqui nesse link https://drive.google.com/open?id=0B9I1XHoC4uO6anJTbmJzelppeFE
Você pode ler no R usando df <- readRDS("df.rds").


AWS Client VPN Access to a Peered VPC

Question: In my AWS infrastructure there are a few VPC.
3 days ago I created Client VPN in VPC1, and successfully configured access to VPC2 according the instruction: https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/scenario-peered.html.
Today I deleted the second VPC2 and created another one. I configured peering between VPC1 and VPC2, it works, but I can not configure VPN for access to the VPC2 (simplified scheme in the attachment).1
From upper instruction: "Associate the subnet you identified earlier with the Client VPN endpoint that you created."
I go to Client VPN Endpoints > Create Client VPN Association to Target Network, and see: "You can associate subnets in one VPC to a Client VPN Endpoint."
But it contradicts official Amazon docs. And I can choose the VPC2, choose a subnet from this VPC and get an error: "Subnet you're associating is from a different vpc" (Sure! It's exactly what I need and what I do)
Do you have any ideas what is happening? How to avoid such error and make VPN works with new VPC?
Thank you in advance.
Answer: I found a reason. It was not because I cannot associate VPC2-subnets with VPN. It's not necessary. As I understood, in AWS association means "VPN endpoint directly connected to this subnet".
Commonly you don't need create special routes between different-Avialability-Zone-subnets. But for VPN it's necessary.
VPN route to VPC2-subnet should be via VPC1-subnet in the same Avialability Zone (AZ).
Route to 10.20.100.0/24 will not work via 10.18.10.0/24.
So you must have a VPN-associated subnet in the same AZ and route traffic via this subnet.

AWS Client VPN Access to a Peered VPC


How do I save and retrieve CKEDITOR media (images and video) on a CDN?

Question: I am using CKeditor, and I need to add media in content. I have enabled the media in the CKeditor configuration.

Then I upload an image:

The image is being added:

Checking the path for the image :

It gets saved in the local server, while I want it to be saved in a CDN.
I am also using the Media module and CDN old S3 module. which saves all the media in the CDN, but the images for CKeditor are saved on the local server.
Currently, it is saved in the base path (eg. https://drupal.stackexchange.com/). I want it to be saved and retrieved from my CDN.
I did find the  Uploadcare : Add media from anywhere plugin, but I don't understand how to use it; I  think it has its own CDN, but I want it to use my own CDN.
Modifying the core is not recommended and it is not the best practice, how do I achieve it in efficient way.
How do I save images added from CKeditor on a CDN instead of the local server?
Comment: Wich version of CKEditor? Have you try looking in CKEditor forum? It seem more related to CKEditor than Drupal.
Comment: check here ... http://ckeditor.com/forums/Support/How-do-I-save-and-retrieve-CKEDITOR-media-images-and-video-on-a-CDN
Comment: @FR6 : do you any solution for this ... any work around for to bring this functionality
Answer: Until CKEditor developers implement the functionality, you could create a custom module that:

on node add/edit you loop thru all fields using CKEditor and crawl each images/videos
detect if the images are already on the CDN
if not, upload the images/videos on the CDN
replace the images links with your new CDN links
save the node

I hope it will help you.


Configure Azure to run nodejs app in development environment

Question: NodeJS applications on Azure portal are running by default in production environment (process.env.NODE_ENV is production).
Is it possible to change the environment to development? And how?
(If it matters, I configured the application as a Web Site on Azure.)
Comment: No. I'm asking how to configure azure to run the development environment?
Comment: Are you asking [how to set an environment variable on Windows](http://superuser.com/questions/223104/setting-environment-variable-for-just-one-command-in-windows-cmd-exe)?
Answer: You can set the NODE_ENV variable under the Website App settings configuration on the portal: http://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/#howtochangeconfig
Additionally, if you are using the Azure CLI (which you can install via npm install azure-cli -g), you can run the following azure site config add NODE_ENV=development assuming your CLI is configured.
This will ask you for the website name then set the config.
Comment: doesn't the app settings in azure add the prefix to it and break how NODE would pick up that setting?
Comment: I saw this when I first started this adventure. I just chuckled to myself and said, yea, I bet that works great for a dotnet app. No way in hell that's ever going to work with node since it's Microsoft. A couple weeks later after trying multiple different setups I came back to this. It works like a charm. I just put in an app setting and referenced it in my node app (`process.env.*`) and it worked like a champ. I hate to do it, but one gold star for microsft. I definitely thought they were just running node in some bastardized fashion with no access to anything you would actually need.


Determine for which value of m, the sequence (a_n ) is convergent and find the limit

Question: Let $a_1=1$ and $a_{n+1}=ma_n+10$ for $n\geq 2$. Determine for which value of m, the sequence $(a_n)$ is convergent and find the limit.
I know that if if we simplify we will get $0=L(M-1)+10$, which is equal to $10/(1-M)=L$ but I have no clue what to do from there
Answer: If $m=1$, then $a_n=10(n-1)+1$ for all $n\in\mathbb N$, so the sequence does not converge. Suppose that $m\neq 1$. Then, we can prove that $a_{n+1}=m^n+10\frac{m^n-1}{m-1}$ for $n\geq 1$ by induction: this holds for $n=2$, and, if it holds for some $n\geq 2$, then $$a_{n+2}=ma_n+10=m\left(m^n+10\frac{m^n-1}{m-1}\right)+10=m^{n+1}+10\frac{m^{n+1}-m}{m-1}+10=$$$$m^{n+1}+10\left(\frac{m^{n+1}-m}{m-1}+1\right)=m^{n+1}+10\frac{m^{n+1}-1}{m-1}.$$ Therefore, this holds for all $n\in\mathbb N$, so $$a_{n+1}=m^n+10\frac{m^n-1}{m-1}=\frac{m^{n+1}+9m^n-10}{m-1}.$$ So, $a_n$ converges if and only if $m^{n+1}+9m^n=m^n(m+9)$ converges. So, either $m=-9$, or $m^n$ converges, which happens only if $|m|<1$. Hence $a_n$ converges only when $|m|<1$ or $m=-9$. In all of those case, you can check that the limit is $\frac{10}{1-m}$.
Answer: $\newcommand{\+}{^{\dagger}}%
 \newcommand{\angles}[1]{\left\langle #1 \right\rangle}%
 \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}%
 \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}%
 \newcommand{\dd}{{\rm d}}%
 \newcommand{\isdiv}{\,\left.\right\vert\,}%
 \newcommand{\ds}[1]{\displaystyle{#1}}%
 \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}%
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}%
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}%
 \newcommand{\ic}{{\rm i}}%
 \newcommand{\imp}{\Longrightarrow}%
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}%
 \newcommand{\pars}[1]{\left( #1 \right)}%
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}%
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}%
 \newcommand{\sech}{\,{\rm sech}}%
 \newcommand{\sgn}{\,{\rm sgn}}%
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}%
 \newcommand{\verts}[1]{\left\vert #1 \right\vert}%
 \newcommand{\yy}{\Longleftrightarrow}$
\begin{align}
\color{#0000ff}{\large a_{n}}
&=
ma_{n - 1} + 10 = m^{2}a_{n - 2} + 10m + 10= m^{3}a_{n - 3} + 10m^{2} + 10m + 10
= \cdots
\\[3mm]&=
m^{n - 1}a_{1} + \sum_{k = 0}^{n - 2}10\,m^{k}
=
m^{n - 1} + 10\,{m^{n - 1} - 1\over m - 1}
=
\color{#0000ff}{\large{m^{n} + 9m^{n - 1} - 10 \over m - 1}\,,\qquad n \geq 1}
\end{align}
It converges whenever
$m = -9$ since the factor $m^{9} + 9m^{n - 1}$ vanishes identically.
Or $\verts{m} < 1$. In that case
$\lim_{n \to \infty} m^{n} = 0 = \lim_{n \to \infty} m^{n - 1}$.

Then, in both cases:
$$
\mbox{When}\quad \lim_{n \to \infty}\pars{m^{n} + 9m^{n - 1}} = 0\,,
\quad
\mbox{we get}\quad
\lim_{n \to \infty}a_{n} = {10 \over 1 - m}
$$


OCUnit, NSLog, and XCode 3.1

Question: I'd been using OCUnit (the default installation that comes with XCode) in XCode 3.0. I've been happy being able to run my tests and see the results in the Build Results window, as well as any NSLog() messages I output.
However, with XCode 3.1 the tests run fine, but I suddenly lose my NSLog() output. Anybody know where it went?
Answer: Just learning this stuff myself and had to poke around to answer that very question (XCode 3.1.2).
Go to the Build Results window after running.  It may not open automatically, depending on configuration.  Build / Build Results menu option will open it if needed.
In the middle area between the two panes, you'll see 4 buttons on the left.  The 3rd icon is just 3-4 horizontal lines.  Click that to toggle the build transcript.  That shows all build steps and NSLog() output from the run.
Comment: What I actually did was make a macro to wrap NSLog() and forgot to #define DEBUG in my Test project. But, I'll give you the answer because most people aren't boneheaded as I am ;)
Comment: I don't see this button in my build results window in 3.2.1
Comment: The icon changed in 3.2 to be a black/yellow "gdb" icon.  Equivalent to the Run / Console menu item (as mentioned by PiPeep).
Comment: Command-Shift-B will take you there as well. And if you build your unit tests once you're already in that window, you shouldn't have to expand anything. In Xcode 3.2 (Snow Leopard) the "show log" button has disappeared, but you can select the *Run custom shell script 'Run Script'* line and click on the little bubble on the right side to expand the unit test log. Works for other build phases as well, such as compilation and linking.
Answer: While it's inconvenient, I found NSLog() messages going to the OSX Console.app.
Applications > Utilities > Console.app I filtered by otest to see output.
I couldn't get any of the above methods to work.
Answer: (on the menu-bar) Run -> Console (Shift-Apple-R)

OCUnit, NSLog, and XCode 3.1


name of a distribution

Question: Consider the discrete distribution supported on $\mathbb{N},$ where the probability of getting $r$ equals $\frac{1}{e r!}.$ I can't seem to find its name (its sort of like a discrete version of the Gamma distribution).
Comment: How does this problem arise? (Needing to identify a name for a pmf,)
Comment: I found that this is the probability density (in large $n$ limit) for the number of fixed points of a random element in $S_n.$ It seemed obvious that this was a known distribution, but I blanked out for some reason.
Comment: Ah. Of course most readers here are unlikely to know that by $S_n$ you're referring to the symmetric group on $n$ symbols; that context could make your question more broadly useful, since if it were in your question a search could turn it up.
Answer: A Poisson distribution with parameter $\lambda$ has pmf
$P(X=x) = \frac{e^{-\lambda}\lambda^x}{x!}$
Your function is a special case of that.
Comment: Poisson(1) occurs in all manner of situations.

name of a distribution


Nginx load balancing based on URL and not IP address?

Question: We have concerns about load balancing based on IP for our service (for instance, a mobile client switching from 3G to Wifi). Is there a way to do it based on a part of a URL instead of by IP hash?
Answer: Use the Upstream Consistent Hash module:
http://wiki.nginx.org/HttpUpstreamConsistentHash
or Upstream Request Hash Module:
http://wiki.nginx.org/NginxHttpUpstreamRequestHashModule
Comment: Consistent Hashing is a technique commonly used when load balancing caches (so you don't have duplicated content on the cache, what means more space)
Comment: While this is certainly the best answer, I find myself wondering exactly /why/ you need this functionality.  Sticky sessions aren't required all that often, and when they are, they're almost always user-based.  I can't think of many situations where they would be URL based, since users frequently move page to page.
Comment: I think that the $request_uri is just used as an example in the nginx wiki, any variable can be used based on your needs
Comment: Thanks! I'll try this out and see if it works. @Scrivener the reason we need this is because it's for a real-time mobile video uploading service that we are planning on scaling horizontally. It's based on the POST URL endpoints.
Comment: all linked pages redirecting to https://www.nginx.com/resources/wiki/ (so sort of dead)
Answer: A very simple way (since 1.7.2) to achieve that is to hash a parameter in the incoming URL:
upstream upstream_name {
    hash $arg_loadBalancingToken consistent;
    server 192.168.1.2:1234;
    server 192.168.1.3:1234;
}

What does the trick is this part:
hash $arg_loadBalancingToken consistent;

It simply means that nginx will hash the argument loadBalancingToken in the query URL (in https://yourserver.com/path?arg1=toto&loadBalancingToken=123, it will hash the 123), and balance the load depending on the result of this hash. You can replace loadBalancingToken with whatever name comes to your mind.
The consistent keyword is optional, and means that if one day you add or remove a server from the upstream, nginx will try to reallocate as few keys as possible. From the documentation:

The optional consistent parameter to the hash directive enables ketama consistent‑hash load balancing. Requests are evenly distributed across all upstream servers based on the user‑defined hashed key value. If an upstream server is added to or removed from an upstream group, only a few keys are remapped which minimizes cache misses in the case of load‑balancing cache servers or other applications that accumulate state.

You could also decide to hash pretty much anything known to nginx.
The value of the cookie toto:
hash $cookie_toto [consistent];

All the arguments in the query:
hash $args [consistent];

Full list of what you can use is here.
Answer: This may not exactly work for you, but 'balancing' by cname might be of interest to you.
server1    IN      A      192.168.0.101
server2    IN      A      192.168.0.102
www        IN      CNAME  server1
mobile     IN      CNAME  server2

Effectively, anyone who hits 'mobile.example.com' ends up asking server2 for data.  Then set up your user agent rewrite rules on sever1/www appropriately.


Views link image to field

Question: I've created a view with two fields(field_img & field_pdf) and the Format as Fields.
Now I want to download the field_pdf file when I click on the field_img.
How to achieve this one?
Thank you.
Answer: You may be able to use "Rewrite the output of this field" to wrap the image in a link using the "replacement pattern" token for the PDF file url as the href there.
Note you can "Exclude field from display" to add a field to the token list without displaying it.
You'll also need to drag the field, in the field order, above the one you want to use it in as a token for it to be available.
hth

Views link image to field


Is there a way to lazy load components, not modules, in Angular?

Question: Lazy loading is a commonly used technique. However, in Angular it seems that the granularity level of this technique stops at the module level.
That means that you can have module main that loads in the browser, and then on special occasion module B and C and D can be loaded lazily.
Almost all tutorials on web explain that. However, is there a way to load components lazily?
Consider this simple example that user goes inside the application, and when clicks "invoices" link, URL changes to the new route /invoice/list and a progress bar shows loading, while the invoices component including HTML and JS is being loaded inside the browser, is registered dynamically with the main module, and is being shown in the relevant outlet. Is that possible with Angular?
Comment: no, there is no straightforward to do that, but you can load a component class and then generate a module and component on the fly, [see this tutorial](https://blog.angularindepth.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e#2b99)
Comment: you mean module per component? That's too overloaded. Not efficient.
Comment: have them as separate module
Comment: Maybe this will be added  in angular 7, [see this issue](https://github.com/angular/angular/issues/23284)
Comment: Yes, as of Angular 9 with Ivy.  See this [post](https://netbasal.com/welcome-to-the-ivy-league-lazy-loading-components-in-angular-v9-e76f0ee2854a).
Answer: Lazy loading a component is not possible.
Reason for this behavior is the structure of angular. Components in angular have to be part of a module. Angular module is a container where you define all the components, services, pipes e.t.c. present inside.
While building the application dist, all the dependencies declared in the module are included to make a chunk (transpiled js code).
All the directly imported modules together form the main chunk whereas modules marked as lazily loaded form a separate chunk that sits on the server untill the respective route is hit and a call for it is made from the client.
Now components do not form a chunk and hence it is not possible
Comment: I have made a service that dynamically load my lazy module then load the component - only when i need
Comment: @FabioLux whould you like to share how to implement it?
Comment: @KLMN yes, if you need it
Answer: Currently (Angular 8 timeframe) there are two 3rd party libraries that make lazy-loading of components easier:

ngx-loadable: https://github.com/mohammedzamakhan/ngx-loadable
hero-loader: https://www.npmjs.com/package/@herodevs/hero-loader

Note: both of these libraries are built upon NgModuleFactoryLoader, which is deprecated in Angular 8, but there is no alternative yet ...

Class marked as deprecated: https://angular.io/api/core/NgModuleFactoryLoader

Explanation of Rob Wormald of the Angular Team: https://twitter.com/robwormald/status/1143981312237137925

The Angular team has announced that lazy loading of components should become easier with Ivy (Angular 9?), but it is not clear yet how this will look like...
Comment: Igor Minar presented how the lazy loading of components will look like in Ivy at this year's AngularConnect. Regarding the NgModuleFactoryLoader being deprecated: see my latest blog post here: https://juristr.com/blog/2019/10/lazyload-module-ivy-viewengine/
Answer: A bit hacky ... but possible (future versions of Angular (beyond ver. 7) will implement an easier apporach)
https://blog.angularindepth.com/dynamically-loading-components-with-angular-cli-92a3c69bcd28
Answer: Update, with Angular 9 and Ivy it is possible and relatively easy.
First of all you need to have some anchor in your app where you want to load your component, it could be named templateRef if you want multiple different components at the same time or ng-template for single one. To do that (i will use ng-template) in your component.html:
<ng-template>

component.ts:
export class ExampleComponent {
    @ViewChild(TemplateRef, { read: ViewContainerRef })
    private anchorRef: ViewContainerRef;

    constructor(
        private readonly componentFactoryResolver: ComponentFactoryResolver
    ) {}

    private async loadComponent() {
        this.anchorRef.clear(); // clear if some components are already there
        const { component } = await import(
            'path to your component'
        );
        const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
            component
        );
        // We could attach @Input and react to @Output by using below instance if needed.
        // Remember we should handle the ngOnChanges lifecycle hook.
        // For that implementation needed.
        this.anchorRef.createComponent(componentFactory);
    }
}

All that is left is basically call loadComponent when it's needed;
If you need some modules, for ex you want to use Angular Material. You need to create simple ngModule without export inside your lazyLoaded component. Like this:
@Component({...})
export class Component implements OnInit {
    constructor() {}

    ngOnInit() {}
}

@NgModule({
    declarations: [Component],
    imports: [MatIconModule],
})
class TasksListModule {}

Also, you could follow the approach Angular team has in their documentation:
https://angular.io/guide/dynamic-component-loader
Comment: Basically, lazy-loaded component is just the same component as any other. You just use the factory Angular use under the hood for any other component and Async function to load the file itself. So no restrictions. Just be careful as the component might not be on page when you try to interact with it programmatically
Comment: Can I follow this approach to lazy-load custom form controls that are part of a bigger reactive form? In other words, are there any restrictions on what kind of components can be lazy-loaded as described above?
Comment: Why is this at 0 votes? Does it not work?


How do I give a user permission to install Report Builder from Report Manager? (SQL Server 2008)

Question: By default, users do not see the "Report Builder" button on the Report Manager toolbar in SQL Server 2008 (R1).  How do I give the user permission to use the Report Builder?
Answer: Try graning Manage Reports
Answer: There is a role for this on the security tab in Report manager.  Do a new role assignment or add the Report Builder role to an existing role assignment.  Additionally you may need to add them to the site security section as a System User.
<code>Home Folder Security:
http:/localhost/reports/Pages/Folder.aspx?SelectedTabId=PropertiesTab

Site Security:
http:/localhost/reports/Pages/Settings.aspx?SelectedSubTabId=SecurityLinkID
</code>


Why my startup class in not getting invoked while hitting the URL?

Question: here is my Azure function which receives a request from http trigger and writes the received data to mongodb. Can you pls help me to figure out why my startup class is not getting invoked on sending data via using Azure function URL? below is the detailed code.
Note: I have all the necessary packages.
[assembly : FunctionsStartup(typeof(Startup))]

namespace ItemApp_Azurefunction
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            ConfigureDatabse(builder);
        }

        private static void ConfigureDatabse(IFunctionsHostBuilder builder)
        {
            string connectionString = Environment.GetEnvironmentVariable("MongoConnectionString");
            string databaseName = Environment.GetEnvironmentVariable("MongoDatabase");
            builder.Services.ConfigureMongoDB(connectionString, databaseName);
        }
    }
}

 public static class DatabaseConfigurationcs
    {
        public static IServiceCollection ConfigureMongoDB(this IServiceCollection services, string connectionString, string database)
        {
            services.AddSingleton<IMongoClient>(v =>
            {
                return new MongoClient(connectionString);
            });

            services.AddSingleton<IMongoDatabase>(v => v.GetRequiredService<IMongoClient>().GetDatabase(database));

            services.AddScoped<ItemHandler>();

            return services;
        }
    }

  public static class Create
    {
        [FunctionName("Create")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                ActionRequest data = JsonConvert.DeserializeObject<ActionRequest>(requestBody);

                await ActionHandlerExtension.CreateHandler(data);

                var result = "Product created.";
                return new OkObjectResult(result);
            }
            catch (Exception ex)
            {
                return new BadRequestObjectResult($"Prduction could not be created. Here is the detailed error description : \n {ex.Message}");
            }

        }

     public static class ActionHandlerExtension
    {
      public async static Task CreateHandler(ActionRequest actionRequest)
        {
            //var request = ProductToActionExtension.ToModel();
            var request = actionRequest.ToModel();
            ItemHandler handler = new ItemHandler();
            await handler.Create(request);
        }
    }

     public class ItemHandler
    {
        private IMongoClient _client;
        private IMongoDatabase _database;

        public ItemHandler(IMongoClient mongoClient, IMongoDatabase mongoDatabase)
        {
            _client = mongoClient ?? throw new ArgumentNullException(nameof(mongoClient));
            _database = mongoDatabase ?? throw new ArgumentNullException(nameof(mongoDatabase));
        }

        public ItemHandler() { }
        public async Task Create(ProductModel action)
        {
            //var client = new MongoClient(Environment.GetEnvironmentVariable("MongoConnectionString"));
            //var MongoDb = client.GetDatabase(Environment.GetEnvironmentVariable("MongoDatabase"));
            var collection = _database.GetCollection<ProductModel>(Environment.GetEnvironmentVariable("MongoDBCollection"));

            IndexKeysDefinition<ProductModel> indexKeys = "{ No : 1 }";
            var indexModal = new CreateIndexModel<ProductModel>(indexKeys);
            await collection.Indexes.CreateOneAsync(indexModal);
            await collection.InsertOneAsync(action);
        }
}

I try to send data through the Azure function URL and when I hit then I get the error
"Object reference not set to an instance of an object."
because this constructor is not getting invoked which is supposed to be invoked via startup class.
public ItemHandler(IMongoClient mongoClient, IMongoDatabase mongoDatabase)
     {
         _client = mongoClient ?? throw new ArgumentNullException(nameof(mongoClient));
         _database = mongoDatabase ?? throw new ArgumentNullException(nameof(mongoDatabase));
     }

since I am beginner without using startup class my code was working but now I want to implement startup class and I ended up with this error.
Comment: What version of Azure Functions are you using?
Comment: Azure function v4.
Answer:
I have referred these links Azure Cosmos DB for MongoDB ,  MongoDB for.NET and thank  for your comment @StephenCleary

[FunctionName("Create")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                ActionRequest data = JsonConvert.DeserializeObject<ActionRequest>(requestBody);

                await ActionHandlerExtension.CreateHandler(data);

                var result = "Product created.";
                return new OkObjectResult(result);
            }
            catch (Exception ex)
            {
                return new BadRequestObjectResult($"Prduction could not be created. Here is the detailed error description : \n {ex.Message}");
            }

        }

with items:
var newProduct = new Product(
                Guid.NewGuid().ToString(),
                "gear-surf-surfboards",
                "Yamba Surfboard",
                12,
                false
            );

            await _products.InsertOneAsync(newProduct);
            var filter = Builders<Product>.Filter.Eq(p => p.Name, "Yamba Surfboard");
            var product = await _products.Find(filter).FirstOrDefaultAsync();
           log.LogInformation("Single product:");
            log.LogInformation(product?.Name);
            var productsFilter = Builders<Product>.Filter.Eq(p => p.Category, "gear-surf-surfboards");
            var products = await _products.Find(productsFilter).ToListAsync();
            log.LogInformation("Multiple products:");
            foreach (var prod in products)
            {
                log.LogInformation(prod.Name);
            }

            return new OkResult();
        }

Output:


I want to subtract elements from 2 nested lists

Question: I have these two nested list:
insurance cost = [('Maria', 4150.0), ('Rohan', 5320.0), ('Valentina', 35210.0)]
estimated insurance cost = [('Maria', 4222.0), ('Rohan', 5442.0), ('Valentina', 36368.0)]

I want to make a code to subtract estimated by insurance so complete a subtraction on every 2nd element in the list. how would i do that?.
Do I unzip or convert back to int(). I've just started learning python and was wondering how to do it. Anyone know how to go about this.
Comment: Ok... You cannot have spaces in variables
Answer: You can go with:
total_cost=[(i[0],j[1]-i[1]) for i,j in zip(insurance_cost, estimated_insurance_cost)]
print(total_cost)

Also, variables in python don't have spaces between them. python will consider words as new variables, which won't be defined and would be syntactically invalid.
You can use _ as an alternative:
insurance_cost = [('Maria', 4150.0), ('Rohan', 5320.0), ('Valentina', 35210.0)]
estimated_insurance_cost = [('Maria', 4222.0), ('Rohan', 5442.0), ('Valentina', 36368.0)]


A Hard Combination Probability Equation From A Reality T.V. Show

Question: I was watching the T.V. show Survivor tonight and miserably failed at wrapping my mathematically out-of-practice post-college brain around a probability equation.
Background:
At the start of the show, 18 people are randomly divided into 2 tribes (red & blue) of equal size, so 9 each. Then tonight the 15 remaining people (6 red & 9 blue) found out that they would be randomly splitting again...but this time into 3 tribes of 5 (red, blue, & green). When they finished the random tribe swap, they were shocked to find that 5 of the 9 old blue team members remained together on the new blue team, 5 of the 6 old red team members all stayed together (but moved to green...not sure if it's relevant), and finally the remaining 4 of the 9 old blue team members and the 1 remaining old red team member ended up on the red team together.
Long story short to the non-mathematically inclined viewer...wow nothing changed (rigged reality tv). But what is the probability of that actually happening?
More specifically what is the probability that after all the randomization of teams, 2 of the 3 newly created teams would have 5 people that had previously been on a team together (when there were only 2 teams).
Thanks ahead of time!
Answer: So the question is, if you have 6 red objects and 9 blue objects , and you generate three random groups of five, what is the probability that two of these groups contain only a single colour of object (one blue group and one red group)?
The total number of ways of choosing three groups of five from the 15 objects is:
$$\text{Total number of ways} = \frac{{15 \choose 5} \cdot {10 \choose 5} \cdot {5 \choose 5}}{3!} = \frac{3003 \cdot 252 \cdot 1}{6} = 126126.$$
To yield two groups containing only a single colour of objects (one blue and one red) we can first choose an all-blue group and then an all-red group, and then the remaining objects become the third (mixed) group.  By the multiplication principle, the number of ways of doing this is:
$$\text{Number of ways with two single-colour groups} = {9 \choose 5} \cdot {6 \choose 5} = 126 \cdot 6 = 756.$$
Thus, assuming simple random sampling, the probability of obtaining two single-colour groups at random is:
$$\mathbb{P}(\text{Two single-colour groups}) = \frac{756}{126126} = 0.005994006.$$
So this would happen coincidentally about one in every 167 times you did the randomisation.
Answer: Calculation of probabilities would closely depend on the way of drawing team members and the way information (on interim team assignments) is made available.
For example, randomly choose five out of 15 people and assign to team (1) another five to team (2) and the remaining go to team (3).
Another way may be to randomly choose one person out of 15 and assigned to team (1), then another is chosen from the remaining 14 and assigned to team (2), and the next to team (3). Then the steps are repeated.
Not knowing the setup, let's assume that the drawing was according to the first case above.
Probability of randomly selecting five blue team members from 15 is $ {9 \choose 5} / {15 \choose 5} = 0.04195804$.
Given that all five were blue, the probability of selecting (in the next step) five red from remaining six red and four blue is ${ 6 \choose 5} / { 11 \choose 5} = 0.01298701$.
The probability of both events happening is $0.04195804 * 0.01298701 =  0.0005492342$.


Specifying the neighborhood for Word-to-Abbreviation associations in corpus of document pairs

Question: TL;DR: When implementing word co-occurence algorithms and word-embeddings, can you specify the area to be treated as the neighborhood for a word 'x' (i.e., treat a separate document as the neighborhood instead of the words near 'x')?

I have a large dataset of document pairs. For each pair, there is an itemized bill (IB) listing all materials used for a client, and there is an order report (OR) detailing how and when those materials were used. I eventually want to build a script or model that takes an IB or OR as input, and outputs a mapping (maybe a dictionary) of all terms in the IB to all descriptions in the OR, so that we can easily detail where expenses come from. Unfortunately, there are multiple ways to list an item (you might call item 'c' by the name 'a', 'x', or 'f'), and so the way an item is listed in the IB often differs from its listing in the OR.
I believe the way to tackle this is to build a word-word co-occurence matrix, where the columns are composed of the vocabulary found in all the IBs, and the rows are composed of the vocabulary of all the ORs. I can then either:
a) feed this co-occurence matrix to some word-embedding algorithm such as GLoVe or word-2-vec.
b) for a given document pair, iterate through all words (items) in the IB and use the matrix to return the most likely synonym of each of those items in the OR.
I've seen many pre-built frameworks for taking a corpus of text and doing word co-occurence based on their neighbors. Is there a way to modify these existing algorithms to consider the other document as the neighborhood rather than the words syntactically near them?
Note: I couldn't think of a better title, but I do feel like this has to be a common thing to do, i.e., cross-document co-occurence rather than within-document co-occurence.
Note 2: I have checked out HAL, KNN, GLoVe and word-2-vec, and while they all seem related to what I want to accomplish, they're either more complicated than I need (I think) or they are incompatible with the kind of synonym search I'm looking for.
Answer: There are two algorithms used for word embeddings. Skip-grams and CBOW. To answer your question directly - both allow to set 'windows-size', which is effectively what you are looking for. Depending on characteristics of your dataset, one may be better than the other. Both algorithms are really about paris of tokens, so it is really up to you how you train it and what pairs you throw at it.
Example implementation for tensorflow: https://github.com/tensorflow/tensorflow/blob/r0.8/tensorflow/examples/tutorials/word2vec/word2vec_basic.py
Having said that, I am not sure what the result is going to be in your case and if it will address your requirement. You can try feeding the algorithm with pairs of words differently, like all from IB / all from BO / pairs between IB and BO.


How was the plus-minus sign removed in these steps for proving a half-angle identity for tangent?

Question: How was the plus-minus sign removed in the following solution? (see red rectangle)
Comment: You want to prove that $\sqrt{(1+\cos{\theta})^2}=1+\cos{\theta}$ and this holds iff $1+\cos{\theta}\geq 0$, but since the cosine is bounded by $1$ and $-1$ then $0\leq 1+\cos{\theta}\leq 2$ and so we are done.
Answer: The derivation is indeed faulty. You can make it rigorous by avoiding the square roots:
\begin{align}
\tan^2\frac{\theta}{2}
&=\frac{1-\cos\theta}{1+\cos\theta} \\[6px]
&=\frac{1-\cos^2\theta}{(1+\cos\theta)^2} \\[6px]
&=\frac{\sin^2\theta}{(1+\cos\theta)^2}
\end{align}
Therefore we have
$$
\Bigl\lvert\tan\frac{\theta}{2}\Bigr\rvert=\frac{\lvert\sin\theta\rvert}{1+\cos\theta}
$$
(note that $1+\cos\theta>0$, so no absolute value is needed in the denominator) and now we can observe that $\tan(\theta/2)$ and $\sin\theta$ have the same sign for every $\theta$ and so the absolute values can be removed.
In a different way:
$$
\frac{\sin2\alpha}{1+\cos2\alpha}=\frac{2\sin\alpha\cos\alpha}{1+2\cos^2\alpha-1}=\frac{\sin\alpha}{\cos\alpha}=\tan\alpha
$$
Now set $\alpha=\theta/2$.


PySpark - converting single element arrays/lists to string

Question: Let's say I have a df like this:
<code>   id  type  length  key1             key2     key3
0  1   A     144     [value1,value2]  value3
1  1   B     20      value4           [value5]
2  4   A     54                                [value6]
</code>
Is there a way in PySpark I can get value5 and value6 out of the list since they are the only elements? I want to apply this to all cells. Output would be:
<code>   id  type  length  key1             key2     key3
0  1   A     144     [value1,value2]  value3
1  1   B     20      value4           value5
2  4   A     54                                value6
</code>
Comment: Can you please give a try to the answer
Answer: <code>    Df= df.withColumn('key3', F.when(F.size('key3) ==1),F.col('key3').getItem(1)  ).when(F.size('column_2) ==1),F.col('column_2').getItem(1))
 .otherwise ('key3')
</code>
You can keep adding the condition like this
<code>.when(F.size('col_2) ==1),F.col('col_2').getItem(1))
</code>
First you need to find the size of the array and if found 1 then get the first element. I responded through mobile, please give it a try, I believe it should work
Comment: This is only for one column though. Also, what is `F`?
Comment: I would like to apply it to allcells in the dataframe.
Comment: To get `F`, run `import pyspark.sql.functions as F`
Comment: Can you please approve the answer if it serves the purpose.. Thanks in advance
Comment: @dsk I did not, sorry. Also, is there a way to easily apply this to whole df? There are many columns.


IIS Redirect Old Site to new site

Question: In IIS we have a website. We are turning this website off. We have redirected all the pages to another server using the redirect. So any hits to example.com will be displayed as example2.com.
We wish to turn the old server off. So the redirect will no longer work. I know I need to change the DNS of example.com to go to the IP address of example2.com.
Is it possible to get the IIS site to handle example.com and server any requests to that to the default page of example2.com?
Or is it better to create a new site on the server for example.com and get that to redirect to example2.com like the site on the original sever that has been switched off.
Answer: You don't need to create a new site.  Edit the properties of the site in IIS for example2.com and add a host header redirection for example.com.

On the Web Site tab of the web site's properties page click the Advanced button next to the IP Address drop-down
Click Add unter Multiple Identities for this Web Site
Enter 80 for your TCP port (assuming your site is running on port 80)
Enter example.com in the Host Header value, click
Click Ok until you're back to IIS manager.

What this does is tells IIS to route any request that comes in with example.com as the value for the Host: HTTP request header to the web site for example2.com.
Comment: What would be differnt if on IIS7? Is it just change the bindings?
Comment: Right, just an additional binding for the site for IIS7.

IIS Redirect Old Site to new site