How is the field goal distance calculated in American football?

Question: I wonder how the position is calculated in American football:

The position that the snapper snaps
The position in that the holder fixes the ball and the kicker kicks.

For example, in the record breaking 66-yard field goal of Justin Tucker on Week 3 of 2021 season between the Baltimore Ravens and Detroit Lions,
The previous play was stopped at DET 48.
When I see the video, the snapper snapped at DET 50 instead of DET 48.
Why did they withdrew two yards, and why is the kick 'just' six yards behind the snap, not five or seven lines?
Last play before the kick

The snap

The kick

Play-by-play record: https://www.espn.com/nfl/playbyplay/_/gameId/401326366
Video:
Comment: Does this answer your question? [What determines the spot of a field goal kick in the NFL?](https://sports.stackexchange.com/questions/17756/what-determines-the-spot-of-a-field-goal-kick-in-the-nfl)
Answer:
The previous play was stopped at DET 48. When I see the video, the snapper snapped at DET 50 instead of DET 48.

Not that I can see.  The angle is different, so it's difficult to tell.  But you can see that the player on the left end of the line (on the right side of the frame) has his foot on the 50.  The ends of the line will be well back from the snap position, so it looks to me like the ball is made ready somewhere near the 48, but definitely closer than the 50.
In the low-angle replay, it's hard to see the actual distance, but the ball is well beyond the hash mark on the 50.  And the yard line marking the 49 to the rear is closer than the ball.  So 2 yards forward of the 50 seems plausible.

That would make the kick from the Baltimore 44 to be 8 yards behind the line of scrimmage, which is common.
There's an answered question about why the distance is 8 yards.


Meaning of this exercise in group theory

Question: This question is from Dummit and Foote:

Let $R$ be the set of all polynomials with integer coefficients in the independent variables $x_1, x_2, x_3, x_4$, i.e., the members of $R$ are finite sums of elements of the form $ax_1^{r_1}x_2^{r_2}x_3^{r_3}x_4^{r_4}$,
  where $a$ is any integer and $r_1,.. .,r_4$ are non negative integers.
  Each $\sigma\in S_4$ gives a permutation of $\{x_1,..., x_4\}$ by defining
  $\sigma\cdot x_i=x_{\sigma(i)}$. This may be extended to a map from $R$ to $R$ by defining $\sigma\cdot p(x_1,\dots,x_4)=p(x_{\sigma(1)},\dots,x_{\sigma(4)})$ for all $p(x_1,\dots,x_4)\in R$.
  Exhibit all permutations in $S_4$ that stabilize the element $x_1+x_2$.

I don't understand what does last line mean. (I do know what 'stabilize' means in context 'action'.)
Comment: Where is the problem? The equation $\sigma\cdot p(x_1,\dots,x_4)=p(x_{\sigma(1)},\dots,x_{\sigma(4)})$ defines an action of $S_4$ on $R$.
Answer: You have a natural action of $S_{4}$ on $R = \mathbb{Z}[x_{1},x_{2},x_{3},x_{4}]$, where your permutations permute the indeterminates of your polynomial ring.  Some polynomials will be fixed/stabilized by certain permutations of the variables, meaning a polynomial $p$ and a permutation $\varphi$ satisfy $\varphi(p) = p$. It is asking you to find the permutations $\varphi \in S_{4}$ such that $\varphi(x_{1}+x_{2}) = x_{1}+x_{2}$.
Answer: You are looking for $\sigma\in S_4$ such that $\sigma.(x_1+x_2)=x_1+x_2$. For example, this holds when $\sigma=(12)$ since $(12).(x_1+x_2)=x_2+x_1=x_1+x_2$.
Answer: "$\sigma$ stabilizes $x_1+x_2$'' means that $\sigma\cdot (x_1+x_2)=x_1+x_2$.
Answer: The order of the stabilizer is known to be the order of the group divided by the order of the orbit.  The order of the orbit of $x_1+x_2$ is $6$, as it can go to any $x_i+x_j$ with $i\not = j$ (but $x_i+x_j=x_j+x_i$)...
Thus the stabilizer has order $4$.

 We get that it equals $\{(12),(34),(12)(34),e\}$.
Comment: The asker didn't request a complete solution to the exercise, but was trying to understand what it meant.


Feature Selection in Multivariate Linear Regression

Question: I have $m$ time series and I partition the time series into two sets: set X and set Y. I want to predict set Y using set X. The time series of set Y are ${\bf y}_t$ and those of the set X are ${\bf x}_t$. The value of $m$ can be large (greater than 100).
To do this I fit a multivariate linear regression model:
$$ {\bf y}_t= \bf a+P {\bf x}_t + \epsilon$$
I can then compute some fitting error (using some method).
I want to know if there exists a way to determine the best way to select the variables that constitute the set X (${\bf x}_t$). I want to select only a subset of around 20 variables that can predict the best the other variables using a multivariate linear regression model. We want to select 20 variables to constitute the set X in order to minimize the fitting error.
A reference of existing papers on this would help greatly.
Thanks!
Answer: A "Hard" Problem
There does not exist a "best way" to select the variables in your model. If you have $p$ possible covariates, you get $2^p$ possible models without any interactions or functions of those inputs or lags.
In general, model selection aka feature selection is an unsolved problem and there is evidence that it is an NP-hard problem. (It is especially difficult if you are working with financial time series due to market efficiency.)
We do often use a few heuristic tools, but they are... imperfect at best.
Theory
We always consider theoretical reasons for a variable or function of variables to be in a model. That often yields the greatest insight; however, that requires knowledge of the problem being modeled. We may even keep that variable or function of variables in the model despite it seeming to be insignificant -- just as a control (aka nuisance parameter) since we expect it should matter.
Forward/Backward Selection
We can try forward and backward selection: adding covariates from a base model or subtracting them from a huge model. This is very common but can lead to some problems. This especially runs into difficulty if you do not have complete data for all covariates. In that case, your model will be fit on different datasets depending on what is the maximal dataset with data for all the covariates in the model. (So, add a covariate with only data from the last year and suddenly your model is estimated only on data from the last year.)
Penalized Regressions
We can also look at which coefficients grow fastest as we relax the penalty in a regression which penalizes coefficients. These regressions (typically the LASSO and ridge regression) are biased to try to have a smaller model. However, even this is not guaranteed to be useful.
SVMs and Other ML Techniques
You may hear about people using support vector machines or other ML methods at the problem; however, these have even more flexibility and so can easily lead to overfitting and thus poor feature selection. Basically: if we don't know which covariates to put into a model, adding more parameters or ways to put those into the model doesn't make our task easier. Some industries are now realizing this and have reduced their expectations of ML techniques.
Combining Variables
We could combine variables as done by PCA or ICA; however, neither of those considers the response we are trying to model. There is no guarantee using these will lead to a better model.
Still An Art
The honest truth is this: model selection (aka feature selection) is still very much an art -- and we have little reason to believe this will change soon. Get to know your problem domain well and get to know your data well. That will likely pay off greater dividends than learning some new method.
Answer: I recommend you take a look to chapter 3 of Elements of statistical learning book.
There you can see different ways of selecting a subset of your variables, methods that penalize the coefficients for each variable, some of them performing subset selection like LASSO, or methods that use linear combinations of your variables in order to use a reduced number of transformed variables.
It also treats the case of multiple outcome case, as I think it may be in your case.
Comment: Feature selection is a bad idea in general because of its volatility.   And it is mistake to say that it "minimizes the fitting error".  Consider ridge regression, elastic net, or better, data reduction (unsupervised learning) as a first step.


mdadm RAID5 RAID6 how to check consistency on running array

Question: On mdadm softraid 6 (about 12 disks, 60TB) there appeared accidental misswrites in large files (>100GB). All system was checked - RAM, NIC, LSI RAID card. The most suspected is the LSI because its battery BBU is flat and write back / write through is not correctly set.
In theory each chunk of data is backed up with XOR redundancy, RAID5 1x, RAID 6 2x. But this comes in act only if some of active disks fails.
In the mdadm is there a command which could start the complete data consistency check taking in account the XOR backup? It means can I identify the miswritten chunks?
After I discarded the BBU I want to know, which files are good and which files are corrupted and have to be replaced. If there is no way to solve it, I should have to create the array from the scratch and get all the files from their backup.
Answer: Run (replace md125 with your actual array):
echo "check" > /sys/block/md125/md/sync_action

It will read all the drives, compute parity stripes and check if they're correct. For RAID6 it will also correct a single-mismatch errors (when just one drive is went out of sync) by using all the rest drives, thanks to dual parity which enables detection of dual errors and correction of single errors, include those could have happened due to the disk bit error rate. This is important for modern very large disks.
It'll report any important messages to kernel log readable via dmesg. You can monitor status via /proc/mdstat file or mdadm --detail /dev/md125.
It is very useful to run the check periodically as it not only will correct misswrites, but also detect and kick out of array dying devices early, so better set up this check to be invoked via system scheduler (cron or systemd timers). Some Linux distros (e.g. Debian) do this by default.
While first parity syndrome is really simply XOR, the second one is not. A second syndrome is calculated using quite sophisticated mathematics called Galois field. Linux software RAID uses a field that enables RAID6 with no more than 257 active devices (not counting hot spares). This calculation is quite intensive for the CPU, so it's better to run this check when your system doesn't have much load. You can also limit its load by limiting the check rate by setting /sys/block/md125/md/sync_speed_max with some arbitrary value (200000, meaning 200 MB/sec is the default). The Linux also tests and reports optimal algorithm for RAID redundancy syndrome calculation for your system on boot, so you can check which one it will use and how fast it'll perform by reading boot logs.
You can also interrupt the running check by sending idle:
echo "idle" > /sys/block/md125/md/sync_action


Assign a workflow to a content type

Question: I had defined a new workflow which has 3 states and I want to assign it to a content type. I had tried to make a workflow file type in manage field but when I try to edit it I can not choose my workflow type.

I only can select "-Select a value-" but my workflow type defined don´t appear.
Thank you in advanced.
Answer: First, I have to make a configuration in "transition" tab (in the same place where I have defined states for my workflow). After that I can choose it.

Assign a workflow to a content type


Existence of splitting field

Question: Consider this theorem on existence of splitting field;
Let $F$ be a field and let $f(x)$ be a non-constant element of $F[x].$ Then there exists a splitting field $E$ for $f(x)$ over $F$.
In proving this theorem we use induction step on deg of $f(x)$ . If deg$f(x)$=1, then $f(x)$ is linear. so how when $f(x)$ is linear this theorem is true.
Answer: Hint: Prove that if $f\in F[x]$ is linear, then the splitting field of $f$ is $F$ itself.
Comment: (Actually, depending on the formalism you're using, this may literally be built into the definition. But in any case the statement is true under any reasonable definitions, so you should figure out why.)

Existence of splitting field


I have a tkinter table with Enter(), how can I convert it to Table()

Question: week = [[0, 1, 2, 3, 4, 5, 6, 7, 8],
        [0, 1, 2, 3, 4, 5, 6, 7, 8],
        [0, 1, 2, 3, 4, 5, 6, 7, 8],
        [0, 1, 2, 3, 4, 5, 6, 7, 8],
        [0, 1, 2, 3, 4, 5, 6, 7, 8]]

for course in self.courses:
    for i in range(course.start_time - 9, course.end_time - 9):
        self.e = Entry(root, width=20, fg='#181a1f',font=('Arial', 12))
        self.e.grid(row=i, column=Schedule.days.index(course.day))
        self.e.insert(END, course.name)
        week[Schedule.days.index(course.day)].remove(i)

for i in range(5):
    for hour in week[i]:
        self.e = Entry(root, width=20, fg='#181a1f', font=('Arial', 12))
        self.e.grid(row=hour, column=i)
        self.e.insert(END, "")
root = Tk()
schedule.print_table(root)
root.mainloop()

The code works fine, I've made a weekly schedule. But all cells are changeable I suppose thats because of Entry(). I tried using state="readonly" but then the cells disappeared.
And my second question is how can I add a empty first row and column, I want to write the days to the top of each column, and hours to left.
For that I tried adding 1 to row and column indexes, but weird things happened.
Answer: You can use a Label instead of Entry to make it readonly
To add empty rows/columns, you can create Labels/Entries with empty text and then increment the indices for the non-empty cells


Tkinter and win32api, while True crashes app

Question: im working with tkinter and win32api. I've declared the next function:
def on_press():
        leftBtn = 0x01
        key = win32api.GetKeyState(leftBtn)
        if key < 0:
                print("Left click pressed")
                time.sleep(0.1)
                root.after(100,on_press)

root.after(100,on_press)

Already tried to do the .after to don't have two infinite loops but still crashing. Any answer??
Git to my project (not finished...): https://github.com/alexcibubins/NoRecoilScript-notFinished-.git
Comment: Remove the `while True` loop. Also you might want to take a look at [this](https://stackoverflow.com/a/459131/11106801)
Comment: Move the `root.after(100,on_press)` one level down. Right now it only runs if the left mouse button is pressed.
Answer: def on_press():
        leftBtn = 0x01
        key = win32api.GetKeyState(leftBtn)
        if key < 0:
                print("Left click pressed")
                time.sleep(0.1)
        root.after(100, on_press)

root.after(100,on_press)


Commerce product programatically with price

Question: How do I get the correct price in the site's default currency to work like the the add product form does?
This function gives a product with a price of $0.01 I want $1.00.
I am sure this has to do with calculated price?
function generate_products () {

    $product_type = 'product';

    $values = array (
        'price' => 1.00 ,
        'currency_code' => commerce_default_currency() ,
    );

    $extras = array(
        'status' => 1,
        'uid' => 1,
        'sku' => randomName ( 10 ),
        'title' => randomName ( 10 ),
    );

    commerce_installments_create_product ($product_type,$values,$extras);
}

function commerce_installments_create_product ( $product_type , $values , $extras ) {
    $form_state = array ();
    $form_state[ 'values' ] = $values;
    $form = array ();
    $form[ '#parents' ] = array ();

    // Generate a new product object
    $new_product = commerce_product_new ( $product_type );

    $new_product->status = $extras[ 'status' ];
    $new_product->uid = $extras[ 'uid' ];

    $new_product->sku = $extras[ 'sku' ];
    $new_product->title = $extras[ 'title' ];
    $new_product->created = $new_product->changed = time ();

    if ( ! empty( $values[ 'original_order' ] ) ) {
        // field_original_order[und][0][target_id]
        $order = array ( LANGUAGE_NONE => array ( 0 => array ( 'target_id' => $values[ 'original_order' ] ) ) );
        $form_state[ 'values' ][ 'field_original_order' ] = $order;
    }

    if ( ! empty( $values[ 'original_line_item' ] ) ) {
        // field_original_line_item[und][0][target_id]
        $line_item = array ( LANGUAGE_NONE => array ( 0 => array ( 'target_id' => $values[ 'original_line_item' ] ) ) );
        $form_state[ 'values' ][ 'field_original_line_item' ] = $line_item;
    }

    if ( ! empty( $values[ 'original_product' ] ) ) {
        $product = array ( LANGUAGE_NONE => array ( 0 => array ( 'target_id' => $values[ 'original_product' ] ) ) );
        $form_state[ 'values' ][ 'field_original_product' ] = $product;
    }

    //commerce_price[und][0][amount]
    $price = array ( LANGUAGE_NONE => array ( 0 => array (
        'amount' => $values[ 'price' ] ,
        'currency_code' => $values[ 'currency_code' ],
    ) ) );
    $form_state[ 'values' ][ 'commerce_price' ] = $price;

    // Notify field widgets to save their field data
    field_attach_submit ( 'commerce_product' , $new_product , $form , $form_state );

    commerce_product_save ( $new_product );
    return $new_product->product_id;
}

//function based on answer here How do I programmatically create an entity with its fields?
Answer: Prices are stocked as integer in database.
Try replacing 1.00 by 100 in your price array :
$values = array (
        'price' => 100 ,
        'currency_code' => commerce_default_currency() ,
    );

Cf : http://drupal.org/node/1124416
Comment: Thanks that makes perfect sense for the database, thanks for the link looks like a good read on this decision :)
Answer: The number that's stored in a commerce price field is the price * 100.
So $1.00 is 100, $10 is 1000, $7.50 is 750, etc.
You could do 'amount' => $values[ 'price' ] * 100 , in commerce_installments_create_product and that would correct it.


Quick, multi-OS, command line conversion of JPEG-2000 to JPEG

Question: I am working on a web script that handles image processing using ImageMagick. It takes relevant parameters, executes an ImageMagick command at the command line or shell depending on OS, and passes the raw image data back to the script. The language of the web script is obviously not pertinent.
Simple use cases include:
convert -resize 750 H:/221136.png - which just resizes the input image to 750 width and outputs the raw data to the console. More complex use cases involve rotating, resizing, cropping/panning, and drawing.
The script works great and is quite fast for PNG, GIF, and JPEG inputs, even at fairly large (4000x5000 resolutions). Unfortunately my input data also includes JPEG-2000. A 10-15 Megabyte JPEG2000 takes a truly insane amount of time for ImageMagick to process, in the order of 10-15 seconds. It is not suitable for live, on the fly conversion.
I know quick conversion of JPEG-2000 to JPEG for web output is possible, because a piece of Enterprise software I work with does it fairly on-the-fly. I'm not sure which library they use--the DLL/so they use is DL80JP2KLib.dll/.so. Looking it up, it seems that a company called DataLogic makes this, but they don't seem to have any obviously relevant programs on their site.
Ideally I'm looking for a solution (plug-in?) that would either enable ImageMagick to convert these high resolution JPEG-2000 images on-the-fly like it does with PNG, GIF, or JPEG... or a separate command utility that I can run in advance of ImageMagick to convert the JPEG-2000 to an intermediate format that ImageMagick can process quickly.
The servers that will run this script have 32 gigs of RAM and beefy processors. Assume that speed of conversion is more important than resource usage efficiency. Assume also that while I need some semblance of quality, image lossyness is not an urgent thing. Licensing requirements and/or price are not important, except that I need to be able to test it myself for speed on a few sample files before we buy. The ideal solution is also (relatively) OS independent
I tried an application from Kakadu Software and it's fairly quick, in the order of 3-4 seconds, but that's still not fast enough. If it's not possible to get below, say, one second, I will look at batch converting files in advance.
I have uploaded a representative file (JPEG-2000, ~8MB) to MediaFire:
http://www.mediafire.com/?yxv0j6vdwx0k996
Comment: I don't know it at all, but have you tried gimp scripting? A plugin exists at http://registry.gimp.org/node/16241
Comment: I haven't, but production version Gimp doesn't do JP2K by default and at first glance the GIMP JP2K plugin uses the Openjpeg library (http://code.google.com/p/openjpeg/). Openjpeg offer their own binary command line utility that has, frankly, pretty crummy performance for the use case of live conversion. Maybe 10-15 seconds per file again, and like Kakadu only outputs to intermediate formats like .raw or .bmp which will still need to be processed by ImageMagick.
Comment: I'm looking at this from a different prespective; while 10-15 seconds does seem like a long time, setting user expectations is a big part performance perception. Test a pop-up notification 'JPEG-2000 input takes longer to process, should complete in 10-15 seconds'; if you have sophisticated users, that may be all you need. Good luck!
Comment: @shellter The thing is, I don't really need to set user expectations. As I mentioned in my original question, I'm already using enterprise software that does JPEG-2000 on the fly for web serving. Using the exact source files that I'm trying to process myself, in fact. But because the enterprise software is compiled, doesn't take arbitrary inputs, and doesn't document the library it uses (like I mentioned, DL80JP2KLib.dll/.so) I can't do it through there.
Comment: Yes, I did read your question, and I did say 'here's a different prespective'. If that doesn't work for you, I understand. Good luck in your search.
Comment: This wall of text needs a TLDR
Answer: I found exact image to be much faster in the past.
http://www.exactcode.de/site/open_source/exactimage/
Mark Tyler (original author of mtPaint) once split out the excellent graphics handling parts into a separate library (mtpixel ...since abandoned as a separate project, but included in mtcelledit @ its Google code home)


Jquery onclick doesn't do anything

Question: While I'm certain that the answer must be incredibly simple and obvious, I can't for the life of me figure it out. Please forgive this newbie.
I have the following code in a js file:
$("#news-updates").onclick = function () {
    $("#news-content").toggle();
    $("#instruction").toggle();
}

The purpose of the code is to hide one object (instruction) and show another (news-content), then to do the opposite the next time it's clicked. Here's the HTML:

News & Updates

Tap here to open

Lorem ipsum

And in case it's somehow relevant, the CSS:
#news-updates {
    margin-top: 20px;
    display: inline-block;
    border: 2px solid #ECECEC;
    float: right;
    width: 88%;
    margin-left: 5%;
    margin-right: 5%;
    h2 {
        text-align: center;
        font-size: 20px;
    }
    #instruction {
        text-align: center;
        display: block;
    }
    #news-content {
        display: none;
    }
}

