Aug 15 2010

I’ll be rich as hell

You’re probably grinning at the daring headline right now, thinking something like “you too, bro?”. However, I think that at least I have a good reason for stating such an aim.

Motivation

I want to be totally financially independent. By all means – I want to be able do and have whatever I’d like to and be financially secured in the same time. For instance in case all my stuff with my house got damaged, I’d like to be able to ’survive’ with any lack of comfort or anything. Also, I’d like to have enough money to be able to help people all around me.

My aim more precisely

I want to be able to live on my own at 20 at my own place, with passive income 1000€ every month. (less than 2 years left)

How I’m going to achieve it

I’m going to earn 1000€ as a normal employee in some job. This will be a ’safety amount’ of money which will be always present on my bank account in case I’d like to use it on special occasions. In the moment when the total balance of my account will exceed this amount, I’ll totally stop working as a employee and I’ll focus only on building passive income.

“well, whatever. but why a blog?”

Actually this blog is not meant to be successful as blogs like johnchow.com or problogger. I don’t intend to monetize this site – but I’ll write it anyway. I’ll write it, because  I want to have some kind of log of my ideas, aims and deeds. Last but not least, in a few years I want to link to this blog post and say “this was my beginning”. From this point of view I guess that my biggest influence is podnikanivusa.com, which is a blog written by a Czech who emigrated in the US and now he has successful business.

Why should you subscribe? Because I want to share all the fun which waits for me along my way with all of you; you will have the ability to share with me all the successes and failures, discuss my opinions and ideas, and so.

That’s for today. In next posts I’m going to describe who am I, what have I already done and what is my plan for the future.

… should be fun!


Mar 6 2010

Programming in 2010 or Collatz Conjecture and yUML.me

<?php
$_GET['max'] = (int)$_GET['max'];
if ($_GET['max'] < 2) $_GET['max'] = 2;
$stack = array(array(2,1));
$out = ”;
$i = 2;
while ($i <= $_GET['max'])
{
$c = array_pop($stack);
//insert new candidates to stack
array_unshift($stack,array($c[0]*2,$c[0]));
if ((($c[0]-1)/3) == (int)(($c[0]-1)/3) && fmod(($c[0]-1)/3,2) != 0 && (($c[0]-1)/3) != 1) array_unshift($stack,array(($c[0]-1)/3,$c[0]));
//add current number to results
$out .= “[$c[0]]->[$c[1]], “;
$i++;
}
?>
<img src=”http://yuml.me/diagram/scruffy/class/<?php echo $out; ?>” />

I suppose programming always had its specifics. Older guys tell me how they used to go into rooms with huge computers, or how every algorithm had to be perfect, because that was the only way how it was possible to get the result in acceptable time. I sometimes get amazed how it is possible to (not necessarily only) program something today. I mean sometimes I just want to see a result as soon as possible and I don’t really care about the way I will get it done. This is what I consider as amazing today. :-)

Yesterday, I wasn’t really going to do anything useful, so I checked some sites, including xkcd.com. And there it was.

Wondering what Collatz Conjecture is? As wikipedia states,

The Collatz conjecture is an unsolved conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937. [...]

Take any natural number n (excluding 0). If n is even, halve it (n / 2), otherwise multiply it by 3 and add 1 to obtain 3n + 1. The conjecture is that for all numbers this process converges to 1.

Since it sounds nicely, I wondered whether I could somehow easily create a program, which would print nice graph with given number of numbers which lead to 1. (example, for input 4, it would print graph like 8->4->2->1).

This was the point when I realized, there is a great service called yUML.me. This is meant to be the best way of producing simple UML diagrams for blogs etc., like this one:

So I thought: wouldn’t it be possible to use this service to create diagrams for my program?

It took me few minutes, but in the end I had working piece of code:

<?php
$_GET['max'] = (int)$_GET['max'];
if ($_GET['max'] < 2) $_GET['max'] = 2;

$stack = array(array(2,1));
$out = '';
$i = 2;

while ($i <= $_GET['max'])
{
  $c = array_pop($stack);
  //insert new candidates to stack
  array_unshift($stack,array($c[0]*2,$c[0]));
  if ((($c[0]-1)/3) == (int)(($c[0]-1)/3) && fmod(($c[0]-1)/3,2) != 0 &&
  (($c[0]-1)/3) != 1)
    array_unshift($stack,array(($c[0]-1)/3,$c[0]));
  //add current number to results
  $out .= "[$c[0]]->[$c[1]], ";
  $i++;
}

?>

<img src="http://yuml.me/diagram/scruffy/class/<?php echo $out; ?>" />

You can try it online – here. To adjust the diagram, just edit the ‘max’ value in url.

Isn’t it nice? Such a nice result in few minutes – this is what I tried to write about in the beginning.

