Technology and Open Source Update

Latest information about new technology and open source.

Posts Tagged ‘programming’

Phalanger

Posted by megahacker136 on February 17, 2009

The .NET development framework facilitates writing applications in more than one programming language like VB or C#. While writing a .NET application, you can always opt for a language of our choice. You can even write each module (say a Windows form or a Web form) of an application in a different language.

On the other hand, PHP is a popular open source scripting language which is used typically for writing Web based applications. Being a scripting language, applications written in PHP are interpreted and not compiled.

With a piece of software/plugin called Phalanger, you can use PHP as one of the languages for writing .Net applications. Plus these applications, written in PHP will be compiled – as with any application written in .NET language. Plus, Phalanger offers an extension/plugin for Visual Studio which allows you to write PHP based .Net applications in Visual Studio 2008 (the latest in the Visual Studio family).

Get, set and go…
Assuming that you have already installed and are running .NET 2.0 (or above) framework and Visual Studio 2008, you require to do the following to download and install Phalanger:

1. Download phalanger-2.0-march-2008.zip from the URL http://www.codeplex.com/Phalanger/Release/ProjectReleases.aspx?ReleaseId=11564#ReleaseFiles.
2. Unzip the file and run the installer via setup.exe. The installer also sets up IIS web server for PHP (to be precise, for PHP Phalanger).
3. To write PHP Phalanger applications in Visual Studio, you need to install the Phalanger extension which is a separate download.
4. Go to the above mentioned link and download the file vsintegration-2.0-march-2008.zip. Unzip the file and run vsiip.msi.

Configure IIS Web Server
To configure IIS on Windows XP to use Phalanger, execute the following steps:
1. Goto Control Panel>Administrative Tools>Internet Information Services.
2.Expand the tree (in the left pane) till you see “Default Web Site”. Right click on it and select Properties.
3.Click on the “Home Directory” tab and then click on the Configuration button. Under the Mappings tab, click on Add. Type in the following for the Executable and the Extension:
Executable: C:\WINDOWS\ Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll Extension: .php

4. Leave the other settings to their default. Restart IIS.

Posted in Programing, computer | Tagged: , | Leave a Comment »

Java Thread Program Using Runnable Interface

Posted by megahacker136 on October 19, 2008