When I click the section, nothing happens. The mouse doesn't even change. Please, how do I make this work?
Comment: where is instruction?
Comment: Oops, I forgot to update the rest of the question when I changed it... It wasn't the problem though.
Answer: Should be
$(window).load(function() {
    $("#news-updates").click(function () {
        $("#news-content").toggle();
        $("#instruction").toggle();
    })
});

Direct assigning, as you did, is for pure javascript, while you are using jQuery. Also function should be assigned when DOM is loaded, so I am adding onload method.
Answer: Correct instance for use jquery is
$(document).ready(function(){
 $("#news-updates").click(function () {
     $("#news-content").toggle();
     $("#instruction").toggle();
 });
});

Answer: onclick is not a jquery function. You are adding a new function called onclick to the jQuery object.  You should be doing something like this:
$("#news-updates").on('click', function () {
  $("#news-content").toggle();
  $("#instruction").toggle();
});

Jquery onclick doesn't do anything


rake assets:precompile not working on production

Question: All of the sudden my server is not able to run assets precompile
RAILS_ENV=production rake assets:precompile

The error I am getting when running the command with trace is
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in    `block in create_shell_runner'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `ruby'
/var/www/website/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/var/www/website/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/var/www/website/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/website/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `'
/usr/local/rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `'
Tasks: TOP => assets:precompile

