SpreadJS not working in Webpack based angular application

Question: I am trying to add the spreadjs library to my Angular 5 application. I am following the tutorial given in this link.
https://www.grapecity.com/en/blogs/spread-sheets-and-angular
But one difference is there between the tutorial and my application. My app is using webpack.
When I am trying to run the application I am getting the following error

Uncaught ReferenceError: GC is not defined
      at Object. (gc.spread.sheets.angular.11.0.4.js:106)
      at webpack_require (bootstrap 05add16ed08b4def07f8:657)
      at fn (bootstrap 05add16ed08b4def07f8:85)
      at Object. (app.module.browser.ts:21)
      at webpack_require (bootstrap 05add16ed08b4def07f8:657)
      at fn (bootstrap 05add16ed08b4def07f8:85)
      at Object. (index.js:4)
      at webpack_require (bootstrap 05add16ed08b4def07f8:657)
      at fn (bootstrap 05add16ed08b4def07f8:85)
      at Object.options.path (html5-entities.js:190) (anonymous) @ gc.spread.sheets.angular.11.0.4.js:106
  webpack_require @ bootstrap 05add16ed08b4def07f8:657 fn @ bootstrap 05add16ed08b4def07f8:85 (anonymous) @
  app.module.browser.ts:21
  webpack_require @ bootstrap 05add16ed08b4def07f8:657 fn @ bootstrap 05add16ed08b4def07f8:85 (anonymous) @ index.js:4
  webpack_require @ bootstrap 05add16ed08b4def07f8:657 fn @ bootstrap 05add16ed08b4def07f8:85 options.path @ html5-entities.js:190
  webpack_require @ bootstrap 05add16ed08b4def07f8:657 fn @ bootstrap 05add16ed08b4def07f8:85
  decorate @ main-client.js?v=m6MAq5LYDxHuj3aQ3FLsDASzSdE0PXrpCFP8K7zsieI:4472
  __webpack_require @ bootstrap 05add16ed08b4def07f8:657 module.exports @ bootstrap 05add16ed08b4def07f8:706 (anonymous) @
  bootstrap 05add16ed08b4def07f8:706

I tried adding  the javascript link to webpack.config.vendor.js. My backend is .net core webapi. Please advice me what to do next
Answer: EDIT
This is likely the result of not importing some required scripts in the angular.json file. This is a step that the default SpreadJS instructions  GrapeCity's website (https://www.grapecity.com/en/blogs/spread-sheets-and-angular) are lacking for current Angular applications.
I found this missing step on one of GrapeCity's Angular/SpreadJS blogs (https://www.grapecity.com/en/blogs/create-angular-spreadsheets-with-angular-cli) , which was a little hidden on their site.
The step you need is:
angular.json:
{
  (…)
  "apps": [
    {
      (…)
      "styles": [
        "./lib/gc.spread.sheets.excel2013darkGray.11.0.0.css"
      ],
      "scripts": [
        "./lib/gc.spread.sheets.all.11.0.0.min.js"
      ],
      (…)
    }
  ],
  (…)
}

Change the filepath to wherever you placed your SpreadJS files. Note that at least in my app, my angular.json files has two styles arrays and two scripts arrays - insert these references into the top set (the styles and scripts array closest to the top of the angular.json file).


how to apply paging on a list

Question: I have a function that retrieves data from database and add it into list. My list is ready and shows the data but i want paging on that list so that it shows limited records per page. but no idea about how to do that.
Here is my code of that data layer function.
 public List<demodto> executereader(List<demodto> Ldemo,SqlCommand cmdshow, string tablename)
    {
         SqlConnection cn;
         try
         {
             cn = this.getconnection();

             cmdshow.Connection = cn;
             cn.Open();

             SqlDataReader rd = cmdshow.ExecuteReader();
             while (rd.Read())
             {
                 demodto dtoobj1 = new demodto();
                 dtoobj1.ID = Convert.ToInt32(rd[0].ToString());
                 dtoobj1.Name = rd[1].ToString();
                 dtoobj1.PhNo = Convert.ToInt32(rd[2].ToString());
                 dtoobj1.Address = rd[3].ToString();
                 dtoobj1.Gender = rd[4].ToString();
                 dtoobj1.Email = rd[5].ToString();
                 dtoobj1.Emptype = rd[6].ToString();

                 Ldemo.Add(dtoobj1);

             }
             cn.Close();
             return Ldemo;
         }
         catch (Exception ex2)
         {
             throw new DataException("error....." + ex2.Message);

         }

    }

And this is for DTO class..
 public class demodto
{
    public Int32 ID{get;set;}
    public string Name{get;set;}
    public Int32 PhNo { get; set; }
    public string Address{get;set;}
    public string Gender { get; set; }
    public string Email { get; set; }
    public string Emptype { get; set; }
 }

