ข้ามไปที่เนื้อหาหลัก

EJB development ด้วย Glassfish Server -- Part 3 EJB3Unit ( Unit Testing EJB3 Modules )

ตัวอย่าง EJB3Unit


ไปดู doc และ ตัวอย่างได้จาก Ejb3Unit homepage
หรือ
download Ejb3UnitSampleProject-2.0.0-RC-1.zip

how to import existing project in eclipse



วิธี1 จะก็อป jar ไฟล์เข้าโปรเจคเองก็ได้
วิธี2 จะ Properties > Java Build Path > libraries > Add External JARs ก็ได้
โดยโหลดจาก ejb3unit-jars.zip

extract ไฟล์ก่อนแล้วค่อย add นะ ย้ำ


จากนั้นลองรัน
Run As -> [Junit icon] Execute all ejb3 unit tests.

มันจะรัน 31 tests ผ่านโดยไม่มี errors




สร้าง new project เพื่อ test EJBs ของคุณ

ejbunit สร้าง on top of Junit ( ใช้ javaSE )

ไม่ต้อง export ก่อนรันเทส ejbunit จะ simulate environment

ทำ Part 2 ให้ work ก่อน

เพราะว่านี่จะทำต่อจาก Part 2 ( Eclipse/EJB/GlassFish/JPA )

ตอนนี้ก็มี Project titan-ejb ที่มี EJB module targeted for GlassFish

- มี entities Cabin, Customer, และ Phone

- มี stateless session bean ชื่อว่า TravelAgentBean และมี remote interface


- สร้าง new Java project ชื่อ titan-tests

add the external JARs for Ejb3Unit ให้เรียบร้อย


- บอก Eclipse ให้ reference unit test project (titan-tests) ไปยัง EJB module project (titan-ejb)

ทำให้สามารถเข้าถึง source classes ใน EJB module project ได้


add the titan-ejb project ไปยัง "Java Build Path" ในแท็บ "Projects"

และ add the titan-ejb project ใน "Project References"

สร้าง entity unit test

- เทส Phone entity ก่อนละกัน

ก่อนอื่น เราต้อง override equals() กับ hashCode() ในคลาส Phone
เพราะ detached entity ต้อง"เท่ากับ" และสร้าง hash code เดียวกันกับ attached version

กลับไปเพิ่ม code เพื่อ override the methods ที่คลาส Phone ใน titan-ejb project

@Override
public boolean equals(Object other) {
if (other != null && other instanceof Phone) {
final Phone that = (Phone) other;
final EqualsBuilder builder = new EqualsBuilder();
builder.append(this.id, that.id);
builder.append(this.number, that.number);
return builder.isEquals();
}
return false;
}
@Override
public int hashCode() {
final HashCodeBuilder builder = new HashCodeBuilder();
builder.append(this.id);
builder.append(this.number);
return builder.toHashCode();
}

โค้ดที่เราเพิ่มไป มันใช้คลาส EqualsBuilder ( อยู่ใน commons-lang-2.4.jar : Apache Commons Lang library และอยู่ในไฟล์ ejb3unit-jars.zip ที่โหลดมาตะกี้ ) add มันใส่ build path ด้วย


ตอนนี้ titan-ejb project มี commons-lang-2.4.jar แต่ dependency มันจะไม่โดนแพ็คไปกับ EJB JAR file ตอน deploy ขึ้น application server (จะเจอ errors ประมาณว่า "class not found" ตอนรันบน application server)
สำหรับ GlassFish, ให้ก็อบ JAR file ที่ต้องใช้ไปที่ glassfish/domains/domain1/lib/ext/ (assuming your domain is domain1) มันจะ available สำหรับทุกๆ components ที่ deployed ไปยัง domain1.


กลับมายัง titan-tests project เพิ่ม class PhoneTest ( package com.titan.entitytests )
public class PhoneTest extends BaseEntityFixture<Phone> {
public PhoneTest() {
super(Phone.class);
}
}

คลาสนี้ แค่ใช้ default behavior ของคลาส BaseEntityFixture เพื่อเทสคลาส Phone

รันได้ละ คลิกขวา Run As -> JUnit Test จะมี 5/5 tests pass

