Bad state: field does not exist within the DocumentSnapshotPlatform after updating the firebase packages

Question: I updated the below packages:

firebase_core: from ^0.5.0+1 to ^1.2.0
cloud_firestore: from 0.14.1+3 to ^2.2.0
firebase_auth: from ^0.18.0+1 to ^1.2.0

After updating the packages I'm getting the below error:
═══════ Exception caught by widgets library ═══════════════════════════════════
The following StateError was thrown building StreamBuilder<QuerySnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<QuerySnapshot<Object?>, AsyncSnapshot<QuerySnapshot<Object?>>>#77e63):
Bad state: field does not exist within the DocumentSnapshotPlatform

The relevant error-causing widget was
StreamBuilder<QuerySnapshot<Object?>>
lib/screens/app_home.dart:183
When the exception was thrown, this was the stack
#0      DocumentSnapshotPlatform.get._findKeyValueInMap
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:86
#1      DocumentSnapshotPlatform.get._findComponent
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:104
#2      DocumentSnapshotPlatform.get
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:120
#3      _JsonDocumentSnapshot.get
package:cloud_firestore/src/document_snapshot.dart:92
#4      _JsonDocumentSnapshot.[]
package:cloud_firestore/src/document_snapshot.dart:96
...
════════════════════════════════════════════════════════════════════════════════

Below is the output of flutter doctor:
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.3, on macOS 11.3.1 20E241 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.56.2)
[✓] Connected device (3 available)

• No issues found!

Below is the code relevant to the error:
final coursesCollection = FirebaseFirestore.instance.collection('courses').limit(10).where('courseLive', isEqualTo: true);
.
.
.
    return StreamBuilder<QuerySnapshot>(
      stream: coursesCollection.snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return Center(
            child: CircularProgressIndicator(
              backgroundColor: kAccentColor,
            ),
          );
        }
        final courseSnapshot = snapshot.data.docs;
        List<CourseTile> courseTiles = [];
        CourseData course;
        for (var courseData in courseSnapshot) {
          course = CourseData.fromDocumentSnapshot(snapshot: courseData);
          final courseDocID = course.courseDocID;
          final courseID = course.courseID;
          final courseTitle = course.courseTitle;
          final courseDescription = course.courseDescription;
          final courseSubTitle = course.courseSubTitle;
          final courseBadge = course.courseBadge;
          final courseLevel = course.courseLevel;
          final coursePaid = course.coursePaid;
          final courseImage = course.courseImage;
          final courseBgColor = hexToColor(course.courseBackgroundColor);
          final courseBgColor1 = hexToColor(course.courseBgColor1);
          final courseBgColor2 = hexToColor(course.courseBgColor2);
          final courseFgColor = hexToColor(course.courseFgColor);
          final courseDeliveryFormat = course.courseDeliveryFormat;
          final courseLive = course.courseLive;

          final courseTile = CourseTile(
            cardBackgroundColor: courseBgColor,
            bgColor1: courseBgColor1,
            bgColor2: courseBgColor2,
            fgColor: courseFgColor,
            cardImage: courseImage,
            titleText: courseTitle,
            titleTextColor: courseFgColor,
            subTitleText: courseSubTitle,
            courseID: courseID,
            courseDocID: courseDocID,
          );

          courseTiles.add(courseTile);
         }
         return Expanded(
          child: ListView(
            children: courseTiles,
          ),
        );
      },
    );

I did verify the fields present in the firestore document, they do match up. Also tried reverting back the packages to their previous versions, but it still breaks.
Not sure, what needs to be done to fix this issue.
Any help would be really appreciated.
Thank you so much for your time in advance.
AFTER APPLYING THE SOLUTION SUGGESTED BY VICTOR
The Bad state: field does not exist error has gone. But still, I'm getting this below error.
════════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building StreamBuilder<QuerySnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<QuerySnapshot<Object?>, AsyncSnapshot<QuerySnapshot<Object?>>>#ef5a5):
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'DocumentSnapshot<Object>'

The relevant error-causing widget was
StreamBuilder<QuerySnapshot<Object?>>
lib/screens/app_home.dart:183
When the exception was thrown, this was the stack
#0      CourseStream.build.<anonymous closure>
lib/screens/app_home.dart:200
#1      StreamBuilder.build
package:flutter/…/widgets/async.dart:545
#2      _StreamBuilderBaseState.build
package:flutter/…/widgets/async.dart:124
#3      StatefulElement.build
package:flutter/…/widgets/framework.dart:4612
#4      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4495
...
════════════════════════════════════════════════════════════════════════════════

Below is the method within the CourseData class which is parsing the data received from the Document Snapshot.
CourseData.fromDocumentSnapshot({DocumentSnapshot snapshot}) {
    courseDocID = snapshot.id;
    courseID = snapshot['courseID'];
    courseTitle = snapshot['courseTitle'];
    courseSubTitle = snapshot['courseSubTitle'];
    courseDescription = snapshot['courseDescription'];
    courseLevel = snapshot['courseLevel'];
    courseBadge = snapshot['courseType'];
    coursePaid = snapshot['coursePaid'];
    courseCategories = snapshot['courseCategories'];
    courseImage = snapshot['courseImage'];
    courseBackgroundColor = snapshot['courseBackgroundColor'];
    courseForegroundColor = snapshot['courseForegroundColor'];
    courseBgColor1 = snapshot['courseBgColor1'];
    courseBgColor2 = snapshot['courseBgColor2'];
    courseFgColor = snapshot['courseFgColor'];
    courseDeliveryFormat = snapshot['courseDeliveryFormat'];
    courseLive = snapshot['courseLive'];
  }

Answer: Inorder to get the data from your DocumentSnapshot, you need to call .data() on the snapshot.

DocumentSnapshotPlatform
Contains data read from a
document in your Firestore database.
The data can be extracted by calling data() or by calling get() to get
a specific field.
DocumentSnapshotPlatform class

Solution:
You can leave this line as it is:
    course = CourseData.fromDocumentSnapshot(snapshot: courseData);

and update the CourseData code to the block of code below:
    CourseData.fromDocumentSnapshot({DocumentSnapshot snapshot}) {
    Map<String, dynamic> snapshotData = snapshot.data();
    courseDocID = snapshot.id;
    courseID = snapshotData['courseID'];
    courseTitle = snapshotData['courseTitle'];
    courseSubTitle = snapshotData['courseSubTitle'];
    courseDescription = snapshotData['courseDescription'];
    courseLevel = snapshotData['courseLevel'];
    courseBadge = snapshotData['courseType'];
    coursePaid = snapshotData['coursePaid'];
    courseCategories = snapshotData['courseCategories'];
    courseImage = snapshotData['courseImage'];
    courseBackgroundColor = snapshotData['courseBackgroundColor'];
    courseForegroundColor = snapshotData['courseForegroundColor'];
    courseBgColor1 = snapshotData['courseBgColor1'];
    courseBgColor2 = snapshotData['courseBgColor2'];
    courseFgColor = snapshotData['courseFgColor'];
    courseDeliveryFormat = snapshotData['courseDeliveryFormat'];
    courseLive = snapshotData['courseLive'];
  }

Comment: Brilliant! Once again thank you so much, @Victor. Highly appreciate your help. May God bless you.
Comment: Thanks Victor for your solution. Now I don't see `bad state: field does not exist` error. Still I'm seeing the another error. I have appended the error to my original question. Could you please have a look at this. Thanks again!
Comment: I have also added the method used to parse the document snapshot present within the `CourseData` class.
Comment: @xpetta, I've updated my answer. Note that you will have to use this line of code:     `course = CourseData.fromDocumentSnapshot(snapshot: courseData);` instead of     `course = CourseData.fromDocumentSnapshot(snapshot: courseData.data());` from the previous answer.
Comment: Thank you so much @Victor this worked perfectly fine. Could you please share me doc or video where I could gain more knowledge on this subject as I'm new to Flutter.
Comment: @xpetta, checkout this link: https://firebase.flutter.dev/docs/firestore/overview, it contains the documentation and the migration guide for the updated version of the firestore plugin
Comment: Glad to help out!


Struct member edition from included file

Question: My file structure looks like this:

primaryFile.h
primaryFile.c
secondaryFile.h
secondaryFile.c

primaryFile.h has:
#include secondaryFile.h

typedef struct{ secondaryStruct member} primaryStruct;
extern primaryStruct pStruct

secondaryFile.h has:
typedef struct{ uint8_t member} secondaryStruct;

Now I want to edit pStruct.member in secondaryFile.c. But if I included secondaryFile.h in primaryFile.h I can't include it back now. What am I supposed to do to edit pStruct in secondaryStruct.c?
Comment: Do your header files have include guards? You better share a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example).
Comment: They both do have include guards #ifndef #define
Comment: What does "include back" mean? Why do you need it?
Comment: It means. I used #include "secondaryFile.h"  in primaryFile.h. Now I want to edit struct that is extern in primaryFile.h inside secondaryFile.c. So I want to do #include "primaryFile.h" in secondaryFile.h. When I do that. Typedef secondaryStruct stops working for primaryStruct
Answer: OK,
I'm just dumb, I should have done #include "primaryFile.h" in secondyFile.c not in .h in order to modify struct members.


unable to call onDrawerOpened and onDrawerClosed

Question: So, i was trying to create my app's navigation drawer, and i don't know why i can't call the public void onDrawerOpened, it just showing an error said void is an invalid type for the variable onDrawerOpened when i type it manually
so here's my NavigationDrawerFragment.java code
package id.WKKR.ktcafe;

import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class NavigationDrawerFragment extends Fragment {

    public DrawerLayout mDrawerLayout;
    public ActionBarDrawerToggle mDrawerToggle;

    public NavigationDrawerFragment() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_navigation_drawer, container,
                false);

    }

    public void setUp(DrawerLayout drawerLayout, Toolbar toolbar) {
        // TODO Auto-generated method stub
        mDrawerLayout = drawerLayout;
        mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout,
                toolbar, R.string.navigation_drawer_open,
                R.string.navigation_drawer_close);
        {
            public void onDrawerOpened(View drawerView){
                super.onDrawerOpened(drawerView);
            }

            public void onDrawerClosed(View drawerView){
                super.onDrawerClosed(drawerView);
            }

        };
    }
}

thanks for anyone who help.
(edited)
so here's my mainactivity.java (called MenuUtama.java)

► ► package id.WKKR.ktcafe;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import android.support.v7.widget.Toolbar;

@SuppressWarnings("deprecation")
public class MenuUtama extends ActionBarActivity{

 Toolbar toolbar;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_menu_utama);

  toolbar = (Toolbar) findViewById(R.id.app_bar);
  setSupportActionBar(toolbar);

  NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
  drawerFragment.setUp((DrawerLayout)findViewById(R.id.drawer_layout),toolbar);

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.menu_utama, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

  int id = item.getItemId();
  if (id == R.id.action_settings) {
   Toast.makeText(this, "This Is " + item.getTitle() + " Button", Toast.LENGTH_SHORT).show();
   return true;
  }

  if (id == R.id.bill) {
   startActivity(new Intent(this, BillTagihanAnda.class));
  }
  return super.onOptionsItemSelected(item);
 }
}
Answer: You need to override onDrawerOpened and onDrawerClosed methods. Add @override annotation or implement as shown below:
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerlayout, toolBar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);

                        };

