Cordova build returns missing plugin.xml

Question: When i build my cordova project i get an warning message as:

Missing file:
  /home/vijay/workspace/Repos_temp/QuickTraq_Android/plugins/nl.x-services.plugins.toast/plugin.xml
Missing file:
  /home/vijay/workspace/Repos_temp/QuickTraq_Android/plugins/cordova-plugin-device-rotation-vector/plugin.xml

This happens when i add an plugin or remove an plugin also .
This happens just as a warning when i add a plugin or build the project but when i remove the plugin error occurs as

Error: ENOENT, no such file or directory
  '/home/vijay/workspace/Repos_temp/QuickTraq_Android/plugins/com.grumpysailor.cordova-plugin-device-rotation-vector/plugin.xml'
      at Object.fs.openSync (fs.js:439:18)
      at Object.fs.readFileSync (fs.js:290:15)
      at Object.module.exports.parseElementtreeSync (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/util/xml-helpers.js:121:27)
      at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/dependencies.js:56:35
      at Array.forEach (native)
      at Object.module.exports.package.generateDependencyInfo (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/dependencies.js:53:45)
      at runUninstallPlatform (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/uninstall.js:218:53)
      at Function.module.exports.uninstallPlatform (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/uninstall.js:81:12)
      at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/plugin.js:205:58
      at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)

and my plugin remove failed .. Is there an way to resolve this ??
Comment: Could you try to `add` the plugin again (use `phonegap local plugin add`) if in-case you used Cordova's commands. If that still won't work, try cleaning npm's cache with `npm cache clean` and re-install Cordova/Phonegap.
Comment: I tried npm cache clean . I don't want to reinstall cordova is there an work around ??
Comment: May I ask why are you unwilling to re-install Cordova? And what happens when you try to `add` the plugin again?
Comment: I have an working environment and i fear something might happen . So i font prefer to reinstall . When i add the plugin it says already exists.
Answer: The plugin.xml looks to be missing. The path to each added plugin's plugin.xml should be:
 <yourapp>/plugins/<some-plugin>/plugin.xml

If you cannot find the plugin.xml files in those folders, you will have to manually download it from its git resource. Try adding device-rotation-vector's xml from here and then run:
cordova plugin remove cordova-plugin-device-rotation-vector

If it works correctly, do the same for Toast plugin.
You can find the list of plugins installed using:
cordova plugin list

Comment: Exactly did the same and worked !! I think there could be an error while removing the plugin last time . Thanks :)
Comment: Glad to know. And yeah, it could be while you tried to remove it the last time; that is why you should be careful about every error given by the CLI while adding/removing anything.
Comment: This error could be caused by something else entirely.
Comment: In case this helps, while using Cordova with Ionic, I have noticed that when I'm switching between machines using the same repo after adding a cordova plugin on one machine but not the other, I see the error above; and the solution for me has been to `ionic platform rm android ios` and `ionic platform add android ios`.
Answer: Remove folder "plugin_name" in rootApp_folder/plugins/plugin_name and try to add again.
Answer: SOLVED
Please try to add the plugin from GitHub repository. I had to install app-preferences plugin. So, I just did it like:
$ cordova plugin add https://github.com/apla/me.apla.cordova.app-preferences
Answer: These solutions not worked for me. I just restarted the command prompt, then everything working fine
Answer: Close all Windows that may touch upon the install.  Then try to install again.
W10:... I had an open Command Prompt open to an Android build output folder.  The install was unable to delete a file, which failed the install, until after I closed the Command Prompt window.
Answer: Removing the plugin folder worked for me, otherwise, both remove and add plugin was giving the same error.
Another method was to remove and re-add platform, but sometimes you have to install the plugins manually before adding the platform.


Security: Block bad spiders and bots from access to website using htaccess and HTTP_USER_AGENT

Question: When building an htaccess rule to block common spiders and bots, what HTTP_USER_AGENT headers should be filtered?
 RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:email@example.com [OR]
 RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
 RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
 RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
 RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
 RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
 RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
 RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
 RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
 RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
 RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
 RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
 RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
 RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
 RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
 RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
 RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
 RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
 RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
 RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
 RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
 RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
 RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
 RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
 RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
 RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
 RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
 RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
 RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
 RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
 RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
 RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
 RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
 RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
 RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
 RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
 RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
 RewriteCond %{HTTP_USER_AGENT} ^Zeus
 ## Return 403 Forbidden error.
 RewriteRule .* - [F]

Comment: I don't think blocking of these agents is necessary at all.
Comment: Perhaps this should be phrased a little more question-ish-ly?
Comment: Can you give me any suggestion how?
Comment: I took a stab at it. Feel free to roll back.
Comment: Can you give me an explanation why you think that? In my opinion it's a first-line defence.
Comment: Because User Agent String can easily be spoofed. BTW - instead having one RewriteCond per each bot, try merging them together making the faster.
Comment: As I said this would be only a first line of defence and secondly I didn't merge the conditions in order to make it more visual-friendly
Comment: First line defense against what? Security through obscurity never works, user agent strings can be easily changed.

I develop web applications many years and I have never seen anything like this in any application.
Comment: Have you ever used any of them? Some, haven't even got possibility to change User Agent header
Comment: If you want to go this route, might it be better(easier) to create a list of allowed agents (white-listing) then to try to block all of the bots?
Answer: This is how I do it:
SetEnvIfNoCase user-agent "^BlackWidow" bad_bot
# and all others from your list
SetEnvIfNoCase user-agent "^Zeus" bad_bot
<FilesMatch "(.*)">
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</FilesMatch>

Comment: OK so where's the difference?


About the measurability of unbounded function on interval

Question: I was asked if a real function $f$ on $[a,b]\subseteq \mathbb{R}$ with countably many points of discontinuity is  $\mathcal{B}_{\mathbb{R}}$- measurable.
If $f$ were bounded, I know it's Riemann/Lebesgue integrable, meaning that it is measurable.

What if $f$ were unbounded?

Thanks!
Answer: If you know the answer for the bounded case, then the unbounded case can be easily resolved by considering $g(x) = \arctan(f(x))$ instead. ($f$ is measurable if and only if $g$ is measurable.)
Comment: I cannot understand your answer. Your example covers all cases where $f$ is unbounded on $[a,b]$?
Comment: @Harumi, Yes. $\arctan(f(\cdot)) : [a, b] \to (-\pi/2, \pi/2)$ is bounded for *any* function $f : [a, b] \to \mathbb{R}$, and moreover, $f$ is measurable if and only if $\arctan(f(\cdot))$ is measurable. So you can first show that $\arctan(f(\cdot))$ is measurable and then use this to conclude that $f$ is also measurable.
Comment: Thanks. I didn't know these results. So the assumption that $f$ be bounded is not needed.
Comment: It looks that $arctan (f)$ has at most as many discontinuity points as $f$ has. So I could apply the result for bounded functions.
Comment: @Harumi, That is true :) The idea here is that both continuity and Borel measurability depend only on topologies, and so, it is conserved under homeomorphisms. In this case, we used the homeomorphism $\arctan : \mathbb{R} \to (-\pi/2, \pi/2)$.


Why in node.tpl.php $content is different from $node?

Question: I'm creating a custom template file for a specific content type.
I'm printing most of values with
<?php print render($content['field_blabla']); ?>

As some of them didn't show up and they are not empty I tried
dpm($content);

Indeed they aren't in the array printed, but if try
$node = node_load($node->nid, NULL, TRUE);
dpm($node->field_blabla['und'][0]['value']);

I can see the value!
What's the problem? Why are they missing?
Thanks
Answer: Sounds like their field display settings are hidden, which is one reason it would not be in the $content renderable array.
Check the display settings for the applicable view mode for this content type on the "Manage Display" tab.
Comment: I have checked it, and it was ok for the default view, but not the "full content" tab...
So I checked now again and found the problem!
Thanks a lot!
Comment: It would be Default by default if full content is not checked off for custom display settings.


Extract key and value from json to new dataframe

Question: I have a dataframe that has JSON values are in columns. Those were indented into multiple levels. I would like to extract the end key and value into a new dataframe. I will give you sample column values below