public class soalan4 {

public static void main(String[] args) {
try {
Thread thread1 = new Thread(new runThread(“Parent Thread”));
Thread thread2 = new Thread(new runThread(“Child Thread”));
thread1.start();
thread2.start();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

class runThread implements Runnable {

String threadName;

runThread(String nama) {
threadName = nama;
}

public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println(threadName + ” “ + i);
}
}
}

Download source code:

>>>DOWNLOAD<<<

Solution 2:

public class soalan4 implements Runnable{

public soalan4(){

try{

Thread thread2 = new Thread(new runThread(“Child Thread”));

thread2.start();

}catch(Exception e){

System.out.println(e.getMessage());

}

}

public static void main(String[] args) {

try {

Thread thread1 = new Thread(new soalan4());

thread1.start();

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

public void run(){

for (int i = 1; i <= 5; i++) {

System.out.println(“Parent Thread ” + i);

}

}

}

class runThread implements Runnable {

String threadName;

runThread(String nama) {

threadName = nama;

}

public void run() {

for (int i = 1; i <= 5; i++) {

System.out.println(threadName + ” ” + i);

}

}

}

Posted in Open Source, Programing | Tagged: , , | 20 Comments »

PHP – Taking Strings Apart

Posted by megahacker136 on October 14, 2008

Problem

You need to break a string into pieces. For example, you want to access each line that a user
enters in a <textarea> form field.

Solution

Use explode( ) if what separates the pieces is a constant string:
$words = explode(‘ ‘,‘My sentence is not very complicated’);

Use split( ) or preg_split( ) if you need a POSIX or Perl regular expression to describethe separator:
$words = split(‘ +’,‘This sentence has some extra whitespace in it.’);

$words = preg_split(/\d\. /,‘my day: 1. get up 2. get dressed 3. eat
toast’
);
$lines = preg_split(‘/[\n\r]+/’,$_REQUEST['textarea']);


Use split( ) or the /i flag to preg_split( ) for case-insensitive separator matching:
$words = split(‘ x ‘,‘31 inches x 22 inches X 9 inches’);
$words = preg_split(‘/ x /i’,‘31 inches x 22 inches X 9 inches’);

Discussion

The simplest solution of the bunch is explode( ). Pass it your separator string, the string to
be separated, and an optional limit on how many elements should be returned:
$dwarves = ‘dopey,sleepy,happy,grumpy,sneezy,bashful,doc’;
$dwarf_array = explode(‘,’,$dwarves);
Now $dwarf_array is a seven element array:
print_r($dwarf_array);
Array
(
[0] => dopey
[1] => sleepy
[2] => happy
[3] => grumpy
[4] => sneezy
[5] => bashful
[6] => doc
)

If the specified limit is less than the number of possible chunks, the last chunk contains the
remainder:
$dwarf_array = explode(‘,’,$dwarves,5);
print_r($dwarf_array);
Array
(
[0] => dopey
[1] => sleepy
[2] => happy
[3] => grumpy
[4] => sneezy,bashful,doc
)

The separator is treated literally by explode( ). If you specify a comma and a space as a
separator, it breaks the string only on a comma followed by a space — not on a comma or a
space.
With split( ), you have more flexibility. Instead of a string literal as a separator, it uses a
POSIX regular expression:
$more_dwarves = ‘cheeky,fatso, wonder boy, chunky,growly, groggy, winky’;
$more_dwarf_array = split(‘, ?’,$more_dwarves);

This regular expression splits on a comma followed by an optional space, which treats all the
new dwarves properly. Those with a space in their name aren’t broken up, but everyone is
broken apart whether they are separated by “,” or “, “:
print_r($more_dwarf_array);
Array
(
[0] => cheeky
[1] => fatso
[2] => wonder boy
[3] => chunky
[4] => growly
[5] => groggy
[6] => winky
)

Similar to split( ) is preg_split( ), which uses a Perl-compatible regular-expression
engine instead of a POSIX regular-expression engine. With preg_split( ), you can take
advantage of various Perlish regular-expression extensions, as well as tricks such as including
the separator text in the returned array of strings:
$math = “3 + 2 / 7 – 9″;
$stack = preg_split(‘/ *([+\-\/*]) */’,$math,-1,PREG_SPLIT_DELIM_CAPTURE);
print_r($stack);
Array
(
[0] => 3
[1] => +
[2] => 2
[3] => /
[4] => 7
[5] => -
[6] => 9
)
The separator regular expression looks for the four mathematical operators (+, -, /, *),
surrounded by optional leading or trailing spaces. The PREG_SPLIT_DELIM_CAPTURE flag
tells preg_split( ) to include the matches as part of the separator regular expression in
parentheses in the returned array of strings. Only the mathematical operator character class is
in parentheses, so the returned array doesn’t have any spaces in it.

How to get filename from address or url?

Solution

$arrStr = explode(“\”, “D:\ruby program\cuba.rb”);
$arrStr = array_reverse($arrStr);

echo(“Filename is “ . $arrStr[0]);

or

$arrStr = split(“\”, “D:\ruby program\cuba.rb”);
$arrStr = array_reverse($arrStr);

echo(“Filename is “ . $arrStr[0]);

See the documentation to know details:

http://www.php.net/explode

http://www.php.net/split

http://www.php.net/preg-split

Posted in Open Source, Programing | Tagged: , , | Leave a Comment »

Transparent JFrame Background

Posted by megahacker136 on September 19, 2008

JFrame not come with the transparent window functionality, but you can try making it by using Java graphics class. The code below is the demo for the transparent frame background. Try the code below if you want to see it.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;

public class TransparentBackground extends JComponent
implements ComponentListener, WindowFocusListener, Runnable {

// constants —————————————————————

// instance —————————————————————-
private JFrame _frame;
private BufferedImage _background;
private long _lastUpdate = 0;
private boolean _refreshRequested = true;
private Robot _robot;
private Rectangle _screenRect;
private ConvolveOp _blurOp;

// constructor ————————————————————-
public TransparentBackground(JFrame frame) {

_frame = frame;

try {

_robot = new Robot();

} catch (AWTException e) {

e.printStackTrace();

return;

}

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

_screenRect = new Rectangle(dim.width, dim.height);

float[] my_kernel = {
0.10f, 0.10f, 0.10f,
0.10f, 0.20f, 0.10f,
0.10f, 0.10f, 0.10f
};

_blurOp = new ConvolveOp(new Kernel(3, 3, my_kernel));

updateBackground();

_frame.addComponentListener(this);

_frame.addWindowFocusListener(this);

new Thread(this).start();

}

// protected —————————————————————
protected void updateBackground() {

_background = _robot.createScreenCapture(_screenRect);

}

protected void refresh() {

if (_frame.isVisible() && this.isVisible()) {

repaint();

_refreshRequested = true;

_lastUpdate = System.currentTimeMillis();

}

}

// JComponent ————————————————————–
@Override
protected void paintComponent(Graphics g) {

Graphics2D g2 = (Graphics2D) g;

Point pos = this.getLocationOnScreen();

BufferedImage buf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);

buf.getGraphics().drawImage(_background, -pos.x, -pos.y, null);

Image img = _blurOp.filter(buf, null);

g2.drawImage(img, 0, 0, null);

g2.setColor(new Color(255, 255, 255, 192));

g2.fillRect(0, 0, getWidth(), getHeight());

}

// ComponentListener ——————————————————-
@Override
public void componentHidden(ComponentEvent e) {
}

@Override
public void componentMoved(ComponentEvent e) {

repaint();

}

@Override
public void componentResized(ComponentEvent e) {

repaint();

}

@Override
public void componentShown(ComponentEvent e) {

repaint();

}

// WindowFocusListener —————————————————–
@Override
public void windowGainedFocus(WindowEvent e) {

refresh();

}

@Override
public void windowLostFocus(WindowEvent e) {

refresh();

}

// Runnable —————————————————————-
@Override
public void run() {

try {

while (true) {

Thread.sleep(100);

long now = System.currentTimeMillis();

if (_refreshRequested && ((now – _lastUpdate) > 1000)) {

if (_frame.isVisible()) {

Point location = _frame.getLocation();

_frame.setLocation(-_frame.getWidth(), -_frame.getHeight());

updateBackground();

_frame.setLocation(location);

refresh();

}

_lastUpdate = now;

_refreshRequested = false;

}

}

} catch (InterruptedException e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

JFrame frame = new JFrame();

TransparentBackground bg = new TransparentBackground(frame);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(bg);

frame.pack();

frame.setSize(500, 500);

frame.setLocation(500, 500);

frame.setVisible(true);

}
}

Posted in Open Source, Programing | Tagged: , , | 3 Comments »

Conway’s Game of Life…

Posted by megahacker136 on September 19, 2008

The Game of Life is not your typical computer game. It is a ‘cellular automaton’, and was invented by Cambridge mathematician John Conway.

This game became widely known when it was mentioned in an article published by Scientific American in 1970. It consists of a collection of cells which, based on a few mathematical rules, can live, die or multiply. Depending on the initial conditions, the cells form various patterns throughout the course of the game.

The popular Conway’s Game of Life that we seen all over the internet today mostly written in java applet. But the program below is written in JFrame class. I hope you enjoy it…

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class ConwayGUI extends JFrame {

int gen;

int[][] conway = new int[50][50];

String[] speed = {“Slow”, “Fast”, “Hyper”};

javax.swing.Timer timerslow = new javax.swing.Timer(900, new startConway());

javax.swing.Timer timerfast = new javax.swing.Timer(100, new startConway());

javax.swing.Timer timerhyper = new javax.swing.Timer(1, new startConway());

javax.swing.Timer timerStart = new javax.swing.Timer(1, new mula());

public ConwayGUI () {

GUIComponent();

}

private void GUIComponent() {

this.setLayout(new BorderLayout());

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setTitle(“Game Of Life”);

this.setResizable(false);

JP1 = new JPanel();

JP1.setLayout(new GridLayout(50, 50));

arrButton = new JButton[50][50];

for (int i = 0; i < 50; i++) {

for (int j = 0; j < 50; j++) {

final int m = i;

final int n = j;

JP1.add(arrButton[i][j] = new JButton(“”));

arrButton[i][j].setPreferredSize(new java.awt.Dimension(12, 12));

arrButton[i][j].setBackground(new java.awt.Color(128, 128, 128));

arrButton[i][j].addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

arrBtnActionPerformed(evt, arrButton[m][n]);

}

});

}

}

add(BorderLayout.CENTER, JP1);

java.awt.GridBagConstraints gridBagConstraints;

JP2 = new JPanel();

JP2.setLayout(new GridBagLayout());

clearBtn = new javax.swing.JButton();

nextBtn = new javax.swing.JButton();

stopBtn = new javax.swing.JButton();

startBtn = new javax.swing.JButton();

speedLabel = new javax.swing.JLabel();

speedCombo = new javax.swing.JComboBox();

genLabel = new javax.swing.JLabel();

genField = new javax.swing.JTextField();

clearBtn.setText(“Clear”);

clearBtn.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

clearBtnActionPerformed(evt);

}

});

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.gridwidth = 5;

gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 16);