please help me. Thanks.
Comment: Possible duplicate of [Paging with LINQ for objects](http://stackoverflow.com/questions/2380413/paging-with-linq-for-objects)
Answer: You can page a list with LINQ, like this:
IList<demodto> GetPage(IList<demodto> list, int page, int pageSize) {
    return list.Skip(page*pageSize).Take(pageSize).ToList();
}

For example, suppose each page has 50 records. To get a third page, call
IList<demodto> thirdPage = GetPage(dataList, 3, 50);

Note, however, that applying paging to data in memory makes very little sense: the idea behind paging is to cut down on the time it takes to retrieve your data from the database, and to save some memory by keeping only a single page, which is not going to happen in your case, because all data is retrieved at once.
In order to make paging worth the effort, you need to move it into the database. Change your method to accept page size and number, and use them to change the SQL to retrieve the list for a single page. Don't forget to force ordering on your sql read, otherwise the same data might appear on different pages. Your SQL needs to be modified to support pagination. This is done differently depending on your database. MS SQL Server solution is described in this answer.
Comment: Shouldn't it be `return list.Skip(page - 1 * pageSize).Take(pageSize).ToList();` ?
Comment: @Saket It depends on whether you consider `page` one-based or zero-based. I prefer zero-based numbering.
Comment: @dasblinkenlight do you have any idea how to know the total page number of the given collection length via LINQ?
Comment: @Roel, i'm a little late to the party but you could use: `int result = Math.DivRem(int a, int b, out new int remainder);`

If remainder is greater than 0 add one to the result (the quotient) and that is your total page count.

[Math.DivRem()](https://learn.microsoft.com/en-us/dotnet/api/system.math.divrem?view=netframework-4.8)
Answer: int pagesize = 1000;
int countitens = list1.Count();
int pagecount = countitens % pagesize <= 0 ? countitens / pagesize : (countitens / pagesize) + 1; // for example 10001 itens and page size of 1000 retusn 2 pages
for (int page = 0; page < pagecount; page++)
{
    var itens = list1.Skip(page * pagesize).Take(pagesize).ToList();
}

Or just
var itens = list1.Skip(page-1 * pagesize).Take(pagesize).ToList(); // page-1 if value of page start with 1

Answer: _context.skip(5).take(10)

Try to use this one. Better explanation in this question Paging with LINQ for objects
Answer: Skip and Take extension methods fits your needs.I don't know how is your page structure but you can use a simple for loop to get values like this:
int recordPerPage = 20;
for(int i=0; i<pageCount; i++)
{
   var values = list.Skip(recordPerPage*i).Take(recordPerPage).ToList();
   // add values to the page or display whatever..
}

Answer: In new versions of SQL Server you can use the ROWNUMBER Function
rowStart    = ((Page - 1) * PageSize) + 1
rowEnd      = Page * PageSize

SELECT * From (SELECT ROW_NUMBER() {0} As RowNum, * FROM table WHERE condition) AS RowConstrainedResult Where RowNum >= rowStart And RowNum <= rowEnd Order By RowNum

This then makes the whole thing a lot quicker as you are not bringing back the whole data-set, just those records on the page you want
Answer: You can iterate while checking that the list is fully processed:
using System;
using System.Linq;

var list = new bool[21];
var batchSize = 10;

var count = list.Length;
var remain = count;
while(remain > 0) {
    var batch = list.Skip(count - remain).Take(batchSize);
    Console.WriteLine($"remain: {remain}\t.Skip({count - remain}).Take({batchSize})\tbatchCount: {batch.Count()}");
    remain -= batchSize;
}

Output:
remain: 21    .Skip(0).Take(10)    batchCount: 10
remain: 11    .Skip(10).Take(10)   batchCount: 10
remain: 1     .Skip(20).Take(10)   batchCount: 1

Answer: Starting from .NET 6 you can write this:
list.Chunk(pageSize).ElementAt(page); // page starts from 0

Answer: Just an addition. You can have a reusable generic method which will give paginated data for any list of object.
 public List<T> GetPaginatedDataFromList<T>(List<T> list, int pageSize, int pageIndex)
        {
            return list.Skip(pageIndex * pageSize).Take(pageSize).ToList();
        }

how to apply paging on a list


How to use internationalization in cakephp with custom URL and extensions

Question: I am using cakephp 2.0 for an application...
everything is fine but I am getting some problem with custom URL or SEO friendly URL.
Here are Route rules that I am using
Router::parseExtensions('html', 'rss', 'xml','json');
    Router::connect('/:language/:controller/:action/*',array(),array('language' => 'eng|chi'));
    Router::connect('/', array('controller' => 'homes', 'action' => 'index'),array('language' => 'eng|chi'));
    Router::connect('/backend/*', array('controller' => 'users', 'action' => 'login', 'lab' => true));
    Router::connect('/about-us/*', array('controller' => 'homes', 'action' => 'about_us'));
    Router::connect('/contact/*', array('controller' => 'homes', 'action' => 'contact'));
    Router::connect('/:slug', array('controller' => 'homes', 'action' => 'page'), array('pass' => array('slug'), 'slug'=>'[a-zA-Z0-9-]*'));

Here for "about-us", 'contact-us' and 3rd and main one is ":slug" ( dynamic )
Two problems:

When I try to change language, url is showing lang/controller/action ( abc.com/eng/homes/about_us )  instead of abc.com/eng/about-us.html or abc.com/chi/about-us.html
for other dynamic url eg. abc.com/page-1.html, abc.com/page-2.html, abc.com/page-3.html so on... how to use abc.com/lang/slug with .html ( abc.com/eng/page-1.html or abc.com/chi/page-1.html)

For this I am using the
Router::connect('/:slug', array('controller' => 'homes', 'action' => 'page'), array('pass' => array('slug'), 'slug'=>'[a-zA-Z0-9-]*'))

rule.
Answer:
When i try to change language, url is showing lang/controller/action ( abc.com/eng/homes/about_us )

The route definitions in the question have this first:
Router::connect(
    '/:language/:controller/:action/*',
    array(),
    array('language' => 'eng|chi')
);

Routes are tested in the order they are declared - this route will match any url which has the language eng or chi passed to it, as all urls have a controller and an action this route will always match.

instead of abc.com/eng/about-us.html or abc.com/chi/about-us.html

If there needs to be a route match for /:lang/:slug - then there has to be a route defined matching that pattern - currently there isn't.

for other dynamic url eg abc.com/page-1.html, abc.com/page-2.html, abc.com/page-3.html so on ... how to use abc.com/lang/slug with .html ( abc.com/eng/page-1.html or abc.com/chi/page-1.html)

I don't fully understand the question but the answer is probably to ensure that all routes exist with a prefix and are defined before the routes without a prefix. e.g.:
Router::parseExtensions('html', 'rss', 'xml','json');

// Define Chinese language routes first as they have a prefix
Router::connect('/chi/', ['controller' => 'homes', 'action' => 'index'],['language' => 'chi']);
Router::connect('/chi/backend/*', ['controller' => 'users', 'action' => 'login', 'lab' => true],['language' => 'chi']);
Router::connect('/chi/about-us/*', ['controller' => 'homes', 'action' => 'about_us'],['language' => 'chi']);
Router::connect('/chi/contact/*', ['controller' => 'homes', 'action' => 'contact'],['language' => 'chi']);
Router::connect('/chi/:slug', ['controller' => 'homes', 'action' => 'page'], ['pass' => ['slug'], 'slug'=>'[a-zA-Z0-9-]*'],['language' => 'chi']);
Router::connect('/chi/:controller/:action/*',[],['language' => 'chi']);

// Define English language routes last as they don't have a prefix
Router::connect('/', ['controller' => 'homes', 'action' => 'index'],['language' => 'eng']);
Router::connect('/backend/*', ['controller' => 'users', 'action' => 'login', 'lab' => true],['language' => 'eng']);
Router::connect('/about-us/*', ['controller' => 'homes', 'action' => 'about_us'],['language' => 'eng']);
Router::connect('/contact/*', ['controller' => 'homes', 'action' => 'contact'],['language' => 'eng']);
Router::connect('/:slug', ['controller' => 'homes', 'action' => 'page'], ['pass' => ['slug'], 'slug'=>'[a-zA-Z0-9-]*'],['language' => 'eng']);
Router::connect('/:controller/:action/*',[],['language' => 'eng']);

In this way all routes can be parsed unambiguously, and generated unambiguously too - assuming language is always passed when generating a url; the persist parameter can help with that.


FTP to use SSL/TLS

Question: I have two applications
a) App-1 - Which is a FTP client (ftp client functionality is built-in into the application code). This is deployed of Host-1.
b) App-2 - Which is a FTP server (ftp server functionality is built-in into the application code). This is deployed on Host-2
Both of these applications are COTS product and are sitting in the internal network and communicating with each other. In addition, both of these application have other Business Logic and performs lot of analysis and computation. Since both these application use their own code and not use OS provided FTP client and server (package) I am stuck.
We recently had an security audit and have been asked NOT to use FTP. The problem is we do not have access to the application code and we want these application to use SSL/TLS (secure channels for communication). I was wondering if there are any solutions which we can use to fix this issue.
Some of the solution that comes to my mind are:
1. Using stunnel based SSL/TLS tunnel on both Host-1 and Host-2 but here the signaling and data channels become the issue.
2. Host-1 to Host-2 IPSEC tunnel.
Can anyone help me with how to setup either of these to make it functional? I am also open to other solutions (except changing the applications or its code).
Thanks
Garry
Comment: Is a ssh tunneling an acceptable Solution? (some security policy does not permit this)
Comment: I agree with you on this one @AlessandroCarini
Comment: VPN between them?
Answer: Restricting SSL/TLS to only selected ports like done with stunnel or SSH forwarding is not possible because the design of FTP uses dynamic ports for the data transfer. This leaves some local proxy on each site which could translate between FTP and FTPS and back (don't know if there is a product for this) or a VPN/IPSec between the two systems.
Comment: On internal network (no NAT involved) FTP does not need to be in PASV
Comment: @AlessandroCarini: I have no idea what this comment relates to. Could you explain it in more detail? If it refers to passive vs. active mode then I can not see any relation to this answer since dynamic ports for data connections are used in both cases - the only difference is which side allocates the listener and announces the port.
Comment: I agree with @SteffenUllrich The only solution that I am able to think of is having a point-to-point IPSEC channel created between the two host to make sure all traffic between these go over secure and encrypted channel. However, this will affect the SLAs because of compression/ decompression and encryption/decryption overhead.

FTP to use SSL/TLS


Laravel: MASSIVE updateOrCreate()

Question: I am trying to export data (nightly) out of an archaic system into something that's a little bit easier to write code for; however, the amount of data being exported is MASSIVE.
I am dumping the data as JSON objects and then trying to updateOrCreate() using Laravel, but I have way too much data. It usually takes about 10 hours to process all of the data into the 2.5 MILLION MySQL rows.
I think it is slow because it is actually performing 5 MILLION queries.
Does anyone know of any good example on how efficiently execute a MASSIVE updateOrCreate() using Laravel?
Comment: You're probably going to want to do this outside of Eloquent.
Comment: ORMs are not particularly great at handling lots of data. Use plain old sql for this. Insert ... select ... for inserts, multi table updates for updates.
Comment: you might want to chunk data at least to avoid occupying your memory with these data before processing. How about attempting this method: https://stackoverflow.com/a/44891984/5704410
Answer: Probably a lot of depends on exact data, but I would try to work with data packages. So you first for take for example 500 data records from JSON, then you manually run 500 queries to verify if data exists.
For those that exist you run update for each of them but for those that don't exist you don't insert them into immediately but you put them into array and then you insert them in bulk like this:
<code>DB::table('your_table')->insert($records);
</code>
You should make sure you don't have too many records or too less to speed up the process as much as possible.
In general bulk inserts can speed your operations a lot but everything depends on data you have and what is exact algorithm of putting those data.
Comment: I like this approach.  It will definitely speed things up, but I am afraid it won't be very much as I am pretty sure 95% of the data is just updates (if it even needs to be updated since it is being dumped whether it has changed or not)
Comment: Are you checking whether the data has actually changed before updating? Select queries are much less expensive than updates.
Answer: Try dividing your data into chunks and try to insert it. It might reduce time and try not to insert same data repeatedly.
<code>$dataChunks = array_chunk($data, 10000);

foreach($dataChunks as $dataChunk){
   foreach($dataChunk as $record){
       DB::table('your_table')->insert($record);
   }
}
</code>
You can increase size of your chunks according to your data's size

Laravel: MASSIVE updateOrCreate()


PuTTY Option: Remote command = 'Top' / How to retain session after 'q' command?

Question: Example #1) 'Unmodified' PuTTY login to default directory >> Enter 'Top' Command >>> enter 'q' = You land back at the root (default) directory.
Example #2) Use the PuTTY settings option remote command = "Top" >> From the top enter 'q' = Instant logout (session closed)
Example #3) Same as #2 w/ 1 difference: PuTTY remote command = echo "Hello World!";  top;
^^^
re #3: I was thinking the brief pause to echo (for example) Hello World! would simulate Example #1 and after 'q' I would land back "Home", but the result was equal to #2 (session closed)
Quick Summary: This is one of those things which "should be simple"; How do I login straight to the 'top' and still have a session after 'q'?
...
..
EDIT: An amazingly fast flood of answers for this time of morning!

logout: not login shell: use `exit'

Here is the exact code which is working best:
top; /bin/bash -il

I'm also testing Phil's code now, his is virtually the same.
Answer: SSH executes the remote command by passing it to your configured shell to execute. If you open PuTTY with the the remote command top, then SSH will run the following:
$SHELL -c "top"

When run with the -c argument, the shell terminates once the command terminates, which causes your session to end.
To run top and then stay logged in, you can use the remote command top; $SHELL -l. This will run top and then start a login shell.
Comment: +1 for maintaining the existing shell. (rather than just assuming bash, like me)
Comment: Yours creates the type of session I'm used to, w/ a 'normal' logout vs. the message  "logout: not login shell: use `exit'"
Answer: It's logging you out because you told putty to run one and only one command in your remote session, which is top.
You could make a file ~/bin/topsh, which said
#!/bin/bash
top
exec bash

and use putty's "remote command" option to try running that; once you leave top, the session will be overwritten with a bash shell, and when you leave that, you should be automatically logged out.
Answer: Try changing your remote command to
top; bash

Answer: One the remote command exits, the shell it runs in will also close, which ends your session. If your last command is top, then existing that will always close your session.
Try top; bash as your command and you'll run a shell after top exits. The session will only then end once you've closed that bash session.
Answer: The best bet is to look at top's batch mode. You can do something like top -n1 -b to get a snapshot of the system. I'm not aware of anyway to get top to stop clearing the screen on exit.
Comment: This isn't what the question is about.


How to prove that if the sum of the totatives of two numbers is equal then the numbers are equal?

Question: As the title says, I am trying to prove that if the sum of the totatives of $a$ equals the sum of the totatives of $b$ then $a = b$ but I am stuck. I have that sum of totatives of $n = f(n)= \frac{n*\phi(n)}{2}$, but I am unsure of how to show that $f(a) = f(b) \implies a = b$.
I have the following:
$f(a) = \frac{a*\phi(a)}{2} = f(b) = \frac{b*\phi(b)}{2}$
$\implies a*\phi(a) = b*\phi(b)$
I am not sure where to go from here.
Comment: This link doesn't have the answer, but it might help: http://oeis.org/A023896
Answer: We are told that $a\varphi(a)=b\varphi(b)$, and want to conclude that $a=b$.
Suppose the result is true whenever $\max(a,b)\lt n$. We show the result is true when $\max(a,b)=n$.
Let $p$ be the largest prime that divides $a\varphi(a)$, or equivalently $b\varphi(b)$. Then $p$ is the largest prime that divides $a$, and $p$ is the largest prime that divides $b$. Moreover,  $a=p^ka'$ and $b=p^kb'$ for some integer $k$, where neither $a'$ nor $b'$ is divisible by $p$. Thus $a\varphi(a)=p^ka'p^{k-1}(p-1)\varphi(a')$ and
$b\varphi(b)=p^kb'p^{k-1}(p-1)\varphi(b')$.
Divide both $a\varphi(a)$ and $b\varphi(b)$ by $p^k\varphi(p^k)$. We get that $a'\varphi(a')=b'\varphi(b')$. By the induction hypothesis $a'=b'$ and therefore $a=b$.


slow down processes (cpu usage)

