Posts

Tutorial 10: OpenSSL 1: A simple connection without any security Using BIO

Following programs are basic implementation of BIO library. BIO is a abstraction library used to handle communication of various kinds, including files and sockets, both secure and not.for both secure and unsecure communication . Note: These programs are only for testing purpose and not optimize for production use. there may be some extra lines on code which are not used and still not removed. You will need openssl installed in your server to compile these programs. You can compile these two programs using gcc server.c -lssl -o server gcc client.c -lssl -o client Server: #include <stdio.h> #include <string .h> //for memset #include <openssl/ssl.h> #include <openssl/err.h> #include <openssl/bio.h> #define MAXCHARS 1024 int main(int argc, char *argv[]) { SSL_load_error_strings(); OpenSSL_add_all_algorithms(); char buf[MAXCHARS]; BIO *bio; if((bio = BIO_new_accept("port")) == NU...

Tutorial 9: Node.js common Error 2 : Unknown system errno 114

If you have used sockets in your node.js project,  you might have seen a error Unknown system errno 114 This error occurs because you are trying to use a socket which is already busy with another connection. What caused it? You might have defined the socket globally and calling the functions that use the socket simultaneously. something like var socket1 = new net.Socket(); ... .. exports.func1=function(){ socket1.connect (PORT, HOST, function() {             socket1.end('some command');         }); }; exports.func2=function(){ socket1.connect (PORT, HOST, function() {             socket1.end('some command');         }); }; When you call func1 and func2 simultaneously func2 try to use socket1 which is already busy in func1. Solution: define socket in new function so that if both function gets called simult...

Tutorial 8: Some Selectors for css + jquery

X + Y ul + p {       color :  red ;   }   It will select only the element that is immediately preceded by the former element. X > Y div #contai ner > ul {      border :  1px   solid   black ;   }  will only select direct children. X ~ Y ul ~ p {       color :  red ;   }  Any child with given tag X[href="foo"] a[href= "http://net.tutsplus.com" ] {      color :  #1f6053 ;  /* nettuts green */    }  a[href^= "http" ] {  //start with http a[href$= ".jpg" ] {   //end with jpg X:checked input[type=radio]:checked {       border :  1px   solid   black ;   } target a user interface element that has been ...

Tutorial 7: Javascript: So you want to know attr ids in your page or no. of duplicate ids

open console (F12) It will require jquery. paste var ids = []; $('div[id]').each(function(){ ids.push( this.id ); }); it contains all the ids in your page. To find unique ids just perform following function on result from previous step $.unique(ids)  So now you know how many duplicate ids you have left in your page

Tutorial 6: Summary of HTTP Protocol - Part 1

Default port for http is 80 and for https is 443 Different part of URL:             Protocol ://host:port/ resource_path ? query There are four popular types of verbs Get, Post, (Put, Delete)  others are  head(same as get but without msg body),  trace(to get the time toandfrom server ),  options (to retrieve server capabilities) STATUS CODES 1XX: Informational messages           100 : Expect, continue sending the data 2XX: Successful            200 : OK             202 : Accepted, but there may be no response           204 : No msg body in response           205 : Telling client to reset the content           206 : Partial content 3XX: Redirection           301 : Moved Permanently     ...

Tutorial 5: Some Useful (sample )join queries (specially for monetdb)

select * from (select 'a' as b,'c' as "c") as t1  left join (select 'b' as b,'d' as "d") as t2 using (b); select * from (select 'a' as b,'c' as "c") as t1  left join (select 'a' as b,'d' as "d") as t2 using (b); select * from (select 'a' as b,'c' as "c") as t1 right join (select 'a' as b,'d' as "d") as t2 using(b); select * from (select 'a' as b,'c' as "c") as t1 right join (select 'b' as b,'d' as "d") as t2 using(b); select * from (select 'a' as b,'c' as c) as t1 full join (select 'a' as b,'d' as d) as t2 using (b); select * from (select 'a' as b,'c' as c) as t1 full join (select 'b' as b,'d' as d) as t2 using (b); select * from (select 'a' as b,'c' as "c") as t1 natural full join (se...

Tutorial 4: Node.js - common error 1: contentType and undesired downloading

Image
Many of beginners may face problem where they want to show some content and the file gets downloaded (the browser does not show the content in its window). This problem arises because of not setting the content type of response.  It is advisable to set the content type, If no content type is defined browser try to detect the type of content. If it contain some buffer (or any type that browser is not designed to render)  it tries to download the file. Normally it does not happen as most of the time the file is in html (or other browser/plugin known format like images, videos, text, pdf). A small file demonstrating use and effect of setting content type with node.js: var http = require('http'); /*var server = http.createServer(function (request, response) {   response.writeHead(200, {"Content-Type": "text/plain"});   response.end(" \n"); }); var server = http.createServer(function (request, response) {   response.writeHead(200, {"Cont...