Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Use jQuery's beforeSend callback to add an HTTP header with the authentication information:
***
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
},
***
3 years ago
I have two functions:
***
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}

function setCaretToPos (input, pos) {
setSelectionRange(input, pos, pos);
}
***
Then you can use setCaretToPos like this:
***
setCaretToPos(document.getElementById("YOURINPUT"), 4);
***
3 years ago
To set up on ready:
***
$(function() {
$("img")
.mouseover(function() {
var src = $(this).attr("src").match(/[^\.]+/) + "over.gif";
$(this).attr("src", src);
})
.mouseout(function() {
var src = $(this).attr("src").replace("over.gif", ".gif");
$(this).attr("src", src);
});
});
***
For those that use url image sources:
***
$(function() {
$("img")
.mouseover(function() {
var src = $(this).attr("src");
var regex = /_normal.svg/gi;
src = this.src.replace(regex,'_rollover.svg');
$(this).attr("src", src);

})
.mouseout(function() {
var src = $(this).attr("src");
var regex = /_rollover.svg/gi;
src = this.src.replace(regex,'_normal.svg');
$(this).attr("src", src);

});
});
***
3 years ago
It should just be
***
$('#someDiv').height();
***
with jQuery. This retrieves the height of the first item in the wrapped set as a number.

Trying to use
***
.style.height
***
only works if you have set the property in the first place. Not very useful!
3 years ago
Create a form, use the POST method, submit the form - there's no need for an iframe. When the server page responds to the request, write a response header for the mime type of the file, and it will present a download dialog - I've done this a number of times.

You want content-type of application/download - just search for how to provide a download for whatever language you're using.
3 years ago
The Underscore library also provides a "delay" function:
***
_.delay(function(msg) { console.log(msg); }, 5000, 'Hello');
***
3 years ago
ease
Equal to cubic-bezier(0.25, 0.1, 0.25, 1.0), the default value, increases in velocity towards the middle of the transition, slowing back down at the end.

linear
Equal to cubic-bezier(0.0, 0.0, 1.0, 1.0), transitions at an even speed.

ease-in
Equal to cubic-bezier(0.42, 0, 1.0, 1.0), starts off slowly, with the transition speed increasing until complete.

ease-out
Equal to cubic-bezier(0, 0, 0.58, 1.0), starts transitioning quickly, slowing down the transition continues. •

ease-in-out
Equal to cubic-bezier(0.42, 0, 0.58, 1.0), starts transitioning slowly, speeds up, and then slows down again.

cubic-bezier(p1, p2, p3, p4)
An author defined cubic-Bezier curve, where the p1 and p3 values must be in the range of 0 to 1.

steps( n, )
Displays the transition along n stops along the transition, displaying each stop for equal lengths of time. For example, if n is 5, there are 5 steps. Whether the transition holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the transition, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following jump terms is used:
jump-start
Denotes a left-continuous function, so that the first jump happens when the transition begins;
jump-end
Denotes a right-continuous function, so that the last jump happens when the animation ends;
jump-none
There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration
jump-both
Includes pauses at both the 0% and 100% marks, effectively adding a step during the transition time.
start
Same as jump-start.
end
Same as jump-end.
step-start
Equal to steps(1, jump-start)
step-end
Equal to steps(1, jump-end)
3 years ago
sudo usermod -a -G sudo
3 years ago
Use n module from npm in order to upgrade node
***
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
***
To upgrade to latest version (and not current stable) version, you can use
***
sudo n latest
***
Fix PATH:
***
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
***
To undo:
***
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
***
You may need to restart your terminal to see the updated node version.
3 years ago
Two things to check (assuming your machine is called my-machine, you can change this as appropriate):

That the /etc/hostname file contains just the name of the machine.

That /etc/hosts has an entry for localhost. It should have something like:
***
127.0.0.1 localhost.localdomain localhost
127.0.1.1 my-machine
***
If either of these files aren't correct (since you can't sudo), you may have to reboot the machine into recovery mode and make the modifications, then reboot to your usual environment.
3 years ago
Edit .bashrc in your home directory and add the following line:
***
export PATH="/path/to/dir:$PATH"
***
You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type
***
$ source ~/.bashrc
***
3 years ago
***
sed -i 's/original/new/g' file.txt
***
Explanation:

sed = Stream EDitor
-i = in-place (i.e. save back to the original file)
The command string:

s = the substitute command
original = a regular expression describing the word to replace (or just the word itself)
new = the text to replace it with
g = global (i.e. replace all and not just the first occurrence)
file.txt = the file name
3 years ago