Nodejs: setup your IDE with Sublime Text Editor 2

Thursday, 29 September 2011 22:05 by myro

If you are considering to develop in nodejs, you should really try Sublime Text Editor 2 with the follwing build setup to let you  easly build your node projects.
Sublime Text Editor 2 has a really customizable build system which lets you personalize the way you build your projects.  If you configurate it correctly, you will be able to launch your node,js applications just pressing [Ctrl] + [B]. 

  1. run Sublime Text Editor
  2. Under Tools > Build System > press New Build System...
  3. Paste this:
    {
      "cmd": ["nodeBuild", "$file"],
      "selector" : "source.js",
       "path" : "/home/myoArch/Bin"
    }

    Please note that  /home/myoArch/Bin is just my path where I personally prefere to store my sh scripts. You should use /usr/lib or whatever you want. 
  4. Press [Ctrl] + [S] to save the file and name it Node. This operation creates a new file under: 
    /home/myoArch/.config/sublime-text-2/Packages/User/Node.sublime-build
  5. Create a new file under /home/myoArch/Bin and name it nodeBuild. This is going to be our launcher script.
  6. Open the file with your editor
  7. Paste this:
         #!/bin/sh
         /usr/bin/killall node
         /usr/bin/node $1
    and save the file.
    Please note again that /usr/bin/node is my path where I have installed the node executable. Always use your paths, not mines!
    As you can see, in this script, I always kill all Node istances that are running before launching a new one, In this way  Ican just press [Ctrl] + [B] to re run my application.
  8. At the last point, just make the file runnable: chmod +x nodeBuild

There you go.. Now you can set up your Build System as Node into Sublime Text Editor and run your node application by pressing [Ctrl] + [B].

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   NodeJs
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

How to change HEAD revision to a previous revision in your SVN repository

Tuesday, 27 September 2011 20:43 by myro

Can happen that you have commited something wrong into your Subversion repositoy and you want to set your Head revision to a specific revision. 
The following steps will illustrate how can you change it.

  1. Checkout your repository
    svn checkout http://url
  2. move to your working copy folder
    cd folder
  3. do a reverse merge (i'm reverting to revision 1269)
    svn merge -r HEAD:1269 .
  4. now that youry working copy is set to rv 1269, you need to commit to update the repository
    svn commit -m "set head revision to r 1269"

That's it. Now your head revision will reflect the r 1269.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:  
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

A simple Http File Server written in Node.js 0.4

Wednesday, 23 March 2011 17:50 by myro

A really interesting project that caught my attention lately is Node.js which is an evented I/O based on google's V8 JavaScript engine.
In few hours I have created a really simple http server in Node.js 0.4 which allows you to browse and download any server's file directly from your browser. First of all let's take a look at the code... if you want to run it just copy and paste it into a txt file and name it HttpFileSystem.js

var http = require('http');
var fs = require('fs');

var httpserver = http.createServer(onRequest);
httpserver.listen(8124, "127.0.0.1",serverCreated_callback());

function onRequest(request, response){
    var pureUrl = request.url;
    if (pureUrl == '/favicon.ico')
        return;
    var candidateQS = require('url').parse(request.url)['query'];
    pureUrl = UrlToFsPath(pureUrl);
   
    console.log(pureUrl + ' is requested');
   
    try{
         if (candidateQS != null) {
            // a file is requested
            candidateQS = candidateQS.substr(5,candidateQS.lenght);
            var fileData = fs.readFileSync(candidateQS);
            response.writeHead(200);
            response.write(fileData);
            response.end();
        }
    else {
            var htmlOutput = FormatHtmlFileList(pureUrl);
            response.writeHead(200, {
                'Content-Type': 'text/html'
            });
            response.end(htmlOutput, 'utf8');
        }
       
    }
    catch(error) {
        response.writeHead(404, {
                'Content-Type': 'text/html'
            });
        response.end();
       
    }
   
   
   
}

function serverCreated_callback(){
  console.log('HttpFileSystem Server running at http://127.0.0.1:8124/');
}

function UrlToFsPath(pureUrl){
    if( pureUrl.substr(-1) != "/" ){
        pureUrl += "/";
    }
    return unescape(pureUrl.replace(/\+/g, " "));;     
}

function FormatHtmlTableRow(absolutePath, filename){
     var fileStats = fs.statSync(absolutePath);
     var htmlRow;
     if(fileStats.isFile()){
        htmlRow = "<tr><td>[-]</td><td style='width:300px'><a href='/?file=" + absolutePath + "'>"
        + filename + "</a> </td><td>" + fileStats['ctime'] + "</td><td>"+ fileStats['size'] +"</td>";
     }
     else{
        htmlRow = "<tr><td>[+]</td><td style='width:300px'><a href='" + absolutePath + "'> "
        + filename + "</a> </td><td>" + fileStats['ctime'] + "</td>";
     }
     return htmlRow;
}

function FormatHtmlFileList(pureUrl){
    var htmlOutput = '<h3>Folder: ' + pureUrl + '</h3>';
    htmlOutput +="<a href='"+ pureUrl +"' >Go back</a>";
    htmlOutput +='<table>';
    htmlOutput +="<tr><td> </td><td style='width:300px'> Name </td><td>Create Date</td><td>Size</td>";
    var directories = fs.readdirSync(pureUrl);
    for (var i in directories) {
        var absolutePath =  pureUrl + directories[i]
        htmlOutput += FormatHtmlTableRow(absolutePath, directories[i]);
    }
    htmlOutput +='</table>';
    return htmlOutput;
   
}

After installing Node.js into your computer you can run this code by tiping into your terminal:

myo@debian:~$ ./node HttpFileSystem.js
HttpFileSystem Server running at http://127.0.0.1:8124/
 

And as you can see a message will inform you that an http server is running under your localhost's 8124 port.
Open up you browser and point to http://127.0.0.1:8124/

Now you see what's in your root..

 

...browse directories..  


... view your local images...
 
 
... view text files...
 
 
... and eventually download files...
 
 
Please note that due to actual V8 limitations you cannot download huge files... until V8 fixes this lack
 
 

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   NodeJs
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

Ssh tunnel through Window and Linux with port forwarding and proxy socks

Monday, 13 December 2010 16:06 by myro

 

This is just a reference guide to accomplish a ssh tunnel and I'm assuminig that you already know what a ssh tunnel is. Otherwise take a read at wikipedia: http://en.wikipedia.org/wiki/Tunneling_protocol  and google a little bit :)

Create an ssh server in Windows:

Let's first create a ssh server in windows (I have tested that it works fine with win 7) 

  1. In you window machine download and install FreeSSHd: http://www.freesshd.com/?ctt=download .
  2. Run the executable and install it into your windows computer. Let the installer creates the required keys. (do not install it as a service, because when you will need it, you will run it by yourself.. right?).
  3. Launch the program: start->freesshd->freesshd. after the icon tray appears, right click it and press settings.
    If you experience  problems with the windows UAC, run it as administrator.
  4. Make sure that the ssh server is running under the server status tab.
  5. Click the Tunneling tab and flag as following:
    Allow local port forwarding = yes
    Allow remote port forwarding = yes
  6. Under Users tab, click Add and create a sample user as following:
    Login: test
    Authorization Pasword stored as SHA1 hash
    Password: test
    User can use:
    -SSH = yes
    -Tunneling = yes
  7. Click OK to save and close the window.
To make sure that your SSH server works, download putty  and try to connect. You should connect to localhost at port 22 and when the login is prompted just use username "test" and set the password to "test".

Create an ssh server in Linux:

  1. install openssh-server :)
    if you are using Debian as me, just type apt-get install openssh-server as root
  2. make sure that you can ssh to it with a valid login 