Question: I found out that an imagemagick/convert application on my VPS is causing troubles due to high load on my box. Now i added renice with priority 10 to all of these convert-processes for throttling each minute.
However, I am not sure if it really slows down the process and relieves my CPU (only 1-core).
How to really make sure that specific processes do not increase the load significantly or attack the stable system?
I have >500MB free RAM, hardly any swap in use and a low iowait at any time. So I guess, it's really because of the cpu with only 1 core. Most of the time, this is enough and no waiting times. But in case of some conversions are running, it's failing.
Answer: Re-nicing processes won't decrease your load average -- the lower-priority processes are still in the run queue, after all.  However, load average is a poor measure of responsiveness, anyway.  You should be monitoring the business-relevant performance statistics of your service (eg is latency important?  Measure that.  Is throughput important?  Measure that).  Correlating configuration changes like lowering the priority on your convert jobs against the business-level metrics should tell you whether your changes have had an effect, and if so, how much of an effect and whether it is sufficient.
Comment: The relevant information is specific to your application and business requirements.  The command is similarly specific.
Comment: Which output will give me all the relevant information at once? It's hard to catch the metrics in realtime when the high load "happens"? nagios is only telling me that the load is high and i manually login and check top, free, iostat. I worry about nagios not giving me really useful information.
Comment: Business requirements: My priority is "only" on the mysql and apache2 which serve my website. It has normal traffic, no peaks. RAM is enough and I/O is average and maybe the 1-core cpu is a bottleneck. Usually it is enough, but sometimes there are some of the conversion processes which are NOT priority tasks. That's why i tried to renice them down to prio of 10. This is nonsense if renice does not affect anything strictly.
Comment: So monitor mysql and apache2; if their operation improves, then you have a win.  `nice` does most assuredly affect the operation of the niced program, in precisely the manner it says on the tin; that it doesn't do what you *expect* is a limitation of your expectation, not the program.

slow down processes (cpu usage)


File's properties: lastModified vs lastModifiedDate

Question: On the following page they mention lastModified and lastModifiedDate. lastModifiedDate is working in every browser for me (FF, Chrome, IE, Edge, Opera) but it is written that is deprecated. lastModified doesn't exist in IE or Edge. So which to use?
Answer: In this case the correct procedure is to verify programmatically if lastModified is available and in that case use it; if it is not available you should fallback to the deprecated one. In this case you are guaranteed to use the most "uptodated" standard if possible.
Answer: Use whichever is available, preferably the non-deprecated one:
var lastModified = file.lastModified || file.lastModifiedDate;

Answer: If lastModifiedDate is deprecated  and works in every browser but lastModified isn't working in IE and Edge, you can write a test to see if lastModified is available so you can use it, otherwise use the deprecated one.
if(File.lastModified){
  //Do whatever you want using File.lastModified
}else{
  //Use File.lastModifiedDate
}

Just make sure you test for lastModified in the first place as it isn't deprecated, so you avoid using the deprecated one in most cases.


Equals pointer in ternary search tree and limitations

Question: HERE it is said that each node in a ternary search tree has three pointers. Left, right and equals. But in the example tree for {CAT, BUGS, CATS, UP}, How is that  equals pointer of 'C' points to 'A' ? 'C' and 'A' are not equal right ?
And if a node can have only three pointers, how will a ternary tree represent a set of keys like {CAB,CBA,CDA,CEA,CFA} ?
Answer: A1:
The equals pointer marks the continuation of the current prefix. Thus C -> CA -> CAT -> CATS but not C -> CB[UGS].
A2:
This would be a ternary search tree for the given set of expressions ( termination flags and leaf node expansion omitted):
<code>                                           C
                                           |
                      +--------------------+---------------------+
                      |                    |                     |
                     /l/                  /e/                   /r/
                      |                    |                     |
                      C                    D                     C
                      |                    |                     |
          +-----------+----+           +---+---+             +---+-----------+
          |           |    |           |   |   |             |   |           |
         /l/         /e/  /r/         /l/ /e/ /r/           /l/ /e/         /r/
          |           |    |           |   |   |             |   |           |
          C           B    x           x   A   x             x   E           C
          |           |                                          |           |
          |           |                                          |           |
      +---+---+   +---+---+                                  +---+---+   +---+---+
      |   |   |   |   |   |                                  |   |   |   |   |   |
     /l/ /e/ /r/ /l/ /e/ /r/                                /l/ /e/ /r/ /l/ /e/ /r/
      |   |   |   |   |   |                                  |   |   |   |   |   |
      x   A   x   x   A   x                                  x   A   x   x   F   x
          |                                                                  |
          |                                                                  |
      +---+---+                                                          +---+---+
      |   |   |                                                          |   |   |
     /l/ /e/ /r/                                                        /l/ /e/ /r/
      |   |   |                                                          |   |   |
      x   B   x                                                          x   A   x
</code>
Comment: The key insight: If you follow the `e[qual]` pointer, you increment the 'current char' ('#cc') position in your input string. If you follow either `l[eft]` or `r[ight]`pointer, you don't. Example (CBA search): #cc is 1. Start with the root node, which has C as payload - match. Follow `e` (so #cc=2) and check the successor node if it has B as payload. It hasn't, the payload character (D) is greater than B. Therefore your input string is smaller than the strings under the current node and you have to search the left subtree of the parent node ...
Comment: ... So backup to the parent node (and remember, that's where #cc was 1 !) and follow `l`. Don't change #cc. you compare C from the input string to the payload(C). Next you follow the `e` pointer, increment #cc to 2 and compare B to the payload (B). 1 more step ( A=A ) and you've consumed the input. Check that the termination bit of the node is set to make sure, that your input is a key represented in the search tree and not just a prefix of stored keys.
Comment: Thanks a lot for replying. I did not get the answer to part 2. Probably I should revisit and try to understand insert operation before asking again.   But not sure how someone will search for CBA in the tree that you formed. ..  I start at root which is C .. but then no child of root C has B.  I think I have not understood the whole thing at all. :)
Comment: That was am amazing explanation. Thanks a lot. Can you please explain insert as well in few words with an example. If we already have CDA in tree and we want to insert CBA .. something of this sort ?  Thanks again .. sorry if I am pushing this too much.
Comment: If you suggest .. I can create a different question/post for insertion :)


What should i know about search engine crawling?

Question: I don't mean SEO things. What should i know. Such as

Do engines run javascript?
Do they use cookies?
Will cookies carry across crawl sessions (say cookies from today and a craw next week or month).
Are selected JS filters not loaded for any reason? (Such as suspected ad which is ignored for optimization reasons?)

I don't want to accidental have all index page say some kind of error or warning msg like please turn on your cookie, browser not supported, or not be indexed because i did something silly such as having my sitemap point to <code>/r?id=5</code> and not have then index because it is a redirect (i would use 301 however).
Answer: From here: http://www.google.com/support/webmasters/bin/answer.py?answer=35769
Use a text browser such as Lynx to examine your site, because most search engine spiders see your site much as Lynx would. If fancy features such as JavaScript, cookies, session IDs, frames, DHTML, or Flash keep you from seeing all of your site in a text browser, then search engine spiders may have trouble crawling your site.
Read Google's Webmaster guidelines


Hibernate, Maps and HQL

Question: Can anybody tell me how maps are used in HQL.
The documentation only have examples like
From Student s WHERE s.courseScore['coursename'] = 'F'

As in, the keys are hard coded. Can anybody point me to some documentation on how to use this with actual class instances as keys? Something like,
From Course c, Student s JOIN s.courseInfo info WHERE info[c].score = 'F'

The above doesn't work, but I'm guessing there must be some way of doing it. I found out I can  use index() to get the keys from a Map property. Ala'
... WHERE index(info) = c

So I can check if a key is exits in the map, but how do I actually get a instance mapped key a key?
Answer: The following does the trick
WHERE index(info) = c AND info.score = 'whatever'

Hibernate, Maps and HQL


Outlook 2007 - Mailbox doesn't show my Items (like Calendar)

Question: I have running an Exchange Server 2003 and 2 IBM Laptops (A&B)with XP SP3. On both Laptops Office 2007 is installed. Laptop "A" Outlook doesn't show me my Calendar and Notes entries in my mailbox tree on Laptop "A". I can click on the calenendar tab and the entries are there.
On Laptop "B" it is working fine.
I know that I can make a "rigth click" on "mailbox" and choose "create new folder". Than I select i.g. my calendar. It creates it, but I can't access it through my mailbox tree. Clicking on the Calendar tab works fine again.
So, the mailbox is fine (I think). There must be failure with Outlook. I tried these commands here with no positive result.
<code>Outlook /cleanviews
Outlook /resetfolders
</code>
I want to avoid a repair installation of Outlook, because the whole office needs to be repaired. (And both laptops belong to my boss).
Answer: Answer to original question:
Outlook 2003 and above do not show the calendar as being part of the mailbox tree in the mail / inbox pane. This is purely a difference in presentation of the data. The calendar pane is the calendar belonging to that mailbox. The calendar folder you created is a separate folder and is analogous to any other user-created folder in the mailbox. This sounds like a user who has switched from 2000 to 2007, and just needs to know that the calendar now appears in a different place in the interface. If the user wants everything in the same pane under the same tree, then have the user use the folders pane instead of the mail pane by default.
Response to the followup question:
From the asker:

"Thanks for your information, but I
  made a mistake here. The real problem
  is that Outlook doesn't show up all
  items from pst files. It contains more
  items than shown in the tree. Do yo
  have an idea?"

It sounds like the user has two machines, and both are configured to auto-archive messages (and once again, I am just guessing at a likely scenario that would result in the situation above).  As such, the archive PST file on laptop A will only contain items that were archived by that copy of Outlook, while the archive PST file on laptop B will only contain items archived by that copy of Outlook.  Therefore, if you are browsing the archived mail on laptop A, you will not see any folders that originated on the server where everything archived to date from that particular folder have been archived by laptop B (and vice versa).
As such, it is usually best to only auto-archive using the user's primary laptop.  An alternative would be to set up both laptops to archive mail to a network share that is accessible by both laptops (with appropriate permissions, of course).  If you do this, though, you'll simply be offloading the storage requirement from the Exchange server to some other server, so the network storage benefit of archiving old items will be minimal.  Once you have changed the destination archive location, you would need to export everything from laptop A's archive file to the new networked archive file, and then you would export everything from laptop B's archive file to the same archive file as laptop A.  Be very sure, though, that you choose the option to not export duplicates, just in case archive A and archive B do in fact have some items in common.
If I am still guessing incorrectly, then please post additional information about the particular configuration.  The more information you provide in your question, the more likely that someone will be able to answer your question.
Comment: Thanks for your information, but I made a mistake here. The real problem is that Outlook doesn't show up all items from pst files. It contains more items than shown in the tree. Do yo have an idea?
Comment: I updated my answer with another scenario that may answer the new question.


Tessellation and circle homeomorphism.

