How do I correctly identify whether a song is in minor or major? (Take "My Old School" as an example)

Question: My Old School:

This song is very confusing. Is it in E minor or G major? 4:31 ends in a G major chord, but 4:50 ends in an E minor chord. How do I identify which key the song is in, in this situation?
Comment: For what practical purpose do you need to know a single key for the whole song? What would that enable you to do?
Answer: Just describe the musical sections as makes sense.
The song starts and ends with instrumental sections in E minor while the main song is in G major.
Different keys for different musical sections is very, very common.
I can't help but think part of the problem is trying to conform to the classical convention of titling and then thinking of those pieces as in a key based on the work's title. Ex. Mozart's String Quartet No. 18 in A Major where the trio is in E major and the andante is in D major, and the autograph score probably doesn't even have a title written out.
The classical convention of starting and ending a piece in the same key is what normally determines the key given in a work's title, but that says nothing about the arrangement of keys within the work, and not all compositions neatly fit that convention.
Sorry for the "classical" digression, but I just don't understand the motivation for identifying a single key other than titling works.
Simply put you don't need to name or describe a piece of music with only one key. Even worse is trying to select one key for the sake of some music software.
Answer: This song is an interesting case. Since G major and E minor are relative keys — that is, they share the same key signature — it would be fair to say it's "in the key of one sharp". That's how my band dealt with it when we played it.
However, from the point of view of analysis, there's another distinction that can be made. The intro and outtro of the piece are in E minor, while the main body of the piece is in G major. That's why one hears G major at 4:31 — the end of the main tune — and E minor at 4:50 — (near) the beginning of the outtro.
If I had to pin down a specific key, however, then I'd go with G major, since that's the primary key for the main body of the song, with the intro and outtro being "extra".
And that's the general rule, I think, for situations like this, where there's no obvious cadence in a single key, or the cadence is contradicted by a significant portion of the rest of the music: determine what key comprises the bulk of, or the main part of, the piece.
Comment: The key word in your question is "song". The Em sections are just arrangement elements, interludes for guitar solos that have chord rhythms but no melody. Every part of the song, that has melody and  lyrics, the verses and choruses are all in G. +1
Comment: You haven't answered the question. You've only answered it for this example (and that would be off topic)
Comment: I disagree - I hear the intro as already in G major, it doesn't make much musical sense to regard that first chord as a dominant.
Comment: @PiedPiper In an attempt to address your concern, I've added a paragraph to the end.
Comment: @reinierpost I'm not sure I understand. The piece doesn't start on the dominant; it starts immediately on an E minor chord. Of course, it's perfectly fine to start a piece on the dominant. One example that happens to come to mind is Schumann's "[The Poet Speaks](https://www.youtube.com/watch?v=yibf6QNjgGU&t=15m31s)", which is in G major but starts on D7.
Comment: @Aaron: Agreed, thanks; I meant the tonic, not the dominant. I hear the opening as a variant on the standard chord sequence G Eb C D G from which the first G chord has been omitted and the D chord has been substituted - making it a sequence with G as the tonic. It's clever because it foreshadows the closing section (from 4:46), which has D (Eb) A B Eb; that section could potentially resolve to G, too, but it doesn't and doesn't need to, so I would say it's in Eb.
Answer: G major and E minor are very closely related keys. It's common for a song to switch freely between them.   Or maybe there are clear sections in each key.
Maybe one key predominates, justifying you to label the piece as being 'in G major'.  Maybe it's more of a mix, and trying to name a single key is futile.
Maybe you're really asking about harmonic analysis.  In a fluid G major/E minor environment is an Em chord i or vi?   When does it become useful to re-define a secondary dominant as an actual dominant, considering B7 as V7 rather than 'V7 of vi'?  I guess the answer's in the word 'useful'.  Are we just passing through or have we set up camp?  Your choice.


Performance "memcpy" incorrect

Question: We have an application copying 80MB bulk data from one memory location to other using existing memcpy and unmodified RISCV compiler. We could see the cycle count is ~900 which seems incorrect. If I change the size, the count remains the same more or less.
This is obviously not correct. Is the problem due to the RISCV compiler being used? We were using riscv64-unknown-elf. Do we need riscv64-unknown-linux-gnu?
Comment: What is your simulator of RISC-V? How can you get 900 cycles? Can you post the source code of test and assembler code?
Comment: Likely, you have some error in measuring the cycles.
Answer: I'd made the similar performance test and compared the result with the SPARC-V8 LEON3 processor, so I've got the following data:

Copying 8 KB (Kilo Bytes) block
LEON3: 11780 clock cycles.
Rocket: 14630 clock cycles.

I've used modificated single-core Rocket configuration with disabled L2 cache and with the own implementation of the NASTI arbiter to provide 1 clock access to the AXI devices. Most probably you will have worse result with the default config.
My SoC implementaiton: https://github.com/sergeykhbr/riscv_vhdl

Performance "memcpy" incorrect


Drupal and its modules kept in two different subfolders -- possible/how?

Question: New to Drupal... I was wondering if it was possible to install it with the core and the modules kept in separate folders, rather than in a hierarchy. A bit like with WordPress, so to speak:
/.htaccess <-- site is here, in /, and in git
/drupal    <-- Drupal core, pulled as a git submodules
/content   <-- plugins and themes, each pulled as git submodules

I'm guessing it's possible, but the installation manual and a bit of googling (skeleton, subfolder, enterprise, etc.) led me nowhere. If so, I could use a pointer to get me in the right direction. If not, will it be possible with Drupal 8, which unless I am mistaking is using Symfony components?
Comment: Btw, sorry about the [cross-post](http://stackoverflow.com/questions/19411601/drupal-and-its-modules-kept-in-two-different-subfolders-possible-how). I hadn't realized there was a special SE.
Comment: Your question is about file structure, but I guess from your mention of git submodules that you are really interested in how to manage core and modules in a convenient way. If so, please ask a separate question on that topic, as there's more to be said about that topic than file systems.
Comment: @Letharion: not quite. I'm looking to do the same as the [WP Skeleton template](https://github.com/markjaquith/WordPress-Skeleton) that I linked to. The master project is in git, WP is in /wp, plugins are in /content/plugins (rather than /wp/wp-content/plugins), etc. WordPress has a bunch of defines to enable this. I'm guessing that Drupal 7 does so as well (Symfony's autoloader should allow to do this in Drupal 8), and was hoping for a pointer to locate them.
Comment: right, so a quick look at the WP skeleton template suggests that what you are looking for is the equivalent of "define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );". Drupal however, bases all file searches from "define('DRUPAL_ROOT', getcwd());" which is the very first statement in index.php. While in theory you could alter that, all sorts of havoc is likely to arise from it. Hence my answer below, is "no". There is no "Find files X here, and files Y there".
Answer:
install it with the core and the modules kept in separate folders, rather than in a hierarchy

In short, no.
Drupal must be able to expect to find files in a certain location, and that is not dynamically configurable. The very first line of code Drupal executes is define('DRUPAL_ROOT', getcwd());, and file wise, most things are based on that constant.
Symfony, and PSR-0, doesn't inherently change that. PSR-0 only defines the directory structure around files, not where to find them. With that said, I haven't looked in enough detail at D8 to know if there's a simple way to alter where the autoloader looks for files.
If your filesystem (and webserver) supports symlinks, you can work around the problem by symlinking the appropriate directories in place.
Comment: Accepting it as is, I guess... Mind expanding a little on how to use git submodules in a convenient way? Your other comment made me wonder if there are things I'd want to know beyond git basics.
Comment: I don't mind at all, but it depends on what you are trying to achieve. :) I prefer to organize things with a make-file (or soon, hopefully a composer.json), since submodules have quite a few shortcomings. (See https://codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/ for examples). You can see http://drupal.stackexchange.com/questions/33403/how-to-effectively-manage-a-site-with-drush-make for a brief discussion on make-files. Again, depending on what exactly you aim to achieve, there's a lot that can be said, and it doesn't all fit into comments. :)
Comment: Basically the same as what I do with the wp skeleton: `git submodule add [plugin|theme]`, alongside an update.sh that takes care of `git submodule update + git pull`. I'll open a new question if needed. (Interesting reads, btw; thanks for your time.)
Comment: Those are technical implementations though, which doesn't say anything about what problem you are trying to solve. (It also happens to sound like it could bite you badly when deploying to production, but I could be wrong)
Comment: Still, if you just want to copy the idea as closely as possible, a symlink for the sites directory should solve that for you.
Comment: Deployment is fine with git, really. I could use capistrano, but if my blog is anything to go, a good old git fetch works fine too, really, as long as you tag the submodules instead of using a branch. Technically, there is no need to place the git submodules the way they are in WP skeleton, but I find it a lot cleaner when they are (e.g. for uploads, etc.), hence my initial question about Drupal.
Answer: try and make a link and see if it works. I have done that for files in drupal and it should work for modules too.


How to use Rules to add custom shipping cost per product?

Question: I use Drupal Commerce  on Drupal 7 site, using product displays and products.
Each product has a shipping cost field.
At checkout, the shipping costs of all products in the order need to be collected and shown.
My approach is this: I use the Commerce Flat Rate module which creates the Flat Rate shipping method.
I then create a flat rate shipping service ´Custom Shipping Cost´.
Then I create a new shipping Rule ´Apply custom shipping costs´ which has a loop that needs to get the field value of the field ´custom shipping cost´ for each product in the order.
Question: how should a rule look like that gets the field values of a product connected to a line item and adds it to the shipping cost.
The following rules (which are nested) are not working.
I figured out using Rules logs that in the third rule, Entity has field is not passed. I try to get the product field value which needs to be added to the total shipping rate.
0.528 ms Evaluating the action component_rules_get_shipping_price_field_value. [edit]
" Evaluating rule get local shipping price field value. [edit]
0 ms Evaluating rule get local shipping price field value.
0.049 ms Evaluating conditions of rule get local shipping price field value. [edit]
0.11 ms The condition entity_has_field evaluated to FALSE [edit]
0.113 ms AND evaluated to FALSE.
0.123 ms Finished evaluation of rule get local shipping price field value.

================================================

{ "rules_apply_custom_product_shipping_costs" : {
    "LABEL" : "Apply custom product shipping costs",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_shipping" ],
    "ON" : { "commerce_shipping_calculate_rate" : [] },
    "DO" : [
      { "drupal_message" : { "message" : "Calculating shipping rates." } },
      { "variable_add" : {
          "USING" : {
            "type" : "commerce_price",
            "value" : { "value" : { "amount" : 0, "currency_code" : "USD" } }
          },
          "PROVIDE" : { "variable_added" : { "custom_shipping_cost" : "Custom shipping cost" } }
        }
      },
      { "component_rules_get_local_shipping_rate" : {
          "price" : [ "custom-shipping-cost" ],
          "line_item" : [ "commerce-line-item" ]
        }
      },
      { "component_rules_get_international_shipping_rate" : {
          "price" : [ "custom-shipping-cost" ],
          "line_item" : [ "commerce-line-item" ]
        }
      }
    ]
  }
}

==================
{ "rules_get_local_shipping_rate" : {
    "LABEL" : "Set local shipping rate",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_line_item" ],
    "USES VARIABLES" : {
      "price" : { "label" : "price", "type" : "commerce_price" },
      "line_item" : { "label" : "line item", "type" : "commerce_line_item" }
    },
    "IF" : [
      { "data_is" : { "data" : [ "line-item:type" ], "value" : "shipping" } },
      { "data_is" : {
          "data" : [ "line-item:commerce-shipping-service" ],
          "value" : "local_shipping_rate"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Start loop: collect line item local shipping price field values" } },
      { "LOOP" : {
          "USING" : { "list" : [ "line-item:order:commerce-line-items" ] },
          "ITEM" : { "lineitem" : "lineitem" },
          "DO" : [
            { "variable_add" : {
                "USING" : {
                  "type" : "commerce_price",
                  "value" : { "value" : { "amount" : 0, "currency_code" : "USD" } }
                },
                "PROVIDE" : { "variable_added" : { "custom_shipping_cost" : "custom shipping cost" } }
              }
            },
            { "component_rules_get_shipping_price_field_value" : {
                "custom_shipping_cost" : [ "custom_shipping_cost" ],
                "line_item" : [ "line_item" ]
              }
            },
            { "commerce_line_item_unit_price_add" : {
                "commerce_line_item" : [ "line-item" ],
                "amount" : [ "price:amount" ],
                "component_name" : "flat_rate_local_shipping_rate",
                "round_mode" : "1"
              }
            },
            { "drupal_message" : { "message" : "Single product shipping cost is" } },
            { "drupal_message" : { "message" : [ "custom-shipping-cost:amount" ] } }
          ]
        }
      }
    ]
  }
}

==============
{ "rules_get_shipping_price_field_value" : {
    "LABEL" : "get local shipping price field value",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "custom_shipping_cost" : { "label" : "custom shipping cost", "type" : "commerce_price" },
      "line_item" : { "label" : "line item", "type" : "commerce_line_item" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "line-item" ], "field" : "commerce_product" } },
      { "entity_has_field" : {
          "entity" : [ "line-item:commerce-product" ],
          "field" : "field_shipping_rate_local_countr"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "line item has field commerce_product" } },
      { "data_set" : {
          "data" : [ "custom-shipping-cost" ],
          "value" : [ "line-item:commerce-product:field-shipping-rate-local-countr" ]
        }
      }
    ]
  }
}

===========================
EDIT
The following issue was causing my problem: In this whole rules setup i used multiple variables as line items. I mistakenly used a lineitem variable outside the loop, instead of the lineitem variable inside the loop. at a certain point i had lineitem and line-item and mixed them up which made it not work. Also, the product needed to be added as variable in the loop.
Comment: Bonjour! What have you tried, and presumably didn't work "yet"? Please include an export of the rule(s) you have so far.
Comment: @Pierre Vriens - it appears that in the third rule the condition ´entity has field´ (line item has field commerce_product) is FALSE. I wonder why since my line items of type ´product´ do have the commerce_product by default.
Comment: Waw, your updated version of your question is a *real* question now, chapeau for this level of detail! Curious to hear to what extend my (possibly bizarre?) answer will get you going ... the bets are open ...
Answer: Below is an attempt to answer this (most important?) part of your question:

The following rules (which are nested) are not working. I figured out using Rules logs that in the third rule, Entity has field is not passed. I try to get the product field value which needs to be added to the total shipping rate.

In your 3rd rule, add another parameter, to also pass the "Commerce Product" that the line item is related to. Say you name that "product_related_to_item".
In your 2nd rule, pass the value of that extra parm (= product_related_to_item) to invoke the 3rd rule, using the line item token related to the product (for sure you'll have that in your 2nd rule).
In your 3rd rule, replace your 2nd "Entity has field" by a similar Rules Condition, but now referring to the (same) field for entity product_related_to_item (not sure if you still need your first Rules Condition then, homework for you ...).

By doing these corrections, the typical Rules magic (after you add such Rules Condition) applies again. E.g you can use their values in subsequent Rules Actions. And yes I know/realize, this may look like "this makes no sense", or "you're basically doiing the same thing". At least that's what I first thought myself just a few days ago when I ran into a similar issue. But sure enough, this was the solution (and it turned out this has to do with some limitation when processing "referenced entities (i.e. product referenced in a line item) in Rules.
Comment: I have tried but can´t get this to work. Can you give a very simple example rule that does your method?
Comment: I would be very happy to give you my login details of the website so you can have a try. I just don´t know how to send you a personal message..how does that work here..
Comment: tried this in the third rule but also keep on hitting the False: https://i.imgur.com/rlt4861.png
Comment: I see that there is another similar unanswered question..with alternative solutions but i dont think using terms will be a solution in this case..the shipping cost must be unique for each product https://drupal.stackexchange.com/questions/80362/drupal-commerce-trigger-shipping-rules-based-on-product-field-value
Comment: hey @Yuri, sorry to hear "cannot get this to work". Probably tomorrow (only) I can provide such sample. Thank you for the login details offer, but let us keep that until "if anything else fails" (if needed: check my profile to contact me). About the rule in the .png: it seems like you're still using 3 Rules conditions that all refer to the line item. My "main point" is that you should replace them with replacement tokens related to that "product_related_to_item" (as in my answer). If you have not tried that, could you let me know the results you get by using those tokens in your conditions?
Comment: I managed to do it successfully..with your help and soe tweaking now it works. I think best is if i delete all images and replace them with the final version...not today because i need sleep. Thank you very much Pierre...you saved me a severe depression. .-)
Answer: The following approach worked, thanks to hints of Pierre Vriens, although my specific use case is a bit complex because it uses two product fields for local and international shipping. I also used extra variables here and there, to make tokens available in system messages..so not all variables are actually required to make this work.
Comment: ***Nice!*** Merci for sharing the final result, looks like you even used my suggested field name for "product_related_to_item". Just in case you want to slightly further improve your answer: if you could ALSO include an export of those rules, future readers can simply copy/paste such export from your answer (instead of eyeballing the various screenprints and retyping them all manually).
Comment: Thank  you, yes I will do that too. By the way can I ask you yo have a look at this question I have no idea where to start debugging with that https://drupal.stackexchange.com/questions/253240/when-selecting-a-product-variation-attribute-the-add-to-cart-button-and-attribu


Package to enable php from command line, and execution of bgr processes with exec

Question: I've ubuntu 12.04 running LAMP.
Script requirements are:
Ability to run PHP from the command line (CLI) with exec()
Ability to execute background processes with exec("binary > /dev/null &")

For the first should I install php-cli? or some other package? And for the second one, can anyone explain what it means?
Answer: if you want to run PHP scripts from command line, the php5-cli package is required.
sudo apt-get install php5-cli

exec function is implemented in a PHP core (http://php.net/manual/function.exec.php), executing process in a background is realized by your shell (it's not related to PHP or any PHP  modules)
Answer:   sudo apt-get install php5
  sudo apt-get install libapache2-mod-php5
  sudo apt-get install apache2

All above commands will install php and apache on your server and you will get the ability to run php commandline also.
Comment: I have all these installed. What is php-cli package than in repo?
Comment: php-cli is command line for php.
Comment: php -v If you see 'cli' somewhere on the first line, you are ready to go, otherwise you will have to install it first. apt-get install php-cli


Passing xargs values as argument to subsequent YARN command

Question: Need help with passing arguments from xargs to subsequent Hadoop command.
I have results like below from this command.
yarn application -list -appStates RUNNING | grep <user> | awk '{print $1}'

Results of above command as below.
17/09/19 12:24:36 INFO client.ConfiguredRMFailoverProxyProvider:
Failing over to rm21 Total Application-Id
application_1505017974932_14847
application_1505017974932_14815
application_1505017974932_14810
application_1505017974932_14784
application_1505017974932_14796
application_1505017974932_14778

I need to be able to pass above output one by one to below command.
yarn application -movetoqueue <application_ID of above output> -queue myqueue

Could you please help here in finding the right command to achieve the same?
Similar setup is working for me in below command but not in the above as above command has n
a)
yarn application -list -appStates RUNNING | grep <user> | awk '{print $1}' | xargs -n 1 yarn application -kill

This is another way..
b.) for app in yarn application -list -appStates RUNNING | grep <user> | awk '{print $1}'; do yarn application -kill "$app";  done
Appreciate your help on this.
Answer: xargs reads the STDIN stream data and converts each line into space separated arguments to the command.
Some reasons why xargs might not work in your case:

Using xargs, the argument to this command "yarn application
-movetoqueue 'application_ID' -queue myqueue" is passed at the end of it.
Not all the applications/tools accept multiple space separated
arguments.
The result of your command is a string containing special characters and it should be quoted.

So, I would suggest the following:
for appid in `yarn application -list -appStates RUNNING | grep user|awk '{print $1}'` ; do
    yarn application -movetoqueue "${appid}" -queue myqueue;
done

Comment: Thank You Very Much for your syntax, It is WORKING with for loop command. Much Appreciated.
Comment: @ Ardit,Could you pls check if below can also be worked in same fashion ?for appid in `oozie job -info 0007218-170910003406158-oozie-oozi-W | grep job | awk '{print $3}' | cut -c4-23 | sed 's/job/application/'`; do yarn logs -applicationId "${appid}" -Owner user9; done
Comment: for loop is suposed to take variables from your command output expression, so you should put the command within $()

`for appid in $(oozie job -info 0007218-170910003406158-oozie-oozi-W | grep job | awk '{print $3}' | cut -c4-23 | sed 's/job/application/'); do yarn logs -applicationId "${appid}" -Owner user9; done`
You are using too many tools in your command, you can do it only with `awk` or `sed` only. In case you have other queries, please post more information (input, desidered output).
Comment: New to this, Where to  mark this question as completed ? Also, can you pls take a look at this. post https://stackoverflow.com/q/46372820/4447530


make available of accessing to full path and reloading page with react-router

Question: I use react-router in my react project.
This is my package.json:
{
  "name": "app_name",
  "version": "1.0.0",
  "description": "app on browser",
  "main": "gulpfile.js",
  "scripts": {
    "build": "gulp build",
    "start": "cordova run browser"
  },
  "author": "maki",
  "license": "ISC",
  "dependencies": {
    "babel-preset-es2015": "^6.13.2",
    "browserify": "^13.1.0",
    "gulp": "^3.9.1",
    "history": "^4.2.0",
    "material-design-icons": "^2.2.3",
    "material-ui": "^0.15.4",
    "react": "^15.3.0",
    "react-dom": "^15.3.1",
    "react-motion": "^0.4.4",
    "react-router": "^2.7.0",
    "react-swipeable-views": "^0.7.0",
    "react-tap-event-plugin": "^1.0.0",
    "vinyl-source-stream": "^1.1.0"
  },
  "devDependencies": {
    "babel-cli": "^6.11.4",
    "babel-plugin-transform-class-properties": "^6.11.5",
    "babel-preset-react": "^6.11.1",
    "babel-preset-stage-1": "^6.13.0",
    "babelify": "^7.3.0",
    "gulp-sass": "^2.3.2",
    "jquery": "^3.1.0"
  }
}

I have a router like below:
<Router history={browserHistory}>
  <Route path="/" component={App}>
    <IndexRoute component={HomePage}/>
    <Route path="/news" component={NewsPage}/>
      <Route path="/news/:id" components={News}/>
    <Route path="/about" component={AboutPage}/>
    <Route path="/member" component={MemberPage}/>
    <Route path="/products" component={ProductsPage}/>
    <Route path="/contact" component={ContactPage}/>
  </Route>
</Router>

Here is what I want to achieve:
1: Access to except IndexRoute.
 ex) http://example.com/news/1234