However, there are more things I want to mention. I’m aware that the program itself might be improved (for instance by better implementation of a stack since array_unshift is O(n)) but again, I just don’t care, because the result is sufficient, and the speed of the program is not important compared to the speed and capacity limits of yUML.me. Speaking about limits, the highest possible value for which this fusion of local PHP script and yUML.me works, is 272. The generation takes a while, but the result is worth it (almost 1MB png file).

Graph of first 272 numbers which are pointing to number 1Btw, if anyone successfully proves that Collatz Conjecture is really true, give me a call :-) .


Nov 21 2009

Php programmer’s .vimrc

Yes, this article was published in the ‘previous’ version of my blog, which fortunately doesn’t exist by now. However, according to Google Analytics, it was quite popular article, therefore I’m reposting it again. I hope someone’ll find it useful.

If you are using Vim, let mi inspire you with my .vimrc specially configured to help me develop web applications.

Vim editor

Vim editor

" skeleton of the new php document
autocmd BufNewFile  *.php  0r ~/.vim/skeleton.php
" enable the nocompatible mode (vim isn't compatible with vi)
set nocompatible
" line numbers
set nu
" syntax highlighting
syntax on
" nice code
filetype indent on
set autoindent
" search
set ignorecas

" auto save file before other things

set autowrite
" wordwrap
set lbr
" I like highlighted search results
set hlsearch
" Use incremental searching
set incsearch
" ask for confirmation
" The completion dictionary is provided by Rasmus:
" http://lerdorf.com/funclist.txt
set dictionary-=~/.vim/funclist.txt dictionary+=~/.vim/funclist.txt
set complete-=k complete+=k
" change colors
colorscheme delek
" extract http://blog.planetxml.de/uploads/vim-php-manual.tgz to the ~/.vim/doc
set runtimepath+=~/.vim
autocmd BufNewFile,Bufread *.php,*.php3,*.php4 set keywordprg="help"
" update the header everytime
function! RedateHeader()
silent! normal! msHmtgg$%
let lastline = line('.')
if lastline == 1
let lastline = Min(15, line('$'))
endif
silent! execute '1,' . lastline . 's/\m\%(date\|changed\?\|modifi\w\+\):\s\+"\?\zs\%(\a\|\d\|[/, :-]\)*/\=strftime("%d-%b-%Y\ %X")/ie'
silent! execute '1,' . lastline . "g/[Vv]ersion:/normal! $\<C-a>"
silent! normal! 'tzt`s
endf
function! Min(number, ...)
let result = a:number
let index = a:0
while index > 0
let result = (a:{index} > result) ? result : a:{index}
let index = index - 1
endwhile
return result
endf

In my opinion the best feature implemented in this config is that when I have header of php file formatted as shown below:

<?php
/**
* Author: Juraj Masar - www.jurajmasar.com - mail@jurajmasar.com
* Description:
* Version: 0.0.0.2
* Last modified: 28-Dec-2007 03:57:12 PM
*/

Vim updates the datetime in ‘Last modified’ every time the file is saved. Pretty cool, huh?

Well, to be honest, I don’t use Vim anymore. Because Zend Studio Eclipse PDT rules the world :-) But that doesn’t belong to this article.


Nov 9 2009

Solution for Sympal installation problem

Sympal logo

Sympal logo

I guess I am not the only who who got interested in Sympal. Actually, the idea sounds pretty cool, screen casts are hillarious. Where’s the problem then?

I carefully followed every step of the official documentation but even though I got an error (produced by Symfony):

404 | Not Found | sfError404Exception
 Unable to find the <pre>
 Component : Content
 Table : content
 </pre><br> object with the following parameters "array ()").

I think my googling abilities are like really enhanced. Nevertheless, I spent more than 15 mins looking for the right solutions for this nasty bug. Finally, I opened the offical google group and digging through tons of spam I found a discussion I was after.

Basically, the issue is that right after installation is the date_published column in tables content and menu_item set to null for all rows. However, when a http request comes to the server, Sympal wants to return only those rows, which has the date_published column < NOW().

So, everything what has to be done is update of these columns. This can be easily achieved by executing commands in terminal using the symfony’s dql interface.

symfony doctrine:dql " update Content set date_published=NOW(); "
symfony doctrine:dql " update MenuItem set date_published=NOW(); "

Thanks to all guys in that discussion!

Well, this initial problem is solved. What could be added?

If you get interested about Sympal, you will soon notice, that even though everything looks ‘cool’ and more or less ‘new’ there is nothing happening around Sympal at this moment.

Yep, there is even a stupid bug directly on the Sympal presentation – look at the Plugins page. I was wondering, what is happening because it really looked interestingly so it would be shame if the project was closed suddenly. I won’t write anything else, I think this quotation from google groups says everything.

Jonathan Wage (author of Sympal)

I will not abandon it [sympal]. Just not actively developing on it right at this
moment. We’re working on releasing Doctrine 1.2 and Symfony 1.3. Once we
have those stable and released I’ll start to work on a stable version of
Sympal.

- Jon

That’s good news for sure. I’m wondering what will Sympal grow up into. :-) It will be intriguing to watch its further development – maybe even being part of it.