Question: If $f$ is an orientation preserving homeomorphism from $S^1$ to $S^1$ and $\tau$ is a tessellation of $\mathbb{D}$ (that is a collection of locally finite geodesics decomposing $\mathbb{D}$ into ideal triangles) then $f(\tau)$ is also a triangulation.
(Locally finite: Any point of $\mathbb{D}$ admits a neighborhood meeting only finitely many geodesics in $\tau$. )
I have read this statement many times but haven't seen any proof of it. Can anyone please give a complete proof of this. In particular I want to know why the image will be locally finite.
Answer: Given a geodesic $\gamma$, let $r(\gamma)$ be the Euclidean distance from the center of the disk to $\gamma$.
Claim 1. A collection $\Gamma$ of geodesics is locally finite if and only if for every $\epsilon>0$ the set $\{\gamma\in\Gamma: r(\gamma)\le 1-\epsilon\} $ is finite.
Proof: If $\Gamma$ is locally finite, then only finitely many geodesics meet the closed Euclidean disk $\{z:|z|\le 1-\epsilon\}$,  by compactness of the latter. In the converse direction, every point of $ \mathbb D$ has a neighborhood contained in some set of the form $\{z:|z|\le 1-\epsilon\}$. $\Box$
Let $d (\gamma)$ be the Euclidean distance between the endpoints of $\gamma$.
Claim 2. There is a continuous strictly decreasing function $\phi:[0,1)\to (0,2]$ such that $d(\gamma)=\phi(r(\gamma))$ for every geodesic. Also, $\phi(1-)=0$.
Proof: either of two quantities $d$ and $r$ determines the geodesic up to Euclidean rotation, and therefore determines the other quantity. A rough upper bound for $\phi$ is $\phi(r)\le 2\sqrt{1-r^2} $, which suffices for $\phi(1-)=0$. This bound follows from the fact that a Euclidean line passing at distance $r$ from the origin cuts off a part of the disk with Euclidean diameter $2\sqrt{1-r^2}$. $\Box$
The function $\phi$  could be written down explicitly,  but this is not necessary.
The image of a geodesic $\gamma$ under a map $f:S^1\to S^1$ is understood as the geodesic between the images of the endpoints of $\gamma$.
Claim 3. if $\tau$ is a locally finite collection of geodesics, and $f:S^1\to S^1$ is continuous, then $f(\tau)$ is locally finite.
Proof: Given $\epsilon>0$, we must show that $\{  \gamma  \in\tau : r(f(\gamma))\le  1-\epsilon\}$ is finite.  By the uniform continuity of $f$, there is $\delta>0$ such that $d(f(\gamma))<\phi(1-\epsilon)$ whenever $d(\gamma)<\delta$. Since $\phi(1-)=0$,  there is $\tau>0$ such that $d(\gamma)<\delta$ whenever $r(\gamma)>1-\tau$.
The chain of containments
$$\begin{split}\{  \gamma  \in\tau : r(f(\gamma))\le  1-\epsilon\} &=
\{  \gamma  \in\tau : d(f(\gamma)) \ge  \phi(1-\epsilon)\}  \\
&\subseteq \{  \gamma  \in\tau : d( \gamma ) \ge  \delta\} \\
 &\subseteq \{  \gamma  \in\tau : r( \gamma ) \le  1-\tau\}
\end{split}$$
proves the claim. $\Box$
This takes care of local finiteness. Another thing to check is that $f(\tau)$ is a tesselation when $\tau$ is a tesselation and $f$ is a homeomorphism. First, the endpoints of geodesics in $f(\tau)$ are dense in $S^1$, because the image of a dense set is dense. Second, the geodesics in $f(\tau)$ do not intersect. Indeed,  two geodesics $\gamma_1,\gamma_2$ intersect if and only if the endpoints of $\gamma_1$ separate the endpoints of $\gamma_2$ in $S^1$ (in other words, removing the endpoints of one geodesic leaves the endpoints of the other in different connected components). This property is also invariant under homeomorphisms.

Tessellation and circle homeomorphism.


AngularJS isolate scope: & vs =

Question: I'm trying to learn AngularJS, but there's one thing I can't wrap my head around.
What is the benefit of using "&" over "="? All the tutorials, demonstrations and documentation I've found tell me that & evaluates the expression in the parent scope. However, when I first tried doing callbacks to my controller from my directive, I just used a = binding to a function on the parent scope, and it worked fine.
For example, with a function on the controller's scope foo that takes a parameter bar, I could do a directive declaration like
scope: { callback: '=' },
template: '

'

and include the directive like
<my-directive callback="foo"></my-directive>

To achieve the same with &, it seems like I have to do
scope: { callback: '&' },
template: '

'

and
<my-directive callback="foo(bar)"></my-directive>

From this, I don't really see the advantage. Have I misunderstood &?
EDIT: I suppose a valid addition to my question is: Is it a bad idea to bind to parent scope functions using = instead of &?
Comment: Is the capability to execute an expression against the parent's context a benefit for you? see my answer below.
Comment: added update, with an example of a beneficial scenario.
Answer: The difference it seems is that with the & binding, the user of the directive fixes what function is called on a parent scope and which parameters are used, while an = binding simply means passing a reference function reference which the directive can call with whatever arguments.
= isn't meant for that though, it exists mainly for synchronizing properties between nested scopes, while & is meant give the directive a way to interact with the 'outside' world without having knowledge about the outside world.
example of both

    <bind-dir func-is="parentCtrl.func" func-and="parentCtrl.func(arg)"></bind-dir>

var app = angular.module('app', []);

app.controller('ParentCtrl', function () {
    this.func = function (arg) {
        alert(arg);
    }
})

app.directive('bindDir', function () {
    return {
        scope: {
            funcIs: '=',
            funcAnd: '&'
        },
        template: '<button ng-click="funcIs(\'=\')">=</button><button ng-click="funcAnd({arg:\'&\'})">&</button>'
    }
});

Comment: Thank you, with the added example this makes it much clearer.
Answer: Official docs.

@ or @attr - bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings.
= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute.
& or &attr - provides a way to execute an expression in the context of the parent scope.

Further reading: Understanding-Scopes.
Answer: '=' gives two way data binding. This means that if you alter the value of the expression within the directive it also alters in the controller. This is called polluting the controller.
'&' is nicer and more modular. You can pass in the function and it will be executed in the scope of the controller but you are unable to change the function in the controller scope.
Please see http://jsfiddle.net/b6ww0rx8/ and it will be a bit clearer.

        <button ng-click="test()">click me</button>

angular.module('myApp', [])

.controller('MyController', function($scope) {

    $scope.aFunction = function() {
        console.log('abc');
    };
    $scope.anotherFunction = function() {
        console.log('def');
    };
    $scope.test = function () {
        console.log($scope.aFunction);
        console.log($scope.anotherFunction);

    };
    console.log($scope.aFunction);
    console.log($scope.anotherFunction);
})

.directive('myDirective', function(){
    return {
        scope: {
            callback1: '=',
            callback2: '&'
        },
        link: function (scope, element, attrs) {
            scope.callback1 = 123;
            scope.callback1 = 456;
        }
    }
});

Answer: Is the capability to execute an expression against the parent's context a benefit for you? The first example below executes myLocalModel as a function, unlike the '=', you get the result already.
template: "{{ myLocalModel() }}"

begin added update 01
example, you might have 2 attributes with expression, and you only want to execute either one depending on a condition. that could save execution time. is it beneficial for you?
end update 01
the '&'
, Execute expression against a parent's context.
http://ngtutorial.com/learn/directive.html#/exec-expr
angular.module("myApp", []).directive("myCustom", function(){
  return {
    restrict: 'EA',
    scope: {
        myLocalModel: '&theElementsAttrName',
    },
    // note that myLocalModel is a function
    template: "{{ myLocalModel() }}"
  };
});
........

        my-custom 1) <my-custom the-elements-attr-name="ParentModel + ' ---> adding more'"></my-custom>

        my-custom 2) <my-custom the-elements-attr-name="ParentNum1 + 12"></my-custom>

    my-custom 3) <my-custom the-elements-attr-name="ParentNum2 + 12"></my-custom>

.... output

my-custom 1) the parents value ---> adding more
my-custom 2) 112
my-custom 3) 212

the '='
,Sync with existing model.
http://ngtutorial.com/learn/directive.html#/sync-existing
angular.module("myApp", []).directive("myCustom", function(){
  return {
    restrict: 'EA',
    scope: {
        myLocalModel: '=theElementsAttrName',
    },
    template: "{{ myLocalModel }}"
  };
});

.....

        my-custom 1) <my-custom the-elements-attr-name="ParentModel"></my-custom>

        my-custom 2) <my-custom the-elements-attr-name="ParentNum1"></my-custom>

    my-custom 3) <my-custom the-elements-attr-name="ParentNum2"></my-custom>

..... output

my-custom 1) the parents value
my-custom 2) 100
my-custom 3) 200

AngularJS isolate scope: & vs =


Is there a rational method to find out which minor scale sounds best in a given situation?

Question: By rational I mean a method that doesn't entirely depend on one's subjective aesthetics, but rather one that has some kind of system behind it.
The obvious rule that you should use the ascending melodic scale when ascending and the natural melodic scale when descending I have found far too simplistic for actual use, especially in a more polyphonic setting. For one thing, Bach often uses the ascending scale in descending as well, which gives his harmony a distinctly Dorian feel (which I happen to like).
Sometimes the augmented 2nd in the harmonic scale sounds pretty good; other times it sounds absolutely terrible. Sometimes the scale to use changes by the beat; other times the resulting false relations sound nauseatingly ugly.
I would like to have some tools to reason why one or the other is the case.
Answer: There are tendencies in many classical pieces on use of the mutable scale steps (6 and 7). These ideas seem to apply to bass more than to melodic voices.
When the harmony is predominately dominant, the raised version of 6 and 7 are preferred.
When the harmony is predominately subdominant, the lowered versions of  6 and 7 are preferred.
When the harmony is predominately tonic, the raised versions are used in ascending passages and the lowered version in descending passages.
The only other tendency seems to be that the raised 6 is never used as the upper neighbor to scale step 5. The raised 6 and lower 7 are not used together as this may seem to be a modulation to the major key based on the lower 7 or 3 st. This is the V of III which is a common pattern in minor.
Classical theory generally considers the minor mode as a single entity rather than having 3 (or more) scales. Scale passages are common but scales are not fundamental; patterns of chord and scale usage are the primary stuff of classical theory. The harmonic minor is (classically) an artificial structure as the minor iv and major V chords are common. Melodies using a lower 6th and raised 7th (the harmonic minor notes in order) are common in instrumental music, not so much in vocal melodies as it's supposedly to hard to sing the augmented second. On the other hand, arpeggiated dominant minor ninth chords are rather common.
The classical composers seemed to like the sound of the above techniques. They are only tendencies. The ascending and descending versions of all three minor scale patterns are common even in a single piece. Sometimes these are used simultaneously ignoring any fasle relations (or even emphasizing such relations.)
Personally, I'd suggest just using one's ear. I do tend to be a bit strict with scale patterns in the bass while playing whatever seems good at the moment in the melody.
Answer: Pat Martino's "Minor Concept" is an improvisation/composition approach that is essentially based on finding the right minor scale or mode for different harmonic situations -- which is quite similar to what your asking.
I think you'll find this subject explained in a video called "Pat Martino Creative Force 1" which should not be hard to find online.
Comment: I love Pat and love those books.
Answer: When lines are moving at a harmonic level direction does seem to be the key factor. Lowered ^6 descending to ^5 and raised ^7 ascending to ^1. Those two lines can be extended back to the longer lines ^1 ♭^7 ♭^6 ^5 descending and ^5 ♮^6 ♮^7 ^1 ascending.
Movement using rhythmic subdivision of the harmony (diminution) will use the form of ^6 or ^7 that match the harmony regardless of direction.

