Drupal Master/Slave Replication

Question: I've setup two MySQL servers with Master/Slave replication for the drupal database and I've confirmed the databases are in sync and replicating.
I am now trying to point drupal to both databases basically for failover/redundancy purposes. That is if I need to reboot our primary database server I don't want our site to go down. (Going read-only is acceptable during failure scenarios)
Based on the following article. I've modified settings.php as follows:
$databases['default']['default'] = array(
  'driver' => 'mysql',
  'database' => 'sdrupal',
  'username' => 'drupal',
  'password' => 'topsecret',
  'host' => 'masterdb.ptp.local',
);
$databases['default']['slave'][] = array(
  'driver' => 'mysql',
  'database' => 'sdrupal',
  'username' => 'drupal',
  'password' => 'topsecret',
  'host' => 'slavedb.ptp.local',
);

The configuration is fine until I shutdown the master (service mysqld stop) - when I do that my site pukes:

PDOException: SQLSTATE[HY000] [2013] Lost connection to MySQL server
  at 'reading initial communication packet', system error: 111
  in drupal_is_denied() (line 1895 of /www/includes/bootstrap.inc).
  Additional
PDOException: SQLSTATE[HY000] [2013] Lost connection to MySQL server
  at 'reading initial communication packet', system error: 111
  in dblog_watchdog() (line 141 of /www/modules/dblog/dblog.module).

Whats the trick to make this work?
Answer: Regarding Master/Master (High availability) is possible to do load-balancing when no master is down.
The following will make all writes go to master1 and all reads go to master2. If master1 fails, all queries will go to master2. If master2 fails, all queries will go to master1.
'master' => array('master1', 'master2')
'slave' => array('master2', 'master1')

The following will make all queries go to master1. If master1 fails all queries will go to master2:
'master' => array('master1', 'master2')
'slave' => array('master1', 'master2')

Comment: Thank you for this answer. I understand this is quite old and might be outdated. Do you have any tips for implementing the same in the latest version of Drupal?
Answer: For the benefit of others - as best as I've been able to find - out of the box Drupal 7 doesn't seem to have any database high availability capability built in.
You can setup two mysql servers in a master/slave configuration but the best it will do is send all writes to the master and all reads to the slave. That provides crude load distribution but not failover.
That is to say if the master mysql server goes down all bets are off – the site goes down with an ugly error message complaining that PHP can't reach the master database.
Traditionally, as I understand, the way to tackle this with other software is to either use mysql ndb clusters or mysql proxy – but after reading a bit - these technologies apparently don't play well with Drupal.
However I stumbled upon a Drupal module called auto-slave (http://drupal.org/project/autoslave). It's not widely used (there are 12 sites actively using it according to the stats) but it does seem to be able to do what we want. It can be configured in a variety of ways:
Master/Slave
Writes go to Master
Reads go to Slave

Drawbacks:
If master is down, the durpal site displays a prominent message that the site is in "read only" mode.

Master/Master (High availability)
Read and Writes go to master1 (primary) unless its unavailable.
If master1 is unavailable, reads and writes go to master2 (secondary)

Drawbacks:
There is no load distribution. All load (reads and writes) go to either master1 or to master2

Master/Master/Slave (High availability/High performance)
Writes go to Master1 (primary) unless it's down then they go to Master2
Reads go to the slave unless it's down
Drawbacks:
Requires a minimum of three database servers (master/master/slave)

So far we've setup the first (Master/Slave) successfully. I'm going to be attempting to setup Master/Master/Slave next.
Hopefully this helps someone else out.
Comment: This did help alot. :)

Drupal Master/Slave Replication


Dynamically assigning IDs to tags using an EL variable

Question: I want to loop over a number of "guests" and insert an id dynanimally
<ui:repeat value="#{guestList}" var="guest">

</ui:repeat>

The problem is, that the
cannot resolve firstname_#{guest.uniqueID}

javax.faces.FacesException - Cannot find component "firstname_1" in view.
  at org.primefaces.component.message.MessageRenderer.encodeEnd(MessageRenderer.java:41)

It works without any problems if I write a constant inside the loop, and also I am sure that the variable can be resolved, as I can output it in that loop.
How can I instruct jsf or primefaces to resolve this variable?
Answer: You cannot use EL expressions in the id attribute.
But you don't need to care for the uniqueness of your ids in ui:repeat. JSF does it for you. Just give your input field a "fixed" id and reference it in your p:message:
<ui:repeat value="#{guestList}" var="guest">

</ui:repeat>

Comment: Thank you for the answer, but the guest number is a mere simplification of my problem since I need those IDs for addressing the right fields inside my backing bean. Unless there is a another way, to address my bean in another way, this isn't yet the solution to my problem. (I tried to make it more clear in my question)
Comment: It is not clear why you need the id in the backing bean. You left the value attribute blank. It should be used to bind the input to a backing bean field. Maybe that is what you need?
Comment: You are right! Now I got it: Since I am iterating through all my "guests" anyway, I can dynamically assign the value bindings in my loop. (Sorry for the confusion, but actually the problem occurs knee-deep in nested compositions)


How to compare K2 blackpearl .sodx files with latest TFS version

Question: I am maintaining an older K2 blackpearl system for a customer. The development environment is a virtual machine running Windows Server 2008R2 Datacenter with K2 blackpearl 4.6.6 and Visual Studio Professional 2012. The  development environment is connected through VPN to the customers Team Foundation Server.
The previous developer who handed over the project to me, apparently made some changes, which I do not know the extent of. And this person is not available in the company anymore. On the Visual Studio Team Explorer I have a couple of pending changes in some .sodx files and a .dll file like shown here.

However I am not able to see, which changes were made. If I rightclick and choose "Compare with Latest Version", I just see a lot of unreadable XML code (.sodx). This doesn't tell me anything useful.
So my question is. Are there a way of finding out, which changes were made to these files?
Thanks in advance.
Comment: If a SODX file is an XML file and it shows you a diff of XML, that sounds like correct behavior. What exactly are you expecting?
Comment: @DanielMann Yes I can see that the files have been changed. But what I want to see is WHAT has been changed in the files. When comparing the XML (SODX) files all I see is a lot of unuseful keys and such generated by K2. I want to find out what the previous developer changed in the files.
Answer: Comparing files  is the right way to show the difference of two version files in TFS source contol.
Since you have see the files have been changed, just the changed is unuseful  or  meaningless to you. This is not related to TFS area.
If you are worrying about the changes will influence your code or environment, you could simply roll back the changesets  after you checked in the pending changes. If you undo the pending changes, these will just disappear and not able to recover. So suggest you to check in the pending changes.  Another way is  connecting to the  previous developer and directly get changed things from him. After all, this is also belongs to your working transition.
Comment: Thanks for your opinion @Patrick-MSFT. This is also what I chose to do. To prevent any loss of work, I checked in the pending changes. If we then are having issues on a later point, we can roll back again.


How to create a unique toJSON method for a property defined by Object.define()

Question: Lets say we have an object with a defined property that is expected to point to another object, as follows:
Object.defineProperty(parent, 'child', {
    enumerable: true,
    get: function() { return this._actualChild; },
    set: function(v){
      if(v && typeof v === 'object'){
            this._actualChild = v;
      } else {
        throw new TypeError('child property must be an object!')
      }
    }
  });

Is there a way to configure the property itself so that when it's run through JSON.stringify(), the toJSON of the .child property can be defined uniquely for that property?
For instance, after we have set the following:
var jill = {id: 3, name: 'Jill'};
parent.child = jill;

If we could somehow define the toJSON for parent.child to return the id property of the child. So JSON.stringify(parent) would return:
{_actualChild: {id: 3, name: 'Jill'}, child: 3}

We can define a toJSON for the child object itself of course, but then we would get:
{_actualChild: 3, child: 3}

I would like to separate the property toJSON method from the actual child object's toJSON method. Is this possible?
It would be really nice if I could just do something like this:
  Object.defineProperty(o, 'child', {
    enumerable: true,
    get: function() {
      return this._hiddenChild;
    },
    set: function(v){
      if(v && typeof v === 'object'){
            this._hiddenChild = v;
      }
      else {
        throw new TypeError('child property must be an object!')
      }
    },
    toJSON : function() {
      return this._hiddenChild.id;
    }
  });

But alas, Object.defineProperty doesn't take a toJSON descriptor.
Comment: are u asking if we can overwrite toJSON mentod?
Comment: since _v_ is an object, you can define a toJSON method on it in your setter, even as an own property it will work.
Comment: @dandavis that's exactly what I meant when I said `"We can define a toJSON for the child object"`. The problem is that toJSON method would be enacted every time you tried to stringify the object. I want it to *only* be enacted when that particular property (in this case `child`) is stringified.
Answer: No, you cannot define stringification behavior for single properties. You will need to put a toJSON method on the parent object itself:
var parent = {};
Object.defineProperty(parent, "child", {…});
parent.child = …;
parent.toJSON = function() {
    return {_actualChild:this.child, child:this.child.id};
};

> JSON.stringify(parent)
{"_actualChild":{"id":3,"name":"Jill"},"child":3}


Can I use a Mustang bridge on a Fender Jaguar? Are there issues?

Question: I've recently purchased a Fender Squier Jaguar from an online dealer, and was aware beforehand, that the stock bridge was unreliable and subject to many complaints. The issue with the Stock Jaguar bridge is that there are no groves that keep the string from moving on the bridge, and so when you play it the strings will usually move around on the bridge. So, before purchasing the guitar I did some research on how I could fix this problem, many people recommended swapping out the Jaguar stock bridge for a Mustang bridge which would fix the issue entirely. However, after purchasing a replacement Mustang bridge and receiving it I took my guitar to a local luthier who then told me that the mustang bridge will not work with the instrument as there is no way to raise or lower the string saddles to adjust it to the fretboard radius or something along those lines. He also continued to say that if this bridge was fitted it would create a false intonation and make everything a huge hassle, after this he said that he could file out groves in the stock bridge and would charge me about $120 AUD (with set-up) for it. I asked him how much he would charge to fit the mustang bridge and have the guitar set-up, but he continued to say it would not work.
So, for those that have replaced the stock Jaguar bridge for a Mustang bridge. Have you had success with replacing it? Does it really effect the intonation? If the Mustang can handle a bridge without the ability to heighten each individual string saddle, why can the Jaguar not do the same? Does anybody you know have an issue with this modification? Or might this fellow just be trying to get a little bit more money out of me to file groves in the stock bridge? Should I have the stock bridge filed and is it a reasonable price?
Below: Jaguar Stock Bridge

