Friday, December 24, 2010

You gotta grow bigger ballz

I had a few interesting conversations with a few very smart people the past few days and it came to me that I've never posted about an very interesting thing -- some people are afraid to ask some questions because they don't want to be categorized as stupid people or dumb as f**k, etc. -- now I'm pretty sure that some of you out there fall into this category, don't be shy we all been there.

Let's analyze a simple scenario: you are(or someone is) assigned to a new project(either in a company or as a independent contractor) there's a big chance that some parts of the project are harder to understand at first, however some people prefer not to ask 2, 3 or more times if they didn't get it the first time -- HUGE MISTAKE!! why is that a huge mistake?! well there is also a fat chance that you will waste time trying to figure some parts out and you might as well fail to deliver on time(happened to almost any person out there or will happen), however if you had ask the manager/client(s) for more details or simply say "I don't understand this and/or that" you could have win a lot of time and also gain trust(there are quite a few people that do appreciate when others admit that they've lost track of the conversation or something isn't clear -- why? because they can see on the spot that you are truly interested in doing a good job!) -- we all know that time is our biggest enemy(for example a day in my life should have at least 30 hours -- same for my clients, cheers!!).

The above example can be applied anywhere, from factory work to software development to rocket science, you name it...

Now I can see some managers going: some of my people always say "I got this", "I understand", "no need for more details", etc. but they actually don't... well yes, some people needs to be pushed from behind a bit, others can grow some balls over time and say "I haven't been concentrating enough to understand" or "sorry I've lost you at X point in the conversation, can you repeat the last part?" -- but these people are few, I won't make up bullshit percentage, I'm just talking from my past and present experience with people, however I can tell you that the number of people who are afraid to ask or simply don't give a damn is pretty big, maybe too big, but as one of my closest friend and client says
It is what it is, we just got to deal with it...
I would recommend spending some time with this people(coworkers, friends, family) and help them bypass their issues in order to get the best out of them, do NOT under any circumstances call them names just because he/she didn't get something the first, second or even third time, there are a lot of reasons why he/she lost focus:
- personal problems -- most often
- was concentrating on a personal project -- rarely
- something distracted the attention along the conversation -- very often, we are surrounded by a lot of gadgets and blinking LED's that it's pretty easy to lose focus
- etc. you get the point...

I believe the keywords are: "take responsibility" and "have the guts to ask" try to master these two, only good things can come to you.

I also want to cover in a few words the "my boss/manager is an idiot, asks only dumb questions, etc., I don't get why he/she is a boss/manager and I'm just a employee" -- well, I can tell you that they grew some balls over time and as a friend of mine says "they grew thicker skin", if you want to succeed, you really must take everything as it is and step by step get to the end goal.

If you're reading this before January 1st 2011 you really need to get a break, spend some time with your family!!

Merry Christmas and a happy new year to all you coders out there!!

Wednesday, December 22, 2010

Dynamic web pages with DWScript and IdHTTPServer

I've finally found some time in my busy schedule to write a new post, this post is about generating dynamic web pages using DWScript( -- if you find DWScript useful please do not hesitate to donate to Eric, he is doing a wonderful job with DWScript) as script interpreter and IdHTTPServer as HTTP server.
But first let's understand the difference between static and dynamic web pages:
1. Static web pages:
- static web pages are just plain HTML files which will be manually updated by the developer or website owner whenever he wants;
Here's a drawing of the process that takes place in the case of static web pages

2. Dynamic web pages:
- dynamic web pages are similar to static HTML files, however this HTML files also contain script which is interpreted by a script interpreter which can be almost any script interpreter out there, i.e. perl, php, python, ruby, etc. for this example I've used DWScript;
Here's a drawing of the process that takes place in the case of dynamic web pages

as you can see the noticeable difference between static and dynamic web pages is the script interpreter which comes into play just before serving the HTML to the client.

In this post I won't cover the benefits of using dynamic web pages and the possible exploits.

