Wednesday, January 23, 2008

Codes

Who would imagine that a famous soda company produces more than 360million bottles a year for a promotion?

I'm currently working for a e-Bussines Company and yeeeeeees, we are developing this amazing system, that will do what, what's the porpuse? No idea what so ever! They just told us..........."guys you need to develop this promo for this famous soda company". (Ok you guys must be thinking what does the title has to do with the blog, wait i'm getting there). I think the purpose of this is to do something like Facebook, were the users don't win anything at all.

Ok, here's the story of the Famous Soda Company Codes, for this project I was asked to create a program to generate around 360 million codes, 30 million codes per year. Hahahahaha, crazy stuff I know! So yeah, here I go with a previous built of the program done in PHP about a year ago, hahahaha, pretty old! Ooook, let's go back a bit!

This "famous soda company" the biggest client we've worked for! We've done big projects with them such as... (ok, some just told me not to post the name of the company)As long as I can remember team work has been key here! The problem was..........organization, schedules, deadlines. Ok been that said...........let's fwd to present day.

December of 2007, Team Leaders, who shall remain anonymous - came to me and said "Dude, we need to generate 30Million Codes every month", "We need 10million right away". How about that hey? Cracked myself up for awhile and then realized that what he/she said, was for real! (hahahahahaha, I think about it and crack myself up again!) Anyways, I started searching for the old program that did this, for my luck I found it! Couple of things I found out:

  1. It was done in a program that I have (till this day i have no idea how to use it) no idea to use.
  2. It wasn't finished
  3. Oh yeah it crashed everytime I tried to run it!
That's to name a few of the issues! Then I found out that the software was re-done in a lighter version in php, haha! Other problems appeared! Briefly explained algorithm......

  • No 2 letters from the same phone key should be together (e.i AB, AC = 2 in the key pad)
  • Codes most be 7 Digits long
Ok, do the math?! O another thing, no 2 codes could be the same, UNIQUE Codes!!!! Impressive algorithm I must say!. Try this:





Yes, that's part of the code, ACTUAL CODE! Beautiful mind! Ok.....moving on with the post!

About 2 days ago I tried running this huuuge script via web browser, hahahahaha, bad idea, my powerbook's vents were flying!! Oh yeah talk about the TEMP!! Around 82 Degrees! I thought it was going to blow or take-off, hahahahaha.

I worked on the script the day after (yesterday) all day, none stop. Around 3pm I left the script running, and that when I had my episode with MAC OSX's UNIX System . All the time I was running the script I checked with another terminal what was the "size of the file" but not the amount of codes inside the textfile, biiiiiiiiiiiiig mistake. My script was set to go for 500million codes. When I did the ls -la I saw that the file was around 658million, and I thought to myself "the code got stuck and its not stopping!" And I needed 15million ASAP, so I decided to stop it. When I did the split command to have batches of 100million textfiles, but only 1 file was getting outputed. So I went back to the terminal to see the amount of lines in the file the wc -l command return 75million, yeeees! the 658 million that I saw................was the size of the file 658-around 500MB, hahahahaaha!

Last night I left the powerbook on all night, running thru terminal the "script" I fell asleep listening to the vents! When I woke up today i realized that the sound had stopped and I thought to myself, "holy shi...., what if the script caused the machine to crash or what if I ran out of combinations" For my surprise.......the script work beautifully! I have now in my possession 398million Codes. Thinking about it now.............I should've had 500million codes............398millon should work fine!

Soooooo, that's my story with the codes, If anybody needs a script to generate these types of codes, lemme know, I have another another one for numbers! hahahahahahaha!

Laters!



ps. check this out, another experience with the codes!!! I tried to Publish the post and it gave me this error.


ERROR
Your HTML cannot be accepted: Tag is broken:

Thursday, January 17, 2008

Instalar Rails en OSX

Para instalar Rails/Mongrel en OS X se necesita:

0. Prerequisitos
Tener instalado XCode y MySQL


1. PATHs
Crear / Editar el archivo "/etc/profile"
%> vi /etc/profile

Y agregar al final de ese archivo (si no existe):
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"


2. Instalar readline
Descargar he instalar la ultima version. Ejemplo:
%> cd /usr/local/src/
%> sudo curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.1.tar.gz
%> sudo tar xzvf readline-5.1.tar.gz
%> cd readline-5.1
%> sudo ./configure --prefix=/usr/local
%> sudo make
%> sudo make install
%> cd ..


3. Instalar ruby
Descargar he instalar la ultima version. Ejemplo:
%> sudo curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz
%> sudo tar xzvf ruby-1.8.6.tar.gz
%> cd ruby-1.8.6
%> sudo ./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local --enable-shared
%> sudo make
%> sudo make install
%> sudo make install-doc
%> cd ..


4. Probar Instalacion de ruby
Ejecutar:
%> ruby -v

Debe desplegar algo como esto:
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]

Si no despliega algo como lo anterior tiene error. (revisar pasos anteriores)