thanks for any help.
Comment: try bundle update and once again precomplile
Comment: thanks, let me try that once on production and ll let u know..
Answer: Try this
touch tmp/restart.txt


Demand prediction multiple target variables

Question: I am working on prediction of porduct demand. I have dataset of transactions for many customers for a whole 2017 year. Problem is that I have lot of porducts with different quantities and packages in dataset and I am not sure what kind of model should I use. Data are timestamped on daily basis. My data looks like this

My target variables are ProductID, items_per_pack, Packaging, volume and quantity. Houw could I predict these five at once? My aim is to be able predict my demand for few days ahead and I want it to be for each product qty of diferrent packaging, volume and packaging.
For example prediction for 01/01/2018:
Product   Qty   Items_per_pack   Packaging   Volume
   A       2         6               12        500
   A       3         4               10       1500
   A       2         8               12       3000
   B       2         6               12        500
   B       3         4               10       1500
   C       2         8               12       3000

There is a lot of combinations for each product since I have many categories for each target variable. Thank you a lot for the answers.
Answer:
How could I predict these five at once?

You could use hierarchical time series forecasting. This approach is used when forecasting grouped or related time series (for example closely related products, or the same products in different geographical locations).
(If I understand your data correctly) In your case specifically you can use the following approach: have a separate time series for each item/pack size and then roll them up into a total demand per item series.
Answer: Aah, that is a classic in applied machine learning: You have many different "things" you want to predict and you are tempted to create a different model for every of them. However, you will run into big trouble when doing so: First of all you have to maintain a lot of models and if you have many models you cannot do that. Also philosophically, this would be wrong because each model would have only very little data and it would be much harder to detect a "general" pattern in the data (that is common among all "things"). But worry no more, friend, (at least IMHO) there is a general solution to deal with this problem.
What I usually do is to introduce features 'with respect to that current thing but normalised over all products' to make this common pattern available to the model. Furthermore you are confronted with a time series problem but let us ignore that for a moment and deal with that below.
Let us further assume that you just want to predict how many products you need on the current day (no fancy stuff with packages, etc to keep it simple for this answer).
Example for such a feature as mentioned above: Price. Let us say that you just use one single feature: Price. One "common pattern among all products" could be "if the price is high then people will not buy the product". However, price itself is hard to interpret because how should the model know whether the price is "high" or "low" at the moment? Let us say that we compute the average price $p_w$ for each product $w$ and then on the new dataset you create a feature "price_diff" that is "price on the current day for product $w$ - $p_w$". If that feature has a value of $100$ then the model knows that the product is 100 units more expensive than "usual" and hence, it is pretty expensive. If, on the contrary, this feature contains the value $-10$ then the model knows that the product is cheaper than usual.
Now that we have this feature "w.r.t. that product" the model must be enabled to do a "fair comparison". That is why you normalise this feature. In that case, $100$ can be "a lot more" if the product usually costs $1000$ and it could mean "just a tiny bit more" if the product usually costs $100.000.000$. Hence, I suggest you normalise and craft a feature that states how much (in %) the price is higher/lower than the average. In the first case, the feature would contain $10$% and in the second it would contain ... well, I'm bad at math... is it $1/10000$ ? I think so... well, you get the pattern ;-)
Now let's deal with the time series part. At the very first stage, time series analysis on some dataset $y_0, y_1, y_2, ...$ is nothing else than "take any regression model and feed it a training set with lagged target variables". I.e. let's say you want the model to be able to look at the last $3$ time points then you feed it the training set
feature_1 feature_2  feature_3   target variable
      y_0       y_1        y_2               y_3
      y_1       y_2        y_3               y_4
      y_2       y_3        y_4               y_5
      ...

Combining these things for your example means: Take one single regression model (for example, gradient boosting) and feed it cleverly crafted features that are generated "with respect to the current product", normalised and lagged. I.e. how much did the current product cost yesterday, the day before yesterday, etc. How much more (in%) does it cost today than average, how much (in%) did it cost more/less than average yesterday, ... and the most important: How was the demand of that product yesterday, the day before yesterday, over the last week, over the same day of week in the last week, ...... there is an endless pool of possibilities here.
Also note that this lagged stuff does not necessarily relate to the product itself but rather to products that "share" many properties. I.e. if the current product is a western movie then I would not only feed the model the features modelling the development of the price of this particular western movie but rather the average price over all western movies (and the %ish deviations on the last days, etc).
In short: Start just with two variables: price and demand and create these lagged, normalised features from them and then let a first regression model run and see how it performs.


Regex formula for string to extract one of two kinds of values

Question: I have values that have single values and concatenated values interspersed. I need to create a regular expression that will evaluate the values and return either the whole number that has no "|" or the first of a group of numbers that are separated by "|" characters.
Example
Existing values
12345667D23
3t23456
ab57890
3t23456|ab57890
12345667D23|3t23456|ab57890

Transformed values (return either the single value as same or the first of the string up to the "|")
12345667D23
3t23456
ab57890
3t23456
12345667D23

I am new to regex. I don't have enough experience here... I am not trying to match a string, just return the values (could be numerical, could be alphanumerical, there is not a set string length, just delimited by pipes)
Comment: You could do a replace all `\|.*` with blank https://regex101.com/r/8sax7c/1. Or create a new string based on matches `(?m)^[^|\r\n]*` https://regex101.com/r/24opi6/1 Which one sounds good ?
Comment: Just a fyi. I see your statement that your new to regex. I don't recommend you say that as some will hold up on the hard answers that will show you a complete response, complexities and all. It's better to bite the bullet and take harshness then be in the dark. Your comment below about a white space or trim white space or disqualify elements because of white space can result in several solutions. I suggest you state your problem with all the gory details thrown in when the question is first created. Or quickly revise the question as discovery unveils.
Answer: Try this:
^[^\|]+

Here, ^ matches the start of a line, [^\|]+ matches a series of characters that aren't pipe (|). So the whole expression matches a sequence of characters from the start of a line until | or the end of the line.
Comment: Thank you so much! This worked great on one file but on the other there is apparently an extra space before the "|"... Is there an elegant way to remove that space?
Comment: I think i figured it out... First I use  ^[^\s]+ as the first rule to classify values that contain a white space, then your original answer as a second rule to classify values that do not contain the white space... it seems to be working.
Comment: If I understand your formatting correctly, you can also try `^[^\s?\|]+`. `\s?` allows for a single space to exist/not exist (match zero or one instance)


Doubly exponential generating function

Question: Miklos Bona, Introduction to Enumerative Combinatorics, Rudin, 2007, Section 3.5 , page 173 gives the definition and one example of a doubly exponential generating function.  The author states in the introduction to this section that these are used "in one of the later chapters".  Does anyone know exactly where else in this book these functions are discussed.  Does anyone have any other references that I could find on-line to give myself an introduction to this type of generating function.
Comment: Did you try the index?
Comment: @J.G.: It has only a reference to p. 173, and I do not recall seeing any other use of them in the book.
Answer: The particular example in Bona is the
OEIS sequence A061573. See OEIS sequence A000275
for another example which is
$$ 1/J_0(\sqrt{4x}) = \sum_{n=0}^\infty a_n \frac{x^n}{n!^2}. $$
There are other examples in the OEIS. In general, when you have a
Hypergeometric function
 power series there can be $\,n!^2\,$
in the denominator of the terms. For example,
$$ {}_2F_1(a,b;1;x) = \sum_{n=0}^\infty \frac{(a)_n(b)_n}
{n!^2}x^n. $$
Comment: I do not have a copy of Bona. He may have been mistaken in his statement. You can find discussions on Doubly-Exponential g.f. by doing a web search. For example, the book by Stanley, _Enumerative Combinatorics_.
Comment: OK, Thank you!.  Do you know where in Bona this particular example is discussed?
Comment: OK, thanks.  I did find finally find it on page 487, section 9.3 , Magic Squares.

Doubly exponential generating function


Combinatorics Problem: Box Riddle

Question: A huge group of people live a bizarre box based existence. Every day, everyone changes the box that they're in, and every day they share their box with exactly one person, and never share a box with the same person twice.
One of the people of the boxes gets sick. The illness is spread by co-box-itation. What is the minimum number of people who are ill on day n?

Additional information (not originally included in problem):
Potentially relevant OEIS sequence: http://oeis.org/A007843
Comment: +1 for "co-box-itation" -- though since "cohabitation" involves sharing a habitat, it should perhaps be "coboxion" -- on the other hand, "box" is derived from Late Latin "buxis", so perhaps it should be "cobuxitation"...
Comment: If you two philologists have quite finished, I suggest "boximity" as the snappy solution.
Comment: I'd suggest an alternative statement (more simple and attractive for me) : A chess tournament has one match per day; each day, each player must play a game with a new opponent. New players can be added, but cannot be removed. What is the minimum number of players needed?
Comment: @joriki: We could take it back even further, to Hellenistic Greek πυχίς, and make it *copyxitation*. Especially if we were well and truly (co)pixilated.
Comment: @leonbloy: This is a good translation with a small rephrasing: A chess tournament has one match per day for each player; each day, each player must play a game with a new opponent. New players can be added, but cannot be removed. New players are added as few as possible (i.e., New players are added in such a way that preserves the total number of players as minimum as possible.) What is the number of players on day n?
Comment: @Brian: But then it should be *synpyxitation*, no? :-)
Comment: @joriki: Good point, but probably *sympyxitation*, with assimilation of the nasal to the bilabial articulation of the following stop. :-)
Comment: @Brian: Also a good point :-)
Comment: Are you sure about the {5,8} term?
Comment: Is there an answer? I suppose that if someone would have told me that this problem is somehow encodes some non-computable function, I wouldn't be surprised.
Comment: I'm not quite sure what you want anymore. I thought the question was: Suppose we fix a natural number $n$, the number of days, what is the minimal number of ill people at day $n$. In that case we would get the sequence (1,2,4,4,6,6,8,8,?). However, you seem to be looking at the minimum number of casualties at day $n$, given how many there were on all previous days. These two problems clearly don't coincide, per the examples that have been provided.