testNothing() ซึ่งเป็น คลาสที่ inherit มา แล้วก็ 4 คลาสที่สร้างขึ้น

Configure Ejb3Unit

โดยใช้ ejb3unit.properties configuration file

New -> Source Folder ชื่อ "resources" ที่ level บนสุดของ titan-tests project
เพิ่ม file ejb3unit.properties


ejb3unit.inMemoryTest=true
ejb3unit.show_sql=true

## values are create-drop, create, update ##
ejb3unit.schema.update=create-drop

โค้ดนี้บอก Ejb3Unit ว่าให้จำลอง database ใน memory เพื่อแสดง SQL queries ที่ส่งไปยัง database บน console ( ไม่ต้องต่อกับ database จริง, ถ้าอยากต่อ database จริง ก็ config ในนี้แหละ ดูวิธีจาก Ejb3Unit documentation )

และ drop and create necessary tables สำหรับ entites ทุกครั้งที่ Ejb3Unit starts up

Unit testing entities manually

Ejb3Unit สนับสนุน automated test entities ที่เป็นแบบ one-to-many bidirectional associations ( เทสโดยใช้คลาส BaseEntityFixture )

แต่ไม่ support automated เทส entities ที่เป็นแบบ unidirectional associations ( ไปใช้คลาส PojoFixture แทน )


Mapping Customer-to-Phone ของเราเป็น one-to-many unidirectional เราจึงไม่สามารถใช้ BaseEntityFixture สำหรับคลาส Customer


เริ่มจาก สร้าง hashCode() และ equals() ในคลาส Customer


@Override
public boolean equals(Object other) {
if (other != null && other instanceof Customer) {
final Customer that = (Customer) other;
final EqualsBuilder builder = new EqualsBuilder();
builder.append(this.firstName, that.firstName);
builder.append(this.lastName, that.lastName);
builder.append(this.id, that.id);
return builder.isEquals();
}
return false;
}
@Override
public int hashCode() {
final HashCodeBuilder builder = new HashCodeBuilder();
builder.append(this.firstName);
builder.append(this.lastName);
builder.append(this.id);
return builder.toHashCode();
}

และสร้าง test class ตามนี้


public class CustomerTest extends PoJoFixture {

private static final Class[] USED_ENTITIES = { Customer.class, Phone.class };

public CustomerTest() {
super( USED_ENTITIES );
}

public void testGetEntityManager() {
assertNotNull(this.getEntityManager());
}

public void testWriteCustomer() {
List<Customer> customers = generateTestCustomers();

// persist the graph and load it again
List<Customer> persisted = persist(customers);
List<Customer> allFromDB = findAll(Customer.class);

// assert the persisted graph and the loaded are equal
assertCollectionsEqual(persisted, allFromDB);
}

private List<Customer> generateTestCustomers() {
final List<Customer> customers = new ArrayList<Customer>();
Customer customer = new Customer();
customer.setFirstName( "Matthew" );
customer.setLastName( "Dailey" );
customer.addPhoneNumber( "+66851234567" );
customers.add( customer );
return customers;
}

// Manually delete customers with the entity manager so that
// the delete cascades to the dependent phone numbers.
private void deleteCustomers() {
EntityManager em = getEntityManager();
List<Customer> customers = findAll(Customer.class);
for ( Customer customer : customers ) {
em.remove( customer );
}
}

@Override
public void setUp() throws Exception {
super.setUp();
deleteCustomers();
deleteAll(Phone.class);
}

@Override
public void tearDown() throws Exception {
deleteCustomers();
deleteAll(Phone.class);
super.tearDown();
}
}
เหมือนเดิม คลิกขวา Run As -> JUnit Test
ปล. ต้องไปเพิ่ม method addPhoneNumber เข้า คลาส Customer เพื่อให้มันเรียก
customer.addPhoneNumber( "+66851234567" );
ได้ด้วย

Unit testing session beans ========================================

Ejb3Unit เทส session beans ได้มากมายมาก ดูจากตัวอย่างที่โหลดมาได้ ( DIFieldSessionBeanTest.java )

ตอนนี้เราจะเทส TravelAgentBean


เพิ่ม functionality ไปยัง TravelAgentRemote interface:


@Remote
public interface TravelAgentRemote {
public void createCabin( Cabin cabin );
public Cabin findCabin( int id );
public List<Cabin> getAllCabins(); //
public int createCustomer( Customer customer );
public Collection<Phone> phoneNumbersForCust( int id );
public EntityManager getEm(); //
}

เราจะ test dependency injection ของ entity manager ที่ initialization timeand each of the methods. นี่คือวิธี implement method ใหม่ :


public EntityManager getEm() {
return this.manager;
}

@SuppressWarnings("unchecked")
public List<Cabin> getAllCabins() {
Query query = manager.createQuery( "SELECT c FROM Cabin c" );
return Collections.checkedList( query.getResultList(), Cabin.class );
}

ใน ejb-tests project, สร้างคลาส TravelAgentBeanTest ( package com.titan.sessionbeantests )


public class TravelAgentBeanTest extends BaseSessionBeanFixture<Travelagentbean> {

private static final Class[] usedBeans = { Cabin.class }; // Entity ที่เกี่ยวข้อง ต้องใส่ลงไปให้หมด ( ไม่งั้นจะเจอ java.lang.IllegalArgumentException: Unknown entity: หรือไม่ก็ EntityManager could not be initialized to load the enities [com.midterm.domain.Cm, com.midterm.domain.BidInvitation]. Cause: org.ejb3unit.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.midterm.domain.BidInvitation.bids[com.midterm.domain.Bid] )
private static final CSVInitialDataSet<Cabin> CSV_SET =
new CSVInitialDataSet<Cabin>( Cabin.class, "testCabins.csv", "id", "name",
"deckLevel", "shipId", "bedCount" );
public TravelAgentBeanTest() {
// super(sessionBeanToTest, introspector, usedEntityBeans, initialData)
super( TravelAgentBean.class, usedBeans, new CabinEntityInitialDataSet(), CSV_SET ); //
}
public void testDependencyInjection() {
final TravelAgentBean toTest = this.getBeanToTest();
assertNotNull(toTest);
assertNotNull(toTest.getEm());
}
public void testLoadData() {
final TravelAgentBean travelAgentBean = this.getBeanToTest();
assertNotNull(travelAgentBean);
List<Cabin> cabins = travelAgentBean.getAllCabins();
assertNotNull(cabins);
System.out.println( "cabins has " + cabins.size() + " entries" );
assertEquals( 6, cabins.size() );
assertEquals( cabins.get(0), new Cabin( 1, "Cabin 8", 1 ));
assertEquals( cabins.get(1), new Cabin( 2, "Cabin 12", 1 ));
}
public static class CabinEntityInitialDataSet extends EntityInitialDataSet<Cabin> {
public CabinEntityInitialDataSet() {
super(Cabin.class);
}
public void create() {
this.add( new Cabin( 1, "Cabin 8", 1 ));
this.add( new Cabin( 2, "Cabin 12", 1 ));
}
}
}

นี่เป็น dependency injection test สองวิธีที่จะสร้าง entity test fixtures
วิธี1 โหลดจาก resources/testCabins.csv ( resources เป็น sources folder )
วิธี2 manually adding entities โดยใช้คลาส EntityInitialDataSet
ตัวอย่างข้างบนใส่ initial data ทั้งสองวิธี

ในไฟล์ csv ใส่อะไรประมาณนี้ลงไป

100,"Cabin 345",1,1,2
101,"Cabin 346",1,1,3
102,"Cabin 347",2,1,2
103,"Cabin 348",2,1,3

แล้วก็เพิ่มเทสลงไป
public void testCreateCabin() {
final TravelAgentBean travelAgentBean = this.getBeanToTest();
// Get list of cabins before we do the create
List<Cabin> cabinsBefore = travelAgentBean.getAllCabins();
assertEquals(6, cabinsBefore.size());
EntityManager manager = travelAgentBean.getEm();
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
for ( int i = 0; i < 10; i++ ) {
Cabin cabin = new Cabin();
cabinsBefore.add( cabin );
cabin.setShipId(3);
cabin.setName("New cabin " + i);
cabin.setDeckLevel(5);
cabin.setBedCount(2);
travelAgentBean.createCabin(cabin);
}
transaction.commit();
List<Cabin> cabinsAfter = travelAgentBean.getAllCabins();
assertEquals(16, cabinsAfter.size());
assertCollectionsEqual(cabinsBefore, cabinsAfter);
}
สังเกตว่า เราสร้าง entity manager transaction manually
ไม่งั้น ในเมธอด getAllCabins() ตอนเรา execute EJB QL query เพื่อ retrieve all persisted Cabins มันจะยัดลง database ไม่ได้

