Sunday, November 28, 2010

My simple floating point arithmetic program via Assembly language using C language

#include stdio.h
#define p printf
#define s scanf

int main() {

float var1, var2, sum, diff, product, dividend;

p( "Enter two numbers : " );
s( "%f%f", &num1, &num2 );

/* Perform floating point */
__asm__ ( "fld %1;"
"fld %2;"
"fadd;"
"fstp %0;" : "=g" (sum) : "g" (num1), "g" (num2) ) ;

__asm__ ( "fld %2;"
"fld %1;"
"fsub;"
"fstp %0;" : "=g" (diff) : "g" (num1), "g" (num2) ) ;

__asm__ ( "fld %1;"
"fld %2;"
"fmul;"
"fstp %0;" : "=g" (product) : "g" (num1), "g" (num2) ) ;

__asm__ ( "fld %2;"
"fld %1;"
"fdiv;"
"fstp %0;" : "=g" (dividend) : "g" (num1), "g" (num2) ) ;

p( "%f + %f = %f\n", num1, num2, sum);
p( "%f - %f = %f\n", num1, num2, diff);
p( "%f * %f = %f\n", num1, num2, product);
p( "%f / %f = %f\n", num1, num2, dividend);

return 0 ;
}

Tuesday, November 23, 2010

My IF Else Loop Sample in COBOL Programming in LINUX ^_^

PROCEDURE Decimal
Begin.
PERFORM DecimalValue THRU DecimalValueExit
STOP RUN.
DecimalValue.
Statements
Statements
IF ErrorFound GO TO DecimalValueExit
END-IF
Statements
Statements
IF ErrorFound GO TO DecimalValueExit
END-IF
Statements
Statements
Statements
IF ErrorFound GO TO DecimalValueExit
END-IF
Statements
Statements
Statements
Statements
DecimalValueExit
EXIT.

Wednesday, November 17, 2010

My Sample ABAP Program ALV Grid Control

My Sample ABAP Program ALV Grid Control


create a screen 100 for call it and Element list of screen supploy OK and type Ok inthe output

Then activate modules STATUS_0100 and USER_COMMAND_0100 in the flow logic .

CALL SCREEN 100.

MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN'.
IF C_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT C_CUSTOM_CONTAINER EXPORTING CONTAINER_NAME = C_CONTAINER

CREATE OBJECT ALV_GRID EXPORTING I_PARENT = C_CUSTOM_CONTAINER.

CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
I_STRUCTURE_NAME = 'bin1'
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
CHANGING
IT_OUTTAB = TAB_DISPLAY
* IT_FIELDCATALOG =
* IT_SORT =
* IT_FILTER =
* EXCEPTIONS
* INVALID_PARAMETER_COMBINATION = 4
* PROGRAM_ERROR = 2
* others = 1
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDIF.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'EXIT'.
LEAVE PROGRAM.

ENDCASE.
END MODULE.

Friday, November 5, 2010

My Sample Embedded C++ program using EC++ compiler

#include
using namespace std;

extern "C" void exit(int);


void johnpaul(const char *msg, int n)
{
cout << msg << n << endl;
exit(1);
}

// The integer array class

class Shit{
private:
// array elements
int *arry;
// array size
int array_counter; public:
// construct a array
Array(int n) : array_counter(n) {
if (n > 0)
elements = new int[array_counter];
else
die("Bad Array size, dumbass try again!!!! ", array_counter);
}
int &operator [](int index_list) const {
// overloaded operator
if (index_list < 0 || index_list >= array_counter)
die("Bad Array index ", index_list);
return arry[index_list];
}
int size() { return array_counter; } // return the size of the array
};