In the first case, I think it can be proven that the sequence you get will be (1,2,2,4,4,6,6,8,8,10,10,12,12...), but I don't see the proof yet.
Comment: What didn't fit in the previous comment anymore and since there doesn't seem to be a option to contact you outside this side: Nice problem! Would it be ok to maybe use the problem for a math camp once in a few years time?
Comment: @HSN Absolutely, feel free to use the problem as you wish. It is not mine, but I know the author would have no qualms with it being shared. As per my interpretation of the problem, it asks simply "What is the minimum number of people who are ill on day n?" To me, this means using any particular process of combinations to produce the "optimized" minimum for that particular n. I do not assert this to necessarily be the correct interpretation, though.
Comment: @AsafKaragila you can compute this function by merely bruteforcing all possible pairings and seeing which leads to the least number of infecteds. Of course this only works if there's a finite number of people. So clearly this problem will get more interesting if there's an infinite number ;)
Comment: @Pedro: Of course if we fix the number of people this is computable. But who cares about finite stuff? :-)
Comment: Context (and problem origin, as far as I know), if anyone is interested: http://forums.xkcd.com/viewtopic.php?f=3&t=99655#p3248808
Comment: @Lopsy Yeah, I know the people who posted it there. The origin is actually a biology teacher at a high school. I was given the problem by that very teacher about 4 years ago.
Answer: I used brute forcing, minimizing as possible, until day 20, then I was comfortable enough to try to make an educated guessing about the minimum number of patients on successive days. A pattern emerged quite evidently, and the number was exactly the sequence of oeis.org/A007843. First thing I have noticed, after having all the results of the first 20 days written down, is that whenever the minimum number of patients becomes a power of 2, it becomes clearly obvious how long the containment of illness, in the minimum case, is going to be valid: it is given as $\log_2 x$, where x is the minimum number of patients. So I have rewritten the minimum number of patients in terms of powers of 2 $ (2^0, 2^1, 2^2, 2^2+2^1, 2^3, 2^3+2^1, 2^3+2^2, 2^3+2^2+2^1, 2^4, 2^4+2^1, 2^4+2^2, 2^4+2^2+2^1, 2^4+2^3, 2^4+2^3+2^1, 2^4+2^3+2^2, 2^4+2^3+2^2+2^1, ...).$ Each item in this sequence represents the minimum number of patients at some point in time, in consecutive order. Note that, the exponent of the last term in each item exposes the number of days in which the illness is going to keep contained at the same level exhibited by the item's value, that is (1 patient at Day 0, 2 patients for 1 day, 4 patients for 2 days, 6 patients for 1 day, 8 patients for 3 days, 10 patients for 1 day, 12 patients for 2 days, ...). So the sequence of the successive days starting at Day 0 is (1, 2, 4, 4, 6, 8, 8, 8, 10, 12, 12, 14, 16, 16, 16, 16, 18, 20, 20, 22, 24, 24, 24, 26, 28, 28, 30, ...) as displayed at OEIS sequence. (I wanted to post this as a comment but it seems that I am not allowed to?)
Comment: I simply assumed an infinite population, since the statement of the problem didn't explicitly impose limits on the number of people, nor the number of boxes.
Comment: @Pedro At each stage you need only follow the infected persons and their new coboxitants. You may assume safely that these new persons have never coboxitated with any of the other finitely many people in focus, i.e. you can generate them as "new" people onyl as needed. The word "huge" in the problem description seems to allow the assumption of an infinite (or at least a sufficiently large) population.
Comment: How exactly did you brute force this? I ask because of the finiteness/infiniteness deal with the population. I originally though that if we took a large enough population $K$ and used it to compute $n$, with $K >> n$, then it wouldn't matter. But maybe it will, since the non-sick people who coboxitate with a non-sick person won't ever be able to coboxitate with that person again.. So a finite population would eventually stall to a point where one individual (or even all of them) has no possible pair left..
Answer: Just in case this helps someone:

(In each step we must cover a $N\times N$ board with $N$ non-self attacking rooks, diagonal forbidden).
This gives the sequence (I start numbering day 1 for N=2) : (2,4,4,6,8,8,8,10,12,12,14,16,16,16)
Updated:  a. Brief explanation: each column-row corresponds to a person; the numbered $n$ cells shows the pairings of sick people corresponding to day $n$ (day 1: pair {1,2}; day 2: pairs {1,4}, {2,3})
b. This, as most answers here, assumes that we are interested in a sequence of pairings that minimize the number of sick people for all $n$. But it can be argued that the question is not clear on this, and that might be interested in minimize the number of sick people for one fixed $n$.  In this case, the problem is simpler, see Daniel Martin's answer.
Answer: If we want to minimize the number of infected people only after a fixed number $n$ of days -- meaning we do not an answer that is a function of $n$ as $n$ tends to infinity -- then the answer depends on the parity of $n$: for odd $n$, the answer is $n + 1$, while for even $n$ the answer is $n + 2$.
First observe that there cannot be less then $n + 1$ infected individuals at day $n$ since the first infected guy has shared boxes with at least $n$ other indiviuals.
Let us now assume $n$ is odd. Take a set $V$ containing $n + 1$ citizens of the box world (one of them is the infected one). Take a complete graph on $V$. Decompose its edges into perfect matchings $M_1, \dots, M_{n}$. Each perfect matching $M_i$ tells you how the co-box-itation will be at day $i$. Assume people outside of $V$ share boxes only with people outside of $V$ during these $n$ days. This scheme makes everyone in $V$ sick at day $n$ while nobody outside of $V$ is sick at day $n$.
For $n$ days, with $n$ even, the proof that there can be as little as $n + 2$ infected individuals is similar to the previous paragraph.
The proof that there cannot be less than $n + 2$ infected individuals is as follows. We already know that, at the end of day $n - 1$, there are at least $n$ infected individuals (because $n - 1$ is odd). If there are precisely $n$, it is because they have shared boxes among themselves during these $n - 1$ days. Since they are not allowed repeat partners, on the $n$-th day, each has to share a box with a non infected individual, which leads to $2n$ infected individuals at the end of day $n$. If there are exactly $n + 1$ infected individuals at the end of day $n - 1$, then it is still possible that some of them share a box on day $n$, but $n$ is even, so one of these $n + 1$ individuals will be forced to share a box with a healthy person.
-- EDITED --
In fact, every complete graph of even order may be decomposed into perfect matchings (see Theorem 3.5 on page 20 of the book One-Factorizations by W. D. Wallis).
Comment: This is similar than my initial approach, but it's wrong. (for $n=5$ the right answer is 8).
Comment: How come the answer is not $6$ for $n = 5$? Suppose $1$ is sick. Setup the boxes as follows:
day $1$: $\{1, 6\}, \{2, 5\}, \{3, 4\}$
day $2$: $\{1, 2\}, \{3, 6\}, \{4, 5\}$
day $3$: $\{1, 4\}, \{2, 6\}, \{3, 5\}$
day $4$: $\{1, 3\}, \{2, 4\}, \{5, 6\}$
day $5$: $\{1, 5\}, \{2, 3\}, \{4, 6\}$
This way there are only $6$ infected individuals after $5$ days.
Comment: Yes, but you had 6 sick people by day 3 which is suboptimal (the mininum is 4). Which begs an interesting and important issue (what means to havea  mininum number of sick people _for each n_)
Comment: Of course, upon your understanding of the problem (that you rightly explain in your first paragraph) you are right. It's just that I don't think that the OP pointed to this - but I agree it's ambiguous.
Answer: Let $f(n)$ be the minimum number of ill people on day $n$ (sequence $1, 2, 4, 4, 6, 8, 8, 8,\ldots$ if we start with $n=0$), let $g(n)$ be the maximal number of days the illness can be kept $\le n$ (sequence $0, 1, 2, 2, 4, 4, 5, 5, 8, 8, \ldots$ if we start with $n=0$), so that $g(n)=\max \{k\mid f(k)\le n\}$ and $f(n)=\min\{k\mid g(k)\ge n\}$ holds.
We want to show for $n\ge 1$ that $g(n)=r(n)+1$ where
$$\tag1 r(n):=\left\lfloor\frac n2\right\rfloor+\left\lfloor\frac n4\right\rfloor+\left\lfloor\frac n8\right\rfloor+\ldots$$
is the exponent of $2$ in $n!$.
By inspection, we see that $g(n)=r(n)+1$ holds at least for $n\in\{1,2,3,\ldots,9\}$.
Lemma 0: $f(n)$ is even for $n>0$. If $n>1$ is odd then $g(n)=g(n-1)$.
Proof: Obviously, after patient $0$ being the only ill person inititally, the ill persons come in pairs as per the last box they were in. The statement about $g$ is dual to this.$_\square$
Lemma 1: $f(n+f(n))\le 2f(n)$ and $g(2n)\ge g(n)+n$.
Proof: Make sure that $f(n)$ people are ill on day $n$, enter $f(n)$ fresh people and let them cobox with the first $f(n)$ people in a circular manner fo the next $f(n)$ days. The statement about $g$ is dual to this.$_\square$
Corollary: $g(n)\ge r(n)+1$ for all $n\ge 1$. $f(n)\le \mathrm{A007843}(n)$.
Proof: Observe that $r(2n+1)=r(2n)=r(n)+n$ so that lemmas 0 and 1 make induction on $n$ work. The claim about $f$ is dual (using the description at OEIS).$_\square$
Lemma 2: $g(n)\le n$.
Proof: Just note that patient 0 cannot coboxitate with more than $n-1$ other people. $_\square$
Corollay: $g(n)=r(n)+1$ if $n$ is a power of $2$.

(to be continued)

Combinatorics Problem: Box Riddle


Read audio file from assets on Android

Question: I am trying to play audio files stored in the assets directory, but before I even read a file I get the error "error occured java.io.FileNotFoundException: track.mp3". Here's how I read it:
AssetFileDescriptor afd = getAssets().openFd("track.mp3");

I read a lot of descriptions on the internet, but no success.
Comment: You could also store it in the raw directory under res, that way you can load it easier into the media player, since you can provide a res id.
Comment: Unfortunately I need to play a large number of files, so I don't really want to track every single one of them in my resources.
Comment: For me it was case issue. File name was MP3 format in asset folder but I was using mp3 from code. By using exactly same name solve the issue.
Answer: I think this code should work for you:
AssetFileDescriptor afd = getAssets().openFd("track.mp3");

MediaPlayer player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.prepare();
player.start();

Otherwise, check if the file is in the right folder and the name is "track.mp3".
Comment: Well, as I said, before I even use MediaPlayer object, I get the FileNotFoundException. It is thrown after I open AssetFileDescriptor.
Comment: This is the code path I'm using but it doesn't work:  http://stackoverflow.com/questions/9124378/mp3-audio-in-the-android-assets-folder-fails-to-play-from-a-signed-and-zip-align
Answer: Right-click your "track.mp3" file, with the "Refactor" > "Move" command, move your file to another directory (e.g. "res"). With  this same command, move it back to your "assets" directory. For me, it works.
Answer: Android guidelines suggest for Audio use res/raw folder. So make sure that all audio are there and when you read you can use this method:
void playAudio(Context mContext, String sound){
    new AudioPlayer().play(mContext, mContext.getResources().getIdentifier(
            sound,"raw", mContext.getPackageName()));
}