JP2.add(clearBtn, gridBagConstraints);

nextBtn.setText(“Next”);

nextBtn.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

nextBtnActionPerformed(evt);

}

});

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 16);

JP2.add(nextBtn, gridBagConstraints);

startBtn.setText(“Start”);

startBtn.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

startBtnActionPerformed(evt);

}

});

JP2.add(startBtn, new java.awt.GridBagConstraints());

speedLabel.setText(“Speed:”);

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.gridwidth = 3;

gridBagConstraints.insets = new java.awt.Insets(0, 21, 0, 0);

JP2.add(speedLabel, gridBagConstraints);

speedCombo.setModel(new javax.swing.DefaultComboBoxModel(speed));

speedCombo.setSelectedItem(speed[0]);

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.gridwidth = 4;

gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);

JP2.add(speedCombo, gridBagConstraints);

genLabel.setText(“Generation:”);

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.insets = new java.awt.Insets(0, 16, 0, 5);

JP2.add(genLabel, gridBagConstraints);

genField.setColumns(7);

genField.setEditable(false);

JP2.add(genField, new java.awt.GridBagConstraints());

add(BorderLayout.SOUTH, JP2);

pack();

}

private void clearBtnActionPerformed(java.awt.event.ActionEvent evt) {

genField.setText(“”);

gen = 0;

for (int i = 0; i < 50; i++) {

for (int j = 0; j < 50; j++) {

arrButton[i][j].setBackground(new java.awt.Color(128, 128, 128));

}

}

}

private void nextBtnActionPerformed(java.awt.event.ActionEvent evt) {

neighbor();

}

private void startBtnActionPerformed(java.awt.event.ActionEvent evt) {

String str = startBtn.getText();

if (str.equalsIgnoreCase(“Start”)) {

timerStart.start();

startBtn.setText(“Stop”);

clearBtn.setEnabled(false);

nextBtn.setEnabled(false);

} else {

timerStart.stop();

timerslow.stop();

timerfast.stop();

timerhyper.stop();

startBtn.setText(“Start”);

clearBtn.setEnabled(true);

nextBtn.setEnabled(true);

}

}

private void set_arr() {

String str = “java.awt.Color[r=255,g=255,b=0]“;

for (int i = 0; i < conway.length; i++) {

for (int j = 0; j < conway[i].length; j++) {

String s = “” + arrButton[i][j].getBackground();

if (s.equalsIgnoreCase(str)) {

conway[i][j] = 1;

} else {

conway[i][j] = 0;

}

}

}

}

private void neighbor() {

set_arr();

gen++;

genField.setText(“” + gen);

for (int i = 0; i < arrButton.length; i++) {

for (int j = 0; j < arrButton[i].length; j++) {

int bil = cal_Neighbor(conway, i, j);

String str = “java.awt.Color[r=255,g=255,b=0]“;

String kosong = “java.awt.Color[r=128,g=128,b=128]“;

String s = “” + arrButton[i][j].getBackground();

if (s.equalsIgnoreCase(str)) {

if (bil == 2 || bil == 3) {

arrButton[i][j].setBackground(new java.awt.Color(255, 255, 0));

} else if (bil < 2 || bil > 3) {

arrButton[i][j].setBackground(new java.awt.Color(128, 128, 128));

}

}

if (s.equalsIgnoreCase(kosong)) {

if (bil == 3) {

arrButton[i][j].setBackground(new java.awt.Color(255, 255, 0));

}

}

}

}

}

private int cal_Neighbor(int[][] arr, int num, int i) {

int total = 0;

if ((num – 1 != -1) && (i – 1 != -1)) {

if (arr[num - 1][i - 1] == 1) {

total += 1;

}

}

if (num – 1 != -1) {

if (arr[num - 1][i] == 1) {

total += 1;

}

}

if ((num – 1 != -1) && (i + 1 < arr[num].length)) {

if (arr[num - 1][i + 1] == 1) {

total += 1;

}

}

if (i – 1 != -1) {

if (arr[num][i - 1] == 1) {

total += 1;

}

}

if (i + 1 < arr[num].length) {

if (arr[num][i + 1] == 1) {

total += 1;

}

}

if ((num + 1 < arr.length) && (i – 1 != -1)) {

if (arr[num + 1][i - 1] == 1) {

total += 1;

}

}

if ((num + 1 < arr.length)) {

if (arr[num + 1][i] == 1) {

total += 1;

}

}

if ((num + 1 < arr.length) && (i + 1 < arr[num].length)) {

if (arr[num + 1][i + 1] == 1) {

total += 1;

}

}

return total;

}

