miércoles, 25 de marzo de 2015

Some random thoughts

Some life FAQs and my answers:

1- Is there a God?

Up to you. There is no way you can prove either way so it really is waste of time to talk about it.

2- Why are we here?

No one knows. The only thing we do know is that we started of from some cells in some ocean. The cell's objective (and what we call life) was to survive and to reproduce. It seems like life's objective is to control as much energy and matter as possible. But again is up to you.

3- What is consciousness?

And yet again, no one knows. Personally I like a lot Hofstadter ideas as written in his book The Eternal Golden Braid. Mixing self representation with swarm intelligence lets you take a peek into the great mystery that consciousness represents. However I think it goes much deeper than that.
I think that in order for a system to be conscious, the first step is for the system to be able to simulate its environment. Once it can simulate it, then it can represent itself in this new environment.
But that's just the first step. I think life in embedded in the world of ideas, with each idea being in its own turn another living system, fighting for its survival in the brain.  Remember how life struggles to reproduce and control? I think that from the moment humans were able to talk to each other, ideas have been leaping from human to human in there attempt to reproduce and survive. Ideas which behave as if they were alive, trying to control as much space as they can. And so what if consciousness arises from such a setting? What if consciousness is just life occupying the space created by our minds trying to simulate the world?
Conjunctures only, but fun to think about!  By the way, would be a good idea to have an AI system based off of how ideas fight each other to gain "brain time". Maybe it could solve some optimization problems?

martes, 3 de marzo de 2015

Posting some cool sites I've been working on

Hey so I've been programming some webapps. I have been using my own home-cooked webapp framework, but will move maybe to struts for my next project. In the meantime I leave you these jewels:

www.apartmentsml.com
www.tm1consultant.com | www.tm1group.com
mindflow.hostzi.com

martes, 25 de noviembre de 2014

Git checkout all deleted files

So the scenario is I removed a bunch files temporarily or by mistake and now I want them back. Instead of going manually one by one with git status, just run

git status | grep deleted | cut -f5 -d' ' | xargs git checkout

This can be used to do many more things like deal with untracked files and other type of problems.

sábado, 25 de octubre de 2014

Building a dev box under $800

Tired of developing on my gaming laptop virtualizing Ubuntu, I now decided it is time to use my old PC case and build meself a new computer. I went for a decent processor and video card but good RAM and SSD drive. This are my final specs:

CPU: Intel Core i5-4670K 3.4GHz Quad-Core Processor  ($234.99 @ Newegg)
CPU Cooler: Arctic Cooling Freezer 7 Pro Rev.2 45.0 CFM Fluid Dynamic Bearing CPU Cooler  ($17.99 @ Amazon)
Motherboard: Asus Z87-A ATX LGA1150 Motherboard  ($119.98 @ SuperBiiz)
Memory: PNY XLR8 16GB (2 x 8GB) DDR3-1600 Memory  ($134.00 @ Amazon)
Storage: Sandisk Ultra Plus 128GB 2.5" Solid State Drive  ($65.98 @ Newegg)
Storage: Western Digital Caviar Blue 1TB 3.5" 7200RPM Internal Hard Drive  ($54.99 @ Amazon)
Video Card: Gigabyte GeForce GTX 750 1GB Video Card  ($99.99 @ Newegg)
Wireless Network Adapter: Intel 7260HMWDTX1 802.11a/b/g/n/ac PCI-Express x1 Wi-Fi Adapter  ($45.99 @ SuperBiiz)
Total: $773.91
Generated by PCPartPicker 2014-10-25 22:46 EDT-0400

The first thing that gets your attention is the i5. Why not i7? The price difference for the i7 version of the processor is almost $100. What do you get with the i7 4770K? You get 2mb more of L3 cache memory and hyperthreading which bumps up your thread count to 8 even though you are still at quad core. IMO these advantages do not merit $100 so that is why I went with the i5.

Other important things here is the 2x8GB at 1600 for only $134. Since the motherboard has 4 slots, I will still have space to go to 32GB if necessary. 128GB of SSD should be enough for OS pagination (in case 16GB of RAM is not enough for the main bins). The video card is just on the threshold between budget and gaming video cards. It is enough in case you want to do some blender renderings or some steam gaming, but still not as expensive.

Note that it is still missing I/O accessories such as sound card, keyboard, monitor and mouse.

viernes, 24 de octubre de 2014

Last Project Euler for 75

Problem 99 (Python ... painfully slow but easy to code):

maxn = 0;
ind = 1;
with open("base_exp.txt") as f:
     
    for line in f:
        base = int(line.split(",")[0]);
        exp = int(line.split(",")[1]);
        res = base ** exp;
        if(res > maxn):
            maxn = res
            print ind
        ind += 1;

Project Euler 99 en Octave

Esp: Uno facil. Escogi Octave porque queria probarlo. Siempre habia usado Matlab, pero Octave soporta operadores que Matlab no asi que Octave FTW.

Eng An easy one. I chose Octave just to try it out. I had always used Matlab, but since Octave has support for operators that Matlab doesn't I had to try it out. Octave FTW.


 a = 2;  
 for i=1:7830457  
 a *= 2;  
 a = mod(a , 10000000000);  
 end  
 printf("%.0f\n",mod(a* 28433 +1, 10000000000))  

Project Euler 92 in Perl

Esp: Para no olvidar Perl decidi echarme el Project Euler 92 en Perl. Como en el problema solo puedes moverte hacia abajo o a la derecha, el codigo se vuelve mucho mas simple. De otra manera tendria que implementar Dijkstra en matrices en Perl (demasiado para una noche de ocio despues del trabajo...). Pero bueno aqui les dejo mi solucion:

Eng: Trying not to lose my working knowledge of Perl I decided to write this problem using it. The more general solution is where you can move up, down, left and right in which case you must use Dijkstra's algorithm using a matrix as the data structure. However for this particular problem you can only move down or right which makes it a lot easier. The algorithm just traverses the matrix in diagonal strips and adds its upper and left cell:

 use strict;  
 use warnings;  
 $| = 1; #turn autoflush on  
 use Text::CSV;  
 my @data;  # 2D array for CSV data  
 my $file = 'matrix.txt';  
 my $csv = Text::CSV->new;  
 open my $fh, '<', $file or die "Could not open $file: $!";  
 while( my $row = $csv->getline( $fh ) ) {   
   print join(", ", @$row) ."\n";  
   #shift @$row;    # throw away first value  
   push @data, $row;  
 }  
 my $w = scalar @{$data[0]};  
 for (my $slice = 0; $slice < 2 * $w - 1; ++$slice) {  
  my $z = $slice < $w ? 0 : $slice - $w + 1;  
  for (my $j = $z; $j <= $slice - $z; ++$j) {  
   my $x = $j;  
   my $y = $slice - $j;  
   my $val = $data[$x][$y];  
   if($x - 1 <= 0 && $y - 1 >= 0){  
    $val += ($data[$x-1][$y] > $data[$x][$y-1])?$data[$x][$y-1]:$data[$x-1][$y];  
   } else {  
    if($x - 1 >= 0){  
     $val += $data[$x-1][$y];  
    }  
    if($y - 1 >= 0){  
     $val += $data[$x][$y-1];  
    }  
   }  
   print "x: $x, y: $y, data: $data[$x][$y], val: $val\n";  
   $data[$x][$y] = $val;  
  }  
 }  
 for (my $i = 0; $i < $w; $i++){  
  for(my $j = 0; $j < $w; $j++){  
   print $data[$i][$j] ." ";  
  }  
  print "\n";  
 }  
 print "res: " . $data[$w-1][$w-1];