Multiply [ C , PERL , PHP CLI , JAVA , C Sharp ]

เจอ bug + error อะไรก็ปลงๆมั่ง เขียนไม่ค่อยเป็น -0-“

Multiply [ C ]

Multiply [ JAVA ]

Multiply [ PERL ]

Multiply [ PHP CLI ]

Multiply [ C Sharp ]

ปล. case 2 : print Exit… ด้วยนะ ลืมใส่ -_-”

Android: ทำ SplashScreen ง่ายนิดเดียว

บทความนี้เป็นตัวอย่างของการทำ Splash Screen หรือหน้า Intro ก่อนเข้า Application ใน Android นะ

ตัวอย่าง Source Code สามารถ Download ได้ที่นี้ SplashScreenDemo

1. สร้าง Android Project ใหม่

Create Project Part1

Create Project Part2

2. สร้าง Layout ของหน้า SplashScreen ใน Folder layout

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#FFF”>
<ImageView android:layout_gravity=”center”
android:src=”@drawable/android”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>

3. สร้าง Activity Class สำหรับหน้า SplashScreen ใน Folder src

public class SplashScreenActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
}

}

การทำ SplashScreen โดยใช้ Handler

3.1 การใช้ Handler สำหรับทำ Splash Screen นั้นสามารถทำได้โดยใช้ Method ของ Handler ที่ชื่อว่า postDelayed(Runnable, DelayedTime)

Runnable: คือ Process ที่จะกำหนดให้กับตัว Handler
ในตัวอย่างคือเรียกคำสั่ง finsish() เพื่อปิด Activity ปัจจุบัน
จากนั้นจึงเรียกคำสั่ง startActivty เพื่อเปิดหน้า Activity หลักของ Application ขึ้นมา

DelayedTime: คือเวลาที่เมื่อผ่านไปตามที่กำหนดแล้วจะเรียก Runnable ขึ้นมาทำงาน มีหน่วยของเวลาเป็น Millisecond (1000 Millisecond = 1 Second)
ในตัวอย่างกำหนดไว้ 2000 Millisecond หรือ 2 Second

private Handler mHandler;
mHandler = new Handler();// Call postDelayed Method for running process after delay time
mHandler.postDelayed(new Runnable() {@Override
public void run() {
finish();
startActivity(new Intent(SplashScreenActivity.this,
MainActivity.class));
}}, 2000);

การทำ SplashScreen โดยใช้ Thread

3.2 การใช้ Thread สำหรับทำ Splash Screen ทำได้โดยสร้าง Thread ขึ้นมาใหม่และใช้คำสั่ง start เพื่อสั่งให้ Thread ทำงาน และใน Thread ให้ทำการ Override Method run() จากนั้นจึงใช้คำสั่ง sleep(time) เข้ามาช่วยทำ SplashScreen

sleep เป็นคำสั่งให้หยุดทำงาน โดยเราสามารถกำหนดเวลาที่ต้องการสั่งให้ Thread หยุดทำงานได้ ซึ่งหน่วยของเวลาคือ Millisecond หลังจากสั่งให้หยุดทำงานเสร็จจึงเรียกใช้ Method finish() เพื่อสั่งปิด Activity ปัจจุบัน และตามด้วย Method startActivity เพื่อเปิดหน้า Activity หลักของ Application

new Thread() {

@Override
public void run() {
try {
sleep(2000);
finish();
startActivity(new Intent(SplashScreenActivity.this,
MainActivity.class));
} catch (Exception e) {
e.printStackTrace();
}
}

}.start();

4. แทรก Activty Tag ในไฟล์ AndroidManifest.xml

ทำการเปลี่ยน Activity แรกสุดที่จะถูกเรียกเป็น SplashScreenActivty และทำการแทรก Activity Tag ของ Class Activity หลักของ Application

<activity android:name=”.SplashScreenActivity”  android:label=”@string/app_name”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.MainActivity”>
</activity>

Output:

1. แสดงหน้า Activity ของ SplashScreen ที่สร้างขึ้น

Output 01

2. หลังจากผ่านไป 2 วินาที ก็จะปิดหน้า SplashScreen ปัจจุบันและเรียกหน้า Activity หลักของ Application ขึ้นมา

