Windows services: what how and why

First of all, what are Windows services?

well, wiki said that

On Microsoft Windows operating systems, a Windows service is a long-running executable that performs specific functions and which is designed not to require user intervention.

Well, lets simplify that a little bit: a service is an application. But, this application has no UI of itself, and no windows. Some services can interact with the desktop, but this is rare and this is not something that I’ll do as a programmer.

So what is the big difference?

There are two big differences between a service and a command line utility (I’m using command here, since commands doesn’t have any UI either) that does the same job:

  1. In a command program you have to start it in order for that command to work. you have to be logged in and start the command. In a service, Windows (using something that called SCM) does that for you. You don’t need to start the service manually (but you can if you need) and you don’t even have to be logged on. If the computer booted correctly, the service is up and running, unless some problem occurred.
  2. Commands run under the user that is running them. True, you can “Run as” a command, but it is usually used to downgrade command priority (run it with less permissions). Services on the other hand, will usually be run as system or administrator users. and so, even if a regular user is logged into the system, some tasks will be performed with higher level of permissions.

So why do we need services?

There are many tasks we want to be started without someone at the machine,like a web server, file server, print server and so on. Yes, services are usually written for server programs. But, there are some other applications as well. As mentioned, Service can run with different  users credentials then the user that is actually logged on, so, services can be used to grant some level of access to the user that normally can not be done under the OS. This will sound better with example: Lets say we have a file that every employ needs to fill his id every time he or she comes to work. Now we can not give the employees write access to that file, because they might be tempted to add more hours, or delete other people records. We can’t even let them have read access since they should not read other people records.

So? we write a service, and a client program. Every time that a user runs the client program (under his privileges) the program interacts with the service (there are many ways to do that) and sends it the user data. the service then updates the file with its own time stamp and with the user data from the client program. Mission accomplished! Database server are based on a scheme like this (but much, much more complicated).

 

 

 

Starting Ruby on rails

What is Rails?

ROR is a web development framework written with Ruby. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Some developers also say that it makes web application development more fun…

Like many dev programs, ROR is also MVC based.

downloading rails: you can download ruby from here.

  1. Creating application folder. very easy, just key in rails new blog in your command. This will create a Rails application called Blog in a directory called blog.
  2. DB configuration: like many other applications, you will probably use a DB to store the information. You can connect to mysql DB like so:
    development:
      adapter: mysql2
      encoding: utf8
      database: blog_development
      pool: 5
      username: root
      password:
      socket: /tmp/mysql.sock this info goes to your config/database.yml file.
  3. Now that you have your database configured, it’s time to have Rails create an empty database for you. You can do this by running a rake command:$ rake db:create
  4. Starting rail server is easy, just key in $ rails server.
  5. If you didn’t change the defaults, you are listening on port 3000.

 

 

Changing time zone in php.ini

In order to get rid of the pesky warning in php about time zone, you can so one of two things: add call to the date_default_timezone_set on every file header, or, define it in your php.ini  like this: date.timezone = US/Central, where the actual values relates to the server time zone.

Looking for you own time zone? not a problem. here are the php time zones.

And you can still use the date_default_timezone_set if you need to stray from the default timezone.