{'shipping_assignments': [{'shipping': {'address': {'address_type':
  'shipping', 'city': 'Calder', 'country_id': 'US',
  'customer_address_id': 1, 'email': 'email@example.com',
  'entity_id': 1, 'firstname': 'Veronica', 'lastname': 'Costello',
  'parent_id': 1, 'postcode': '49628-7978', 'region': 'Michigan',
  'region_code': 'MI', 'region_id': 33, 'street': ['6146 Honey Bluff
  Parkway'], 'telephone': '(555) 229-3326'}, 'method':
  'flatrate_flatrate', 'total': {'base_shipping_amount': 5,
  'base_shipping_discount_amount': 0,
  'base_shipping_discount_tax_compensation_amnt': 0,
  'base_shipping_incl_tax': 5, 'base_shipping_invoiced': 5,
  'base_shipping_tax_amount': 0, 'shipping_amount': 5,
  'shipping_discount_amount': 0,
  'shipping_discount_tax_compensation_amount': 0, 'shipping_incl_tax':
  5, 'shipping_invoiced': 5, 'shipping_tax_amount': 0}}, 'items':
  [{'amount_refunded': 0, 'applied_rule_ids': '1',
  'base_amount_refunded': 0, 'base_discount_amount': 0,
  'base_discount_invoiced': 0, 'base_discount_tax_compensation_amount':
  0, 'base_discount_tax_compensation_invoiced': 0,
  'base_original_price': 29, 'base_price': 29, 'base_price_incl_tax':
  31.39, 'base_row_invoiced': 29, 'base_row_total': 29, 'base_row_total_incl_tax': 31.39, 'base_tax_amount': 2.39,
  'base_tax_invoiced': 2.39, 'created_at': '2019-09-27 10:03:45',
  'discount_amount': 0, 'discount_invoiced': 0, 'discount_percent': 0,
  'free_shipping': 0, 'discount_tax_compensation_amount': 0,
  'discount_tax_compensation_invoiced': 0, 'is_qty_decimal': 0,
  'item_id': 1, 'name': 'Iris Workout Top', 'no_discount': 0,
  'order_id': 1, 'original_price': 29, 'price': 29, 'price_incl_tax':
  31.39, 'product_id': 1434, 'product_type': 'configurable', 'qty_canceled': 0, 'qty_invoiced': 1, 'qty_ordered': 1,
  'qty_refunded': 0, 'qty_shipped': 1, 'row_invoiced': 29, 'row_total':
  29, 'row_total_incl_tax': 31.39, 'row_weight': 1, 'sku':
  'WS03-XS-Red', 'store_id': 1, 'tax_amount': 2.39, 'tax_invoiced':
  2.39, 'tax_percent': 8.25, 'updated_at': '2019-09-27 10:03:46', 'weight': 1, 'product_option': {'extension_attributes':
  {'configurable_item_options': [{'option_id': '141', 'option_value':
  167}, {'option_id': '93', 'option_value': 58}]}}}]}],
  'payment_additional_info': [{'key': 'method_title', 'value': 'Check /
  Money order'}], 'applied_taxes': [{'code': 'US-MI--Rate 1', 'title':
  'US-MI--Rate 1', 'percent': 8.25, 'amount': 2.39, 'base_amount':
  2.39}], 'item_applied_taxes': [{'type': 'product', 'applied_taxes': [{'code': 'US-MI--Rate 1', 'title': 'US-MI--Rate 1', 'percent':
  8.25, 'amount': 2.39, 'base_amount': 2.39}]}], 'converting_from_quote': True}

Above is single row value of the dataframe column df['x']
My codes are below to convert
sample = data['x'].tolist()
data = json.dumps(sample)
df = pd.read_json(data)

it gives new dataframe with columns

Index(['applied_taxes', 'converting_from_quote', 'item_applied_taxes',
         'payment_additional_info', 'shipping_assignments'],
        dtype='object')

When I tried to do the same above to convert the column which has row values
m_df = df['applied_taxes'].apply(lambda x : re.sub('.?\[|$.|]',"", str(x)))
m_sample = m_df.tolist()
m_data = json.dumps(m_sample)
c_df = pd.read_json(m_data)

It doesn't work
Check this link to get the beautified_json
Answer: I came across a beautiful ETL package in python called petl. convert the json list into dict form with the help of function called fromdicts(json_string)
order_table = fromdicts(data_list)

If you find any nested dict in any of the columns, use unpackdict(order_table,'nested_col')
it will unpack the nested dict.
In my case, I need to unpack the applied_tax column. Below code will unpack and append the key and value as a column and row in the same table.
order_table  = unpackdict(order_table, 'applied_taxes')

If you guys wants to know more about -petl
Answer: It seems that your mistake was in tolist(). Try the following:
import pandas as pd
import json
import re

data = {"shipping_assignments":[{"shipping":{"address":{"address_type":"shipping","city":"Calder","country_id":"US","customer_address_id":1,"email":"email@example.com","entity_id":1,"firstname":"Veronica","lastname":"Costello","parent_id":1,"postcode":"49628-7978","region":"Michigan","region_code":"MI","region_id":33,"street":["6146 Honey Bluff Parkway"],"telephone":"(555) 229-3326"},"method":"flatrate_flatrate","total":{"base_shipping_amount":5,"base_shipping_discount_amount":0,"base_shipping_discount_tax_compensation_amnt":0,"base_shipping_incl_tax":5,"base_shipping_invoiced":5,"base_shipping_tax_amount":0,"shipping_amount":5,"shipping_discount_amount":0,"shipping_discount_tax_compensation_amount":0,"shipping_incl_tax":5,"shipping_invoiced":5,"shipping_tax_amount":0}},"items":[{"amount_refunded":0,"applied_rule_ids":"1","base_amount_refunded":0,"base_discount_amount":0,"base_discount_invoiced":0,"base_discount_tax_compensation_amount":0,"base_discount_tax_compensation_invoiced":0,"base_original_price":29,"base_price":29,"base_price_incl_tax":31.39,"base_row_invoiced":29,"base_row_total":29,"base_row_total_incl_tax":31.39,"base_tax_amount":2.39,"base_tax_invoiced":2.39,"created_at":"2019-09-27 10:03:45","discount_amount":0,"discount_invoiced":0,"discount_percent":0,"free_shipping":0,"discount_tax_compensation_amount":0,"discount_tax_compensation_invoiced":0,"is_qty_decimal":0,"item_id":1,"name":"Iris Workout Top","no_discount":0,"order_id":1,"original_price":29,"price":29,"price_incl_tax":31.39,"product_id":1434,"product_type":"configurable","qty_canceled":0,"qty_invoiced":1,"qty_ordered":1,"qty_refunded":0,"qty_shipped":1,"row_invoiced":29,"row_total":29,"row_total_incl_tax":31.39,"row_weight":1,"sku":"WS03-XS-Red","store_id":1,"tax_amount":2.39,"tax_invoiced":2.39,"tax_percent":8.25,"updated_at":"2019-09-27 10:03:46","weight":1,"product_option":{"extension_attributes":{"configurable_item_options":[{"option_id":"141","option_value":167},{"option_id":"93","option_value":58}]}}}]}],"payment_additional_info":[{"key":"method_title","value":"Check / Money order"}],"applied_taxes":[{"code":"US-MI-*-Rate 1","title":"US-MI-*-Rate 1","percent":8.25,"amount":2.39,"base_amount":2.39}],"item_applied_taxes":[{"type":"product","applied_taxes":[{"code":"US-MI-*-Rate 1","title":"US-MI-*-Rate 1","percent":8.25,"amount":2.39,"base_amount":2.39}]}],"converting_from_quote":"True"}

df = pd.read_json(json.dumps(data))
m_df = df['applied_taxes'].apply(lambda x : re.sub('.?\[|$.|]',"", str(x)))
c_df = pd.read_json(json.dumps(list(m_df)))
print(c_df)

prints the following:
                                                   0
0  {'code': 'US-MI-*-Rate 1', 'title': 'US-MI-*-R...

Comment: we need the end key and value of the rows as a new dataframe. For example,
Code as column and its value as row and so on


Codeigniter Query returns Empty results for Special Character

Question: I have a simple query which works just fine in workbench or phpmyadmin .
Ex1 select * from tabel1 where name='(Jhon Rick)';
Ex2: seelct* from tabel1 where name='John';

Ex1 works in Normal Console or phpmyadmin,but doesn't on CI.
Ex2 works both on Console as well as CI, so i assume the issue is with parenthesis ()
When i prepare the same query using CI, empty results are returned for EX1.
On debugging the query i get the same query as above.
Possible issue with CI db driver?
Any help regarding this.
Comment: have you loaded your database?
Comment: Maybe you should use `like` ?
`select * from tabel1 where name like '%John%'`
Comment: What if you use the query builder syntax? `$query = $this->db->get_where('tabel1', array('name' => '(Jhon Rick)'));`
Answer: Figured out the issue.
PHP buy default encodes Unicode character Parenthesis () as HTML entity
i.e     ( and   ) respectively for ()

In order to fix it, i had to just decode it back using
html_entity_decode($varName);


Phantomjs using a local file with page.includeJs?

Question: I am using PhantomJS to screenshot a webpage. However the library calls to a hosted jQuery file to inject jQuery functionality in the page DOM to allow some manipulations. Seen here: http://phantomjs.org/api/webpage/method/include-js.html
The code looks like this:
if ( loaded ) {
page.includeJs("http://code.jquery.com/jquery-1.8.3.min.js",
  function() { . . .

I don't want to make an external call for JS because (a) it's slower and (b) its not reliable. I would like to use a local copy and I set that path as such but it is NOT loading in.
page.includeJs("assets/javascript/jquery.min.js",
  function() { . . .

What is the problem here? Why is my path not working as I expect it to? Does this function page.includeJs not allow relative paths?
Answer: According to the documentation this function includes the script from given URL which needs to be accessible from the hosted page. Obviously your local path is not accessible on remote host (relative nor absolute) so you need to inject the script with injectJs instead.
Edit: Here is the code I used for testing:
var page = require('webpage').create();

page.open("http://ipecho.net/", function(status) {
    if ( status === "success" ) {
        if (page.injectJs("jquery.min.js")) {
            var h1 = page.evaluate(function() {
                return $("h1:eq(0)").css({fontSize: 10, color: "red"}).text();
            });
            console.log(h1);
        }
    }
    page.render("test.png");
    phantom.exit();
});

The extra code can be also injected the same way as jquery and will work for sure. Remember about evaluate() limitations (but it is not really a big deal in this case):

Note: The arguments and the return value to the evaluate function must
  be a simple primitive object. The rule of thumb: if it can be
  serialized via JSON, then it is fine.
Closures, functions, DOM nodes, etc. will not work!

Edit: Also about your filepath problem: check what is your working directory. Using relative paths can be tricky because of that so I suggest you to use absolute. webpage.libraryPath is all you need. I hope I helped you now.
Comment: You have misunderstood the docs then. "The arguments and the return value to the evaluate function must be a simple primitive object." It is about `page.evaluate()` limitations, not `injectJs`. jQ and manipulations with its help work perfectly fine. I just tested it by myself.
Comment: Tried injectJs too. Path isn't resolving either. From reading the docs I think they have subtle differences too.
Comment: @fab Yes, there are some differences but it's the only way to run local script. You are probably providing wrong filepath. Try using absolute one and see if it works.
Comment: Btw `injectJs` is not correct DOCS: "Note: The arguments and the return value to the evaluate function must be a simple primitive object. The rule of thumb: if it can be serialized via JSON, then it is fine.

Closures, functions, DOM nodes, etc. will not work!" See link: http://phantomjs.org/api/webpage/method/inject-js.html
Comment: Add all your extra code (manipulations you need to do) to the end of `jquery.min.js` or put it in the new file and inject both.
Comment: Doc says you can only inject a PRIMITIVE object.. jquery is NOT a primitive object. So `injectJs` will not work.


Probability clarification $\chi^2$ distribution table

Question: I'm having some trouble understanding the solution of this probability question.

Ammeters produced by a manufacturer are marketed under the specification that the standard deviation of gauge readings is no larger than $.2$ amp. One of these ammeters was used to make ten independent readings on a test circuit with constant current. If the sample variance of these ten measurements is $.065$ and it is reasonable to assume that the readings are normally distributed, do the results suggest that the ammeter used does not meet the marketing specifications? [Hint: Find the approximate probability that the sample variance will exceed $.065$ if the true population variance is $.04$.]

The solution is as follows:

At the step $P(9S^2 / .04 >= 14.925)$, where does the $.10$ come from. I look at the $\chi^2$ distribution and I'm looking at $9$ degrees of freedom, but I still don't understand.
Comment: Use `$\chi^2$` to show $\chi^2$.
Answer: I guess it skipped a step...
$$P\left(\frac{9S^2}{.04}\geq 14.925\right) = 1-P\left(\frac{9S^2}{.04}< 14.925\right)  =1-0.9069832 = 0.09301681$$
which is approximately $.10$ considering possible table rounding errors.
In other words
$$P\left(\frac{9S^2}{.04}\geq 14.925\right)$$
indicates to look at the area to the right, not the left.
Comment: Sorry I am completely out of it today, where does the $0.9069832$ come from?
Comment: @user270494 The value comes from lookup-tables or an [online calculator](http://www.fourmilab.ch/rpkp/experiments/analysis/chiCalc.html)
Comment: @user270494 $P\left(\frac{9S^2}{.04}< 14.925\right)  =0.9069832$ using a calculator, or you could use a table with high accuracy.
Comment: @user270494 Anyway, the value you found using your table, call it $c$. Then I think your answer will match the answer key if you do $1-c$.
Answer: $\Bbb P\left(\frac{(n-1)S^2}{\sigma^2}\geq \frac{(n-1)s^2}{\sigma^2}\right) = \Bbb P({\raise{0.5ex}{\chi}}^2_{9}\geq 14.925) = ~$$0.0930...$ $~\approx 0.1{\small 0}$
The value comes from lookup tables or an online calculator.


Log out URL returns 503, redirects to path with double slash

Question: When users access /user/logout they receive a "Page Not Found" error, and the URL they are forwarded to looks like this:
https://wwws.site.com/dir/site_name//dir/site_name/
Why is this redirect happening and how do I change the logout path so that it wouldn't create the double slash?
Comment: Then it should work properly. I think, there is some other issue, not related to url.
Comment: Did you create "logout" as custom link or displaying link of "user menu"?
Comment: I'm displaying the standard logout link of the "user menu"
Answer: You should use URL() to create logout url. For example,
url('user/logout')


Cloned node entity reference field stay in sync with parent node

Question: I have three content types A, B and C. A have entity reference fields to B and C. I create a Node of type A say a1. When i clone a1 node as a2 with node clone module i get the same value for entity reference fields in a2 same as a1. In a2 i can change the entity reference field value so that they refer to another nodes of B and C content type.
But with node clone module there is no way to maintain relationship between parent node and cloned node.
So I basically have two requirements:

In cloned node i can override the entity reference field value or leave it same as parent node. If i override, later i should be able to revert back to those values same as parent node. Currently there is no way to do this.
If parent node change the value of those entity reference fields then in all the cloned node of this parent node also change their respective entity reference field value except overridden cloned nodes.

The solution i found so far during searching is using Replicate, replicate_ui module which provide more hook to alter the cloning process. The another module is Corresponding Entity References which create entity reference field back to parent node.
I don't need comprehensive solution but anything existing solution can do almost this functionality?
Answer: 1) You could use a hidden field of the same type with the same information. This way, the information relating the parent to child can be reverted, regardless of the changes or overrides. Use Rules to populate the duplicate field. Create a "Revert" button on the node and again use Rules, or as a form submit to react to copy the information from the hidden field to the visible one.
2) Use Rules to adjust any child nodes when the parent is saved/updated. This would act on both the hidden and visible field, with a condition on the visible (not to change if it has been overridden).
You could also write a module to do this, but I think it can be done with just Rules.


Not able to decode very large data which is stored in mysql database using Base64 decoding in java

Question: I want to take data from mysql database and download it.
<code>        import java.util.Base64;
</code>
When I am trying below code I am not getting any output...
<code>        String content = rt.getString("data1");
        byte[] conArray = content.getBytes();
        byte[] decodeBytes = Base64.getDecoder().decode(conArray);
        String decode = new String(decodeBytes, "UTF_8");
        System.out.println(decode);
        response.setHeader("Content-Disposition", "attachment;filename=\"" + filedetails[0] + "\"");
        out.write(decode);
</code>
Here is my encoding part....
<code>    byte[] a = fileItem.get();
    byte[] encodedfile = Base64.getEncoder().encode(a);
    String s = new String(encodedfile, "UTF-8");
    System.out.println(s);
</code>
Without decoding I am getting encoded string, so no problem in code
<code>        String content = rt.getString("data1");
        System.out.println(content);
        response.setHeader("Content-Disposition", "attachment;filename=\"" + filedetails[0] + "\"");
        out.write(content);
</code>
And when I try online Base64 Encoder decoder, I am getting correct output.
Edit:
Data in mysql - hey there
After applying Base64 encoding and stored in mysql data column - aGV5IHRoZXJl
I am trying to decode this string from above code.
Getting aGV5IHRoZXJl when printing content (same which is stored in database column)
When printing decode - nothing is printed
Comment: I notice you are using "UTF-8" everywhere, except `String.getBytes()`  Try `String.getBytes("UTF-8")` see if that helps.
Comment: Your question is incomplete.  We need to see actual data, its encoded value and the results of the decode that does not work.  You will have to insert debug logging at the appropriate places to get these values.  Without that, the question cannot be answered.  To be very specific, in the "code that does not work" we need to see the values of `content` and `decode`, plus the original text that was encoded to produce `content`.
Comment: @JimGarrison - edited. Please have a look.
Comment: @markspace- tried but still same problem.
Comment: I am getting data from file. @JonSkeet
Comment: The original data you're encoding appears to be bytes, not text (`byte[] a = fileItem.get();`. Why are you then assuming it was originally UTF-8-encoded text?
Comment: That doesn't answer why you're then assuming it's a string afterwards: `String decode = new String(decodeBytes, "UTF_8");` You started with a `byte[]` from the file, so your decoding process should end with a `byte[]` as well.
Answer: <code>   byte[] decodeBytes = Base64.getDecoder().decode(conArray);
    //String decode = new String(decodeBytes, "UTF_8");
    System.out.println(decode);
    response.setHeader("Content-Disposition", "attachment;filename=\"" + filedetails[0] + "\"");
    out.write(decodeBytes);
</code>
The bytes must be written as-is, with an OutputStream, not as text with a Writer.
Those bytes probably are not a valid UTF-8 sequence anyways, and converting bytes to chars (twice the memory) is a bit too much anyway.
Maybe you need to alter out:
<code>OutputStream out = response.getOutputStream();
</code>


Find the median from a dictionary of values and number of their occurences?

Question: I have a dictionary that looks like this (although is much larger):
data = {
    100: 8,
    110: 2,
    1000: 4,
    2200: 3,
    4000: 1,
    11000: 1,
}

Each pair consists of value:number of occurrences in my dataset. I need to calculate the median of my dataset. Any hints/ideas how to do it?
I am using Python 3.6
EDIT:
I don't want to create a list (because of the size of my dataset). The size of the list was actually the very reason to use a dictionary instead. So, I am looking for another way.
Comment: Are there any more restrictions on the algorithm? If you don't care much about speed or space, you could just create a list from the dictionary that contains each of those values the specified number of times (e.g. `[100,100,100,100,100,100,100,100,110,110,1000,...]`), sort that list, then find the middle value.
Comment: I gave you a downvote because you gave too little information for a good answer. In addition to the issues I mention in my previous comment, you do not say if the dictionary is an ordered-dictionary or a standard one and whether the dictionary items were inserted in sorted order. You do not say if converting the dictionary to a list of ordered pairs (as in the `items` method) takes too much space. All those things matter.
Comment: put `number of occurrences` instances of `value` in a list for all pairs, sort it and get the element in the middle of the list or the average of the two elements in the middle
Comment: Is your dictionary ordered as the example dataset shows?
Comment: I forgot to mention I dont want to create a list because of the size of my dataset. Obviously, that would be a way to do so.
Comment: by the way, I'd be glad if anyone explained why I am getting minus votes on this question so I can ask better next time. I did search through other questions and answers before I asked and didn't find any answer.
Comment: I upvoted because it's a relevant question. It might be worth mentioning that as of Python 3.6 (unofficially, but officially from 3.7) dictionaries are in key insertion order.
Answer: I believe this solution works as well, at least for positive numbers. I tested some data sets in conjunction with your answer, and they both work similarly to my knowledge.
(sorted_dict is the dictionary sorted by its keys numerically)
    length = 0
    for value in sorted_dict.values():
        length += value
    half = length / 2
    sum_var = 0
    #finds the index of the middle of the dataset
    for val in sorted_dict.values():
        if half-sum_var > 0:
            sum_var += val
        else:
            break
    index = (list(sorted_dict.values()).index(val))
    #returns the median based off some characteristics of the dataset
    if sum(list(sorted_dict.values())[index:]) != sum(list(sorted_dict.values())[:index]):
        if sum(list(sorted_dict.values())[index:]) > sum(list(sorted_dict.values())[:index]):
            median = list(sorted_dict.keys())[index]
        else:
            median = list(sorted_dict.keys())[index-1]
    else:
        median = (list(sorted_dict.keys())[index-1] + list(sorted_dict.keys())[index]) / 2
    return(median)

Answer: This will work for python 3.6+ when your dict is ordered.
from math import floor, ceil

def find_weighted_median(d):
    median_location = sum(d.values()) / 2
    lower_location = floor(median_location)
    upper_location = ceil(median_location)
    lower = None
    upper = None
    running_total = 0
    for val, count in d.items():
        if not lower and running_total <= lower_location <= running_total + count:
            lower = val
        if running_total <= upper_location <= running_total + count:
            upper = val
        if lower and upper:
            return (lower + upper) / 2
        running_total += count

Comment: OP stated that he was using Python 3.6 and that the dict is ordered.
Comment: @RoryDaulton - I made that explicit in my answer since OP only mentioned that it was ordered in the comments.
Comment: Thanks but I unless I am mistaken your code doesn't compute the correct value.
Answer: So, not finding a satisfying answer, this is what I have come up with:
from collections import OrderedDict
import statistics

d = {
 100: 8,
 110: 2,
 1000: 4,
 2200: 3,
 4000: 1,
 11000: 1,
}

    # Sort the dictionary
values_sorted = OrderedDict(sorted(d.items(), key=lambda t: t[0]))
index = sum(values_sorted.values())/2

# Decide whether the number of records is an even or odd number
if (index).is_integer():
    even = True
else:
    even = False

x = True

# Compute median
for value, occurences in values_sorted.items():
    index -= occurences
    if index < 0 and x is True:
        median_manual = value
        break
    elif index == 0 and even is True:
        median_manual = value/2
        x = False
    elif index < 0 and x is False:

        median_manual += value/2
        break

# Create a list of all records and compute median using statistics package
values_list = list()
for val, count in d.items():
    for count in range(count):
        values_list.append(val)

median_computed = statistics.median(values_list)

# Test the two results are equal
if median_manual != median_computed:
    raise RuntimeError

I have tested it with different datasets and compared the results with the median computed by statistics.median() and the results were the same.
Comment: Sorry I tried your code but I got the following error AttributeError: 'function' object has no attribute 'items'. I have the d which is a dictionary
Answer: A pandas-based solution is below.
import pandas as pd

def getMed(item_dict : dict[int, int]) -> int:
    'function finds median'
    df = pd.DataFrame.from_dict(item_dict, orient='index').reset_index()
    df.columns = ['values', 'count']
    df.sort_values('values', inplace=True)
    df['cum_sum'] = df['count'].cumsum()
    total_count = df.iloc[-1, -1]
    for id, row in df.iterrows():
        if row['cum_sum'] >= int(total_count*0.5):
            return row['values']

The result from your input:
your_dict = {100: 8,
             110: 2,
             1000: 4,
             2200: 3,
             4000: 1,
             11000: 1
            }

getMed(your_dict)
>> 110

Answer: Here is my take:
data = {
    100: 8,
    110: 2,
    1000: 4,
    2200: 3,
    4000: 1,
    11000: 2,
}
total_frequency = sum([v for v in data.values()])           # 1
middles = (total_frequency+1)//2, (total_frequency+2)//2    # 2

cumulated, first, second = 0, None, None

for key, frequency in data.items():                         # 3
    cumulated += frequency                                  # 3
    if (not first) and cumulated >= middles[0]:             # 4
        first = key
    if (not second) and cumulated >= middles[1]:            # 4
        second = key

median = (first+second)/2                                   # 5

print(f'''
Middle Frequencies: {middles[0]},{middles[1]}
Middle Values: {first},{second}
Median: {median}
''')

The steps are:

Calculate the total frequencies for the table, which are the values in the dictionary.
Find two middle frequencies. If there is an odd number, they will be the same.
Iterate through the table and accumulate the frequencies.
If the accumulated frequency has reached one of the middles, store the key.
The median will be the average of the two.


interpreting logistic regression coefficients when reversing the reference group

Question: I applied logistic regression to check the relationship between a binary variable that is called FG and few independent variables
the reference group for the variable SSE is SSE1. The OR is 0.48 meaning that the chances for those in SSE2 (from the same age group and the same physiological status) decrease by 52% to be in FG group 1 compared to those from SSE1.
However now when considering SSE2 as the reference group :
now OR for SSE1 is 2.08 meaning the chances for SSE1 are 108% higher to be in FG group 1 compared to those from SSE2. Is it logical this way or am I making some interpretation error (because I thought that the resulted OR must indicate 52% more of chances) ? Thanks.
Answer: I strongly recommend that you don't try to interpret such results in terms of percentage changes. That too often leads to confusion like this. See Frank Harrell post on "Why I Don't Like Percents."
If you just stay in the odds ratio (OR) scale, everything makes sense. The OR for SSE2 versus SSE1 is 0.48 in the first model. The OR for SSE1 versus SSE2 in the second model is exactly the inverse, 1/0.48 = 2.08, as expected. The problems arise when you try to convert to percentage changes as the baseline for comparison changes. There's no need to do that. As Harrell says:

Many quantities reported in the scientific literature are naturally ratios. For example, odds ratios and hazard ratios are commonly used. If the ratio of stroke hazard rates [in] treatment B compared to treatment A is 0.75, I prefer to report "the B:A stroke hazard ratio was 0.75." There's no need to say that there was a 25% reduction in stroke hazard rate.
Comment: Thank you so much it was very helpful


Erro com o jQuery ColorPicker

Question: estou usando o jQuery ColorPicker só que esta dando o seguinte error:

Uncaught TypeError: Object [object Object] has no method 'ColorPicker'

O meu codigo esta assim:

                Cor

Alguém consegue me ajudar com esse erro?
Comment: Entre aqui > http://www.digitalmagicpro.com/jPicker/
Comment: esse é muito grande, fica feio, tem que ser algo mais sutil @SamirBraga
Comment: O erro que você está a receber dá-me a ideia que o ficheiro .js não carregou. Pode confirmar se o seu url está correcto?
Answer: Eu baixei o pacote do jQuery ColorPicker e vi que o arquivo jQuery que vem nele é a versão 1.3.2.
A versão 1.10 tem mudanças grandes em relação à 1.3.2, então tente carregar o arquivo jQuery do pacote que é baixado junto com o jQuery ColorPicker, a 1.3.2 para confirmar se o problema não é causado por isso.
Answer:
Uncaught TypeError: Object [object Object] has no method 'ColorPicker'

Esse erro ocorreu porque a biblioteca ColorPicker não foi incluida corretamente, eu recomendo ao contrário de usar uma biblioteca use o "novo input" <input type="color" /> com um Polyfill como o Spectrum por exemplo.
Além disso, eu achei na Wikipédia do jQuery UI um artigo falando sobre isso, (aqui), ele cita algumas bibliotecas que devem se encaixar nas suas preferências.

Erro com o jQuery ColorPicker


Expectation of Scalar Function of Multivariate Gaussian

Question: If $X \sim N(\mu, \Sigma)$ is an $n$-dimensional Gaussian, and $A \in R^n$, so that $X^TA \in R$, and $f(x) = x^2$.
I want to know the solution to the following expectation:
$$
\int_R \int_R \dots\int_R f(Ax)N(x\mid\mu, \Sigma)\, dx = E_X[f(AX)]
$$
noting that $v := AX \sim N(\mu^TA, A^T\Sigma A)$ is a one dimensional Gaussian, it seems intuitive to write this expectation as the second moment of $v$:
$$
E_{v}[v^2] = \text{Var}[v] + E[v]^2 = A^T\Sigma A + (\mu^TA)^2
$$
but I am unsure if this is correct, if someone knows that it is, or has a proof, that would be great.
Comment: One should not use the very same symbol for both the random variable and the bound variable of integration. In the expression $\displaystyle \int_{-\infty}^\infty f_X(x)\, dx,$ there is a reason why the subscript $X$ is capital and the two lower-case $x$s are in lower case. Without that distinction, one could not understand things like $\Pr(X\le x),$ and one will be substantially confused about other things as well. And the subscript on the expectation operator is also a mistake.
Comment: @MichaelHardy why is the expectation subscript a mistake? I was asking whether the density we are taking the expectation with respect to is the density of the random variable $v$
Comment: One does not take expectations "with respect to" random variables; one takes expectations _of_ random variables. $\qquad$
Answer: That's quite straightforward, and you don't even need to assume a gaussian distribution:
$$ E[f(X)]=E[(X^t A)^2]=E[A^t X X^t A] = A^t E[X X^t] A$$
But $$\Sigma = Cov(X)=E[(X-\mu)(X-\mu)^t]=E[X X^t] - \mu \mu^t$$
Then, putting all together:
$$ E[f(X)] = A^t (\Sigma + \mu \mu^t) A = A^t \Sigma A + (\mu^t A )^2$$
Comment: $v = X^t A$ is certainly a scalar random variable. So, of course, to compute $E(f(v))$ it's enough to deal with the (univariate) distribution of $v$. But, of course, for arbitrary $f$ one cannot expect to express the result in terms of the first moments of $v$ (and hence the first  moments of $X$).
Comment: is there a more general result though? this property apparently also holds for $f(x) = \sigma(x)$ (logistic sigmoid). I mean to say that the expectation is taking as a function of $v$ and with respect to the distribution of $v$, even if the function is the sigmoid for example
Comment: I'm not sure what "the property holds for other $f(x)$" means. What about the first term ($A^t \Sigma A$) ?
Comment: I mean to answer it here we explicitly use the fact that $f(x) = x^2$, but I believe this property in which we reduce the expectation from being with respect to a multidimensional distribution down to a univariate distribution holds for other functions, for example the logistic sigmoid. i.e. $E_X[\sigma(AX)]   = E_v[\sigma(v)]$


subtyping relationships in OO paradigm

Question: Let us consider a class 'Human' -->(1..*) 'Human' , where Human is a supertype. Say it has subclasses like 'Male', 'Female', 'SociallyPathologicalMale' etc. The basic association b/w 2 entities remains common, the subtypes define name and constraints on the association but the basic relationship is still m:n b/w 2 Human entities.
Example:-

'Male' -->(1:1)('wife'(relationship name)) 'Female'
'Female'-->(1:1)('husband') 'Male'
'SociallyPathologicalMale'-->(1:0)('friends') 'Male'
[edit 13/12/2011] - If say we have to implement it in java, what are some of the best practices such that reuse of the association possible?

Say we start with base class :-
 class Human{
  private List<Human> relationships; // in a subclass this field, could
//  this generically be represented ??
}

something like
   class Man extends Human{
    private List<Woman> relationships;//should be 0 or 1
    }

Now the fact that relationships field is redefined in Man (or any other subclass) could be structurally enforceable , i.e while defining any subclass it should be mandatory for me to define out the relationships. Is it possible for such a kind of construct in java ?? are there other languages that can do this easily ??
Answer: Two methods of implementation i would use would be Inheritance and Composition.
The is a relationship is expressed with inheritance and has a relationship is expressed with composition.
Both inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for code reuse are class inheritance and object composition.
Inheritance
class Human {
//some code
}
class Male extends Human {
//some code
}

Composition
class Male
{
     Wife mrs = new Wife();
}

Comment: Hi Darren , thanks for the answer. I felt my question was not clear enough , so edited and tried to nail the main thing i was seeking, please see the edit part and you may like to add to your answer here
Answer: There are two important things you should review from your scenario:
1) Fields cannot be redefined by subclasses. It is not a limitation of the language (Java) but a conceptual imposition that is reasonable. Fields define what an object is and methods define what an object does and how. The only thing you can redefine is how things are done by your objects but you are not allowed to change what your superclass is or does. (I'm saying "objects" but please keep in mind that I mean "the instances of the class" since you actually define the behavior in the class body).
2) You must make the Relationship a first-class object. Since it is not enough using what the paradigm provides you: "is a" and "has a". As Darren Burgess stated, the paradigm provides you with two conceptual relationships: "is a" and "has a". For the Human->Man or Human->Woman example, you can use inheritance, in other words, "is a". The Man class extends Human because a Man is a Human. The difficulty is on the "has a" relationship since OOP does not allows you to specify cardinality and you also want to specify a name on the relationship. For simplicity, let's define relationships as binary. For example, A man has a Wife or a Woman has a Husband. For the relationship John is the father of Tom and Linda, we will define two relationships: John is the father of Tom and John is the father of Linda. The problem with your approach is that you specified a List of Man and a List of Woman. However, what a Human actually has is a Collection of Relationships. The design will look like this:
public Human {
    private Collection<Relationship> relationships;
}

public Relationship {
    private Human party; // We are defining only relationships between humans.
    private Human counterparty;
    private String name; // e.g., "is the Husband of" and "is the Wife of".
}

Party and counterparty are the members of the relationship and the object instance of Relationship will represent how one relates to the other.
Defining particular behavior would be more ad-hor. For example, a SociallyPathologicalMale will not have any Relationship. You can add the following method to Human:
public void addRelationship(Relationship newRelationship) {
    relationships.add(newRelationship);
}

The SociallyPathologicalMale class (who extends Male) will inherit that method and will redefine it as follows:

public void addRelationship(Relationship newRelationship) {
      // Nothing to do here. }

Basically, as SociallyPathologicalMale, by definition, is unable to have any relationship, you disable programmatically the ability provided by the superclass Male.
I hope it clarifies your question.

subtyping relationships in OO paradigm


Content from the same content type as the current user

Question: I have users with a "field_org" entity reference (multiple values allowed) to the "Org" content type. I also have a "field_org" (single value) in my "Article" content type.
When looking at a user profile (let's call this user "UserA"), how do I build a view that gets you "articles from your orgs" (i.e. created by other users that also belong to any of UserA's orgs)? And, bonus question: how do I exclude articles created by UserA? (since I have a separate "your articles" view showing in the same page).
I know this is probably a combination of relationships and contextual filters, but I can't figure out exactly how to configure them. Probably something like this:

Contextual filter on node author to prevent "UserA's articles" from showing (set to "exclude" in the options)
Contextual filter on node author, but probably set to one of the relationships below.
Relationship between article nodes and orgs?
Relationship between orgs and users?

Both contextual filters would load the same user ID using "Provide default value".
Answer:
Create a content view
Add the Content: Author relationship
Add the Content: Author uid contenxtual filter

Provide default value: User ID from URL

So far we have a view displaying content created by a certain user, we still have to narrow down the results to a single content type.

Add the Content: Type filter = Org

Note that a page view (with a path) will show no results if you just hit the path. To have results you must pass a uid to the url, like mypath/%uid. On the other hand you can create a block or a content pane and place/embedded it to the user's profile, view's will return all results (if any) for you!


Play framework 2.5 how to set mode?

Question: The application object has the isDev(), isTest() and isProd() methods.
But I can't find out where to set this in the .conf file.
Using the search feature on the website for "mode", "dev", "test" or "prod" gives nothing related to this. This doesn't appear to be documented.
Answer:
Production mode use: activator stage or  activator dist
Dev mode use activator run

To test a production mode, run (not to be used in production):
cd project-dir
activator
testProd

Comment: Ah, thanks for that. I saw that before on this page: https://www.playframework.com/documentation/2.5.x/SBTCookbook, but didn't find anything else.

Play framework 2.5 how to set mode?


How to create an array in R with the vector elements row wise?

Question: When I create an array it always stores the elements column wise I've searched for row-wise but can't find anything
For example for this code
<code>  X = c(1,2,3)
  Y = c(4,5,6,7,8,9)
  R = array(c(X,Y), dim=c(3,3,2))
  print(R)

</code>
How do I get an output of
<code>, , 1

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9

, , 2

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9

</code>
Answer: You can do:
<code>aperm(R, c(2, 1, 3))

, , 1

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9

, , 2

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
</code>


Help understanding Anova Three Factors

Question:
I am looking to understand the following table from this article to better understand some statistical stuff.
The article is exploring the outcomes of meat via 3 factors(marinade, temperature and cooking time). And they state the tools used in the statistical analysis as this:

Descriptive and inferential statistics were used according to procedures described by Anderson.
[22]
The
Dixon's Q-test was applied in order to examine outlier values. A three-factors´ ANOVA was applied to
evaluate the influence of the factors (marinade type, cooking temperature, and cooking time). Differences
between two means were identified using an unpaired t Student test(P< .05). For multiple comparisons,
Fisher´s Least Significant Difference (LSD) test was applied. The significance level was set at P<.05 in all
cases. Discriminant analysis was performed to ascertain which of the instrumental parameters (pH,
instrumental color and SF) were useful in differentiating among the beef and meat analog samples.
Statistical analysis was carried out with Minitab® software (Version 18.1, Minitab Inc., PA, USA).

A couple of things I want to understand from this table are:

How are the values in table expressed as Mean (since there is only one measurement) and what are the values in parentheses?
What does it mean that different superscripts in the same column differ significantly (P < 0.05)
Of the statistical analysis tools that I quoted, which ones produce this table?
Answer:
Next to the mean figures in brackets is standard deviation
ANOVA is an omnibus test, that means when you have a significant model F test, this tells you that overall there are differences between groups. You then need to follow this up with a post-hoc procedure (if not doing planned contrasts, i.e., if you have no apriori hypotheses you want to test). The post hoc test the authors in this paper use is Fisher's LSD multiple comparison test. This compares all the mean values of each group, two at a time. Because the authors are doing multiple comparisons in such a way, the Type 1 error rate is inflated (false positive), so the Fisher's LSD post-hoc procedure adjusts the signifance level, essentially making it stricter.
Without going into detail and reading the whole paper, it looks like these are the results of the Fisher's LSD multiple comparison test following up from the significant ANOVA. It looks like the superscript shows a signficant comparisons between groups, e.g. the superscript cd means the authors found a significant difference (at p<0.05) between group c and d when doing a Fisher's LSD multiple comparison test.
Comment: It is the mean value calculated from all observations in the experimental group. Looking in the article, it says: "two batches were prepared, which means that the experimental design was replicated twice. For each batch, 1200 g approximately of beef and 1200g approximately of meat analog were used and 24 samples (100 ± 10 g and 1 cm thick) were analyzed". So I am assuming that the mean figure is created based on the results from the two batches.
Comment: Ok, but why is the value before brackets a mean? Isn't it just a single measurement?
Comment: These are the values of the beef dependent variable (I believe it is called "beef yield" in the article) by whatever group they are in (shown by superscript (cd etc.) See the article text: "Beef samples were only significantly affected by the individual factors cooking time and cooking temperature (P< .05)." The 3 factor ANOVA tests overall if group means differ, the Fisher's LSD post-hoc procedure is used to compare groups pairwise, and the authors subsequently report only the IVs cooking time and cooking temperature had significant effects.
Comment: Yes, but take a look at first row for example, the value $5.60$, why do they call this value a "mean"? What is it a mean of if only a single measurement is performed? Shouldn't there be at least 2 measurements to calculate a mean?

Help understanding Anova Three Factors


Facebook API Publishing action with Java script sdk

Question: I am really struggling with the facebook api. A have created a app, an object an action, and I want to test to publish in my stream, (I know the public publishing has to be authorised by facebook but as an adminsitrator of my app, I am allowed to test it). But it doesn't wor. Here's the script :

<title>OG Tutorial App</title>
<meta property="fb:app_id" content="452488354765730" />
<meta property="og:type" content="subhinajjar:article" />
<meta property="og:title" content="3eesho" />
<meta property="og:image" content="https://3eesho.com/public/admin/logo.png" />
<meta property="og:description" content="3eesho reading club" />
<meta property="og:url" content="https://3eesho.com/">

Stuffed Cookies

<form>
<input type="button" value="read" onclick="postreads()" />
</form>

<fb:activity actions="subhinajjar:read"></fb:activity>

but I always have this message : error accord. and this drive me crazy .
I hope if any body can modify this code to me.
Answer: Try changing the URL for the API call in FB.api to: '/me/subhinajjar:read' (i.e. remove article as you will be posting it as data anyway).
In the response block, alert the error to see what actually happen when the action was posted to facebook. You code should look like:
function postreads()
{
  FB.api(
    '/me/subhinajjar:read',
    'post',
    { article: 'https://3eesho.com/articles/2346/-' },
    function(response) {
       if (!response || response.error) {
          // show the error
          alert( response.error );
       } else {
          alert('read was successful! Action ID: ' + response.id);
       }
    });
 }

If that doesn't work, try using the build-in read action:
  FB.api(
    '/me/news.reads',
    'post',
    { article: 'https://3eesho.com/articles/2346/-' },
    function(response) {
       if (!response || response.error) {
          // show the error
          alert( response.error );
       } else {
          alert('read was successful! Action ID: ' + response.id);
       }
    });
 }

Comment: this tow ways doesn't work. I think I have another problem because the value of response.id always: undefined


How to block Bad robots, spiders, crawlers and harvesters

Question: I'm sick and tired of this bad robots, spiders, crawlers and harvesters. I have already configured my server to block IP connected for 5 minutes and with maxretry of 250 using fail2ban. But still some of them cannot be intercept with 250 maxretry as they are not accessing it more than 250 within 5 minutes.
Here's my jail.local config:
<code>[http-get-dos]
enabled = true
filter = http-get-dos
logpath = /var/log/ispconfig/httpd/*/access.log
maxretry = 250
findtime = 300
#ban for 10 hours
bantime = 36000
action = iptables-multiport[name=HTTP, port="http,https", protocol=tcp]
         cloudflare-blacklist
         sendmail-whois[name=HTTP, email@example.com]
</code>
Here's the http-get-dos.conf filter file:
<code>[Definition]

failregex = ^<HOST> -.*"(GET|POST)

ignoreregex =
</code>
The majority of the tutorial that can block this crawler is using apache. But because I am using nginx, I cannot use them. Here's one tutorial I found.
Here's the example log of this robot:
<code>18.104.22.168 - - [24/Jul/2013:00:00:19 +0800] "GET /php?page=9 HTTP/1.1" 200 10897 "http://www.mysite.com/php?page=8" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
220.127.116.11 - - [24/Jul/2013:00:00:22 +0800] "GET /sites/default/files/download/jkev/jkev_search.zip HTTP/1.1" 200 35199 "http://www.mysite.com/sites/default/files/download/jkev/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:00:00:24 +0800] "GET /sites/default/files/styles/thumbnail/public/images/kalola/sk_3.jpg?itok=-pXuOEq2 HTTP/1.1" 200 3958 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
18.104.22.168 - - [24/Jul/2013:00:00:24 +0800] "GET /sites/default/files/styles/thumbnail/public/images/kalola/sk_1.jpg?itok=ug6jsTPP HTTP/1.1" 200 3958 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
188.8.131.52 - - [24/Jul/2013:00:00:24 +0800] "GET /sites/default/files/styles/thumbnail/public/images/kalola/sk_2.jpg?itok=ZPOMnJeK HTTP/1.1" 200 3958 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
18.104.22.168 - - [24/Jul/2013:00:00:26 +0800] "GET /sites/default/files/styles/thumbnail/public/images/argie/currency.jpg?itok=hodqOr4_ HTTP/1.1" 200 7976 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
184.108.40.206 - - [24/Jul/2013:00:00:26 +0800] "GET /sites/default/files/styles/thumbnail/public/images/localhost27/untitled.jpg?itok=uVeczDjI HTTP/1.1" 200 3136 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
184.108.40.206 - - [24/Jul/2013:00:00:26 +0800] "GET /sites/default/files/styles/thumbnail/public/images/Oelasor/screenshot_11.jpg?itok=uu3d0GpX HTTP/1.1" 200 6674 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
126.96.36.199 - - [24/Jul/2013:00:00:27 +0800] "GET /sites/default/files/styles/thumbnail/public/images/localhost27/member.jpg?itok=inA9ULoC HTTP/1.1" 200 4500 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
18.104.22.168 - - [24/Jul/2013:00:00:28 +0800] "GET /php/4852/shopping-cart-checkout-using-codeigniter.html HTTP/1.1" 200 11414 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
22.214.171.124 - - [24/Jul/2013:00:00:29 +0800] "GET /sites/default/files/styles/medium/public/images/admin/codeigniter_shopping_cart.jpg?itok=QO0YV6JP HTTP/1.1" 200 22534 "http://www.mysite.com/php/4852/shopping-cart-checkout-using-codeigniter.html" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
220.127.116.11 - - [24/Jul/2013:00:00:32 +0800] "GET /php/4846/simple-ajax-example-php.html HTTP/1.1" 200 10174 "http://www.mysite.com/php?page=9" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
126.96.36.199 - - [24/Jul/2013:00:00:34 +0800] "GET /sites/default/files/download/teejaygenius/e_library.zip HTTP/1.1" 206 3655400 "http://www.mysite.com/sites/default/files/download/teejaygenius/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:00:00:36 +0800] "GET /sites/default/files/download/Chritian/bus.zip HTTP/1.1" 206 4462491 "http://www.mysite.com/sites/default/files/download/Chritian/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:00:00:37 +0800] "GET /sites/default/files/styles/medium/public/images/kalola/sk_2.jpg?itok=1N0a__bq HTTP/1.1" 200 9693 "http://www.mysite.com/php/4846/simple-ajax-example-php.html" "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"e188.8.131.52 - - [24/Jul/2013:03:03:13 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 1555432 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"                                                                                184.108.40.206 - - [24/Jul/2013:03:03:20 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18541381 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:03:29 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 6186320 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:03:31 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 13495467 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:03:34 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 17908605 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:03:51 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 10082448 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:03:57 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 8639709 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:04:03 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 12150765 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:04:04 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 17972316 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:04:09 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18453052 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:04:23 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 777716 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:04:40 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 8033075 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:04:45 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 12935983 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:04:49 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 8262600 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:04:49 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 11598966 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:04:49 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 11249310 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:04:57 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 5969210 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:05:02 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 12978641 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:05:03 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 13390784 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:05:07 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 6124786 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:05:15 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 9962834 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:05:19 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 12021359 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:05:27 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 8432875 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:05:44 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18371964 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:05:46 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 19867749 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:05:50 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18164900 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:06:00 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 17839100 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:06:01 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18329973 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:06:11 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18651902 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:06:31 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 9858200 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:06:34 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 12914955 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:06:36 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 13315966 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:06:38 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 12804285 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:06:41 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 6043976 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:06:42 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 11900897 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:06:52 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 8293782 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:07:06 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 11582412 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:07:24 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18667357 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
18.104.22.168 - - [24/Jul/2013:03:07:27 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 7977266 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:07:35 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 11190040 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:07:36 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18555860 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:08:09 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 5932064 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:08:10 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 12730175 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:08:13 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 13208853 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:08:16 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 8178860 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:08:22 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 5896753 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:08:25 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 8183834 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:08:26 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 12671818 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:08:30 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18581925 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
188.8.131.52 - - [24/Jul/2013:03:08:36 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18224268 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:08:37 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 11761743 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
126.96.36.199 - - [24/Jul/2013:03:08:51 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 11412627 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
220.127.116.11 - - [24/Jul/2013:03:08:59 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 18600749 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
22.214.171.124 - - [24/Jul/2013:03:09:01 +0800] "GET /sites/default/files/download/mindgamez/system1.zip HTTP/1.1" 206 11129155 "http://www.mysite.com/sites/default/files/download/mindgamez/" "FDM 3.x"
184.108.40.206 - - [24/Jul/2013:03:09:14 +0800] "GET /sites/default/files/download/argie/tameraplazainn.zip HTTP/1.1" 206 7836467 "http://www.mysite.com/sites/default/files/download/argie/" "FDM 3.x"
</code>
Here's the frequency of visits by hour:
<code># grep "126.96.36.199" /var/log/ispconfig/httpd/*/access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c
545 00:00
524 01:00
404 02:00
491 03:00
396 04:00
183 05:00
</code>
Here's the frequency of visits by minute (around 12 midnight):
<code># grep "18.104.22.168 - - \[24/Jul/2013:00" /var/log/ispconfig/httpd/*/access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
33 00:00
14 00:01
12 00:03
26 00:05
15 00:10
18 00:11
22 00:13
15 00:14
14 00:15
15 00:18
21 00:19
17 00:20
15 00:23
14 00:24
17 00:25
27 00:29
15 00:30
18 00:32
14 00:52
</code>
Here's the frequency of visits by minute (around 1AM):
<code># grep "18.104.22.168 - - \[24/Jul/2013:01" /var/log/ispconfig/httpd/*/access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
16 01:01
16 01:02
12 01:05
16 01:06
14 01:10
14 01:11
14 01:12
13 01:14
22 01:16
18 01:17
13 01:21
21 01:22
14 01:26
20 01:37
30 01:38
13 01:45
11 01:50
17 01:51
11 01:53
</code>
Is there a way to block this using IPTables or something?
If I will lower it, I'm afraid some of the legitimate traffic will be ban also.
The access rate is very low. I cannot set the maxretry to something like 50 or even 70. That will also ban legitimate traffic.
So how can I prevent this one? They consume too much bandwidth. Before my normal bandwidth is at 59.31 GB per day but now it reaches up to 136.74 GB.
Comment: You may also want to set up a honeypot...  Just add an invisible link on the home page that triggers your ban if loaded.  Humans will not (normally) access it as it's not visible but crawlers will.
Comment: @MarkHenderson. User-agent is not the way to go, they can be faked very easily. The ones that don't fake are more than likely the bots you do want indexing your site
Comment: Check their user-agents. If they are using a specific spider-related user agent, it should be simple enough to block based on that.
Comment: hi mark, can you give me some little guidance on where to check this? is it using fail2ban? or robots.txt? I believe robots.txt is of no use here since they can ignore it easily.
Comment: According to your log, the user-agent is `FDM 3.x` - see http://stackoverflow.com/questions/15599544/how-to-block-specific-human-looking-user-agent-in-nginx for info on how to block.
Comment: Also, a quick google shows this probably isn't a normal spider, but rather someone specifically scraping your entire site for content: http://en.wikipedia.org/wiki/Free_Download_Manager
Comment: @ChrisNava I am currently researching about honeypot. I've already spent several hours on how I can block this robots using honeypot. Do you know of any link that will guide me?
Comment: Sorry, I haven't been in a position to do this in a long time... This link looks like it will help you though. It mentions fail2ban integration of a "bottrap"  http://www.bsdguides.org/2012/a-simple-bot-trap-using-robots-txt/  I would add an invisible link on any page you want to protect in addition to the robots.txt suggestion.
Comment: @geosword if you have a better idea feel free to post an answer. My comment after all is just that - a comment.
Comment: Whit nginx you can use limit_req, and for iptables use dos-deflate or maybe csf - ldf whit webmin.
Answer: Maybe, as a first step, limiting the number of connections could help (IPTABLES):
(from http://www.extrapepperoni.com/post/2013/03/iptables%3A-connlimit):
<code>-A INPUT -j ACCEPT -p tcp --dport    80 -s xxx.yyy.0.0/16 --syn -m connlimit ! --connlimit-above 20
-A INPUT -j ACCEPT -p tcp --dport    80                   --syn -m connlimit ! --connlimit-above 5 --connlimit-mask 24
</code>
This will mostly help against DDoS attacks, but might be part of your problem:
The first rule allows internal users (from a specific network) to connect with up to 20 connections.
The second rule allows everybody else to only connect with 5 connections at a time.
A more general but quite complex command line tool for traffic shaping is tc:
http://www.tldp.org/HOWTO/html_single/Traffic-Control-HOWTO/
With tc you can limit the bandwidth of a particular user, service or client.


What is difference between lcuda and lcudart in CUDA SDK 7.5?

Question: I have Nvidea SDK 7.5. I want to compile OpenMP for CUDA. On step "Clone, build & install OpenMP target backends" I get:

Yet I see no libcuda.lib at all in my SDK:

So I wonder what is difference between lcuda and lcudart and if there is any where one can find lcuda in CUDA 7.5 SDK?
Answer: The l you are discussing in "lcuda" and "lcudart" is actually part of the compiler switch.  The library is cuda or libcuda, and cudart or libcudart.
On linux, I don't think these libraries end in .lib either.  They should end in .so  That's pretty evident in your printout - take a look.
Anyway, libcuda.so is installed by the GPU driver installer, not the toolkit.
(except possibly for stubs, which you should not use) libcuda.so will not be found in the toolkit location but somewhere else where the driver puts it. This particular location will vary depending on the specific linux distro.
So I suggest using find or a similar linux command to locate it on your machine.  It may be in /usr/lib or /usr/lib64 or someplace like that.
If you can't find it at all, then the likely explanation is that you have not installed (properly) the GPU driver on your machine.
In a nutshell, libcuda.so provides access to the CUDA driver API, whereas libcudart.so provides access to the CUDA runtime API.
By the way, in the future,  please post text output, not pictures, for actual text output from your console.
Comment: could not find `libcuda.so` nowhere in `/usr/`. Is there any option of asking `nvcc` where it is located?
Comment: no, `nvcc` won't locate it for you.  Is linux `find` not an option?  Something like this:  `sudo find / -name libcudart*`   If that doesn't find anything, then it is not installed, and that indicates a broken driver install.
Comment: Sorry, that should have been `sudo find / -name libcuda.*`.  And when I do that on a properly installed ppc64le node with RHEL 7, I observe that the GPU driver has placed the `libcuda.so` at: `/usr/lib/nvidia/libcuda.so` and also at `/usr/lib/libcuda.so`


Can kint be used to debug templates?

Question: Normally, I can use kint() in the place of dump() to debug my twig templates.  The theming manual agrees.
However, this doesn't work for me in Commerce 2.
In commerce-product.html.twig, I added
{{ kint(product) }}
And rebuilt the cache.
This caused me to be redirected to the "install" url, with the message "Drupal is already installed".
If I use {{ dump(product) }}, I get the expected output, but this array is enormous and hard to read so I want to use kint.  Is there something different about variables in Commerce?
If I use {{ kint(links) }} and the like in a template copied from core I see the kint output correctly.
Comment: Does this answer your question? [How to make use of Devel debugging functions on large or complex objects](https://drupal.stackexchange.com/questions/224928/how-to-make-use-of-devel-debugging-functions-on-large-or-complex-objects)
Answer: The object/array is too big for your server resources to handle the default kint settings.
Edit modules/devel/kint/kint/config.default.php and set $_kintSettings['maxLevels'] to a lower number to reduce recursion and the memory needed for dumping variables. The default is 7, I have mine set to 4. If 4 still doesn't work for you, keep lowering the number.
Answer: For debug big array, i use first :
{{kint($array|keys)}}

after i got key i can kint the array with the key.
With this method i don't have memory error.

Can kint be used to debug templates?


Group queryset into categories django

Question: I have a Ingredient model and a Shopping model for a shopping list and I would like to group ingredients by their category in the shopping list view. Is there a database method to achieve this or will running the for loop I have in my Views.py the easiest?
The below image is exactly what I would like to achieve in my shopping list view:
html:
{% for key, value_list  in shoppingList.items %}

{{key}}

    {% for value in value_list %}

{{value}}

    {% endfor %}
{% endfor %}

models.py:
class Ingredient(models.Model):
    name = models.CharField(max_length=220)
    category = models.CharField(max_length=50, default="uncategorised")

class Shopping(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    name = models.CharField(max_length=220, blank=True, null=True) # users can create their own items not just those in the Ingredient model
    category = models.CharField(max_length=80, default="uncategorised")

views.py:
def shopping_list_view(request):
    queryset = Shopping.objects.filter(user=request.user)
    shoppingList = {}

    for item in queryset:

        ingredientItem = item.name # e.g Fish

        ingredientCategory = item.category # e.g. Meat & Seafood

        if ingredientCategory in shoppingList:
            shoppingLists[ingredientCategory].append(ingredientItem)
        else:
            shoppingLists[ingredientCategory] = []
            shoppingLists[ingredientCategory].append(ingredientItem)
    # print(shoppingLists)
    # will return something like > {'Meat & Seafood': ['bacon', 'fish'], 'Baking & Spices': ['all purpose flour', 'parsley'], 'pantry': ['pasta']}
    return render(request, "shopping/shoppinglist.html", {"shoppingList": shoppingList}
    )

Comment: Consider not using SQL, but just group by `ingredient` in python.
Comment: Could you please show me your expected output?
Comment: @ShahriarRahmanZahin I have just updated the post, with how I am getting what I want currently. If the queryset was: `queryset = [['bacon', 'Meat & Seafood'], ['fish', 'Meat & Seafood'], ['oil', 'Oils & Spices'], ['pasta', 'pantry'], ['parsley', 'Oils & Spices']]`

                   I would expect the following output:
`{'Meat & Seafood': ['bacon', 'fish'], 'Oils & Spices': ['oil', 'parsley'], 'pantry': ['pasta']}`
Comment: You are definitely showing the truncated or miscopied code. Check it, please.
Comment: @Yevgeniy Kosmak, fixed
Answer: In case you use PostgreSQL, you can use ArrayAgg in annotate with values:
from django.contrib.postgres.aggregates import ArrayAgg

queryset = Shopping.objects.filter(
    user=request.user
).values("ingredients__category").annotate(
    ingredient_list=ArrayAgg('ingredients__name')
).all()

Then you'll get the list with desired structure and wouldn't need to perform any calculations at Python's side.

Group queryset into categories django


Comparing Perplexities With Different Data Set Sizes

Question: I am currently doing research comparing language modelling in English to language modelling in programming languages (namely Java) using perplexity as the metric for the language model being used. My question is whether different data set sizes will invalidate the comparison of the perplexities.
I am using the Penn Treebank as the English data set and it contains approximately 1,000,000 words. The other data sets I am using each contain about 200,000 to 500,000 words. All of the data sets have constant vocabulary size of 10,000.
If it matters at all, I am using a recurrent neural network. Would comparing perplexities be invalidated by the different data set sizes? Thanks.
Answer:
Would comparing perplexities be invalidated by the different data set sizes?

No. I copy below some text on perplexity I wrote with some students for a natural language processing course (assume $\log$ is base 2):
In order to assess the quality of a language model, one needs to define evaluation metrics. One evaluation metric is the log-likelihood of a text, which is computed as follows, assuming that the language model is a trigram model, and the text contains $N$ words:
\begin{align}
l_{\text{corpus}} = \log \left ( \prod_{i=3}^{N} p(w_i | w_{i-2},w_{i-1}) \right ) =  \sum_{i=3}^N \log p(w_i | w_{i-2},w_{i-1})
\end{align}
In order to make this metric independent from the size of the corpus, one can compute the average log-likelihood of the corpus on a per word basis, i.e. the log-likehood of the corpus normalized by the number of words:
\begin{align}
l_{\text{word_average}} = \frac{1}{N} \sum_{i=1}^N \log p(w_i | w_{i-2},w_{i-1})
\end{align}
The most common evaluation metric for a language model is the perplexity, which can be computed directly from the average log-likelihood of the corpus on a per word basis:
\begin{align}
\text{Perplexity} \ = \ 2^{-l_{\text{word_average}}}
\end{align}
Note that in general, to make a meaningful comparison between two different language models, one needs to use the same vocabulary.
Using unigram, bigram and trigram models trained on 38 million words from the Wall Street Journal, and using a vocabulary of size 19,979 one obtains a perplexity 962, 170, and 109, respectively, when tested on 1.5 million words from the same journal.
What is the intuitive meaning of perplexity? This measure can be interpreted as an actual branching factor of the model. Let's explore this intuition using a simple uniform model for unigrams: $P(w) = \frac{1}{|V|}, \forall w \in V$.
This means that:
\begin{align}
P(w_1, ..., w_N) = \prod_{i \in { [ 1, N ] }}{P(w_i}) = \left( \frac{1}{|V|} \right)^N \notag \\
\text{perplexity} = 2^{-  \frac{1}{N} P(w_1, ..., w_N)} = 2^{-  \frac{1}{N}  \log \left(  \left( \frac{1}{|V|} \right)^N    \right)} = |V|
\end{align}
Under this uniform language model, the perplexity is equal to the size of the vocabulary. Generally,  perplexity captures the effective vocabulary size under the model. For instance, a trigram model described above has a factual branching factor of 109, even though it operates over the vocabulary of 19,979.


Roman numeral analysis of chord with non-chord tone in bass

Question: We use figured bass notation to help indicate chords in inversion by establishing the interval between the bass note and the other notes of the chord.  I have seen figured-bass symbols applied to major triads, resulting in the "five-three" chord (root position), the "six-three" (3rd in bass), the "six-four" (5th in bass), as well as to 7th chords, giving us the "seven", "six-five", "four-three", and "four-two chords".  Forgive me if this explanation is too brief or if you prefer different nomenclature.
For analysis, I prefer using roman numeral notation instead of "slash" notation, in which the chords are named . . . by name.  For example, a I63 chord in C major would be written as "C/E".  Now, depending on the song, there may be chords that have neither non-chord tones nor the 7th of the chord in the bass, such as a C major chord with a D in the bass.  In slash notation, this would be a "C/D".  How would this be written in roman numeral/figured bass notation?  Note:  please treat this C/D example, along with any chord with scale degree 2, 4, or 6 in the bass, as an actual chord, rather than a chord with a counter-melody moving in the bass line--I am not thinking of the bass as a passing tone here.
Is there a procedure for naming chords with scale degrees 2, 4, or 6 in the bass?  Please let me know.
Best,
286642
Comment: Related question: [Roman numeral notation for a suspended chord?](https://music.stackexchange.com/questions/25670/roman-numeral-notation-for-a-suspended-chord).
Comment: Related question: https://music.stackexchange.com/questions/73537/using-roman-numeral-notation-with-notes-in-the-bass-not-figured-bass
Answer: The figures would still reflect the intervals above the bass, so X[7-4-2] or, possibly, X[9-7-4]. The Roman numeral would depend on the context. In common practice harmony C/D would be some kind of suspension, so X would be the chord of resolution. X cannot be determined from the information given in the OP. At minimum, we need to know the key and the next chord, if not additional chords before and after.
Roman numeral analysis is context dependent.
Comment: @Tim - C/D can easily be a suspension - one that involves the bassline. For example, I'd treat the C/D in G7/D - C/D - C as a suspension.
Comment: @286642 Slash chords don't have a single function. They could be chord inversions, suspensions, pedal tones, part of an independent bass-line happening against a set of chords. Further, when a song is written using chord notation, it is often used as a practical shorthand rather than a formal, analytic interpretation. Finally, pop music doesn't attempt to adhere strictly to the functional ideas behind Roman numeral analysis. So, with all that said, I encourage you to re-post your comment as its own question. You've asked the general question here; now ask the specific one. Best of both worlds.
Comment: If the preceding chord were a garden-variety C major chord or even a C/E chord then the figures for the C/D chord could just be horizontal lines.
Comment: As an example, we could look at "The Long and Winding Road", which I am trying to analyze the harmony of.  The progression, in E-flat major, goes: Cm Gm Ab/Bb Eb Eb7/Db Ab Eb/G Cm7 . . . how would you draw that up in roman numeral analysis?  I am trying to determine the function of the slash chords.
Comment: @286642 You might find this post helpful: [What does the chord notation X/Y ("slash chord") mean?](https://music.stackexchange.com/questions/104163/what-does-the-chord-notation-x-y-slash-chord-mean).
Comment: C/D isn't a suspension. C/D is made up from C D E G. A suspension would necessitate losing the E, but it's going to be there. Cadd9.


Is "Covariance is 0" equivalent to "Conditional Expectation equals Unconditional Expectation"?

Question: In formulas:
\begin{align}
Cov(X,Y)=0 \quad \Leftrightarrow\quad \mathbb{E}[Y|X]=\mathbb{E}[Y]
\end{align}
is this true?
Comment: Not sure what the problem is - I mean if I actually would have expected an answer from someone else I would maybe have put more effort into it but it was just a question I couldn't find an answer to when looking so I thought I would post the answer I found since this seems like something that someone else might think about as well
Answer: Only "$\Leftarrow$" is true:
\begin{align}
Cov(X,Y)&=\mathbb{E}[(X-\mathbb{E}[X])(Y-\mathbb{E}[Y])] \\
&=\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]\\
&=\mathbb{E}[\mathbb{E}[XY|X]]-\mathbb{E}[X]\mathbb{E}[Y]\\
&=\mathbb{E}[X\mathbb{E}[Y|X]]-\mathbb{E}[X]\mathbb{E}[Y]\\
&=\mathbb{E}[X\mathbb{E}[Y]]-\mathbb{E}[X]\mathbb{E}[Y]\\
&=0
\end{align}
While "$\Rightarrow$" is false in general:
Be $X\sim N(0,1)$ and $Y:=|X|$ then $\mathbb{E}[X|Y]=0$ which implies that $Cov(X,Y)=0$ as shown above. But $\mathbb{E}[Y|X]=Y$
Comment: https://math.stackexchange.com/a/376087/445105


for loop goes infinite within the ready function

Question: <code>    $(document).ready(function() {
        for (var i=0; i<20; i++) {
        document.write('hello world');
    }
    });
</code>
in this code for goes infinite. so what's the reason of that?
Comment: *-shrug-* Not for me. http://jsfiddle.net/BoltClock/ZWjL9
Comment: it doesn't go to inifinite? it stops at 20? http://jsfiddle.net/niklasvh/bMyhf/
Comment: What do you mean 'goes infinite'? By inspection and testing, there's no infinite looping here.
Answer: It does not go infinite,it prints 20 times only.
Comment: So I'm not sure what the heck is going on here. You ask why it runs infinitely, Srinivas says it doesn't, and then you mark him accepted and leave?
Answer: Is it possible that your document.write() is triggering another 'ready' event every time? Can you put an alert or something before the for loop to see if the ready function is being called repeatedly?


Consulta promoção ecommerce

Question: Estou desenvolvendo uma plataforma ecommerce, e me deparei com um problema para calcular o valor dos produtos, aplicando o desconto das promoções na consulta SQL, atualmente as regras de promoção estão sendo aplicadas no PHP, porém quando mando ordenar por valor, ele ordena sem levar em consideração o valor do produto com a promoção aplicada, e esse não é o objetivo, necessito que o produto que tiver a promoção na lista fique antes dos produtos de maior valor que ele.
Obs.: As promoções podem ser associadas as categorias ou aos próprios produtos e um produto/categoria pode ter mais de uma promoção associada, as promoções podem acumular de acordo com uma flag existente dentro da tabela de promoção e os descontos podem ser preço fixo ou porcentagem de acordo com o campo tipo existente dentro da promoção, que determina se o desconto é porcentagem ou valor.
Atualmente minha consulta retorna os produtos é assim (de forma simplificada sem levar em consideração outros tabelas relacionadas que não inteferem em minha pergunta):
SELECT p.nome, MIN(e.valor) AS valor, p.id_produto, c.categoria
FROM produtos p
INNER JOIN estoque e ON p.id_produto = e.id_produto
INNER JOIN categorias c ON p.id_categoria = c.id_categoria
GROUP BY p.id_produto
ORDER BY valor, p.id_produto

E minha tabela de promoção é assim:
id_promocao INT
data_inicial DATETIME
data_final DATETIME
acumular TINYINT(1)
ativo TINYINT(1)
tipo TINYINT(1)
valor DECIMAL(10,2)

E existe as tabelas produtos_promocoes que relaciona os produtos com as promoções e categorias_promocoes que relaciona as categorias com as promoções.
Alguém já fez algo parecido ou conhece alguma solução para isso?
Answer: Resolvido usando functions.
Links que auxiliaram:
Procedures e functions
Cursor

Consulta promoção ecommerce


Parallelize bash script in HPC slurm

Question: I have a file like this:
bash scripts/1-Call_HC.sh Uni_Mont_1_3 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_1_3.e 2> logs/HC_Uni_Mont_1_3.o
bash scripts/1-Call_HC.sh Uni_Mont_27_1 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_27_1.e 2> logs/HC_Uni_Mont_27_1.o
bash scripts/1-Call_HC.sh Uni_Mont_27_2 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_27_2.e 2> logs/HC_Uni_Mont_27_2.o
bash scripts/1-Call_HC.sh Uni_Mont_29_1 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_29_1.e 2> logs/HC_Uni_Mont_29_1.o
bash scripts/1-Call_HC.sh Uni_Mont_29_3 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_29_3.e 2> logs/HC_Uni_Mont_29_3.o
bash scripts/1-Call_HC.sh Uni_Mont_30_1 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_30_1.e 2> logs/HC_Uni_Mont_30_1.o
bash scripts/1-Call_HC.sh Uni_Mont_30_2 /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_30_2.e 2> logs/HC_Uni_Mont_30_2.o

In a normal machine I will use nohup parallel -j 3 < file.sh to parallelize the execution. I would like to do the same on a HPC server with Slurm using the queue of the server.
How can I do that?
Thanks a lot,
Denise
Answer: A job array should do the job here.
Write a submission script like this:
#! /bin/bash
#SBATCH --ntask=1
#SBATCH --cpus-per-task=...
#SBATCH --mem-per-cpu=...
#SBATCH --array=0-6

OPTIONS=(1_3 27_1 27_2 29_1 29_3 30_1 30_2)
CURROPT=${OPTIONS[$SLURM_ARRAY_TASK_ID]}

bash scripts/1-Call_HC.sh Uni_Mont_$CURROPT /home/db/fagiolo/config_fagiolo_Pvulgaris.sh > logs/HC_Uni_Mont_$CURROPT.e 2> logs/HC_Uni_Mont_$CURROPT.o

and submit it with sbatch. This will create 6 independent jobs that will be scheduled in parallel.
Comment: I'm doing it but is always the same sample starting
Comment: I've change CURROPT=${OPTIONS[$SLURM_ARRAY_JOBID]} with CURROPT=${OPTIONS[$SLURM_ARRAY_TASK_ID]} and it works! Thanks
Comment: @DeniseLavezzari Indeed, thanks, corrected.

Parallelize bash script in HPC slurm