public void testFindCabin() {
final TravelAgentBean travelAgentBean = this.getBeanToTest();
// The cabin with name "Cabin 8" added in the create() method of the initial data
// set should have its ID generated as 118 by the time we get to this test case.
Cabin cabin = travelAgentBean.findCabin(118);
assertEquals(cabin, new Cabin(118, "Cabin 8", 1));
}


ref : mdailey

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งไปรษณีย์ทีละมากๆ ที่ช่องไปรษณีย์สำหรับธุรกิจ

  ถ้าเราส่งไปรษณีย์ทีละ 10 กล่องขึ้นไป สามารถไปส่งโดยใช้ช่องทางธุรกิจได้ โดยต้องกรอกใบรับฝากรวม ( Receipt for bulk Posting ) เป็นลิสต์รายการให้เขาไปด้วย โดยกรอกพัสดุแต่ละรายการ และ ไปยื่นให้เขาพร้อมกับพัสดุที่จะส่ง วิธีกรอก คือ ให้กรอกพัสดุแบบเดียวกันไว้แผ่นเดียวกัน  เช่น พัสดุ10 กล่อง กล่องขนาดเท่ากัน น้ำหนักเท่ากันหมด กรอกไว้ 1 แผ่น ถ้าน้ำหนักต่างกัน ขนาดกล่องต่างกัน กรอกแยกแผ่นไว้ดีที่สุด ซึ่งใบนี้สามารถไปขอได้ที่ไปรษณีย์ฝ่ายธุรกิจ สามารถนำมาทำใส่ A4 ก็ได้ ขอบคุณคุณพี่ amarin.ch ที่ไปรษณีย์กลาง ( BANGKOK G.P.O. ) มากๆ นะครับ สำหรับคำแนะนำ ขอบคุณที่ช่วยคีย์ให้ทีละรายการสำหรับมือใหม่ที่ยังไม่รู้ว่ามีใบรับฝากรวมอย่างผมด้วยครับ คราวหน้าผมจะทำใบรับฝากรวมไปครับ

อยู่เหงาๆ เราไปเที่ยว - ไหว้พระขอพร ศาลเจ้าแม่ทับทิม (อาม่า), เจริญกรุง, กรุงเทพ; 天后聖母廟, 石龙軍路, 曼谷, 泰国; Thap Thim Chinese Goddess Shrine, Chareon Krung 63 Road, Bangkok, Thailand

天后聖母廟, 石龙軍路, 曼谷, 泰国 ไหว้ศาลเจ้าแม่ทับทิม ขอให้การค้าเจริญรุ่งเรือง ตำนานเจ้าแม่ทับทิมเกิดที่ตำบลตุ้ยบ๊วย เขตบ่นเซียว เกาะไหหลำ มีผู้เฒ่าแซ่พัว เป็นผู้มีความซื่อสัตย์สุจริต ทำงานขยันขันแข็ง ครั้งหนึ่งแกออกไปหาปลา โดยผูกแหเป็นช้อนดักปลา เวลาผ่านไปแกยังหาปลาไม่ได้ คืนนั้นก็ประสบความล้มเหลว เมื่อช้อนแหขึ้นมาทีไรก้อมีแต่ท่อนไม้ ด้วยความโมโหแกเลยขว้างท่อนไม้นั้นออกไปให้ไกล แต่แล้วเมื่อช้อนแหขึ้นมาใหม่ก็ปรากฏท่อนไม้ท่อนเดิมอีก ต่อจากนั้นแกก็ขว้างท่อนไม้ขึ้นฝั่ง และแกก็ฉุก คิดว่าแปลกที่ท่อนไม้ธรรมดาจะสามารถลอยทวนน้ำได้ คงจะเป็นสิ่งวิเศษ และแกก็ได้นำท่อนไม้นั้นขึ้นฝั่ง และเพ่งมองท่อนไม้นั้นพร้อมกับอธิษฐานว่า หากท่อนไม้นี้มีความศักดิ์สิทธิ์ขอให้คืนนี้จับปลาได้มาก เมื่อพ้นจากความจนแล้ว เมื่อขึ้นฝั่งจะนำท่อนไม้นี้แกะสลักเป็นเทวรูปศักดิ์สิทธิและสักการะบูชาเช้าวันไม่ให้ขาด เมื่ออธิษฐานจบแกเอาท่อนไม้นั้นวางบนหัวเรือ ปรากฏว่าช้อนเพียงสองถึงสามครั้งก็ได้ปลาตัวโตเต็มเรือ จึงนำปลาขึ้นฝั่งวันนั้นปลาของแกขายได้ราคา เพราะชาวประมงคนอื่นจับได้น้อยแกจึงมีเงินจับจ่ายใช้สอย และทุกครั้งที่แกออกหาปลา ...