...from an aria in the Bach, Anna Magdalena notebook, in the final three bars, two scalar lines descend in the treble, the first time the harmony is dominant and so the descending line uses raised ^6 & ^7, the line is sequenced, but the second iteration is subdominant harmony so the lowered ^6 & ^7 are used. Notice the cross relationship of D, it's natural in the descent of the scale to the dominant, but the harmony is not yet dominant, then it's raised when the harmony has become tonic/dominant and D# ascends to the tonic. The bass when moving to the final cadence uses the lowered ^6 as an auxilliary to the dominant degree, but the chord is a subdominant ii.
When viewing the harmonic level movement in that piece it's important to note the difference in treatment when the dominant is part of a half cadence versus the dominant moving to the tonic. Notice at the fermata the descending line in the treble, the chord is dominant, but the leading tone (D#) does not ascend to the tonic, because it's a half cadence, it's ending on the domimant. In harmonic terms there isn't a leading tone ascent and so the line is "free" to move in any direction. In the next bar the D# is part of a dominant chord moving in a deceptive progression and it ascends to the tonic. It ascends here, not because ascending lines in minor use raised tones, but because the essential harmonic movement of the progression is the leading tone to tonic.

...from the Bach's Two-Part Inventions, in the bass there is a descending line which is sequenced, on the first descent the harmony is not dominant and the lowered ^6 & ^7 are used, in the second iteration the harmony is dominant and the raised ^6 & ^7 are used - despite the line descending. The essential harmonic tones of the dominant chord are pointed out with blue arrows, the descending line uses the raised ^7 to match the dominant harmony, but it moves freely downward, because it is just decorative motion, diminution of the chord.
The is also an interesting occurrence of the augmented second in the third bar. That interval is supposedly avoided or filled in, but it seems to me there isn't a problem using it when the line is a decoration of a dominant chord, especially descending.
The end of bar 2 and all of bar 3 are an elaboration of the dominant chord. Within that dominant harmony there is lots of "freedom" or direction for the lines. When the movement is finally happening at a harmonic level, the lines follow the more obligatory directions: bar 3 to 4 treble Bb C Bb Ab descending through dominant to mediant, bars 3 to 4 the bass E♮ up to F ascending to the tonic.

...from Bach's BWV 851, there is a nice example of a cross relationship with degree ^6. The middle of bar 13 moves through a dominant in a deceptive progression. The harmonic rhythm is fast so each tone moving to and from ^6 is real harmonic motion and all the expected directional tendencies are fulfilled. ^6 is natural as it ascends to a dominant harmony which in turn ascends to the tonic for form the deceptive progression. At the same time the bass from from the dominant to the ^6 degree, and because the ^6 at that point in the bass is not moving to a dominant or leading tone - but rather away - it is not raised. A beat later, in the treble, the ^6 appears again but as part of a subdominant harmony, it is not raised but is part of an auxilliary motion around ^5.
Notice the difference in treatment of raised ^6 & ^7 in the ascent here B♮ C♯ D where each tone is part of harmonic movements dominant to tonic, versus the example in the two-part invention where the movement is decorative within a single dominant chord and the line freely ascends and descends.
This the systematic treatment of ^6 & ^7 in minor. The treatment is strongly directional when occurring at the harmonic level, but ascends/descends freely on the decorative/diminution level.
Comment: Thank you, Michael, for this extended and excellent explanation! I already thought it was right up your alley.


What is the default behavior for performDefaultHandlingForAuthenticationChallenge:?

Question: The documentation for this just says: "Causes the system-provided default behavior to be used."
What is the system default behavior?
I presume the system will check the server's certificate, is that correct?
Answer: Yes, if the challenge is for server certificate validation (<code>[challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]</code>), the system will do the default/safe SSL certificate validation.
Comment: What is the default policy(SSL or BasicX509)?


How do I increase the length of a text-field with saved values?

Question: I have a multi-value text-field, projects. Its length is 4, and I would like to increase it to 255, but there are values saved in the database for that field.
How can I increase its length?
Comment: backup, export field's db table, delete field, clear the cache, create same field with 255, import, clear the cache.
Comment: In my case, to import the previously backed-up content into the newly created table (when you create the same field again with the new character length), I had to open up the exported sql and only select the INSERT INTO part with all its values and paste that into the SQL query box in phpMyAdmin. Because simply importing that previously exported table using the Import function/tab gave an error saying that it could not create the table again, logically.
Answer: I got an answer from my friend as well. I would like to share his code here:
/**
 * Update field.
 */
function MODULE_update_8301() {
  $db = \Drupal::database();
  $field_name = 'field_MY_TEXT_FIELD';
  $table_prefixes = [
    'node',
    'node_revision'
  ];
  foreach ($table_prefixes as $table_prefix) {
    $db->schema()->changeField(
      "{$table_prefix}__{$field_name}",
      "{$field_name}_value",
      "{$field_name}_value",
      [
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
      ]
    );
  }

  $config = \Drupal::configFactory()->getEditable('field.storage.node.' . $field_name);
  $settings = $config->get('settings');
  $settings['max_length'] = 255;
  $config->set('settings', $settings);
  $config->save();
}

Comment: I strongly against this solution. You shouldn't manipulate the fields by yourself. Do this via Drupal API.
Answer: The schema of a field is not changeable until it has data inside.
There can be many scenarios like you have multiple languages, or revisions are important etc, but the following steps can be an abstract approach of the situation:

Keep in memory (variable) or save all the field values, which host field you are about to manipulate
Delete your old field and import the new one (you can do it based on the YML file itself)
Backup all the information with help of the EntityTypeManager.

This is indeed an advanced part of Drupal, but once you master it, updates like this will work like charm.
Answer: I tried the answer of asrob, but it doesnt work with entity update (drush entup).
There is a better solution using Drupal API.
The code is from here: https://coderwall.com/p/uyidlq/updating-the-storage-definition-of-entities-that-already-have-content-in-drupal-8
/**
 * Increase FIELD size to 50.
 */
function MODULE_update_8XXX() {
  $database = \Drupal::database();
  // Retrieve existing field data.
  $entity_type = 'ENTITY_TYPE';
  $field = 'FIELD_NAME';
  $tables = [
    "{$entity_type}__$field",
    "{$entity_type}_revision__$field",
  ];
  $existing_data = [];
  foreach ($tables as $table) {
    // Get the old data.
    $existing_data[$table] = $database->select($table)
      ->fields($table)
      ->execute()
      ->fetchAll(PDO::FETCH_ASSOC);

    // Wipe it.
    $database->truncate($table)->execute();
  }

  $field_storage_configs = \Drupal::entityTypeManager()
    ->getStorage('field_storage_config')
    ->loadByProperties([
      'field_name' => $field,
    ]);
  foreach ($field_storage_configs as $field_storage) {
    $new_field_storage = $field_storage->toArray();
    $new_field_storage['settings']['max_length'] = 50;

    $new_field_storage = FieldStorageConfig::create($new_field_storage);
    $new_field_storage->original = $new_field_storage;
    $new_field_storage->enforceIsNew(FALSE);

    $new_field_storage->save();
  }

  // Restore the data.
  foreach ($tables as $table) {
    $insert_query = $database
      ->insert($table)
      ->fields(array_keys(end($existing_data[$table])));
    foreach ($existing_data[$table] as $row) {
      $insert_query->values(array_values($row));
    }
    $insert_query->execute();
  }
}

Answer: This is what I do. I would only use it to increase the length of a string. I have not tested, but assume that shortening a string will truncate data.
First, backup the database.
Then, edit the structure of the following tables (change yourfield to match the name of your field):
field_data_field_yourfield
field_revision_field_yourfield

Change the length of the field_data_field_yourfield_value field (VARCHAR) in both tables to the value you want. This allows the fields to hold more characters. But doesn't tell Drupal about the change in length.
Next, locate this table:
field_config

Find your field in the list and edit the data value. Look for a section like this:
s:10:"max_length";s:3:"100";

The length of the field in this example is 100. Change it to match the change you made earlier. If the number of characters changes (e.g. you increase it from 100 to 1000), change the s:3 value to reflect the new character count.
Flush all caches.
Edit the field on an entity type to which it is attached to verify that its length has changed.
Edit an entity with this field and verify that you are able to enter a value that is the new length.
That's all ....
Answer: Up-to-date method for Drupal 8 (for field name "field_myfield"):

Backup database
Edit structure for table node__field_myfield, set new length for column field_myfield_value.
Edit structure for table node_revision__field_myfield, set new length for column field_myfield_value.
Use Admin Toolbar Extra Tools module, top menu: go to Development > Config editor
Filter by "field.storage.node.field_myfield"
Edit the max_length: line under settings: to match new column length.
Flush all caches.
Enable the entity_update module.
drush @miniloco upe --show
Give up....

Will keep trying and will come and edit this if/when I find a solution.


Comparing two columns and highlighting if the specified value is not available

Question: I have two columns A and B, If A Column have the specific value "High" then the corresponding cell in B Column should contain the Date (dd/mm/yyyy)value otherwise if date value is not available the cell should be highlighted as Red. I am new to this macro and I am not able to find the logic for this.
Comment: Use [Conditional Formatting](https://support.office.com/en-us/article/use-formulas-with-conditional-formatting-fed60dfa-1d3f-4e13-9ecb-f1951ff89d7f) there is no need for VBA here.
Comment: can this be done using vba
Comment: Yes, but it makes no sense to re-invent the wheel if there is a buit-in tool for this in Excel. If you need to do this with VBA do some research try something on your own and come back with your code. Otherwise it is just asking us to do all the work for you. Reading [ask] might help you to improve your question.
Answer: Sorry this isn't a comment, but I don't have sufficient rep.
I'm a little unclear how dates are populated in column B. Is this something we can take as given or are you assigning dates somehow? It might help if you could share a bit more about the structure of the sheet, maybe some "dummy data"?
That said, this sounds like a straightforward case of loops + conditional statements. I doubt this will work for you out of the box, but you could try nested For loops over columns A and B à la:
<code>For Each cell in Range("A:A")
  If cell.Value = "High" Then
      If IsEmpty(Range("B"&cell.Row)) Then       'IsEmpty tests whether the cell is empty, you may need to change this if the cell has some other value in it
        Range("B"&cell.Row).Interior.Color = 255 '255 corresponds to the color red
      End If
  End If
Next cell
</code>
I agree with Pᴇʜ though, you don't actually need VBA for this at all. You can apply conditional formatting using a formula for the rule and then use a formula like this for the cells in column B:
<code>=IF(A2="High",IF(ISBLANK(B2),TRUE,FALSE),FALSE)
</code>
Then just make sure you apply the formula to all the rows you care about.


How is drupal able to see a module even when I renamed it

Question: I ran down into a serious issue with mediabox module. After spending some time I realized its because the update has broken some functionality. I just wanted to revert back to older version. I did it by copying my local folder which is older version to the production. However it looks like drupal is still taking the older version. This I confirmed by observing the html code which is different for two versions.
I cleared cache, restarted apache. But it still somehow is getting it from the bugged code. I even removed the folder. But surprisingly it is still reading it from somewhere. I made sure I removed the cache and rebooted apache. I did this in my local machine which actually broken my site which was expected but I am wondering why its still not throwing any error even after I renamed the folder name
Answer: Drupal stores information about where to find module files in the system and registry tables.  If you want to revert an update, you'll have to replace the updated version with the old version. If you ran database updates to update the module, you'll have to disable and uninstall it first, and then re-enable it after you've replaced the module files.
If you've removed the module without disabling it, the site should break. If it's still running with the updated module, there must be another copy of it somewhere.
If you want to know where drupal's reading the files from you can run the following SQL on the db:
<code>SELECT filename FROM system WHERE name = 'mediabox';
</code>


Best way to show another site's page via Drupal?

Question: I have a somewhat odd request and, while I hate asking vague questions, I just don't know where to start with this one.
I am developing a website (Drupal 6) for a user that also has a seperate website with some very particular server side apps that allow their staff to do data entry.
The request is that they would like to show a certain data entry form from within the new site. The data entry form can span several pages but once done shows a very definitive End of Form marker. I am thinking that to simply show the form can be done using iFrames, perhaps. But this requested level of integration of having the current site recognize the end of form marker puzzles me.
Any advice on how to:

Show the data entry form from the other site.
Have Drupal recognize the "End of Form" marker (just some text that says Done, basically) would be very much appreciated.

Googling things like "Drupal show another page" and such doesn't yield much.
Comment: Things that might help this question get better answers:
explain what the "End of Form maker" is, and why it's problematic with an iFrame.  Can you modify the existing form to redirect back to a Drupal after form is submitted?  Can you re-produce the other form using Drupal Webform or a Content Type?  Is it better to simply link to the old form?
Comment: Have you thought about putting a button (like a 'Continue') at the end of the form within the iframe that will redirect the user? I no that this won't programically let Drupal know that the user has finished but it might be a quick fix until you do.
Comment: @JohnathanElmore "End of Form Marker" is just as I said previously, some text on the page that just says "Done". Problematic with iFrame because javascript can't access it due to "same origin" policy (Google it if you've never heard of before). I cannot modify that form to redirect at all. I have no access to it and modifying it is not an option. Recreating their existing form and backend in the Drupal environment is not an option either. Simply linking to the old form isn't really what is wanted. Request is for a more seamless user experience.
Comment: If I were in your shoes, I would modify my settings.php to have [multiple-databases](http://drupal.org/node/18429), and write a small custom module that creates a similar multi-step form, and has a submit handler that writes the form results to the other database (of the old website). That way you don't really have to worry about javascript limitations across domains. Of course this depends on how complex the form is, and if it can be implemented using [Form API](http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/6)
Answer: You should be able to use this.  Enable PHP code mode and paste it into a page:
<code><?php
  $curl_handle = curl_init();
  curl_setopt($curl_handle,CURLOPT_URL,"http://www.google.com");
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  $html = curl_exec($curl_handle);
  curl_close($curl_handle);
  print $html;
?>
</code>
Comment: That will indeed work but only for the most simple cases. I am trying to interface with, as I said, a nontrivial data entry application.
Comment: Well let us know how we can help ;)  It's working well for me.
Comment: The main problem with a curl wrapper is that in this case the external app has a decent amount of JavaScript and curl, of course, acts like a simple browser without JS Enabled and there isn't any way around that that I know of. The external app detects the lack of JS and just returns a typical "You need JS enabled" error message. The module Wrapper I linked to in another post does handle js/css/etc pretty well though. Thanks for trying to help though! :)
Answer: This is a complex problem that doesn't have any one good solution.
The best I have found is a module which is still under development called Wrapper.
http://drupal.org/sandbox/dman/1140564
I recommend anyone with this problem start off with that module as it may do exactly what you want.


Is there a goodness of fit metric that can be computed online with $O(1)$ memory?

Question: Say I have two random streams of two dimensional data. I want to measure how closely their underlying PDF's match. My current method is to estimate the PDF's by accumulating the samples online in a 256x256 histogram. After this, I measure the deviation between the two. I am using sum of absolute differences here, but I believe other metrics will work fine as well.
Some other possibly relevant details: I will be ranking the streams based on their goodness of fit; I don't actually need to perform any hypothesis testing— just find which has highest rank. Also, the distributions are complex, and I don't believe they can be estimated to sufficient accuracy by any well-known analytic distributions.
The problem is, the memory accesses on $t*2^{16}$ bins with $t$ threads, is a significant bottleneck. I was wondering if there were a way to compute the goodness of fit metric without having to accumulate $O(k)$ data about the distributions. Maybe something similar to how there are online calculations of mean/variance that just accumulate one or two variables along the way.
I have looked at Komogorov-Smirnov, Cramer-von Mises, and Shapiro-Wilk tests. They appear to require either 1) an estimation of the sample's CDF, which would still need $O(k)$ variables or 2) ordered data, which isn't possible with an unordered, random stream of data.
Maybe there's some fundamental limitation that prevents a computation comparing PDF's with just $O(1)$ variables?
Comment: 1. If your pmf is really discrete why do you need to accumulate a histogram on the first pass? Its not clear what you're doing there. The KS statistic is based on a difference in cdf, so the question is whether there's a fast update on that. If the pmf is only on a few atoms of probability it may be pretty fast to update. 2. Given a discrete pmf, the C-vM won't require sorting the observations; it should be possible to calculate it from the same cdf you'd update in a K-S, so again the question is whether the cdf is fast to update.
Comment: Maybe I'm misunderstanding the test, but seems you need to first compute the empirical distribution function of the samples. For discrete data, you can calculate that efficiently from a histogram.
Comment: 3. If you're just computing a measure of fit with the S-W (not testing), you don't need to assume normality -- if you have some location-scale family you replace the calculation of expected order statistics. However, I am curious how you're doing it online (since a typical implementation would require something equivalent to sorting the data; however this could be gotten around with a discrete distribution). A chi-square statistic should be very fast to update but would be less sensitive than some other options.
Comment: You just said in your post that a histogram was too inefficient; it can't be both efficient and inefficient. If it is actually efficient, do it. If it is not, stop insisting on doing it that way and instead try to consider if there's a faster way to do it online. It looks to me like the crucial issue is how many values your discrete r.v. can take. If it's say 5 or 6 different values, no problem. If it's thousands, it will be slow to update an unnormalized cdf online.
Comment: Note that if you intend testing any of this you have multiple issues to contend with (such as the impact of the discrete distribution on statistics designed for continuous variables, the sequential testing)
Comment: I meant if you have a histogram already you can calculate its cdf efficiently. The problem would be building the histogram in the first place. I'm assuming updating a cdf or chi-square statistic would be about the same, since you're still accumulating the samples into $O(n)$ bins.
Comment: No, it's not O(n) bins. conventionally n is the number of observations, but you'll need a different symbol (say $k$) to represent the number of possible values taken by the discrete variable, and it's easy to update the counts. You'd still need an O(k) update in general (though in some special cases there's a few tricks that might speed things up; a uniform distribution might be faster than O(k) for example). If k is small, several of these statistics should be fast.
Comment: The purpose is just to rank the measure of fit for many candidate distributions; don't need to do hypothesis testing since I'm just interested in highest rank. You're right with SW, it does need ordered-- I misread that, haven't implemented anything yet. I'm estimating the candidate PDF's with PMF's, at least for now, but if there is a 2-sample test that is fast I will switch to that.
Comment: Wait, you're actually interested in comparing two samples? why are we solving the wrong problem?
Comment: Yeah, problem with stackexchange is they want a "minimal working example" so to speak, else the question gets too complex and nobody answers. So it is hard to pick which details to exclude. I figured if you can do it with a single sample, I can figure out how the 2 sample works myself
Comment: I know it is easy to update $k$ bins online, and normally it would be pretty fast too. For me the distributions are 2d (another detail I figure should be straightforward to generalize from 1d case), meaning 256*256 bins; then imagine 16+ cores contending for RAM access to accumulate histograms... it becomes a bottleneck. GPU texture memory might be a little faster, but I don't expect by much. So mostly wondering if there were some computation, like you would with online mean/variance calculation, where you could compute goodness of fit without accumulating $O(k)$ bins. Make any more sense?
Comment: If you have $k=2^{16}$ positions in the pmf that's worth mentioning in the post. What distributions are you looking at?
Comment: Updated the question with the answers to your comment inquiries. The distributions are complicated, which is why I was estimating as discrete PMF's.
Comment: How are you getting the discrete pmfs?
Comment: I'm discretizing the PDF as a histogram. Wouldn't that be equivalent to discrete PMF? You seem to have a good skill for poking holes in my understanding of statistics.
Comment: It is, but I was trying to get into what exactly that saved you. However, considering that the underlying problem is 2D you may want to avoid the issues with trying to get an order on observations in 2D anyway, so the chi-square may well be reasonably sensible and you'd be binning in any case. It sounds like the alternatives will tend to be smooth deviations though so there might perhaps be some power gain in looking at partitioning the chi-square and pulling off lower order components along the line of a Smooth test; that would complicate the updates though; I don't know how much.
Answer: Consider updating a chi-squared statistic.
$X^2 = \sum_{i=1}^k \frac{(O_i-np_i)^2}{np_i}$
First let us simplify:
$= \sum_{i=1}^k \frac{O_i^2-2np_iO_i+(np_i)^2}{np_i}$
$= \sum_{i=1}^k \frac{O_i^2}{np_i}-2\sum_{i=1}^k O_i+n\sum_{i=1}^k p_i$
$= \sum_{i=1}^k \frac{O_i^2}{np_i}\,-n$
$= [\frac{1}{n}\sum_{i=1}^k \frac{O_i^2}{p_i}]\,-n$
$= S/n - n$
If we can update $S=\sum_{i=1}^k \frac{O_i^2}{p_i}$ quickly it looks like there's a fast algorithm.
So now let us focus on updating $ S$
Note that $O_i$ is just the count in the $i$th bin. When you add a new observation to bin $i$, you add $(2O_i+1)/p_i$ to the sum - all the contributions from other bins are unchanged, and then you can recompute $S/n-n$ at the new value of $n$, this is $O(1)$ in both $n$ and $k$.
Stability
This may potentially be an issue; as $n$ grows you're subtracting two relatively equal quantities (the expected value of the first term $S/n$ should be about $n+k$(*) if the null is true but will tend to be larger otherwise). As $n$ grows very large relative to $k$ this may become an issue; specifically, computing something akin to $(1+k/n) - 1$ may be inaccurate if $k/n$ is very small.
At the same time if $n$ is really large, $S$ may be large relative to the increment in $S$. Ideally we avoid both issues by adjusting the S-calculation.
I believe the same sort of idea used in online variance update calculations could be adapted to this computation in that case, it would slightly complicate the update of $S$ - in a way that it's already reduced by $n^2$ (or something close to it).
Actually I think we just add something like $(2O_i+1)/p_i - 2n-1$ to $S$ instead and don't subtract $n$ at the final step (or it may be $-2n+1$ depending on when we update $n$).
(However if $n$ is only a few million it's probably not worth it; if you have several figures of accuracy on your statistic - and you should have plenty to spare - it will probably be sufficient to your purposes. If $n$ is many billions, you should do it but you will want to consider efficiency of the update pretty carefully then)
* actually, n+k-1 but that matters not in the least to the issue.
Comment: So maybe this is my fault for not clarifying precisely, and I apologize. I meant an online algorithm in that it reads the data one-by-one in a single pass. I don't actually need to compute the final metric on each iteration. In my original attempt, I'd accumulate $O(k)$ bins in a single pass, then compute the metric. The binning being the bottleneck, I was wondering if you could do it with just $O(1)$ memory total, over all iterations.
Comment: My line of thinking was something like: Assume $p_i$ is already known (accumulated before for one of the data streams). For each observation you see increment your metric by $p_i/n$, where $p_i$ is the observation's corresponding bin. That gives you $\sum p_io_i$, where $o_i$ is probability from 2nd data stream's bin... so maybe you could compare this to $\sum p_i^2$?
Comment: If your $p_i$ are themselves estimates of true p's based on data, the entire question is incorrectly specified and you should write a new one that explains that you want to compare proportions across data streams (or whatever it is you want). But if you have $p$s prespecified (as the question here suggests) then I don't see what you're getting at with this at all. In any case I don't see what you mean by "increment your metric" (what metric?) nor "where $p_i$ is the observations corresponding bin" (no, $p$ is a probability, $i$ is the bin, $n$ is the index of the current observation).
Comment: If you're trying to do it without storing either the $p_i$s or the $O_i$s that's going to be tricky. If you do store $p$, storing $O$ doesn't change the big-$\mathcal{O}$ factor on storage space, just the multiplier out the front. Anyway, I am presently confused (and I presumably missed something important), but maybe you can clarify.
Comment: I was coming from the angle, "if its impossible to compute in $O(1)$ when one of the distributions is known (e.g. $p_i$ known apriori), then its probably impossible when both are unknown." So it was just an intuition pump that got me thinking it might actually be possible. To clarify you've got $o_i$=1st distribution's histogram probabilities, $p_i$=2nd distribution's histogram probabilities (assume you estimated it already— actually unknown in real problem). Then if you make $N$ observations, you can compute $S=\sum_{n}^{N}p_i/N$, where $i$ is sample $n$'s bin. Giving you $S=\sum_i p_io_i$.
Comment: The formula doesn't actually work, which is why its just a thought. It would be an underestimate, since it only gives you the middle term in $(p_i-o_i)^2 = p_i^2-2p_io_i+o_i^2$. Would need to figure out how to calculate $o_i^2$ online in $O(1)$ for it to work. Then again, its all assuming $p_i$ is known, so not practical anyways.
Comment: Again, if this is "compare two sample distributions", you need a new question. Again, I don't quite follow what you're trying to achieve here, though defining that o was probabilities helps. Note that my O's are *counts* and if you wanted to compare two distributions it would be two sets of counts you'd work with.
Comment: Okay, I will try to write a new question then


Can a subspace be written as the direct sum of its intersections with subspaces generated by partitions of a basis?

Question: Say $V$ is a vector space with some basis $\mathcal{B}=\{b_i\}_{i\in I}$, and let $\{B_1,\dots,B_n\}$ be a partition of $\mathcal{B}$. In general, for $S$ a subspace it is not true that
$$
S=\bigoplus_{i=1}^n (S\cap\langle B_i\rangle).
$$
For example, take $V=\mathbb{R}^2$ as a real vector space, and $S=\langle(1,1)\rangle$, with $B_1=\{e_1\}$ and $B_2=\{e_2\}$. Then $S\cap\langle B_i\rangle=\{0\}$ for $i=1,2$, so no equality can hold.
If we add the condition that $S\cap\langle B_i\rangle\neq\{0\}$ for all $i$, can the above equality be shown to hold? Or is it still impossible? It is clear that the $\supseteq$ containment holds in all cases.
Answer: Take $V=K^4$ with basis $\mathcal{B}=\{e_1,e_2,e_3,e_4\}$. Consider the partition $\{\{e_1,e_2\},\{e_3,e_4\}\}$ of $\cal B$. Then we set $S=\langle e_1+e_3,e_2,e_4\rangle$. It is clear that $S\cap\langle e_1,e_2\rangle=\langle e_2\rangle$ and $S\cap\langle e_3,e_4\rangle=\langle e_4\rangle$ but $S$ is a three-dimensional subspace of $V$ whereas $\langle e_2\rangle\oplus\langle e_4\rangle$ is only a two-dimensional subspace.
Answer: The poblem with your purported equation is that the direct sum on the right hand side is in general smaller than $S$. Requiring that $S\cap\langle B_i\rangle\neq\{0\}$ is not going to help, since you can just add some external new vectors, and allot each of them to $S$ and to one of the parts $B_i$ that previously had a zero intersection with $S$; this will ensure $S\cap\langle B_i\rangle\neq\{0\}$ without doing anything to solve your problem. In your example both $S\cap B_1$ and $S\cap B_2$ are zero, so you can add two new basis vectors $e_3,e_4$, and in $W=\Bbb R^4$ consider $S=\langle (1,1,0,0),e_3,e_4\rangle$ with $B_1=\{e_1,e_3\}$ and $B_2=\{e_2,e_4\}$; now $S\cap B_1$ and $S\cap B_2$ are nonzero, but both being singletons they span a subspace $\langle e_3,e_4\rangle$ of dimension $2$, strictly contained in $S$. You see that the extension did nothing to remedy the situation restricted to (or if you want, projected onto) the subspace $\langle e_1,e_2\rangle$.
In general if you have a false statement with a counterexample, and you think of correcting it with an extra condition that is not satisfied in the example, then you should think first whether the condition has sufficient "muscle" to do this, in other words whether you can imagine this condition to be a crucial ingredient of a proof of the statement. One way to show that it does not have enough muscle is to show that you can adopt the counterexample easily to satisfy your condition without really changing the essence. And you could also guess that conditions $S\cap\langle B_i\rangle\neq\{0\}$ are not very strong for a proof; they will allow you to choose one nonzero vector in the intersection, but that's about it, and this does not seem the kind of thing that will lead to a general statement like the one you want to prove. In fact your statement is rather hopeless; the equality holds (if and) only if $S$ it actually spanned by a subset of $\mathcal B$ (just compare dimensions), which is a very exceptional situation.
Comment: Thanks for the more detailed criticism.


Multi-column ComboBox

Question: Can somebody please recommend a good multi-column combobox control for use in a Web Form?  I'm quite disappointed to not find any multi-column support on the  DevExpress ASPxComboBox control, unless I'm missing something.
Answer: I've found better luck exploring javascript controls than asp.net controls; especially if 'free' is a requirement.  I haven't evaluated this control but it's one built with jQuery: http://code.google.com/p/jquerymulticolumnselectbox/
Comment: I'm slowly moving over to the extJS JavaScript framework, but it's too early for me to do an urgent project in.
Answer: I'm using the telerik RadComboBox control. You can see an online demo of the multi-column functionality here.
Comment: Unfortunately, the telerik control suite costs just under three times what I'm making on this project.
Comment: Well in that case it's probably not an option. Unless you plan to do more ASP.NET projects in the future.
Comment: I have found a sponsor.  Damn, the telerik stuff looks good since I last used it, maybe Q1 2008, or earlier.
Answer: We used a control from this article.  No longer use it, but it was part of an aspalliance article and came with source code (VB.NET).

Multi-column ComboBox


in ant :BUILD EXCEPTION

Question: I am getting some problem while running ant
Here is the details of problem:
<code>C:\jboss-5.1.0.GA\server\default\deploy\mdd_install\mc_config\ant\compile\compile.xml:30: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
    at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105)
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:924)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
</code>
I echo java_home and its value is correct
I am running my aplication from jboss and try to execute it, but it is getting the above exception. I put tools.jar in jboss server lib folder ,with that it is runnig fine,but it is not correct way.
Comment: The exception isn't lying to you. It's very possible that the JBoss startup script changes JAVA_HOME. You should also show how you're starting Ant: are you using Runtime.exec() or are you calling `Launcher.main()`? And please format your question.
Comment: hi.sorry for format of the question.I am not getting your point.please elabroate it.
Comment: @mum How do u call ant? Is the JAVA_HOME correct prior to calling ant?
Answer: Make sure the case of the path to JAVA_HOME is right. Reopen the window or environment you're running ant from to make sure it's using the updated environment vars.

in ant :BUILD EXCEPTION


Free Wpf scheduler control

Question: Is there any free scheduler control for WPF?  I found ComponentOne and Telerik
but they are not free. I need something with equivalent functionality that I can use in school project.
Answer: As it is a school project your use of it would be limited. I know the guys at Telerik are very helpful. It may be worth contacting them with a view to "lending" you a license for your project. It is, after all, good for them because you'll then recommend them to others. Sort of like an "educational license".
Answer: Codeplex has a open source control for Scheduler Control See.. http://wpfschedule.codeplex.com/ . And this control has daily view only
Answer: There is also a control by Devcomponents
You could compare prices and buy.