main()
{
Array m(6);
for (int i=0; i a[i] = i;
for (int i=0; i cout << i << ". " << m[i] << endl;
}

Monday, October 18, 2010

How to create and run COBOL Program in Linux ^_^

1. Write a Hello World Cobol Program

Create the JohnPaulSample program using the Vim editor as shown below.

$ sudo gedit JohnPaulSample

Note:

Types of Editor in Linux

1. Gedit
2. Kedit
3. Emacs
4. Anjuta
5. Nano
6. Vim
7. JEdit (Open Source Java Code Editor)

My Sample Program in Cobol

IDENTIFICATION DIVISION.
PROGRAM-ID. JohnPaulSampleProgram.
PROCEDURE DIVISION.
DISPLAY 'Hello John Paul!'.
STOP RUN.

Note: Comment in Cobol starts with *.
2. Make sure Cobol Compiler is installed on your system

Make sure Cobol compiler is installed on your system as shown below.

$ whereis cobc
cobc: /usr/bin/cobc /usr/share/man/man1/cobc.1.gz


Note:

whereis - command in linux for looking faster for a specific path or directory of file or package.




$ which cobc
/usr/bin/cobc

Installing COBC compiler

If you don’t have cobol compiler, install it as shown below.

$ sudo apt-get install open-cobol

Note

sudo - super user do. (Admin privileges)



3. Compile the cobol program trought Terminal

Compile the JohnPaulSample which will create the JohnPaulSample executable.

$ cobc -free -x -o JohnPaulSample-exe JohnPaulSample

$ ls
JohnPaulSample JohnPaulSample-exe*

* -free – use free source format. Without this option cobol program requires certain format.
* -x – build executable program.
* -o FILE – place the output file into the specified FILE.

4. Execute the cobol Program

Execute by mentioning the program name.

$./JohnPaulSample-exe
Hello John Paul!

Saturday, October 16, 2010

How to Configure RIP in a Cisco Router

NOTE: RIP - Router Interface Protocol


1. enable the RIP protocol on the router with the ‘router rip’ command.


Router(config)#router rip

2. trace the network to be used directly connected to the router.


Router(config-router)#network 192.168.0.0

Note:

Remember use Supernet if you have a group of subnets.

Router(config-router)#network 172.69.0.0

there are 3 subnets in the supernet


3. Adjust the update, invalid, holddown and flush timers.

Router(config-router)#timers basic 30 190 280 260

4. Stop the updates from being broadcasted on internet.

Router(config-router)#passive-interface Fa0/0

5. RIP, sends updates as broadcast. If the router is connected through non-broadcast networks (like FrameRelay).

Router(config-router)#neighbor XXX.XXX.XXX.XXX

Where XXX.XXX.XXX.XXX is the IP address of the neighbor.

6. Cisco's implementation of RIP Version 2 supports authentication, key management, route summarization, classless interdomain routing (CIDR), and variable-length subnet masks (VLSMs).

Router(config-router)#version 2

And if you like to stick to version one, just replace the 2 in the command above with 1.

Note:

Can control ther versions of the updates and recieved on each interface.
this will be determined in 'IP rip' and 'IP Rip Version'.

Router(config-if)#ip rip send version 2

Router(config-if)#ip rip receive version 1


7. Check the RIP configuration using the ‘show ip route’, ‘show ip protocols’, and ‘debug ip rip’ commands.

Tuesday, July 13, 2010

JQuery for Web Design using JQuery Web Broswer API

JQuery for Web Design using JQuery Web Broswer API

bind and unbind events with colored button.


function ClickMe() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("jejeje").live("click", ClickMe)
.text("Can Click!");
});
$("#unbind").click(function () {
$("jejeje").die("click", ClickMe)
.text("Does nothing...");
});

Using the Datastore for Google App Engine

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)

class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('')

greetings = db.GqlQuery("SELECT * FROM JPDBinfo ORDER BY date DESC LIMIT 10")

for greeting in greetings:
if greeting.author:
self.response.out.write('%s wrote:' % greeting.author.nickname())
else:
self.response.out.write('An anonymous person wrote:')
self.response.out.write('
%s
' %
cgi.escape(greeting.content))