2: Making available of reload except IndexRoute page.
Now, I try that, and I receive this message:

Cannot GET /news

what should I do??
Answer: You need to implement the history fallback for browserify in your gulpfile similar to this:
var historyApiFallback = require('connect-history-api-fallback');

// ...
browserSync({
  server: {
    baseDir: './',
    middleware: [historyApiFallback()],
  },
});

Comment: but, when I did so, I receive an error message: "Cannot GET /"
Comment: Check if if the `baseDir` is the path to where your `index.html` is.


Using Drupal as a server application user front-end (feasability question)

Question: I am very new to Drupal. I am currently watching videos and reading many online tutorials. I came to Drupal, because I understand it is a good CMS system (at least recommended by many, and the more I learn, the more I agree).
But, the more I learn, the more I am wondering whether it could solve another of my needs: acting as a user front-end for a server-side application. Let me describe this.

I have a couple of experts entering technical information in a system (i.e. database). I understand I can create specific screens with specific fields in Drupal (that's great, no coding) and that it would be stored in the database when ready.
After information is entered by experts, heavy time and cpu consuming asynchronous processes should be started in background and resulting information stored in the database.
Next, users should be able to read results with another screen in Drupal.

Instead of performing the heavy processes on the web-server, I was wondering whether I could use another server to connect to the drupal database instance (with a deamon application written in Java for example), perform the heavy duty tasks, and store the information in that same database.
My questions are:

Is this realistic? Has anyone attempted this?
Is it easy for a 3rd party application to read data from a Drupal database and store results in it? Does Drupal offer specific modules faciliting this? Any documentation or tips available?

Thanks.
Comment: Not sure but you should check the **services** module it might be helpfull for you to communicate with drupal.
Comment: I guess like any PHP framework you can 'make' it work for your project.  But as @stefgosselin said, Drupal is far more than CMS. Orchestrating workflows and interacting with external services are two things Drupal can do very, very well.
Answer: Absolutely.
Do not be put off by the 'CMS' label, Drupal is actually quite a framework in itself.  Drupal really does a good job for small to mid-sized applications, as the application gets larger though one has to tweak and push the limit a bit more. To be fair, this is true of most any PHP application.
I have built quite a few applications myself that leverage the power of Drupal, some internal, some public: production management, calendaring applications, rental/item reservation for 4000 items +, mailing list management, (and more).
In my (very humble) opinion, Drupal saves a lot of time, especially for the 'user-management' aspect of application building. As a bonus, you have the rest of the framework to play with when developping your app.
Hope that helps, happy coding, good-luck!
Answer: Here's my understanding:

Drupal will allow you to quickly create a content-type to store the data you need, and customise how your users enter their data.
It's possible to query the Drupal database directly, but if you're not familiar with Drupal's schema, you'll need to spend a little time understanding where your data is stored.
Once you do understand the schema, you may find the database is over-normalised for your requirements, which will mean a lot of joins will be required. Might not be an issue depending on your infrastructure and the quantity/frequency of data you're talking about.
There are several APIs you can use to get data out of the database (assuming Drupal 7):

For direct SQL queries, use db_query
For the Drupal db access layer, use db_select
For something you configure, you could use views which you could output to any number of formats (json, XML, HTML etc.)
There are dozens of other modules which will allow you to integrate with other systems, one of those might suit your purpose.

Storing the processed information again will depend on how much the data has changed, and how it need to be stored. For example: are you just overriding the existing data? Will the new data be added to the existing nodes, or will new nodes be created? Regardless, you'll probably need a custom module for this.


Is cross-validation the most important measure of a predictive model's effectiveness?

Question: Why bother with p-values, R squared, etc. ... Model size is not a factor with the computing power available now so why not just run multiple iterations of all possible sets of input variables and see which one has lowest cross-validation error?.
Comment: You must distinguish between two things -- model selection (which type/parameters of the model is best) and model evaluation (what accuracy the model should have on new data). If the first part is present, you must either remove it (with regularization or similar idea) or include it in model assessment CV or you'll get overoptimistic results.
Answer: A good reason not to do this is that the cross-validation estimator has a finite variance, so if you evaluate it on many choices of input variables you will end up with a set that explains the data you have well, but will generalise poorly as it has effectively learned the noise that is particular to that dataset. The more choices you investigate, the worse the problem gets. Often you end up with a worse predictor than a regularised model, with all the features, such as ridge regression.  So if you are interested in predictive performance, don't perform feature selection at all, instead use regularisation.  This is the advice given in Millar's monograph on subset selection in regression, and in my experience, he is right.
Answer: I would personally favor cross-validated score evaluation because:

it is easily interpretable by the analyst provided that the underlying score function (accuracy, f1-score, RMSE...) is interpretable too,
it gives an idea of the uncertainty by looking at the stdev of the score values across CV folds,
it gives a way to decompose the error into bias (error measured on train folds) and variance (difference of errors measured on train and  test folds).

Model size is not a factor with the computing power

This is not always true: deep learning machine learning models for instance have a model size that is often limited by the hardware (typically the amount of RAM on the GPU card).
Answer: Two scenarios spring to mind where you wouldn't want to just run iterations of all possible models:

Your model is in a clinical setting. For example, a nurse takes some measurements and uses it to predict something. If you include every possible covariate, then you are more likely to get missing values. Especially if some of the covariates require sensitive information.
In your model, $p>> n$, however, your covariates can be "grouped". For example, one set of covariates could be "lifestyle", another could be socio-economic class. It might be better to try and select a few variables from each group.
Comment: You didn't spell out why all possible subsets would *ever* be a good idea.
Comment: +1, though you haven't spelled out why this last is better than using all possible subsets of predictors.


Does Acoustic Blues Guitar Require Use of a Thumb Pick?

Question: I've recently started going through some acoustic blues lessons at jamplay.com.  The instructor plays with a thumb pick.  I had gone through the first 8 lessons using a standard pick but the latest lesson requires plucking the 3rd and 6th strings simultaneously for the turn-around.  So, I bought a thumb pick and I really can't stand using it.  It seems you can only pick down unless you put it on so tight that it cuts off circulation to your thumb.  I also had alot of trouble adjusting to the height difference between my thumb and other figers and also maintaining a consistent volume between the strings.  I've actually worked on keeping hold of a regular pick while I pluck the 6th string with my thumb.
My question is, will I be crippling myself by not learning to use the thumb pick?  If so, does anyone have any tips on getting comfortable with it?
I forgot to mention that I was initially playing the latest lesson with no pick at all but my thumb became very sore.
P.S.  Just to clarify for everyone, I'm still holding the pick between my thumb and pointer finger but twisting my pointer and pick out of the way a little and plucking the 6th string with my thumb, not the pick and the 3rd string with my middle finger.  Almost like I would do it if I wasn't holding the pick at all.  I'm able to switch to this and back to normal picking without any pause so it's working pretty well.
Comment: In the movie "M for Mississippi", a street musician uses a spoon for a slide. I don't think there are any rules.
Answer: The short answer is, no, blues doesn't require a thumb pick. The blues is a broad class of music, played on all kinds of instruments, in all kinds of ways.
The longer answer is, that it depends what sound you want. If you want the sound you get from a thumb pick, then a thumb pick is probably the best way of getting it!
I suggest you don't attempt upstrokes with the thumb pick. Play only downstrokes and that particular problem is solved. I don't think it's common for a thumb pick style blues riff to require fast patterns on the bass strings. After all, it's pretty much impossible to do an clean sounding upstroke with a naked thumb, too.
If you choose to use a plectrum, you either sacrifice the ability to pluck non-adjacent strings simultaneously, or you learn to sneak a finger in when you need it. My instinct would be to pluck the bass note with the plectrum while using a spare finger to find the higher string. You seem to have tried the other way round. Whatever works for you is fine.
If you choose to go without a pick altogether, you can pluck two or three strings at the same time, but you get a more mellow sound because you're using softer objects to pluck. Your thumb will get sore at first, but it will soon toughen up. Remember how sore your left hand fingers were when you first took up the guitar.
There is no "right" answer to this. Find your own preference.
Comment: I do upstrokes with the thumbpick, momentarily using my index finger to do it. It's not the same thing a flat pick, but it's very alike a heavy one.
Answer: I have never found those finger/thumb picks useful, they seem too far removed from my hand to be comfortable.
Use of them is purely a personal preference thing, not at all 'required'.
My first suggestion would be to grow your fingernails a bit and try picking with those, fingernails are used by all types of player, not just classical guitarists.  They are the most natural way to pick if you are finger-picking, bare fingertips can be a bit clumsy but are also fine after some practice.
Fingernails will take some getting used to, a little maintenance and some bad habit breaking if your a biter :), but are well worth it.
I use a pick (plectrum) most of the time, but use my fingernails for hybrid picking and often for acoustic playing latin/blues/jazz, whatever.
Comment: Surely you could say the same of a plectrum? You get used to it. Fingernails are great, but they sound different to a pick.
Comment: As you said there is no right answer to this question, as with many such things.  This is just another option.  I would still advise fingernails when hybrid picking also (thumbpick/plectrum and fingers).
Answer: First off, you definitely don't need a thumb pick, or indeed any particular use of fingers or picks to play blues. Blues is about the feel, and can be accomplished with fingers, picks, slide, whatever. However learning different styles is very useful, so this lesson sounds worth trying to do correctly.
Second, your thumb will toughen up quickly - don't worry about that. You will also get used to the height with practice.
Answer: John, the use of a finger pick won't necessarily cripple your ability to play Blues or any other fingerpicking style of music.   But let's put this in perspective:
How Did Fingerpicks Come About? (Click Me)
The link in the above title gives reference to finger/thumb picks being used by banjo players in the 1800s.  In turn, the banjo is associated with blues because of its historical association with REALLY early blues and african instruments starting to use steel strings.
The finger picks also had a particular way of being used, ie. exclusively upstroke or downstroke.  Overtime, these different stylistic leanings would have lead to some musicians playing with and some without.
So the use of fingerpicks is more a question of preference based on how "authentic" you want your blues to sound, and/or of what particular era's of blues are you playing?
Playing with Fingerpicks
On a more practical note, I have it on good authority from several great fingerpicking friends that if you have sensitive thumbs, then they do help prevent you becoming sore.
But I agree with Dr Mayhem in that playing without them will surely develop toughness and strength over time.
If you learn to play with them and also without them, then at least you will learn the different nuances in using them and you can have a more personal choice as to what you prefer with the style of "blues" you are going for.
Answer: It is buried in Slim's answer, but for this specific question, it is pretty straightforward to use a standard pick to strike the top note and use your middle or ring finger to pluck the 2nd note simultaneously.
While using a standard pick, you have 3 fingers not really doing anything.
Comment: I hold my pick between my thumb and index finger. Everyone else I know who plays also does this, as well as every single guitarist with a pick I have ever seen in a video etc. As far as top note, I mean "top" as in "above" with respect to gravity.
Comment: Reverted. I didn't mean bass note, because the actual note is not relevant. This can be done at the 23rd fret with the B and high e strings
Comment: I'm confused about this. If you're holding the pick between first and second fingers, isn't it easier to play the bass note with the pick and the higher note with a spare finger? Otherwise you have to tuck your spare finger under your pick "assembly". Or am I misunderstanding your use of "top note"?
Comment: Fixed that for you.
Comment: Sorry, yes, I meant thumb and first finger. But in music, my meaning of "top" is the opposite to yours. "high", "low", "top" and "bottom" when I'm on a guitar, are matters of pitch not gravity. On SE, I take care to use words like "bass" rather than "low", to avoid ambiguity.