Output 02

credit : http://puyblog.piscessera.com/android-ทำ-splashscreen-ง่ายนิดเดียว
               http://lookpat.wordpress.com/2012/01/19/android-ทำ-splashscreen-ง่ายนิดเดียว/ 

สถาปัตยกรรมของ Android

1. Linux Kernel – เป็น kernel ที่ใช้สร้าง Android ประกอบด้วย Low-level device driver สำหรับองค์ประกอบทาง Hardware ต่างๆของอุปกรณ์ Android

2. Libraries- มี Code ที่ให้ Feature หลักๆของ Android OS เช่น
– SQLite library เพื่อให้ App สามารถเรียกใช้ในการเก็บข้อมูล
– WebKit library ให้ function ในการทำ web browsing

3. Android runtime- อยู่ layer เดียวกับ libraries ซึ่งตัว Android runtime จะให้
– Set ของ Core library : ให้ developer สามารถเขียน Android App โดยใช้ภาษา Java
– Dalvik virtual machine : ให้ Android App สามาถทำงานได้ใน process ของตน เป็น instance ของ Dalvik virtual machine (Android App ถูก compile เป็น Dalvik executable)
– Dalvik เป็น VM ที่ถูกออกแบบโดยเฉพาะสำหรับ Android และถูก optimize สำหรับมือถือที่ใช้ battery ให้พลังงานที่มี memory และ CPU จำกัด

4. Application framework -ความสามารถของ Android ที่ developer สามารถนำไปใช้ในการพัฒนา App ได้

5. Application – ติดอยู่กับอุปกรณ์ Android หรือใช้งาน เช่น โทรศัพท์,Browser,Contacts, App ที่ download และ install จาก market

ที่มา :  http://lookpat.wordpress.com
http://ubuntuone.com

How to : compile c with Notepad++

**COMMAND :
gcc $(FULL_CURRENT_PATH) -o $(FULL_CURRENT_PATH).exe
cmd /K gcc $(FULL_CURRENT_PATH) -o $(FULL_CURRENT_PATH).exe
(/K = Run Command and then return to the CMD prompt. This is useful for testing, to examine variables)

**Note
You Must Install MinGW or DevC
if use “gcc $(FULL_CURRENT_PATH) -o $(FULL_CURRENT_PATH).exe” or cmd /K gcc $(FULL_CURRENT_PATH) -o $(FULL_CURRENT_PATH).exe dose’n work
please change “gcc” to “gcc directory”
Example : “C:\MinGW\bin\gcc.exe $(FULL_CURRENT_PATH) -o $(FULL_CURRENT_PATH).exe

ตาราง Enviroment ของ Notepad++
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Defining_User_Commands

HqRxD8yHIWU

Perl : 3 Ways to Clear Screen Cross-Platform

1. Use : Term::Screen:Uni

require Term::Screen::Uni;
my $scr = new Term::Screen::Uni;
$scr->clrscr()

^
^
$scr->clrscr()

2. Use : Term::ANSIScreen

use Term::ANSIScreen qw(cls);
cls();

3. Use : this method does not require the user to install some cpan module!

print "\033[2J"; #clear the screen
print "\033[0;0H"; #jump to 0,0

Cr. http://stackoverflow.com/questions/197933/whats-the-best-way-to-clear-the-screen-in-perl

Nmap Cheat Sheet

Nmap Cheat Sheet

Basic Scanning Techniques

Scan a single target —> nmap [target]

Scan multiple targets —> nmap [target1,target2,etc]

Scan a list of targets —-> nmap -iL [list.txt]

Scan a range of hosts —-> nmap [range of IP addresses]

Scan an entire subnet —-> nmap [IP address/cdir]

Scan random hosts —-> nmap -iR [number]

Excluding targets from a scan —> nmap [targets] –exclude [targets]

Excluding targets using a list —> nmap [targets] –excludefile [list.txt]

Perform an aggressive scan —> nmap -A [target]

Scan an IPv6 target —> nmap -6 [target]

Discovery Options

Perform a ping scan only —> nmap -sP [target]

Don’t ping —> nmap -PN [target]

