13 December 2010

java JDBC MySQL Connect

java JDBC MySQL Connect Table: test
ID Name
1 A
2 B
3 C

import java.io.File;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {   
    public static void main(String args[]) {
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost","USERNAME", "PASSWORD");
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from test");
            int count = 0;
            while(rs.next())
            {
                System.out.println("ID : " + rs.getString(0));
                System.out.println("NAME : " + rs.getString(1));
                count++;
            }
            System.out.println("sum = "+count);
            
            } catch(Exception e) {
            e.printStackTrace();
            System.out.println("Exception: " + e.getMessage());
            } finally {
            try {
                if(con != null)
                con.close();
        } catch(SQLException e) {}
        }
    }
}

11 December 2010

List āļŠื่āļ­āđ„āļŸāļĨ์āđƒāļ™ Directory - java

List āļŠื่āļ­āđ„āļŸāļĨ์āđƒāļ™ Directory āļ”้āļ§āļĒ java āļ­่āļēāļ™āļŠื่āļ­āđ„āļŸāļĨ์āļ—ั้āļ‡āļŦāļĄāļ”āđƒāļ™ Directory āļ•ัāļ§āļ­āļĒ่āļēāļ‡ āđāļŠāļ”āļ‡āđ€āļ‰āļžāļēāļ° .txt āđāļĨāļ° .TXT
import java.io.File;
public class ListFiles
{
    public static void main(String[] args)
    {
        // Directory path here
        String path = ".";
        String files_name;
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();
        for (int i = 0; i < listOfFiles.length; i++)
        {
            if (listOfFiles[i].isFile())
            {
                files_name = listOfFiles[i].getName();
                if (files_name.endsWith(".txt") || files_name.endsWith(".TXT"))
                {
                    System.out.println(files_name);
                }
            }
        }
    }
}

23 November 2010

URLReader - java

URLReader āļ”้āļ§āļĒ java āļ­่āļēāļ™ HTML code āļˆāļēāļāđ€āļ§็āļš
import java.net.*;
import java.io.*;
public class URLReader  {
    public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.google.com");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(
        url.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
        in.close();
    }
}

16 October 2010

āļāļēāļĢāđƒāļŠ้āļ‡āļēāļ™ āđāļĨāļ° config github āđ€āļšื้āļ­āļ‡āļ•้āļ™

āļāļēāļĢāđƒāļŠ้āļ‡āļēāļ™ āđāļĨāļ° config github āđ€āļšื้āļ­āļ‡āļ•้āļ™ - āļŠāļĄัāļ„āļĢāļŠāļĄāļēāļŠิāļ github āļ—ี่
- āļŠāļĢ้āļēāļ‡ Github Repository āđ‚āļ”āļĒāđ€āļĨืāļ­āļāļ—ี่
āļāļĢāļ­āļāļĢāļēāļĒāļĨāļ°āđ€āļ­ีāļĒāļ”āđƒāļŦ้āļ„āļĢāļš āļŦāļĨัāļ‡āļˆāļēāļāļ™ั้āļ™āļˆāļ°āđ€āļŦ็āļ™āļāļēāļĢāđāļ™āļ°āļ™āļģāļ‚ั้āļ™āļ•āļ­āļ™āļāļēāļĢāđƒāļŠ้āļ‡āļēāļ™
#Global setup:
#Set up git
  git config --global user.name "Chagridsada  Boonthus"
  git config --global user.email mr.tumcpe@gmail.com
      
#Next steps:
  mkdir chagridsada-blog
  cd chagridsada-blog
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin https://github.com/chagridsada/chagridsada-blog.git
  git push -u origin master
      
#Existing Git Repo?
  cd existing_git_repo
  git remote add origin https://github.com/chagridsada/chagridsada-blog.git
  git push -u origin master   

#Importing a Subversion Repo?
#Push the repo    
  git remote add origin git@github.com:chagridsada/chagridsada-blog.git
  git push origin master

#When you're done:
#Continue
- Download āđāļĨāļ° āļ•ิāļ”āļ•ั้āļ‡ Git āđ„āļ”้āļ—ี่
- āđ€āļžิ่āļĄ public key āđ€āļžื่āļ­āđƒāļŦ้āļŠāļēāļĄāļēāļĢāļ–āļ•ิāļ”āļ•่āļ­āļัāļš Github āđ„āļ”้āđ‚āļ”āļĒ
1.āļŠāļĢ้āļēāļ‡ public key āđ‚āļ”āļĒāļ”ูāļ‚ั้āļ™āļ•āļ­āļ™āļˆāļēāļ 2.āđ„āļ›āļ—ี่āļŦāļ™้āļē profile āđ€āļĨืāļ­āļ 3.āđ€āļĨืāļ­āļāļ—ี่ 4.āļ™āļģ public key āļ—ี่āđ„āļ”้āļĄāļēāđƒāļŠ่ āđāļĨ้āļ§āļšัāļ™āļ—ึāļ - āļ—āļ”āļŠāļ­āļšāļŠāļĢ้āļēāļ‡ project āļ•āļēāļĄāļ‚ั้āļ™āļ•āļ­āļ™āļ—ี่āđ„āļ”้āļĄāļēāļ•āļ­āļ™āđāļĢāļāđ€āļ›็āļ™āļ­ัāļ™āđ€āļŠāļĢ็āļˆ.