แนะนำ ยาบำรุงครรภ์ จับซาไท้เป้า หรือ 13 องครักษ์พิทักษ์ครรภ์ ยาจีน บำรุงครรภ์

จับซาไท้เป้า  ยาบำรุงครรภ์ สมุนไพรจีน ช่วงนี้เพื่อนๆ เริ่ม ทยอย แต่งงาน กันแล้ว นะครับ เราเองก็มียาจีนมา นำเสนอ ซึ่งเป็น ยาดี ที่คุณแม่ ของเรา ทาน ตอนคลอดเรา นั่นก็คือ "จับซาไท้เป้า" ยาบำรุงครรภ์ นั่นเอง เงง เงง เงง เงง จับซาไท้เป้า เป็น ยาจีน ซึ่ง ประกอบไปด้วย สมุนไพร จีน 13 อย่างด้วยกัน มี สรรพคุณ เป็น ยาบำรุงครรภ์ บำรุง ทั้งคุณแม่ และ คุณลูก เลย เรียกได้ว่า สรรพคุณ ครบครัน บำรุง คุณแม่ ช่วงตั้งท้อง ช่วยให้ คุณลูก แข็งแรง มีผิวพรรณ สะอาดสะอ้าน ในตอนที่คลอดออกมา จะ คลอดง่าย ตัวจะไม่มีคราบไขมันติดเยอะ จ้า วิธีกินจับซาไท้เป้า ทานตั้งแต่ท้อง 5 เดือนขึ้นไป 2 อาทิตย์ทาน 1 ห่อ ทานจนคลอด ศิริรวมแล้ว ถ้าทาน ครบ dose โดยเริ่มตั้งแต่ 5 เดือน ต้องทานทั้งหมด 10 ห่อ จ้ะ วิธีต้มจับซาไท้เป้า  1 ห่อ ต้มได้ 2 ครั้ง ครั้งแรก ใส่น้ำ 3 ถ้วย ต้มเหลือ 8/10 ถ้วย ครั้งที่ 2 ใส่น้ำ 2.5 ถ้วย ต้มเหลือ 7/10 ถ้วย ซื้อที่ไหนดี หลายๆ คน มักจะมีคำถาม ว่า จับซาไท้เป้า ซื้อที่ไหน  ซึ่งเราเอง แนะนำร้านขาย จับซาไท้เป้า ซึ่งก็คือ ร้าน ขายยา ย่ง เช...

ปีอธิกสุรทิน อธิกมาส อธิกวาร และ การทดปฏิทิน

 ปีที่แบ่งตามรอบพระอาทิตย์ (สุริยคติ) มี 2 แบบ คือ 1. ปกติสุรทิน คือ มี 365 วัน 2. อธิกสุรทิน คือ มี 366 วัน (เดือนกุมภาฯมี 29 วัน) การคำนวน ปีอธิกสุรทิน ตรงนี้บางท่านจะจำได้แต่เพียง ว่า หาร 4 ซึ่งไม่ใช่แค่นั้นครับ ความจริงแล้ว จะมีสูตรคำนวณที่ถูกต้องคือ ให้เอา ค.ศ.ตั้ง แล้วเอา 4 หาร หากหารลงตัวก็ใช่ ยกเว้น 100 หารลงตัว แต่หาก 400 ลงตัวก็ให้นับเป็นอธิกสุรทินด้วย (เช่น ปี 1900 ไม่เป็นอธิกสุรทิน แต่ปี 2000, 2004 เป็นปีอธิกสุรทิน) ปีที่แบ่งตามรอบพระจันทร์ (จันทรคติ) แบ่งเป็น 3 คือ 1. ปกติมาส-ปกติวาร  (บางที่เขียนย่อ เป็น ปกติมาส-วาร)       คือ ปีที่เป็นปกติ มีเดือนคู่ ข้างขึ้น 15 วัน ข้างแรม 15 วัน       และมีเดือนคี่ ข้างขึ้น 15 วัน ข้างแรม 14 วัน       รวมวันใน 1 ปี เป็น (30*6+29*6) = 354 วัน 2. ปกติมาส-ปีอธิกวาร (บางที่เรียกเป็น อธิกวาร)       คือ ปีที่เป็นปกติ แต่เดือน 7 จะมีข้างแรม 15 วัน        รวมวันใน 1 ปี เป็น 354+1 = 355 วัน 3. ปีอธิกมาส-ปกติวาร (บางที่จะเรียกเป็น อธิกมาส)     ...

เทคนิคคิดเลขเร็วโดยใช้ วิธีคิด แบบ เวทคณิต ( Vedic Mathematics example )

จากที่สงสัยเรื่อง ลูกคิด ของ จินตคณิต ที่ลองไปค้นดู ปรากฎว่า เจอ เวทคณิต ซึ่งเขาบอกว่า อยู่ในคัมภีร์พระเวท ลองอ่านดูแล้ว รู้สึกว่าฝึกสมอง ก็ทำให้คิดเลขเร็วดี เลยสรุปมาให้ ตามนี้ Tutorial 1 การลบเลข ALL FROM 9 AND THE LAST FROM 10 ทุกตัวลบจาก 9 และตัวสุดท้ายลบจาก 10 เช่น 1000 - 357 = 643 10,000 - 1,049 = 8951 ถ้า 1,000 - 83 ให้มองว่ามี 0 อยู่ข้างหน้า เป็น 1,000 - 083 = 917 ฝึกบ่อยๆ ก็คล่อง แล้วก็ไม่ต้องใช้เครื่องคิดเลขด้วย ลองทำดูสิ 1) 1000 - 777 = 2) 1000 - 283 = 3) 1000 - 505 = 4) 10,000 - 2345 = 5) 10,000 - 9876 = 6) 10,000 - 1011 = 7) 100 - 57 = 8) 1000 - 57 = 9) 10,000 - 321 = 10) 10,000 - 38 = 3,000 - 467 ก็ทำเหมือนกัน โดยลบตัวแรกสุดของ 3,000 ไป 1 จากนั้นก็ทำเหมือนเดิม จะได้ว่า 3,000 - 467 = 2,533 Tutorial 2 VERTICALLY AND CROSSWISE สำหรับตัวเลขที่น้อยกว่าฐานนิดหน่อย ลอง 88x98 88 น้อยกว่า 100 อยู่ 12 98 น้อยกว่า 100 อยู่ 2 12x2 = 24 88-2 หรือ 98-12 ได้ 86 ดังนั้นตอบ 8,624 ดูอีกตัวอย่าง หรือ ลองทำนี่ดู 1) 87 x 98 = 2) 88 x ...

[ www.whoisblocked.info ] See who blocked you from MSN, MSN phising อีกเวปหนึ่งที่น่าระวัง