TCP SYN Ping —> nmap -PS [target]

TCP ACK ping —-> nmap -PA [target]

UDP ping —-> nmap -PU [target]

SCTP Init Ping —> nmap -PY [target]

ICMP echo ping —-> nmap -PE [target]

ICMP Timestamp ping —> nmap -PP [target]

ICMP address mask ping —> nmap -PM [target]

IP protocol ping —-> nmap -PO [target]

ARP ping —> nmap -PR [target]

Traceroute —> nmap –traceroute [target]

Force reverse DNS resolution —> nmap -R [target]

Disable reverse DNS resolution —> nmap -n [target]

Alternative DNS lookup —> nmap –system-dns [target]

Manually specify DNS servers —> nmap –dns-servers [servers] [target]

Create a host list —-> nmap -sL [targets]

Advanced Scanning Options

TCP SYN Scan —> nmap -sS [target]

TCP connect scan —-> nmap -sT [target]

UDP scan —-> nmap -sU [target]

TCP Null scan —-> nmap -sN [target]

TCP Fin scan —> nmap -sF [target]

Xmas scan —-> nmap -sX [target]

TCP ACK scan —> nmap -sA [target]

Custom TCP scan —-> nmap –scanflags [flags] [target]

IP protocol scan —-> nmap -sO [target]

Send Raw Ethernet packets —-> nmap –send-eth [target]

Send IP packets —-> nmap –send-ip [target]

Port Scanning Options

Perform a fast scan —> nmap -F [target]

Scan specific ports —-> nmap -p [ports] [target]

Scan ports by name —-> nmap -p [port name] [target]

Scan ports by protocol —-> nmap -sU -sT -p U:[ports],T:[ports] [target]

Scan all ports —-> nmap -p “*” [target]

Scan top ports —–> nmap –top-ports [number] [target]

Perform a sequential port scan —-> nmap -r [target]

Version Detection

Operating system detection —-> nmap -O [target]

Submit TCP/IP Fingerprints —-> www.nmap.org/submit/

Attempt to guess an unknown —-> nmap -O –osscan-guess [target]

Service version detection —-> nmap -sV [target]

Troubleshooting version scans —-> nmap -sV –version-trace [target]

Perform a RPC scan —-> nmap -sR [target]

Timing Options

Timing Templates —-> nmap -T [0-5] [target]

Set the packet TTL —-> nmap –ttl [time] [target]

Minimum of parallel connections —-> nmap –min-parallelism [number] [target]

Maximum of parallel connection —-> nmap –max-parallelism [number] [target]

Minimum host group size —–> nmap –min-hostgroup [number] [targets]

Maximum host group size —-> nmap –max-hostgroup [number] [targets]

Maximum RTT timeout —–> nmap –initial-rtt-timeout [time] [target]

Initial RTT timeout —-> nmap –max-rtt-timeout [TTL] [target]

Maximum retries —-> nmap –max-retries [number] [target]

Host timeout —-> nmap –host-timeout [time] [target]

Minimum Scan delay —-> nmap –scan-delay [time] [target]

Maximum scan delay —-> nmap –max-scan-delay [time] [target]

Minimum packet rate —-> nmap –min-rate [number] [target]

Maximum packet rate —-> nmap –max-rate [number] [target]

Defeat reset rate limits —-> nmap –defeat-rst-ratelimit [target]

Firewall Evasion Techniques

Fragment packets —-> nmap -f [target]

Specify a specific MTU —-> nmap –mtu [MTU] [target]

Use a decoy —-> nmap -D RND: [number] [target]

Idle zombie scan —> nmap -sI [zombie] [target]

Manually specify a source port —-> nmap –source-port [port] [target]

Append random data —-> nmap –data-length [size] [target]

Randomize target scan order —-> nmap –randomize-hosts [target]

Spoof MAC Address —-> nmap –spoof-mac [MAC|0|vendor] [target]

Send bad checksums —-> nmap –badsum [target]

Output Options

Save output to a text file —-> nmap -oN [scan.txt] [target]

Save output to a xml file —> nmap -oX [scan.xml] [target]

Grepable output —-> nmap -oG [scan.txt] [target]

Output all supported file types —-> nmap -oA [path/filename] [target]