13 October 2010

āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ Apache, PHP, MySQL āđāļĨāļ° phpMyAdmin āļšāļ™ Ubuntu

āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ Apache, PHP, MySQL āđāļĨāļ° phpMyAdmin āļšāļ™ Ubuntu āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ Apache
1. āđ€āļ›ิāļ” Terminal āļˆāļēāļ Applications/Utilities/Terminal āļˆāļēāļāļ™ั้āļ™āđƒāļŦ้āļžิāļĄāļž์āļ„āļģāļŠั่āļ‡āļ™ี้
sudo apt-get install apache2
2. āļŦāļēāļāđƒāļ™ Terminal āđ€āļŦ็āļ™āļ‚้āļ­āļ„āļ§āļēāļĄāļ§่āļē
gksu vi /etc/apache2/conf.d fqdn
āđ€āļĄื่āļ­āđ€āļ›ิāļ”āđ€āļŠāļĢ็āļˆāđāļĨ้āļ§ āđƒāļŦ้āļžิāļĄāļž์ ServerName localhost āļĨāļ‡āđ„āļ›āđƒāļ™āđ„āļŸāļĨ์āđāļĨāļ°āļšัāļ™āļ—ึāļ āļˆāļēāļāļ™ั้āļ™āļ็āļ›ิāļ”āđ„āļŸāļĨ์ 3. āđ€āļĄื่āļ­āļ•ิāļ”āļ•ั้āļ‡āđ€āļŠāļĢ็āļˆāđāļĨ้āļ§ āļ—āļ”āļŠāļ­āļšāđ‚āļ”āļĒāđƒāļƒ้āđ€āļšāļĢāļēāļ§์āđ€āļ‹āļ­āļĢ์ āđāļĨāļ°āđ€āļ›ิāļ” http://localhost
āļŦāļēāļāđƒāļŠ้āļ‡āļēāļ™āđ„āļ”้āļˆāļ°āļžāļšāļ‚้āļ­āļ„āļ§āļēāļĄāļ§่āļē It works!
āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ PHP5
1. āļžิāļĄāļž์āļ„āļģāļŠั่āļ‡
sudo apt-get install php5 libapache2-mod-php5
2. āđ€āļĄื่āļ­āļĨāļ‡ PHP5 āđ€āļŠāļĢ็āļˆāđāļĨ้āļ§āļˆāļģāđ€āļ›็āļ™āļ•้āļ­āļ‡āđ€āļĢิ่āļĄāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡ Apache āļ­ีāļāļ„āļĢั้āļ‡ āļ”้āļ§āļĒāļāļēāļĢāđƒāļŠ้āļ„āļģāļŠั่āļ‡
sudo /etc/init.d/apache2 restart
3. āļ—āļ”āļŠāļ­āļšāļāļēāļĢāđƒāļŠ้āļ‡āļēāļ™ PHP āđ‚āļ”āļĒāļžิāļĄāļž์āļ„āļģāļŠั่āļ‡
sudo vi /var/www/info.php
- āđ€āļĄื่āļ­āđ„āļŸāļĨ์āļ–ูāļāđ€āļ›ิāļ”āļ‚ึ้āļ™āļĄāļēāđāļĨ้āļ§ āđƒāļŦ้āļžิāļĄāļž์āđ‚āļ„้āļ” PHP āļ”ัāļ‡āļ™ี้
<?php
    phpinfo();
?>
    
- āļˆāļēāļāļ™ั้āļ™āđƒāļŦ้āļšัāļ™āļ—ึāļāđ„āļŸāļĨ์āđāļĨāļ°āļ›ิāļ”āđ„āļŸāļĨ์āļ™ี้ 4. āļ—āļ”āļŠāļ­āļšāđ‚āļ”āļĒāđƒāļƒ้āđ€āļšāļĢāļēāļ§์āđ€āļ‹āļ­āļĢ์ āđāļĨāļ°āđ€āļ›ิāļ” http://localhost/info.php āļŦāļēāļāđƒāļŠ้āļ‡āļēāļ™āđ„āļ”้āļˆāļ°āļœāļĨāļ”ัāļ‡āļ™ี้
Display PHP Info
āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ MySQL
1. āļžิāļĄāļž์āļ„āļģāļŠั่āļ‡
sudo apt-get install mysql-server
2. āđ€āļĄื่āļ­āđ€āļŦ็āļ™āļ āļēāļžāļ”ัāļ‡āļ”้āļēāļ™āļĨ่āļēāļ‡āļ™ี้ āđƒāļŦ้āļāļĢāļ­āļāļĢāļŦัāļŠāļœ่āļēāļ™āļŠāļģāļŦāļĢัāļšāļœู้āđƒāļŠ้ root āļƒāļ­āļ‡ MySQL
Configuring mysql-server-5.0
3. āļŦāļĨัāļ‡āļˆāļēāļāļ•ิāļ”āļ•ั้āļ‡āđ€āļŠāļĢ็āļˆ āļˆāļ°āļ•้āļ­āļ‡āđƒāļŦ้ PHP āļ—āļģāļ‡āļēāļ™āļĢ่āļ§āļĄāļัāļš MySQL āđ„āļ”้āđ‚āļ”āļĒāđ€āļ›ิāļ”āđ„āļŸāļĨ์ php.ini āļ”้āļ§āļĒāļ„āļģāļŠั่āļ‡āļ™ี้
gksudo vi /etc/php5/apache2/php.ini
- āļˆāļēāļāļ™ั้āļ™āđāļ้āđ„āļ‚āļšāļĢāļĢāļ—ัāļ”āļ—ี่āļĄี
;extension=msql.so
āđ€āļ›็āļ™
extension=msql.so
- āļ•่āļ­āđ„āļ›āļ็āđ€āļĢิ่āļĄāļāļēāļĢāļ—āļģāļ‡āļēāļ™ Apache āļ­ีāļāļ„āļĢั้āļ‡āļ”้āļ§āļĒāļ„āļģāļŠั่āļ‡
sudo /etc/init.d/apache2 restart
āļāļēāļĢāļ•ิāļ”āļ•ั้āļ‡ phpMyAdmin
1. āļžิāļĄāļž์āļ„āļģāļŠั่āļ‡
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
2. āđ€āļĄื่āļ­āđ€āļŦ็āļ™āļ āļēāļžāļ”ัāļ‡āļ”้āļēāļ™āļĨ่āļēāļ‡āļ™ี้ āđƒāļŦ้āđ€āļĨืāļ­āļ Apache2
Configuring phpmyadmin
3. āļŠāļĢ้āļēāļ‡āļ—āļēāļ‡āļĨัāļ”āđƒāļ™ /var/www
sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
4. āđ€āļĄื่āļ­āļ•ิāļ”āļ•ั้āļ‡āđ€āļŠāļĢ็āļˆāđāļĨ้āļ§ āđƒāļŦ้āļ—āļ”āļŠāļ­āļšāđ‚āļ”āļĒāđƒāļƒ้āđ€āļšāļĢāļēāļ§์āđ€āļ‹āļ­āļĢ์ āđāļĨāļ°āđ€āļ›ิāļ” http://localhost/phpmyadmin āļˆāļ°āđ„āļ”้āļœāļĨāļ”ัāļ‡āļ™ี้
Display phpMyAdmin

09 October 2010

CodeFese2010#8 āļิāļˆāļāļĢāļĢāļĄāđ€āļ‚ีāļĒāļ™āđ‚āļ›āļĢāđāļāļĢāļĄāļĄāļēāļĢāļēāļ˜āļ­āļ™ āļ„āļĢั้āļ‡āļ—ี่ 8

  
āļŠāļ–āļēāļ™āļ—ี่āļˆัāļ”āļิāļˆāļāļĢāļĢāļĄ
 āļ“ āļĄāļŦāļēāļ§ิāļ—āļĒāļēāļĨัāļĒāļžāļēāļĒัāļž āļˆัāļ‡āļŦāļ§ัāļ”āđ€āļŠีāļĒāļ‡āđƒāļŦāļĄ่
āļ§ัāļ•āļ–ุāļ›āļĢāļ°āļŠāļ‡āļ„์
  1. āđ€āļžิ่āļĄāļˆāļģāļ™āļ§āļ™āļ‹āļ­āļŸāļ•์āđāļ§āļĢ์āđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠāļ—ี่āļžัāļ’āļ™āļēāđƒāļ™āļ›āļĢāļ°āđ€āļ—āļĻ āđāļĨāļ°āļĒāļāļĢāļ°āļ”ัāļšāļ„āļ§āļēāļĄāļŠāļēāļĄāļēāļĢāļ–āļ‚āļ­āļ‡āļ™ัāļāļžัāļ’āļ™āļēāđ„āļ—āļĒāđƒāļŦ้āļ—ัāļ”āđ€āļ—ีāļĒāļĄāļัāļšāļ™āļēāļ™āļēāļ›āļĢāļ°āđ€āļ—āļĻ
  2. āđ€āļ›ิāļ”āđ‚āļ­āļāļēāļŠāđƒāļŦ้āļœู้āļ—ี่āļŠāļ™āđƒāļˆāđ„āļ”้āđ€āļžิ่āļĄāļ„āļ§āļēāļĄāļĢู้āđāļĨāļ°āļ—ัāļāļĐāļ°āđƒāļ™āļāļēāļĢāļžัāļ’āļ™āļēāđ‚āļ›āļĢāđāļāļĢāļĄāđāļšāļšāđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āļ‹ี่āļ‡āđ€āļ›็āļ™āļāļēāļĢāđ€āļžิ่āļĄāļĻัāļāļĒāļ āļēāļžāļ”้āļēāļ™āļ§ิāļŠāļēāļŠีāļž
  3. āđ€āļ›็āļ™āļŠื่āļ­āļāļĨāļēāļ‡āļ‚āļ­āļ‡āļ™ัāļāļžัāļ’āļ™āļēāļ—ี่āļĄีāļ„āļ§āļēāļĄāļŠāļ™āđƒāļˆāļĢ่āļ§āļĄāļัāļ™ āđāļĨāļ°āļĄีāļŠ่āļ§āļ™āļŠāļĢ้āļēāļ‡āļŠุāļĄāļŠāļ™āļ™ัāļāļžัāļ’āļ™āļēāđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠāđƒāļŦ้āđ€āļิāļ”āļ‚ึ้āļ™āđƒāļ™
āļĨัāļāļĐāļ“āļ°āļิāļˆāļāļĢāļĢāļĄ
āļˆัāļ”āļิāļˆāļāļĢāļĢāļĄāđƒāļ™āļĢูāļ›āđāļšāļšāļāļēāļĢāđ€āļ‚้āļēāļ„่āļēāļĒāđ€āļ‚ีāļĒāļ™āđ‚āļ›āļĢāđāļāļĢāļĄāļĄāļēāļĢāļēāļ˜āļ­āļ™āđāļšāļšāđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āđ€āļžื่āļ­āđƒāļŦ้āļœู้āđ€āļ‚้āļēāļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄāđ„āļ”้āđ€āļĢีāļĒāļ™āļĢู้āļ§ิāļ˜ีāļāļēāļĢāđāļĨāļ°āļŠิ่āļ‡āđāļ§āļ”āļĨ้āļ­āļĄāđƒāļ™āļāļēāļĢāļžัāļ’āļ™āļē āļ‹āļ­āļŸāļ•์āđāļ§āļĢ์āļˆāļēāļāļ—ีāļĄāļ™ัāļāļ§ิāļˆัāļĒāđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āļ‚āļ­āļ‡āļĻูāļ™āļĒ์āđ€āļ—āļ„āđ‚āļ™āđ‚āļĨāļĒีāļ­ิāđ€āļĨ็āļāļ—āļĢāļ­āļ™ิāļāļŠ์āđāļĨāļ°āļ„āļ­āļĄāļžิāļ§āđ€āļ•āļ­āļĢ์āđāļŦ่āļ‡āļŠāļēāļ•ิ āļ‹ึ่āļ‡āļˆāļ°āđƒāļŦ้āļ„āļģāđāļ™āļ°āļ™āļģāļāļĢāļ°āļšāļ§āļ™āļāļēāļĢāļžัāļ’āļ™āļēāļ‹āļ­āļŸāļ•์āđāļ§āļĢ์āđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āļ•āļĨāļ­āļ”āđ‚āļ„āļĢāļ‡āļāļēāļĢ āļĢāļ§āļĄ 2 āļ§ัāļ™ 1 āļ„ืāļ™ (āļœู้āđ€āļ‚้āļēāļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄāļ•้āļ­āļ‡āļžัāļāļ„้āļēāļ‡āļ„ืāļ™āđƒāļ™āļ„่āļēāļĒ) āļĢāļēāļĒāļĨāļ°āđ€āļ­ีāļĒāļ”āļ”ัāļ‡āļ™ี้
  • āļĢัāļšāļŠāļĄัāļ„āļĢāļœู้āđ€āļ‚้āļēāļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄ 30 āļ„āļ™ (āļžิāļˆāļēāļĢāļ“āļēāļ„ัāļ”āđ€āļĨืāļ­āļāļˆāļēāļāļ„āļ§āļēāļĄāļŠāļ™āđƒāļˆ) āđ‚āļ”āļĒāđ€āļ›ิāļ”āđ‚āļ­āļāļēāļŠāļāļ§้āļēāļ‡āđāļ่āļ™ัāļāđ€āļĢีāļĒāļ™ āļ™ัāļāļĻึāļāļĐāļē āđāļĨāļ° āļšุāļ„āļ„āļĨāļ—ั่āļ§āđ„āļ›āļ—ี่āļĄีāļ„āļ§āļēāļĄāļŠāļ™āđƒāļˆāļˆāļēāļāļ—ั่āļ§āļ›āļĢāļ°āđ€āļ—āļĻ
  • āđ€āļ‡ื่āļ­āļ™āđ„āļ‚āļāļēāļĢāļŠāļĄัāļ„āļĢ āļœู้āļŠāļĄัāļ„āļĢāļ•้āļ­āļ‡āļĄีāļ„āļ§āļēāļĄāļŠāļēāļĄāļēāļĢāļ–āđƒāļ™āļāļēāļĢāđ€āļ‚ีāļĒāļ™āđ‚āļ›āļĢāđāļāļĢāļĄāļĄāļēāļ่āļ­āļ™ āđāļĨāļ°āļĄีāļ„āļ§āļēāļĄāļŠāļ™āđƒāļˆāđ€āļĢีāļĒāļ™āļĢู้āļāļēāļĢāļžัāļ’āļ™āļēāđ‚āļ›āļĢāđāļāļĢāļĄāđāļšāļšāđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āđāļĨāļ°āļ•้āļ­āļ‡āļŠāļēāļĄāļēāļĢāļ–āļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄāđ„āļ”้āļ•āļĨāļ­āļ”āđ‚āļ„āļĢāļ‡āļāļēāļĢ
  • āđƒāļ™āļĢāļ°āļŦāļ§่āļēāļ‡āļāļēāļĢāđ€āļ‚้āļēāļ„่āļēāļĒ āļœู้āļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄāđ€āļ‚้āļēāļāļĨุ่āļĄāļ•āļēāļĄāļ„āļ§āļēāļĄāļŠāļ™āđƒāļˆ āļāļĨุ่āļĄāļĨāļ° 5-7 āļ„āļ™ āļ•āļēāļĄāđ‚āļˆāļ—āļĒ์āļŦัāļ§āļ‚้āļ­āđ‚āļ›āļĢāđāļāļĢāļĄāļ—ี่āļĢāļ°āļšุāđƒāļ™āļ‚ั้āļ™āļ•āļ­āļ™āļĢัāļšāļŠāļĄัāļ„āļĢ
  • āļĢāļ°āļ”āļĄāļŠāļĄāļ­āļ‡āđ€āļžื่āļ­āļāļģāļŦāļ™āļ”āļĢูāļ›āđāļšāļš āđāļĨāļ°āļœāļĨāļĨัāļžāļ˜์āļ‚āļ­āļ‡āļิāļˆāļāļĢāļĢāļĄ
  • āđāļš่āļ‡āļŦāļ™้āļēāļ—ี่āļัāļ™āļ—āļģāļ‡āļēāļ™ āđ€āļžื่āļ­āđƒāļŦ้āđāļ•่āļĨāļ°āļāļĨุ่āļĄāđ„āļ”้āļœāļĨāļĨัāļžāļ˜์āļ—ี่āļ•้āļ­āļ‡āļāļēāļĢ
  • āļ™āļģāđ€āļŠāļ™āļ­āļœāļĨāļ‡āļēāļ™ āđāļĨāļ° āđ€āļ›้āļēāļŦāļĄāļēāļĒāđƒāļ™āļāļēāļĢāļ”āļģāđ€āļ™ิāļ™āļ‡āļēāļ™āļ‚āļ­āļ‡āļāļĨุ่āļĄ
  • āļœāļĨāļĨัāļžāļ˜์āļ—ี่āđ„āļ”้āļˆāļēāļāļิāļˆāļāļĢāļĢāļĄ āļˆāļ°āđ€āļœāļĒāđāļžāļĢ่āđƒāļ™āļĢูāļ›āđāļšāļšāļ‚āļ­āļ‡āđ‚āļ­āđ€āļžāļ™āļ‹āļ­āļĢ์āļŠ āļ—ั้āļ‡āļ‹āļ­āļŸāļ•์āđāļ§āļĢ์ āđāļĨāļ° āļĢāļēāļĒāļ‡āļēāļ™āļ•่āļēāļ‡ āđ†
āļŦัāļ§āļ‚้āļ­āļิāļˆāļāļĢāļĢāļĄ
TwitterTalk v.2 āđ‚āļ”āļĒāđƒāļŠ้āļ āļēāļĐāļē Java

Linux Kiosk āđ‚āļ”āļĒāđƒāļŠ้ Linux shell

āļāļēāļĢāļ„āļ§āļšāļ„ุāļĄāļ­ุāļ›āļāļĢāļ“์āļĢāļ°āļĒāļ°āđ„āļāļĨāļœ่āļēāļ™āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāđ‚āļ—āļĢāļĻัāļžāļ—์ āđ‚āļ”āļĒāđƒāļŠ้āļ āļēāļĐāļē C āđāļĨāļ° PHP
āļāļģāļŦāļ™āļ”āļāļēāļĢ
āļ§ัāļ™āļĻุāļāļĢ์āļ—ี่ 8 āļ•ุāļĨāļēāļ„āļĄ 2553
08.00āļ™.-09.00āļ™. āļĨāļ‡āļ—āļ°āđ€āļšีāļĒāļ™āļœู้āđ€āļ‚้āļēāļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄ
09.00āļ™.-09.30āļ™. āļžิāļ˜ีāđ€āļ›ิāļ”
09.30āļ™.-10.30āļ™. āļšāļĢāļĢāļĒāļēāļĒāļĢāļēāļĒāļĨāļ°āđ€āļ­ีāļĒāļ” āđ€āļ‡ื่āļ­āļ™āđ„āļ‚ āđāļĨāļ°āļ āļēāļĢāļิāļˆ
10.30āļ™.-12.00āļ™. āļšāļĢāļĢāļĒāļēāļĒāđ€āļ—āļ„āļ™ิāļ„ āđāļ™āļ°āļ™āļģāļ•ัāļ§āļœู้āđ€āļ‚้āļēāļĢ่āļ§āļĄāļิāļˆāļāļĢāļĢāļĄ āđāļĨāļ°āđāļš่āļ‡āļāļĨุ่āļĄ
12.00āļ™.-13.00āļ™. āļĢัāļšāļ›āļĢāļ°āļ—āļēāļ™āļ­āļēāļŦāļēāļĢāļāļĨāļēāļ‡āļ§ัāļ™
13.00āļ™.-15.00āļ™. āļ›āļĢāļ°āļŠุāļĄāļāļĨุ่āļĄāđāļĨāļ°āļ§āļēāļ‡āđāļœāļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™
15.00āļ™.-18.00āļ™. āļžัāļ’āļ™āļēāđ‚āļ›āļĢāđāļāļĢāļĄ
18.00āļ™.-19.00āļ™. āļĢัāļšāļ›āļĢāļ°āļ—āļēāļ™āļ­āļēāļŦāļēāļĢāđ€āļĒ็āļ™
19.00āļ™. āđ€āļ›็āļ™āļ•้āļ™āđ„āļ› āļžัāļ’āļ™āļēāđ‚āļ›āļĢāđāļāļĢāļĄ āļŦāļĢืāļ­āļžัāļāļœ่āļ­āļ™
āļ§ัāļ™āđ€āļŠāļēāļĢ์āļ—ี่ 9 āļ•ุāļĨāļēāļ„āļĄ 2553
07.30āļ™.-08.30āļ™. āļĢัāļšāļ›āļĢāļ°āļ—āļēāļ™āļ­āļēāļŦāļēāļĢāđ€āļŠ้āļē
08.30āļ™.-12.00āļ™. āļžัāļ’āļ™āļēāđ‚āļ›āļĢāđāļāļĢāļĄ
12.00āļ™.-13.00āļ™. āļĢัāļšāļ›āļĢāļ°āļ—āļēāļ™āļ­āļēāļŦāļēāļĢāļāļĨāļēāļ‡āļ§ัāļ™
13.00āļ™.-15.00āļ™. āđ€āļ•āļĢีāļĒāļĄāļŠāļĢุāļ›āļœāļĨāđāļĨāļ°āđ€āļ•āļĢีāļĒāļĄāļ™āļģāđ€āļŠāļ™āļ­āļœāļĨāļ‡āļēāļ™
15.00āļ™.-16.30āļ™. āļ™āļģāđ€āļŠāļ™āļ­āļœāļĨāļ‡āļēāļ™
16.30āļ™.-17.00āļ™. āļžิāļ˜ีāļ›ิāļ”
āļ āļēāļžāļิāļˆāļāļĢāļĢāļĄ

 
...............................................................................................
http://gallery.opentle.org/v/2010108_09_CodeFest8/