For this post I've modified the HTTP server which I've created for a video tutorial, so here's the updated source of the uClientContext.pas file:
unit uClientContext;



  TClientContext = class(TIdServerContext)
    FLogStrings: TStrings;
    procedure Log(const s: string);
    procedure HandleRequest(ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
    procedure ServeHTMLFile(const AFileName: string;
      ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
    property LogStrings: TStrings read FLogStrings write FLogStrings;


  WebDir: string;

{ TClientContext }

procedure TClientContext.HandleRequest(ARequestInfo: TIdHTTPRequestInfo;
  AResponseInfo: TIdHTTPResponseInfo);
  SERROR_404 = 'Error 404 page not found "%s"';
  LLocation: string;
    LLocation := ARequestInfo.Document;
    if LLocation <> EmptyStr then begin
      if (LLocation = '/') or (LLocation = '/*') or SameText(LLocation, '/index.html') then
        ServeHTMLFile(WebDir + 'index.html', ARequestInfo, AResponseInfo)
      else begin
        LLocation := WebDir + Copy(LLocation, 2, MaxInt);
        if NOT SameText(ExtractFileExt(LLocation), '.html') then
          LLocation := LLocation + '.html';
        if FileExists(LLocation) then
          ServeHTMLFile(LLocation, ARequestInfo, AResponseInfo)
          AResponseInfo.ContentText := Format(SERROR_404, [LLocation]);
    end else
      AResponseInfo.ContentText := Format(SERROR_404, [LLocation]);
    on E: Exception do
      Log('Exception occured from IP ' + Connection.Socket.Binding.PeerIP +
        sLineBreak + E.Message);
  end; // trye

procedure TClientContext.ServeHTMLFile(const AFileName: string;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  LHTMLFile: TStringList;
  LScript: TDelphiWebScript;
  LHTMLFilter: TdwsHtmlFilter;
  LClasses: TdwsClassesLib;
  LProgram: TdwsProgram;
  LScript := TDelphiWebScript.Create(NIL);
  LClasses := TdwsClassesLib.Create(NIL);
  LHTMLFilter := TdwsHtmlFilter.Create(NIL);
  LScript.Config.Filter := LHTMLFilter;
  LHTMLFile := TStringList.Create;
    LClasses.Script := LScript;
    LProgram := LScript.Compile(LHTMLFile.Text);
      if NOT LProgram.Msgs.HasErrors then begin
        AResponseInfo.ContentText := (LProgram.Result as TdwsDefaultResult).Text;
      end else
        AResponseInfo.ContentText := LProgram.Msgs.AsInfo
    end; // tryf
  end; // tryf

procedure TClientContext.Log(const s: string);
  if Assigned(FLogStrings) then

  WebDir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + 'www');

as you can see the source code is pretty similar to the initial code, just that I've added a new method called ServeHTMLFile -- this method is called only if the requested HTML file is found in the www directory.
Technique: we don't create the interpreter instance unless the requested file is found in the www directory -- the reason is pretty obvious, we try to avoid memory allocation if it's not necessary, we could also improve the efficiency by caching the files in memory in order to serve them faster(RAM IO is faster than disk IO therefore this will give a significant speed improvement when server has thousands requests per second) however this will be covered in a future post hopefully.
In order to provide a proof of concept I've created a fairly simple "website" which has 3 buttons, each button redirects the client to a new web page:
index.html file
    Hello world!!<BR>
    <BUTTON ONCLICK="window.location.href='/primes100.html'">show me primes up to 100</BUTTON> <BR>
    <BUTTON ONCLICK="window.location.href='/primes200.html'">show me primes up to 200</BUTTON> <BR>
    <BUTTON ONCLICK="window.location.href='/primes300.html'">show me primes up to 300</BUTTON> <BR>            
very simple, right?
we also have a file in which we have a method which checks if a number is prime, this file is also located in www directory
function IsPrime(Value: integer): boolean;
  Index: Integer;
  Result := False;
  if Value <= 0 then
  for Index := 2 to Round(Sqrt(Value)) do
    if (Value mod Index) = 0 then
  Result := True;
here are the other 3 HTML files primes100.html
      {$I ''}
        Index: Integer;
      for Index := 1 to 100 do
        if IsPrime(Index) then
          Send('<BR>' + IntToStr(Index)); 
      {$I ''}
        Index: Integer;
      for Index := 1 to 200 do
        if IsPrime(Index) then
          Send('<BR>' + IntToStr(Index)); 
      {$I ''}
        Index: Integer;
      for Index := 1 to 300 do
        if IsPrime(Index) then
          Send('<BR>' + IntToStr(Index)); 
Now, this is an extremely simple example, but as you can see it can be used as a template for a real hardcore web server. Unfortunately I don't have enough time these days for more in depth details, but you can download binary + source code or just the source code and enjoy the power and simplicity of DWScript.
The application is created in Delphi 2010.

Monday, December 13, 2010

Politics is anything but random

I admit that I'm having trouble understanding politics, however I try my best to understand it and I'm really interested in how things go around the world because I live in it and to some extent it can/will affect me or my life style, having that said let's see what this post is all about:

In a previous post I've expressed my opinion regarding Wikileaks as being a hoax -- it is my opinion and even if I'm right or wrong I stand by it until someone can prove me wrong -- a reader commented "You're incoherent. Stick to writing about Delphi.", I agree to the second part however, the first part it might also be true.
The reason I'm against Wikileaks is very obvious... or at least I hope it is...
We all(or at least a pretty big number of us) know that the mainstream media is corrupted and it's anything but "for the people", they make money out of advertising(it's not a secret) however sometimes it comes down to one or more of the following situations:
- someone(or the government) does not want something to be published -- this leads into one or all of the following situations:
a) "someone" has power over the owner of the newspaper, news channel, etc.;
b) "someone" has enough money to make the newspaper, news channel, etc. turn the head in another direction;

- the media is paid(or forced by "someone") to spread disinformation;

- the media spreads disinformation in order to gain more audience -- this results in higher rate for advertising which leads to more cash;

- the journalist has a pretty good salary however if "someone" threatens his/her family the "subject" vanishes into thin air or if "someone" pays him/her a year(or more) worth of salary to shut up he/she will most likely do it, of course both situations can come as one(pay $ X and threaten family to shut up), most common is the pay;

The Internet is part of our lives these days and it helps us share information with outstanding speed -- this means that any information(especially if it's important) can reach millions of people in very short period of time -- he who controls the Internet has power over people's information(personal as well!!).
Take the social networks for instance, they hold so much personal information(which we give for free) that one can know almost anything about Mr./Mrs. X, WHAT IF "someone" would control the Internet or these companies?! yes... he/they would know where you are, where you live, what you've done the past X time, who you know, with who are you in a relationship, what you've talked to, who did you talked to, where ware you when you've wrote something, etc. -- can you see how much information we reveal about our selfs on the Internet?!
Deleting posts or images or changing information on the social networks won't do you any good, why?! because the data doesn't get deleted, there's a field that says "deleted" or "isdeleted" in tables so that information is not shown, however... it's there and can be accessed from server side or with some API's to which only few people have access.

OK, OK, enough BS, where do I want to get with all this?! well... the equation is simple, what if Wikileaks is just disinformation(from what I know until now, there's no real sensitive information released...) which will raise(I'm pretty sure already did) the question in a lot of governments around the world: "What if our sensitive information gets leaked?!" -- now we all know that a lot of dirty things happen(and happened and will still happen in the future) in politics since the beginning of it, do they want you(the guy who is working like a slave everyday in order to have a roof above your head and have something to eat, YOU pay his salary) to know what exactly is the government doing with the money it gets from you?! of course NOT...
Take China(and not only) as example, the government monitors the data that the people are accessing and spreading, WHY?! it's simple, they don't want anything to be leaked, riots or revolutions.
NOW, what IF the governments around the world starts controlling the data that floats on the Internet?! we get to the above situation in which we won't have privacy at all.
How can this happen?! simple, take Wikileaks as a "threat"(which until now isn't a threat at all...) and tell the people that we need to take actions so that we protect sensitive information from the hands of the "terrorists" -- it's a threat to national security, we must act immediately!! -- do you see a pattern?!

Let's take the word "terrorist", what does it mean?! according to Wikipedia:
Terrorism is the systematic use of terror especially as a means of coercion.[1] No universally agreed, legally binding, criminal law definition of terrorism currently exists. Common definitions of terrorism refer only to those violent acts which are intended to create fear (terror), are perpetrated for a religious, political or ideological goal, deliberately target or disregard the safety of non-combatants (civilians), and are committed by non-government agencies.
OK, OK... now do me a favor, think of yourself as a terrorist(it's hard, but please try), can you throw yourself sky high with a bomb because you don't agree with a government or something?!! I would not think so... I mean some of you have kids, family, friends, etc. can you leave them just to make a point?!
"But terrorists don't have friends, family, etc." -- possibly true, BUT still... just thinking that you will give your life should give you chills...

"You're paranoid, a total fu** up", "not another conspiracy crap", etc. -- I agree, it's possible that I'm wrong as hell, but still... what if I'm not?!
Take the time before 9/11 for example, would you allow the police to come into your house without a warrent?! NO!! could they vote this law?! NO!! why?! because it's illegal and immoral by all means!! still they wanted this, what happened?! well... the 9/11 incident in which a lot of people died and got injured -- now that's not right!!
How many towers got hit by a plane?! 1?! yea... sooo... why ware there 3(three) towers that collapsed?!! there are few people that know how many towers did actually collapsed on that day -- check that again, don't leave this "unfortunate incident" pass by because it was anything but an "incident".
Ohhh... yea... after that police got more aggressive, people can't really speak their mind if there's any injustice done to them, why?! because police can arrest you using BS's as excuses, can keep you locked up for as long as they please, etc.

By the way, I've saw a documentary on Discovery channel about "America's doomsday", it's a program started way back in the '50's by the president of USA, the program involved keeping the president and as many people from the government alive in case of a soviet nuclear attack. That's sweet and cool, EXCEPT that they've built a lot of bunkers which where absolute before it was finished because the soviets ware always improving their weapons, they knew that... YET they continued constructing bunkers using the people's money!!
Where do I want to get with this?! well.. what's the scope of a government?! in my opinion it is a group of people who leads the people and takes necessary actions to protect them against outside threats or against their own people, also the government must improve the life of each and every citizen as much as possible, YET the people are doing very bad, the people have NO defence against a war attack, YET the people is paying a lot of money for weapons, bunkers and all kind of BS's that "we need" in order to insure our safety, YET the people are struggling everyday to have a job or to have something to eat, while to governments around the world starts austerity programs because they "needed" to bailout banks(with the people's money of course) that got us in this situation(the economic crisis that is...) in the first place -- YET few people are revolting on this, WHY?! I'm not saying that we need to start revolutions around the world, NO!! that's not the solution, we need to change governments more often(1, 2 years max.!! if you can't keep our life style in that period, you can't improve it, so why do we need you?!), we need to put government people that took stupid actions with people's money in jail for a few years so that others will be more careful of how they spend money and what actions they take.

I want you to send this message to all your friends that work in the army, police or any type of armed force:
Don't forget that we're all people and you should protect the people NOT THE GOVERNMENT, any action taken against the people who try to express their problems or needs to the government(which has the job to improve the life of citizens) should be considered a THREAT TO THE PEOPLE, ANY THREAT TO THE PEOPLE SHOULD BE REMOVED IMMEDIATELY BY ALL MEANS NECESSARY!!

In the end I would like you to express your opinions about what I've wrote above(note that I might also be wrong) and also I would like you to verify everything that I wrote above, DO NOT TAKE ANYTHING FOR GRANTED, QUESTION MORE!!

Saturday, December 11, 2010

Religion: who, what, where, why?!!!

Skip this post if you're not open to impartial when it comes to religion.

NOTE: that I respect each person's belief regarding religion, we are entitled to our own opinions.

Today I received a e-mail from one of the readers regarding my previous post in which I've mentioned about Vatican's wealth, I will keep the person's name anonymous. the question was:
"what is your problem with the Vatican?"
Note: the person was polite and I have no issue whatsoever with his question, therefore I don't want to be misunderstood.

My "issues" with Vatican(and not only) are:
- why do they need a bank?
- why do they have their own laws?
- why do they ask for money(for tickets) in order to see the pope?!
- why can't ordinary people go in the Vatican library and see at least some(if not all) ancient documents?! -- as a believer you should be entitled to see(under surveillance or whatever, it doesn't matter) -- do they have something to hide?!?!
- the "why" list goes on...

I am what you call a "atheist" -- I wasn't raised like this, but in time I started to question a lot of things regarding religion(and not only) and I came to the conclusion that people tend to believe in "stuperstitial" stuff before science(NOTE: that NOT ONCE but a lot of times, religions have tried to ban early science because they hate questions to which they have to answer with proof -- why?! simply because you cannot explain religion...).

Let's NOT forget the deaths with the crusades "in the name of god" -- really now, do we have to kill people because they don't believe in our god or because they don't believe in anything?! my answer is NO(what's your answer?!), each individual has the right to own opinions.

I believe that the religions where started because people needs to believe in something in order to go over the hard life, however, from ancient times until now the religion was used as a control tool with each occasion, remember the history classes in which you've learned about how priests where selling "places in heaven"?! Ohhh... yea the same people who are preaching the "word of god" and the same people which added text in the "holly bible".

My main issue is with the influence of the pope(and priests), I mean we're teached in school about god and all that stuff in stead of being educated on how to behave in society and how to be hard worker and a honest person.

When I was young I've read a lot of holly books and the more I read the more I've found out how it contradicts itself and that is very, very hard on taking actions against non-belivers -- again, can you see a pattern?! YES, either you're with us or against us!!

The main issue with people is that a huge percent of them are like sheeps, they refuse to think or to have own opinions, the biggest problem is that they almost never question what's happening around them, they take for granted what others tell them(why should I bother to think?! I already have the answer... -- oh-ho-ho, but DO YOU?) -- this leads to mass manipulation.

I know most of the people don't like history, however, try to read a bit when you have time but don't forget that history is written by the victor -- never forget that!! -- you will see a lot of dirty things regarding religion and not only, manipulation schemes and other!

I'm pretty sure that a lot of you out there won't agree with what I've written above and very few will.., I'm waiting for your comments, however please be polite, we are humans(we're supposed to be polite with each other) after all...

Question more, don't stop at first answers, don't be afraid to ask "dumb" questions, silence is NOT the answer!

Friday, December 10, 2010

OK, I can't help myself regarding Wikileaks...

My blood pressure is sky high each time I hear, read and/or see something regarding the Wikileaks so called "leaks", I'm f**kin' fed up with all this nonsense... I have yet to hear, read and/or see SENSITIVE INFORMATION released by Wikileaks, really now, can someone tell or point me to the right direction?! I only see the scandals on mainstream media regarding the so called "hacks" on Amazon, Visa, Mastercard and PayPal and regarding the illegal detention of J.A. with which I don't agree however law is law and is for everyone(well at least us..., the small people...).

Now regarding the "hackers" which "attacked" the Amazon(huge fail — LOL!! what the hell?! it's like trying to flood Google servers -- which are millions...), Visa(they don't really give a damn), Mastercard(they laughed their ass off on this...) and PayPal(I'm happy about this attack, they really have big fees!!) websites, c'mon people, that's NOT hacking... and I really hate the freakin' media which is trying to amplify this like it's a major attack on government server... blahhh... major attacks have happen in the past and we didn't hear about and still are happening and still will long after we're gone.

Wanna protect your server for this kind of "hacks"?! simply add another system(near the server) to which the server sends the logs via UDP or whatever... and then if the server is down because of this kind of attack(s), just follow the looong list of IP's which where making requests to the server and resulted in server crash, hello?! someone will have to pay huge amounts of money to da' court.

Bottom line, anyone can and SHOULD think if this is subject is really interesting, I mean, come on people, a lot of shit is happening in the world and no one is lifting a finger to do something, now all of the sudden someone(J.A.) came with some "leaks" which doesn't seem sensitive to me(again, I might be wrong, however please point to the "real" stuff) and we and the media are making a big case out of nothing, it seems to me like something else is happening behind the curtain, but it might be that I'm paranoid...
Take Vatican for instance, they got so much money that they could literally save tens(if NOT more) of millions of people around the whole freakin' World from starvation and diseases, but do they do it?! NO!! does the media care?! NO!! do WE care?! HUGE NO!! but still they say they are the voice of God and other BS'es...


Blogroll(General programming and Delphi feeds)