@joincolunm com foreignKey hibernate

Question: Olá eu queria fazer uma chave estrangeira, porém não estou entendendo a sintaxe.
Na classe Endereco:
@Embeddable
@Table(name = "tab_endereco")
public class Endereco {

@Column(length = 40, nullable = false)
private String logradouro;

@Column(length = 40, nullable = false)
private String bairro;

@JoinColumn(columnDefinition = "char(3)", nullable = false, foreignKey = @ForeignKey(name="fk_cidade"))
private Cidade cidade;

Na classe Cidade, onde que pegar a sigla:
@Entity
@Table(name = "tab_cidade")
public class Cidade {

@Id
@JoinColumn(columnDefinition = "char(3)", nullable = false, referencedColumnName = "fk_cidade")
private String sigla;

@Column(length = 40, nullable = false)
private String nome;

@Column(columnDefinition = "char(2)", nullable = false)
private Estado estado;

Answer: Olá, segue um exemplo de como vc pode criar relacionamento em suas classes.
Classe estado:
@Entity
public class Estado {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String nome;
private String sigla;

Quanto a Classe Cidade, nesta classe tomei a liberdade de colocar como chave primária um campo de Id, não sei se entenderia a sua necessidade, porém vc pode mudar conforme regras do seu projeto:
@Entity
public class Cidade {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long cidadeId;
private String nome;

@ManyToOne
@JoinColumn(name = "estadoId")
private Estado estado;

Por fim a classe endereço, nesta classe não coloquei o campo estado pois a Cidade já possui um estado vinculado a ela:
public class Endereço {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String logradouro;

@ManyToOne
@JoinColumn(name = "cidadeId")
private Cidade cidade;

Então vamos lá:
@Id = Indica qual é o atributo de identificação única do objeto a ser persistido;
@GeneratedValue(strategy=GenerationType.IDENTITY) = Ao usar esta anotação o SGDB fica responsável por gerar o valor do ID do objeto de maneira incremental;
@ManyToOne = Define uma relação de cardinalidade de muitos para um, ou seja Muitos endereços estão em uma única cidade por exemplo;
No seu código percebi que vc tinha utilizado uma anotação @Embeddable, no meu exemplo retirei pois esta anotação se utiliza quando trabalha-se com chave composta.
Valeu.
Comment: Na classe `Cidade`, o atributo `estado` não deveria ser `@ManyToOne`? em vez de `@OneToMany`?
Comment: Vc esta certo, fiz a correção.
Comment: Nesse caso, o @ManyToOne está dizendo que o muitos Endereço para uma Cidade? E como o private Cidade cidade identifica qual o atributo da classe Cidade é o que vai servir de chave estrangeira? Através do @Id?
Comment: E o @JoinColumn(name = "cidadeId"), o name dentro da JoinColunm tem que ser o mesmo nome do atributo(private Long cidadeId) ?
Comment: Olá Danilo, sim, quando vc faz o mapeamento para definir o relacionamento entre as entidades a própria API já faz o o relacionamento para a chave primária da classe que estamos vinculando, Quanto a utilizar o mesmo nome, não é necessário, eu utilizo para manter mais fácil a leitura.
Comment: Danilo, tem um material que é um resumo de algumas anotações que facilita o entendimento da utilização: http://www.techferry.com/articles/hibernate-jpa-annotations.html

@joincolunm com foreignKey hibernate


Probability of tossing a fair coin with at least $k$ consecutive heads

Question: Tossing a fair coin for $N$ times and we get a result series as $HTHTHHTT\dots~$, Here '$H$' denotes 'head'  and '$T$' denotes 'tail' for a specific tossing each time.
What is the probability that the length of the longest streak of consecutive heads is greater than or equal to $k$? (that is we have a $HHHH\dots~$, which is the substring of our tossing result, and whose length is greater than or equal to $k$)
I came up with a recursive solution (though not quite sure), but cannot find a closed form solution.
Here is my solution.
Denote $P(N,k)$ as the probability for tossing the coin $N$ times, and the longest continuous heads is greater or equal than $k$.
Then (For $N>k$)
$$
P(N,k)=P(N-1,k)+\Big(1-P(N-k-1,k)\Big)\left(\frac{1}{2}\right)^{k+1}
$$
Comment: I'm getting $(N-k+1)/2^k$ for the closed form. Would you like for me to post my solution, or do you want to think about it some more before I spoil the beans?
Comment: @Braindead: That can't be right; it's $\gt1$ for small $k$.
Comment: I tried to clarify some of the formulations; please check whether I preserved the intended meaning. In particular, I assumed that you had merely accidentally written "greater" once instead of "greater or equal".
Comment: Your example sequence reminded me of [this brilliant Simpsons scene](http://www.youtube.com/watch?v=NAeXSwE1HGI) :-)
Comment: Duh, you are right. I overcounted.
Comment: @joriki, yes, you've preserved the intended meaning. 'at least' should mean greater or equal
Comment: @Benson: It does, but you had only "greater" in one place.
Comment: The approach I took was to divide into cases where the exact number of heads is known. Supposing that there is a $k$ block of heads in $N$ tosses, the number of heads can be exactly $k$, $k+1$,..., $N$. In my first failed attempt at the solution, I overcounted the number of possible arrangements for $k$-block with $r$ heads. I fixed this, and right now I'm checking to see if I overlooked anything...
Comment: Can't this be simplified to $P(N,k)=P(N-1,k)+\frac{1}{2}·P(N-1,k-1)$?
Comment: how do i calculate $P(N-1,k)$? @GregRos
Answer: We can derive an explicit formula of the probability $P(N,k)$ based upon the  Goulden-Jackson Cluster Method.

We consider the set of words $\mathcal{V}^{\star}$ of length $N\geq 0$ built from an alphabet $$\mathcal{V}=\{H,T\}$$ and the bad word $\underbrace{HH\ldots H}_{k \text{ elements }}=:H^k$ which is not allowed to be part of the words we are looking for. We derive a function $f_k(s)$ with the coefficient of $s^N$ being  the number of wanted words of length $N$.
The wanted probability $P(N,k)$ can then be written as
  \begin{align*}
P(N,k)=1-\frac{1}{2^N}[s^N]f_k(s)
\end{align*}

According to the paper (p.7) from Goulden and Jackson the generating function $f_k(s)$  is
\begin{align*}
f_k(s)=\frac{1}{1-ds-\text{weight}(\mathcal{C})}\tag{1}
\end{align*}
with $d=|\mathcal{V}|=2$, the size of the alphabet and with $\mathcal{C}$  the weight-numerator with
\begin{align*}
\text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[H^k])
\end{align*}
We calculate according to the paper
\begin{align*}
\text{weight}(\mathcal{C}[H^k])&=-\frac{s^k}{1+s+\cdots+s^{k-1}}=-\frac{s^k(1-s)}{1-s^k}
\end{align*}

We obtain the generating function $f(s)$ for the words built from $\{H,T\}$ which don't contain the substring $H^k$
  \begin{align*}
f_k(s)&=\frac{1}{1-2s+\frac{s^k(1-s)}{1-s^k}}\\
&=\frac{1-s^k}{1-2s+s^{k+1}}\tag{2}\\
\end{align*}

$$ $$

Note: For $k=2$ we obtain
  \begin{align*}
f_2(s)&=\frac{1-s^2}{1-2s+s^{3}}\\
&=1+2s+3s^2+5s^3+8s^4+13s^5+21s^6+34s^7+\mathcal{O}(s^8)
\end{align*}
The coefficients of $f_2(s)$ are a shifted variant  of the Fibonacci numbers stored as A000045 in OEIS.
Note: For $k=3$ we obtain
  \begin{align*}
f_3(s)&=\frac{1-s^3}{1-2s+s^{4}}\\
&=1+2s+4s^2+7s^3+13s^4+24s^5+44s^6+81s^7+\mathcal{O}(s^8)
\end{align*}
The coefficients of $f_3(s)$ are a    shifted variant of the so-called Tribonacci numbers stored as A000073 in OEIS.

$$ $$

We use the series representation of $f_k(s)$ in (2) to derive an explicit formula of the coefficients.
\begin{align*}
[s^N]f(s)&=[s^N](1-s^k)\sum_{m=0}^{\infty}(2s-s^{k+1})^m\\
&=[s^N](1-s^k)\sum_{m=0}^{\infty}s^m(2-s^k)^m\\
&=[s^N](1-s^k)\sum_{m=0}^{\infty}s^m\sum_{j=0}^m\binom{m}{j}(-1)^js^{kj}2^{m-j}\\
&=([s^N]-[s^{N-k}])\sum_{m=0}^{\infty}s^m\sum_{j=0}^m\binom{m}{j}(-1)^js^{kj}2^{m-j}\tag{3}\\
&=\sum_{m=0}^{N}([s^{N-m}]-[s^{N-k-m}])\sum_{j=0}^m\binom{m}{j}(-1)^js^{kj}2^{m-j}\tag{4}\\
&=\sum_{{m=0}\atop{m\equiv N(\bmod k)}}^{N}\binom{m}{\frac{N-m}{k}}(-1)^{\frac{N-m}{k}}2^{m-\frac{N-m}{k}}\\
&\qquad-\sum_{{m=0}\atop{m\equiv N(\bmod k)}}^{N-k}\binom{m}{\frac{N-m}{k}-1}(-1)^{\frac{N-m}{k}-1}2^{m-\frac{N-m}{k}+1}\\
&=\sum_{{m=0}\atop{m\equiv N(\bmod k)}}^{k-1}\binom{m}{\frac{N-m}{k}}(-1)^{\frac{N-m}{k}}2^{m-\frac{N-m}{k}}\tag{5}\\
&\qquad+\sum_{{m=k}\atop{m\equiv N(\bmod k)}}^{N-k}
\left(\binom{m}{\frac{N-m}{k}}-\frac{1}{2^k}\binom{m-k}{\frac{N-m}{k}}\right)(-1)^{\frac{N-m}{k}}2^{m-\frac{N-m}{k}}\\
\end{align*}
Comment:

In (3) we use the linearity of the coefficient of operator and $[s^N]s^mf(s)=[s^{N-m}]f(s)$
In (4) we change the limit of the left hand sum from $\infty$ to $N$ according to the maximum coefficient $[s^N]$. According to the factors $s^{kj}$ we consider in the following only summands with $m\equiv N(\bmod k)$
In (5) we reorganise the sums from the line above by extracting from the left hand sum the first summand and shifting in the right hand side the index by one and putting both sums together.

We conclude: An explicit representation of the probability $P(N,k)$ $(n\geq 0)$ is according to (5)
  \begin{align*}
P(N,k)&=1-\sum_{{m=0}\atop{m\equiv N(\bmod k)}}^{k-1}\binom{m}{\frac{N-m}{k}}(-1)^{\frac{N-m}{k}}2^{-\frac{(k+1)(N-m)}{k}}\\
&\qquad-\sum_{{m=k}\atop{m\equiv N(\bmod k)}}^{N-k}
\left(\binom{m}{\frac{N-m}{k}}-\frac{1}{2^k}\binom{m-k}{\frac{N-m}{k}}\right)(-1)^{\frac{N-m}{k}}2^{-\frac{(k+1)(N-m)}{k}}
\end{align*}
Answer: Your recurrence relation is correct. I don't think you can do much better than that for general $k$, but you can find a closed form for specific values of $k$. For the first non-trivial value of $k$, the recurrence relation is
$$
p_n=p_{n-1}+(1-p_{n-3})/8\;.
$$
With $p_n=1+\lambda^n$, the characteristic equation becomes $\lambda^3-\lambda^2+1/8=0$. One solution, $\lambda=1/2$, can be guessed, and then factoring yields $(\lambda-1/2)(\lambda^2-\lambda/2-1/4)$ with the further solutions $\lambda=(1\pm\sqrt5)/4$. Thus the general solution is
$$p_n=1+c_1\left(\frac12\right)^n+c_2\left(\frac{1+\sqrt5}4\right)^n+c_3\left(\frac{1-\sqrt5}4\right)^n\;.$$
The initial conditions $p_0=0$, $p_1=0$, $p_2=1/4$ determine $c_1=0$, $c_2=-(1+3/\sqrt5)/2$ and $c_3=-(1-3/\sqrt5)/2$, so the probability is
$$
\begin{align}
p_n
&=1-\frac{1+3/\sqrt5}2\left(\frac{1+\sqrt5}4\right)^n-\frac{1-3/\sqrt5}2\left(\frac{1-\sqrt5}4\right)^n\\
&=1-\frac4{\sqrt5}\left(\left(\frac{1+\sqrt5}4\right)^{n+2}-\left(\frac{1-\sqrt5}4\right)^{n+2}\right)\;.
\end{align}
$$
Thus, for large $n$ the probability approaches $1$ geometrically with ratio $(1+\sqrt5)/4\approx0.809$.
Comment: I've added an explicit formula for the $P(N,k)$ which might be of interest to you. Note, that your $p_n=1-\frac{1}{2^n}F_{n+2}$ with $F_n$ the Fibonacci numbers. Regards,
Answer: Feller considers this problem in section XIII.7 of An Introduction to Probability Theory and Its Applications, Volume 1, Third Edition.  He shows that the probability of having no run of length $k$ in $N$ throws is asymptotic to
$$\frac{1-(1/2)\;x}{(k + 1 - kx)\; (1/2)} \cdot \frac{1}{x^{N+1}}$$
where $x$ is the least positive root of $$1 - x +(1/2)^{k+1} x^{k+1} = 0$$
(I have changed Feller's notation to agree with the problem statement and have only considered the case of a fair coin; Feller considers the more general case of a biased coin.  For more information see equation 7.11, p. 325 in the referenced document.)
Answer: A bit more practical focus than previous answers:
Main idea:

We build a "staircase":
$p$ chance to get to next step, $1-p$ chance to fall down and have to restart (or "reflip"). Except for the highest step where we always stay (whenever we manage to get there).
We need $k+1$ steps to "remember" where on the stairs we are for $k$ flips in a row.

We can use this to build a matrix for a Markov chain:
We can build a block matrix:$$\frac{1}{2}\left[\begin{array}{cc}2&1&\bf 0^T\\\bf 0&\bf0&\bf I_k\\0&1&\bf 1^T \end{array}\right]$$
(For the special case $k = 5$). We build a stochastic matrix:
$${\bf P} = \frac{1}{2}\left[\begin{array}{cccccc}2&1&0&0&0&0\\0&0&1&0&0&0\\0&0&0&1&0&0\\0&0&0&0&1&0\\0&0&0&0&0&1\\0&1&1&1&1&1\end{array}\right]$$
Now our answer will simply be $$[1,0,{\bf 0}]\, {\bf P}^k\, [{\bf 0},0,1]^T$$
Which is a scalar product using ${\bf P}^k$ as a gramian matrix.
Now to calculate this in practice one could probably in general (for general $p$) benefit from a canonical transformation of $\bf P$, but it's doubtable in this case as the matrix is already sparse with literally only sums and permuations and bit shifts required on the vector elements.
Answer: One solution uses a Markov chain. Let state $i=0,1,\dots,k-1$ be the state that we've never had any sequence of $k$ tails, and currently ending in $i$ consecutive tails. Let state $k$ be the state when we have already had $k$ tails in a row somewhere.
Then the transition matrix is $(k+1)\times(k+1)$:
$$M_k=\begin{pmatrix}
1/2&1/2&0&0&\cdots&0&0\\
1/2&0&1/2&0&\cdots&0&0\\
1/2&0&0&1/2&\cdots&0&0\\
\vdots&\,&&&&&\vdots\\
1/2&0&0&0&\cdots&1/2&0\\
1/2&0&0&0&\cdots&0&1/2\\
0&0&0&0&\cdots&0&1
\end{pmatrix}
$$
Then the probability you want is:
$$p_{N,k}=\begin{pmatrix}1&0&0&\cdots&0&0\end{pmatrix}M_k^N\begin{pmatrix}0\\\vdots\\0\\1\end{pmatrix}$$
We can diagonalize $M_k$ to get get $p_{N,k}$ in terms of the eigenvalues of $M_k,$ but in general we can't get nice closed forms for those eigenvalues or the related constants. We can compute this value exactly by "repeated squaring," taking $O(\log_2 N)$ matrix multiplications. The characteristic polynomial for $M_k$ might let us avoid a lot of Matrix multiplications, if $N$ is much larger than $k.$
$1$ is the largest eigenvalue, and the second highest real eigenvalue will be a value $\lambda_k$ which dominates the other terms, so you will get something like:
$$p_{N,k}\sim 1-c_k\lambda_k^N$$ for some $c_k$ constant. $\lambda_k$ is half of the largest real rook to:
$$x^k-(x^{k-1}+x^{k-2}+\cdots+x+1),$$ but it is a little less obvious what $c_k$ is.


Find the equation of the plane that passes through a point and is parallel to to a plane

Question: Find the equation of the plane that passes through the point $(8,-6,-7)$ and is parallel to the plane $9x-y-z= 8$.
Using the linear definition:
$9x-y-z-8=0$ is a plane with normal vector (9,-1,-1). So I think I can use this as my normal vector for the plane since two parallel planes would have the same normal vector?
Answer: Correct.  And shift coordinates to your new point.
$9 (x-8) - (y+6) - (z+7) = 0$ gives you the new plane
Answer: Alternatively, a plane is parallel to $9x-y-z = 8$ if and only if it is $9x-y-z = k$ for some constant $k$.  We can find this specific $k$ by plugging in the point $(8, -6, -7)$:
$$
k = 9(8) - (-6) - (-7) = 85
$$
So the equation of the plane is $9x-y-z = 85$.  Note that this isn't any different in essence from Phillip's and your solution (how could it be, really?); it's just a slightly different way of looking at the same problem.
Answer: your new plane will have an equation of the form
$9x-y-z=D$
the point $(8,-6,-7)$ is in the plane if
$72+6+7=D=85$
thus the equation we are looking for is
$9x-y-z=85$.


Como clonar um elemento com jQuery e adicionar um novo name?

Question: Estou usando o plugin jQuery CloneYa
para clonar elementos de um formulário com jQuery, mas ele é um pouco limitado, queria clonar os inputs mas preciso incrementar o name quando for feito isso, por exemplo:
<input type="text" name="produtos[qtd][1]">

O próximo input clonado teria que ter o name produtos[qtd][2], se houver uma maneira de fazer isso com este plugin ou de outra maneira, a consequência de clonar os inputs assim é que o plugin de validação só valida o primeiro input (jquery.validate).
Este é um exemplo de como está um formulário meu
<form method="post">

            <select name="list">
                <option>selecione...</option>
                <option>opção 1</option>
                <option>opção 2</option>
                <option>opção 3</option>
                <option>opção 4</option>
            </select>
            <input type="text" name="produtos[qtd][]">
            <button type="button" id="add">+</button>
            <button type="button" id="remove">-</button>

    <input type="submit">
</form>

JSFiddle
Comment: Para clonar um elemento em js: http://pt.stackoverflow.com/q/4321/3082
Comment: o plugin exige apenas o comando de inicialização, que é o que esta descrito na documentação. fora isso, não encontrei nada lá que ajudasse a resolver o problema em incrementar os names
Answer: Para clonar o seu elemento, e setar o name para o name anterior com um valor +1, basta fazer da seguinte forma:
function adicionar(){
  var ElementoClonado = $(this.parentNode).clone(); //clona o elemento
  var str = $(ElementoClonado).children('input').eq(0).attr('name').split("["); //divide o name por "["
  console.log(str);
  var intQtd = parseInt(str[2].split("]")[0]); //resgata o numero entre "[" e "]"
  console.log(intQtd);
  var newName = "produtos[qtd]["+(intQtd+1)+"]"; //novo valor name somado +1 do original
  ElementoClonado.children('input').eq(0).attr('name', newName); //seta o novo name para o elemento clonado
  $('.wrapper').append(ElementoClonado);
  $('.add').on("click", adicionar);
  $('.remove').on("click", remover);
  $(this).unbind("click");
}
function remover(){
  $(this.parentNode).remove();
}
$('.add').on("click", adicionar);
$('.remove').on("click", remover);

Porém, você deve lembrar que não se pode ter mais de um HTML ID igual, por isso mude todo seu html para utilizar classes, e também você deve iniciar com o numero 1 da "qtd" desta forma:
<form method="post">

        <select name="list">
            <option>selecione...</option>
            <option>opção 1</option>
            <option>opção 2</option>
            <option>opção 3</option>
            <option>opção 4</option>
        </select>
        <input  type="text" name="produtos[qtd][1]">
        <button type="button" class="add">+</button>
        <button type="button" class="remove">-</button>

    <input type="submit">
    </form>

Exemplo funcionando no JSFiddle
Comment: congratulations!
Comment: tem um fiddle? para exemplo?
Comment: é possivel clonar a div com a classe ".toclone" com seus inputs dentro e fazer esse script funcionar da mesma maneira? porque na verdade eu clono o "wrapper" inteiro com aqueles dois inputs dentro.
Comment: sim é possível, vou editar a resposta e fazer um fiddle
Comment: Editei, vê se é isso que você quer @LeandroRuel eu também fiz o de remover ^^
Comment: ô beleza! estou olhando nesse exato momento!


Como fazer um gif seja executado apenas uma vez?

Question: Tenho um GIF e quero que ele apenas seja executado uma vez, sem haver repetições. Há alguma forma de fazer isso? Como?
Answer: Olha Daniel encontrei algo que possa te ajudar: https://github.com/krasimir/gifffer
Com ele você consegue fazer o gif "tocar" uma única vez.
Inclua o gifffer.min.js na página.

Ao invés de atribuir valor no src da sua imagem, utilize o data-gifffer.

E por último adiciona a chamada do Grifffer(); aonde quiser. Por exemplo:
window.onload = function() {
    Gifffer();
}

Comment: Poxa que bacana, não conhecia o gifffer
Comment: @RBoschini fiz uma poc com ele agora, pois fiquei tão curioso, sempre quis fazer isso com gif e nunca consegui hehehe
Answer: Abra a imagem em um editor gráfico e remova a opção de loop infinito.
Agora, com Javascript você pode criar uma imagem estática em um canvas. E depois de um tempo (no caso, duração do .gif) a imagem animada será removida e no lugar dela o canvas será exibido:
Fiddle

(function(){

  var $gif         = document.querySelector('.gif'),
      GIF_DURATION = 1050;

  function handleGif(){

    // Cria o canvas com o mesmo tamanho da imagem.
    var $canvas = document.createElement('canvas');
    $canvas.setAttribute('width', $gif.width);
    $canvas.setAttribute('height', $gif.height);

    // Desenha a imagem no canvas
    var context = $canvas.getContext('2d');
    context.drawImage($gif, 0, 0);

    // Remove a imagem e insere o canvas
    document.body.removeChild($gif);
    document.body.appendChild($canvas);
  }

  var timeout = setTimeout(function(){
   handleGif();
    clearTimeout(timeout);
  }, GIF_DURATION);

})();


D7 - Can't set selected value of a webform select element

Question: I'm trying to set the selected value of a webform select form element before it is rendered. I'm using the below code and the textfields are working just fine but no luck with the select options.
function mytheme_preprocess_webform_form(&$vars) {
    $vars['form']['submitted']['emailAddress']['#value'] = 'email@example.com'; //This is working
    $vars['form']['submitted']['country']['#selected'] = 'BARBADOS'; // This is not working even though #default value is used instead
}

I can't figure it out why this is not working for select field. I would be glad if someone could help me.
Thanks in advance.
Answer: You can set value by using #value
$vars['form']['submitted']['country']['#value'] = 'BARBADOS';

But make sure that the select option key should be same
Example:
<option value="BARBADOS">BARBADOS</option>
$vars['form']['submitted']['country']['#value'] = 'BARBADOS'; //will work

<option value="barbados">BARBADOS</option>
$vars['form']['submitted']['country']['#value'] = 'BARBADOS'; //will not work
$vars['form']['submitted']['country']['#value'] = 'barbados'; //will work

Comment: Thanks man, I've spent hours for this, didn't expect it would be that easy.
Comment: Always welcome :)
Answer: For webform forms, I think you have to set #value to TRUE on the option itself.
Something like this should work:
$vars['form']['submitted']['country']['BARBADOS']['#value'] = TRUE;

If there are any other default values, you'll have to set those to FALSE.
Comment: Thanks a lot but nope, didn't work either


Use variable inside "from" in firebird

Question: I try use variable inside "from" SELECT COUNT(*) FROM :T_NAME, but is not work. How can i fix this? This my code:
SET TERM ^ ;
CREATE OR ALTER PROCEDURE Myfunction
RETURNS(
    T_NAME varchar(100),
    NUM_RECORDS integer
)
AS
BEGIN
    FOR SELECT RDB$RELATION_NAME FROM RDB$RELATIONS
        WHERE (RDB$SYSTEM_FLAG <> 1 OR RDB$SYSTEM_FLAG IS NULL) AND RDB$VIEW_BLR IS NULL
        ORDER BY RDB$RELATION_NAME
        INTO :T_NAME
    DO
    BEGIN
        SELECT COUNT(*) FROM :T_NAME
        INTO :NUM_RECORDS;
        SUSPEND;
    END
END^
SET TERM ; ^

Comment: You need dynamic SQL for that
Answer: You can't parametrize object names. You will need to dynamically build the query (which if you aren't careful may leave you open to SQL injection).
Specifically you need to use:
...
BEGIN
    EXECUTE STATEMENT 'select count(*) from "' || T_NAME || '"'
        INTO :NUM_RECORDS;
    SUSPEND;
END

This should be safe except for table names that contain double quotes. I haven't explicitly checked the behavior with single quotes in an object name, which technically is possible. You may need to take extra steps to protect against these forms of SQL injection if you use this in real production code.

Use variable inside "from" in firebird


Is post-sudden-power-loss filesystem corruption on an SSD drive's ext3 partition "expected behavior"?

Question: My company makes an embedded Debian Linux device that boots from an ext3 partition on an internal SSD drive.  Because the device is an embedded "black box", it is usually shut down the rude way, by simply cutting power to the device via an external switch.
This is normally okay, as ext3's journalling keeps things in order, so other than the occasional loss of part of a log file, things keep chugging along fine.
However, we've recently seen a number of units where after a number of hard-power-cycles the ext3 partition starts to develop structural issues -- in particular, we run e2fsck on the ext3 partition and it finds a number of issues like those shown in the output listing at the bottom of this Question.  Running e2fsck until it stops reporting errors (or reformatting the partition) clears the issues.
My question is... what are the implications of seeing problems like this on an ext3/SSD system that has been subjected to lots of sudden/unexpected shutdowns?
My feeling is that this might be a sign of a software or hardware problem in our system, since my understanding is that (barring a bug or hardware problem) ext3's journalling feature is supposed to prevent these sorts of filesystem-integrity errors.  (Note:  I understand that user-data is not journalled and so munged/missing/truncated user-files can happen; I'm specifically talking here about filesystem-metadata errors like those shown below)
My co-worker, on the other hand, says that this is known/expected behavior because SSD controllers sometimes re-order write commands and that can cause the ext3 journal to get confused.  In particular, he believes that even given normally functioning hardware and bug-free software, the ext3 journal only makes filesystem corruption less likely, not impossible, so we should not be surprised to see problems like this from time to time.
Which of us is right?
Embedded-PC-failsafe:~# ls
Embedded-PC-failsafe:~# umount /mnt/unionfs
Embedded-PC-failsafe:~# e2fsck /dev/sda3
e2fsck 1.41.3 (12-Oct-2008)
embeddedrootwrite contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Invalid inode number for '.' in directory inode 46948.
Fix<y>? yes

Directory inode 46948, block 0, offset 12: directory corrupted
Salvage<y>? yes

Entry 'status_2012-11-26_14h13m41.csv' in /var/log/status_logs (46956) has deleted/unused inode 47075.  Clear<y>? yes
Entry 'status_2012-11-26_10h42m58.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47076.  Clear<y>? yes
Entry 'status_2012-11-26_11h29m41.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47080.  Clear<y>? yes
Entry 'status_2012-11-26_11h42m13.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47081.  Clear<y>? yes
Entry 'status_2012-11-26_12h07m17.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47083.  Clear<y>? yes
Entry 'status_2012-11-26_12h14m53.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47085.  Clear<y>? yes
Entry 'status_2012-11-26_15h06m49.csv' in /var/log/status_logs (46956) has deleted/unused inode 47088.  Clear<y>? yes
Entry 'status_2012-11-20_14h50m09.csv' in /var/log/status_logs (46956) has deleted/unused inode 47073.  Clear<y>? yes
Entry 'status_2012-11-20_14h55m32.csv' in /var/log/status_logs (46956) has deleted/unused inode 47074.  Clear<y>? yes
Entry 'status_2012-11-26_11h04m36.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47078.  Clear<y>? yes
Entry 'status_2012-11-26_11h54m45.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47082.  Clear<y>? yes
Entry 'status_2012-11-26_12h12m20.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47084.  Clear<y>? yes
Entry 'status_2012-11-26_12h33m52.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47086.  Clear<y>? yes
Entry 'status_2012-11-26_10h51m59.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47077.  Clear<y>? yes
Entry 'status_2012-11-26_11h17m09.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47079.  Clear<y>? yes
Entry 'status_2012-11-26_12h54m11.csv.gz' in /var/log/status_logs (46956) has deleted/unused inode 47087.  Clear<y>? yes

Pass 3: Checking directory connectivity
'..' in /etc/network/run (46948) is <The NULL inode> (0), should be /etc/network (46953).
Fix<y>? yes

Couldn't fix parent of inode 46948: Couldn't find parent directory entry

Pass 4: Checking reference counts
Unattached inode 46945
Connect to /lost+found<y>? yes

Inode 46945 ref count is 2, should be 1.  Fix<y>? yes
Inode 46953 ref count is 5, should be 4.  Fix<y>? yes

Pass 5: Checking group summary information
Block bitmap differences:  -(208264--208266) -(210062--210068) -(211343--211491) -(213241--213250) -(213344--213393) -213397 -(213457--213463) -(213516--213521) -(213628--213655) -(213683--213688) -(213709--213728) -(215265--215300) -(215346--215365) -(221541--221551) -(221696--221704) -227517
Fix<y>? yes

Free blocks count wrong for group #6 (17247, counted=17611).
Fix<y>? yes

Free blocks count wrong (161691, counted=162055).
Fix<y>? yes

Inode bitmap differences:  +(47089--47090) +47093 +47095 +(47097--47099) +(47101--47104) -(47219--47220) -47222 -47224 -47228 -47231 -(47347--47348) -47350 -47352 -47356 -47359 -(47457--47488) -47985 -47996 -(47999--48000) -48017 -(48027--48028) -(48030--48032) -48049 -(48059--48060) -(48062--48064) -48081 -(48091--48092) -(48094--48096)
Fix<y>? yes

Free inodes count wrong for group #6 (7608, counted=7624).
Fix<y>? yes

Free inodes count wrong (61919, counted=61935).
Fix<y>? yes

embeddedrootwrite: ***** FILE SYSTEM WAS MODIFIED *****

embeddedrootwrite: ********** WARNING: Filesystem still has errors **********

embeddedrootwrite: 657/62592 files (24.4% non-contiguous), 87882/249937 blocks

Embedded-PC-failsafe:~#
Embedded-PC-failsafe:~# e2fsck /dev/sda3
e2fsck 1.41.3 (12-Oct-2008)
embeddedrootwrite contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Directory entry for '.' in ... (46948) is big.
Split<y>? yes

Missing '..' in directory inode 46948.
Fix<y>? yes

Setting filetype for entry '..' in ... (46948) to 2.
Pass 3: Checking directory connectivity
'..' in /etc/network/run (46948) is <The NULL inode> (0), should be /etc/network (46953).
Fix<y>? yes

Pass 4: Checking reference counts
Inode 2 ref count is 12, should be 13.  Fix<y>? yes

Pass 5: Checking group summary information

embeddedrootwrite: ***** FILE SYSTEM WAS MODIFIED *****
embeddedrootwrite: 657/62592 files (24.4% non-contiguous), 87882/249937 blocks
Embedded-PC-failsafe:~#
Embedded-PC-failsafe:~# e2fsck /dev/sda3
e2fsck 1.41.3 (12-Oct-2008)
embeddedrootwrite: clean, 657/62592 files, 87882/249937 blocks

Comment: Neither option would fix this. We still use devices with supercapacitors in ZFS, and battery or flash-protected cache is recommended for ext4 in server applications.
Comment: Have you all thought of changing to ext4 or ZFS?
Comment: I've thought about changing to ext4, at least... would that help address this issue?  Would ZFS be better still?
Answer: You're both wrong (maybe?)... ext3 is coping the best it can with having its underlying storage removed so abruptly.
Your SSD probably has some type of onboard cache. You don't mention the make/model of SSD in use, but this sounds like a consumer-level SSD versus an enterprise or industrial-grade model.
Either way, the cache is used to help coalesce writes and prolong the life of the drive. If there are writes in-transit, the sudden loss of power is definitely the source of your corruption. True enterprise and industrial SSD's have supercapacitors that maintain power long enough to move data from cache to nonvolatile storage, much in the same way battery-backed and flash-backed RAID controller caches work.
If your drive doesn't have a supercap, the in-flight transactions are being lost, hence the filesystem corruption. ext3 is probably being told that everything is on stable storage, but that's just a function of the cache.
Comment: @pusi Old now, but you mention this: `as long as the drive correctly reports whether it has a write cache and obeys commands to flush it, the journal guarantees that the metadata will not be inconsistent.` That's the thing: because of storage controllers that tend to assume older disks, SSDs **will sometimes lie** about whether data is flushed. You do need that supercap.
Comment: Sorry to you and everyone who upvoted this, but you're just wrong.  Handling the loss of in progress writes is exactly what the journal is for, and as long as the drive correctly reports whether it has a write cache and obeys commands to flush it, the journal guarantees that the metadata will not be inconsistent.  You only need a supercap or battery backed raid cache so you can enable write cache without having to enable barriers, which sacrifices some performance to maintain data correctness.
Comment: @psusi The SSD in use probably has cache explicitly enabled or relies on an internal buffer regardless of the OS_level setting. The data in that cache is what a [supercapacitor-enabled SSD](http://thessdguy.com/how-controllers-maximize-ssd-life-external-data-buffering/) would protect.
Comment: The data in the cache doesn't need protecting if you enable IO barriers.  Most consumer type drives ship with write caching disabled by default and you have to enable it if you want it, exactly because it causes corruption issues if the OS is not careful.
Answer: You are right and your coworker is wrong.  Barring something going wrong the journal makes sure you never have inconsistent fs metadata.  You might check with hdparm to see if the drive's write cache is enabled.  If it is, and you have not enabled IO barriers ( off by default on ext3, on by default in ext4 ), then that would be the cause of the problem.
The barriers are needed to force the drive write cache to flush at the correct time to maintain consistency, but some drives are badly behaved and either report that their write cache is disabled when it is not, or silently ignore the flush commands.  This prevents the journal from doing its job.
Comment: -1 for reading-comprehension...
Comment: @ewwhite, maybe *you* should try reading, and actually writing a useful response instead of this childish insult.
Comment: +1 this answer probably could be improved, as any other answer in any QA. But at least provides some light and hints. @downvoters: improve the answer yourselves, or comment on possible flows, but downvoting this answer without proper justification is just disgusting!


Is class an object in JAVA?

Question: Class is defined as a collection of Objects in every OOPS Language, but I'm confused is a class an object by itself ?
If yes, Is class an Object in every OOPS language ?
Edit :  By class I mean the structure defined as class NameOfClass{ ... }
Comment: Also by class do you mean `java.lang.Class` or structure defined as `class NameOfClass{ ... }`?
Comment: yes, it is an object of type java.lang.Class.
Comment: "Class is defined as a collection of Objects in every OOPS Language" that is the first time I hear it. Can you link *any* source of such claim?
Answer: In simple terms, think of a Class as a layout of a building and the Object as the building itself. With one layout you can build multiple buildings but each different from one and another. If you've a data member in your Class where you point to a different Class, they don't exist until you create a instance of your class.
So no Class it not an object by itself. But every Java object has an instance of the java.lang.Class describing it. Such instances are objects though.

Is class an object in JAVA?


What two keys are associated with a fix dominant 7th chord?

Question: The following exercise has me bewildered:

As you can see I instinctively flatted the E and made the key the dominant 7th chord of Bb major.  What other key could the author be looking for?  Unfortunately there are no examples to go by.
Alternatively, I could have sharped the F, A, and C to make it the dominant 7th chord of B major.  But neither of these options can simultaneously describe a dominant 7th chord in two keys, correct?
The chord as I've modified it also is the dominant 7th chord of Bb minor; is that what I'm supposed to put as the second key?
I apologize if this question is not concrete enough, but I'm hoping someone with more experience will see through this mystery.
Comment: I cannot see the image; are you able to re-upload it? But based on your question, a single dominant 7th chord will be the dominant in the major and minor form of a given key; I don't see how it can be a dominant in two keys with two different tonics.
Comment: I deleted and re-uploaded the image.  Hopefully it's now visible.  But either way I believe you have understood my question perfectly already so it probably will not be helpful.
Answer: The exercise means well, but the directions are a bit poor; they could have worded their intentions better to make it more clear.
A single dominant 7th chord will be the dominant in the major and minor form of a given key (e.g., C major and C minor). Although all major-minor 7th chords can appear in any key, each is only the true dominant 7th (in other words, V7) of that single major/minor pair.
As such, your opening F7 will be in the key of B-flat major and B-flat minor. (Or, if you write F-sharp 7, it's B major and B minor.)
Comment: Ah, that's fair. Then the directions aren't so bad. (PS: check your last two on question #1 of that previous page, and make sure D is in the bass!)
Comment: I actually just took a look at the previous page's exercises, which I did last night.  On that page, they take turn getting you to identify the major and minor key (using key signatures).  With that context, it actually makes sense to give both keys since I am asked to use accidentals here.  Anyways it still left me feeling a bit uncertain, so thanks very much for confirming.
Comment: Picture of previous page:  https://i.imgur.com/8PWWxJd.jpg
Comment: Thanks for pointing those mistakes out!  :)   I've fixed them now; but I could definitely use more practice at that particular exercise.  I should just sit down and do it with every note at some point.


Visually split Path into two side-by-side colors in WPF

Question: If I have a rather meandering Path in my WPF app, is there a way I can make it appear as two differently-colored Paths of identical widths side-by-side? I'd rather not try to hand-code the whole thing again with slightly different values. I thought of using a Brush, but the list of Brushes doesn't appear to have one such.
Edit: I want a Path divided sharply by color, even if it curves, like this:
Comment: Could you add a small image of what you are trying to obtain, not sure I understood. Maybe is something as `LinearGradientBrush` you are looking for?
Comment: Ok, so I have no idea if such a thing is possible "at once". I did something similar for another application (in my case, I have a distance between the 2 lines, but you could put distance = thickness of line). I made a function `MoveToRight`, then I drew all my pathes with a parallel line. If nobody answers or have a better idea, this would make the deal.
Comment: @Siegfried.V Interesting idea! I was trying to do something similar by drawing two identical lines and setting one's top margin and the other's bottom margin negative. Maybe I could make a function `MoveOutward`.
Comment: As for me, I worked from `Contour` class I made, with X1, X2, Y1, Y2, Radius if needed. So having a List, in order to have a clean result, you even can calculate intersections of parallel lines. Then there is a little bit of mathematics for the function, but nothing so difficult.
Comment: Oh, wow. I like that. We'll see. I'm also trying something with a scaled duplicate.
Answer: Made a little search, and found that also :
Two-color Path object
Timwi answer :
<StackPanel Orientation="Horizontal">
    <StackPanel.LayoutTransform>
        <ScaleTransform CenterX="0" CenterY="0" ScaleX="15" ScaleY="15" />
    </StackPanel.LayoutTransform>

    <Grid Margin="-5,0,0,0">
        <Path Fill="Blue" Stroke="Transparent">
            <Path.Data>
                <PathGeometry>M10,10 C20,10 10,20 20,20 L20,19 C11,19 21,9 10,9</PathGeometry>

            </Path.Data>
        </Path>
        <Path Fill="Red" Stroke="Transparent">
            <Path.Data>
                <PathGeometry>M10,10 C20,10 10,20 20,20 L20,21 C9,21 19,11 10,11</PathGeometry>

            </Path.Data>
        </Path>
    </Grid>
</StackPanel>

So "playing" with margin may be much easier that the other options I told you about for what you need.
Answer: DropShadowEffect solved my issue.


All my harddrives are around 10 MB/s read/write

Question: I have a HP N54L MicroServer (AMD N54L, 4GB RAM) running on Lubuntu (doesn't really matter happens on Ubuntu too). In there are 4 HDDS each 1 TB, Samsung HD103SJ. I tried every single BIOS setting (AHCI, IDE) as well as other settings, but the read and write speed of those hdds is around 10 MB/s. I'm measuring this with dd. I can't figure out whats the problem.
Comment: Add `bs=1m` to the dd command and test again.
Comment: Hello! I already tried this...
Comment: Sounds a bit like a misaligned partition or tiny inode size. What's the output of `tune2fs -l /dev/sdaX | grep Inode` (replace sdaX with one of the drives, or the volume if using LVM)
Comment: @ChrisS All 4 drives are showing this:

Inode count:            61054976
Inodes per group:       8192
Inode blocks per group: 512
Inode size:             256
Answer: If you do not set buffer size (bs, obs or ibs), it defaults to 512. If you have a 4k drive this is  inefficient. Also moving small chunks of data and waiting for each of them to arrive will lower the bandwidth.
You can use hdparm -tT /dev/sd...
You can also increase the size of dd buffer.
But you should test your disk with a disk benchmark like bonnie++ or iozone.
Comment: hdparm gives me 400 - 1000 MB/s but why does moving a 20 GB file take 30 minutes?
Comment: Are you moving it on the same disk, on another disk? The  real speed vs disk raw speed could be affected (positively and negatively) by alignment, fragmentation, encryption, snapshot, compression, deduplication, caching, RAID level, mount options...
Comment: So first determine what is the raw speed of the disk (both for linear and random operations), then compare it with the current speed.
Comment: You can use `strace -c cp ....` to determine where the CPU time is spend (reads/writes vs userspace). Then you can use `sysdig`, `ftrace/trace-cmd` or `sytemtap` to see what is happening at the kernel level.


Likelihood function as number of observations increases

Question: If we have $n$ iid observations from some $X \sim p(\cdot|\theta)$, what happens to the likelihood function $p(x_1,\dots,x_n|\theta)$ as $n\rightarrow \infty$?
I plotted the product of several $\mathcal{N}(0,1)$, and it got flatter and more spread out as I took more products. Is it generally true that the likelihood of $n$ observations gets more and more disperse as $n$ increases?
E.g. suppose the likelihood is in the exponential family, which has the form
$$p(x_1, \dots, x_n|\theta) = \prod_{i=1}^n h(x_i) \exp \bigg\{ \theta^\top \big(\sum_{i=1}^n T(x_i)\big) - n A(\theta)\bigg\}$$
I'm having trouble visualizing what happens as $n$ increases in this case.
Answer: Here are three slides from my statistical modelling course illustrating why the average log-likelihood function concentrates with the number $n$ of iid observations:

This second picture represents $L_n(\theta;\mathbf x)^{1/n}$ as $n$ increases. This function stabilises around its (entropy) limiting function
$$\exp\int\log p(x|\theta) \text dF(x)$$
Comment: Answer to the first question: no. $L_n(\theta;x_1,\ldots,x_n)^{1/n}$ converges almost surely (the $\mathcal L$ is not needed here) to$$\exp\int\log p(x|\theta) \text dF(x)$$not to $p(x|\theta)$ (for one thing there is no $x$ in the limit).
Comment: I can't access the course without login, but this is great, thank you!
Comment: the second picture doesn't seem to converge to a delta function, why is that? What is $\mathcal{P}(3)$?
Comment: Sorry, now I'm confused. If we're summing log likelihoods then it seems like the overall log likelihood will become more diffuse. And even though the average of the log likelihoods approaches its expectation, I don't understand why that relates to concentration
Comment: I also don't think I understand the first image. Does the sequence of likelihoods correspond to increasing $n$? Why does the peak height decrease? (Seems like the spike gets both narrower and shorter, which doesn't make sense)
Comment: In the sequence of Poisson likelihoods (Fig. 1), the scale decreases with $n$. Rescaling with a power $1/n$, the rescaled likelihood, function of $\theta$, converges to the function of $\theta$ in slide #2, not to a Dirac mass function. Since$$\dfrac{1}{n}\sum_i \log f(x_i|\theta)$$converges to a negative quantity, obviously$$\sum_i \log f(x_i|\theta)$$diverges to $-\infty$...
Comment: I see, just to make sure I get it - so the scaled-down log likelihood converges to the model $ \log p(x|\theta)$ as $n$ increases, by LLN. (You've plotted likelihood, not log likelihood, right?) And the unscaled log likelihood goes to $-\infty$ while the likelihood turns into something very spread out and near 0. @Xi'an
Comment: What is the difference between $L$ and $\mathcal{L}$? (Sorry, I am pretty new to statistics) Is $L_n$ the empirical log likelihood while $\mathcal{L}$ is the 'true'/model log likelihood?
Comment: I think I get it, thanks a lot for your help. Would you have any suggested references on asymptotics of the likelihood function?
Comment: Not an introductory reference.


Output not coming while scraping and storing in database

Question: I thought of storing my scraped data from amazon in a database using SQLite3. First I scraped and stored that in .csv format. It worked perfectly fine. But when I tried to store that in a database, it says:
Error:
Cost = r.html.find('#priceblock_ourprice', first=True).text.strip()[1:]
AttributeError: 'NoneType' object has no attribute 'text'
The code I first used to get in .csv format was:
import csv
from requests_html import HTMLSession

csv_file = open('Laptop2.csv', 'w', encoding = 'utf-8')
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['Laptop','Cost', 'Savings'])

urls = ["https://www.amazon.in/gp/product/B091HGK1B6/ref=ox_sc_act_title_1?smid=A372Y0DOIAPTGJ&psc=1","https://www.amazon.in/gp/product/B08D3T9CK3/ref=ox_sc_act_title_2?smid=A5QX138YR4YQ&psc=1","https://www.amazon.in/gp/product/B096W63DZV/ref=ox_sc_act_title_3?smid=A339C6POJNB9GM&psc=1","https://www.amazon.in/gp/product/B0928TPR8H/ref=ox_sc_act_title_4?smid=A2YBFAXWY0FFA4&psc=1"]

for url in URLs:
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
    }

    session = HTMLSession()
    r = session.get(url, headers = header)
    r.html.render(timeout=120)

    title = r.html.find('#productTitle', first=True).text.strip()[:25]
    Cost = r.html.find('span#priceblock_ourprice', first=True).text.strip()[1:]
    Savings = r.html.find('.priceBlockSavingsString', first=True).text.strip()[1:]

    csv_writer.writerow([title, Cost, Savings])

csv_file.close()

Then I used this code to store in SQLite3 DB:
from requests_html import HTMLSession
import sqlite3
import datetime

connection = sqlite3.connect('laptop.db')
c = connection.cursor()

c.execute('''CREATE TABLE Tracker(Date DATE, Name TEXT, price REAL, Savings REAL)''')

urls = ["https://www.amazon.in/gp/product/B091HGK1B6/ref=ox_sc_act_title_1?smid=A372Y0DOIAPTGJ&psc=1","https://www.amazon.in/gp/product/B08D3T9CK3/ref=ox_sc_act_title_2?smid=A5QX138YR4YQ&psc=1","https://www.amazon.in/gp/product/B096W63DZV/ref=ox_sc_act_title_3?smid=A339C6POJNB9GM&psc=1","https://www.amazon.in/gp/product/B0928TPR8H/ref=ox_sc_act_title_4?smid=A2YBFAXWY0FFA4&psc=1"]

for url in urls:

    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
    }