08 October 2010

CodeFese2010#8 āđ‚āļ„āļ”āđ‚āļ›āļĢāđāļāļĢāļĄ Embed

CodeFese2010#8 āđ‚āļ„āļ”āđ‚āļ›āļĢāđāļāļĢāļĄ Embed embed.c
#include "stdio.h"
#include "fcntl.h"
#include "getopt.h"
#include "unistd.h"
#include "stdlib.h"
#include "errno.h"
#include "string.h"
#include "sys types.h"
#include "sys stat.h"
#include "24cXX.h"
#include "sys socket.h"
#include "netinet in.h"
#include "netdb.h"
 
#define VERSION     "0.7.6"
#define ENV_DEV        "EEPROG_DEV"
#define ENV_I2C_ADDR    "EEPROG_I2C_ADDR"
 
int g_quiet;
 
#define usage_if(a) do { do_usage_if( a , __LINE__); } while(0);
void do_usage_if(int b, int line)
{
const static char *eeprog_usage =
"eeprog " VERSION ", a 24Cxx EEPROM reader/writer\n"
"Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.\n"
"Usage: eeprog [-fqxdh] [-16|-8] [ -r addr[:count] | -w addr ]  /dev/i2c-N  i2c-address\n"
"\n"
"  Address modes: \n"
"    -8        Use 8bit address mode for 24c0x...24C16 [default]\n"
"    -16        Use 16bit address mode for 24c32...24C256\n"
"  Actions: \n"
"    -r addr[:count]    Read [count] (1 if omitted) bytes from [addr]\n"
"            and print them to the standard output\n"
"    -w addr        Write input (stdin) at address [addr] of the EEPROM\n"
"    -h        Print this help\n"
"  Options: \n"
"    -x        Set hex output mode\n"
"    -d        Dummy mode, display what *would* have been done\n"
"    -f        Disable warnings and don't ask confirmation\n"
"    -q        Quiet mode\n"
"\n"
"The following environment variables could be set instead of the command\n"
"line arguments:\n"
"    EEPROG_DEV        device name(/dev/i2c-N)\n"
"    EEPROG_I2C_ADDR        i2c-address\n"
"\n"
"    Examples\n"
"    1- read 64 bytes from the EEPROM at address 0x54 on bus 0 starting\n"
"       at address 123 (decimal)\n"
"        eeprog /dev/i2c-0 0x54 -r 123:64\n"
"    2- prints the hex codes of the first 32 bytes read from bus 1 \n"
"       at address 0x22\n"
"        eeprog /dev/i2c-1 0x51 -x -r 0x22:0x20\n"
"    3- write the current timestamp at address 0x200 of the EEPROM on \n"
"       bus 0 at address 0x33 \n"
"        date | eeprog /dev/i2c-0 0x33 -w 0x200\n";
 
    if(!b)
        return;
    fprintf(stderr, "%s\n[line %d]\n", eeprog_usage, line);
    exit(1);
}
 
 
#define die_if(a, msg) do { do_die_if( a , msg, __LINE__); } while(0);
void do_die_if(int b, char* msg, int line)
{
    if(!b)
        return;
    fprintf(stderr, "Error at line %d: %s\n", line, msg);
    //fprintf(stderr, "    sysmsg: %s\n", strerror(errno));
    exit(1);
}
 
#define print_info(args...) do { if(!g_quiet) fprintf(stderr, args); } while(0);
 
void parse_arg(char *arg, int* paddr, int *psize)
{
    char *end;
    *paddr = strtoul(arg, &end, 0);
    if(*end == ':')
        *psize = strtoul(++end, 0, 0);
}
 
int confirm_action()
{
    fprintf(stderr,
    "\n"
    "____________________________WARNING____________________________\n"
    "Erroneously writing to a system EEPROM (like DIMM SPD modules)\n"
    "can break your system.  It will NOT boot anymore so you'll not\n"
    "be able to fix it.\n"
    "\n"
    "Reading from 8bit EEPROMs (like that in your DIMM) without using\n"
    "the -8 switch can also UNEXPECTEDLY write to them, so be sure to\n"
    "use the -8 command param when required.\n"
    "\n"
    "Use -f to disable this warning message\n"
    "\n"
    "Press ENTER to continue or hit CTRL-C to exit\n"
    "\n"
    );
    getchar();
    return 1;
}
 
int read_from_eeprom(struct eeprom *e, int addr, int size, int hex ,int *ar)
{
    int ch, i,arr=0;
    for(i = 0; i < size; ++i, ++addr)
    {
        die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error");
        if(hex)
        {
            if( (i % 16) == 0 )
                printf("\n %.4x|  ", addr);
            else if( (i % 8) == 0 )
                printf("  ");
            
            if(!(i%2==1)){
                ar[arr]= ch;
                arr++;
            }
        } else
            putchar(ch);
    }
    if(hex)
        printf("\n");
    fflush(stdout);
    return 0;
}
 
int write_to_eeprom(struct eeprom *e, int addr)
{
    int c;
    while((c = getchar()) != EOF)
    {
        print_info(".");
        fflush(stdout);
        die_if(eeprom_write_byte(e, addr++, c), "write error");
    }
    print_info("\n");
    return 0;
}
 
int main(int argc, char** argv)
{
    struct eeprom e;
    int ret, op, i2c_addr, memaddr, size, want_hex, dummy, force, sixteen;
    char *device, *arg = 0, *i2c_addr_s;
    struct stat st;
    int eeprom_type = 0;
 
    op = want_hex = dummy = force = sixteen = 0;
    g_quiet = 0;
 
    while((ret = getopt(argc, argv, "1:8fr:qhw:xd")) != -1)
    {
        switch(ret)
        {
        case '1':
            usage_if(*optarg != '6' || strlen(optarg) != 1);
            die_if(eeprom_type, "EEPROM type switch (-8 or -16) used twice");
            eeprom_type = EEPROM_TYPE_16BIT_ADDR;  
            break;
        case 'x':
            want_hex++;
            break;
        case 'd':
            dummy++;
            break;
        case '8':
            die_if(eeprom_type, "EEPROM type switch (-8 or -16) used twice");
            eeprom_type = EEPROM_TYPE_8BIT_ADDR;
            break;
        case 'f':
            force++;
            break;
        case 'q':
            g_quiet++;
            break;
        case 'h':
            usage_if(1);
            break;
        default:
            die_if(op != 0, "Both read and write requested");
            arg = optarg;
            op = ret;
        }
    }
    if(!eeprom_type)
        eeprom_type = EEPROM_TYPE_8BIT_ADDR; // default
 
    usage_if(op == 0); // no switches
    // set device and i2c_addr reading from cmdline or env
    device = i2c_addr_s = 0;
    switch(argc - optind)
    {
    case 0:
        device = getenv(ENV_DEV);
        i2c_addr_s = getenv(ENV_I2C_ADDR);
        break;
    case 1:
        if(stat(argv[optind], &st) != -1)
        {
            device = argv[optind];
            i2c_addr_s = getenv(ENV_I2C_ADDR);
        } else {
            device = getenv(ENV_DEV);
            i2c_addr_s = argv[optind];
        }
        break;
    case 2:
        device = argv[optind++];
        i2c_addr_s = argv[optind];
        break;
    default:
        usage_if(1);
    }
    usage_if(!device || !i2c_addr_s);
    i2c_addr = strtoul(i2c_addr_s, 0, 0);
 
    print_info("eeprog %s, a 24Cxx EEPROM reader/writer\n", VERSION);
    print_info("Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.\n");
    print_info("  Bus: %s, Address: 0x%x, Mode: %dbit\n",
            device, i2c_addr,
            (eeprom_type == EEPROM_TYPE_8BIT_ADDR ? 8 : 16) );
    if(dummy)
    {
        fprintf(stderr, "Dummy mode selected, nothing done.\n");
        return 0;
    }
    die_if(eeprom_open(device, i2c_addr, eeprom_type, &e) < 0,
            "unable to open eeprom device file "
            "(check that the file exists and that it's readable)");
    switch(op)
    {
    case 'r':
        if(force == 0)
            confirm_action();
        size = 1; // default
        parse_arg(arg, &memaddr, &size);
        print_info("  Reading %d bytes from 0x%x\n", size, memaddr);
        int ar[3],i,j,x[2],y[2],z[2];
        while(1){
            for(i=0;i<2;i++){
                read_from_eeprom(&e, memaddr, size, want_hex,ar);
                    x[i]=ar[0];    y[i]=ar[1];   z[i]=ar[2];
                printf(" P[%d] = %d %d %d",i,x[i],y[i],z[i]);
            }
            printf("\n\n");
            int ac = 15,ac1 = 230;
            if(((abs(z[0]-z[1]) > ac)&&(abs(z[0]-z[1]) < ac 1))||
   ((abs(y[0]-y[1]) > ac)&&(abs(y[0]-y[1]) < ac 1))||
   ((abs(x[0]-x[1])="">ac)&&(abs(x[0]-x[1]) < ac 1))){ 
   if(((z[0]-z[1]="" > ac)&&(z[0]-z[1] < ac 1))){ 
   printf("error="" in="" z="" val="%d" and="" %d="" <-=""> %d.\n",z[0],z[1],abs(z[0]-z[1]));
                SendToServer(z,'Z');
                break;
                }else if (((y[0]-y[1]>ac)&&(y[0]-y[1] < ac 1))){ 
    printf("error="" in="" y="" val="%d" and="" %d="" <-=""> %d.\n",y[0],y[1],abs(y[0]-y[1]));
                  SendToServer(y,'Y');
                }else{
                  printf("Error in X val = %d and %d <-> %d.\n",x[0],x[1],abs(x[0]-x[1]));
                  SendToServer(x,'X');
                break;
                }
             }
        }
 
        break;
    case 'w':
        if(force == 0)
            confirm_action();
        parse_arg(arg, &memaddr, &size);
        print_info("  Writing stdin starting at address 0x%x\n",
            memaddr);
        write_to_eeprom(&e, memaddr);
        break;
    default:
        usage_if(1);
        exit(1);
    }
    eeprom_close(&e);
 
    return 0;
}
 
int SendToServer(int acc[],char ch[]){
    
        int sockfd, portno, n;
            struct sockaddr_in serv_addr;
            struct hostent *server;
 
        char buffer[1024];
        portno = atoi("80");
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd < 0)
        error("ERROR opening socket");
        server = gethostbyname("192.168.1.9");
        if (server == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
        }
        bzero((char *) &serv_addr, sizeof(serv_addr));
        serv_addr.sin_family = AF_INET;
        bcopy((char *)server->h_addr,
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
        serv_addr.sin_port = htons(portno);
        if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) {
        error("ERROR connecting");
        }
        bzero(buffer,1024);
           // sprintf(buffer,"GET /g-Box/index.php?act=%c&val=%d HTTP/1.0\n\n",ch,abs(acc[0]-acc[1]));
        sprintf(buffer,"Error in  %c val = %d and %d <-> %d.\n",ch,acc[0],acc[1],abs(acc[0]-acc[1]));
        n = write(sockfd,buffer,strlen(buffer));
        if (n < 0)
         error("ERROR writing to socket");
        bzero(buffer,1024);
        n = read(sockfd,buffer,1024);
        if (n < 0)
         error("ERROR reading from socket");
        printf("%s\n",buffer);
 
return 0;
}
 
int  error(char *msg)
{
    perror(msg);
    exit(0);
return 0;
}

03 September 2010

āļ āļēāļžāļิāļˆāļāļĢāļĢāļĄ CodeFest āļ„āļĢั้āļ‡āļ—ี่ 7 āļĄ.āļ§āļĨัāļĒāļĨัāļāļĐāļ“์

āļĢāļ°āļŦāļ§่āļēāļ‡āļ§ัāļ™āļ—ี่ 3 – 4 āļัāļ™āļĒāļēāļĒāļ™ āļž.āļĻ. 2553
āļ āļēāļžāļิāļˆāļāļĢāļĢāļĄ  http://gallery.opentle.org/v/CodeFest7/

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Blog by Chagridsada Boonthus | http://chagridsada.blogspot.com/