Fork me on GitHub

noSQL Databases and mongoDB installation/quickstart

noSQL, mongoDB Yorum yapılmadı »

noSQL term first introduced by Carlo Strozzi in 1998. It was basically key/value storage system. Concept was old but sharding capabilities were promising. There were a few companies emerged. Google started to develop BigTable in 2004. Amazon, twitter, facebook and some others started to develop and use their noSQL variants as well. Today a lot of companies using that kind of databases.

I would like to add cap diagram below. It’s not related to my post but it’s very useful to see the difference between noSQL databases.

I have used Redis, CouchDB and mongoDB. They are all powerful and great key/value stores. But i guess mongoDB is one step ahead with its sharding, bson, mapreduce and query abilities. Today i would like to tell you about renowned mongoDB’s installation to debian/ubuntu systems. Actually it will be quickstart to mongoDB.

  • You can download latest version from http://www.mongodb.org/downloads and use as is.
  • Or you can install it the aptitude way.

  • I’ll be telling aptitude way in my post. Basically you should open sources list of aptitude, add mongodb source, make it trusted source, update aptitude and install mongodb. To do that follow steps below:

    1. $ sudo vi /etc/apt/sources.list
    2. deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen # Append this line to sources.list if you upstart
      deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen # Append this line to sources.list if you have SysV init scripts
    3. Save file and exit.
    4. $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
    5. $ sudo apt-get update
    6. $ sudo apt-get install mongodb-10gen


    further reading can be found at http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

    You can check your server status from http://localhost:28017 anytime. Do not open the network port to outside. If you want to use commands feature you need to enable rest option. To do that:

    $ sudo vi /etc/mongodb.conf
    rest=true # will be added
    $ sudo service mongodb restart

    When you have finished with the installation without any problem you should see

    mongodb start/running, process ...

    Then you can use commands below to get more information about usage. And also check out the mongoDB pages at http://www.mongodb.org/display/DOCS/Introduction

    $ mongostat # realtime statistics
    $ mongod --version # version information
    $ mongo # mongoDB shell utility. Use -u username -p password for auth
    > help # general help
    > show dbs # show databases
    ...
    > use mydb # use mydb database
    > show collections # show collections
    ...
    > db.help() # database command help

    Have great days with mongoDB…

Upstart rocks!

Chrome OS, Library, Canonical, Google, upstart, NodeJS Yorum yapılmadı »

With Upstart Canonical hit the nail on the head this time. I am so grateful to Canonical for making our life less painful. They made big effort for sure. I guess it was necessity for system admins. Upstart venerable predecessor System-V init has achived well by this time. Today we have simple, powerful and event based initialization system. Google also notified so they used it in Chrome OS.

I’m a web developer for a decade. On the other hand i had to administer ec2 instances for myself a few months ago. So i started to learn and manage linux. Actually it was ubuntu i studied during that time. So thats how its started.

I wanted to write down my opinions about upstart with this entry. There is a simple upstart example and node.js configuration below. You can learn more about it on http://upstart.ubuntu.com/cookbook

Example: your web app needs memcached to be started before apache:
start on starting apache2
stop on stopped apache2
respawn
exec /usr/sbin/memcached

Example: node.js web server that starts automatically and also respawn (restart 10 times in 5 secs) when its crashed.
author "Erhan Gundogan"
description "my node.js web server"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

respawn

chdir /home/username/mysite
exec sudo -u username /usr/local/bin/node app.js >> /var/log/myserver.log 2>$1

javascript types and boolean results

Tips & tricks, javascript, Bilgi ve İpucu Yorum yapılmadı »
typeof undefined undefined
typeof (function(){})() undefined
typeof void(0) undefined
typeof eval(”") undefined
typeof 0 number
typeof -1 number
typeof 0.0 number
typeof Infinity number
typeof NaN number
typeof null object
typeof {} object
typeof [] object
typeof “” string
typeof false boolean
typeof function(){} function
typeof Error function
typeof eval function
typeof Object function
Boolean() false
Boolean(0) false
Boolean(null) false
Boolean(”") false
Boolean(NaN) false
Boolean((function(){})()) false
Boolean(void(0)) false
Boolean(function(){}) true
Boolean(-1) true
Boolean(Infinity) true
Boolean({}) true
Boolean([]) true
Boolean(Error) true

node-validator, javascript xss and encode-decode usage

sanitize, encode/decode, xss, node-validator, NodeJS Yorum yapılmadı »

node-validator xss prevention:
sanitize('<script type="text/javascript"></script>').xss() >>>
[removed][removed]

node-validator entityEncode, javascript encodeURI/encodeURIComponent:
sanitize("<script type='text/javascript'></script>").entityEncode() >>>
<script type='text/javascript'></script>

encodeURI("<script type='text/javascript'></script>") >>>
%3Cscript%20type='text/javascript'%3E%3C/script%3E

encodeURIComponent("<script type='text/javascript'></script>") >>>
%3Cscript%20type%3D'text%2Fjavascript'%3E%3C%2Fscript%3E

node-validator entityDecode, javascript decodeURI/decodeURIComponent:
sanitize("<script type='text/javascript'></script>").entityDecode() >>>
<script type='text/javascript'></script>

decodeURI("%3Cscript%20type='text/javascript'%3E%3C/script%3E") >>>
<script type='text/javascript'></script>

decodeURIComponent("%3Cscript%20type%3D'text%2Fjavascript'%3E%3C%2Fscript%3E")
>>> <script type='text/javascript'></script>

MD5 hash generation and gravatar usage

encryption, profiling, hash, md5, gravatar, Linux Yorum yapılmadı »

You can easily generate md5 hash value. Just open up your terminal screen and type:

echo -n "email" | md5sum

You should type your e-mail address between quotation marks. When you get your email adress’ hash value you may use it in RESTful manner with gravatar domain as below. It will simply produce your registered gravatar image.

http://www.gravatar.com/avatar/HASH

You can read further details here

Debugging NodeJS application with WebStorm

NodeJS, Express, JetBrains, javascript, Debugging, WebStorm, Tutorial, Linux, Ubuntu, Web Tasarım 1 Yorum »

I would like to show you how to debug your nodejs web server applications. I’m using JetBrains’ WebStorm for some time and it’s my favourite web development tool for linux box. It’s 2.1 version. There is a nodejs plugin for debug operation in WebStorm. You can search and install plugin from File->Settings->Plugins window.

settings.jpg

I assume that you have installed nodejs and express already. You can grab nodejs from https://github.com/joyent/node and follow installation instructions. It’s quite easy. Then you can install express with
npm install -d express

There is a “Hello world” application to test our server. Create a new javascript file and name it “app.js”

var app = require('express').createServer();
app.get('/', function(req, res){
res.send('Hello world');
});
app.listen(3000);
console.log('Server started on port 3000');

Click Run->Debug… or press alt+shift+f9 to open debug configuration screen. Click plus icon and then click nodejs option.

debug2.jpg

Give a name to your configuration. Enter your node path (get node path from terminal: which node) and type your app.js file path.

debug3.jpg

Now we are all set for debugging. Hit the debug button or press shift+f9 and you will see “debugger listenin on port …” message in console. You can make breakpoints to debug your application.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Giriş