Make ActiveMQ Keeping Data After Install

Standard

Checking config .xml on activeMQ and using persistent=”true”

<broker brokerName="broker" persistent="true" useShutdownHook="false">
   <transportConnectors>
     <transportConnector uri="tcp://localhost:61616"/>
   </transportConnectors>
   <persistenceAdapter>
     <kahaPersistenceAdapter directory="activemq-data" maxDataFileLength="33554432"/>
   </persistenceAdapter>
 </broker>

MongoDB: Mongodump terminate called after throwing an instance of ‘std::runtime_error’

Standard

If you encounter this error:

1
2
3
4
5
connected to: 127.0.0.1
Mon Oct 21 10:49:30.638 DATABASE: soft_production to dump/soft_production
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Aborted

Please add this

1
2
3
export LC_ALL=C
# or
export LC_ALL="en_US.UTF-8"

either in the console (for current session) or in .bashrc file.

After that you should be ready to go with:

1
mongodump --db soft_production

How To Work With JSON In Node.js / JavaScript

Standard

String To JSON Object:

This is very much easier and straight forward as below:

1
2
3
var jsonString = "{\"key\":\"value\"}";
var jsonObj = JSON.parse(jsonString);
console.log(jsonObj.key);

As you can see, we are using the built-in global JSON Object to parse a string which has JSON Data. Also, it might be good idea to use “.trim()” method on the string, if you think there might be some chance of extra space etc in the JSON string. Otherwise, it won’t get parsed and you will face an unexpected error.

Continue reading

404 error when calling REST api (Phalcon)

Standard

XMLHttpRequest cannot load http://ajax.example.com/like/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://blog.example.com' is therefore not allowed access.

Solution:

Set htaccess like this:

# Always set these headers.
Header always setAccess-Control-Allow-Origin"*"
Header always setAccess-Control-Allow-Methods"POST, GET, OPTIONS, DELETE, PUT"
Header always setAccess-Control-Max-Age"1000"
Header always setAccess-Control-Allow-Headers"x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

 

Pasang Swap ubuntu

Standard

Open Terminal 

root@ARJUNA:~# mkdir /var/data
root@ARJUNA:~# dd if=/dev/zero of=/var/data/swap1.swp bs=1024 count=1024000
root@ARJUNA:~# mkswap /var/data/swap1.swp
root@ARJUNA:~# swapon /var/data/swap1.swp
root@ARJUNA:~# htop
root@ARJUNA:~# free

ini sample jika server kita mengalami kehabisan memory dan bisa di akalin dengan cara seperti ini .. 

 

Install Dev-Tools Phalcon

Standard

First:

git clone https://github.com/phalcon/phalcon-devtools.git

Installing via Composer

Install composer in a common location or in your project:

curl -s http://getcomposer.org/installer | php

Create the composer.json file as follows:

{
    "require": {
        "phalcon/devtools": "dev-master"
    }
}

If you are still using Phalcon 1.3.x, create a composer.json with the following instead:

{
    "require": {
        "phalcon/devtools": "1.3.*@dev"
    }
}

Run the composer installer:

php composer.phar install

Create a symbolic link to the phalcon.php script:

ln -s ~/devtools/phalcon.php /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon

How do I change the privileges for MySQL user that is already created?

Standard

To list users:

select user,host from mysql.user;

To show privileges:

show grants for 'user'@'host';

To change privileges, first revoke. Such as:

revoke all privileges on *.* from 'user'@'host';

Then grant the appropriate privileges as desired:

grant SELECT,INSERT,UPDATE,DELETE ON `db`.* TO 'user'@'host';

Table:

GRANTALTER,CREATEON example TO'someuser'@'somehost'

Finally, flush:

flush privileges;

The MySQL documentation is excellent:

http://dev.mysql.com/doc/refman/5.0/en/user-account-management.html

Sample Project mongodb with phalcon Framework

Standard

Selain kemampuannya untuk memetakan tabel dalam database relasional, Phalcon dapat memetakan dokumen dari database NoSQL. ODM menawarkan fungsi CRUD, peristiwa, validasi antara layanan lainnya.

Karena tidak adanya query SQL dan perencana, database NoSQL dapat melihat perbaikan nyata dalam kinerja menggunakan pendekatan Phalcon. Selain itu, tidak ada bangunan SQL mengurangi kemungkinan suntikan SQL.

Untuk terkoneksi dengan mongoDB

Continue reading