Periodically display statistics —-> nmap –stats-every [time] [target]

133t output —-> nmap -oS [scan.txt] [target]

Troubleshooting and debugging

Help —> nmap -h

Display Nmap version —-> nmap -V

Verbose output —-> nmap -v [target]

Debugging —-> nmap -d [target]

Display port state reason —-> nmap –reason [target]

Only display open ports —-> nmap –open [target]

Trace packets —> nmap –packet-trace [target]

Display host networking —> nmap –iflist

Specify a network interface —> nmap -e [interface] [target]

Nmap Scripting Engine

Execute individual scripts —> nmap –script [script.nse] [target]

Execute multiple scripts —-> nmap –script [expression] [target]

Script categories —-> all, auth, default, discovery, external, intrusive, malware, safe, vuln

Execute scripts by category —-> nmap –script [category] [target]

Execute multiple scripts categories —-> nmap –script [category1,category2, etc]

Troubleshoot scripts —-> nmap –script [script] –script-trace [target]

Update the script database —-> nmap –script-updatedb

Ndiff

Comparison using Ndiff —-> ndiff [scan1.xml] [scan2.xml]

Ndiff verbose mode —-> ndiff -v [scan1.xml] [scan2.xml]

XML output mode —-> ndiff –xml [scan1.xm] [scan2.xml]

 

Cr. http://pentestlab.wordpress.com

Beginning XHTML

XHTML ลักษณะคล้ายๆ HTML แต่จะเข้มงวดเรื่อง syntax มากกว่า strict มากกว่า HTML
ตัวอย่างเช่น
☻ attribute ต้องเป็นตัวเล็กเท่านั้น
<TITLE> ✘
<title> ✔

☻ ค่าใน attribute ต้องใส่ ”
<img src=pic.jpg /> ✘
<img src=”pic.jpg” /> ✔

☻ ต้องมี / ปิดท้ายด้วยเสมอ
<br> ✘
<br /> ✔

☻ attributeใช้ id แทน name
<img src=”pic.jpg” name=”image” /> ✘
<img src=”pic.jpg” id=”image” /> ✔

☻ การเปิดปิด tag ต้องทำให้ถูกต้องถูกลำดับ
<b><i>xhtml</b></i> ✘
<b><i>xhtml</i></b> ✔