And if you need something line audio player then take a look at MediaPlayer
Answer: Use this code
MediaPlayer mediaPlayer = new MediaPlayer();
            AssetFileDescriptor afd;
            try {
                afd = getAssets().openFd("1.mp3");
                mediaPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
                mediaPlayer.prepare();
                mediaPlayer.start();
            } catch (IOException e) {
                          Toast.makeText(LearnActivity.this, "Error Playing audio from Asset directory",Toast.LENGTH_SHORT).show();
            }

Otherwise, check if the file is in the right folder and the name is "track.mp3".
Comment: Code-only answers are low quality answers.

Read audio file from assets on Android


java.io.File cannot recognize "~" symbol of home dir?

Question: I tried this on mac:
touch ~/a.txt

And then java file:
import java.io.File;

public class testPwd {
    public static void main(String [] args) {
        File f = new File("~/a.txt");
        System.out.println(f.exists());
    }
}

It prints out "false".
Why is this? Does java recognize the "~" symbol? If I use absolute path, this f.exists() returns true.
Any explanations?
Comment: `Does java recognize the "~" symbol?` — As you have demonstrated, it does not. What else are you asking?
Comment: Yeah, you can't do that. Use `System.getProperty("user.home");` as demonstrated in this question https://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java to get the user's home directory.
Comment: That's a Unix convention; not sure if it's platform independent.
Answer:
Why is this?

Because the ~ symbol is only understood by the Unix shell (and, confusingly, it was used in HTTP servers). Even if you wrote the program in C, it wouldn't understand ~ to designate the home directory of the current user.
To get the user's home directory, use System.getProperty("user.home"). (Answer from What is the best way to find the users home directory in Java?)


Obtaining an isosurface from 3D data and the corresponding indices

Question: I have a 3D numpy array of temperature values on a grid. From this I can compute the gradients using dTdx, dTdy, dYdz = np.gradient(T). Now I'm only interested in the values of the gradients on the isosurface where the temperature is 900. What I want to do is something like (pseudo-codish):
import nympy as np
def regular(x,y,z,q=100,k=175,a=7.1e-5):
    R = np.sqrt(x**2+y**2+z**2)
    return 100 / (2*np.pi*k) * (1/R) * np.exp(-0.5/a*(R+x))
x = np.arange(-1.5,0.5+res/2,res)*1e-3
y = np.arange(-1.0,1.0+res/2,res)*1e-3
z = np.arange(0.0,0.5+res/2,res)*1e-3
Y,X,Z = np.meshgrid(y,x,z)
T = regular(X,Y,Z)
dTdx, dTdy, dYdz = np.gradient(T)

(xind,yind,zind) = <package>.get_contour_indices(X,Y,Z,T,value=900)
x_gradients_at_isosurface = dTdx[xind,yind,zind]
...

I've tried:
import numpy as np
from skimage import measure
contour_data = measure.find_contours(T[:,:,0],900)
contour_data = np.int_(np.round(contour_data[0]))
xs,ys = contour_data[:,0],contour_data[:,1]
gradients_of_interest = np.array([G[x,y,0] for x,y in zip( xs,ys )])

which works fine, but only works for 2D data. I'm looking for the 3D equivalent. I've found the following:
import plotly.graph_objects as go
surf = go.Isosurface(x=X.flatten(),y=Y.flatten(),z=Z.flatten(),value=T.flatten(),isomin=900,isomax=900)
fig = go.Figure(data=surf)
plt.show()

But I'm not interested in plotting it. I want to know the indices where the temperature is T=900 so I can use it on the gradients. Any ideas?
Answer: You need skimage.measure.marching_cubes.


Como utilizar uma página personalizada no wordpress?

Question: Estou criando um site no wordpress, tenho alguns modelos já prontos como: index.php, category.php, 404.php, single.php.
Criei uma página personalizada "blog.php" e direcionei um link para ela com:
<code>href="<?php echo esc_url( home_url( '/blog.php' ) ); ?>"
</code>
Isso me diz que a página não existe.
Comment: Eles são fora do wordpress? Se sim ele provavelmente está procurando esse arquivo `blog.php` na pasta raiz aonde está o index do wordpress
Comment: está na pasta do index.php sim
Comment: Com tão pouca informação não tem como saber de fato o que está acontecendo. Tentou acessar a rota direto pela url? seusite/blog.php ?
Comment: Estou montando a estrutura ainda, qual outra informação precisa? Sim já tentei, not found também.
Comment: Olá, Matheus, pode nos dar um pouco mais de informação sobre o contexto e o caso de uso? Estou presumindo que você está tentando criar um modelo personalizado para quando o visitante acessar www.exemplo.net/blog/ e 2) que esta página vai mostrar as últimas postagem. Estou certo?