วันก่อนได้รับเมลจากเพื่อน ซึ่งตกเป็นเหยื่อของ MSN phishing อีกรายแล้ว มันส่งมาตามนี้ ตัวอักษรการ์ตูน น่าอ่านมาก คลิกที่ภาพเพื่อดูรูปใหญ่ หรือ อ่านจากข้อความข้างล่าง From: invites@5554.whoisblocked.info on behalf of myfriendemail@hotmail.com ¿Want to know who deleted you from MSN Messenger? Join Now to WHOISBLOCKED.INFO ... Easy look who deleted or blocked you from msn contact list i have do that! now i know what "friends" blocked me ... www.whoisblocked.info Now byebye! dont forget to join that website, its amazing! PD: WhoIsBlocked.info ... Great website 82703700473147717107 ซึ่งพอคลิกเข้าไปมันไปที่หน้า http://www.whoisblocked.info/?4771370071078270 ซึ่งหน้าตาเป็นแบบนี้ ซึ่งตรงหัวมันบอกว่า SSL 128 BITS SECURE WEBSITE แต่ว่า URL เป็น http:// นะฮะ ป้าย SSL หลอกลวงผู้บริโภคของเวปไซท์ whoisblocked.info ( cheating SSL sign from website whoisblocked.info ) สังเกตว่า ป้ายโฆษณา ของเวปมันใหญ่เท่าฝาบ้าน ข้างบน โลโก้ มีแถบ โฆษณา กูเกิล แถบหนึ่ง ซึ่งถ้าดูเผินๆ จะดูเหมือนเป็นแท็...

[ AI ] IBM granite, NVIDIA robotics, IBM Langflow, watsonx, LMCache, LiteRT, Self driving car, Mamba model, RAG

 IBM granite: Time series from sensor, stock market * Forcast * Anomaly detection - classification high medium risk, data synthesis Embedding AI - 1M params - edge device - small AI Send insight --- NVIDIA * Jackson Thor robotic * Nemo ---- * IBM Langflow : open source * Watsonx (n8n) Enterprise : guardrails / log, tool using policy ----- LMcache : open source KC cache Prompt -> key value (RAGs) Same context ( e.g. same docs) Reduce operating costs CacheGen : make cache cheap to move and store CacheBlend : reuse chunk, not just prefix ---- Google มี framework ที่ optimize AI บน mobile phone นั่นคือ LiteRT : google pytorch Quantisation เท่าไหร่บน device นี้ Model explorer: quantize แล้ว error < 5% XMNpack ใช้ CPU ลดลง Google AI edge portal : benchmark AI on real device ---- Self driving car * Nvidia Alpamayo 2 model * Carla simulation Random forest -> multiple scenarios -> json -> LLM Car talk to mobile phone (cross the road) ----- Mamba model (recursive)  - alte...

ถังดับเพลิง ตรวจสภาพยังไง, ถังดับเพลิงแบบไหน ดูยังไง

ถังดับเพลิงแบบไหน ดูยังไง * ผงเคมีแห้ง Dry Chemical Powder ภาพจาก safetymanshop.com ผงเคมีแห้ง Dry Chemical Powder : ถังแดง  สามารถดับเพลิงประเภท A,B,C,D วิธีตรวจถังดับเพลิงแบบผงเคมีแห้ง * ดูที่เข็มมาตรวัด ถ้าสีเขียวคือโอเค ถ้าเข็มเอียงมาทางซ้ายในโซนสีแดง ต้องเติมแรงดัน * ให้คว่ำและฟังการไหลของผงเคมี ถ้าไม่มีการเคลื่อนไหว แสดงว่าสารเคมีหมดอายุจับกันเป็นก้อน * สายฉีด ตัวถัง ด้ามจับ มีแตกชำรุด อุดตันหรือไม่ ภาพจาก uandnsupply.safety * ฮาโลตรอน Halotron  ภาพจาก safetymanshop.com ฮาโลตรอน Halotron : ถังเขียวต้องดูอีกทีเพราะถังเขียวอาจใส่สารได้หลายแบบอาจไม่ใช่ฮาโลตรอน  ไม่ทิ้งคราบสกปรกไว้  สามารถดับเพลิงประเภท A,B,C * คาร์บอนไดออกไซด์ CO2 ภาพจาก safetymanshop.com คาร์บอนไดออกไซด์ CO2 : ถังแดงปากแตร  ไม่เหลือกากไว้  เหมาะกับ ตู้ไฟ ห้องคอม ห้องเซอร์เวอร์ ห้องเครื่องเสียง สามารถดับเพลิงประเภท A,B,C วิธีตรวจถังดับเพลิงแบบ CO2 ให้ชั่งน้ำหนักถังและเทียบน้ำหนักที่แจ้งไว้ในเสปคถังดับเพลิง * สเปรย์ สเปรย์ : สามารถดับเพลิงประเภท K เหมาะกับใช้ในครัว สูตรน้ำดีกว่าสเปรย์โฟม ...