5. Instalar RubyGems
%> sudo curl -O http://files.rubyforge.mmmultiworks.com/rubygems/rubygems-0.9.2.tgz
%> sudo tar xzvf rubygems-0.9.2.tgz
%> sudo cd rubygems-0.9.2
%> sudo /usr/local/bin/ruby setup.rb
%> cd ..


6. Instalar Rails
%> sudo gem install rails -ry


7. Instalar Mongrel y Mongrel Cluster
%> sudo gem install mongrel -ry
%> sudo gem install mongrel_cluster -ry


8. MySQL Native Binds (opcional)
%> sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql


9. Capistrano / Termios (opcional)
Nota: se requiere que se tenga instalado subversion antes.

%> sudo gem install capistrano -ry
%> sudo gem install termios -ry

Instalar Apache/2.2.6 (Unix) en OS X

Para instalar el Apache 2.2 en OS X se debe seguir los siguientes pasos:

0. Prerequisitos
Tener instalado XCode que viene en el CD de OSX.


1. Descargar el Software
Siempre descargar la ultima version. Ejemplo de descarga:
%> sudo mkdir -p /usr/local/src
%> cd /usr/local/src
%> curl -O http://apache.mirrors.esat.net/httpd/httpd-2.2.6.tar.gz <----Varia de la version que deseen instalar
%> gnutar -xzf httpd-2.2.6.tar.gz <----Varia de la version que deseen instalar
%> cd httpd-2.2.6


2. Configurar Generador de Instalador
%> sudo ./configure --enable-mods-shared=ALL --enable-deflate --enable-proxy --enable-proxy-html --enable-proxy-ftp --enable-proxy-balancer --enable-rewrite --enable-cache --enable-mem-cache --enable-ssl --enable-headers --enable-mod_dav


3. Generar Instalador
%> sudo make


4. Instalarlo
%> sudo make install


5. Configurar Apache
Para configurar el apache:
%> vi /usr/local/apache2/conf/httpd.conf

Es ideal cambiar el User/Group a "www" y el ServerName. Tambien seria ideal habiliar la seccion de WebDav, Default y VirtualHost.


6. Para encender Apache
%> sudo /usr/local/apache2/bin/apachectl start


7. Para apagar Apache

%> sudo /usr/local/apache2/bin/apachectl stop


8. Para revisar configuracion
%> sudo /usr/local/apache2/bin/httpd -S


9. Para revisar los modulos configurados
%> sudo /usr/local/apache2/bin/httpd -l


10. Para que auto arranque en OS X
Se debe utilzar el "Apache2StartupItems.zip" y restaurarlo en "/Library/StartupItems". Y agregar en "/etc/hostconfig" la siguiente linea:

APACHE2=-YES-


11. Hacer links simbolicos
Ingresar a:
%> cd /usr/sbin

Mover:
%> sudo mv apachectl apachectl_1
%> sudo mv apxs apxs_1
%> sudo mv httpd httpd_1

Links:
%> sudo ln -s /usr/local/apache2/bin/apachectl apachectl
%> sudo ln -s /usr/local/apache2/bin/apxs apxs
%> sudo ln -s /usr/local/apache2/bin/httpd httpd

Installing PHP in OSX

Para instalar PHP en OS X, se debe seguir los siguientes pasos:


0. Pre-requisitos
Se supone que se tiene instalado XCode, MySQL y Apache.


1. PATHs
Crear / Editar el archivo "/etc/profile"
%> vi /etc/profile

Y agregar al final de ese archivo (si no existe):
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"


2. MySQL FIX
A la hora de compilar de un problema que no encuentra una libraria. Por lo que hay que hacer un link simbolico.
%> sudo mkdir -p /usr/local/mysql/lib/mysql/
%> cd /usr/local/mysql/lib/mysql/
%> sudo ln -s /usr/local/mysql/lib/libmysqlclient.15.dylib libmysqlclient.15.dylib


3. Descargar PHP
Se recomienda descargar la ultima version de PHP. Ejemplo:
%> sudo mkdir -p /usr/local/src
%> cd /usr/local/src
%> curl -O http://ie2.php.net/distributions/php-5.1.4.tar.gz
%> gnutar -xzf php-5.1.4.tar.gz
%> cd php-5.1.4
%> sudo mkdir -p /usr/local/php


4. Configurar Generador de Instalador
%> sudo ./configure --prefix=/usr/local/php --with-zlib --with-xml --with-ldap=/usr --enable-cli --with-zlib-dir=/usr --enable-exif --enable-ftp --enable-mbstring --enable-soap --enable-mbregex --enable-dbx --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-apxs2=/usr/local/apache2/bin/apxs


5. Generar Instalador
%> sudo make


6. Probar Instalador
%> sudo make test

PD. Si no termina el TEST para eliminar el make ejecutar:
%> sudo make clean


7. Instalarlo
%> sudo make install


8. Configurar Apache
Agrege las siguientes entradas en el archivo de configuracion de apache (/usr/local/apache/conf/httpd.conf):

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.htm index.php


9. Probar Instalacion
En el root del Apache agregar el archivo "info.php" que solo ejecuta la funcion "phpinfo()"