self.response.out.write("""

//* YOUR OWN HTML CODE

class Guestbook(webapp.RequestHandler):
def post(self):
greets = Pagabati()

if users.get_current_user():
greets.author = users.get_current_user()

greets.content = self.request.get('content')
greets.put()
self.redirect('/')

application = webapp.WSGIApplication(
[('/', UnangPahina),
('/sign', Lakdaan)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()




Note:

After compile the code and save do the following:

Go -> Application - Terminal

Type the command

/* compile the python file that you created and compile by Google App Engine
chmod u+x progname.py

run the script

./programko.py

Linux Iptables block all network traffic in your ISP

Linux Iptables block all network traffic in your ISP

# iptable -F
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP


Note:

You can create bash script and execute this command.


Types of Scipt in Linux

1. bash Script
2. bourne script
3. Shell script
4. C shell

Struts 2 Java Framework Using Selection in Form for Web Page

Struts 2 Java Framework Using Selection in Form for Web Page


package ActionForm;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class MyTagActionForm extends org.apache.struts.action.ActionForm{

private String MySelection;

public String getMySelection() {
return singleSelect;
}
public void setMySelection(String string) {
MySelection = string;
}
public MyTagActionForm() {
super();
}
}

Monday, July 12, 2010

Programming with Asterisk Elastic in Linux ^_^

#!/usr/bin/php -q
set_time_limit(30);
require('include/phpagi.php');
error_reporting(E_ALL);
$agi = new AGI();
$agi->answer();
$agi->stream_file("congrats you are connected to the VOIP line","#");
do
{
$agi->stream_file("enter-digits-call-number","#");
$result = $agi->get_data('beep', 3000, 20);
$keys = $result['result'];
$agi->stream_file("you entered nubmer:","#");
$agi->say_digits($keys);
} while($keys != '111');
$agi->hangup();
?>

Tuesday, July 6, 2010

Build Android application in Windows and Linux ^_^

Step 1: Generate Resource java code and packaged Resources
aapt package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]

Step 2: Compile java source codes + R.java
use javac

Step 3: Convert classes to clear bytecodes
use dx.bat
dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory} ${jar files..}

Step 4: Create unsigned APK
use apkbuilder

apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file}

or

apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file} -rf ${source.dir} -rj ${libraries.dir}

-rf = resources required for compiled source files?
-rj = resources required for jar files

Step 6: Generate a key
use keytool

Step 7: Sign APK
use jarsigner

jarsigner -keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}

Step 8: Publish
use adb
adb -d install -r ${signed.apk}

Inspecting your APK file:

aapt list -v latest.apk

Friday, July 2, 2010

Locking a mailbox file in SHELL Programming on Linux

Locking a mailbox file in SHELL Programming on Linux

function my_lockfile ()
{
TEMPFILE="$1.$$"
LOCKFILE="$1.lock"
{ echo $$ > $TEMPFILE } >& /dev/null || {
echo "No permission to access the directory `dirname $TEMPFILE`"
return 1
}
ln $TEMPFILE $LOCKFILE >& /dev/null && {
rm -f $TEMPFILE
return 0
}
kill -0 `cat $LOCKFILE` >& /dev/null && {
rm -f $TEMPFILE
return 1
}
echo "Removing stale lock file"
rm -f $LOCKFILE
ln $TEMPFILE $LOCKFILE >& /dev/null && {
rm -f $TEMPFILE
return 0
}
rm -f $TEMPFILE
return 1
}

lock any kind of file


wait for a lock
until my_lockfile /etc/passwd ; do
sleep 1
done

# The body of the program might go here
# [...]

# Then to remove the lock,
rm -f /etc/passwd.lock

Friday, June 25, 2010

How to Setup static IP Addres in Linux

Procedure:

1. Go to Application --> Terminal.
2. Type the following command:

#network setting interface

sudo emacs /etc/network/interfaces/

Note:

Text code editor of linux debian, mint, and fedora, red hat.

a. emacs
b. nano
c. vi
d. gedit
e. pico
f. blufish
g. aljuta

3. Setup your network

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.xxx.xxx
broadcast 192.168.xxx.xxx
gateway 192.168.xxx.xxx

Note:
Comment the default DHCP network settings.

iface eth0 inet DCHP

4. Restart the network server by typing this command

sudo /etc/init.d/networking restart


''' You have now Static IP Address '''



Change IP address and netmask from command line


Activate network interface eth0 with a new IP (192.xxx.xxx.xxx) / netmask:

$ sudo ifconfig eth0 192.168.xxx.xxx netmask 255.255.255.0 up


Display the routing table

$ /sbin/route OR$ /sbin/route -n

Output:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
localnet * 255.255.255.0 U 0 0 0 ra0
192.xxx.xxx.0 * 255.255.255.0 U 0 0 0 eth0
192.xxx.xxx.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.xxx.xxx 0.0.0.0 UG 0 0 0 ra0

Define new DNS servers

Open /etc/resolv.conf file
$ sudo vi /etc/resolv.conf

You need to remove old DNS server assigned by DHCP server:
search myisp.com
nameserver 192.xxx.xxx.xxx
nameserver 192.xxx.xxx.xxx
nameserver 192.xxx.xxx.xxx

Friday, June 18, 2010

Installing Open Source VoIP PBX System on Linux

The Open Source VoIP PBX System

From the root prompt, type:
ipkg install asterisk

Optionally install the additional sound package:
ipkg -force-overwrite install asterisk-sounds
Configuration:

The original sample configuration files are in /opt/etc/asterisk/sample

Take a look at it, consult the voip-info.org Asterisk wiki and create your configuration files in /opt/etc/asterisk

Because the NSLU has only 32MB of RAM I'll recommend you to use a slim configuration (modules.conf).

I have tested it with the second Asterisk slim configuration with the iLBC codec disabled as it requires a floating point unit which isn't present on the IXP420.

You have to configure the path to the various asterisk component in asterisk.conf:

[directories]
astetcdir => /opt/etc/asterisk
astmoddir => /opt/lib/asterisk/modules
astvarlibdir => /opt/var/lib/asterisk
astagidir => /opt/var/lib/asterisk/agi-bin
astspooldir => /opt/var/spool/asterisk
astrundir => /opt/var/run
astlogdir => /opt/var/log/asterisk

Use the voip-info.org Asterisk wiki to find out how to configure:

extensions.conf
iax.conf
sip.conf
voicemail.conf

Performance expectations

The slug's IXP420 should have enough horse power for a home PBX with up to 4 lines, when less CPU intensive codecs (like GSM, G711u, G711a or G726) are used.

The CPU intensive codecs (iLBC, G729, Speex) are not working, but it should be possible to rewrite them using the DSP extended instruction set supported by the IXP4xx. The Intel(R) IXP4XX DSP Software Library contains efficient implementations of all codecs including G729 and other VoIP goodies, but it looks that it cannot be used by asterisk: http://www.intel.com/design/network/products/npfamily/ixp425swr1.htm
Flash installation

To install on a USB flash disk, 128Mb or more is recommended to allow room for voicemail files etc.. See Ext3flash. It has been reported to run on 64Mb.
Asterisk sample configuration for Slug

If you want to try the Asterisk VoIP PBX without going trough the hassle of configuring it from the scratch, you can start with this sample configuration and you will have Asterisk running on the Slug in minutes.
Starting and stopping Asterisk

If you have just installed and configured Asterisk, you can try running it for the first time in console mode with some debugging applied with this command:

/opt/sbin/asterisk -vvvc

Use the command "stop now" to shut down Asterisk from the CLI console.

If run with no arguments, Asterisk is launched as a daemon process:

/opt/sbin/asterisk

You can get a CLI console to an already-running daemon by typing:

/opt/sbin/asterisk -r

on the same computer on which Asterisk is running. More than one console CLI can connect to Asterisk simultaneously.

You can list all the available CLI commands by entering "help", or get information on a particular command by entering "help ".

To start asterisk at boot time, create a script whose name starts with S[number][number] in /opt/etc/init.d/ that executes asterisk:

/opt/etc/init.d # cat S99asterisk
#!/bin/sh

if [ -f /opt/var/run/asterisk.pid ] ; then
kill `cat /opt/var/run/asterisk.pid`
else
killall asterisk
fi

rm -f /opt/var/run/asterisk.pid

umask 077

/opt/sbin/asterisk

Installing Java on Linux ^_^

Installing Java on Linux ^_^


sudo apt-get install sun-java5-jdk

Set Java environment variables

$ export JAVA_HOME="path of your java home"
$ export PATH=$PATH:$JAVA_HOME/bin

In Ubuntu 6.06,do:

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.06

You may have to change the numbers for updated versions.

Installing Apache Tomcat 5

$ sudo aptitude install tomcat5 tomcat5-admin tomcat5-webapps

(The package tomcat5-webapps just contains some example applications. It is interesting for developers, but you should omit it on production servers.)

Depending on your JDK version, you must set (or not) the JAVA_HOME variable in /etc/default/tomcat5. The start script tests for a couple of JDKs, but only finds older versions. Probably you must set (the already existing) JAVA_HOME variable as follows:

JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun

Run, Stop, And Restart Apache Tomcat

Use the following command to run Apache Tomcat:

$ sudo /etc/init.d/tomcat5 start

To stop it, use :

$ sudo /etc/init.d/tomcat5 stop

Finally, to restart it, run :

$ sudo /etc/init.d/tomcat5 restart

Using Tomcat5

You can find tomcat up and running (if you have followed the previous steps) at the following ip:

127.0.0.1:8180

Configuration

Configuring & Using Apache Tomcat 6 and Securing tomcat are good external resources about this topic.

Administering Tomcat5

If you have installed also the admin package as listed before you will be able to enter in the administation window only if you edit the file

$ /usr/share/tomcat5/conf/tomcat-users.xml

and add the following lines for creating new users with admin and manager privilegies as described in Tomcat's main page





Obviously if you want only one kind of role you've to delete the one you are not interested in. Example only admin




Installing new servlet or jsp pages in Tomcat5

Using the Tomcat manager included in the installed packages you'll be able to to control your servlet/jsp properly.

1.Enter in your server (by default 127.0.0.1:8180).

2.Enter in the Tomcat manager page (you find the link on the left) typing username and password chosen in the previous step.

3.Search the section Deploy and in the field WAR or Directory URL type:

file://YOUR SERVLET or JSP PAGE DIRECTORY

Usually servlet/jsp pages are located in the directory /usr/share/tomcat5/webapps.

Tomcat on port 80

If you run Tomcat without a separate web server, but you want it to listen on port 80, then you should redirect port 80 to 8180 with iptables. For this you should create two files:

/etc/network/if-pre-up.d/tomcat5-port80

[ "$IFACE" == "eth0" ] || exit 0;
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport http -j REDIRECT --to-ports 8180

/etc/network/if-post-down.d/tomcat5-port80

[ "$IFACE" == "eth0" ] || exit 0;
iptables -t nat -D PREROUTING -i eth0 -p tcp --dport http -j REDIRECT --to-ports 8180

They must be executable, but only root should be able to modify them (e.g. use chmod 744). Please do also adjust your network interface as needed. After restarting the server, you can access Tomcat on port 80 and 8180.

There are a couple of other possibilities to achieve this goal (see the sections in Securing tomcat and Configuring & Using Apache Tomcat 6). For most situations the given solution should be appropriate. But please pay attention to avoid running Tomcat as root!

Turn of directory listings

For security reasons and to not disturbe guests you might want to turn of directory listings in case of non-existing welcome pages (e.g. if index.html is missing). To do this modify the listings parameter in conf/web.xml:


listings
false

Tuesday, April 20, 2010

Python connecting to MS SQL Server 2008

def adodbapi_connection (server, database, username, password):
import adodbapi
connectors = ["Provider=SQLOLEDB"]
connectors.append ("Data Source=%s" % server)
connectors.append ("Initial Catalog=%s" % database)
if username:
connectors.append ("User Id=%s" % username)
connectors.append ("Password=%s" % password)
else:
connectors.append("Integrated Security=SSPI")
return adodbapi.connect (";".join (connectors))

def pymssql_connection (server, database, username, password):
import pymssql
if not username:
raise RuntimeError, "Unable to use NT authentication for pymssql"
return pymssql.connect (user=username, password=password,
host=server, database=database)

def pyodbc_connection (server, database, username, password):
import pyodbc
connectors = ["Driver={SQL Server}"]
connectors.append ("Server=%s" % server)
connectors.append ("Database=%s" % database)
if username:
connectors.append ("UID=%s" % username)
connectors.append ("PWD=%s" % password)
else:
connectors.append ("TrustedConnection=Yes")
return pyodbc.connect (";".join (connectors))

Obtaining IP Address for Android Phone SDK

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);

public String intToIp(int i) {

return ((i >> 24 ) & 0xFF ) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
( i & 0xFF) ;
}

Thursday, February 25, 2010

Haiku with out category 2

"Empty Painting"

color mixed into one for good.
abstract cannot visualize by thoughts.
brush defined by its stroke.

By: John Paul Mamaril

My Haiku without Category

Haiku without any Category.

"Lonely Path"

Lonely Hearts on February.
Angels Began to sing quietly
White Became Black in Breeze.

By: John Paul Mamaril