// Util function function addFormatter(input, formatFn) {   let oldValue = input.value;    const handleInput = event =&gt; {     const result = formatFn(input.value, oldValue, event);     if (typeof result === 'string') {       input.value = result;     }      oldValue = input.value;   }    handleInput();   input.addEventListener("input", handleInput); }  // Example implementation // HOF returning regex prefix formatter function regexPrefix(regex, prefix) {   return (newValue, oldValue) =&gt; regex.test(newValue) ? newValue : (newValue ? oldValue : prefix); }  // Apply formatter const input = document.getElementById('user_login'); addFormatter(input, regexPrefix(/mysite-/, 'mysite-'));     I want to use this fiddle to work with a variable instead of text, this is the line:  addFormatter(input, regexPrefix(/mysite-/, 'mysite-'));   As you can see it only allows you to input text after mysite- which is how I want it to work. But I want to be able to use a variable where it says mysite-. Like this:  addFormatter(input, regexPrefix(/$sitetitle/, $sitetitle));   Do you have any idea on how to do this?
I would like to create a String.replaceAll() method in JavaScript and I'm thinking that using a regex would be most terse way to do it.  However, I can't figure out how to pass a variable in to a regex.  I can do this already which will replace all the instances of "B" with "A".  "ABABAB".replace(/B/g, "A");   But I want to do something like this:  String.prototype.replaceAll = function(replaceThis, withThis) {     this.replace(/replaceThis/g, withThis); };   But obviously this will only replace the text "replaceThis"...so how do I pass this variable in to my regex string?
CSS two divs next to each other Passing a variable to sed What does Pokémon Appraisal actually tell you in Pokémon Go? What is an intuitive explanation of the Expectation Maximization technique? How can I verify a Google authentication access token?  I need to somehow query Google and ask: Is [given access token] valid for the [example@example.com] Google account?  Short version: It's clear how an access token supplied through the  can be used to then request data from a range of Google services. It is not clear how to check if a given access token is valid for a given Google account. I'd like to know how.  Long version: I'm developing an API that uses token-based authentication. A token will be returned upon provision of a valid username+password or upon provision of a third-party token from any one of N verifiable services.  One of the third-party services will be Google, allowing a user to authenticate against my service using their Google account. This will later be extended to include Yahoo accounts, trusted OpenID providers and so on.  Schematic example of Google-based access:    The 'API' entity is under my full control. The 'public interface' entity is any web- or desktop-based app. Some public interfaces are under my control, others will not be and others still I may never even know about.  Therefore I cannot trust the token supplied to the API in step 3. This will be supplied along with the corresponding Google account email address.  I need to somehow query Google and ask: Is this access token valid for example@example.com?  In this case, example@example.com is the Google account unique identifier - the email address someone uses to log in to their Google account. This cannot be assumed to be a Gmail address - someone can have a Google account without having a Gmail account.  The Google documentation clearly states how, with an access token, data can be retrieved from a number of Google services. Nothing seems to state how you can check if a given access token is valid in the first place.  Update The token is valid for N Google services. I can't try a token against a Google service as means of verifying it as I won't know which subset of all Google's services a given user actually uses.  Furthermore, I'll never be using the Google authentication access token to access any Google services, merely as a means of verifying a supposed Google user actually is who they say they are. If there is another way of doing this I'm happy to try. How does one get started with web test automation using Selenium? So I've been testing web based analytical software now for the past 4 years or so with mostly manual techniques. But for 2015, I've set myself the goal of getting setup and start writing automated tests and to introduce automated testing into my company.  I've done a little research and it seems that Selenium is quite big when it comes to writing automated tests, but most of the tutorials I've come across reference the Java language.  Some questions:   Is Java the primary language used for Selenium tests?  Do you recommend it over C# ?  Wat is the process of writing test scripts?  Are there Frameworks that I should use that can make the process even easier? Does a non-EU Spouse of a UK national need a visa to visit the Schengen area? I am a British national resident in the UK. My wife is Jordanian, resident in the UK with me. She has a UK biometric residency permit. We were married in the UK and the marriage is registered in the UK.   Does my wife need visas to travel with me on holiday in France and Spain? I understand from EU Directives that she does not. Would we be able to leave the UK by ferry to France if my wife does not have a French visa but can prove that she is married to me and resident in the UK? If visas are necessary but the French or Spanish consulates were NOT to grant the visas, would this be in contravention of EU Directives/Law? If the answer to question 3 is "Yes, it would be unlawful", what action can one take to get the visas? R.Java not generated Merging two xml files in C# without appending and without deleting anything (example given) Is the phrase "it's just a matter of semantics" meaningless? I hear this phrase from time to time, and I really don't know what it means.  Two people are debating, and one says "the difference between your position and mine is just a matter of semantics."   This would seem to me to be quite an important difference.  That is, if one person means one thing, and the other person means something else, then they really do have different positions.  If they said "it is just a matter of terminology" or "just a matter of phrasing" I would get it.  But if someone says "we differ only what we mean" ... it kinda makes me chuckle because it seems to be saying that their meaning is not important, as if the argument was primary and the positions they take a secondary consideration.  So I started looking around for examples of this. I guess it seems that there is a popular notion that semantics is about very fine distinctions, such as:   Another interpretation seems to be that semantics is the difference between two ways of saying the same thing:   Maybe it is just a way of stopping an annoying conversation:   And then there is some usage that I simply don't understand:    And also:   Still, to me it is just a meaningless phrase.  Am I missing an important meaning here? I've been using mac for years, but prefer to do software development on windows. I'm really used to is using the folowing shortcuts on windows very much:  &lt;CTRL&gt;  + INSERT: Copy &lt;SHIFT&gt; + INSERT: Paste &lt;SHIFT&gt; + DELETE: Cut   Of late, I've taken to doing even my development work on the Mac. However, as a matter of habit, I'm missing these shortcuts very much. Actually, I find these a lot more convenient than COMMAND + (C/V/X) combo.  Is there a way to reassign these three shortcuts at least?   I've look all over the internet and in the "Keyboards" system preferences but I did not find anything.  PS: If you're wondering where I find the INSERT keys on a mac book pro, I use a wireless keyboard. I am trying to create a flowchart with Tikz. Since it is a long one, it spans three pages. So after creating a node to stop, I am continuing to the next page using \newpage command. Unfortunately some elements in page 1 are connected to page 2, 3 and vice versa. So when I try to create the arrow connection, it is not possible since the \newpage command comes in between. I am sharing the code with you for info. Could  anyone help me to improve the flowchart so that I could direct the arrows among multiple pages. My sample code is below:  \begin{tikzpicture} \node 1 \node 2 ........ \draw[arrow] (node1)--(node2) \draw[arrow] (node2)--(node3) ---- \end tikzpicture} \newpage \begin{tikzpicture} \node 1 \node 2 ........ \draw[arrow] (node1)--(node2) \draw[arrow] (node2)--(node3) ---- \end tikzpicture} \newpage  \begin{tikzpicture} \node 1 \node 2 ........ \draw[arrow] (node1)--(node2) \draw[arrow] (node2)--(node3) ---- \end tikzpicture} USB is a popular standard and I was wondering whether there is some way to connect two or more computers using USB ports rather than the Ethernet ports. ASP.NET MVC How to pass JSON object from View to Controller as Parameter I have a complex JSON object which is sent to the View without any issues (as shown below) but I cannot work out how Serialize this data back to a .NET object when it is passed back to the controller through an AJAX call. Details of the various parts are below.     var ObjectA = {         "Name": 1,         "Starting": new Date(1221644506800),          "Timeline": [             {                 "StartTime": new Date(1221644506800),                 "GoesFor": 200              }             ,             {                 "StartTime": new Date(1221644506800),                 "GoesFor": 100              }          ]     };   I am not sure how this object can be passed to a Controller Method, I have this method below where the Timelines object mirrors the above JS object using Properties.  public JsonResult Save(Timelines person)   The jQuery I am using is:          var encoded = $.toJSON(SessionSchedule);          $.ajax({             url: "/Timeline/Save",             type: "POST",             dataType: 'json',             data: encoded,             contentType: "application/json; charset=utf-8",             beforeSend: function() { $("#saveStatus").html("Saving").show(); },             success: function(result) {                 alert(result.Result);                 $("#saveStatus").html(result.Result).show();             }         });   I have seen this question which is similar, but not quite the same as I am not using a forms to manipulate the data.   I have also seen references to using a 'JsonFilter' to manually deserialize the JSON, but was wondering if there is a way to do it nativly though ASP.NET MVC? Or what are the best practices for passing data in this way? Is $R^2$ useful or dangerous? I was skimming through  by Cosma Shalizi (in particular, section 2.1.1 of the ), and was reminded that you can get very low $R^2$ even when you have a completely linear model.  To paraphrase Shalizi's example: suppose you have a model $Y = aX + \epsilon$, where $a$ is known. Then $\newcommand{\Var}{\mathrm{Var}}\Var[Y] = a^2 \Var[x] + \Var[\epsilon]$ and the amount of explained variance is $a^2 \Var[X]$, so $R^2 = \frac{a^2 \Var[x]}{a^2 \Var[X] + \Var[\epsilon]}$. This goes to 0 as $\Var[X] \rightarrow 0$ and to 1 as $\Var[X] \rightarrow \infty$.  Conversely, you can get high $R^2$ even when your model is noticeably non-linear. (Anyone have a good example offhand?)  So when is $R^2$ a useful statistic, and when should it be ignored? Diagonal lines in table cell I need this table:    (each row and column should have the same height and length, last cell should be divided by diagonal line). I tried the following code:  \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{array} \usepackage{makecell} \newcolumntype{x}[1]{&gt;{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}} \begin{document} \setlength{\extrarowheight}{0.1cm} \begin{tabular}{|x{0.5cm}|x{0.5cm}|x{0.5cm}|x{0.5cm}|x{0.5cm}|}\hline &amp;&amp;&amp;&amp;20\\ \hline &amp;&amp;&amp;&amp;30\\ \hline &amp;&amp;&amp;&amp;45\\ \hline 15&amp;12&amp;18&amp;50&amp;\diaghead(-3,2){\hskip \hsize}{$a_i$}{$b_j$}\\ \hline \end{tabular} \end{document}   but text in the last cell is displayed incorrectly and cells are not the same.     How can I change that? Let's assume you have a table groups and a table item. Each item belongs to exactly one group. It is an inherent part of that group. An item cannot exist outside of a group and it cannot be moved to another group.  When trying to decide on a primary key for the item table, what should I use?  Should I make up an artificial global serial key like this:  CREATE TABLE items (     item serial PRIMARY KEY,     group integer NOT NULL REFERENCES groups(group), );   ... or should I rather use a composite key and per-group item serial like this:  CREATE TABLE items (     group integer NOT NULL REFERENCES groups(group),     item integer NOT NULL,      PRIMARY KEY(group, item) );   The reason why I'm leaning more towards the second solution is that the post URL will always show the group and item, so it makes sense to have both of them as the composite primary key. In case of the first solution, the URL contains superfluous information because the group ID can already be deduced from the item ID alone. The URL structure is given, however, and cannot be changed.  The disadvantage of the second solution is that you have to manage a per-group serial (i.e. each item integer should start from 0 for each group).  What's better in terms of best practices, normalization and performance? Or is it simply a matter of taste? How prove this inequality $\frac{a}{b+3}+\frac{b}{c+3}+\frac{c}{d+3}+\frac{d}{a+3}\le 1$ Question:  let $a,b,c,d\ge 0$,such $$a^2+b^2+c^2+d^2=4$$ show that $$\dfrac{a}{b+3}+\dfrac{b}{c+3}+\dfrac{c}{d+3}+\dfrac{d}{a+3}\le 1$$  My try: By Cauchy-Schwarz inequality,we have $$\sum_{cyc}\dfrac{a}{b+3}\le\sqrt{(\sum_{cyc}a^2)\left(\sum_{cyc}\dfrac{1}{(b+3)^2}\right)}$$ then we have only prove this $$\sum_{cyc}\dfrac{1}{(a+3)^2}\le \dfrac{1}{4}?$$ This is  not true,in fact, we have $$\sum_{cyc}\dfrac{1}{(a+3)^2}\ge \dfrac{1}{4}?$$ because we have $$\dfrac{1}{(a+3)^2}\ge\dfrac{5-a^2}{64}$$ this is true because $$\Longleftrightarrow \dfrac{(a-1)^2(a^2+8a+19)}{64(a+3)^2}\ge 0$$ so $$\sum_{cyc}\dfrac{1}{(a+3)^2}\ge\sum_{cyc}\dfrac{5-a^2}{64}=\dfrac{1}{4}$$ can see:  This methods is from: can  see:  By the way I have see this three variable inequality  let $a,b,c$ be non-negative numbers such that $$a^2+b^2+c^2=3$$  show that $$\dfrac{a}{b+2}+\dfrac{b}{c+2}+\dfrac{c}{a+2}\le 1$$  proof: By expanding,the inequality becomes $$ab^2+bc^2+ca^2\le abc+2$$ without loss of generality,assume that  $$\min(a,b,c)\le b\max(a,b,c)$$ then \begin{align*} 2-ab^2-bc^2-ca^2+abc&amp;=2-ab^2-b(3-a^2-b^2)-ca^2+abc\\ &amp;=(b^3-3b+2)-a(b^2-ab+ca-bc)\\ &amp;=(b-1)^2(b+2)-a(b-a)(b-c)\ge 0 \end{align*} Equality occurs for $(a,b,c)=(1,1,1)$ and also for $(a,b,c)=(0,1,\sqrt{2})$ or any cyclic permutation.  so my Four-inequality  variable inequality,can use this methods $$\dfrac{a}{b+3}+\dfrac{b}{c+3}+\dfrac{c}{d+3}+\dfrac{d}{a+3}\le 1$$ $$\Longleftrightarrow a^2cd+3a^2c+3a^2d+9a^2+ab^2d+3ab^2+abc^2-abcd+3ac^2+9ac+3b^2d+9b^2+3bc^2+bcd^2+3bd^2+9bd+9c^2+3cd^2+9d^2-81\le 0$$ $$\Longleftrightarrow a^2cd+3a^2c+3a^2d+ab^2d+3ab^2+abc^2+3ac^2+9ac+3b^2d+3bc^2+bcd^2+3bd^2+9bd+3cd^2\le 45$$ $$\Longleftrightarrow a^2(cd+3c+3d)+ab^2d+3ab^2+abc^2+3ac^2+9ac+3b^2d+3bc^2+bcd^2+3bd^2+9bd+3cd^2\le 45$$ $$\Longleftrightarrow (4-b^2-c^2-d^2)(cd+3c+3d)+ab^2d+3ab^2+abc^2+3ac^2+9ac+3b^2d+3bc^2+bcd^2+3bd^2+9bd+3cd^2\le 45$$  Then  I can't  Thank you  very  much I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code? I am trying to create a beamer animation using tikz, but I can't even get basic rotating of a tikz image working as desired.  I have a rectangle specified by  \draw[rounded corners,dotted] (-3.5,0) rectangle (-0.5,2);   I would like to rotate this rectangle about the point (-1,.5) (which is near the bottom right corner of the rectangle).  I've tried:  {\rotatebox[origin=c,x=-1,y=.5]{130}{             \draw[rounded corners,dotted] (-3.5,0) rectangle (-0.5,2);}}   But this produces an error.  If I just use the origin=c option, it compiles, but it rotates the rectangle about the point (0,0).  I've also tried it with just the x=-1,y=.5 (without the origin option), and it fails to compile.  I have searched the documentation, which is where I learned about the options x=xdim and y=ydim.  However, I can't find a single example demonstrating how these options should be used.  Any suggestions would be greatly appreciated.    Also, if there is a better command for rotating things that will be more suitable for use in a beamer animation, please let me know.  Thanks!