This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget --mirror -p --convert-links -P [local dir] [url] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input[type=text]').val(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 | |
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list | |
apt-get -y update | |
apt-get -y install mongodb-10gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) In mongo command line: (let say, set administrator) | |
> use admin; | |
> db.addUser('admin','123456'); | |
2) Shutdown Server and exit | |
> db.shutdownServer(); | |
> exit | |
3) Restart Mongod with --auth | |
$ sudo ./mongodb/bin/mongod --auth --dbpath /mnt/db/ | |
4) Run mongo again in 2 ways: | |
i) run mongo first then login. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. enable mod_rewrite: a2enmod rewrite | |
2. overwrite index.php via .htaaccess | |
RewriteEngine on | |
RewriteCond $1 !^(index\.php|public|\.txt) | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)$ index.php?$1 | |
3. $config['index_page'] = 'index.php' -> $config['index_page'] = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ajaxSend(function(e, xhr, options) { | |
var token = $("meta[name='csrf-token']").attr("content"); | |
xhr.setRequestHeader("X-CSRF-Token", token); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Once I was posting a form to server and I am getting the warning of missing authenticity token. | |
Though form_for is adding authenticity_token filed automatically when generating form for object. | |
But if you are not going to use the form_for tag then you can add hidden field with token as a value. | |
Following is the example of adding that field in form. | |
<input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>" /> | |
There is one more helper in Rails which will return you the token value. i.e. form_authenticity_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("someElement").ajaxSend(function(e, xhr, options) { | |
var token = $("meta[name='csrf-token']").attr("content"); | |
xhr.setRequestHeader("X-CSRF-Token", token); | |
}); | |
$("someElement").click(function(){ | |
$.ajax( | |
{ | |
type: "POST", | |
url: "/products", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sethrefs = function () { | |
if (document.querySelectorAll) { | |
var datahrefs = document.querySelectorAll('[data-href]'), | |
dhcount = datahrefs.length; | |
while (dhcount-- > 0) { | |
var ele = datahrefs[dhcount], |
OlderNewer