E aproveitando, você já verificou o manual de desenvolvedor para [hierarquia de template](https://developer.wordpress.org/themes/basics/template-hierarchy/) e este [gráfico interativo](https://wphierarchy.com/) da hierarquia.?
Answer: Vamos lá, oque você deve fazer é criar um template de página:

Abra seu arquivo blog.php e na linha em seguida do <?php você adiciona:
/* Template name: Blog */

Feito isso,

Crie uma página no Wordpress > Página
Na opção de "Atributos da página" você define ela como seu template.

Exemplo final:

OBS: não esqueça de importar seu cabeçalho e seu footer.


Cleaning up AD and DNS on Windows SBS 2008

Question: I searched serverfault.com for duplicates of this question but couldn't find anything close enough for my needs, so here goes.
I'm administering a small Windows domain, where a Win SBS 2008 is the DC and a Win Server 03 acts as our print and file server.
Recently, we migrated our old DC (a SBS 03) to the SBS 08 we are using now, and also upgraded our computers, giving them different hostnames from the old ones we removed from the system.
Going through the SBS console, and AD Users and Computers snap-ins shows me that we have a lot of entries of computers that are no longer present at the organization, and additionally, that some of the old computers have DNS entries for their names that point to IP addresses of the new computers we are using, so you could ping "OldComp01" and it will actually answer back, even though the computer is actually "NewComp05".
How can I go about cleaning out the AD computer entries and DNS entries correctly?
Is it as simple as deleting the computers from the SBS console? If I do that, what happens to the DNS entries, do they simply dissapear (after a certain amount of time)?
Do I need to go into the DNS snap-in and manage from there as well?
Thanks in advance for reading this long question and any help or explanation! Also, if you have extra time and want to add in a little explanation as to why, that would be appreciated as I like to know what goes on under the hood, but am too new to have grasped everything I need to (might never be able to... who knows).
Thanks again,
Josh
Answer: Removing a computer from the domain doesn't remove its account, it disassociates the  machine from its AD Object(1). This tool might help you find them
Personally, I would simply move them all to a new OU, disable the lot of them, wait a week, then delete. (You can use AD Explorer to search for last access time and object class.. he he, just like other LDAP tools)
The DNS side is separate, and is created by the DHCP server dynamically, typically the entries will last a week before being scraped(2).
You can "scavange" the stale DNS entries any time from the DNS console. However "stale" is defined by you. You can probably ignore the extra DNS entries.

(1): Revokes Kerberos certificates and trust relationships, restores the SAM database to the local machine. All local profiles will remain using the domain SID's but can be removed by the local administrator.  It sounds like you will have a bunch of duplicated profiles lying around!
(2): Depending on your DNS settings and DHCP config. The DNS DB is actually stored in an Active Directory partition for replication, its still completely separate from AD.


How can I Bold First two words bold in a paragraph Dynamically?

Question: How can I Bold First two words bold in a paragraph Dynamically?
I am trying to bold first two words in the Paragraph what can i do ? for that
Using HTML Javascript Css Jquery AngularJs
Comment: Wrap them in some inline element like `span` and style them with CSS.
Comment: Thank for ur Response. But I want it as dynamically , Here i am not entering the text
Comment: Yes try to attempt this yourself as Paulie_D said. To get you started my approach might be to get the `` tag, split the string into an array, prepend ``, append `` to mySplitArray[0] and mySplitArray[1], join the array with a `" "` to make it back into a string and replace the `` tag with that. Split docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split and join docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
Answer: You can achieve this as below:
<!DOCTYPE html>

How can I Bold First two words bold in a paragraph Dynamically?

I am trying to bold first two words in the Paragraph what can i do ? for that


Let $f:[-1,1]\to \mathbb{R}$ diferentiable, with $f'$ integrable, such that $\frac{\int_{-1}^{1}e^xf(x)dx}{f(1)-f(-1)}=2(e+e^{-1})$.

Question:
Let $f:[-1,1]\to \mathbb{R}$ diferentiable, with $f'$ integrable, such that $$\frac{\int_{-1}^{1}e^xf(x)dx}{f(1)-f(-1)}=2(e+e^{-1})$$
  Prove that there exists $c\in (-1,1)$ such that $$\int_{-1}^{1}\frac{f(x)}{e^x}dx=4ef'(c)$$

My progress so far:
I integrated $\int_{-1}^{1}e^x f(x) dx$ by parts.
I got $(e-e^{-1})-\int_{-1}^{1} f'(x)e^x dx =2(e+e^{-1})$.
By Mean Value Theorem for integrals, $$\frac{e-e^{-1}}{e+e^{-1}}=f'(c)e^c$$ for $c \in (-1,1)$.
But how to proceed now?
Comment: Your integration by parts is erroneous. You should  get $e f(1)-e^{-1}f(-1)-$ $\int_0^1e^x f'(x)\;dx.$
Comment: sorry, yes it was erroneous
Comment: It is confusing, since, in the context, you have $e^x$ in the denominator, which is different from in the title.
Comment: The MVT should give you $e^tf'(t)=\frac{e^{-1}-e}{2}$, for $t\in (-1,1)$ not the result you have written.
Comment: I did it faultily from the beginning , my bad...still will the correct MVT yield positive results?
Answer: Here is one version,
$$A=\int_{-1}^1 e^xf(x)dx$$
$$B=\int_{-1}^1 e^{-x}f(x)dx$$
So B is what we need to estimate.
Using integration by parts.
$$A=f(1)e-f(-1)e^{-1}-\int_{-1}^1 e^xf'(x)dx$$
$$B=-f(1)e^{-1}+f(-1)e+\int_{-1}^1 e^{-x}f'(x)dx$$
equation (1) $$A-B=(f(1)-f(-1))(e+e^{-1})-\int_{-1}^1 (e^x+e^{-x})f'(x)dx$$
from the condition, $$A=2(f(1)-f(-1))(e+e^{-1})$$
So with mean value,
$$B=(f(1)-f(-1))(e+e^{-1})+\int_{-1}^1 (e^x+e^{-x})f'(x)dx$$
$$B=2\frac {f(1)-f(-1)}2(e+e^{-1})+2(e^{c}+e^{-c})f'(c)$$
Comment: Any ideas how to bring $4e$ in the RHS?
Comment: I guess $$\frac{\int_{-1}^1e^{-x}f(x)dx}{f(1)-f(-1)}=2e$$
Answer: Am giving a try. Did a bit progress in my way and so want to share it.
$$I = \int_{-1}^{1} e^x \cdot (f(x) + f(-x))dx$$
$$ = 0 - \int_{-1}^1 e^x \cdot (f'(x) - f'(-x))dx$$
$$ = 2f'(c)(e-\frac{1}{e})$$
Now, $$I = \int_{-1}^1 e^x f(x) + \int_{-1}^{1} e^{-x}  f(x)$$
$$ \implies \int_{-1}^{1} e^{-x}  f(x)= 2(e-\frac{1}{e})\cdot(f'(c) - f(1) + f(-1))$$
And am stuck out here only


Likelihood overflow in Metropolis-Hastings acceptance probability

Question: Consider a Bayesian framework where we have priors for some parameters and a likelihood based on the data. Consider the likelihood (and its parametric format) to be very sensitive to the choice of the parameters in a sense that for some not-so-proper parameter proposals, likelihood may overflow and become infinity. This is particularly a problem as in Metropolis-Hastings, you fail to compute the acceptance rate where you have likelihood overflow.
So, I wanted to ask if someone has a solution to deal with this situation. I'm looking for solutions on:

Avoiding likelihood overflow
If likelihood overflow happens, properly calculating acceptance probability
Comment: Numerous posts on site deal with the closely related issue of underflow/overflow in calculation of likelihood. For example, see the answers [here](http://stats.stackexchange.com/questions/56724/computation-of-likelihood-when-n-is-very-large-so-likelihood-gets-very-small).
Answer: This is a very good question! Although a much less common situation than likelihood underflow.
If the likelihood at a given proposed value $\theta'$ is exactly $+\infty$, then the chain should move there and not move except to other values of $\theta$ with infinite likelihood. I do not know of such cases.
If the likelihood at a given proposed value $\theta'_0$ is much larger than the likelihood at the current value $\theta$ so that
$$\dfrac{\pi(\theta') \ell_n(\theta'_0|x)}{\pi(\theta) \ell_n(\theta|x)}\gg 1$$
to the point that it creates an overflow in a computer code, the likelihood can be renormalised by
$$\tilde\ell_n(\theta)=\exp\{\log(\ell_n(\theta))-\log(\ell_n(\theta'_0))\}$$
which means that $\tilde\ell_n(\theta'_0)=1$ while
$$\dfrac{\pi(\theta'_0) \ell_n(\theta'_0|x)}{\pi(\theta) \ell_n(\theta|x)}=\dfrac{\pi(\theta_0') \tilde\ell_n(\theta'_0|x)}{\pi(\theta) \tilde\ell_n(\theta|x)}$$
This renormalisation somehow turns overflow issues into underflow issues, which are easier to handle because such values of $\theta$ are not of interest for the Markov chain.

Note also that a related problem may also happen because of the
  proposal density $q(\theta'|\theta)$: when the Metropolis-Hastings
  ratio
  $$\alpha(\theta,\theta')=\dfrac{\pi(\theta'|x)}{\pi(\theta|x)}\dfrac{q(\theta|\theta')}{q(\theta'|\theta)}\wedge
1$$ is computed, if $q(\theta|\theta')$ is very small, while $q(\theta'|\theta)=\text{O}(1)$ and
  $\pi(\theta'|x)\approx\pi(\theta|x)$, the chain may get stuck forever
  at $\theta$. This happens for instance when $\pi(\cdot)$ is almost constant over a large compact and $q(\theta|\theta')$ is the density of a normal $\mathcal{N}(0,\sigma^2)$ with a small $\sigma$.
Answer: A very common approach is to work with log likelihood values rather than likelihood itself.  Rather than multiplying the likelihood and prior, you can add the log likelihood to the log of the prior density.


i have a problem with this HttpGet method, i´ve used it before

Question: I have used the same on a different Controller in the same folder. but this should not affect this? When i run the code it shows a SQLite error 1 message
My goal is to have the user to fill in a form and the input is transfered to the Database.
<code>namespace findAMusicianApi.Controllers {
    [ApiController]
    [Route("[controller]")]
    public class MissionsController : ControllerBase{

        private readonly FindAMusicianContext _context;
        private readonly IWebHostEnvironment _hosting;
        public MissionsController( FindAMusicianContext context, IWebHostEnvironment hosting ){
            _context = context;
            _hosting = hosting;
        }

        [HttpGet]
            public async Task<IEnumerable<Missions>> Get(){
                List<Missions> missionList = await _context.Missions.ToListAsync();
                return missionList;
            }
</code>
Comment: The error is pretty self-explanatory; your `Missions` class has a `Descriptions` property (or another property mapped to that name) but here is no corresponding column in the database.
Comment: @YoungSushi, check your Mission class against the Mission table in your database, does this `Description` existed as the column in the database table?
Comment: i cant find the classes in the database no.. is there an update needed to the database ?
Comment: Problem solved, i had to run "dotnet ef migrations add classes" in Commandline.. and then do "dotnet ef database update". Thanks for the help!
Answer: I guess that the Missions model is the representation of the DB table.
The error says that you have a column named "Description" that is not present in the Missions Model.
Make sure that the Missions mode have all the properties needed to the deseralization process.
Comment: Problem solved, i had to run "dotnet ef migrations add classes" in Commandline.. and then do "dotnet ef database update". Thanks for the help!


effficient way to implement try/catch in C

Question: I want to do something like the following in C:
doSomthing(test_arg1); // first time
check_if_everything_good();

doSomething(test_arg2); // second time
check_if_everything_good();

doSomething(test_arg3); // third time
check_if_everything_good();

The idea is that after I call doSomething(), I want to make sure the function call didn't corrupt anything else, by calling check_if_everything_good(). In case doSomething() corrupted something, check_if_everything_good() returns before the second doSomething() call.
I however want to avoid calling check_if_everything_good() each time after doSomething() {check_if_everything_good is expensive}. Is there a way I can efficiently achieve this in C? Something maybe like a try/catch in java
Comment: So you want to call the function without calling it?
Comment: You could write a function that accepts a function pointer which calls the argument, then calls checkifeverythingood.
Comment: @scott_fakename or a macro.
Comment: The way you describe this, it doesn't seem very possible.
Comment: @feralin: Or copy&paste all the code from that function everywhere... but that's unlikely to solve their initial problem. Whatever it is...
Comment: If `check_if_everything_good()` is expensive in C, it's likely expensive in any other language as well.  The try-catch syntax doesn't make it more efficient; merely easier to type.
Comment: You mention `try`/`catch` in C. There is an implementation of such a thing in C called [cexcept](http://www.nicemice.net/cexcept/).
Answer: Assuming that check_if_everything_good is only needed for debug/diagnostic purposes in a development environment, then you could do something like this:
#ifndef NDEBUG
#define check_if_everything_good() do_check_if_everything_good()
#else
#define check_if_everything_good()
#endif

NDEBUG is a define typically defined by the compiler in a "release" (or "not a debug") build, so we use that here to "only do this when it actually makes sense".
Answer: You can use set jump and longjump
read  this http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html
and you can also use goto statment
http://www.roseindia.net/c-tutorials/c-goto-statement.shtml
Comment: There's no automatic unwinding though, so you have to be careful of creating memory leaks when you "throw".
Answer: If what you want is to be able to compile out the checks for production code, then Mats' suggestion works fine. The equivalent solution without creating your own macro is to simply change your check function to return 0 for failure and non-zero for success, and wrap the call with an assert().
assert(check_if_everything_good());

If you want to sometimes perform the check but not always, because it impacts performance, you can use random sampling. In this case, it just means you call rand(), and if the returned value is within some range, you perform the check, and otherwise you skip the check.
#define maybe_check_everything() \
    do { \
        if (CHECK_ALWAYS || (CHECK_THRESHOLD ? rand() < CHECK_THRESHOLD : 0)) \
            check_if_everything_good(); \
    } while (0)


Access Repeater values using JavaScript

Question: i searched a lot on NET, to get the solution, but i could not find
Can anyone tell me how to access the label and textbox values of repeater control inside using the javascript ?
This is my code
 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>

                    <asp:TextBox ID="TextBox3" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'
                        runat="server" />
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                    <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>
                    <asp:Label ID="lblname" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ename")%>'></asp:Label>

    </ItemTemplate>
</asp:Repeater>

Now i want to access the label, textbox of repeater using javascript
@Diodeus
I tried your code
function submitAll() {
        var thisLabel = $('.myLabel').eq(0);
        alert(thisLabel);
    }

But i got the result in alert as
[object Object]
and @deostroll
I tried your code this way
But not getting anything
    function GetData() {
        var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
        var tbl = arrTables[0];
        var td = tbl.childNodes[0].childNodes[0].childNodes[0];
        var txt = td.childNodes[0];
        alert(txt.value);
    }

Comment: Please provide the relevant HTML you are asking about.
Answer: <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>

IDs must be unique, so you can't apply the same ID to all of the labels in your repeater. Use CSS class names instead.
<asp:Label CssClass="myLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>

Since jQuery comes with .NET you can use it instead of plain JavaScript to access these elements more easily.
var thisLabel = $('.myLabel').eq(0) where 0 is the index of the element since there can be many.
Comment: I m not able to post code how to post code? its being posted like paragraph
Comment:  function submitAll() {
            var thisLabel = $('.myLabel').eq(0);
            alert(thisLabel);
        }
Comment: but on alert i got [object Object]
Comment: Yes, that gives you a reference to the object. You can get the value with $('.myLabel').eq(0).text() or $('.myLabel').eq(0).html()
Comment: Awsome. :) but its just giving single value, i have to get all the values so how can i get the count of rows of repeater so i can use it in for loop
Comment: $('.myLabel').length will give you a count so you can use a loop: replace .eq(0) with your counter .eq(x)
Answer: Wrap the repeater in a div with some id, say myDiv.

<asp:Repeater ID="Repeater1" runat="server"...>
<ItemTemplate>

...

</ItemTemplate>
</asp:Repeater>

Do a
var arrTables = document.getElementById('myDiv').getElementsByTagName('table');

Now arrTables is just array of all table elements inside the div. Find the ordinal of the desired table: For e.g. sake I am taking first table.
var tbl = arrTables[0];

Find the corresponding td of the table element:
var td = tbl.childNodes[0].childNodes[0].childNodes[0];

The above may vary based on how your browser loads the DOM and stuff. Hence I say you debug and find out for your self.
Once you get the td reference:
var txt = td.childNodes[0];

This will give the textbox. txt.nextSibling will give the label...and so on.
Comment: I tried your code but not getting it , i put the  of repeater inside the .. and write the code this way                                                        function GetData() {
            var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
            var tbl = arrTables[0];
            var td = tbl.childNodes[0].childNodes[0].childNodes[0];
            var txt = td.childNodes[0];

            alert(txt.value);

        }

Access Repeater values using JavaScript


Adding ADFS to existing AD Application

Question: We have an existing .NET application that uses Active Directory to authenticate users and search for user/OU data using DirectorySearcher object. Our customer has several AD servers and would like our existing application to authenticate/search from a single endpoint. Can we leverage our existing application by adding ADFS service to the customer's network to authenticate/search across several AD servers? Our application uses .NET System.DirectoryServices.DirectorySearch object using LDAP queries to authenticate and search for user/OU data.
Comment: Each DC holds a copy of the AD database. Why would you need to search more than one DC?
Comment: The customer wants to group the users within the application that would span multiple Active Directories/DC.
Comment: So you mean multiple AD Forests or multiple AD Domains in the same AD Forest?
Comment: This is a international customer across continents, I believe multiple AD Forests, we are in the midst of getting more information on the specific topology.
Answer: No, ADFS is a tool to create a trust between two identity providers (e.g. Active Directory) or an identity provider and a service provider (e. g. your application). It is used for authentication only. It does not offer any functionality to access objects between the trust parties.
As your goal is to search directories, ADFS will not help you there.
Comment: Good to know. We could possibly still use ADFS as authentication is a primary requirement.

Adding ADFS to existing AD Application


How to use CKEditor on the front-end?

Question: CKEditor do not work on one specific theme, it works fine in the back-end and also when I switch the theme.
When I look the sources, I get the JS & CSS, ckeditor class on textarea but not the injected code that CKE add under each textbox with id="cke_edit-body".
What can be the sources of the problem?
I know it's not jQuery, I found similar issues but they were provoked by a custom jQuery update, I use 1.3.2
Comment: Did you also give your users permission to access the _text format_ associated with the body field in the content type? e.g. filtered_html, full_html, etc.?
Comment: I should verify that! Where can i modify thoses parameters?
Comment: I forget exactly what the text is in D6, but it'll be under something like "text formats" in the standard user permissions page
Comment: @Clive I do not see anything like that in the permissions page , i am testing in admin mode, so i should just see everything and i just see a textarea with no Ckeditor.

One strange thing is that i have the class "ckeditor-mod" added to my textarea
Answer: On Input filter option (admin/settings/filters) you can check the user permission for each type of input filter you have on the site.
Then if you are using the WYSIWYG module, at admin/settings/wysiwyg you can check which type of editor is using each input filter.
If the WYSIWYG editor is working for anonymous user on one theme but not on the other, you could also check (with Firebug or Chrome DevTools) if there are Javascript errors. If that is the case, please, update this post with the error message.

How to use CKEditor on the front-end?


Empirical Likelihood estimation in R

Question: I'm new to Empirical Likelihood Estimation.
I'm trying to find an example of how to find the empirical likelihood estimate of a univariate mean $\mu$ using the emplik software package in R.
Any help or reference is greatly appreciated.
Answer: Suppose that we have a random variable $X$ with expectation $\mu$ and we want to test $H_0 : \mu = 0$.
We can test this by
el.test(x, mu=0)

This will give us the log likelihood ratio  $-2 \sum (\log(n p_i))$ and $p$ value.
Then you can decide about your hypothesis.
Comment: Could you write a little bit more because from your answer it is not even clear what is `el.test` function and what are the `n`, `p`, `i` values in log likelihood function.
Answer: maximum empirical likelihood estimate, in the iid case, is the sample mean.
empirical likelihood method helps you to find a confidence interval.
Comment: Could you provide a working example with R code, as requested by the OP?

Empirical Likelihood estimation in R


How to select a query as datasource in Apache Superset?

Question: I want to select a saved query as datasource in my charts but Superset only displays views and tables as data sources.
What is required to select a query as a datasource?
Answer: In SQL Lab, after you execute the query, you have an option to visualize the query, and then you are able to create a chart using the query, save it, and use it in a Dashboard once saved.
Not very intuitive, I had to look for it too ;-)
Comment: Once you've created the first virtual dataset in SQL Lab you can simply edit the dataset to update the SQL, and the change will be reflected in all charts that use the virtual dataset.
Comment: Yep, I haven't found any other way to do it. Maybe someone else knows how to do it, but I don't think it's implemented yet.
Comment: Last I tested, I used 0.38, but I don't think I have seen anything related to this in the 1.0 announcement (I've just skipped over the change log, so don't take my word on it)
Comment: Thank you. But this approach has the disadvantage that modifications to the query result in another query name (the id of the part that supersets adds changes) and changes are to reflected into any charts that use the query already.
Comment: Do you use Version 1.0 of Superset or any previous version? My expectation is that Superset V1.0 brought some improvements regarding this behaviour. Still on V0.37.2
Comment: Yes @RangaB., with version 1.0 or 1.1 of Superset this has changed a bit, but not much, you can use SQL Lab to build Virtual Datasources with your query, to use the same as physical tables/views in your database, look for more information about it in Superset documentation.
Answer: IDK if it is still relevant but you can query the dataset. This can be very useful when you're doing nested queries. You can do this with the help of jinja templating. make sure you have enabled them in the config file
<code>select * from {{dataset(233)}}
</code>


How can I quickly check Drupal 7 porting status of the contributed projects?

Question: How can I quickly check Drupal 7 porting status of the contributed projects ?
Answers should also guide readers if

a user is a developer and would like to help porting the most
frequently needed Drupal contributed modules, or
a user is a website owner
and would like to assess a possible upgrade from Drupal 6
to Drupal 7.
Answer: There is the Drupal 7 contributed project porting status website that uses data from the Upgrade Status module to show Drupal 7 porting status of the top 61 contributed projects.


Datatype of ROWID in Oracle/SQL

Question: What is the data type of ROWID in Oracle/SQL? How is this value stored?
Comment: See: [ROWID (oracle) - any use for it?](http://stackoverflow.com/a/2701811/272735)
Answer: The following link explains what the data type for ROWID is - ROWID data type
ROWID is stored as a psuedocolumn.
Comment: Oracle 11gR2 documentation: [ROWID Pseudocolumn](http://docs.oracle.com/cd/E11882_01/server.112/e41084/pseudocolumns008.htm#sthref63) and [Rowid Data Types](http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#sthref213)
Comment: Well technically, a rowid is not stored at all, which is why it is a pseudo column.
Answer: A ROWID data type stores information related to the disk location of table rows. They also uniquely identify the rows in your table. The ROWID data type is stored as a hexadecimal.
Therefore the hexadecimal string represents the unique address of a row in its table.
Comment: A rowid need not be unique to a particular row. Rows stored in clusters can have the same rowid, although they have different urowids. Some rows do not have rowids at all. Where ROWIDs are stored, they are string representations of concatenated hexadecimals, not hexadecimals themselves.
Answer: The ROWID (since Oracle8 called extended ROWID, till Oracle7 now called restricted ROWID) stores/encodes the physical location of a row.
The (extended) ROWID encodes (in hexadecimal format) the following fields:
OBJID (unique id of the object the row belongs to), the FILENO (relative file number within the TABLESPACE in which the object is created, the BLOCKNO (the relative block number within the file), and ROWNUM (the relative number of the row within the block).
The (restricted) ROWID only contained FILENO (relative file number within the database), BLOCKNO and ROWNUM (like in exteded ROWID) and no OBJID.
At any given time, the ROWID uniquely encodes the row in a database (except perhaps for clustered tales which share the same ROWID). ROWID's may change (due to reorganization of the database) and also may be re-used (for example after delete and insert, the new row may re-use a ROWID). Also exporting/importing tables will re-assign new ROWID's for tables.
Note that the FILENO is not necessarily unique per database in the extended ROWID format, but since the extended format also contains OBJID (which uniquely identifies the tablespace in which segments of the table object is stored), we can find a unique file.
BLOCKNO is unique per database file, and ROWNUM is unique per database block.
Exceptions: Index organized tables - ROWID can not locate the exact block due to index reorganisation (movement of leaf blocks).
ROWID's may change due to database reorganisation operations.

Datatype of ROWID in Oracle/SQL


Views: output item fields grouped by field instead of item?

Question: So currently if I make up a view that outputs three articles with their title and body fields a cleaned up version of the html structure would be:

Item One Title

Blah Blah Blah......

Item Two Title

Blah Blah Blah......

Item Three Title

Blah Blah Blah......

Anyone know how I can, through Views or the best alternative, make the structure like this instead:

Item One Title

Item Two Title

Item Three Title

Blah Blah Blah......

Blah Blah Blah......

Blah Blah Blah......

Answer: Look at Views Attachments. Set up your first View w/ just titles. Then Add display > Attachment, override your Fields to get body and use Attachment settings to position it after the first. Should be a few tutorials out there if this is confusing. Hope it helps.


What is an axiom schema?

Question: ZFC is not finitely axiomatizable. But it is, (and I know this is not precise yet) finitely axiom-schematizable. So my question is, what exactly is an axiom schema of a logical calculus like first order logic or propositional logic, such as ((A AND B) IMPLIES B)? Well, I guess it would be a set of statements. But what exactly makes a set of statements schematic?
Comment: It's usually a set characterized syntactically. They're all alike modulo some relettering of variables and plugging in subformulae in the right spots.
Answer: An axiom schema is an infinite set of axioms, all of which have a similar form.
For example, in Peano Arithmetic, there is the axiom schema of induction; for each first order predicate $\phi$ in the language of PA, we have an axiom:
$$(\phi(0) \wedge \forall n (\phi(n) \rightarrow \phi(n+1))) \rightarrow \forall n \phi(n)$$
For different formulas $\phi$, we get completely separate axioms. For example, we can replace $\phi$ with the formula $n+1+1 = n+2$ or with the formula $\forall m (((\exists l) n + l = m) \vee ((\exists l) n = m + l))$ or whatever other formula we can write down.
However, each of these axioms has the same "shape" - they're given by substituting some formula in for $\phi$. This is not a finite set of axioms, and you can show that there can be no finite set of axioms that works, but if we were to allow a symbol $\forall^* \phi$ which quantified over all formulas $\phi$ (which is basically what second-order logic is), we would be able to write this down as a single axiom.
Answer: As mentioned above, "scheme" isn't a fully-precise term (and incidentally, see here for an analysis of the role of schemes in the history of logic). However, there is a natural candidate for what this should mean, and it's basically Dorebell's answer (to which this answer is really just an excessively long footnote):

An scheme of sentences in a signature $\Sigma$ is a sentence $\sigma$ in the language $\Sigma\sqcup\{R\}$ for some $k$-ary (usually unary) relation symbol $R$. An instance of $\sigma$ is then a sentence of the form $$\forall y_1,...,y_n(\sigma[R/\varphi(y_1,...,y_n,x_1,....,x_k)])$$ where $\varphi$ is some $(n+k)$-ary formula in the original language $\Sigma$ and $\sigma[R/\varphi(y_1,...,y_n,x_1,..., x_k)]$ is the $L$-formula gotten by replacing each "$R(t_1,...,t_k)$" with "$\varphi(y_1,...,y_n,t_1,...,t_k)$" throughout $\sigma$.

The additional $y_i$s and the outermost $\forall$ amount to allowing object parameters in the scheme.
For example, let's look at the language of arithmetic $\Sigma_{arith}=\{0,1,+,\cdot, \le\}$. We pick some yet-unused unary relation symbol $U$, and the induction scheme $\eta$ is then just (represented by) the $\Sigma_{arith}\sqcup\{U\}$-formula $$[U(0)\wedge \forall x(U(x)\rightarrow U(x+1))]\rightarrow \forall xU(x).$$ Taking $\varphi(y,x)$ to be the formula $$y\le x$$ we get the $\eta$-instance $$\forall y([\varphi(y,0)\wedge \forall x(\varphi(y,x)\rightarrow \varphi(y,x+1))]\rightarrow\forall x\varphi(y,x)),$$ or more simply $$\forall y([y\le 0\wedge\forall x(y\le x\rightarrow y\le x+1)]\rightarrow \forall x(y\le x)).$$ This is of course a very silly thing to say (although true), but it's a good example of an instance of a scheme.

For most purposes, we don't really care about this precise notion - the vastly weaker notion of computably axiomatizable theory is generally enough for our purposes. However, there is one particular situation in which schemes as defined above shine, and that is abstract model theory.
A scheme $\sigma$ is formulated in some "basic logic" - say, first-order logic. However, we can then interpret $\sigma$ in larger logics (e.g. second-order logic) by allowing the instances of $\sigma$ to come from $\varphi$s in that larger logic. Fixating on first-order logic for the moment, this is to say the following:

From a scheme $\sigma$ in a signature $\Sigma$, we get a map $M_\sigma$ assigning to each logic $\mathcal{L}$ which is at least as strong as first-order logic a set $M_\sigma(\mathcal{L})$ of $\mathcal{L}$-sentences of signature $\Sigma$, namely the set of all instances of $\sigma$ gotten from allowing $\mathcal{L}$-formulas (as opposed to merely $\mathsf{FOL}$-formulas) as input $\varphi$s.

(I'm ignoring the issue of precisely defining "logic" here, but see e.g. Ebbinghaus' chapter in the Model-Theoretic Logics collection.)
This lets us treat "schematic" theories like $\mathsf{PA}$ or $\mathsf{ZFC}$ as instances of a broader construction:

$\mathcal{PA}$ is the map sending a logic $\mathcal{L}$ containing first-order logic to the $\mathcal{L}$-theory $$P^-+M_\eta(\mathcal{L}),$$ where $\eta$ is the induction scheme above and $P^-$ is the axiom for discrete ordered semirings.

$\mathcal{ZFC}$ is the map sending a logic $\mathcal{L}$ containing first-order logic to the $\mathcal{L}$-theory $$\mathsf{PPIUECR}+M_\rho(\mathcal{L})+M_\xi(\mathcal{L}),$$ where $\mathsf{PPIUECR}$ is the conjunction of the Powerset, Pairing, Infinity, Union, Extensionality, Choice, and Regularity axioms and $\rho$ and $\xi$ are schemes corresponding to Replacement and Separation respectively.

(Incidentally, this "parameterized-by-logics" idea occurs in other contexts too - such as analogues of Godel's constructible universe.)
Personally, I like this recasting of "schematic" theories as "parameterized" theories because it helps us cleanly separate two often-entangled questions:

What are our basic mathematical intuitions for natural numbers/sets/whatever?

What is the right logical system for analyzing natural numbers/sets/whatever?

We can say "Well, the natural numbers are a discrete ordered semiring + induction" in a vague-but-compelling answer to the first bulletpoint without yet settling on first-order logic as the correct answer to the second. The map $\mathcal{PA}$ described above constitutes a formalization of this answer without committing to an answer to the second bulletpoint. The utter dominance of first-order logic means that this isn't something we care about too much, but it is an example of a very simple idea facilitated by the precise notion of "scheme" articulated above for which more general notions like "computably axiomatizable theory" don't really cut the mustard.
Comment: This is a very nice definition.  It's worth mentioning one very simple generalisation: allow a schema to mention multiple predicates, i.e. it's written over a signature $\Sigma \sqcup \{R_1,\ldots,R_n\}$, and in its instances, we substitute multplie formulas $\varphi_1,\ldots,\varphi_n$.  This gives for instance the axiom schemas of propositional logic as examples (e.g. $\varphi \Rightarrow (\psi \Rightarrow \varphi)$).  Often this version can be reduced to the single-predicate version by coding, but the multiple-predicate version seems more natural, and the coding isn't always available.
Answer: "Schema" is not a precise term but the well-meaning intent is that it should be easy to enumerate the axioms and it should be easy to decide if a particular formula is an axiom or not.  For example we typically want to be able to verify proofs in polynomial time, so we should demand the same of any "axiom schema".

What is an axiom schema?


Isso é um bug no stdClass?

Question: No PHP é possível declarar uma variável ao mesmo tempo que passamos ela como parâmetro de uma função ou na instanciação da classe.
Vou dar um exemplo com a função is_file e a classe ArrayObject.
$arrayObject = new ArrayObject($a = []);

var_dump($a); // Imprime: array(0) {}

is_file($b = 'index.php');

print_r($b); // Imprime: "index.php";

Porém, quando fazemos isso no stdClass, algo inesperado acontece.
$object = new stdClass($c = []);

print_r($c); //Undefined variable 'c'

Nota: Para comprovarem que eu não estou inventando, aí vai o código no IDEONE
Atualização: Devido as respostas postadas falarem a respeito de ter a ver com os parâmetros existirem no construtor da classe ou da função, ou não para que a atribuição aconteça quando atribuímos o valor a uma variável que ao mesmo tempo passamos como parâmetro, estou colocando um código de exemplo para comprovar que isso não é verdade.
Criei três cenários.

A primeira classe ComParametro aceita apenas um parâmetro no construtor
A segunda classe SemParametro não aceita nenhum paràmetro no construtor, como no caso do stdClass
E por último, temos o stdClass.

Vejamos:

class ComParametro
{
   public function __construct($parametro){}
}

class SemParametro
{
    public function __construct(){}
}

new ComParametro($a = 'a');

print_r($a);

new SemParametro($b = 'b');

print_r($b);

new stdClass($c = 'c');

print_r($c);

Como podemos ver no IDEONE, os resultados foram respectivamente:

a
b
Undefined variable 'c'

Então, o que quero saber é por que esse comportamento está presente no stdClass!
Comment: *Para comprovarem que eu não estou inventando...* :D
Answer: Não sei como o PHP trata esse caso, mas se uma classe não tem definido o construtor(que é o caso stdClass), então qualquer atribuição será inválida na hora da instanciação do objeto.
Exemplo
<?php
class aa {
  function __construct() {}
}

class bb {
}

new aa($a = []);

var_dump($a);

new bb($b = []);

var_dump($b);

Comment: PHP tem dessas coisa 1 = true, null = false...
Comment: Se eu tiver uma classe que não aceita parâmetros no construtor, a atribuição vai acontecer corretamente. Vou postar um exemplo!
Comment: O problema então não está na questão da parametrização. Deu para entender pelo seu exemplo que, quando instanciamos a classe, o construtor não é chamado (pois não há construtor). Então o interpretador do PHP não cria a variável internamente por conta disso. Ou seja, a questão não é o construtor sem parâmetros, é que, não existindo ele, o interpretador do PHP não processa o que é passado por parâmetro no `stdClass` ou qualquer outra classe sem `__construct`. Legal :)
Comment: Agora o +1 foi mais que merecido. As respostas não estavam erradas, mas faltava então explicar que `__construct()` sem parâmetro não é a mesma coisa de não ter o `__construct`. Loucura, loucura, loucura!
Comment: Veja de alguma forma quando definimos um construtor, a atribuição é válida, mas quando não definimos o construtor a atribuição não é.
Answer: stdClass não aceita parâmetros.
A melhor forma de definir um valor como este para sdtClass é uma conversão:
$std = (object)$c = [];

var_dump($std); // Retorna object(stdClass)#1 (0) {}
var_dump($c); // Retorna array(0) {}

Portanto NÂO, esta é a definição da classe e não um bug.
Comment: Detalhe,, `stdClass` tem uma forma específica de ser usada o que faz com que mesmo que você passe qualquer parâmetros pra ela, ela desconsidera, mesmo que seja a você setando uma variável. isso nunca funcionou e não há previsão de que essa classe passará a fazer isso, então sim, este é um caso específico que foge às regras gerais do *PHP*. e não é o único caso que o *php* quebra suas próprias regras. :D
Comment: O que está sendo discutido aqui é que: Se o PHP aceita declarar variáveis ao mesmo tempo que a passamos por parâmetro, por que não é assim em `stdClass` (em qualquer outra classe, é assim)
Comment: +1 por editar a resposta e deixar mais claro, a sua resposta é boa, eu faço desse jeito também.
Comment: Ainda vocês não entenderam o sentido da pergunta
Comment: @ErlonCharles, você fez um cast, para converter `array` para `object` (Ou o `stdClass`). A resposta ainda assim não tem a ver com a pergunta que eu fiz. Não perguntei sobre como funciona a instância do `stdClass`, mas porque esse comportamento só está presente nele. Não estamos tratando do assunto "instância", e sim "variáveis definidas ao mesmo tempo que passadas com parâmetro dando pau"
Comment: Mas sua pergunta é especificamente "Isso é um bug no stdClass?". Portanto há sim uma resposta para sua pergunta na primeira e na última linha da minha resposta.
Answer: Para reforçar mais ainda a nossa teoria em relação à pergunta, vou dar o meu pitaco a respeito do assunto.
Como exemplificado pelo nosso amigo, a questão não é o fato de ter um construtor ou função com ou sem parâmetros. Isso não afeta em nada em relação a variável passada por argumento.
Os exemplos abaixo causarão a atribuição das variáveis:
function a(){}

class b
{
   public function __construct(){}
}

a($a = 1);
new b($b = 2);

var_dump($a, $b); // Imprime 1 e 2

Já no caso do construtor não ser definido, ocorre o problema descrito na pergunta:
class C{}

new C($c = 3);

var_dump($c); // Undefined variable 'c'

Essa é uma questão que provavelmente está relacionada ao interpretador do PHP.
Se a classe não tiver construtor, então não há necesidade de processar o que é passado por parâmetro de instância da classe - talvez pensaram assim quando fizeram a codificação das classes.
A última coisa que temos que fazer então é verificar se o stdClass realmente não possui o __construct internamente - apenas para meios de provas concretas.
Então, vamos lá:
$object = new stdClass;

$reflector = new ReflectionClass($object);

var_dump($reflector->getConstructor()); // NULL

Já em ArrayObject
$reflector = new ReflectionClass(new ArrayObject());

var_dump($reflector->getConstructor());

A saída é :

class ReflectionMethod#4 (2) {
  public $name =>
  string(11) "__construct"
  public $class =>
  string(11) "ArrayObject"
}

Então está provado que não existe __construct na classe stdClass
Comment: Depois também dá para fazer coisas como esta, é por isso que eu gosto do PHP :)

Isso é um bug no stdClass?