private void arrBtnActionPerformed(java.awt.event.ActionEvent evt, JButton arrayBtn) {

String str = “java.awt.Color[r=255,g=255,b=0]“;

String s = “” + arrayBtn.getBackground();

if (s.equalsIgnoreCase(str)) {

arrayBtn.setBackground(new java.awt.Color(128, 128, 128));

} else {

arrayBtn.setBackground(new java.awt.Color(255, 255, 0));

}

}

class startConway implements ActionListener {

public void actionPerformed(ActionEvent e) {

neighbor();

}

}

class mula implements ActionListener {

public void actionPerformed(ActionEvent e) {

try {

if (speedCombo.getSelectedIndex() == 0) {

timerhyper.stop();

timerfast.stop();

timerslow.start();

} else if (speedCombo.getSelectedIndex() == 1) {

timerhyper.stop();

timerslow.stop();

timerfast.start();

} else if (speedCombo.getSelectedIndex() == 2) {

timerslow.stop();

timerfast.stop();

timerhyper.start();

}

} catch (Exception ew) {

}

}

}

public static void main(String[] args) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

ConwayGUI showWin = new ConwayGUI ();

showWin.setVisible(true);

}

});

}

private JButton[][] arrButton;

private JPanel JP1;

private JPanel JP2;

private JButton clearBtn;

private JButton nextBtn;

private JButton stopBtn;

private JButton startBtn;

private JComboBox speedCombo;

private JLabel speedLabel;

private JTextField genField;

private JLabel genLabel;

}

Posted in Open Source, Programing | Tagged: , , | Leave a Comment »

Dev-PHP Review

Posted by megahacker136 on September 12, 2008

Dev-PHP is a lightweight development environment for PHP. Dev-PHP is hardly comparable with the likes of Zend Studio or Nusphere but is more than adequate for the PHP novice not willing to part with $299.

Dev-PHP is however more than a syntax editor. It provides syntax highlighting for CSS, JavaScript, HTML, XML and even SQL. Currently in alpha release, Dev-PHP also supports development of PHP-GTK applications, an internal web browser, class browser and convenient access to your PHP documentation.

Download Link:

Dev-PHP Download

Posted in Open Source, Programing, Software, Windows | Tagged: , , , , | 1 Comment »

Open Source SOA Benifits

Posted by megahacker136 on September 11, 2008

The benefits of the service-oriented architecture are widely touted: reduced integration costs, greater asset reuse, and the ability for IT to respond more quickly to changing business and regulatory requirements. But what about the pitfalls?

SOA pioneers know all too well the challenges that can arise when a company service-enables critical applications. The SOA endeavor spans IT disciplines: It’s part systems design and architecture overhaul, part application development and business makeover. Here, early adopters and other experts give their best advice about avoiding the obstacles when building this New Data Center essential, the SOA.

SOA requires the integration of many varied processes, applications and technologies that are difficult to mesh seamlessly, meaning incompatibility, scalability and flexibility issues often arise. The license-fee structure of traditional software can also limit options and add cost. Turning to open source technology can help alleviate these issues and accelerate deployment, as well as business adoption.

Open source has become a staple of enterprise-class IT as concerns about stability, security and support fall away. Open source is as stable, secure and well supported as proprietary solutions, if not more so. In addition open source SOA solutions provide:

  • Simplicity – Open source solutions are easy to find and easy to implement, with many architects and developers being familiar with the core mechanics of the technology. Open source developers are motivated by their communities to deliver easy-to-use frameworks and platforms. It also enables enterprises to rapidly create solutions to deliver tangible, measurable benefits.

  • Openness – The flexibility inherent in open source allows for more freedom and personalization of the solution than proprietary offerings, and means that an organization will see more value relevant to its operations from the installation.

  • Affordability – The open source subscription model makes SOA products less expensive than proprietary tool sets.

The benefits of open source SOA solutions can be realized in each of the six stages of the SOA evolution:

1) business process understanding;

2) IT assessment;

3) SOA design/determination;

4) SOA service enablement;

5) SOA integration and governance infrastructure;

and

6) process orchestration/composition.

For the first three steps, work efforts are focused on the business processes, current IT design and SOA design, and the open source subscription model offers a more affordable and flexible pricing structure than traditional SOA solutions. That helps the SOA design work proceed more quickly without concern about per-CPU license fees.

The advantages of open source solutions are particularly evident during the final three steps in the process.

quickly without concern about per-CPU license fees.

The advantages of open source solutions are particularly evident during the final three steps in the process.

Posted in Open Source, Programing, Tech Industry | Tagged: , , , | Leave a Comment »