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];  

martes, 12 de agosto de 2014

Yahoo, worst customer care ever

So I deleted my Yahoo account by mistake and now I have a problem with the BOSS billings. So I go to login and reactivate my account however I cannot since I don't recognize the identity questions (yeah... what?). So then I need to call there customer service number.


After 2 hours on the phone I still cannot get in touch with them. Also there message "due to the large call traffic it may be possible we do not answer your call" is not very encouraging to say something. Do not ever get in this situation since apparently there is no way out. Call their number, hold for 10 minutes. After it they finally let you enter your CS code, I guess they only let persistent clients go through the first filter. Customer care with client filters... this is so wrong. So then you get to hold indefinitely until someone answers (which I haven't had the pleasure of) or you simply get disconnected..

I have had to deal with bad customer care before, but Yahoo's is by far the worst.

lunes, 28 de julio de 2014

Analyzing logs

As I was coding my new server for apartmentsml I redirected all of my server's exceptions to the log file. After a while I remembered about the file and when I decided to check it it was already 30Mb long... So in comes linux tools to view logs. As of now the most useful is

tail -100f /myserver/logs/mylogfile

This command lets you view the log in real time as people hit your server. Well maybe not useful but quite interesting. The most traditional way to view the log is just to

cat /myserver/logs/mylogfile

However when the log is too long you might want to view it with

less /myserver/logs/mylogfile
more /myserver/logs/mylogfile

Well maybe just less since "less is more, and more". This will let you scroll up and down as if it were a read-only vim editor. Remember to exit by pressing 'q'!

If you just want to see the beginning or the end you can also do

tail -10 /myserver/logs/mylogfile
head -10 /myserver/logs/mylogfile

As you can imagine tail gives you the last n (10 in this case) lines and head the n first.
Now this is all fine but how about actually crunching some number on the logs? Imagine you logged for each call to your page the ip address as IP: xxx.xxx.xxx.xxx. So now you want to do some stats about your page. First let's count how many impressions your page has gotten:

cat /myserver/logs/mylogfile | grep -c "IP:"

For this example we used a new command called 'grep' which basically is designed to match lines of text based off on the regular expression you provide. This will then count the number of times 'IP:' occurs in the logs which will be the number of impressions of your webpage. Now more interesting yet let's grab all the unique ip's

cat /myserver/logs/mylogfile | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u

You can now use this ips to track where people are accessing your page from. This regex might seem complicated but it is simple once you understand that '[]' tells which characters to match and '{}' tells how many times these characters will appear. So in principle the regex used will also match 999.999.999.999 which is not correct but I think we can live with it. Finally sort -u sorts your IPs and deletes repetitions. If you do not want to sort them but delete repetitions then you can use uniq.

miércoles, 23 de julio de 2014

Apartment finder

So I decided, after having to look for apartments in the US, that there is no suitable tool to do this. So I wrote my own service which helps you find an apartment by maximizing whatever features you are looking for. Have a look at www.apartmentsml.com and tell me what you think!