Change the setup method in activity to:
NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setup(R.id.fragment_navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);

setup method in fragment include id fragment as said in one of my comments.
Comment: already add the @Override, but the error still remain, when i pointed my cursor on super.onDrawerOpened, it said "The method onDrawerOpened(View) is undefined for the type Fragment", is the problem because i'm extending fragment?
Comment: Even I have extended fragment and it works fine for me.  Please upload the complete code of fragment.
Comment: Try using the following method for setup:

 public void setup(int fragmentId, DrawerLayout drawerlayout, final Toolbar toolBar) {
Comment: i've add my main activity, please take a look
Comment: do  not add it in answer edit the question and post it in question.
Comment: You need to add one more parameter in your setUp method of fragment and activity.
Comment: ok, i'll just try it, i'll post my answer if i figure it out, thanks anyway.
Comment: i finally find the problem, thanks for your help Keshav.
Comment: I have mentioned even that in my answer check. Any way cool that you solved it.
Answer: I had this problem, my solution was the following:
1 - Create instance of: DrawerListener
DrawerLayout.DrawerListener acc = new DrawerLayout.DrawerListener() {
    @Override
    public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
        // Action to onDrawerSlider
    }

    @Override
    public void onDrawerOpened(@NonNull View drawerView) {
        // Action to onDrawerOpened
    }

    @Override
    public void onDrawerClosed(@NonNull View drawerView) {
        // Action to onDrawerClosed
    }

    @Override
    public void onDrawerStateChanged(int newState) {
        // Action to onDrawerStateChanged
    }
};

2 - Set Listener to DrawerLayout Object:
mDrawerLayout.addDrawerListener(acc);

Answer: hye Keshav, thanks for your help before, now i can figure it out why i can't use the onDrawerOpened before, kinda silly mistake, i accidentally put the semi-colon after the parentheses without knowing.
public void setUp(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
        // TODO Auto-generated method stub
        mDrawerLayout = drawerLayout;
        mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout,
                toolbar, R.string.drawer_open, R.string.drawer_close);
                            //here is my problem, i put the semi-colon after parentheses
                     {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }

Answer: public void setUp(DrawerLayout drawerLayout, Toolbar toolbar) {
    // TODO Auto-generated method stub
    mDrawerLayout = drawerLayout;
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout,
            toolbar, R.string.navigation_drawer_open,
    // you just need to remove the semicolon here
            R.string.navigation_drawer_close) {
        public void onDrawerOpened(View drawerView){
            super.onDrawerOpened(drawerView);
        }

        public void onDrawerClosed(View drawerView){
            super.onDrawerClosed(drawerView);
        }

    };
}

Comment: please, edit your answer to provide more information about your code.


Views3 - Is there are feature in Views3 that allows for authenticated users to change the fields in a view?

Question: I'm using Drupal 7 to display a particular content type as a table view. This particular content type has the possibility of 15 columns, but I want to give users the option of displaying fields that are interesting to them. Does Views3 allow for users to select which fields he or she is interested in and save that to the profile?
Drupal 6 has a module based on Views - Control field display, which seems to have this feature.
Answer: you can allow users acces to the views UI but you couldn't limit that just to "fields". It wouldn't be end user friendly either.
You might want to show all fields in your view and then hide the fields dynamically with css.
If you want it more robust you can use a hook like hook_views_post_execute to remove fields dynamically.
Answer: Field permissions. You can fine grained decide which fields you want to display to a specific role.
You can give permission to let users edit the permissions for fields. It is off course not designed for exactly what you want. But it can be a good starting point to think about.
http://drupal.org/project/field_permissions
There is also flags and rules modules that can be used to achieve such a functionality.


Using maximum Likelihood regression to get closer to the true posterior when doing Approximate Bayesian Computation : contradiction?

Question: Post-hoc adjustments are used to get closer to the true posterior distribution when doing Approximate Bayesian Computation. This is particularly important when using a rough algorithm like rejection/sampling. I have been using the multiple weighted linear regression as proposed by Beaumont et al (2002) for a while. This is particularly convenient since there is an analytic answer (very fast) to get the slopes and the intercepts. But as this linear model is somehow part of the ABC model, would it be more respectful (probably not the good word to use) to the whole Bayesian framework employed until that post-hoc adjustment to use a Bayesian regression model. That way, it could be possible to account for the Bayesian incertitude in the objective of getting closer to the true distribution.
I don't know exactly what to think about that, and the maximum Likelihood framework is good at getting closer to the true posterior distribution. Any line of thought or philosophical perspectives on that?
And What about considering the model used in the post-hoc operation as part of the ABC model? The same question could be extended to more recent post-hoc adjustments using more sophisticated machine learning algorithms (e.g., neural network and random forest).
Maybe there is too many questions here?
Answer: This is an interesting question I have also asked myself overtime. However, I came to the conclusion that the non-parametric Bayesian approach was not particularly appropriate or respectful or useful in this context.
The fundamental reason is that the learning process in ABC is mostly based on the prior predictive, not on the data. The algorithm produces a huge reference table of $(\theta_i,z_i)$'s from the prior predictive and infer the connection between $\theta$ and $z$ from this table before applying the construct to the actual observation $z^\text{obs}$. This is thus a context where [machine] learning techniques [like neural nets and random forests] and cross-validation make more sense than Bayesian inference on $\mathbb{E}[\theta|z]$.


Query to save 10 fields

Question: Using Drupal 7, I created a node with the 10 fields; these fields are inserted as a table.
What query can I use insert the field values to the multiple tables, since multiple tables are the multiple fields?
Comment: You should not worry about the query to use, normally, as Drupal saves the fields for you, if you are using the node edit form.
Comment: what do you mean by "multiple tables are the multiple fields."?
Answer: Use the API: node_save().
Saving data directly to field tables is not possible, you shouldn't even consider this. There are many ways to import data into nodes, for example the Migrate or Feeds modules, if that's what you're after.
Answer: You should not worry about the query to use, normally, as Drupal saves the fields for you, if you are using the node edit form.
If you are not using the node edit form, you should use the functions Drupal provides to save entities, such as node_save() for nodes, or user_save() for user objects.
The reason you should not save field data directly in the database is that there is an API for field storage: the Field Storage API. The default field storage module uses the local SQL database to implement these operations, but that could not be true for other implementations of the field storage; this is what happens with the MongoDB field storage module, part of the Mongodb project.
Drupal doesn't take assumptions about the field storage, and so should your code.

Query to save 10 fields


Is it safe to assume every Android Phone has a DCIM Folder?

Question: I am storing pics created from my app into DCIM folders. Is it safe to assume that DCIM folder would be present in every Android handset?
Comment: On the off-chance it doesn't, can't you create it anyways?
Answer: The DCIM folder is retrieved via
File dcimDir = Environment.getExternalStoragePublicDirectory(
    Environment.DIRECTORY_DCIM);

As per the getExternalStoragePublicDirectory() Javadoc:

Returns the File path for the directory. Note that this directory may not yet exist, so you must make sure it exists before using it such as with File.mkdirs().


Different background color depending on URL

Question: I'd like to emphasize where a web application is loaded from: the local development environment vs a test or production environment.
To keep things simple, the mechanism should work just on CSS. But so far my CSS is a static file.
Is it possible to write a CSS that evaluates on the browser what background color to use, maybe based on the URL it was loaded from (localhost vs other hosts)?
Somehow I am hoping to get a solution based on CSS Conditional Rules.
Answer: I don't think this is possible using CSS, however you can do this using JavaScript. Checking if the current URL that is visited contains a certain string. Then changing style, you can also of course add a class within the if statement.
If you were to run this snippet in the answer it is blue, if you run this snippet on your localhost it will be red.

if (window.location.href.indexOf("stackoverflow") > -1) {
  document.body.style.backgroundColor = 'red';
} else {
  document.body.style.backgroundColor = 'blue';
}

The following screenshots will show how it effectively changes the background color based on the URL entered in the browser.
Without localhost in the name;

With localhost in the name;

To ignore everything that comes after the hostname and only take a look at the hostname and port you can use location.host seen in the following snippet.

if (window.location.host.indexOf("localhost") > -1) {
  document.body.style.backgroundColor = 'red';
} else {
  document.body.style.backgroundColor = 'blue';
}
Comment: @FUZIION Yes, the answer is much better with screenshots.
Comment: ignore the array, that is part of a test I am currently experiencing with
Comment: Well, I could try to match ` ://localhost` so the problem does not really occur. But
it moves the task to adding JavaScript to my UI framework. I will try to look into that then.
Comment: Alright glad I could help.
Comment: @HiranChaudhuri just out of curiosity, what UI framework are you using? :)
Comment: For _reasons_ I am still on Vaadin 8
Answer: While the accepted answer is the correct one to my question, I found a solution that I want to share with others and possibly my future self.
Since in Vaadin 8 it is not possible to directly add JavaScript into the generated HTML output (see here and here) it was easier for me to change the application slightly.
So in the application I added code like this. I am aware it does not check if the request was going to localhost - yet it checks that the client is on the same machine as the server, which essentially means the same.
public class App extends UI implements View {

    @Override
    protected void init(VaadinRequest request) {
        if ("127.0.0.1".equals(request.getRemoteAddr()) || "localhost".equals(request.getRemoteAddr())) {
            this.addStyleName("dev-environment");
        }
    }
}

Now as there is a new CSS class name in use, a simple tweak on the CSS did the trick:
// emphasize we are on localhost. The application sets the class name 'dev-environment' in this case
.dev-environment {
    background-color: #EEF0FF;
}


Debugging Hive in Eclipse?

Question: I'm trying to modify Hive and hence am trying to debug it in Eclipse. I followed the instruction in the wiki to setup Hive in Eclipse (https://cwiki.apache.org/Hive/gettingstarted-eclipsesetup.html).
When I try to launch the CLI using HiveCLI.launch template, it shows be the Hive CLI, but any query that I execute results in an error "ERROR metastore.HiveMetaStore: JDO datastore error".
The interesting part is that if I just launch hive in terminal using "/hive/build/dist/bin/hive", then everything works perfect. Does anyone have an idea why this is happening? If you can point me to any document which shows how to debug hive would be of tremendous use!
Thanks!
Answer: You can try out these steps:

Start the thrift server by opening CLI usind command :
hive --service hiveserver 10000
Now you can run your program from eclipse .

Note: 10000 is the port number generally.
Answer: Step 1:
Copy your code as a jar file to your cluster
Step 2: RUN THE FOLLOWING COMMAND ON CLUSTER
export SPARK_SUBMIT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=7777
Step 3: Go to your ecllipse code. Right Click -> Debug as -> Debug Configuration
Put the follwing parameters :
Host name: COMPLETE ADDRESS OF YOUR CLUSTER
Port : 7777
Project Name: Choose the project in ecllipse which has the code class
DEBUG !
Step 4:
Run the code from the dev cluster by the usual command of spark-submit
You can see your code running in Dev cluster, but coming to a halt and passing the pointer back to ecllipse when it tries to execute the Debug break point.
Step 5:
To go back to the original non suspending mode:
export SPARK_SUBMIT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n

Debugging Hive in Eclipse?


Why is back-stick penalized?

Question: I find lots of explanations online of how and when is a back stick sanctioned.
But I wasn't able to find why this rule was added or what is it trying to achieve or prevent.
In two of its closest relatives, rink and ice hockey, you can hit the ball or puck with any side of the playing end of the stick, in rink hockey the stick is totally symmetrical but not on ice hockey.
If the answer is that the curved side of the stick isn't very useful or accurate to strike the ball because of its curve, then it begs the question of why does the stick have a curved side?
Comment: "why does the stick have a curved side?" This feels like a separate question, but the simple answer is "to put mass behind the ball, so it goes further and faster". Compare a hockey stick to a golf driver/wood.
Comment: But it could have that mass and still be flat on both sides. More over, with modern materials it could have more weight in less thickness
Answer: The rule exists for safety reasons, both historically and today.
You can only play the ball using the left-hand, flat face of the stick, which places it on the right side of the body.
When two opponents both move to play the ball, they will be on opposite sides of the ball, minimising the risk of bodily collision.
As skills have developed, top-level players are capable of rotating the stick to use the playing side in almost any position, this rule also serves to elevate the ability required, helping to make the sport more interesting as well.

Why is back-stick penalized?


MTLS on Nginx that works with client side Android Apps?

Question: Is there a way to pull off MTLS/Two-Way SSL/Client Certificates that work on unrooted v10+ Android Clients on the cheap?
I have a couple of personal api end points that I want to be publicly accessible for just me and a few family members but filter all other traffic out like bad bots, exploit scanners or any nosey clients on the same gateway. I have been using IP filtering which works for the bots but still exposes to any device on the whitelisted ip.
Currently I reverse proxy the end points through subdomains on Nginx then filter access with DDNS IP whitelist and 444 the rest. Another option available for restricting access with Nginx is through Client Certificates/MTLS. This seemed like a perfect fit, I can get Nginx to request a client certificate as optional, and 444 all traffic except matching mapped ssl_client_fingerprint's. This would be a tighter setup than just IP.
I went though and created my own Private EC Root CA's, Intermediary Server CA's and client certificates all signed and and chained together and packaged in a PFX with OpenSSL. On MacOS and Windows, everything works great and as expected in browsers and through Apps that access the API's. Nginx gets fed the proper certificate back from clients and allows matching fingerprint hashes in or else drops the connection.
On Android 10+, everything works the same when accessed through a browser, perfect. Trouble comes when I try to access the API's though Android Apps, Nginx gets no client certificate response.
From what I have gathered, this kind of setup used to work, maybe Android <=7 was where things changed. My understanding is that from 8+, Android Apps no longer trust User Trust Stores/Private CA Client chains at all by default, only Public System Stores unless they explicitly allowed to do so in the apps manafest/network security settings before compiling the APK? I'm assuming there is a valid and necessary security reasons for the changes.
Is there still a way to make this work on the cheap? This is what I think my options are:

Buy a Public Well-Known CA that I can sign client certificates with? Not sure if I can get away with a cheap DV or if it has to be something much more complicated and expensive?

Setup OpenVPN service on the server and tunnels for just the apps that need access. Seems overkill compared to client certificate. I'm using a small VPS, less overhead is the better option for me.

Hand roll open source APKs of said Android Apps to allow User Trust Stores. Seems like a pain in the ...

Root all devices to force cert auth. Not an option for me for all the needed devices.

Stick with IP whitelists. Not perfect but it does work at keeping the bad scanners out.

Does anyone have any alternative recommendations I may not know about, suggestions or corrections to what I am trying to do above?
Cheers
Answer: I ended up using Wireguard and so far it seems to be light on resources.
I filtered the Wireguard port with the DDNS whitelist since I already had it in place then I changed Nginx to allow peers from the VPN or else they must have a valid Client Cert that has it's hash mapped or else they 444. Then Android apps can use the VPN tunnel for specific apps that need them and then all others can use the normal setup with certificates.


Why the fourth homology of the cofibre of Moore space $H_4(C) = 0$?

Question: Why the fourth homology of the cofibre of Moore space (of dimension 2) equals $0$ i.e. $H_4(C) = 0$?
Could anyone explain this to me, please? I think it is related to the construction of Moore space of dimension 2 and that there are no cells in the fourth dimension, but why there are cells in the third dimension?
Definition:
Let $G$ be an abelian group and $n$ an integer $\geq 2.$ A Moore space of type $(G,n)$ is $1-$connected, $CW-$complex $X$ such that:
$$ \widetilde{H}_i(X) = \begin{cases}
      0 & if \, i \neq n, \\
      G &  if   i = n.
   \end{cases} $$
Comment: @ConnorMalin ok I will edit my question with the definition.
Comment: What do you mean by "the cofiber of Moore space"?
Comment: Please tell us your definition of Moore space.
Comment: Have you tried looking at the long exact sequence in homology?
Comment: @EricWofsey I mean the cofibre of maps (universal quantifiers ) between Moore spaces.
Comment: @JHF I think I get this information from my professor and my professor said it is related to the construction of Moore spaces but I do not know why.
Answer: Use the long exact sequence in homology as @JHF said: given a map $f: X \to X$ with cofiber $C$, it will look like
$$
\dots \to H_4(X) \xrightarrow{f_*} H_4(X) \to H_4(C) \to H_3(X) \to \dots
$$
You know from the definition of $X$ that its homology groups in this range are zero, so the long exact sequence looks like
$$
\dots \to 0 \to 0 \to H_4(C) \to 0 \to \dots
$$
Comment: @Happy: 0 also: use the long exact sequence for reduced homology, in which the only nonzero entry for the Moore space is in dimension 2.
Comment: Because it works? Because the Moore space is defined in terms of its reduced homology? Because 0-dimensional homology and maps between 0-dimensional homology groups are easy to understand? I don't think I understand your question.
Comment: The ordinary sequence works, because as I just said, maps between 0-dimensional homology groups are easy to understand. But the reduced sequence is simpler.
Comment: I will say this one last time: maps between 0-dimensional homology groups are easy to understand. If you don't understand this, please ask a new question on this site rather than just commenting on someone else's old question.
Comment: How do I know from the definition of $X$ that its homology groups in this range are zero ? what in the definition tell me that?
Comment: You gave the definition: $\widetilde{H}_i(X)=0$ unless $i=n$. In this case $n=2$ since you said it is a Moore space "of dimension 2".
Comment: What about $H_1(C)$ in this sequence? what is it equal? is it $0$ or $\mathbb Z$?
Comment: And why we should use the long exact sequence for reduced homology in that case?
Comment: I mean why the ordinary long exact sequence for homology does not work if we are asking about $H_1(C)$?
Comment: but the ordinary sequence has $0$ before $H_1(C)$ and $\mathbb Z$ after it .... why should we conclude from this that $H_1(C) = 0$?
Comment: Ok, I am sorry about that.


Load PHP generated HTML with JS in HTML div class doesn`t work anymore

Question: Some time ago I put up a Twitch.tv stream status indicator with a little help of a friend on my website, but suddenly it`s not showing up anymore.
This is my setup:
Folder where all of my files for this are included. An index.php file that provides the HTML Code is working when opening the directory with the browser and is showing the correct status.
In this folder I also have the following JS File, that should load the HTML output:
var myRequest = new Request({
    url: 'https://myurl.de/twitch/',
    method: 'get',
    onRequest: function(){
        document.getElementById('streamNavList').set('html', '');
    },
    onSuccess: function(data){
        document.getElementById('streamNavList').set('html', data);
    }
}).send();

My HTML Code to show is:

At the moment nothing is displayed where the status would be.
This has worked in the past. I can`t remember whether I changed anything relevant to this.
When opening the PHP generated HTML directly it works perfectly.
So I assume it has something to do with the JS loading, but can not figure out what...
Would be great if someone could help me out here.
Thank you very much :)
Comment: 1) Check your browser's dev console for errors. 2) Where does `Request` come from? 3) Where does `Element.set()` come from? _Edit: ok, looks like Mootools_
Comment: `console.log(data)` in success and check what you get.
Comment: I have looked into this again. Right as you said "Mootools" it made click and my search began. Seemed that my way of loading Mootools from google is outdated and now got blocked. I need to include a new version of Mootools in my  and change the way it`s getting loaded from Google. Thanks for you help guys. How could i be so blind....
Answer: The Mistake was loading Mootools via the outdated Google jsapi.
Loading it directly with:

fixed the Problem.
Thanks for your help.


Is dependent choice necessary to prove every perfect compact Hausdorff space is uncountable?

Question: The answer to Cardinality of a locally compact Hausdorff space without isolated points shows that AC is required to show that if $X$ is a compact Hausdorff space with no isolated points then $|X| \ge 2^{\aleph_0}$.
But I haven't been able to find anything sensible about whether dependent choice is needed to prove the weaker statement that $|X| \not\le \aleph_0$.
https://mathoverflow.net/questions/38450/compact-hausdorff-spaces-without-isolated-points-in-zf seems to try to answer the question, but it falls short. Choosing points is not a problem, but choosing open sets is.
Comment: Oh good! This is better than sleep! *gets out his pen and paper...*
Comment: (In my deleted answer, to those who can read it, there are a couple of mistakes that I have yet to correct. When those are cleared up, I'll fix and undelete it.)
Comment: I avoid using the built in chat system. Feel free to send me an email, my address is not very difficult to find...
Answer: Some choice is necessary: if ZF is consistent, there is a model of ZF in which there is a perfect compact Hausdorff topology on a countable set. On the other hand you can weaken dependent choice to "Dependent choice for relations on $\mathbb R$" (Howard-Rubin Form 211).
The idea is to embed a generic Boolean algebra into $\mathcal P(\omega)$ and use this as a topological base. I'll need a few properties of the free countably generated Boolean algebra $\mathcal B.$ This can be constructed by its Stone representation as the algebra of clopens (closed and open sets) of Cantor space, $2^\omega$ with the product topology. The Cantor space has an important homogeneity property that any nonempty clopen is actually homeomorphic to $2^\omega.$ This can also be seen using Fraïssé's theorem.
The interesting part of the argument, showing compactness, will use this homogeneity. I'll illustrate the basic principle with a special case. Given two nonzero elements $b,c\in\mathcal B,$ there is an automorphism $\pi$ such that $b\vee \pi(c)=1.$ This is obvious if $b=1$ or $c=1.$ Otherwise, there is a partition $b$ as $b=b_1\vee b_2,$ where by "partition" I mean $b_1,b_2\neq 0$ and $b_1\wedge b_2=0.$ Similarly there is a partition $c=c_1\vee c_2.$ For $b\in\mathcal B$ temporarily let $D(b)$ denote the corresponding clopen under the Stone representation mentioned earlier. There are homeomorphisms taking $D(\neg c),D(c)$ to $D(b_1),D(\neg b\vee b_2)$ respectively. The union of these is a homeomorphism corresponding to an automorphism $\pi$ of $\mathcal B$ satisfying $b\vee \pi(c)=b\vee \neg b \vee b_2=1.$
Note we could have just sent $D(\neg c),D(c)$ to $D(b),D(\neg b)$ respectively, but that would introduce the unnecessary constraint $b\wedge c=0.$ It will be important to be able to add the constraint $b\vee c$ in a sufficiently generic way. The general statement I want to use is:
Lemma. Fix finite subalgebras $A,B,C\subset \mathcal B$ with $A\subseteq B,C,$ and elements $b\in B$ and $c\in C$ such that $a\wedge b>0$ and $a\wedge c>0$ for each atom $a$ of $A.$ There is an automorphism $\pi$ fixing each element of $A$ and such that for all pairs of atoms $t_B$ and $t_C$ of $B$ and $C$ respectively, $t_B\wedge \pi(t_C)>0$ if and only if $t_B,t_C\leq a$ for some atom $a$ of $A,$ and either $t_B\leq b$ or $t_C\leq c.$ In particular $b\vee \pi(c)=1.$
(Arguably this isn't really any more general, it's just extra bookkeeping. It immediately reduces to the case $A=\{0,1\}.$ And by being more clever later about forcing conditions for statements with lots of symmetry, I think we only really need the case where $B$ is generated by $A\cup \{b\}$ and $C$ is generated by $A\cup \{c\}.$)
Proof. Partition each atom $t_B$ of $B$ into $\bigvee_{t_C} z(t_B,t_C)$ where $t_C$ ranges over atoms $t_C$ of $C$ such that $t_B,t_C\leq a$ for some atom $a$ of $A,$ and either $t_B\leq b$ or $t_C\leq c.$ Take $\pi$ to be an automorphism taking $\bigvee_{t_B} z(t_B,t_C)$ to $t_C$ for each atom $t_C$ of $C.$
Finally, by distributivity $1=\bigcup (t_B\wedge \pi(t_C)),$ so from $t_B\wedge \pi(t_C)\leq b\vee \pi(c)$ we get $b\vee \pi(c)=1.$
$\square$
I'll use the technique of building a symmetric submodel of a generic extension; my reference is Jech's Set Theory, in the chapter "Applications of Forcing". Working in ZFC, let $\mathcal B$ be the free countably generated Boolean algebra and let $\mathbb P$ be the poset whose elements are triples $p=(B_p,m_p,f_p)$ such that:

$B_p$ is a finite subalgebra of $\mathcal B,$ and
$m_p\in \omega,$ and
$f_p$ is a function $B_p\times m_p\to 2$ whose curried version $B_p\to 2^{m_p},$ i.e.  $b\mapsto (f(b,i))_{i\in m_p},$ is a Boolean algebra homomorphism. By Stone duality this corresponds to choices of atoms $x_0,\dots,x_{m_p-1}$ of $B_p,$ with $f_p(b,i)=1\iff x_i\leq b.$

And define $p\leq q$ to hold whenever

$B_p\supseteq B_q,$ and
$m_p\geq m_q,$ and
$f_p\supseteq f_q.$ So for $i<m_q,$ the atom of $B_p$ corresponding to $f_p(-,i)$ must refine (=is less than or equal to) the atom of $B_q$ corresponding to $f_q(-,i).$

Let $\mathcal G$ be the group of automorphisms of $\mathcal B,$ and for finite subalgebras $B\subset\mathcal B$ let $\mathcal G_B$ denote the subgroup of automorphisms that fix each element of $B.$ Equip $\mathcal G$ with the normal filter generated by $\{\mathcal G_B:B\subset \mathcal B\}.$ There is an obvious action of $\mathcal G$ on $\mathbb P.$ Starting with a transitive model $M$ of ZFC, take an $M$-generic set of conditions $G$ for the notion of forcing $\mathbb P,$ then restrict to the symmetric submodel $N\subset M[G]$ with respect to $\mathcal G.$ When I talk about forcing from now on, I am quantifying over $N.$
$N$ contains each set $X_b=\{i\in\omega:(\exists p\in G)(f_p(b,i)=1)\}$ for $b\in \mathcal B$ as well as the collection $\mathcal X=\{X_b:b\in\mathcal B\},$ which is a Boolean subalgebra of $\mathcal P(\omega).$ Beware however that the function $b\mapsto X_b$ is not in $N.$ Let $\tau$ be the topology generated by $\mathcal X.$
The easy part of the argument is that $\tau$ is Hausdorff in $N.$ Below any condition $p,$ given $i<j,$ we can pick a $b$ "independent" of $B_p$ by partitioning each atom $a$ of $B_p$ as $a_0\vee a_1$ and taking $b=\bigvee_{a} a_1.$ Then choose a condition $q\leq p$ that forces $X_b$ to contain $i$ and not $j,$ so that $i$ and $j$ have disjoint neighborhoods $X_b$ and $X_{\neg b}.$
There are no isolated points because any non-empty set $X_b$ will be infinite.
It remains to show that $\tau$ is compact in $N.$ Working with the base $\mathcal X,$ we want to show that any subset of $\mathcal X$ which is closed under finite unions and which covers $\omega$ must in fact contain $\omega.$ Consider a hereditarily symmetric name $\dot{\mathcal A}$ (I'm not consistently using dots, but it seems worth it here to emphasise that this is a name) and consider a condition $p$ forcing $\dot{\mathcal A}$ to be a subset of $\mathcal X$ which is closed under finite unions and which covers $\omega.$ We want to find $s\leq p$ such that $s\Vdash X_1\in\dot{\mathcal A}.$
Let $A$ be an algebra such that $\mathcal G_A$ fixes $\dot{\mathcal A}$ and $p.$ Extending $m_p$ and $f_p$ if necessary (without changing $B_p$) we can ensure that for each atom $a$ of $A$ there is $i_a\in\omega$ such that  $p$ forces $i_a\in X_a.$
Using the covering property we can pick $q\leq p$ and $b\in\mathcal B$ such that $q$ forces: $X_b\in\dot{\mathcal A},$ and $i_a\in X_b$ for each atom $a$ of $A.$ Using the covering property again we can pick $r\leq p$ and $c\in\mathcal B$ such that $m_r\geq m_q$ and such that $r$ forces: $X_c\in\dot{\mathcal A}$ and $m_q\subset X_c$ and $i_a\in X_c$ for each atom $a$ of $A.$ Apply the Lemma to get $\pi\in\mathcal G_A$ such that $t_B\vee \pi(t_C)>0$ for atoms $t_B\in B$ and $t_C\in C$ if and only if $t_B,t_C\leq a$ for some atom $a\in A,$ and either $t_B\leq b$ or $t_C\leq c.$
To complete the argument we just need to show that the conditions $q$ and $\pi(r)$ have a common refinement $s$; this will force $X_1=X_b\cup \pi(X_c)\in\dot{\mathcal A}$ as required. Take $B_s$ to be a finite Boolean algebra containing $B_q$ and $B_{\pi(r)}$ and take $m_s=m_r$ (which we ensured was at least $m_q$).
For $i<m_q$ we need to pick an atom $t$ of $B_s$ such that $t\leq t_B$ and $t\leq\pi(t_C)$ where $t_B$ is the atom of $B_q$ corresponding to $f_q(-,i),$ and $t_C$ is the atom of $B_r$ corresponding to $f_r(-,i).$ We arranged that $r$ forces $i\in X_c,$ which is equivalent to $f_r(c,i)=1,$ which is equivalent to $t_C\leq c.$ By definition of $\pi$ we get $t_B\wedge\pi(t_C)>0,$ so there is an atom $t$ of $B_s$ with $t\leq t_B\wedge\pi(t_C).$
For $m_q\leq i< m_r$ we need to pick an atom $t$ of $B_s$ such that $t\leq \pi(t_C)$ where $t_C$ is the atom of $B_r$ corresponding to $f_r(-,i).$ Just pick any atom $t$ of $B_q$ with $t\leq \pi(t_C).$
Answer: Here's a proof from the axiom of countable choice.
Let $(X,\tau)$ be a compact Hausdorff space with $|X|=\aleph_0$ and no isolated points.  $\tau\subseteq \mathcal{P}(X)$ is the topology.  Since $X$ has no isolated points, every non-empty open set is infinite.
$\tau$ being a subset of a set of cardinality $2^{\aleph_0}$ may not be well-orderable, but $X$ is well-orderable.  Let $(X,<)$ be a well-ordering of $X$ in order type $\omega$ (so every proper initial segment of $(X,<)$ is finite.)  For a non-empty $S\subseteq X$ denote $m(S)=\min_<(\{x:x\in S\})$.
Since $X$ is Hausdorff, if $x,y\in X$ and $x\ne y$ there are $U,V\in\tau$ such that $U\cap V=\emptyset$, $x\in U$ and $y\in V$.  Then $\overline{V}\subseteq X\setminus U$, so $x\not\in\overline{V}$.  Now, for all $x,y\in X$ such that $x<y$ let
$$\mathcal{W}_{x,y}=\{V\in\tau:x\not\in\overline{V}\land y\in V\}\in\mathcal{P}(\tau)$$
By the above, for all $x<y$, $\mathcal{W}_{x,y}\ne\emptyset$.  By the axiom of countable choice there exists a selection $W_{x,y}\in \mathcal{W}_{x,y}$ for each $x<y$.  So $W_{x,y}\in\tau$, $x\not\in\overline{W_{x,y}}$ and $y\in W_{x,y}$.
Now we construct by recursion a sequence of sets $\{B_n\}_{n=0}^\infty$ such that each $B_n$ is a closed subset of $X$ with the following properties

$B_n$ has non-empty interior (and in particular is infinite.)
$B_{n+1}\subseteq B_n$
$m(B_n) < m(B_{n+1}$)

Let $B_0 = X$.  Assume $B_n$ has been constructed.  Let $x=m(B_n)$.  By the induction hypothesis $B_n$ has an infinite non-empty interior.  So let
$$y=m(\{y\in B_n:x<y\land y\in\operatorname{int}(B_n)\})$$
Now let $B_{n+1}=B_n\cap \overline{W_{x,y}}$.  Note that $B_{n+1}$ is closed as an intersection of two closed sets and $B_{n+1}\subseteq B_n$.  By the definition of $W_{x,y}$, $x\not\in\overline{W_{x,y}}$ and $y\in W_{x,y}$.  So $x\not\in B_{n+1}$ which proves that $x=m(B_n)<m(B_{n+1})$.  Furthermore $y\in\operatorname{int}(B_n)\cap W_{x,y}$ which establishes that $y$ is an interior point of $B_{n+1}$.  Hence $B_{n+1}$ has non-empty interior.
Finally, let $B=\cap_{n=0}^\infty B_n$.  $B$ is the intersection of a decreasing sequence of closed non-empty sets and $X$ is compact, so $B\ne\emptyset$.
But is it?  Let $x\in X$ be any point.  Since $(X,<)$ has order type $\omega$, the initial segment $\{y\in X: y \le x\}$ is finite.  The sequence $\{m(B_n)\}_{n=0}^\infty$ is strictly increasing in $(X,<)$.  So there must exists some $k$ such that $x < m(B_k)$.  Then $x\not\in B_k$ and so $x\not\in B$.  So $B=\emptyset$, a contradiction.
Comment: Whoops; looks like I fat-fingered a downvote. Sorry! I'll try to read over this tonight, though I've forgotten an awful lot of topology since I wrote this question :-/.


Descobrir o sistema operacional da máquina em C

Question: Preciso fazer uma função para limpar a tela em C que rode no Windows, no Mac e no Linux. Pensei em fazer uma função que:
Se o SO fosse Windows: system("cls");
Se o SO fosse Linux ou Mac: system("clear");
O problema é: Como faço pra descobrir o sistema operacional do computador e como seria esses if e else?
Comment: Da uma olhada http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
Comment: Acho melhor você criar um programa para cada SO. Se você for fazer tudo junto, vai ficar mais pesado e confuso.
Answer: Para saberes se o sistema é linux ou windows podes fazer da seguinte maneira:
#ifdef __unix__
    #include <unistd.h>
    #include <stdlib.h>

#elif defined(_WIN32) || defined(WIN32)

   #define OS_Windows

   #include <windows.h>

#endif

int main(int argc, char *argv[])
{
#ifdef OS_Windows
 /* Codigo Windows */
    system("cls");
#else
 /* Codigo GNU/Linux */
    system("clear");
#endif
}

Answer: Nesta resposta, eu usei isso:
#if defined(__MINGW32__) || defined(_MSC_VER)
#define limpar_input() fflush(stdin)
#define limpar_tela() system("cls")
#else
#include <stdio_ext.h>
#define limpar_input() __fpurge(stdin)
#define limpar_tela() system("clear")
#endif

Comment: Eu normalmente procuro pela definição de `WIN32` ou `_WIN32`.  Também uso mais o Visual Studio do que o `MingW` para programar


Get attachment ID

Question: How do i get the "attachement_id="
like here ;

I hope someone can give me an answer. I want to tie this id to a jquery selector for fullscreen images.
Comment: @S.Pols lol thanks -> http://www.hdwallpapersimages.com/wp-content/uploads/2014/01/Winter-Tiger-Wild-Cat-Images.jpg
Comment: show us how you're using this in your template
Comment: @DannyHearnah that doesnt really matter does it? I just want to know how i can achieve that attachment ID as seen in the picture.
Comment: I do not have knowledge about wordpress, but if you can show your html we can maybe archieve this using jQuery.
Comment: Well.. this is the backend of wordpress and this is its media-library, so i did not use any html to achieve this image and link etc
Comment: From where are you trying to get the attachment id? From the frontend (i.e. javascript)? Backend (php)? What are you using it for?
Comment: I want to get the attachment id for the backend, to show it to the front end. so in Index.php (of wordpress) I want to get that damn ID to pass it into jquery in the index.php file
Answer: Fixed it this way;
foreach ($metas as $metakey) {
        $image_id++;

 echo "
";

and for the jquery selector;
$('#img\\_<?php echo $image_id ?>').on('click', function () {

this way each image i click, actually is that image. So i got this
$full_image = wp_get_attachment_image_src($metakey['image'], 'full');

This results that each image i click i get the right url.
Thanks though.
Answer: It is a little bit complicated, because all attachments are linked to the given posts.
Example: To display all of the images and titles attached to a certain page and display them as a list you can use the following:
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post();

 $args = array(
   'post_type' => 'attachment',
   'numberposts' => -1,
   'post_status' => null,
   'post_parent' => $post->ID
  );

  $attachments = get_posts( $args );
     if ( $attachments ) {
        foreach ( $attachments as $attachment ) {

           echo wp_get_attachment_image( $attachment->ID, 'full' );
           echo '
';
           echo apply_filters( 'the_title', $attachment->post_title );

          }
     }

 endwhile; endif; ?>

Answer: What you looking for is :
$attachment->ID

Take a look at the function wp_get_attachment_image
Reference: Wordpress Attachment
You have to get the $post->ID in order for that to work.
Reference : https://core.trac.wordpress.org/browser/tags/4.0.1/src/wp-includes/link-template.php#L392
Comment: echo $attachment->;

doesnt do anything.

Get attachment ID


How can i use Jenkins with Atlassian Stash?

Question: I've just setup Jenkins and i have some Repositories in my Stash.
I installed the "Git plugin" in jenkins.
I can now enter the repository url but there is nothing to enter my credentials.
It's possible using
<code>http://username:password@mydomain/xx/yy.git
</code>
but that is something i dont want to do.
What else can i do to authenticate?
Answer: I am the author of this stash plugin that might help you: https://github.com/palantir/stashbot
Taking selectively from the readme:
To work with Jenkins, you MUST install the following jenkins plugins first.

Jenkins GIT plugin
Post build task

Next, build and install the plugin using the plugin SDK (more details in the readme)
Next, the stash admin goes into the Stashbot Admin page and creates a jenkins server config - here you give it the URL, username/password, etc details of the jenkins server.
Next, for each repository a "Stashbot CI Admin" link shows up for repo admins.  From there you can check the "enabled" checkbox and tell it what branches you want build (via a regex) and what command it should run to do the build (optionally verifies and publishes).
After this point, the remainder is completely self-service.  Any repo admin can ask for their project to "have CI" by filling out that form, and the jobs will automatically be created in the jenkins server.
Hope that helps.
Comment: -1 Please summarize how to solve the OP's actual problem.  Including a link is fine, but link-only answers are discouraged.
Comment: Updated with details from the README.
Answer: Set up an SSH key for the user that runs your Jenkins builds and add it to the repository's SSH keys in Stash.  See the Stash docs for instructions.
Answer: Two things to add to Gareth's answer.

While I agree that using SSH keys are definitely better than hard-coding the username/password, it's worth mentioning that Stash (currently) scales better with HTTP when it comes to CI. If you have quite a few builds we generally recommend using HTTP. We are currently extending our Git cache support to support SSH so this no longer an issue.
Somewhat related, you might be interested in watching and voting for the following feature which will make it easier to create CI specific keys.

Lastly having build icons show up in Stash is surprisingly handy, and you should have a look at the following plugin if you haven't already:
https://github.com/jenkinsci/stashNotifier-plugin
Comment: It's worth noting also that stash currently randomly fails clones with http(s) but doesn't with git protocol =(
https://jira.atlassian.com/browse/STASH-6887
Answer: Since version 2.0 of "Git Plugin" for jenkins you should be able to directly add the required credentials for both ssh and username/password (based on credentials plugin).
See changelog of Git plugin: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Changelog for details.
For further integration of git and stash regarding pull requests you additionally need the "Stash Webhook for jenkins" add-on in stash and the "Stash Notifier" plugin for jenkins to connect each other.


Cannot upload firestore cloud function with wildcard and onDelete trigger?

Question: I have a function with trigger like so:
exports.eventDeleteListener = functions.firestore.document('events/{eid}').onDelete((doc, context) => {

And when I try to upload to Google cloud functions I am met with the following error:
Failed to configure trigger PubSub projects/myprojectstringthingy
I have similar functions with this same document path, but with an onUpdate trigger like so:
exports.isDeletingFlagListener = functions.firestore.document('events/{eid}').onUpdate((change, context) => {

And these all deploy and work perfectly fine. This function has deployed previously. However, after updating node and firebase tools this function will no longer deploy. I believe it has something to do with rules, as per documentation here, however I do not understand why the other function triggers deploy.
If needed, I can paste the entire function in question.
UPDATE:
I tried deleting all cloud functions and re deploying. I am getting the same error message for four of the functions now, however they are appearing on firestore console as deployed?
Comment: I suggest contacting Firebase support if you're unable to deploy, and you don't get an actionable error message.  https://support.google.com/firebase/contact/support
Comment: Thanks I'll do that and update
Answer: I have a test project that I successfully deployed functions to yesterday. I deleted them and tried redeploying the exact same ones and got your error as well. So the problem seems to be something at Firebase.
Comment: No problem, I hope it can help someone in the future!
Comment: I just clean deleted all of my current functions and tried to re deploy all of them. Now four of them are returning with the same error. But they appear on the firestore console as successfully deployed?
Comment: Same for me. Now it's 24 hours later and deploying works fine again. I guess this will be true for you as well. The only thing you can do in this situation is report it to Firebase support.
Comment: It is now working for me too. Unfortunately I cannot mark as the answer because it did not fix the issue, but I did upvote because it was helpful.


Apache RewriteRule help needed

Question: application uses url like http://www.mydomain.com/item/3193.html to select and show proper record from mysql database.
just to mention, application is written in php, hosted on apache web server..
in fact that should be http://www.mydomain.com/item.html/3193.html, but in .htaccess i have RewriteRule that helps me to treat it like http://www.mydomain.com/item/3193.html
but on the new server that RewriteRule, from some reason does not work. as i said, it is defined in .htaccess with:
RewriteEngine On
RewriteBase /
#some conditions here
RewriteRule ^item/(.*) item.html/$1
#more conditions here

so, it works on old server. it (looks like ?) that it's not working on new server...
so, first of all, i will check with hosting provider if rewrite rules are allowed on server.
also, if they are (and i guess that they are), can i change syntax for this RewriteRule, to get ability i need?
thank you very much in advance!
Answer: It is more likely that you don't have permission to setup .htaccess files. Try to do some basic things like directory listing (without having an index{htm,html,php} or any default page you might have) using Options Indexes
If you are unable to see directory contents, the AllowOverride is set to None (or something restrictive) and that is your problem. It must at least be set to AllowOverride FileInfo and Options FollowSymLinks is also required. Talk to your provider if you really need it (*).
In case you can view the directory listing, then you don't have the required options, and then again, talk to your provider.
(*) RewriteRules are OK inside an .htaccess in a staging or development server where you are trying to get a job done fast without restarting apache many times. If you can, be sure to move them up to virtualhost configuration once your on production.
Comment: syntax in my .htaccess is ok, right? i can setup and use .htaccess, but it doesen't work for RewriteRule... i talked to hosting provider, and he confirmed that i can use .htaccess to write my own rules...
Comment: Yes syntax is OK as long as the working directory is efectively the root of your site. Otherwise RewriteBase should make that clear (i.e. RewriteBase /some/path/). Ask them what is the configuration for AllowOverride and Options. That should give us a hint on why they do not work.

Apache RewriteRule help needed


Is there an algorithm to detect which side of a polygon I have collided with?

Question: If given a n-sided polygon, and a line of length k (at x,y and angle a), is there an algorithm to detect which side of the polygon (if any) I have collided with?  So far I've resorted to testing if x,y is outside of the polygon, and then iterating through each edge of the polygon, calculating the distance to each end.  Here is a JS Fiddle that shows the world I've created.
Here is the JavaScript (the HTML and CSS aren't really worth copying):
var eventLoop,
    maxVelocity = 10,
    agility = 5,
    baseLength = 5,
    degree = ((2*Math.PI)/360),
    world = document.getElementById('world'),
    context = world.getContext("2d"),
    boundry = [[180, 120],[240, 60],[360, 40],[420, 120],[360, 220],[350, 240],[360, 265],[470,360],[450,480],[360,540],[240,550],[140,480],[120,470],[100,360],[120,300],[220,240],[240,220]],
    camera = {
        location: {
            x:300,
            y:90
        },
        angle: 0,
        velocity: 0
    },
    engine = {
        drawWorld: function(shape, context) {
            var point,
                index,
                size = shape.length;

            context.clearRect(0, 0, world.width, world.height);
            context.beginPath();
            for(index = 0; index < size; index++) {
                point = shape[index];
                if(index == 0) {
                    context.moveTo(point[0], point[1]);
                } else {
                    context.lineTo(point[0], point[1]);
                }
            }
            context.closePath();
            context.stroke();
        },
        drawCamera: function(camera, context) {
            var a = camera.location,
                b = this.calcNextPoint(camera, 1);

            context.beginPath();
            context.moveTo(a.x, a.y);
            context.lineTo(b.x, b.y);
            context.stroke();

            context.beginPath();
            context.arc(a.x, a.y, baseLength, 0, Math.PI*2, true);
            context.closePath();
            context.stroke();
        },
        calcNextPoint: function(camera, moment) {
            return {
                x: camera.location.x + ((camera.velocity*(1/moment))*Math.sin(camera.angle)),
                y: camera.location.y + ((camera.velocity*(1/moment))*(Math.cos(camera.angle)))
            };
        },
        isInside: function(point, shape) {
            var i, j, c = 0;
            for (i = 0, j = shape.length - 1; i < shape.length; j = i++) {
                if (((shape[i][1] > point.y) != (shape[j][1] > point.y)) && (point.x < (shape[j][0] - shape[i][0]) * (point.y - shape[i][1]) / (shape[j][1] - shape[i][1]) + shape[i][0])) {
                     c = !c;
                }
            }
            return c;
        }
    };

document.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == '37') {
        // left arrow
        camera.angle += degree*agility;
    }
    else if (e.keyCode == '39') {
        // right arrow
        camera.angle -= degree*agility;
    }
    else if (e.keyCode == '38') {
        // up arrow
        camera.velocity += 1;
        if(camera.velocity > maxVelocity) {
            camera.velocity = maxVelocity;
        }
    }
    else if (e.keyCode == '40') {
        // down arrow
        camera.velocity -= 1;
        if(camera.velocity < 0) {
            camera.velocity = 0;
        }
    }
}

engine.drawWorld(boundry, context);
engine.drawCamera(camera, context);

eventLoop = setInterval(function() {
    engine.drawWorld(boundry, context);
    engine.drawCamera(camera, context);
    if(engine.isInside(camera.location, boundry)) {
        camera.location = engine.calcNextPoint(camera, 1);
    }
}, 100);

I've been toying around with some JavaScript that models a 2-Dementional version of the game Flower by ThatGameComapny, eventually I want to try and implement a Oculus Rift version.  The next problem I'm looking to tackle is a routine to turn the player back into the polygon once they have collided with an edge.
Comment: I would recommend you use dynamic svg's with d3.js or dc.js and they will let you use clip-paths very smoothly.
Comment: I've written this in JavaScript because it's easier to hack away at an idea (for me) and to share it with others, but the final implementation of the algorithm would likely be inside Unity Engine's scripting framework, I don't know if I could use d3.js or dc.js inside that environment.
Comment: I don't know about that engine, but if it supports javascript and svg elements then I am 100% sure that you can use d3.js. Give it a try! if no other thing is working for you.
Comment: Is the polygon convex?
Comment: In order to solve for the hardest use-case the polygon I've constructed is convex. At least it doesn't close over itself like a Möbius strip :) the jsfiddle has the polygon I'm working with.
Comment: @JasonSperske there is a significant difference between a polygon being convex and being non-intersecting. Also the performance of the algorithm for convex polygon will be significantly better.
Answer: So you basicly want to know which edges of the polygon are intersected by given line, right?
This is just quite simple handling of a few linear equations representing the edges (inequations, to be more precise). You already have a great implementation of the inside operation, which also does that. The common denominator of all these algorithms is to compare at which side of the line [x1, y1] - [x2, y2] the point [x, y] lies:
compare = function (a, b) { // classical compare function, returns -1, 0, 1
    return a < b ? -1 : (a == b ? 0 : 1);
}
...
_lineSide: function (x, y, x1, y1, x2, y2) {
    return compare(x - x1, (x2 - x1) * (y - y1) / (y2 - y1));
}

This function will return -1 if [x, y] lies on one side of the line [x1, y1] - [x2, y2], 1 for the other side and 0 if it lies exactly on the line. It is not important here which side is which one, just to separate them. This will however not work when y2 - y1 is zero or close to zero. In that case you have to x-y flip the situation:
lineSide: function (x, y, x1, y1, x2, y2) {
    var eps = 1e-20; // some very small number
    if (Math.abs(y2 - y1) > eps)       // this way we avoid division by small number
        return _lineSide(x, y, x1, y1, x2, y2);
    else if (Math.abs(x2 - x1) > eps)  // flip the situation for horizontal lines
        return _lineSide(y, x, y1, x1, y2, x2);
    else // edge has close-to-zero length!
        throw new this.zeroLengthLineException()
},
zeroLengthLineException: function () {},

Now to test if the two lines [x1, y1] - [x2, y2] and [x3, y3] - [x4, y4] intersect is very easy. Just look if [x1, y1] and [x2, y2] lie on the opposite side of [x3, y3] - [x4, y4], and if [x3, y3] and [x4, y4] lie on the opposite side of [x1, y1] - [x2, y2]. If yes, then the lines intersect!
// proper: true/false (default false) - if we want proper intersection, i.e. just
// touching doesn't count
linesIntersect: function (x1, y1, x2, y2, x3, y3, x4, y4, proper) {
    var min_diff = proper ? 2 : 1;
    return Math.abs(this.lineSide(x1, y1, x3, y3, x4, y4) -
                    this.lineSide(x2, y2, x3, y3, x4, y4)) >= min_diff
        && Math.abs(this.lineSide(x3, y3, x1, y1, x2, y2) -
                    this.lineSide(x4, y4, x1, y1, x2, y2)) >= min_diff;
},

Final solution - http://jsfiddle.net/gLTpT/7/
Now, the final solution is easy: just check the intersection of given line with all of the polygon edges by calling linesIntersect in loop:
http://jsfiddle.net/gLTpT/7/
Comment: I am so glad I added a bounty to this question. This has been nagging at me for a while and already this input has been very helpful :)
Answer: A generic LS to LS test would consists of finding if the polygon end points P[i], P[i+1] lie in the different side of the vector (p, p+d), where d is the direction vector. In order of the lines to cross, also the opposite must hold: both (p, p+d) must be on different side of the line segment P[i], P[i+1].
  o  P[i]              Here P[i], P[i+1] are on different side of p -> q=p+d
   \                   but not the opposite.
    \     q__----p
     \
      o  P[i+1]

In complex or concave scenarios the vector can cross several segments and one needs to solve the closest segment. This is easiest done from the parametric equation
  (x0, y0) + (t * dx, t * dy) == i[0] + u * (i[1]-i[0]), j[0] + u * (j[1]-j[0])

EDIT
Comparing the signed distances of point (i[n],j[n]) to a line (x0,y0) -> (x0 + dx, x1 +dy) requires two dot products and comparison of the sign.
  sameSide = sign((i0-x0)*(-dy)+(j0-y0)*dx) == sign((i1-x0)*(-dy)+(j1-y0)*dx))

In javascript this may be most efficiently done by a * b > 0, where a and b are the expressions whose signs are under comparison.
Comment: Aki, this will not work because the polygon doesn't have to be convex. Look at the picture in my answer and it will be clear to you why this method will not work. It is also much easier and faster to test for the edge intersection than to use the `isInside` test for each edge.
Answer: Here is a little library that will do what you need. I also incorporated the lib into a rewrite of your program. It's in this Gist, which you can download and open in your browser. (I had been meaning to try HTML5 canvas graphics forever. Thanks for giving me this inspiration!)
Also got running here in JS Fiddle.
The library uses a bit of linear algebra to find the intersection of two line segments, if it exists, or tell you if it doesn't.  To determine where you've collided, just check each edge of the boundary against the line segment from the camera position to the position you're about to occupy.  If there's an intersect, you have a collision.
If your camera is taking big steps, or if you are trying to determine where a bullet will strike before it's fired, then you do need to worry about the possibility of crossing multiple edges in one step and getting the right one of several possible intersections. However this little library makes it easy to do that. Say your step is a-->b.  Then keep track of the min intersecting parameter t_ab.  This one gives you both the correct colliding edge and collision point.
I did this with the light gray line segment in the animation.
My code just checks for any intersection and, if found, prevents the step from being taken, so the camera stops one partial step short of moving outside the boundary.
A more interesting and fun thing to try would be to move the camera to the exact intersection point and then compute the physically correct "bounce" direction so it continues to move, pinging off the walls. If you want to know how that works, ask and I can show you.
There are fancier (faster) ways to do collision detection, but this simple method works fine for the number of segments in this little program.  See the classic "Collision Detection in Interactive 3D Environments" by Gino Van Den Bergen for a nice treatment of this subject.  His discussion is obviously for 3D, but the ideas work well in 2D and many of his examples are in 2D as well.
var lib = {
  // Find parameters of intersection of segments a->b and c->d or null for parallel lines
  intersectionParams: function(a, b, c, d) {
    var dx_ab = b.x - a.x
    var dy_ab = b.y - a.y
    var dx_dc = c.x - d.x
    var dy_dc = c.y - d.y
    var eps = 0.00001
    var det = dx_ab * dy_dc - dx_dc * dy_ab
    if (-eps < det && det < eps) return null
    var dx_ac = c.x - a.x
    var dy_ac = c.y - a.y
    var t_ab = (dx_ac * dy_dc - dx_dc * dy_ac) / det
    var t_cd = (dx_ab * dy_ac - dx_ac * dy_ab) / det
    return { t_ab: t_ab, t_cd: t_cd }
  },

  // Determine if intersection parameters represent an intersection.
  // This always counts parallel lines as non-intersecting even if they're touching.
  areIntersecting: function(ip) {
    return ip != null && 0 <= ip.t_ab && ip.t_ab <= 1 && 0 <= ip.t_cd && ip.t_cd <= 1
  },

  // Find the intersection from its parameters and two points.
  intersection: function(ip, a, b) {
    return { x: a.x + ip.t_ab * (b.x - a.x), y: a.y + ip.t_ab * (b.y - a.y) }
  }
}


Count distinct possible words without rotations or reflections

Question: Suppose I have an alphabet ${\{A, B, C, D\}}$ and I want to count all possible words of length $n$. Easy: it's $4^n$.
What should I do if I want to count all possible words that:
a) are unique given any rotation, and
b) are unique including mirroring
For example:
$AAAA$ would definitely be included part of the total (there are no other strings that are rotations or mirrors of it).
Only one of $BAAA$ or $ABAA$ or $AABA$ or $AAAB$ would count towards the total (as they're all the same under some rotation).
Only one of $ABCD$ or $CDBA$ would count towards the total (as they're mirrors of each other).
Only one of $ABCD$ or $ADCB$ would count towards the total (as you can go between them via a rotation and a mirror).
A small illustration
With the above alphabet and words of length 2, there are 10 possible words:
<code>AA - counted
AB - counted
AC - counted
AD - counted
BA - not counted (a reversal and also rotation of AB)
BB - counted
BC - counted
BD - counted
CA - not counted (a reversal and also rotation of AC)
CB - not counted (a reversal and also rotation of BC)
CC - counted
CD - counted
DA - not counted (a reversal and also rotation of AD)
DB - not counted (a reversal and also rotation of BD)
DC - not counted (a reversal and also rotation of CD)
DD - counted
</code>
Comment: Consider the set of ordering of the letter. let $Z/nZ$  act on the set by shifting. We want to count the number of orbit. By Cauchy-Frobinius lemma this is sum of the number of elements fixed by the shifts over n. Then I 'm stuck
Comment: Only 10 words of length 2 as CB == BC. I have not devised a method for counting, but enumeration gives 10, 20, 55 and 136 for lengths 2, 3, 4 and 5.
Comment: Thanks @DanielMathias, fixed my question
Answer: After writing some python to find some numbers by brute force, then searching them on OEIS, I've found out that I'm looking at Bracelet numbers, with alphabet size = colours. Which makes sense, since bracelets (AKA turnover necklaces) allow identity under mirroring and rotation.
To summarise the equation I found at OEIS, for $k$ symbols and word length $n$, the count is found by:
$$
T(n, k) = \frac{k^{\lfloor (n+1)/2 \rfloor} + k^{\lceil (n+1)/2 \rceil}} {4} + \frac{ \sum_{d|n} \phi (d) \cdot k^{n/d} } {2n}
$$
I've written a pure python implementation of this equation and it does match my brute force results for all numbers I've tried.
(See also my follow-up question: Count of bracelets with no adjacent colours the same)


Best modelling approach to account for covariates (Linear Mixed Models, ANCOVA, or another option)?

Question: I have some electrophysiology data that I am analyzing with SPSS (I know R however as well if that makes things easier). Participants were recruited (healthy controls and patients) to undergo an electrophysiology experiment. Patients then participated in two different treatments, and underwent the same electrophysiology experiment 8 weeks later. Controls also did the same experiment 8 weeks later from their initial assessment.
I have 92 participants, with the between-group variables:

Treatment Group: Controls, treatment 1, or treatment 2 (no randomization was done for patients)
Response status (as in whether they responded to the treatment or not): Controls, responders, or non-responders

I also have 2 within-group variables:

emotion of task during the experiment (happy or angry emotional stimuli)
assessment time (baseline or week 8)

Finally, I have some covariates I would like to control for

age
sex
site of data collection (data was collected from 4 different locations and then pooled together).

I have many questions with regards to this dataset, but my primary question is this: were there any differences in electrophysiology data at baseline that differentiated eventual responders and non-responders, and if so, was this relationship modulated based on the treatment type.
My initial thought was to use a repeated measures ANOVA. Here, I added 'Response Status' and 'Treatment Group' as my between-subject measures, and my two within-subject variables of 'Time' and 'Emotion Valence'.
However, my question is, with the described dataset, how can I go about "controlling" for the three described covariates? Would this have to be done via linear mixed modelling, or would an ANCOVA be okay?
Comment: ANOVA isn't appropriate. Are there only two measurement occasions - baseline and followup ? Was there any randomization ? ANCOVA would probably be OK provided that all the covariates were balanced at baseline. Otherwise a mixed model would be better.
Comment: Hi Robert, yes there are only two measurement occasions (baseline and follow up) and there was no randomization.
Answer: In this case you can't use a repeated measures ANOVA because of the potential confounders that you want to control for.
ANCOVA is not appropriate because you have differential baseline distribution of the covariates.
A linear mixed model with random intercepts for participants, and fixed effects for the other variables (and appropriate interactions) would be a good approach to take.
Comment: You're welcome. I would model site as fixed, since you only have 4 of them.
Comment: Thank you very much Robert. Would site of data collection be considered a random effect in this case?


Prove an Unbiased Estimator of p.

Question: Suppose you have a random variable X with distribution Geom(p), and you would like to estimate p.

Since E(x)=1/p, a natural approach to estimate p is to get a sample from X and then take the reciprocal 1/X. Show that this is NOT an unbiased estimator for p.
Suppose you take n i.i.d. samples X1, X2,...,Xn, and you let Y be the fraction of these samples that equal 1. Show that Y is an unbiased estimator for p.
Answer: Let your estimator be $1/X$ based on a one-element sample. Then, using the probability mass function of the geometric distribution,
\begin{align*}
\mathbb{E}\left(\frac{1}{X}\right)=\sum_{k=1}^{\infty}(1-p)^{k-1}p\times\frac{1}{k}=\frac{p}{1-p}\sum_{k=1}^{\infty}\frac{(1-p)^k}{k}=\frac{p}{1-p}(-\log p),
\end{align*}
where I used the Taylor expansion $\sum_{k=1}^{\infty}(1-x)^k/k=-\log x$, which is valid for any $x\in(0,1)$. This estimator is biased, since its expected value is not equal to $p$.
As for the second estimator, let, for each $i\in\{1,\ldots,n\}$, $K_i$ be the indicator of whether $X_i=1$. Then,
\begin{align*}
Y=\frac{1}{n}\sum_{i=1}^nK_i
\end{align*}
by construction. Note that $\mathbb{E}(K_i)=\mathbb{E}(\mathbf{1}_{\{X_i=1\}})=\mathbb{P}(X_i=1)=p$. Hence,
\begin{align*}
\mathbb{E}(Y)=\mathbb{E}\left(\frac{1}{n}\sum_{i=1}^n K_i\right)=\frac{1}{n}\sum_{i=1}^n\mathbb{E}(K_i)=\frac{1}{n}\sum_{i=1}^n p=\frac{1}{n}\times np=p.
\end{align*}
Therefore, $Y$ is an unbiased estimator of the parameter $p$.
Comment: For the first part one could use the fact that, by convexity, $E[1/X]\gt1/E[X]=p$.

Prove an Unbiased Estimator of p.


Is it good practice to use Linear Least-Squares with SMA?

Question: I have time-series (daily) data and I want to understand the general trend.
My current approach is:

Calculate the 7-day simple moving average.
Add a line of best fit (linear least squares regression).
Plot, then review metrics such as r, r^2, etc.

Question: is it good practice to draw a line-of-best fit on a moving average?  I'm not very experienced but my understanding is MA and linear trend lines are both trend lines, so I'm not sure if it's OK to combine them in this way.
Raw data looks like this:
day             + count
2015-01-01 | 123
2015-01-02 | 290
2015-01-03 | 329
2015-01-04 | 276
Let me know if more detail would help- any direction on this is much appreciated.
Comment: It depends on how you compute step (2), "a line of best fit (linear least squares regression)." If you just drop the data into a least squares black box, most likely it operates under the assumption the errors are independent, whereas in a moving average the errors are strongly interdependent (*e.g.*, neighboring 7-day averages have six days of data in common).  You need to use a procedure that accounts for this. There are robust ways to explore trends, such as various nonparametric smoothers, so maybe it would be more fruitful to investigate them rather than fixing your current approach.
Answer: Of course you can do a fit on a moving average. That is your right. But the statistical diagnostics are not reliable anymore. The reason is that the IID property required in standard OLS are violated when you apply plain regression on a quantity that is highly autocorrelated.
Your $r^2$ will be artificially high and will insinuate a false sense of statistical significance. Think about this case, instead of a moving average do a linear fit on your original data in time first. And then do it a gain, you will get 100% $r^2$.
These models are not reliable ex-ante predictors and will have very low out-of-sample qualities.


GMAP 3 Plugin for JQuery. Change the Marker Position?

Question: I am using the GMAP 3 plugin for JQuery on my website.
I want to re-position the Marker to point to this place.
The Code is Here.
Due to limitation of the number of characters, I am posting the Code in Pastebin.
Anyone who has used this plugin before and knows how to re-position the map marker to point to a particular place?
Answer: Not sure if you still have issues with this but that should be the simplest of all usage of the plugin:
<code><script>
      $(document).ready(function(){
        $('#IdOfYourMapDivContainer').gmap3({
           map:{
              options:{
                  center: [17.435939, 78.341678],
                  zoom: 8
              }
           },
           marker:{
              latLng: [17.435939, 78.341678]
           }
        });
      });
</script>
</code>
Comment: Thanks, I got the implementation. The change was to be done in the main JS file where the GMAP3 was finally called.
Comment: Great thanks! Become insane by trying using position variable from documentation. With latLng work fine.


OneDrive for business data retention post license deactivation

Question: OneDrive for business data retention post license deactivation
My client doesn't want his users to use OneDrive for business.
They want to use Sharepoint on-premise. Unfortunately few of the users have enabled Onedrive as it was a part of Microsoft 365 Apps for Enterprise (formerly pro-plus) license bundle/pack.
As part of the remediation.

The Officeonline and Onedriveforbusiness services have been disabled in the M365 license option and reassigned to the users.
The existing personal sites lockstate is set to no access.

Q: Some of the users had data in the onedrive sites. How long the data will be retained ? Will OD4B data deletion get triggered in this case ?
Answer: As of October 2020, the data will be retained forever unless you delete the user or stop syncing them.
Source: Files saved in OneDrive for Business aren't deleted unless the user is deleted from the Microsoft 365 admin center or is removed through Active Directory synchronization. For more information, see OneDrive retention and deletion. Based on your description of the scenario, the answer is no, data will not be deleted. As a best practice, the Client should configure Retention Policies in their Tenant for all 365 services.


É possível carregar templates do undescore externamente com javascript?

Question: Geralmente, costumo utilizar Template Engines para poder renderizar HTML via JavaScript. Uso comumente o undescore.js.
Gosto muito dessa maneira de tornar mais fácil a criação de HTML com Templates.
Exemplo:
Em algum lugar do HTML:

No arquivo JS
var tplTemplate = _.template($('#tpl-template').html());

$('body').append(tplTemplate({nome: 'Wallace'}));

Porém é sempre necessário ter que deixar esse código junto ao código HTML. Eu gostaria de poder organizar esses códigos em um arquivo separado (como um tpl.js), por exemplo, porém ainda não consegui uma maneira.
Creio que através do atributo src não exista maneira de se fazer isso - se existir me corrijam.
Preciso saber se existe alguma maneira de fazer isso em JavaScript.
Comment: Você quer fazer um novo AngularJs. **Ps1** - Não fui eu que negativei. **Ps2** - Você faz muitas perguntas, deve ser por isso o -1. **Ps3** - Não sei a reposta. **Ps4** - Já começou a fabricação nacional, vai baixar o preço.
Comment: Alguma razão especial para eu ter tomado um -1? Minha pergunta foi tão burra assim?kkkkkk
Comment: Não entendi a PS4.
Comment: Muitas perguntas não é critério para negativo (Ainda bem que a minha esposa não me dá votos negativos) kkkkkk
Comment: http://olhardigital.uol.com.br/noticia/ps4-produzido-no-brasil-ja-esta-a-venda-por-r-2-6-mil/51846
Comment: Critério do SOpt não é, mas pode ser critério de alguém.
Comment: Ps4 foi uma piada... Você tem bom humor
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/29817/discussion-between-wallace-maxters-and-deesouza).
Comment: Então quer dizer que o angular já faz isso? valeu pela dica, só fui atinar agora
Answer: Amigo, o melhor a ser fazer é automatizar o processo de pre-compilação, caso queira saber como faze-lo usando o Grunt, você pode ler mais a respeito neste link;
você também pode pegar o recuperar o script do script acessando a propriedade source através da propriedade source, por exemplo, se fizer isto:
console.log(_.template($('#tpl-template').html()).source)

você possivelmente terá a seguinte saida:
function(obj){
    var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
    with(obj||{}){
        __p+='    Meu nome é '+
            ((__t=( nome ))==null?'':__t)+
            '\n';
    }
    return __p;
}

então basicamente você apenas precisaria ter o seguinte codigo em um arquivo JS separado:
var templates = {};
templates.meuNome = function(obj){
    var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
    with(obj||{}){
        __p+='    Meu nome é '+
            ((__t=( nome ))==null?'':__t)+
            '\n';
    }
    return __p;
}

no seu script principal, você apenas teria de usar o templates.meuNome({nome: 'Wallace'}), sem a necessidade de ter a tag script#tpl-template na pagina.
por fim um pequeno exemplo com um utilitario para gerar os Scripts:

var textTemplate = document.getElementById("textTemplate");
var textPreCompiled = document.getElementById("textPreCompiled");
var txtNomeTemplate = document.getElementById("txtNomeTemplate");
var btPrecompilar = document.getElementById("btPrecompilar");

btPrecompilar.addEventListener("click", function (event) {
    var tmplSource = textTemplate.value;
    var template = _.template(tmplSource);

    textPreCompiled.value = "var " + txtNomeTemplate.value + " = " + template.source;
});
textarea {
    width: 100%;
    height: 240px;
}

<textarea id="textTemplate">
  Meu nome é <%= nome %>
</textarea>

  Nome template:
  <input id="txtNomeTemplate" type="text" value="tplTemplate" />

<input id="btPrecompilar" type="button" value="PreCompilar Template" />
<textarea id="textPreCompiled">

</textarea>


question about convergence of random variables

Question: $X_n,X$ are square integrable random variables.We have $$\lim_{n\to\infty}\mathbb E|X_n-X|^2=0$$
The question is can we get
$$\lim_{n\to\infty}\mathbb EX_n^2=\mathbb EX^2$$
I use the Schwarz inequality, but I can't use the dominated convergence theorem because there is no function dominating $|X_n+X|$.(they are not necessarily bounded).
Answer: You don't need the dominated convergence theorem. You just need to know that $\|X\|_2 = \sqrt{E[X^2]}$ is a (semi)norm in the space of square-integrable random variables. More specifically, the reversed triangle inequality holds:
$$|\thinspace \|X_n\|_2 - \|X\|_2\thinspace| \le \| X_n - X\|_2$$
The assertion now follows from observing that the maps $x \mapsto x^2$ and $x \mapsto \sqrt{x}$ are continuous.
Comment: Excuse me , but I have a new question that can't avoid DCT : Does convergence in $L^2$ ($\mathbb E|X_n-X|^2\to 0$) imply square convergence in $L^1$ ($\mathbb E|X_n^2-X^2|\to 0$) ?
Comment: Yes, apply the Cauchy-Schwarz-inequality to $|X_n^2 - X^2| = |X_n - X| \cdot |X_n + X|$.
Comment: but $\mathbb E|X_n+X|^2$ is not bounded by a constant $C$ , it is merely finite for each $n$
Comment: No, it is actually bounded.
Comment: Oh,I got an idea, since $\mathbb E|X_n+X|^2\le 2\mathbb E|X_n^2|+2\mathbb E|X|^2$, the former is bounded because it converges to the latter.right?
Comment: That is correct.


How to check if the bowler is throwing instead of bowling in cricket?

Question: How to check if the bowler is throwing instead of bowling in cricket? Is there any technology for checking throw bowling in cricket?
Comment: Do you mean during a match, or during separate testing?
Comment: During a match and also in player debut .
Answer: If we say the bowler is literally throwing the ball for example like this:

Source: ESPNCrickinfo
then the umpire shall declare it as a No-ball imminently.
If we say the bowler bowls throw balls in bowling action. That means he is running and performing the same action as bowling like this:

Source: Wikipedia

but not bowling properly (i.e. still throwing the ball), then if umpires catch such action during the match (that is totally up to them) they can call it a no-ball immediately. However, even if they don't catch such illegal bowling actions, the report for the illegal bowling actions is generated by match officials. If any illegal action found they submit the report the the relevant team manager. And process further. You can check the full procedure on Illegal Bowling Actions PDF.
Comment: This doesn't appear to answer the question, which is how can you tell the difference, at all.
Answer: Throwing in Cricket

A ball is fairly delivered in respect of the arm if, once the bowler's arm has reached the level of the shoulder in the delivery swing, the elbow joint is not straightened partially or completely from that point until the ball has left the hand. This definition shall not debar a bowler from flexing or rotating the wrist in the delivery swing.

Bowling Action

A guideline was introduced to allow extensions or hyperextensions of angles up to 15 degrees before deeming the ball illegally thrown.

What Happens Next?
A bowler will be wired up with number of sensors, and Biomechanics experts -  Human Movement Specialists monitor the action.
Update
Quoting ESPNCricinfo

If the arm is bent at the onset of the delivery stride but remains rigid or does not flex or extend beyond the permissible 15 degrees during the duration of the stride, the action is not illegal. An action is only illegal if the arm flexes or extends beyond the permissible limit while in the delivery stride.
Comment: The guidline only applies in cricket played under the ICC regulations or those where the governing body allows it.  The law does not allow the extension of any amount.


How do you find the length of an arc given arc measure?

Question: So I have a circle with a diameter of 160,000 miles, with three points on it that form a perfect 90 degree angle. How are you supposed to find the length of an arc based on it's angle measure M and if needed, the diameter d?
Also I was interested because I have seen a few problems that require you to know how to do this and I was only able to get the arc measure from them so far. I don't know if there is a general formula for it or something but I would like to know how to do this.
Comment: I suggested including an illustration so that the angle in question is unambiguous.
Answer: There's a very simple formula for this: the length of an arc with angle measure $\theta$ and radius $r$ is
$$\theta r$$
For this formula to work, $\theta$ must be measured in radians.
To convert degrees to radians, multiply the angle by $\frac{\pi}{180}$.
So in your example:

90 degrees is $90 \cdot \frac{\pi}{180} = \frac{\pi}{2}$ radians.
The radius is half the diameter, or $\frac{160,000}{2} = 80,000$ miles.
Therefore, the length of the arc is
$$
\theta r = \frac{\pi}{2} \cdot 80,000 = 40,000 \pi.
$$


Error adding one content type. Bundle missing in term references

Question: I've got a problem on a Drupal 7.14 site when trying to add a new node to only one content type.
I get the following error message in the log:
<code>EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7389 of /homepages/33/d169792374/htdocs/sites/yourfutureinautomotive.com/includes/common.inc).
</code>
I've tried the fixes outlined here as well as removing modules one by one and I'm not getting anywhere.
I've even reverted back to 7.8 to make sure I was on the same version as other people who were having the issue.
I'm open to any ideas or troubleshooting hints.
Ta
EDIT
As per @mojzis suggestion below I used the Devel dpm function. The following was output:

EDIT 2
vid: 14 is the problem. There is no vocab with vid of 14. Trying to hunt down a reference to it anywhere but not having much luck.
Comment: try adding dpm($entity) before the exception to see which one it was, and whether it has a vocabulary_machine_name set.
Comment: Are you creating the node programmatically? Could you post your code?
Comment: No this is all through the admin.
Comment: @mojzis - I've tried this, it's giving me a vocab machine name of null.
Comment: it looks weird altogether :) there is no tid ? And BTW, the vid should refer to some term, not taxonomy.  So, to recap the situation:  you have a  field which is setu[ as a term reference, right ? And what are the settings there ? Which vocab is selected ?  Is there any default value set ? What value do you provide when saving ? Does this happen when you set some value or when you set no value ?
Comment: Strangely enough, I added a vocab called Nothing with a VID of 14 and can now add content again which is really odd and not much help in terms of troubleshooting this but it seems to have worked.
Comment: sorry, vid does refer to vocabulary, you are right ... then i would think that there is a mistake in the settings of your field, did you check it ?
Comment: Yeah I've had a good look. The thing with it being a vid that doesn't exist is that it's hard to narrow down which field is misbehaving. I was hoping the terms that were being added would give me a club but nothing yet. For now I'll settle with the old "Working is better than perfect" mantra and try and come back to it later.
Answer: Your issue is most likely related to the Media module, and specifically this issue: 'Missing bundle property on entity of type file error'. In your troubleshooting efforts, did you run across this info? A quick check to confirm if this is the culprit is to follow the step(s) outlined in comment #5.
Answer: OK I'm going to answer this with that's solved the issue for me.
I got a bit desperate and was trying to hack common.inc in the core (may god have mercy on my soul), but after checking things out using the wonderful Devel module I just added in a test taxonomy vocabulary with a VID of 14. I can now add content again which is good, but am none the wiser as to the actual cause of the problem.
Interestingly the vocab as terms added to it when I add a new content of the type that was giving me trouble but they're blank. When I get a bit more time I'll try and troubleshoot this properly but if anyone else has the same issue, this is what solved it for me.
Comment: so, once you have some time :) try running dpm(field_info_fields()); in devel/php . the fields that are of interest to you have ['type'] = 'taxonomy_term_reference' and you should check their ['settings']['allowed_values'][0]['vocabulary'] - that holds the machine name of the vocabulary ... how it translates to a non-existent id is really interesting :)