วิธีการไป อย. กระทรวงสาธารณสุขจากหัวลำโพง

ทางไป : รถไฟฟ้า MRT หัวลำโพง ไปลงที่ สถานี กระทรวงสาธารณสุข  ถ้ากดที่ตู้ต้องเปลี่ยนไปหน้าจอสายสีม่วง สนน ราคา 48 53 บาท ต่อมอไซด์ ถ้าไป อย. 20 บาท จากหน้าทางเข้า  ถ้าฝนตกแนะนำให้โบกแท็กซี่จากข้างหน้า ข้างในหาแท็กซี่ยากมาก ถ้าจะเดินประมาณ 2.4 km ให้ระวังหลงเข้าไปรพ ศรีธัญญา รพ ศรีธัญญาพื้นที่ข้างในใหญ่มาก และเหมือนจะล้อมด้วยคลอง เหมือนจะมีทางออกแค่ทางที่เข้าไปนั่นแหละ ทางกลับ : รถเมล์ 97 จาก อย. ตรงข้ามประกันสังคม ทางที่ 1 : ถ้าจะใกล้ลงหน้าปากซอยขึ้นสายสีม่วงที่สถานีกระทรวงสาธารณสุขที่เดิม ทางที่ 2 : ผ่าน ท่าน้ำนนท์​ กลับเรือได้ ทางที่ 3 : ผ่านหน้าพระจอมพระนครเหนือด้วยนะ ผ่าน สถานีรถไฟฟ้า MRT บางซื่อ  ( จาก อย. ไป MRT บางซื่อ 17 บาท,  จาก MRT บางซื่อ ไป MRT หัวลำโพง 44 บาท นั่งกลับได้ 2 ทาง ทางหัวลำโพง กับ ไปเปลี่ยนที่ท่าพระ ไม่รู้ว่าทางไหนเร็วกว่ากัน ) ทางที่ 4 :  ผ่าน สะพานควาย  ทางที่ 5 :  นั่งถึงอนุสาวรีย์ชัยสมรภูมิได้ ค่ารถเมล์ 21 บาท ค่ารถไฟฟ้าไป BTS สะพานตากสิน 47 บาท 

ลอง recovery file โดยใช้ ubuntu

จาก ที่ไปอ่านมา ลองเล่น photorec ดูดิ๊ $ sudo photorec จากนั้นมันก็จะเข้าสู่เมนูของมันซึ่งก็มั่วๆไปได้ มันใช้ไม่ยาก ผมขออนุญาตไม่เอา screenshot ของ shell มาให้ดูละกัน เนื่องจากไปดูของคนอื่นแล้วตกใจว่าต้องเลือกอะไรมากมาย แต่ยืนยันครับว่ามันใช้ง่ายจริงๆ พอมัน recovery เสร็จ ก็ไปอยู่ในโฟลเดอร์ที่สร้างไว้ แต่ติด permission The folder contents could not be displayed. You do not have the permissions necessary to view the contents of ... ก็เปลี่ยนเจ้าของมันซะเลย $ chown -R dsin recup_dir.1 # Give permissions as owner to user dsin. ส่วน ข้อเสียคือ ชื่อไฟล์ มันจะออกมาเป็น f ตามด้วยตัวเลข และที่เหมือนจะเหนือความคาดหมายคือ มันชื่อว่า photorec แต่มัน recover ไฟล์อื่นๆมาให้ด้วย เช่น mp3 mov mid gz zip แต่มันดันเปิดไม่ได้ซักกะอันน่ะสิ 55+ photorec ใช้ได้ทั้ง DOS, Windows, Linux, Sun Solaris, Mac OS X และที่สำคัญ ฟรี !!! ดูเพื่มเติมจาก หน้า official ของ photorec จริงๆ software พวก recovery มีอยู่มากมาย อันนี้คัดๆมาที่ใช้ฟรี ที่ใช้บน windows เช่น UndeletePlus Roadkil's Unstoppable Copier recuva (...