Fork me on GitHub

Dynamically generated tweet button and render issues.

Ajax, Tweet, Twitter Yorum yapılmadı »

I searched for a while and cannot find a good solution so i thought that i should write about that.

Twitter’s tweet button in ajax content has render issues. There are some blog posts and forums about that but they didn’t work for me. So i beautified twitter’s widget.js library and found a solution. Just add small piece of code below to the end of your ajax function. That’s all.

window.twttr.widgets.load();

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

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