Saturday, March 16, 2013

Turing Machine

This is where I got an idea of what a Turing machine is. This document is brilliant what a tragic loss was this mind



Saturday, October 6, 2012

Windows 8 keyboard shortcuts

The next version of Windows has new keyboard shortcuts for the benefit of keyboard users which are most users. It still seems that Windows 8 is only worth having for touch screen system.

This file contains the shortcuts listed
ShortcutDescription
Win key+COpen the Charms
Win key+FOpen the Search charm to search files
Win key+HOpen the Share charm
Win key+IOpen the Settings charm
Win key+JSwitch the main app and snapped app
Win key+KOpen the Devices charm


Reference

http://windowsteamblog.com/windows/b/windowsexperience/p/win8_keyboard_shortcuts.aspx

Sunday, July 8, 2012

Semaphores in Java Example

Semaphores in java handles permits to execute the next lines of instructions. They are often use to restrict the number of threads to access a resource.

Before getting a resource the thread must acquire a permit form a semaphore and release the resource after using the shared resource which can be memory, storage or data.

Constructors

Semaphore ( i n t   permits )
Creates a Semaphore  with  the given  number of  permits and no fair fairness setting .
Semaphore ( i n t   permits ,   boolean   fair )
Creates a Semaphore  with  the given  number of  permits and the given  fairness setting .

Now for a sample semaphore program that counts until 20 using two threads that uses semaphores for data consistency.
Counter.java
import java.util.concurrent.Semaphore;
import javax.swing.JTextArea;

public class Counter extends Thread{
 private static int count=0;
 private String ID;
 private JTextArea TBox;
 private Semaphore sem;
 
 public ServiceQueue(String name,JTextArea jArea, Semaphore s){
  ID=name;
  TBox=jArea;
  sem=s;
 }
 
 private void nonCrit(int i){
  System.out.println(ID+" is not in critical: "+i);
 }
 
 
 private synchronized void doCrit(){
   count++;
   TBox.append(ID+" gave count: "+count+"\n");
 }
 
 public void run(){
  for(int ctr=0;ctr<10;ctr++){
  nonCrit(ctr);
   try{
   sem.acquire();
    } catch (InterruptedException e){ }
   doCrit();
   sem.release();
  }
 }
 
}
Executioner.java
import javax.swing.*;
import java.util.concurrent.Semaphore;
import java.awt.*;
public class Executioner extends JFrame{

 public Executioner(){
  super("Hello World");
  JTextArea TA=new JTextArea(20,15);
  Semaphore sem = new Semaphore(3, true);
  
  setLayout(new FlowLayout());
  add(TA);
  
  Counter Q1=new ServiceQueue("1st Class",TA,sem);
                Counter Q2=new ServiceQueue("3rd Class",TA,sem);
  
  
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
  
  C1.start();
  C2.start();
  pack();
 }

 public static void main(String args[]){
  new Executioner();
 }
}

Monday, June 18, 2012

Adding User Accounts in mysql

Sample create user command for Mysql


CREATE USER 'myUser'@'localhost' IDENTIFIED BY 'hello';
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'myUser'@'localhost';

The first command is the CREATE USER where
  • myUser is the user name
  • localhost is where the database is
  • hello is the password
The next command is the Grant command containing the Mysql statements to be allowed, the the database/s to be granted and the user to assigned for the permission.
  • The assigned user is myUser
  • The user can use the commands SELECT,INSERT,UPDATE,DELETE on all databases in localhost
  • ON *.* means that the user can use all the granted commands
  • ON *DBname.* can be used to allow the user to use the commands on the database names DBname
After the CREATE USER command has been executed, the user can now use the new user name and password as arguments in running mysql. In this example, the user can type mysql -u myUser -p then type hello. However not all commands can be used by myUser unlike the root user.

Reference

Oracle (2012). Adding User accounts. http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Friday, May 25, 2012

Checking If software development process is Working

The process must Improve the ff.

Appropriate model
Can improve:
development speed
quality
tracking & control
client relations
Can minimize:
overhead
risk exposure




Inappropriate
-Can improve:
slow
unnecessary
redundant
frustrating

Monday, May 21, 2012

HTTP STATUS CODES

Error CodeMeaning
302Redirect
400bad_request
401unauthorized
403forbidden
404not_found
405method_not_allowed
500internal_server_error
507insufficient_storage

Sunday, May 6, 2012

Agile Software Development

As gleaned from (Beck, K. et al., 2001), Agile development is a approach of developing software that aims to develop software that can adapt. it does not recommend a certain life-cycle model.

It has the ff. characteristics

  • Design and analysis has less emphasis
  • Early implementation of software
  • Prioritize working software over detailed documentation
  • Aim to respond to requirement changing
  • Aims to collaborate with the client
  • Aims to Deliver working software frequently, ideally every 2 to 3 weeks


  • Values Individual and interactions
  • Flexible for changes
  • Not much emphasis on analysis and design
  • Implements project early
  • Working on software is prioritized over documentation
  • Shorter life cycle than waterfall
  • Promotes collaboration with clients
  • Has multiple variations

Reference Beck, K. et al. 2001. Manifesto for Agile Software Development

Monday, March 26, 2012

Shortest Job First Simulation in C#


Where did I go wrong. How do I make this right


public ShortestJobFirst(int pollTime)
        {
            if (pollTime < 1)
            {
                throw new ArgumentOutOfRangeException(Resources.PollTimeGreaterThanZero);
            }

            _pollTime = pollTime;
        }

       
        public void Execute(Runner runner)
        {
            List readyQueue = new List(runner.ProcessLoad);
            while (readyQueue.Count > 0)
            {
                try
                {
                    // select the process that is eligible to run with the smallest remaining burst time
                    Process p = readyQueue.Where(x => x.ArrivalTime <= runner.Time).OrderBy(x => x.BurstTime - x.Data.UtilizedCpuTime).First();
                    runner.UtilizeCpu(p, _pollTime);
                    if (Process.IsComplete(p))
                    {
                        runner.LogProcessMetrics(p);
                        readyQueue.Remove(p);
                    }
                }
                catch (InvalidOperationException)
                {
                    runner.SkipIdleCpuTime();
                }
            }
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.InvariantCulture, "Shortest Job First (Job Time = {0})", _pollTime);
        }
}