Skip to content

Instantly share code, notes, and snippets.

View intruxxer's full-sized avatar

Ali Fahmi intruxxer

  • PT SOLUSI INFOTECH SEMESTA INDONESIA
  • Jakarta
View GitHub Profile
@intruxxer
intruxxer / 0_reuse_code.js
Created October 4, 2013 02:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@intruxxer
intruxxer / wget-crawl
Created November 7, 2013 07:57
Crawling Website & Download All using WGET
wget --mirror -p --convert-links -P [local dir] [url]
$('input[type=text]').val("");
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
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.
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'] = '';
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrf-token']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
});
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
$("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",
sethrefs = function () {
if (document.querySelectorAll) {
var datahrefs = document.querySelectorAll('[data-href]'),
dhcount = datahrefs.length;
while (dhcount-- > 0) {
var ele = datahrefs[dhcount],