☻ XHTML ต้องใส่ DOCTYPE ไว้ด้านบนสุดเสมอ
(More : http://www.w3schools.com/tags/tag_doctype.asp)
แนะนำให้ใช้ XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

☻ เลิกใช้การประกาศ Language Attribute
<script language=”javascript” type=”text/javascript” ></script> ✘
<script type=”text/javascript” ></script> ✔

☻ XHTMLL ไม่สามารถใช้ Characters แบบตรงๆได้
(More : http://www.ascii.cl/htmlcodes.htm)
<title>hello >>TEST<< hello</title> ✘
<title>hello &gt;&gt;TEST &lt;&lt; hello</title> ✔

☻ ห้ามย่อค่าของ attributes
<option selected> ✘
<option selected=”selected”> ✔

☻ สำหรับการกำหนดลักษณะต่างๆ กำหรดรูปแบบ ขนาดต่างๆ ในบาง elements XHTML ห้ามใช้ attributes บางอย่าง ให้เราไปใช้ style แทน
ปล. XHTML จะเหมาะกับการใช้ร่วมกับ CSS มากกว่า
<td background=”pic.jpg”></td> ✘
<td style=”background-image:url(‘pic.jpg’);”></td> ✔

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
✎ <a> Must not contain other <a> elements.
✎ <pre> Must not contain the <img>, <object>, <big>, <small>, <sub>, or <sup> elements.
✎ <button> Must not contain the <input>, <select>, <textarea>, <label>, <button>, <form>, <fieldset>, <iframe> or <isindex> elements.
✎ <label> Must not contain other <label> elements.
✎ <form> Must not contain other <form> elements.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
ตัวอย่างการเขียน XHTML
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title></title>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ />
</head>
<body></body>
</html>
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
The <marquee></marquee> tag creates a scrolling text marquee. This tag is not part of the XHTML specification
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
XHTML Reference
http://www.w3schools.com/tags/default.asp
http://xhtml.com/en/xhtml/reference/
http://www.december.com/html/x1tran/– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Markup Validation Service (ตรวจสอบความถูกต้องของโค้ด)
http://validator.w3.org/#validate_by_upload
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
attributes = คุณสมบัติ , ลักษณะ
elements = องค์ประกอบ

Perl : PDF album Downloader [ SS : GUI ]

SS : เป็นแบบ GUI นะครับ แต่โค้ดด้านล่างเป็นแบบธรรมดา ^^”


#!/usr/bin/perl
#########################################################################
# ░░░░░░░░░░░░▄▄░░░░░░░░░░░░░░ Copyright (c) 2012 by sornram9254.com
# ░░░░░░░░░░░█░░█░░░░░░░░░░░░░
# ░░░░░░░░░░░█░░█░░░░░░░░░░░░░ This software is open source,
# ░░░░░░░░░░█░░░█░░░░░░░░░░░░░ licensed under the GNU/GPL,v3.0
# ░░░░░░░░░█░░░░█░░░░░░░░░░░░░
# ██████▄▄█░░░░░██████▄░░░░░░░ Basically,
# ▓▓▓▓▓▓█░░░░░░░░░░░░░░█░░░░░░ this means that you're allowed to modify and
# ▓▓▓▓▓▓█░░░░░░░░░░░░░░█░░░░░░ distribute this software.
# ▓▓▓▓▓▓█░░░░░░░░░░░░░░█░░░░░░ However, if you distribute modified versions,
# ▓▓▓▓▓▓█░░░░░░░░░░░░░░█░░░░░░ you MUST also distribute the source code.
# ▓▓▓▓▓▓█░░░░░░░░░░░░░░█░░░░░░
# ▓▓▓▓▓▓█████░░░░░░░░░██░░░░░░ See http://www.gnu.org/licenses/gpl.html
# █████▀░░░░▀▀████████░░░░░░░░ for the full license.
#########################################################################
use LWP::Simple;
print "Create new Album...\nName : ";
$album = ;
mkdir($album);
my $ua = LWP::UserAgent->new();
my $content = $ua->get('http://www.eduunix.ccut.edu.cn/index/pdf/')->content;
print "=============================================\n";
print "Please wait to Download...\n";
print "=============================================\n";
while($content =~ m/<\/td>/g){
$file = $1;
$url = "http://www.eduunix.ccut.edu.cn/index/pdf/".$file;
print "Getting ==> $file ..\n";
my $data = LWP::Simple::get $url;
my $filename = $file;
open (FH, "> /home/sornram9254/$album/$filename");
binmode (FH);
print FH $data;
close (FH);
print "\tDone ..\n";
sleep(1);
}

 

 

อยากได้ลูกเล่นอะไรเพิ่มเติมก็ลองไปโมฯกันเองนะครับ ^_^

สาเหตที่ทำให้ผมหลงใหล Perl :)

อ่าห์...
ยอดเยี่ยมจริงๆ :D
นี่แหละครับเป็นสาเหตที่ทำให้ผมหลงไหลภาษา Perl
สาเหตหลักๆก็มี 2 ประการ
1. สามารถเขียนเว็บไซต์ได้ ความสามารถไม่แพ้ php
2. สามารถใช้เขียนโปรแกรมได้ด้วย ทั้งแบบ command line และแบบ gui ซึ่งภาษาอื่นทำไม่ได้ มีไกล้เคียงหน่อยก็ php แต่ php ก็ทำได้แค่แบบ command line เท่านั้น ^^"

Change Apache Ports [Ubuntu]

Change Apache Ports [Ubuntu]
1.
sudo gedit /etc/apache2/ports.conf
2.
NameVirtualHost *:80 <– เปลี่ยนเป็นหมายเลข port ที่ต้องการ
Listen 80 <– เปลี่ยนเป็นหมายเลข port ที่ต้องการ
3.
sudo gedit /etc/apache2/sites-available/default
4.
<VirtualHost *:80>  <– เปลี่ยนเป็นหมายเลข port ที่ต้องการ
5.
sudo /etc/init.d/apache2 restart