The happiest place on earth.

Sunday, July 5, 2009

No, it is not Disneyland, it is Costa Rica. http://www.happyplanetindex.org

Friday, July 3, 2009

A few weeks ago Bill Maher let Obama have at it for not doing enough. It rings true. The only thing that Bill doesn't take into account is that when it comes to fixing the world, people have to listen to what you say. To have people listening to what you say, you have to be on TV.

Computer Glitch Stops Flight at O'Hare Airport

Thursday, July 2, 2009

And while we are at it, some field validation software doesn't check for not properly escaped characters. From chicagotribune.com

467,000 Jobs Lost in June 2009

Around 8:50 EDT the headlines hit all mayor networks. Just following the trend.

Pesky c++ interview questions.

Tuesday, June 30, 2009

Things you are suppose to regurgitate during c++ screening interviews (yep, in the real world you can't look up things on the Internet). Mostly lifted from Wikipedia. Posted looking for clarity and avoiding fire-hose effect (bucket loads of information cramming your screen

Smart Pointer: Data type that simulates a pointer while providing additional features, such as automatic garbage collection or bounds checking. These additional features are intended to reduce bugs caused by the misuse of pointers while retaining efficiency. Smart pointers typically keep track of the objects that point to them for the purpose of memory management.

Virtual Function: Function or method whose behavior can be overridden within an inheriting class by a function with the same signature.

Dynamic Cast: Operator, which allows the program to safely attempt conversion of an object into an object of a more specific object type (as opposed to conversion to a more general type, which is always allowed).

STL Vector. A vector is a dynamic array. It is one of several data structures called container, others being sets, maps, ... It is implemented as a class template. Access time to any member is constant. The vectory access mechanism is a random iterator.

Copy Constructor. A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object. This constructor takes a single argument: a reference to the object to be copied.

Default Constructor. Constructor without parameters.

STL Map. Standard C++ container. It is a sorted associative array of unique keys and associated data.

STL List. A doubly-linked list; elements are not stored in contiguous memory. Opposite performance from a vector. Slow lookup and access (linear time), but once a position has been found, quick insertion and deletion (constant time)

Virtual Destructor. A virtual destructor is a destructor that can be overridden by subclasses. In C++, use of virtual destructors in inheritance hierarchies facilitates proper clean-up of objects, preventing resource leaks and heap corruption.

Abstract Class A Base class without implementation. The implementation must take place in the derived class.

Local Class A class defined within the scope of a function.

Conversion Constructor. Constructor with a single argument used for type conversion.

class Boo
{
 double value;
 public:
 Boo(int i);
 operator double ()
 {
     return value;
 }
};
Boo BooObj;
double i = BooObject; // good heavens you can assign Boo to double!

Time Is up!

Friday, June 26, 2009

Now that the kiddos are idle and asking to use the computer (watch videos rather) the script below, with the right permissions (root), can be used to abruptly terminate the user's session (just a minute I'm almost done!) when the timer expires. And you don't even have to be there.
Usage: ./kickuser.py username time
time is in minutes
>cat kickuser.py

#!/usr/bin/python
# Python script to time out a user.
# basically I'm allotting some time for a given user to use the system and after
# the time is up, I zap the user pretty mean eh?
# after time expires destroy all programs used by that user, time is given in seconds
import time
import threading
import sys
import os

username = sys.argv[1] # the username is a string
timeout  = sys.argv[2] # the time out is in minutes

class Timer(threading.Thread):
   def __init__(self, seconds):
      self.runTime = seconds
      threading.Thread.__init__(self)
def run(self):
      time.sleep(self.runTime)
      cmd = 'ps -U' +  username + ' | awk \'{print $1}\''
      for pid in os.popen(cmd).readlines():
              kill_command =  "kill -9 " + pid
              print kill_command
              os.system(kill_command)
              #now lock account
              lock_cmd = "passwd -l" + username
              os.system(lock_cmd)

t = Timer(int(timeout) * 60 )
#start the timer
t.start()
print "setting time out for " , username , " " , timeout , "minutes"
And that's that. Easy to execute and timely executed.

The Ruby way. vs. The Python way

Thursday, June 25, 2009

Here are a the python examples of the Active Python Python tutorial and their Ruby counterpart. By comparing simple operations the strength of both languages come to show. When you instruct the script to read an integer from STDIN. In python:
>>> x = int(raw_input("please enter an interger: "))
in Ruby:
irb(main):041:0> p "please enter an integer: " "please enter an integer: " => nil irb(main):042:0> x = gets.to_i
In Ruby there is no raw_input equivalent. In Python the int() operation converts the input string to integer while in Ruby the string object returned by gets invokes the to_i method to convert the string to an integer. Interesting.