    session = HTMLSession()
    r = session.get(url, headers = header)
    r.html.render(timeout=120)

    current_date = datetime.datetime.now()
    title = r.html.find('#productTitle', first=True).text.strip()[:25]
    Cost = r.html.find('#priceblock_ourprice', first=True).text.strip()[1:]
    Savings = r.html.find('.priceBlockSavingsString', first=True).text.strip()[1:]

    c.execute('''INSERT INTO Tracker VALUES(?,?,?,?)''', (current_date, title, Cost, Savings))

connection.commit()
c.execute(''' SELECT price FROM Tracker''')
results = c.fetchall()
print(results)
connection.close()

I feel like I made some mistake in sqlite3 or requests_html. Please help me to solve this issue.
Comment: It is not an issue with sqlite - Please focus on your `requests_html` part and the selector - Improving  your question, would be great.
Comment: Oh, I feel like the selector part is kinda correct but I'm not sure.
Comment: You have `span#priceblock_ourprice` in the first block of code for `Cost`, but just `#priceblock_ourprice` in your second block of code.
Answer: We should not use the render function when there is no data in json form. So If I remove that line, this problem is solved.


Special Characters Are Read Wrong - File I/0

Question: This code reads a file byte per byte in order to duplicate it:
 fplain = fopen("plaintext", "rb");
 fcypher = fopen("cyphertext", "wb");