Create the tunnel 

I will describe how to create the tunnel in linux, because my primary laptop is a  Debian box. If you are using windows, there are so many guides over the net... just try to figure out how to do that with Putty.

 Port Fordwards

You will forward all your local request to your ssh server

 ssh user@yourSshServer -L LocalPort:remoteAddressToReach:RemotePortToReach -N

Let's see in details:
 user@yourSshServer : is the user that will be used to connect to the ssh server. If you have created the ssh server in windows, just use test@yourWinIpCompuer

-L    creates the port forwarding
       -LocalPort:RemoteAddressToReach:RemotePortToReach means:
       -LocalPort: you are making the port forwarding from your local port 9999 (localhost:9999)
       -RemoteAddressToReach: the address you want to reach
       -RemotePortToReach: the remote port you want to reach

-N prevents running command through ssh 

So if you want to RDP (Remote Desktop) a server named sampleserver.com you will run:

ssh test@sshServerIp -L 9999:sampleserver.com:3389 -N

Now I can connect and rdp the server using localhost:9999

SOCKS Proxy

Unfortunalty this is not possible if you want to use your ssh server for browsing the web, because most of websites replies on specifics host headers as defined in the http 1.1 protocol.
What you need here is to set up a local socks server which will translate every http request.
 
ssh user@yourSshServer -D localhost:9999 -N 

Let's see in details:
 user@yourSshServer : is the user that will be used to connect to the ssh server. If you have created the ssh server in windows, just use test@yourWinIpCompuer

-D localhost:9999 binds the socks proxy on local port 9999

-N prevents running commands through ssh

Once you have launched this command, open your browser and configure to use the socks proxy.
In firexfox go under Edit -> Preferences -> Network -> Settings:

 
And you are done! 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Linux
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

Debian Squeeze: mount windows share using CIFS

Sunday, 12 December 2010 14:24 by myro

To mount a remote share In Debian Squeeze, make sure that cifs-utils is installed, otherwise you would receive the following error:

 mount: wrong fs type, bad option, bad superblock on //x.x.x.x/share

 to install cifs-utilis, just use apt-get:  apt-get install cifs-utilis.

Now you can mount the share on your local filesystem:
mkdir -p /mnt/yourShare
mount -t cifs //x.x.x.x/share/ -o username=username,password=password /mnt/yourShare 
-o iocharset=utf8,file_mode=0777,dir_mode=0777

If you want to mount this share automatically when your system loads, just add this line to your /etc/fstab file:

//x.x.x.x/share/mnt/yourShare   cifs  credentials=/root/.credentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

As you can see, I'm not writing the credentials directly in fstab file because this file can be viewed by anyone. To store your credentials in /root/.credentials, do:

sudo nano  /root/.credentials

and add the followin text:

username=your_smb_username
password=your_smb_password

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Linux
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed