Friday, June 27, 2008

Finish What You Start


As usual we will go straight to the point.

Three Ways to finish things:
  • Throw it away. Put an end to it. Example: Your sudoku game. Seriously is not that important.

  • Do it yourself. But really, do it.

  • Delegate it. Find someone to do it for you, your friend, or that developer from india. Make sure that you find someone who you can trust.


Why is it important?
Sense of accomplishment and tranquility. Yes, now you can get that out of your mind. As embarrassing or ridiculous you may think it is; it is now out of your head.

How is it relevant to programming?
Finish that project you started a couple of days ago and gave up because it turned too complicated. Spend an entire night finding the solution. It will be more rewarding than what you think and you will probably learn more than what you intended.

Crazy Googled Internet Quote
"The way to achieve inner peace is to finish all the things you've started."

Monday, June 23, 2008

PHP Segmentation Fault

I ran around this problem a couple of times, and recently i spent more than 20 mins trying to figure out why my php page was seg faulting. Well now I'm going to document it.

To make it simple, this code will give you a seg fault:

class A
{
function __construct()
{
new B;
}
}

class B extends A
{

}

new A;


Don't create new objects from classes that inherit from the class you are creating the object. Yes sounds confusing, and probably it makes no sense but i think the code above is enough to explain it.

Monday, June 9, 2008

New Company Website


My new website is up at : http://coaxialhost.com Handcoded HTML, JS and CSS. Fun to make but is it Google friendly? I hope it is.

Saturday, June 7, 2008

Validating (X)HTML using Ruby


This function returns validation messages from the w3c website (http://validator.w3.org)

require 'net/http'
require 'uri'

class XHTML

VALIDATOR_URL = 'http://validator.w3.org/check'
XHTML_STRICT = 'XHTML 1.0 Strict'
XHTML_TRANSITIONAL = 'XHTML 1.0 Transitional'
XHTML_FRAMESET = 'XHTML 1.0 Frameset'

# Returns validation messages
def XHTML.validate(what, xhtml_version=XHTML_STRICT)
post_data = {
'fragment' => what,
'doctype' => xhtml_version
}

r = Net::HTTP.post_form(URI.parse(VALIDATOR_URL), post_data)

return r.body
end

end



We could try to parse the results into an array... maybe in the future.

Friday, June 6, 2008

Creating Custom Ruby Accessors

Built In Ruby Accessors

attr_reader :a # Generates a reader/get function:
#def a
# @a
#end

attr_writer :a # Generates a writer/set function
#def a= (value)
# @a = value
#end

attr_accessor :a # Generates Both get/set functions



Creating Custom Accessors

We need to define a function in the main Module class:

class Module
def custom_accessor(*symbols)
symbols.each do |symbol|
class_eval "
# Here we would insert the code that we want to generate.
"
end
end
end


And this is it. Now we can use our custom accessor like this:

custom_accessor :accessor