 for(j = 0; j < Nb; j++){
    for(i = 0; i < 4; i++){
            if(feof(fplain))
                break;
            fread(&in[i][j], sizeof(unsigned char), sizeof(unsigned char), fplain);
            fwrite(&in[i][j], sizeof(unsigned char), sizeof(unsigned char), fcypher);
    }
 }

The problem is that the input file contains special characters that are not being read correctly:
2Cö¨Z011¢à74

It seems that the end of the file is detected before, the result in the output file is:
2Cö¨Z011

I use "rb" mode in the fopen() function.
Comment: `2Cö¨Z011¢à74` are **twelve** characters.
Comment: Which value contains variable `Nb`?
Comment: @Howard 4 (int). The input file has 16 characters written in hex ascii.
Comment: Thus, depending on the encoding of your file (and on the size of char of your compiler), you may read not enough bytes.
Comment: @Howard The compiler is gcc, and the file has no extension.
Comment: looks like your input is written using 16bit characters - you are reading 4x4x8bit so you get 8 characters
Comment: I'm confused - is the input as described in the question or is it 'hex ascii'. And you might want to clarify what 'hex ascii' means to you, because I have a feeling you might be using a different meaning that I do, which is that the file contains only the characters '0'-'9', 'a'-'f', 'A'-'F', maybe with whitespace/newlines.
Answer: A byte encoded in hex occupies two bytes. To produce 16 characters you have to read 32 bytes from the file; if you read 16 bytes you can produce only 8 characters.
On the other hand, if by "16 hex encoded chars" you mean that the file contains only 16 bytes, you can't expect to read 12 characters (24 bytes). In that case the last 4 characters in your expected output are probably random garbage produced by a buggy program, and there's no way to reproduce them reliably.
Comment: Here: "The input file has 16 characters written in hex ascii." I guess you could interpret that as saying there are 16 hex characters, which would mean the file contains data for 8 characters, but that contradicts the expectation of being able to read 12 characters from the file.


Inserir ID em Tabela com 13.346 linhas com LOOP

Question: Estou precisando atualizar uma tabela com 13 mil linhas. E essa tabela contem um campo chamado "faixa_cep_id" e todos os ids estão 0. Preciso atualizar isso com um loop para não duplicar os campos (EX: 1, 2, 3, 4...). Alguém poderia dar essa ajuda?
DROP TABLE IF EXISTS `pl_joseanmatias_faixa_cep_peso`;
CREATE TABLE `pl_joseanmatias_faixa_cep_peso` (
  `faixa_cep_id` int(11) NOT NULL,
  `title` varchar(150) NOT NULL,
  `weight_min` float NOT NULL,
  `weight_max` float NOT NULL,
  `postcode_min` int(11) NOT NULL,
  `postcode_max` int(11) NOT NULL,
  `cost` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Comment: Os dados que você quer inserir vem de outra tabela? Se vem, existe um relacionamento entre a tabela que quer alterar e a tabela aonde se encontra os dados? Sua pergunta ficou meio vaga, especifique com um exemplo.
Comment: @RafaelSalomão não... Quero que inicie a inserção de ids automaticamente contando a partir de 1.
Ficando:
1
2
3
4

Mas sem interferir nos outros campos da tabela...
Comment: Ahhhh, você quer um campo de auto-incremento? Ou seja, faixa_cep_id conta de 1 até as 13 mil correto?
Comment: @RafaelSalomão isso mesmo :D
Comment: @RafaelSalomão aconteceu um erro. Tentei te marcar la em baixo mas não consegui
Comment: @RafaelSalomão atualizei o post com uma sql pra criação da tabela
Comment: @RafaelSalomão e como eu faço isso?
Comment: Não vejo coluna de auto-incremento na sua tabela. Você definiu o atributo : faixa_cep_id como índice? Ela tem que ser um indice de sua tabela. Postei lá em baixo como cria o indice.
Comment: @RafaelSalomão
#1062 - Entrada '0' duplicada para a chave 'faixa_cep_id'
Comment: Porque o indíce que mandei definir é do tipo indice unico e sua coluna contém valores duplicados. crie um indice simples apenas : " ALTER TABLE `faixa_cep_id` ADD INDEX `ID` (`ID`); "   também funciona.
Answer: Para adicionar um atributo novo em sua tabela e definir ele como auto-incremento pode rodar um ALTER TABLE dessa forma :
ALTER TABLE `nome_tabela`
ADD COLUMN `faixa_cep_id` INT(10) NOT NULL AUTO_INCREMENT FIRST;

Exemplo se a coluna já existir :
ALTER TABLE `nome_tabela`
CHANGE COLUMN `faixa_cep_id` `faixa_cep_id` INT(10) NOT NULL AUTO_INCREMENT FIRST;

Atualização :
Crie o índice :
ALTER TABLE `pl_joseanmatias_faixa_cep_peso`
ADD UNIQUE INDEX `faixa_cep_id` (`faixa_cep_id`);

Em seguida dê o alter table criando um atributo auto-increment
ALTER TABLE `pl_joseanmatias_faixa_cep_peso`
CHANGE COLUMN `faixa_cep_id` `faixa_cep_id` INT(10) NOT NULL AUTO_INCREMENT FIRST;

PS: A cada nova linha o própio banco de dados já insere a numeração automaticamente para você. Então não precisa mexer em nenhum INSERT seu.
Comment: ALTER TABLE `pl_joseanmatias_faixa_cep_peso`
ADD COLUMN `faixa_cep_id` INT(10) NOT NULL AUTO_INCREMENT FIRST
Mensagens do MySQL : Documentação

#1075 - Definição incorreta de tabela. Somente é permitido um único campo auto-incrementado e ele tem que ser definido como chave
Comment: apareceu o seguinte erro:
#1075 - Definição incorreta de tabela. Somente é permitido um único campo auto-incrementado e ele tem que ser definido como chave
Comment: Então deu isso porque na sua tabela já existe um campo definido como auto-increment. E ele só aceita um atributo com auto-increment. Nesse caso poste a estrutura da tabela vou montar um querie que faz isso.
Comment: Consegui criar o indice assim:
CREATE INDEX id_faixa_de_cep ON pl_joseanmatias_faixa_cep_peso (faixa_cep_id);

E rodei o change column...

Muito obrigado pela ajuda @RafaelSalomão :D
Answer: A resposta do Rafael já resolve o seu problema.
Mas caso queira apenas atualizar os dados sem ter que alterar
o tipo da coluna, segue um exemplo:
declare @i int
set @i =0
while @i < 13346
begin
BEGIN TRAN

update  pl_joseanmatias_faixa_cep_peso set faixa_cep_id = SELECT @i + 1
COMMIT TRAN;
set @i =@i + 1
end

Comment: Consegui com o autoincrement... Mesmo assim muito obrigado @MarcosMarques ^^