Posted on Oct 20th, 2009 At 7:06 pm by baldo
Recently I moved to Monterrey Mexico, I met a very nice girl and now I live with her, she is great (and pretty), her friends are great too (hehe, we already got drunk) and also I've met many amazing people at work. It's great when I have many new people in my live, it's a fantastic feeling that is very difficult to describe.
At the time of writing this post, I have no Internet access, I can't believe I been without Internet during the past three weeks, even more, I can't believe I'm survive, hehe!. Literally, I used to have my brain connected to an Access Point (AP), but now I'm learning to live without it. Now I use to do normal things, like listen to music, go to the supermarket, go for a walk, talk with people (of course, not in a chat room). By the way I'm learning to play guitar, it's very difficult and I can't play well, but as they say: "I already win by try".
Well, I hope to enjoy the best of this city and met many interesting people while I'm here.
I'm writing this on October 01 2009, It's a beautiful night, just stop raining and thundering.
UPDATE 1 on Oct 18 2009: Now the enchant is GONE, the hope is GONE and everything seems to be GONE; and I'm starting to hate weekends. This place is really boring, probably this is not my place and I don't belong here...
UPDATE 2 on Nov 10 2009: Brain connected to an Access Point again.
Category: Personal
Posted on Sep 12th, 2009 At 11:14 pm by baldo
Proposition
Let
and
be two vectors in n-dimensional Euclidean space, subject to the condition
, so that both vectors x,y are also in Hamming space.
Hamming space is defined by:

where:
is a set of n-dimensional vectors, each component is a real number 
condition that each component is restricted to the values
Relationship
The Hamming distance has a relationship to the Euclidean distance according to the following formulas:
Euclidean distance
The Euclidean distance (d) between two n-dimensional vectors is given by:
Which can be reduced to:
where:
#dc is the number of components that are different between x and y
Since:

Note: the Hamming distance can be determined according to the prior relationship
Exercises:
1.- Determine the Hamming distance between
, 
2.- Write a C/C++ program to determine the hamming distance between
, 
Category: Math
Posted on Sep 2nd, 2009 At 1:16 am by baldo
Checking if graphics acceleration already enabled
Required package:
* mesa-utls
# glxgears 524 frames in 5.0 seconds = 104.564 FPS 486 frames in 5.1 seconds = 95.546 FPS 540 frames in 5.0 seconds = 107.794 FPS 420 frames in 5.0 seconds = 83.957 FPS 480 frames in 5.1 seconds = 93.990 FPS
You can see the very poor rate of frames per second. It seems direct rendering is not enabled.
# glxinfo | grep direct direct rendering: No (If you want to find out why, try setting LIBGL_DEBUG=verbose) OpenGL renderer string: Mesa GLX Indirect
Enabling graphics acceleration
Required packages:
* xserver-xorg-video-i810
* libgl1-mesa-dri
# glxgears 3374 frames in 5.0 seconds = 674.634 FPS 3499 frames in 5.0 seconds = 699.728 FPS 2674 frames in 5.0 seconds = 534.604 FPS # glxinfo | grep direct direct rendering: Yes
Now, with direct rendering enabled, I get a high rate of frames per second.
Category: Linux
Posted on Aug 25th, 2009 At 12:41 am by baldo
Recently I coded a JQuery version of a feature I've been using in some projects. Basically this feature is a PHP script that queries a MySQL database and displays a list of possible input keywords using AJAX. It is based on the idea of Google suggest.
Here is an example:

Here is the code to accomplish that fancy behaviour.
Note: I´m using the world database, you can download it from the MySql documentation
autocomp.php
1 <?php 2 $USER = "someuser"; 3 $PASS = "somepass"; 4 5 $conn = mysql_connect("localhost", $USER, $PASS); 6 // R�union = Réunion 7 mysql_query("SET NAMES 'utf8'"); 8 mysql_select_db("world",$conn); 9 10 //trim searchKeyword 11 $searchKeyword = trim($_POST["searchKeywordTmp"]); 12 //clean searchKeyword 13 $searchKeyword = mysql_real_escape_string($searchKeyword, $conn); 14 15 if(isset($searchKeyword) && ($searchKeyword)){ 16 $query = "SELECT Name FROM Country"; 17 $query .= " WHERE Name LIKE '$searchKeyword%' LIMIT 5"; 18 if($result = mysql_query($query)){ 19 $flag = 0; 20 while($dataArray = mysql_fetch_array($result)){ 21 $data = $dataArray["Name"]; ?> 22 <li onclick="fill('<?php echo $data; ?>');"> 23 <?php echo $data; ?> 24 </li><?php 25 $flag = 1; 26 } 27 if($flag == 0) 28 echo "Your search keyword is incorrect."; //empty query 29 } else 30 echo mysql_error(); 31 }else echo "ERR"; 32 ?>
suggest.js
1 var flag = 1; 2 3 function suggest(searchKeyword){ 4 //using ajax and jquery for asynchronous update 5 $.post("autocomp.php", {searchKeywordTmp: ""+searchKeyword+""}, 6 function(data){ 7 if(data == "ERR") 8 $("#suggestions").hide(); 9 else{ 10 $("#suggestions").show(); 11 $("#suggestionsList").html(data); 12 } 13 } 14 ); 15 }//end function suggest 16 17 function fill(thisValue) { 18 $("#searchBox").val(thisValue); 19 $("#suggestions").hide(); 20 }//end function fill 21 22 //disable browser' auto-complete 23 function disAutoComplete(obj){ 24 if(flag){ 25 obj.setAttribute("autocomplete","off"); 26 flag = 0; 27 } 28 window.location = "#tc"; 29 obj.focus(); 30 }
suggest.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 6 <link rel='stylesheet' type='text/css' href='style.css' media='screen'/> 7 <script src="js/jquery-1.3.2.js" type="text/javascript"></script> 8 <script src="js/suggest.js" type="text/javascript" ></script> 9 </head> 10 <body> 11 <p> 12 <b> 13 <span id="tc">Type a country name:</span> 14 </b> 15 </p> 16 <input size="30" type="text" id="searchBox" onkeyup="suggest(this.value);" 17 onclick="disAutoComplete(this);" /> 18 <div class="suggestionsBox" id="suggestions" style="display: none;"> 19 <img src="img/upArrow.png" alt="upArrow" 20 style="position: relative; top: -10px; left: 30px" /> 21 <div class="suggestionsList" id="suggestionsList"></div> 22 </div> 23 </body> 24 </html>
Update:
The example has been changed to save resources in the new server, now I use a screenshot.
Posted on Aug 11th, 2009 At 3:16 am by baldo
Prerequisites
Road-Warrior(Host to Net) configuration with OpenVPN
IP forwarding
With IP forwarding you can set your Linux box to act as a router. To enable IP forwarding as root issue the following command.
# echo "1" > /proc/sys/net/ipv4/ip_forward
Note: To enable by default when your system boots up edit the "/etc/sysctl.conf" (on a Debian system).
# Uncomment the next line to enable packet forwarding for IPv4 #net.ipv4.ip_forward=1
Masquerading or packet mangling
Since Internet routers can not forward traffic from private IP addresses you need to invoke IP masquerading. Masquerading is when your Linux system rewrites the IP headers of network packets so the network packet appears to originate from a non-private IP address.
Iptables rules.
This is the set of iptables rules that I use for IP forwarding and packet mangling.
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -i tun+ -j ACCEPT -A FORWARD -i tun+ -j ACCEPT -A FORWARD -o tun+ -j ACCEPT . . *nat :PREROUTING ACCEPT [244:17449] :POSTROUTING ACCEPT [2:486] :OUTPUT ACCEPT [2:486] -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE . . .
Finally in your server configuration file, add the following line and restart the OpenVPN:
push "redirect-gateway def1"
Basically all traffic coming from the internal network(tun0) is forwarded to the Internet through the eth0 interface. Now all the Internet sites I visit record the IP of the OpenVPN server not the IP given by my ISP. One useful application for this configuration is that you can avoid the lack of security on wireless networks, because you connect to the Internet through the VPN.
Older Posts