Free Wpf scheduler control


Ngrok outgoing requests

Question: I'm using Ngrok to forward my development env. I've added custom domains (white label URLs) and configured the CNAME (example: mycustomdomain.com). I need to request some server with url (example: a.com/whitelisted). The server has a whitelisting where multiple url's are being stored (this list also contains our mycustomdomain.com), the server checks each incoming request with the whitelisting document and the certificate.
So basically we want something like this:
<code>                                                          XXXXXXX
                                                         X        X
+--------+              +------------+                  XX        XX
|        |              |            |                 XX          XX
|        --------------->            | -------------> X   Internet   X
|        |              |            |                X              X
+--------+              +------------+                 XX           XX
                                                        XX        XX
 localhost                Ngrok server                     X     X
                                                           XXXXXXX
</code>
Now I figured out that we can do something like this with Ngrok:
<code>./ngrok tls -region=eu -hostname=mycustomdomain.com -key mykey.key -crt mycert.crt 3005</code>
But I'm not quite sure regarding the outgoing request to the server, because for example I can't just make a simple HTTP request, because that will come from my development env and not from the Ngrok with all the configured/required stuff. Does anyone have experience with such use case?
Thanks!
Answer: You're looking for a proxy, not a reverse proxy like ngrok.
ngrok can forward requests to your development server but it isn't involved with outgoing requests from your development server.
Alternatively if you control the server you're looking to reach from your development server, you could have ngrok act as a reverse proxy on behalf of that server and proxy your requests through ngrok with IP whitelisted tunnel authentication.

Ngrok outgoing requests


What is the probability of being the last to touch an object passed around a circle of $N+1$ people?

Question: We have $n+ 1$ people numbered by $0,1,...,n$ standing in a circle.  Person $0$ has a bag of chips to start passing around.  Every time, the person $k$ who is holding the bag of chips has probability $j$ to pass to person $k+ 1$ and probability $i = 1-j$ to pass to person $n−1$ with $j >0.5$.  The game ends when all but one have held the bag, the one who hasn't held the chips gets to eat them.
Calculate $P_k$: the probability that the person $k$ will eat the chips
The way I wanted to approach this is the following. I realize that for person $K$ to be the one, both person $k+ 1$ and person $k−1$ must have held the bag. I wanted to condition  on  whether  person $k−1$ will have touched  the bag before person $k+ 1$ or vice versa. This is my first time in probability and I am having trouble approaching the question. I know that we need to A)  compute the probability that the $k-1$ person has held the bag before the $k+1$ person. B) Consider that given $k-1$ held the bag before the $k+1$ person, Calculate is the probability that person K wins  C) Given that person $k + 1$ touches the bag before $k-1$, calculate the probability person k eventually wins. And then use those to calculate the probability of $K$ winning. But I am not sure how to calculate the individual probabilities
Comment: Hence the word "similar" instead of voting for duplicate.
Comment: Looks like a random walk of bag of chips, and very similar to this [Random walk around circle](https://math.stackexchange.com/questions/801963/random-walk-around-circle)
Comment: No, all these questions have symmetry and p=1/2!  that is not my case
Answer: This is a modification of an answer to a similar question where which had $j=i=\frac12$ and all the probabilities in the answer to the original question were $P_k=\frac1n$.  Let's call movement to a position one more positive a step to the right.
So to find the probability of finishing at position $k$, we want to consider probabilities that on a biased random walk, either

Event 1: Starting from $0$, the walk visits $k-1$ before visiting $-(n-k)$, then, starting from $k-1$, it visits $-(n-k)$ (i.e. a distance of $n-1$ to the left) before visiting $k$ (i.e. a distance of $1$ to the right)
Event 2: Starting from $0$, the walk visits $-(n-k)$ before visiting $k-1$, then, starting from $-(n-k)$, it visits $k-1$ (i.e. a distance of $n-1$ to the right) before visiting $-(n-k+1)$ (i.e. a distance of $1$ to the left)

Using biased versions of the Gambler's Ruin formulae gives the sum of these probabilities as
$$P_k= \frac{1-\left(\frac{i}{j}\right)^{n-k}}{1-\left(\frac{i}{j}\right)^{n-1}}  \frac{1-\left(\frac{j}{i}\right)^{1}}{1-\left(\frac{j}{i}\right)^{n}} +\frac{1-\left(\frac{j}{i}\right)^{k-1}}{1-\left(\frac{j}{i}\right)^{n-1}} \frac{1-\left(\frac{i}{j}\right)^{1}}{1-\left(\frac{i}{j}\right)^{n}}  $$ which can be simplified to $$P_k= \dfrac{j^{k-1}i^{n-k}(j-i)}{j^{n}-i^{n}}$$
and though this might suggest $\frac00$ when $j=i=\frac12$, its limit as $j \to \frac12$ would be $\frac1n$, as in the linked answer.
To give an example of how simple this turns out to be, suppose $j=\frac34$ then $i=\frac14$, so you are $3$ times as likely to go right as left, and if $n=4$ then

the probability the final position is $1$ is $P_1= \frac1{40}$
the probability the final position is $2$ is $P_2= \frac3{40}$
the probability the final position is $3$ is $P_3= \frac9{40}$
the probability the final position is $4$ is $P_4= \frac{27}{40}$

with the probability being multiplied by $\frac j i = 3$ each time and $1+3+9+27=40$.


Limit of summation of fractional parts

Question: I have been trying to calculate the following limit of a fractional part without much success, as I am not very competent at mathematics. Could anyone provide any help please?
$lim_{x \to \infty} \frac{1}{x+1}\sum_{k=0}^x \{k/c\}$
Comment: What if $c$ is an integer ? What if $c = p/q$ is rational ?
Answer: If c is irrational (but not zero), k/c has uniform distribution in (0,1).
Thus the average goes to 0.5. The rational case can be more difficult.
Comment: The rational case is easy ($p$ is inversible modulo $q$ so $\sum_{k=1}^{mq} \{ kp/q\} =\sum_{k=1}^{mq} \{ k/q\}$). Then for $c$ irrational find a sequence $p_n/q_n$ of rationals such that $\lim_{n \to \infty} q_n |c-\frac{p_n}{q_n}|  = 0$ to obtain the result.

Limit of summation of fractional parts


Text classification based on keywords

Question: Totally new to ML so please bear with me. I'm trying to classify text from certain email messages and RSS feed entries. The texts should be classified as either relevant or irrelevant. The decision whether some text is relevant or not should be based on whether it contains certain keywords. I already have a set of these keywords labeled as "relevant" and "irrelevant".
Now my lack of ML knowledge makes me think this should be a simple comparison of keywords found in text. For example, if the text contains the word "blue", which is labeled as "relevant", the text itself is relevant. If it contains "red" (labeled as "irrelevant") it should be classed as irrelevant. Naturally, multiple occurrences should be compared and the winner determines the relevancy. Optionally, keywords could specify weights so that few mentions of an important relevant keyword outweigh many mentions of an irrelevant keyword.
On the other hand, from what I'm reading, I could run this through a naive Bayes classifier. The question is, can such a classifier accept single words rather than entire texts to analyze? Can it also give more weight to certain words over others?
Answer: Take a look at generalized expectation. It's a lightly supervised classification algorithm that starts from keywords and extends from there.
Single word can always be treated as a document which contains only one word. So conceptually there's no difference. If you're using a model where the features are words itself (NB or logistic regression), you can also read off the feature weight. But it's not clear how to interpret them.

Text classification based on keywords


Under nginx and codeigniter how do i redirect certain pages from http to https

Question: I want that certain pages to be available on https but not on http. I have a Code Igniter framework there.
Here is the code from nginx conf:
server {
   listen         80;
   ......
        #enforce https
        if ($request_uri ~ "^(winkelmandje|(index.php/)?winkelmandje|(index.php/)?history|(index.php/)?mobile/winkelmandje|(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ https://$http_host/$1 permanent;
        }
....
}

server {
  listen      443;
  ssl         on;
   ....
        #enforce http
        if ($request_uri ~ "^(!(index.php/)?winkelmandje|!(index.php/)!mobile/winkelmandje|!(index.php/)?history|assets/|!lib_desktop/|!lib_mobile/|!images/|!widget/|!(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ http://$http_host/$1 permanent;
        }

   .....
}

if i go to my domain/winkelmandje (this page is the cart) on http i do not get redirected to https.
Another example is if i access the domain index on https i do not get redirected on http
Comment: I asked *why*.  The reason I ask is that I suspect you're worried about the SSL overhead.  The overhead is tiny and not worth worrying about.  But if you share session cookies between the SSL and non-SSL parts of the site then anyone who can see the non-SSL traffic can just log in as that user using their cookie.  So if you don't have the `secure` attribute in your cookies, you might as well not bother having SSL at all.  If you want security, make the whole site SSL.
Comment: You're unlikely to achieve your security goals that way.  Why do you want *any* pages to not use SSL?
Comment: Well i want only the basket, secure checkout and order history to be on https. The rest of the pages must be on http
Comment: I made it work! I removed the ! in the ssl and removed the ^ from http and https (because request_uri contains the domain as well).
Answer: Remove the ! in the https server directive and remove the ^ from http and https (because request_uri contains the domain as well).
server {
   listen         80;
   ......
        #enforce https
        if ($request_uri ~ "(winkelmandje|(index.php/)?winkelmandje|(index.php/)?history|(index.php/)?mobile/winkelmandje|(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ https://$http_host/$1 permanent;
        }
....
}

server {
  listen      443;
  ssl         on;
   ....
        #enforce http
        if ($request_uri ~ "(!(index.php/)?winkelmandje|!(index.php/)!mobile/winkelmandje|!(index.php/)?history|assets/|!lib_desktop/|!lib_mobile/|!images/|!widget/|!(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ http://$http_host/$1 permanent;
        }

   .....
}


ODI Sql Spool with GetOption of Query Separator

Question: Hello .
I need to run a select using a separator for the fields to make a sql spool WHEN use static character ;
So I do:
select < % = odiRef.getColList ( " " , " [ EXPRESSION ] ',' || ' , ' || " , " " , " " ) % > from < % = snpRef.getFrom ( ) % >

Now if I try to replace ' || ' , ' || " with a odiRef.getOption not working .
Some of you have already had a similar problem ?
Answer: try this:
select <%=odiRef.getColList("", "[EXPRESSION]", **"||'" + odiRef.getUserExit("option_name") + "'||"**, "", "")%> from <%=snpRef.getFrom()%>