If you would like further details, please just ask me about anything I may have missed. I've tried to get down all the things I feel were important.
Below: Mustang Stock Bridge

Thank you for reading, I greatly appreciate any input or advice you may have.
Best Wishes,
Trash Incarnate
Comment: Even though you **can** switch out the bridge for the Mustang, and some people do, there does not seem to be a consensus on whether it's a good idea or not: https://www.gearslutz.com/board/so-many-guitars-so-little-time/592316-replacing-bridge-jazzmaster-jaguar.html I suggest playing your new Jaguar a lot and working with the bridge to decide if you really can't stand it or if you grow to love it. Then decide for yourself whether to change out the bridge.
Comment: I'm confused about the jaguar bridge problem. I can see grooves in the saddles of that bridge.
Comment: Also a quick web search reveals the answer to your question is definitely "yes": http://www.jag-stang.com/guitars/jaguar/fender-jaguar-jazzmaster-bridge-mod/ It almost looks like you took the pictures from that web site but I'm assuming those are just popular bridge pictures because if you'd seen that site I doubt you would have asked here.
Answer: I would not ever use a Mustang bridge as a replacement for either a Jaguar or Jazzmaster. They cause all kinds of intonation problems. I had one that came stock on my Troy Van Leeuwen signature Jazzmaster. What a headache. Honestly the absolute best replacement bridge for these type of guitars in a Mastery Bridge. It is absolutely the finest and most reliable bridge for these type of guitars. They are made from the best materials and are the most ideal bridge for function, for these particular guitars. They are not cheap however. But if you have a high end Jag or Jazzmaster, they are worth their weight in gold. However as someone pointed out above, you have a Squire Jaguar and it's probably not worth the investment given the fact that it's a low end model.
Answer: Warmouth does a "Mustang" bridge with individual saddle height adjustments and deep groove. One of the strong features of the much mis-understood Jag bridge, is the individual saddle height adjustments. This is a great improvement over the stock Mustang bridges  - which WILL work just fine on Jags and Jazzmasters without intonation problems, by the way - and are way better than terrible 'tune o matic" types. Mastery bridges are excellent , as well as StayTrems, but too expensive for most...
A slight shim in the neck pocket helps the break angle. It's easy to do.
I've simply filed slightly deeper grooves in the stock Jag bridge, installed 11's that feel like 10's on a Jag or JM , done a PROPER setup and had great , consistant results.
Answer: The problem is my Jaguar has a 7.25 in radius and the Mustang is 9.5in...I settle mine with graphtech saddle and problem solved...I just don't like the look of the Mastery, too high-tech for a vintage thin line Jaguar...Cheers
Answer: Two things: first, the bridge supplied w/ the guitar is presumably set to match the guitar's factory-built fret height.  You would have to grind down or build up the replacement bridge to match.  However, IMHO neither of these bridges is optimal, as the string height should be adjustable to match both the neck and your individual preference for string clearance.
Second, given that the Jaguar is a pretty low-end model, you may want to save your money and switch to a better instrument altogether, rather than dropping a chunk of change on a proper bridge (i.e. one which has both length and height adjusters) to install on the Jaguar. Decent bridges will run $50 to $100 or more.
Comment: The jaguar bridge clearly has height adjustment screws for each saddle piece. The mustang bridge pictured does not seem to have any height adjustment. Even without string height adjustment at the bridge, a bolt on neck can be shimmed or shaved to make the neck angle match the bridge. Many multi platinum albums have been made with inexpensive low end gear, so I wouldn't worry too much about that myself.
Comment: The little holes on the sides of the saddles on the Jag bridge are the height adjusters, very similar to other adjustable saddles. It's those little things that are one of the major complaints about the Jag bridge actually.
Comment: @ToddWilcox in the photo provided I can see no evidence of height adjusters.  the length adjustment screws appear to be mounted to the solid-body frame exactly like the mustang bridge.


Locating a key on the keyboard

Question: I'm trying to figure out what the correct technique is for locating a key on the piano keyboard. As far as I can tell, there are the following clues (names invented on the spot):

"absolute position", i.e. the ability of locating with closed eyes a certain key on the keyboard.
"relative position", i.e. combining the knowledge of the current position of your hand on the keyboard and the knowledge about the size of intervals on the keyboard. This works both in space ("one fifth upwards from where my pinky is") and in time ("the same key that my thumb played two notes ago").
"keyboard shape", i.e. slightly grazing the black keys and using the gaps B-C and E-F to deduce the location of the hand.
"direkt looks", i.e. taking your eyes off the score to directly look at the keyboard.
"peripheral look", i.e. keeping your eyes on the score but using your peripheral vision to guide your hands.

Obviously I try to avoid 4, although I sometimes cannot avoid it (especially for large jumps). I'm pretty bad at 1, while 2 works okay (especially once I had some time to practice the piece). 3 also works, but I'm not able to do it fast enough for most pieces. So far I haven't used 5 too much.
What I'm wondering: Is any of these techniques the "preferred" one? Or is the golden way a combination of some of these? Should I try to train these techniques individually, and if so, are there special training pieces?
Comment: #3 + practice, practice, practice... eventually your fingers know how to find the keys on their own, without needing any conscious intervention.
Answer: 2 and 5 are the most important ones during your play and most commonly used probably.
1 is very useful as well. But I wouldn't go as far as naming it 'absolute' position, since it is always relative to something right? Even it is the way your seat is positioned against the piano.
Of course you will start the piece by looking at the keys (4) and do the same for big jumps. In my opinion that is pretty normal. During a play I would focus on 2 and 5.
Answer: Choice #3 is the most important.  Here's why.
Some works have lots of notes.  A pianist can't possible play the notes by picking them out one by one-- instead, a pianist will (unconsciously) break the parts into scales, arpeggios, and chords.  Melodies can be thought of as scales or chords with notes "missing," i.e. to play a melody composed of C E Bb I might shape my hand like a C-dominant chord and play the notes one by one, skipping G.  It is way faster for me to put my hand in the shape of a chord and subtract a note than it is for me to construct the chord note by note as I go.  In principle, this is quite similar to the way fast typists will type words in one quick motion instead of hunting and pecking letter by letter.
This is why some of the most difficult pieces are in keys with lots of black notes-- they'd be infinitely harder to play if they were all white notes.  This is also why pianists practice scales and arpeggios so religiously-- if you can play those well, it makes it far easier to play tonal music.
Answer: I always practice a song very slowly, and look and where I need to put my hand after a large jump. After playing the same jump over and over at varying speeds, I kind-of know where it is automatically. Also, by the time you can preform a piece, you should have it memorized, so that you don't need to look at the sheet music at all. Staring at your hands is obviously not much better, but at least then you can look at your hands if you need to. Also, as for pieces that help you with being able to jump large distances without having to look at your hands, Maple leaf rag is great. Both hands jump large intervals consistently throughout the song. Or anything by Scott Joplin is good.

Locating a key on the keyboard


Why simulating touch events in Lollipop doesn't work

Question: I want to inject touch events into the device. I use instrumentation for that. The method works well on Jelly Bean, but it doesn't inject nor does it give any error in Lollipop.
When I searched I found that it might be due to the enforcement of SELinuxwhich prevents some actions from being executed for security purposes. I downloaded SELinux Mode Changer and set SELinux to permissive, and I made sure that it was set to permissive by checking its status in About phone in the settings. My device is rooted, and I have tried with suand without it. But, really I don't know what is the problem.
Here is my code:
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View view = findViewById (R.id.face);

try {

    Runtime.getRuntime().exec("supoliciy –live \"allow appdomain input_device dir ( ioctl read getattr search open )\" \"allow appdomain input_device dir ( ioctl read write getattr lock append open )\"");
    //supoliciy –live "allow appdomain input_device dir ( ioctl read getattr search open )" "allow appdomain input_device dir ( ioctl read write getattr lock append open )"
    // Runtime.getRuntime().exec("reboot");
    // Runtime.getRuntime().exec("su -c reboot");
    /*

    Process process = Runtime.getRuntime().exec("su");//supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"");
    DataOutputStream os = new DataOutputStream(process.getOutputStream());
    String cmd = "/system/bin/input tap 100 200\n";
    os.writeBytes(cmd);
    os.writeBytes("exit\n");
    os.flush();
    os.close();
    process.waitFor();
    */

    Process process = Runtime.getRuntime().exec("su");//supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"");

}
catch (IOException e) {
    Toast toast = Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_LONG);
    toast.show();
    e.printStackTrace();
 //   Log.e(" ", e.getStackTrace().toString());
}
/*
used in cmd case only
        catch (InterruptedException e){
            Toast toast = Toast.makeText(getApplicationContext(), "ERROR 2", Toast.LENGTH_LONG);
            toast.show();
        }

*/

        final Instrumentation m_Instrumentation = new Instrumentation();
        final MotionEvent down = MotionEvent.obtain(SystemClock.uptimeMillis(),
                SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 400, 600, 0);
        down.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        final MotionEvent up = MotionEvent.obtain(SystemClock.uptimeMillis(),
                SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 400, 600, 0);
        up.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                m_Instrumentation.sendPointerSync(down);
                m_Instrumentation.sendPointerSync(up);
            }
        });

        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

               Toast toast = Toast.makeText(getApplicationContext(), "View touched", Toast.LENGTH_LONG);
               toast.show();
                return false;
            }
        });

        t.start();

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        Toast toast = Toast.makeText(getApplicationContext(), "View touched", Toast.LENGTH_LONG);
        toast.show();
        return true;
    }
}

I even tried to execute supoliciy as you can see in the code above, but nothing worked.
How can I solve this problem?
Answer: What error are you seeing?  logcat should tell you why it was denied.  You may be missing some additional permissions.  Also, permissions should be grouped together using curly braces, not parentheses.
The error should look something like:

04-12 19:57:31.501 4885-4885/? E/audit: type=1400 msg=audit(1460509051.501:7365): avc:  denied  { read } for  pid=18086 comm="yourappname" name="lux" dev="sysfs" ino=19601 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sysfs_sensor_writable:s0 tclass=file permissive=0

You can then use this to fix/update your supolicy command.  In this example, you would use "allow untrusted_app sysfs_sensor_writable file { read }" (braces aren't needed in this case, but you will probably be adding multiple permissions here).


Apache conditional logging regex (pcre)

Question: I have the following for conditional:
SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "[^,]+" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio

However, when I send a request with the X-Forwarded-For header set to a comma-separated list of IPs (more than one) it sets BOTH enivronment variables log-format-combinedio-xff-multiple-ips and log-format-combinedio-xff-single-ip and so I get it logged twice.
Any ideas how to fix this?
Answer: In the second condition (to match a single IP), if you add a check for the beginning (^) and end ($) of the string to create the following regex, it won't match multiple comma separated values.
^[^,]+$

It means: from the beginning to the end of the string, match a sequence of non-comma characters.
Comment: Awesome, I just came to the same conclusion, but I'm accepting your answer. Thank you!
Answer: Ok I figured it out and posting here in case it helps anyone else:
The regex for the second SetEnvIfshould be:
SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip

This will basically only match strings that DO NOT have a comma in them (as in a single IP).
So the full solution is something like this:
SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio

Apache conditional logging regex (pcre)


Comparing sample fluorescence at different temperatures

Question: First of all, sorry if this format of question has already been answered - but I've had a look at previous answers and still can't figure this out for the life of me.
So, I have these 15 samples of bacterial colonies. Leftmost column are 3 replicates of a cell line that I think should be more shiny when they get hot, all 4 columns to the right are triplicate controls for comparing against. (2nd column from the left is the direct comparison to the leftmost column as this cell line expresses the same fluorescence protein, but shouldn't get shinier when hot.)
I have taken this single plate of these colonies and put it into 0 degrees before measuring the fluorescence, and then I put the plate into 45 degrees before measuring fluorescence. What I'm struggling now with is how to process and present the data. My first instinct was to make a 3x5 table where each entry is equal to the fluorescence of its corresponding well at 45 degrees divided by its fluorescence at 0 degrees. From there I would then take the average and standard deviations for each column, before plotting those on a graph. I turned them into relative percentage changes by calculating =100*(1-(proportion)) and =100*(standard deviation) for the standard deviations.
(In terms of what bar represents what columns on the plate: dTomato = 2nd column from left. dTomatoELF3 = 1st column on the left. GFP = 4th column from the left. GFPELF3 = 3rd column from the left. 5th column is not represented in this graph.)
This resulted in some really nice graphs that actually show the trend I was hoping for with no standard deviation overlaps for dTomato and dTomatoELF3 and so some possible significance. To test this hypothesis I did a simple Students T-Test in excel, 2 tails, type 2 test, where the two arrays corresponded to the proportions for each column. The p-value was 0.034722 so I wanted to accept the alternative hypothesis that the dTomatoELF3 samples are shinier in the heat; however this p-value is a little suspicious and nice seeing as I have only 3 replicates.
A colleague looked at these graphs, wasn't convinced, and asked for the results but processed in a different way. Rather than calculating proportions first and then averaging the proportions from 0 to 45 degrees, he wanted me to just calculate the average fluorescence across the triplicates, and make a graph of the averages for 0 and 45 degrees side-by-side. He wasn't interested in the value of the proportions.
(Sorry this isn't as refined a graph; GFP = 4th column from left, GELF = 3rd column from left, DTOM = 2nd column from left, DTELF = 1st column on left.)
Sadly my promising results were lost when the data was presented in terms of absolute data instead of proportions, but I guess that's not surprising with only 3 replicates.
So finally I've got to the problem.

I feel that absolute values is a more accurate way to represent the data than proportions, but I honestly don't know why and so I don't know how to explain it in my discussion section (and I would definitely like to try as I think it's important for the write-up). The person who asked me to present it this way didn't have much to say other than that the first graph was unconvincing. My maths graduate friend tried to figure out an explanation, but he wasn't entirely sure either and pointed me to this website.

I don't know what stats test I should be using. The same friend mentioned "I think the discrepancy comes from the weirdness that happens when you divide one stat by the other", (i.e. the fluorescence at 45 degrees divided by fluorescence at 0 degrees.) "I think you want to treat the 0 and 45 as separate trials. Combining them into a combined statistic is [probably] invalid for this sort of hypothesis test". But this has only confused me more, as this means a T-test isn't correct. But I have no idea what other test I'd use.

For context, I've dabbled in stats for previous write-ups and I can generally follow a good online guide for how to do stats tests like One-way ANOVA on Excel. But unfortunately I have no R experience. I would very much like to get some, but my write-up is due soon and I don't have time to learn.
Thank you very much for reading! If you have any suggestions or any commentary at all please let me know what you think I should do :) (Oh and unfortunately due to time constraints, repeating this experiment with lots more replicates isn't feasible)
Answer: I'm not confident I followed all the details, so I summarize my understanding first:
The experiment involves one 3x5 plate with 15 wells: 5 cell lines with 3 replicates. Fluorescence is measured at 0° separately in each well, then the plate is heated to 45° and fluorescence is measured again. The hypothesis is that one cell line gets shinier when heated.
And there are two questions:

What is the proper order of operations: compute statistic (comparing fluorescence at 0° and 45°) and then average (across replicates). Or average first and then compute statistic?
What is the appropriate statistic: ratio or differences of fluorescence values?

If this is the correct setup, then the measurements before and after heating are paired since the data comes from the same wells. Then averaging first and making a comparison second is not the right approach; instead make comparison first (between the before and after fluorescence values within a well) and then average. We observe the same wells under two different conditions, so we make a pre-post comparison of paired measurements.
Now about what you should compare: ratios (value after heating divided by value before heating) or differences (value after heating minus value before heating). This is best determined by domain knowledge: do you expect the effect of heating on shininess to be multiplicative or additive? If the multiplicative, then you can look at the logs rather than the raw values, so let's assume that you want to compare differences of fluorescence values.
We've abstracted the problem to the following analysis: we want to determine if there are differences in post-heating fluorescence between groups (columns) given the pre-heating fluoresence. I think it's reasonable to contrast only two groups: the first and the second column on the left because they are comparable before heating: the cell lines express the same fluorescence protein.
The most straightforward analysis is to compare change scores (post-fluoresence - pre-fluoresence) by cell line (column in plate). This you can do it with a two-sample Wilcoxon rank sum test. Better but requires more statistics, is to use ordinal regression to analyze post-fluoresence as a function of pre-fluorescence and cell lines.

Comments about the fine print:

We don't accept the alternative hypothesis. We reject the null hypothesis.
It's not very meaningful to compute the standard deviation of 3 numbers (3 wells).
I'm confused by the "ice  bath" values for DTELF and DTOM. Aren't these cell lines supposed to be comparable at 0° because they express the same fluorenscence protein?


How to show tooltips on form labels based on view filter descriptions in a Bootstrap sub-theme?

Question: I am trying to find a way to display tooltips when a user hovers the mouse over a filter label of a views search page. Preferably, to reduce hard-coding, I would like to take into advantage the filter description and get the tooltip text from there (and subsequently hide descriptions through css).
Also the best way I found to actually activate the tooltips in Bootstrap is to add the attribute data-toggle="tooltip" to the element that we need to show a tooltip for.
So far I am using the recipe from here adding the data-toggle element
 function mytheme_form_element($variables){
     dpm($variables);
  $original = theme_form_element($variables);
  $return = '
' . $original . '
';
  return $return;
 }

but I don't see the filter description anywhere in the $variables array plus this snippet themes the filter field and not the label but would probably do the trick.
Answer: You can do it in form alter, here's an example (add additional conditions yourself):
/**
 * Implements hook_form_FORM_ID_alter().
 */
function yourmodule_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  $field_name = 'filter-title';
  $form['title']['#attributes'] = array(
    'data-toggle' => 'tooltip',
    'data-original-title' => $form['#info'][$field_name]['description']
  );
  $form['#info'][$field_name]['description'] = '';
}

Comment: Sounds nice! Is there any way of doing this globally for all views without having to alter all? I'm having a few of them
Comment: Also shall I `unset` the description instead?
Comment: About `unset` - I wouldn't recommend to unset form elements, in some cases it produces warnings.
Comment: Unfortunately, I don't know a good way to do it globally, since views filter field renders in template_preprocess_views_exposed_form() function, you even can't alter it in yours _preprocess_views_exposed_form(), because filter field has already rendered. One dirty way is to replace  template_preprocess_views_exposed_form to yours function, but I would recommend you to use form_alter if its possible.
Answer: As per this post

For performance reasons, the Tooltip and Popover data-apis are opt-in,
  meaning you must initialize them yourself.

So you have to initialize and use like

Please visit on this post.
Comment: Right, I have already added the snippet above in the `html.tpl.php`. My question is how to show tooltips on filters, where the tooltip text comes from the filter description


Como resolver este erro ao utilizar a Room Persistence Library com Kotlin?

Question: Quando mando executo o app, recebo um crash assim na primeira chamada ao banco de dados:
java.lang.RuntimeException: Unable to start activity ComponentInfo{.../....ActivityLogin}: java.lang.RuntimeException: cannot find implementation for ....database.AppDatabase. AppDatabase_Impl does not exist

Minhas dependências relacionadas ao banco de dados:
compile "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

P.S.: Não estou usando o kapt na minha aplicação.
Comment: *"Não estou usando o kapt na minha aplicação."*  -  mas deveria estar se quer usar a Room em kotlin.
Answer: @ramaral resolveu o mistério!

If you previously used the Android support for annotation processors,
  replace usages of the annotationProcessor configuration with kapt. If
  your project contains Java classes, kapt will also take care of them.

fonte


how to approach a large data set with multiple regression

Question: This is a more theoretical question, perhaps less suiting to the required format of a question on cross validated. Still I hope someone can help or advise me.
I'm using r.
I have a data frame with roughly 180k observations and 120 variables. When running through a multiple regression model there ends up being ~1000 variables including dummy variables.
My baseline kitchen sink model is the target variable as a function of all ~999 variables. This takes r about 10 minutes to compute on a single 0.8 train and 0.2 test data on my 6gb Mac, 2.2 processor.
On my baseline kitchen sink model I also did kfolds cross validation on training with 10 folds. Roughly this took an hour to compute.
I'm looking at my notes from school on feature selection. I would like to try stepwise regression, forwards and backwards to see what it comes with for my performance measure Mean Absolute Error.
I would also, for each iteration within stepwise, train using cross validation.
Is this possible? If running the baseline model 10 times with a single cross validation takes 1hour then I'm about to ask r to do the same 999 times with a stepwise instruction.
Is what I'm trying to do "normal"? Is my understanding and approach "sane"? Given the size of my data and that I'm on a 6gb Mac, what would be a logical approach for feature selection and training?
If I should provide any more info here such as str(df) let me know.
Comment: For a speed boost look up the lmfit function in R, and use it instead directly with matrixes instead of a formula based model
Answer: Instead of using stepwise regression, which is a method very often frowned upon, I would use LASSO/Elastic Net, gamboostLSS or Bayesian Model Averaging.
If you would like to gauge the models predictive performance then a kfold cv is a good way to go about doing so.


Local Blast empty xml file python

Question: I am trying to implement a little script in order to automatize a local blast alignment.
I had ran commands in the terminal en it works perfectly. However when I try to automatize this, I have a message like : Empty XML file.
Do we have to implement a "system" waiting time to let the file be written, or I did something wrong?
The code :
<code>#sequence identifier as key, sequence as value.
for element in dictionnaryOfSequence:
    #I make a little temporary fasta file because the blast command need a fasta file as input.
    out_fasta = open("tmp.fasta", 'w')
    query = ">" + element + "\n" + str(dictionnary[element])
    out_fasta.write(query) # And I have this file with my sequence correctly filled
    OUT_FASTA.CLOSE() # EDIT : It was out of my loop....

    #Now the blast command, which works well in the terminal, I have my tmp.xml file well filled.
    os.system("blastn -db reads.fasta -query tmp.fasta -out tmp.xml -outfmt 5 -max_target_seqs 5000")

    #Parsing of the xml file.
    handle = open("tmp.xml", 'r')
    blast_records = NCBIXML.read(handle)
    print blast_records
</code>
I have an Error : Your XML file was empty, and the blast_records object doesn't exist.
Did I make something wrong with handles?
I take all advice. Thank you a lot for your ideas and help.
EDIT : Problem solved, sorry for the useless question. I did wrong with handle and I did not open the file in the right location. Same thing with the closing.
Sorry.
Comment: Please delete the question, rather than editing to comment that it's no longer relevant.
Comment: Thank you, I did not see that I can delete a useless question.
Answer: try to open the file "tmp.xml" in Internet explorer. All tags are closed?
Comment: I found my problem solution, but I tried your idea and you are right. With the ancient XML file all tags were not closed!Thank you
Comment: Hi, could you please elaborate on what you changed? I'm getting the same error. Thanks.

Local Blast empty xml file python


Is the range of labels important for scikit classifiers?

Question: I could not find an answer for my question anywhere.
Let's say I am going to make a classification with from sklearn.linear_model import SGDClassifier. Should the classes need to be integers (and if so do they have to start from 0 or 1 ? )
Answer: No the classes can be any discrete values.

They can be strings as in ['yes', 'no'] or ['high', 'medium', 'low']
Integers like [4, 5, 10] or [1, 2, 3] or [-1, 1]

Internally, they will be converted to integers starting from 0, using LabelEncoder. You don't need to worry about that.
Answer: The standard approach is to model classes via one-hot encoding
Comment: But one-hot encoding this is obviously not required here, the doc of `SGDClassifier` has an example where the targets are `Y = np.array([1, 1, 2, 2])`.


Normally distributed effect size

Question: I have read in several articles that effect sizes (like Cohen's d or Hedges g) can be considered to be normally distributed around the population effect size for large samples. On what basis can we say this? Is the calculation of the variance of d based on this statement?
Comment: Is it not the central limit theorem?
Comment: @POC Often the CLT doesn't apply, because the effect size is a *ratio,* rather than a mean.  Much depends on how the effect size is computed and on the underlying model.
Answer: I think I found an answer here : Larry Hedges Journal of Educational Statistics, Summer, 1981, Vol. 6, No. 2, p.117 :
I quote (p.117) : When the number of experiments to be combined is large or the degrees of freedom of the experiments are large, the computations involved in the method of Walker and Saw become tedious. In this case, the normal approximation to the noncentral t-distribution is quite good (see Johnson & Welch, 1939) and much simpler to compute. The normal approximation to the noncentral t-distribution treats each g (The Hedges g nowadays) as if it were normally distributed with mean the effect size (the parameter).

Normally distributed effect size


Form - Prepopulate and hide field with given argument

Question: I have two content types: City and Request.
Request is entity referenced to city.
Now i created a custom themed node /berlin.
On this page i have a button that says "send request", which brings you to the node/add/request form.
The form should now somehow pre-populate the field "field-city" with the previously selected city entity/node.
Additionally the field should be hidden.
Could you guys point me in the right direction?
Answer: There appears to be a dev version of the Prepopulate module for Drupal 7:

The Prepopulate module allows fields in most forms to be pre-populated from the $_REQUEST variable.
For example, the following URL,
http://www.example.com/node/add/blog?edit[title]=this is the title
will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets. For examples on usage for all of these cases, please read the USAGE.txt file that comes with the module or you can read the online handbook page.

So you would just have to craft that button on your City node page to include the additional variable for your city field.
If for whatever reason this doesn't work exactly to your liking, eg, I am not sure if it allows for hiding of the prepopulated field, it would be fairly trivial to craft the functionality in a form_alter() hook in a custom module.
Comment: the plugin indeed helps. now i need to figure out how to hide the field...
Answer: After some more research i came across a module that does exactly what i need!
Prepopulating a entity reference field and hiding the form field.
https://drupal.org/project/entityreference_prepopulate
Answer: The Prepopulate module allows fields in most forms to be pre-populated from the $_REQUEST variable. Maybe you could use that module to fill the city field on the add form.
Answer: You can try Node Reference URL Widget to auto-populates the field form url and its value can't be change later on. For More information go through the documentation of this module.
 For Entity reference use Entityreference prepopulate module.
Comment: this plugin can't handle entity reference.


How to include a pattern for'unknown' for an SVM classifier?

Question: I am doing a classification of heart beat with SVM. There are five kinds of beats in my training data. I plan to add a new kind of data named 'unknown' beat. If there is no unknown beat, one to-be-test beat will always be classified into one of the five beats even though it is far from these five beats. That's why I want to have a sixth beat called 'unknown'. Then I found posterior probability seems to help me with it. But When working into it, I didn't find a good way to deal with posterior probability. Hope some one could give me some hints to solve this problem.
edit:
Actually there are over sixteen kinds of heart beats in all. But there are five main kinds of beats which occupy nearly 90% of all the beats. My work is to classify the heart beats, and if some abnormal beats or some beats related to some disease is found, there beats will be sent to the doctor for further work. The 'unknown' beat is a set of the remaining 11 kinds of beat(except the five main kinds of beats).
Answer: Basically you want to use that sixth class as a junk class, right? Everything that does not look like a heartbeat put it there. I would try to adopt a two stage approach:
(1) One-class SVM to separate beats from non-beats
(2) For all beats patterns, do one-vs-all SVM classifier (or any other multiclass classifier).
By (1) you actually model your class of interest (which are all the five beats classes). This classifier should help you to get rid of those bad patterns. The (2) gets only clean patterns that need to be classified in one of five classes.
Comment: Thanks for your answers. But the unknown beat is still a beat not a junk class. I have complained in more detail in my answer. Just edited. You can take a look.
Comment: @NiuWorld You can try to train a single multi-class classifier. The twist is that the unknown beats are much less common. You should put a higher weight on those class beats in order not to end up with a disbalanced classifier (if your performance measure is classification accuracy). This is one approach.
Comment: Thanks! I will try your idea. But my initial plan is: I was using [LIBSVM](http://www.csie.ntu.edu.tw/~cjlin/libsvm/). Is there some probability when testing the beats? For one to-be-tested beat is classified into 'R' Beat with a probability of "80%". In this way, the to-be-tested beat will be classified into a sixth beats, if its probability is less than 50%. This is my initial idea.
Comment: @NiuWorld SVMs are not very good at estimating probabilities, they are inherently discriminative. You can try to use Platt's normalization of SVM scores: they try to estimate the probabilities from scores. I would suggest to try Logistic Regression instead as it gives the probabilities in a more native way.
Answer: If you don't mind me asking, why use a SVM? why not do something like a multi-class logistic regression (apologies if you have already tried it but thought I should put this in there).
As a tip, this is a scenario very similar to what you use in Natural Language Processing (NLP) so you might think of borrowing a lot of the results developed there. For e.g., \ to classify words in a sentence what you suggested is essentially softwares you do for Proper Nouns (e.g. James). These words either (a) have not occurred in the sentence or (b) are words your machine did not find in a dictionary (so they are put in an `other' bucket)


Django: How to set initial values for a field in an inline model formset?

Question: I have what I think should be a simple problem.  I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user.  In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing request.user.
What I haven't been able to figure out, though, is how to set that user as the default selected value in a select box (ModelChoiceField) containing a list of users.  Can anyone help me with this?
Answer: This does the trick. It works by setting the initial values of all "extra" forms.
formset = MyFormset(instance=myinstance)
user = request.user
for form in formset.forms:
    if 'user' not in form.initial:
        form.initial['user'] = user.pk

Answer: I'm not sure how to handle this in inline formsets, but the following approach will work for normal Forms and ModelForms:
You can't set this as part of the model definition, but you can set it during the form initialization:
def __init__(self, logged_in_user, *args, **kwargs):
    super(self.__class__, self).__init__(*args, **kwargs)
    self.fields['my_user_field'].initial = logged_in_user

...

form = MyForm(request.user)

Comment: Not sure how this would work with the inline formset.  I'm using inlineformset_factory to create my formset and passing it the form class, not an instance.  So I'm not directly instantiating a form object anywhere and don't know how I'd pass it that constructor parameter.
Comment: Hmmm... I believe ModelForms will take the 'default' value, won't they?  And standard form fields use initial as you show, but as far as I know there's no reason to go super() on it.
Comment: This is great! I was looking for a way to send data from the form to the view so that I can send status that will be displayed using the messages framework. In the form I used the initial keyword, and then in the view I did this on validate:

            cur_key_status = form.cleaned_data['key_status']
            messages.success(request, cur_key_status)
Answer: I'm using Rune Kaagaard's idea above, except I noticed that formsets provide an extra_forms property: django.forms.formsets code
@property
def extra_forms(self):
    """Return a list of all the extra forms in this formset."""
    return self.forms[self.initial_form_count():]

So, sticking with the example above:
formset = MyFormset(instance=myinstance)
user = request.user
for form in formset.extra_forms:
    form.initial['user'] = user.pk

Saves having to test any initial forms, just provide default for extra forms.


awk compare columns from two files, impute values of another column

Question: I want to compare the second columns from two files. If there is a match, print the corresponding value of the third column from the second file to the first file. If no match is found, fill with "NA"
File 1

1      rs1    AA    10
1      rs2    DD    20
1      rs3    EE    30
1      rs4    RR    40

File 2

1      rs1    Pascal
1      rs4    Albinoni

Desired output

1      rs1    AA    10    Pascal
1      rs2    DD    20    NA
1      rs3    EE    30    NA
1      rs4    RR    40    Albinoni

I have used this code, but it only output the matches:
awk 'NR==FNR { a[$1]=$2; next} $1 in a {print $0, a[$1]}' File2 File1

Thank you
Comment: http://theunixshell.blogspot.in/2012/12/i-have-two-files-file-1-contains-3.html
Answer: awk 'FNR==NR{a[$2]=$3;next}{print $0,a[$2]?a[$2]:"NA"}' file2 file1

tested below:
> cat temp1
1      rs1    AA    10
1      rs2    DD    20
1      rs3    EE    30
1      rs4    RR    40
> cat temp2
1      rs1    Pascal
1      rs4    Albinoni
> awk 'FNR==NR{a[$2]=$3;next}{print $0,a[$2]?a[$2]:"NA"}' temp2 temp1
1      rs1    AA    10 Pascal
1      rs2    DD    20 NA
1      rs3    EE    30 NA
1      rs4    RR    40 Albinoni
>

Comment: How is determined that the correct index for the array a in this case is $2
Answer: No exactly what you want, but using small tools is always nice. You can use join:
$ join -1 2 -2 2 -a1 file1 file2
rs1 1 AA 10 1 Pascal
rs2 1 DD 20
rs3 1 EE 30
rs4 1 RR 40 1 Albinoni

Explanation:

-1 2: use second field of file1 as join key
-2 2: use seceond field of file2 as join key
-a1: left outer join on file1.
Comment: Join only works if sorted. Sorting can be slow for large files. However, do join -o 1.1,1.2,1.3,1.4,2.3 -e "NA" to achieve the desired output.
Answer: awk 'NR==FNR{a[$2]=$3;next;}{print $0 "    " ($2 in a ? a[$2] : "NA")}' file2 file1

Output:
1      rs1    AA    10    Pascal
1      rs2    DD    20    NA
1      rs3    EE    30    NA
1      rs4    RR    40    Albinoni

Comment: Thank you. It works fine. Could you please explain what " " in the second action part does?
Comment: @user2162153 It appends a space. You could customize your separator with that.
Comment: Another way to put it is: `{printf "%s    %s\n", $0, ($2 in a ? a[$2] : "NA")}`
Comment: Thank you. Is it correct to say that the second condition i.e. `if $2 of the first file exists in array "a"` is written after `" "`?
Comment: After `"   "`, it appends `a[$2]` (which is `$3` of file2) if `$2` of file1 is a key in `a`, or "NA" if not.
Comment: Thank you. Just one more question, could you explain why this code would not work? `awk 'NR==FNR{a[$2]=$3;next;} $2 in a {print $0 "    " ($2 in a ? a[$2] : "NA")}' file2 file1`
Comment: @user2162153 It would only print those with a value from file2 obviously.


Infinite series of Hypergeometric function

Question: Any ideas how to find a closed form for the sum given by:
$$
\sum^\infty_{n=0}
\frac{1}{n!}
\frac{a^n b^{n+m}}{(m+n)^2 \Gamma(m+n)}
{}_2F_2 \left(m+n,m+n;m+n+1,m+n+1;-b\right)
$$
Given that both $a$ and $b$ are positive real numbers, and $m$ is a nonzero positive integer.
Answer: $\sum\limits_{n=0}^\infty\dfrac{1}{n!}\dfrac{a^nb^{n+m}}{(m+n)^2\Gamma(m+n)}{_2F_2}\left(m+n,m+n;m+n+1,m+n+1;-b\right)$
$=\sum\limits_{n=0}^\infty\sum\limits_{k=0}^\infty\dfrac{a^nb^{n+m}\Gamma(m+n)(m+n)_k(m+n)_k(-b)^k}{\Gamma(m+n+1)\Gamma(m+n+1)n!(m+n+1)_k(m+n+1)_kk!}$
$=\sum\limits_{n=0}^\infty\sum\limits_{k=0}^\infty\dfrac{\Gamma(n+k+m)\Gamma(n+k+m)(-1)^ka^nb^{n+k+m}}{\Gamma(n+m)\Gamma(n+k+m+1)\Gamma(n+k+m+1)n!k!}$
$=\sum\limits_{n=0}^\infty\sum\limits_{k=0}^\infty\dfrac{m\Gamma(m+1)(m)_{n+k}(m)_{n+k}(-1)^ka^nb^{n+k+m}}{(m)_n(m+1)_{n+k}(m+1)_{n+k}n!k!}$
$=b^mm!m\mathrm{F}^{2:0;0}_{2:1;0}\Bigg(\begin{matrix}m,m&:&-&;&-&\\m+1,m+1&:&m&;&-&\end{matrix}\Bigg|ab,-b\Bigg)$
Comment: Thanks Harry ... I see you have used Kampé de Fériet.


Android parallax header effect

Question: I want to recreate UI features such as the new G+ app, or the airbnb interface where the parallax effect is invoked solemnly on the header picture.
My app uses (both) ListView and Gridview under different constraints, I was going over @CFlex tutorial for recreating it but couldn't achieve the effect.
Main.axml:
namespace ParallaxTest
{
[Activity(Label = "ParallaxTest", MainLauncher = true, Icon = "@drawable/icon")]
public class ParallaxTest : Activity, AbsListView.IOnScrollListener
{
    int count = 1;

    public GridView _gridView;
    public CustomImageView _imageView;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        _gridView = new GridView(this)
        {
            VerticalFadingEdgeEnabled = false,
            LayoutParameters =
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent,
                    LinearLayout.LayoutParams.MatchParent),
            CacheColorHint = Color.Transparent,
        };
        _gridView.SetOnScrollListener(this);
        _gridView.Adapter = new GridViewAdapter();
        _gridView.VerticalFadingEdgeEnabled = false;
        _gridView.SetColumnWidth(Resources.DisplayMetrics.WidthPixels / 2);
        _gridView.SetNumColumns(2);
        _gridView.SetVerticalSpacing(2);
        _gridView.SetHorizontalSpacing(2);
        _gridView.StretchMode = StretchMode.NoStretch;
        _gridView.SetGravity(GravityFlags.Center);
        _gridView.SetBackgroundColor(Color.Pink);
        _gridView.SetOnScrollListener(this);
        _imageView = new CustomImageView(this)
        {
            LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, 400, GravityFlags.Center)
        };
        _imageView.SetBackgroundColor(Color.White);
        FindViewById<FrameLayout>(Resource.Id.top_picture).AddView(_imageView);
        FindViewById<LinearLayout>(Resource.Id.items).AddView(_gridView);

    }

    public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
    {
        if (visibleItemCount == 0) return;
        if (firstVisibleItem != 0) return;
        _imageView.SetCurrentTranslation(_gridView.GetChildAt(0).Top);
    }

    public void OnScrollStateChanged(AbsListView view, ScrollState scrollState)
    {
        //throw new NotImplementedException();
    }
}

public class CustomImageView : ImageView
{
    protected CustomImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
    {
    }

    public CustomImageView(Context context) : base(context)
    {
    }

    public CustomImageView(Context context, IAttributeSet attrs) : base(context, attrs)
    {
    }

    public CustomImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {
    }

    public int mCurrentTranslation;

    public void SetCurrentTranslation(int currentTranslation) {
        mCurrentTranslation = currentTranslation;
        Invalidate();
    }

    public override void Draw(Canvas canvas)
    {
        canvas.Save();
        canvas.Translate(0, -mCurrentTranslation/2);
        base.Draw(canvas);
        canvas.Restore();
    }

}

}
Main.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#000000"
          android:id="@+id/items">
<FrameLayout
android:id="@+id/top_picture"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#ffffff"/>

The app is running on mono powered by Xamarin's framework.
Any help's appreciated!
Answer: I made an open source library that dose just what you need - https://github.com/nirhart/ParallaxScroll you can see the example here - https://play.google.com/store/apps/details?id=com.nirhart.parallaxscrollexample
Comment: Hello nr hope you are doing well.The scroll_one_parralax is not working if i place a linear layout below an imageview
Answer: I think the easiest way to do parallax with a header is the next:
-Use ObservableScrollView that contains inside an ImageView that is your header image.
-Afterwards, on your java code of the activity that uses this layout, manage the ScrollView behaviour, by implementing ScrollViewCallBacks. And finally, to achieve the parallax effect, use imageView.setTranslation, like next:
scrollView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
        @Override
        public void onScrollChanged(int i, boolean b, boolean b1) {
            imageView.setTranslationY(i*0.5f);
        }

        @Override
        public void onDownMotionEvent() {

        }

        @Override
        public void onUpOrCancelMotionEvent(ScrollState scrollState) {

        }
    });

Pay special attention to  the attribute "i" that is the value of the scrolling movement. And use 0.5f or more to reach the proper effect during scrolling time. Hope it helps

Android parallax header effect


Proof that $\omega^\omega$ is completely metrizable and second countable

Question: I have almost solved the following problem but am stuck at the very end, can you help me finish it? Thank you for your help.

Let $n<\omega$ and $t\in {}^n\omega$. We define $U_t=\{s\in {}^\omega\omega : t\subseteq s\}$. The family
  $\mathcal B=\{U_t : t\in\bigcup {}^n\omega\}$ is a basis for a topology $\tau$ on ${}^\omega\omega$. This means that a set $X$
  is in $\tau$ if and only if $X$ is a union of elements of $\mathcal B$.
EXERCISE 50 (PG): Show that $\langle {}^\omega\omega,\tau \rangle$ is a second countable completely metrizable space. Hint:
  For $r,s\in {}^\omega\omega$ such that $r\ne s$, the $\varrho(r,s)=1/\min\{n : r(n)\ne s(n)\}$. Moreover, let $\varrho(r,r)=0$.
  Show that $\varrho$ is a complete metric on ${}^\omega\omega$ that induces the topology $\tau$.

(i) Second countable: the set of $n$-tuples is countable since it is a finite union of countable sets.
(ii) complete with respect to $$ d(f,g) = \frac{1}{\min \{n \mid f(n) \neq g(n) \}}$$
Let $f_k$ be a Cauchy sequence. This means that the index at which $f_k, f_i$ differ gets larger as $i,k$ get larger. Let $f(n)$ denote the pointwise limit, that is, $\lim_{k \to \infty} f_k(n)$. Then $f(n) \in \omega$ for every $n$ since $f_k(n)$ is eventually constant. Hence $f \in \omega^\omega$.
(iii) $d$ induces the same topolgy as $U_t$:
$\tau_t \subset \tau_d$: Let $s \in U_t$. Then $B(s, \frac{1}{n+1})$ is an open ball contained in $U_t$ hence $U_t$ is open in $\tau_d$.
$\tau_t \supset \tau_d$: Let $B(s, \frac{1}{k})$ be an open balls. If $k < n$, $s \in U_s \subset B(s, \frac{1}{k})$. But if $k \ge n$ then I'm stuck. The ball $B(s, \frac{1}{k})$ consists of all sequences that agree with $s$ on the first $k$ coordinates. So it is quite small. How do I make the $U_t$ small enough to fit in this ball? I have thought of intersection but since I'm only allowed to do finite intersections I don't see what to do.
Comment: The problem in question is from the book Discovering Modern Set Theory: The basics By Winfried Just, Martin Weese, [p.148](http://books.google.sk/books?id=TPvHr7fcvHoC&pg=PA148).
Answer: I'm going to alter the notations a little bit.  In the below I will use $s,t$ to denote finite sequences, and $x,y$ to denote infinite sequences.
Also, note that there is a slight problem with the metric as presented:  If $x , y \in {^\omega}\omega$ are such that $x(0) \neq y(0)$, then according to the formula we must have that $$d ( x , y ) = \frac{1}{\min \{ n : x(n) \neq y(n) \}} = \frac{1}{0},$$ which, as we have all learned, is slightly problematic.  We can fix this by instead defining the metric by $$d ( x , y ) = \frac{1}{\min \{ n +1 : x(n) \neq y(n) \}}$$ when $x \neq y$.

To show that $\tau_t \supseteq \tau_d$ it suffices to show that given any $x \in {^\omega}\omega$ and every $\epsilon > 0$ there is a $s \in {^{< \omega}}\omega$ such that $x \in U_s \subseteq B ( x , \epsilon )$.
Note that given $x \in {^\omega}\omega$ and $\epsilon > 0$ there is an $N$ such that $\frac{1}{N+1} < \epsilon$.  Consider now $s = x \restriction N$.  Given any $y \in U_s$ we know that $y \supseteq s$, and so it must be that $y(n) = s(n) = x(n)$ for all $n < N$.  Therefore either $y = x$ (whence $d(x,y) = 0$) or $\min \{ n : y(n) \neq x(n) \} \geq N$ (whence $d(x,y) \leq \frac{1}{N+1}$); in either case $d ( x , y )  < \epsilon$.  As we clearly have that $x \supseteq s$, then $x \in U_s \subseteq B ( x , \epsilon )$.
Answer: (i) No, $\mathcal B$ is countable because it's the countable union of the countable sets $\mathcal B_n=\{U_t:t\in{^n\omega}\}$.
(ii) I assume that you've verified that $d$ really is a metric. What you've written to show that $\left\langle{^\omega\omega},d\right\rangle$ is complete is rather sloppy, but you have the right idea; let me know if you want me to elaborate.
(iii) Your $\tau_t$ should be simply $\tau$: the name was already given in the problem, and you don't want the name to seem to refer to a specific element of ${^{<\omega}\omega}$. In your argument that $\tau\subseteq\tau_d$ you should say explicitly that $t\in{^n\omega}$ rather than forcing the reader to work this out from what follows:

Let $t\in{^n\omega}$ and $s\in U_t$; then $s\in B_d\left(s,\frac1n\right)\subseteq U_t$, so $U_t\in\tau_d$.

(You don't need $n+1$.)
In fact $U_t=B_d\left(s,\frac1n\right)$, and this observation essentially finishes the proof that the two topologies are equal: if $s\in B_d(t,\epsilon)$, choose $n$ so that $B_d\left(s,\frac1n\right)\subseteq B_d(t,\epsilon)$ and observe that $$B_d\left(s,\frac1n\right)=U_{s\upharpoonright n}\;.$$
Comment: @Matt: That first sentence is just defining the notation $U_t$. It could perhaps better have been written: 'For each $n<\omega$ and $t\in{^n\omega}$ we define $U_t=\ldots~$', and the union should definitely have been indexed: $\bigcup_{n\in\omega}$.
Comment: @Matt: They were careful up at the top when they defined strategies; I don't know why they omitted the indexing of the union in the description of $\mathcal B$, but I suspect that it was either a genuine typo or a simple oversight. You're welcome!
Comment: Regarding (i): Yes. I argue that ${^n}\omega$ is a finite union of countable sets. Therefore $\mathcal B$ is countable. (I agree that I wrote the whole thing a bit sloppily and I admit to not verifying that $d$ is indeed a metric. I know how to do it but what I'm very much after is the second inclusion at the end of the proof.
Comment: @Matt: But $\mathcal B$ is indexed by ${^{<\omega}\omega}=\bigcup_{n\in\omega}{^n\omega}$, so it's the union of countably infinitely many countable sets.
Comment: But in the book $\bigcup \mathcal A$ is used to mean $\bigcup_i A_i$  for some index set $I$ or $\bigcup_{A \in \mathcal A}A$ hence for $n$ fixed, the set $\bigcup {^n}\omega$ should denote the set of all $n$-tuples!
Comment: @Matt: No, ${^n\omega}$ is the set of all $n$-tuples of finite ordinals. Interpreted literally, for a fixed $n$, $\bigcup{^n\omega}$ is the set of elements of $n$-tuples of finite ordinals, something that clearly makes no sense here. The authors were simply careless here and omitted the indexing of the union.
Comment: And what about the paragraph before the exercise: "Let $n < \omega$...". This sounds to me as if $n$ is fixed. I'm quite sure you must be right but it's a bit frustrating that an otherwise so carefully written book suddenly contains something like this.
Comment: [This](http://i.stack.imgur.com/8EHXH.png) is most of page 148. It's a chapter about Axiom of Determinacy, starting on this same page.
Comment: Thank you for your help!  : )


How reliable is neural network in terms of safety issue? Any distribution of output?

Question: I work for auto industry, where the reliability of machine inference is the critical issue becaue of lawsuit all that.
The neural network(NN) is very much popular now, but how about reliability?
They say, it was tested on 1000 tests data. Well that's not enough, how about 10000 or more? What can you say about untested or unseen data?
I don't only mean to raise a lack of data issue, but its black box nature of NN. Gaussian process is,I found "safer" since the output can be derived as some kind of distribution(although that depends on kernel you choose), and at least I know the unseen data will return the similar prediction as the similar seen data would. What about NN? any nice distribution of output? Can I safely assume to get continuous result from NN as input data changes?
Thank you.
Similar topic
How to prove the reliability of a predictive model to executives?
Answer: It is hard to say how a neural network will perform on unseen data. Like you said, a neural network is a black box, but that doesn't always make it unreliable.
For a neural network to really see patterns and just overfitting the data, you need to implement dropout. This prevents overfitting and stimulates the detection of (large) patterns in the dataset.
Secondly, you should implement a test set. This will tell you how well a neural network performs on data that it isn't trained to. So if you have 1000 samples, you use 800 for training and 200 for testing. After training the network with those 800 samples, you test the network on the 200 unseen samples.
Additionally, you could generate some samples: make samples from which you expect a certain output.
But yes, it is hard to predict how the neural network will perform on 10000 other samples. For example, you don't know if those 10000 samples share the same pattern with the small 1000 samples you trained it on.


libvirt - Restart VMs after return from power failure?

Question: Is there any way to make KVM automatically restart any VMs that have been shut down due to power failure? Here is my scenario: I run a small VM tank, mostly with development VMs on it. I now have a VM that is set to autostart on system boot, which works. I have installed apcupsd on that VM, reading from the daemon on the host, and configured to shut down when battery reaches 75%. The host will shut down when the battery reaches 15%. My question is, if power returns during this window (i.e. the host stays up), can I restart the VM that was shut down? I know I could hard-code a call to 'virsh start [VM name]' but I am looking to start any VM flagged as 'autostart', somewhat like doing 'mount -a' to mount all defined filesystems. Is this possible?
Answer: On my RHEL6 and CentOS6 that is established by creating a symbolic link to VM XML description in /etc/libvirt/qemu/autostart/ :
ls -la /etc/libvirt/qemu/autostart/
total 4
drwxr-xr-x. 2 root root 4096 Dec 19  2012 .
drwx------. 4 root root 4096 Dec 21 08:50 ..
lrwxrwxrwx. 1 root root   29 Mar  3  2012 hosting2.xml -> ../hosting2.xml
lrwxrwxrwx. 1 root root   43 May 25  2011 hosting.xml -> /etc/libvirt/qemu/hosting.xml

If you want to avoid setting up links manually: virsh autostart <domain>

autostart [--disable] domain
             Configure a domain to be automatically started at boot.


Upgrade angular-cli from version 1.7.4 to latest 9 in Angular 8 project

Question: After upgrading the cli using the commands below:
npm install --save-dev @angular/cli@latest

ng update @angular/cli --from=1.7.4
--migrate-only --allow-dirty (to convert the angular-cli.json to angular.json)

I am getting the following error:
ERROR in ./app/assets/less/bootstrap/input-groups.less (./node_modules/css-loader?{"sourceMap":true,"minimize":false}!./node_modules/less-loader/dist/cjs.js?{"sourceMap":true,"modifyVars":{"root":"/"~@angular/../../"","styles":"/"~@angular/../../app/assets/less
/""}}!./app/assets/less/bootstrap/input-groups.less)
Module build failed (from ./node_modules/less-loader/dist/cjs.js)

any idea?
Comment: Can you show your config.js file please
Answer: Maybe try upgrading your angular/core ?
ng update @angular/core

Comment: its happening also with cli version 8. the same as the project...


Google Places Autocomplete API key not working on live form & shiny (but works on jsfiddle)

Question: I am trying  to make an html form through google script and have a place field which requires autocomplete api. I tried the same using shiny app and I am getting similar errors.
The code works when tried in jsfiddle but the same when run through live google script url/ shiny app results in an error. "Oops something went wrong".
The error when checked on console is :
"Google Maps JavaScript API error: RefererNotAllowedMapError"
However I have placed no restrictions on the api key (to just make it work atleast once).
API Key Config Settings
I have also enabled billing in the project. (But still obviously plan to run the project on the free credits I have :D)
I have followed the format of code as shown in this tutorial to build the form. https://www.bpwebs.com/how-to-create-data-entry-form-with-google-html-service-and-submit-data-to-google-sheets/ And customized the form to suit my fields.
Any suggestions on what to try out to make it work on the google script url or shiny?
There is unfortunately no google cloud support available to basic users and hence looking for the community to help out here.
Example Code:

    <form name="tutorial-check">

      Select Eatery:
      <input id="locationTextField" type="text" size="50" name = "eateryname">

      Choose Rating:

      <input type='radio' name='rating' value='0'> 0:
      <input type='radio' name='rating' value='1'> 1:
      <input type='radio' name='rating' value='2'> 2:
      <input type='radio' name='rating' value='3'> 3:
      <input type='radio' name='rating' value='4'> 4:
      <input type='radio' name='rating' value='5'> 5:

      <button type="submit">Send</button>

    </form>

Thanks a lot.
Comment: Perhaps you should contact the author.
Comment: Could you please provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)?
Comment: Added. Please check.
Answer: After many weeks of struggles around the api issue, I finally figured the problem and was able to resolve the issue. Posting it for everyone else who might be facing issues due to a similar problem.
So apparently there are different rules for Google Maps platform in India. The google cloud billing account cannot be used for Google Maps Platform usage. And it doesn't error out on the console for us to know that the issue of api's not being able to be used is because of lack of additional billing account to be put for maps apis.
https://developers.google.com/maps/gmp-india-faq
So what needs to be done is, if your project includes only maps apis like mine, then you can disable the existing billing account from the project, set up a new one for maps project and link it with the project.
That should resolve the error of "Google Maps JavaScript API error: RefererNotAllowedMapError".
Maybe this is the not the case for other countries but wherever these new sets of rules are, this is a new additional thing to take care of.


What happens when I try to move files within a remote folder in a windows network?

Question: I am accessing a shared folder on another machine using Windows Explorer. I find that moving a large file in that folder into a sub-folder takes a very long time. Is the file actually being copied to the new location and then deleted from the old one? Or is there another reason why it takes so long?
Note: The same operation on a local folder takes a fraction of a second since a new copy of the file is not created at all. Only the directory entries are modified.
Comment: Dave - clean that up and post it as a new question. It doesn't belong in a comment on an existing (old) question.
Comment: Sorry, more questions! When you move the file does the header info get moved to your local PC and then copied back?? Is that why it takes longer. Ditto if you copy from a remote m/c to the same remote m/c does the data come down the n/w and then go back up or is the n/w more intelligent and just copy the data locally (on the remote m/c)? (I Hope so!)
Answer: When you use a CIFS share, moving a file inside the share should act similar to the local case, except there is something like DFS involved, where the file actually has to be copied on the server from one location to another.
DFS means that you see a single directory tree that could consist of shares on totally different servers. Something similar would be the case if different disks are mounted into a common tree on a Samba server and you move a file from one mount point to another.
Comment: What if I copy a file from one file server to another using Explorer on my local PC?  Does it get copied directly or come via my PC?
Comment: @userSteve: Copied via your PC. There wouldn't be any guarantee that the two servers could even talk to each other directly.
Answer: A file move on a remote share is exactly the same as a local one: Explorer simply instructs the server to move the files/folders into their new destination.  It can also be thought of as a full path rename.  There's no need to copy the files to your local system and back out.
One of the biggest causes of any slowdown is something on your local system holding the file open: Virus scanners, shell extensions (e.g. compression utilities checking .exe files for SFX stubs, image/movie thumbnail generation, getting title/author information from Word Documents, scanning music/movies for tags, etc.), and so on.  Explorer now has to wait for everything to close their open handles on the file before it can finish the file operation, and since many of the things I mentioned involve random small block I/O, SMB latency turns into a much bigger problem than it is on local disks.  It's even worse if you're doing this over a wireless connection.
For an example of how fast it can be, try doing the move from a Command Prompt without Explorer open in your source folder.  The operation will be very quick.
Answer: In most cases - yes, it is being copied across the network first and then deleted from the source when the copy is completed successfully. You can verify this action by disrupting the "move" which typically results in the source being intact and an incomplete copy of the target.
Comment: @user48838: This is nonsense. Moving a file inside a network share (without the special cases noted in my answer) just moves it, it doesn't copies it to the local machine and then back to the new location. If this is indeed is happening on your machine, something is wrong. But I guess you misread the question and are thinking about a move from a local folder to a remote one.
Comment: I've often found files littered in directories when doing network transfers and having them interrupted by something, so I've always suspected some cache-copying behavior from Windows during remote file operations.
Comment: Your right, it should be "In most cases - no" instead.
Answer: Maybe I'm overly cautious, but I would never advise moving files across a network.  Instead, I copy and paste, validate that the sizes match exactly, and then go back and delete them.  I just don't trust the OS to keep up with it well enough (no matter the OS).
Comment: You can't be sure the contents match just by checking the file size, so you need to compute the SHA2 hashes of each copied file. But in all seriousness, if you don't trust the OS with the basic task of moving files, you shouldn't be using a computer.


Regularization strength and problem size

Question: Let's say I run an Ordinary Least Square regression with a Ridge regression on 100.000 points randomly sampled from a huge dataset. The best regularization strength found is C=1.
What is approximately the optimal regularization strength I can expect if I run the same algorithm on 1.000.000 points from the same dataset ?
Are there general rules that link the optimal regularization strength and the problem size ? Do these rules rely on statistical assumptions ? / What is their robustness ?
Thanks
Answer: In general, if you multiply the number of data points, $n$, by $s$ while leaving the number of predictors, $p$, unchanged, then $\|X\beta-y\|_{2}^{2}$ will increase by roughly a factor of $s$, while $\| \beta \|_{2}^{2}$ won't change much.  To keep the same balance between the misfit term and the regularization term, you'll have to increase the regularization parameter by a factor of $s$ (or $\sqrt{s}$ if your regularization parameter is squared in the objective function.)
Although this is a good rule of thumb and a reasonable starting point for searching for a regularization parameter, you generally shouldn't just set the parameter by this rule of thumb.  Rather, you should use whatever method you're using to select the regularization parameter on the larger data set.
Comment: Using more and more points, I can reach the situation where overfitting in negligible. In such a situation the optimal C is small, at least not linear with the problem size.
Comment: Yes- my suggestion was that you don't just scale linearly with the the number of data points.


"Easiest to sound ok" small non-reed woodwinds to learn

Question: Of all the small woodwinds from any culture, which ones are known for having the SHORTEST learning curve (for a veteran of any common woodwind) to achieve clean, controlled tones from 90% of playable notes?
Ok, that may be technically vague. I realize certain instruments (at least in their traditional playing style) depend on lots of textured or warbling tones. But it should be possible to get a rough idea of which ones are the easiest to play tones that are acceptable (i.e. not unnerving earsplitting baby crying).
Answer: Well, "non-reed" eliminates most of the woodwind family, leaving only the flute family.
Recorder is pretty easy.  There's a reason it's the instrument of choice for elementary school music programs.  It takes zero embouchure (mouth position/strength) and almost no air support--you pretty much just blow into it gently and it works.
Other recorder-like instruments are going to be similar, but even less commonly used.
Comment: I would add that the fastest recorder to get to a pleasant sound that won't annoy the neighbors is the alto.  The soprano is physically smaller, but can be a bit shrill in the hands of a beginner.
Comment: I've been told by recorder players that the bigger recorders are easier to get a decent sound out of. It definitely matches my anecdotal experience — I was wretched at the soprano recorder in grade school, had no further experience with woodwinds, and got an alto to sound better the first time I picked it up than the soprano ever did.
Comment: Another possibility that's very similar to recorder might be ocarina.
Answer: Irish whistle (aka pennywhistle aka tin whistle) is not only the easiest to learn, it's also the probably the only musical instrument in the world where you can get a professional level instrument for around US$20.
A great starter site for Irish whistle is Chiff and Fipple.
Comment: In this part of the world (Ireland), they're usually called tin whistles.
Comment: I agree, actually. Instruments like this get a bad rap because people associate them with players who have played for about 10 minutes in their entire life, but it's easy to get a great sound out of one and, hey, only 6 holes to worry about!
Comment: Eluveitie FTW. (I know, that's stupid)
Comment: You all might be interested in the melodica, too. It's probably easier to learn even than a tin whistle, but it is a reeded instrument, as a harmonica is reeded, and isn't as small. They're also fairly inexpensive, but a little higher priced on the low end than whistles. Whistles definitely fit for the desired answer, though.
Answer: I'm going to bet the recorder fits this bill.


Probability to get the HHT sequence for the first time after n coin flip

Question: Consider a coin that has the probability $p$ to give head and $1-p$ to give tail.
I denote $H$ the event Head and $T$ the event Tail.
Let $A_n$ = "At the $n$-th flip, we get for the first time the sequence $HHT$"
and $B_n$ = "At then $n$-th flip, we get the sequence $HHT$" be two events.
Finding a recurrence relation, determine the $\Bbb P(A_n)$.
I cannot find this recurrence relation.
What I tried :
$$
A_{n+3} = B_{n+3}\cap \bigcap_{i=3}^{n+2} \overline {B_i}
$$
but it doesn't give anything interesting...
I don't understand why is it suggested to use $B_n$ too.
Answer: Well maybe you've not seen this formalism yet but here's how I would solve your problem.
Let us introduce the following Markov Chain $(X_n)_{n>0}$ : at each step we follow where we are in the word "$HHT$", that is at $n=0$ set $X_0 = 0$. If the firt coin toss is Tail, then the word $HHT$ has not begun, and $X$ stays to 0. If the first coin toss is $H$ then the word $HHT$ we just have red the first letter of the word $HHT$ and hence go to state 1.
Once in state 1, if we read $T$ then we return to state 0, because we cannot form $HHT$ by starting our word by $HT..$. If we read $H$ we go to state 2. Here is the tricky part now : once in state 2, if we read $H$ we stay in state 2, because it is possible to form $HHT$ starting from $HH$. If we read $T$ of course we go to state 3 and then we kill our particule, because we are only interested in the first time it hits 3. Formally, we are considering the following Markov Chain.
Markov Chain
Now all we have to do is to remark $A_n = \{X_n = 3\} $, and to compute $\mathbb{P}_0(X_n = 3)$, which can be done by classical Markov chain arguments. More precisely, the transition matrix for the Markov chain is :
$$
P =
\begin{pmatrix}
 p & 1-p & 0 & 0 & 0 \\
 p & 0 & 1 - p & 0 & 0 \\
 0 & 0 & p & 1-p & 0 \\
 0 & 0 & 0 & 0 & 1 \\
 0 & 0 & 0 & 0 & 1 \\
\end{pmatrix}
$$
and all we want to do is to compute $P^n(0, 3)$. We could use algebraic arguments to compute $P^n$ but here we will use the Markov property.
\begin{equation}
 \mathbb{P}_0(X_n = 3) = \mathbb{P}_0(X_n = 3 | X_1 = 0) \mathbb{P}_0(X_1= 0) + \mathbb{P}_0(X_n = 3 | X_1 = 1) \mathbb{P}_0(X_1 = 1)
\end{equation}
We denote $p_n(x, y) = \mathbb{P}_x(X_n =y)$. Then after using the Markov property at time $n=1$ this equation becomes :
\begin{equation}
p_n(0, 3) = p_{n-1}(0,3)(1-p) + p_{n-1}(1,3)p
\end{equation}
By similar arguments we obtain :
\begin{equation}
p_{n-1}(1,3) = p_{n-2}(0,3)(1-p) + p_{n-2}(2,3)p  \\
\end{equation}
\begin{equation}
p_{n-2}(2,3) = p_{n-3}(2,3)p + p_{n-3}(3,3)(1-p) \\
\end{equation}
Using $p_{n-3}(3,3) = 0$ for $n \geq 4$ (see our Markov chain description) and putting all things together we get :
$$
p_n(0,3) = p_{n-1}(0,3)(1-p) + p(p_{n-2}(0,3)(1-p) + p^{n-2}(1-p)),
$$
which we solve by induction.
Comment: Thanks for this answer. I just don't understand what the "$x$ index" in $\Bbb P_x$ stands for?
Comment: It means that we start our Markov chain from the point $x$. Actually this whole Markov chain thing is not very important as long as you understand the ideas behind the decomposition of $P_0(X_n = 3)$ : you want to know, knowing that you started from 0, what is the probability to hit 3 at time $n$. First you look at the first step : which one could have it been ? To 0 or to 1 ? Etc... Another expression for $P_x(X_n = y)$ would be $P(X_n = y | X_0 = x)$. Is it more clear ?
Comment: Yeah it is! Thank you very much


sometimes occur errrors dump/restore PostgreSQL

Question: sometimes when i do database dump and restore occur below errors
pg_restore: [archiver (db)] Error during TOC PROCESSING:
pg_restore: [archiver (db)] Error in the item TOC 3569; 2606 4196743 CONSTRAINT uc_xtb_ruleset_key elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "uc_xtb_ruleset_key" failed
DETAILS: The key (name) = (FEL.DATI_RIEPILOGO) is duplicated.
    The command was: ALTER TABLE ONLY xtb_rulesets
    ADD CONSTRAINT uc_xtb_ruleset_key UNIQUE (name); pg_restore: [archiver (db)] Error in the item TOC 3425; 2606 4196747 CONSTRAINT uq_currency_iso elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "uq_currency_iso" failed
DETAILS: The key (iso_code) = (SBD) is duplicated.
    The command was: ALTER TABLE ONLY xtb_currencies
    ADD CONSTRAINT uq_currency_iso UNIQUE (iso_code); pg_restore: [archiver (db)] Error in the item TOC 3418; 2606 4196751 CONSTRAINT xtb_countries_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_countries_pkey" failed
DETAILS: The key (uic_code) = (075) is duplicated.
    The command was: ALTER TABLE ONLY xtb_countries
    ADD CONSTRAINT xtb_countries_pkey PRIMARY KEY (uic_code); pg_restore: [archiver (db)] Error in the item TOC 3420; 2606 4196753 CONSTRAINT xtb_cultures_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_cultures_pkey" failed
DETAILS: The key (culture_id) = (IT) is duplicated.
    The command was: ALTER TABLE ONLY xtb_cultures
    ADD CONSTRAINT xtb_cultures_pkey PRIMARY KEY (culture_id); pg_restore: [archiver (db)] Error in the entry TOC 3427; 2606 4196755 CONSTRAINT xtb_currencies_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_currencies_pkey" failed
DETAILS: The key (uic_code) = (206) is duplicated.
    The command was: ALTER TABLE ONLY xtb_currencies
    ADD CONSTRAINT xtb_currencies_pkey PRIMARY KEY (uic_code); pg_restore: [archiver (db)] Error in item TOC 3447; 2606 4196773 CONSTRAINT xtb_email_resources_pkey elinex
[.....]
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_cultures"
    The command was: ALTER TABLE ONLY xtb_profiles
    ADD CONSTRAINT fk_profile_to_culture FOREIGN KEY (culture_id) REFERENCES xtb_cultures (cult ...
pg_restore: [archiver (db)] Error in the item TOC 3709; 2606 4196955 FK CONSTRAINT fk_users_to_culture elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_cultures"
    The command was: ALTER TABLE ONLY xtb_users
    ADD CONSTRAINT fk_users_to_culture FOREIGN KEY (culture_id) REFERENCES xtb_cultures (culture_i ...
pg_restore: [archiver (db)] Error in the item TOC 3680; 2606 4197020 FK CONSTRAINT fk_xtb_f_role_2_role elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_roles"
    The command was: ALTER TABLE ONLY xtb_function_roles
    ADD CONSTRAINT fk_xtb_f_role_2_role FOREIGN KEY (role_id) REFERENCES xtb_roles (role _...
pg_restore: [archiver (db)] Error in the item TOC 3679; 2606 4197030 FK CONSTRAINT fk_xtb_file_ty_2_folder elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys indicated for the referenced table "xtb_folders"
    The command was: ALTER TABLE ONLY xtb_file_types
    ADD CONSTRAINT fk_xtb_file_ty_2_folder FOREIGN KEY (folder_id) REFERENCES xtb_folders (fo ...
[...]
    WARNING: error ignored during recovery: 24

I do dump from postgreSQL 9.5.6 and i restore dump on PostgreSQL 9.6.11
[xxxxx@xxxx ~]$ pg_dump -V
pg_dump (PostgreSQL) 9.5.6

[xxxx@xxxx ~]# pg_restore -V
pg_restore (PostgreSQL) 9.6.11

below dump command and restore commande executed
DUMP
ssh user@remoteserver "pg_dump --format=c -c --if-exists -O --schema=public --exclude-table-data=xtb_process_runs --exclude-table-data=xtb_app_properties --exclude-table-data=xtb_doc_properties --exclude-table-data=xtb_export_properties --exclude-table-data=xtb_file_storage --exclude-table-data=xtb_import_properties --exclude-table-data=xtb_org_prop_template --exclude-table-data=xtb_org_props --exclude-table-data=xtb_process_properties --exclude-table-data=xtb_rule_functions --exclude-table-data=xtb_rules --exclude-table-data=xtb_templates --exclude-table-data=xtb_trigger_properties --exclude-table-data=xtb_triggers --exclude-table-data=xtb_user_preferences --exclude-table-data=xtb_variables --exclude-table-data=xtb_events -d DATABASE_NAME" > DATABASE_DUMP.dmp

RESTORE
pg_restore --clean --if-exists --no-owner -h localhost -p 5432 -d DATABASE_NAME -U user DATABASE_DUMP.dmp

can yuo help me ?
Comment: did you restore the data into an empty database?
Comment: Yes, i drop and recreate database then i restore dump in the new database.
Answer: Most likely the original database is suffering from corruption. To verify that, try to REINDEX one of these indexes on the original database.
To solve the problem, remove duplicate rows in the table and REINDEX.
Comment: I re-indexed all the indexes affected by error but erros persist on the same indexes.
Comment: Hard to believe. Set `enable_indexscan`, `enable_bitmapscan` and `enable_indexonlyscan` to `off` and check if these duplicate keys are present in the original database. The alternative explanation would be that there were already data in the database to which you restore.


Implements popular keyword in ElasticSearch

Question: I'm using ElasticSearch on AWS EC2.
And i want to implement today's popular keyword function in ES.
there is 3 indexes(place, genre, name), and i want see today's popular keyword in name index only.
I tried to use ES slowlog and logstash. but slowlog save logs every shard's log.
(ex)number of shards : 5 then 5 query log saved.
Is there any good and easy way to implement popular keyword in ES?
Answer: As far as I know, this is not supported by Elasticsearch and you need to build your own custom solution.
Design you mentioned using the slowlog is not good as you mentioned its on per shard basis, even if you do some more computing and able to merge and relate them to a single search at index level, it would not be good, as

you have to change the slow log configuration and for every index there needs to be a different threshold, you can change it to 0ms, to make sure you get all the search queries in slow logs, but that would take a huge disk space and would not be good for Elasticsearch performance.
You have to do some parsing of slow log in your application and if you do it runtime it would be very costly.

I think you can maintain a distributed cache in your application where you store the top searched keyword like the leaderboard of a multi-player gaming app, which is changing very frequently but in your case, you don't even have to update this cache very frequently. I would not go into much implementation details, but simple Hashmap of search term as key and count as value would solve the issue.
Hope this helps. let me know if you have questions.


CSS - Conventions For Selecting Multiple Elements

Question: I have a few CSS commands that change a lot of similar elements but it just looks ugly, I was wondering if there was a better way (conventionally) to select them. All documentation suggests that I am correct so I have turned to the community again.
Code:
.customRadioNPS .generic_radio_1, .customRadioNPS .generic_radio_2{
  background:#33CC66;
  height: 40px;
  width: 40px;
}
.customRadioNPS .generic_radio_3, .customRadioNPS .generic_radio_4, .customRadioNPS     .generic_radio_5, .customRadioNPS .generic_radio_6, .customRadioNPS     .generic_radio_7, .customRadioNPS .generic_radio_8{
  background:#FFFF99;
  height: 40px;
  width: 40px;
}
.customRadioNPS .generic_radio_9,.customRadioNPS  .generic_radio_10{
  background:#FF3333;
  height: 40px;
  width: 40px;
}
.customRadioNPS .generic_roption_1, .customRadioNPS .generic_roption_2{
  background:#33CC66;
}
.customRadioNPS .generic_roption_3, .customRadioNPS .generic_roption_4, customRadioNPS .generic_roption_6, .customRadioNPS .generic_roption_7, .customRadioNPS .generic_roption_8{
  background:#FFFF99;
}
.customRadioNPS .generic_roption_9, .customRadioNPS .generic_roption_10{
  background:#FF3333;
}
.customRadioNPS .generic_roption_5{
  border-right: 2px dashed gray;
  background:#FFFF99;
}

You can see that they are all within the customRadioNPS class but I am not sure if there was a better way so I did not perhaps, have to keep on naming .customRadioNPS?
Answer: You cannot simplify the CSS selectors used as such. But depending on the markup (about which you do not say anything), it may be possible to refer to the same elements using simpler selectors.
For example, if classes like generic_radio_1 are only used, and will only be used, for the specific elements that you wish to refer to, then there is no need to use the selector .customRadioNPS before class selectors like .generic_radio_1 (except in the unlikely case that you have other rules that apply to those elements, too, and you need selectors with higher specificity to override them).
Comment: So in essence, based on my question, the css is correct, thank you. The reason I say nothing about the markup is because I cannot change it without a painful time. I am editing auto generated stuff from a Java core product. So I can only play with the css at present... complicated setup but entirely essential for the level I am at with the technology I use. I just wanted to ensure I am getting the standardisation correct. Many thanks for the speedy response