<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ekarat Rattagan on Medium]]></title>
        <description><![CDATA[Stories by Ekarat Rattagan on Medium]]></description>
        <link>https://medium.com/@pok-ekarat?source=rss-1e693fe42a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Hcyh7f4RVjt0oukyo4MZ5g.jpeg</url>
            <title>Stories by Ekarat Rattagan on Medium</title>
            <link>https://medium.com/@pok-ekarat?source=rss-1e693fe42a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:49:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pok-ekarat/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[การใช้งาน KsqlDB หรือ PySpark Structured Streaming ในการจัดการ Streaming data (ตอนที่ 2)]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-ksqldb-%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD-pyspark-structured-streaming-%E0%B9%83%E0%B8%99%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3-streaming-data-%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-2-eac967128518?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/eac967128518</guid>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Sat, 27 Apr 2024 00:16:05 GMT</pubDate>
            <atom:updated>2024-04-27T00:16:05.183Z</atom:updated>
            <content:encoded><![CDATA[<p>Previous</p><p>จากตอนที่ 1 ที่เป็นการใช้ KsqlDB</p><p><a href="https://pok-ekarat.medium.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-ksqldb-%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD-pyspark-structured-streaming-%E0%B9%83%E0%B8%99%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3-streaming-data-eb165c46cf18">การใช้งาน KsqlDB หรือ PySpark Structured Streaming ในการจัดการ Streaming data</a></p><p>บทความนี้ (ตอนที่ 2) เป็นการใช้ Pyspark structured streaming ในการรับ data มาจาก Kafka topic ชื่อ quickstart-jdbc-test แล้ว clean แล้วส่งไปยัง topic ชื่อ quickstart-clean</p><p>Data ที่ใช้ในการรับส่งนั้นมี schema เป็นแบบ avro (<a href="https://avro.apache.org/">https://avro.apache.org/</a>) ตัวอย่างข้างล่างนี้เป็น code สำหรับ Pyspark Structured Streaming ซึ่งมีคำอธิบายเป็น comment ดังนี้</p><pre># %% Download libraries ที่เกี่ยวข้องประกอบด้วย spark sql, streaming และ avro<br>!wget &quot;https://repo1.maven.org/maven2/org/apache/spark/spark-sql-kafka-0-10_2.12/3.5.0/spark-sql-kafka-0-10_2.12-3.5.0.jar&quot;<br>!wget &quot;https://repo1.maven.org/maven2/org/apache/spark/spark-streaming-kafka-0-10_2.12/3.5.0/spark-streaming-kafka-0-10_2.12-3.5.0.jar&quot;<br>!wget &quot;https://repo1.maven.org/maven2/org/apache/spark/spark-avro_2.12/3.5.0/spark-avro_2.12-3.5.0.jar&quot;<br><br># %% Install kafka library<br>!pip install confluent_kafka</pre><pre># Import library ที่ต้องใช้<br>import os<br>from pyspark.sql import SparkSession<br>from pyspark.sql.functions import *<br>from pyspark.sql.types import *<br>import pyspark.sql.functions as func<br>from confluent_kafka.schema_registry import SchemaRegistryClient<br>from pyspark.sql.avro.functions import from_avro, to_avro</pre><pre>#Setup environment ของ library ที่ download ลงมาให้ คอมพิวเตอร์ รู้จัก<br>os.environ[&#39;PYSPARK_SUBMIT_ARGS&#39;] = &#39;--packages org.apache.spark:spark-streaming-kafka-0-10_2.12:3.5.0,org.apache.spark:spark-sql-kafka-0-10_2.12:3.5.0,org.apache.spark:spark-avro_2.12:3.5.0 pyspark-shell&#39;<br><br>#สร้าง spark app ชื่อ app1<br>spark = SparkSession.builder.appName(&quot;app1&quot;).master(&quot;local&quot;).getOrCreate()<br><br>#กำหนดค่าต่างๆ ที่ต้องใช้<br>kafka_url = &quot;broker:29092&quot;<br>kafka_topic = &quot;quickstart-jdbc-test&quot;<br>schema_registry_url = &quot;http://schema-registry:8081&quot;<br>schema_registry_subject = f&quot;{kafka_topic}-value&quot;<br><br># Read data มาจาก kafka ที่ Topic ชื่อ &quot;quickstart-jdbc-test&quot; โดยให้เริ่มอ่านจาก Offset แรก<br># จากนั้นให้ printSchema ออกมา<br>df = spark \<br>  .readStream \<br>  .format(&quot;kafka&quot;) \<br>  .option(&quot;kafka.bootstrap.servers&quot;, kafka_url) \<br>  .option(&quot;subscribe&quot;, kafka_topic) \<br>  .option(&quot;startingOffsets&quot;, &quot;earliest&quot;) \<br>  .load()<br>df.printSchema()<br></pre><p>ส่วนต่อมานี้เป็นการ จัดการข้อมูล (avro) ที่ได้มาจาก kafka ซึ่งต้องมีการจัดการ format เพื่อให้เป็น human-readable data โดยใช้วิธีจาก link ข้างล่างนี้</p><p><a href="https://medium.com/@mrugankray/real-time-avro-data-analysis-with-spark-streaming-and-confluent-kafka-in-python-426f5e05392d">Real-time AVRO Data Analysis with Spark Streaming and Confluent Kafka in Python</a></p><pre># สร้าง 3 column ใหม่โดยเอา substring ตาม format ดังนี้<br>df2 = df.withColumn(&quot;magicByte&quot;, func.expr(&quot;substring(value, 1, 1)&quot;))<br>df2 = df2.withColumn(&quot;valueSchemaId&quot;, func.expr(&quot;substring(value, 2, 4)&quot;))<br>df2 = df2.withColumn(&quot;fixedValue&quot;, func.expr(&quot;substring(value, 6, length(value)-5)&quot;))<br>df3 = df2.select(&quot;magicByte&quot;, &quot;valueSchemaId&quot;, &quot;fixedValue&quot;)<br>df3.printSchema()<br><br># ดึง schema ที่อยู่ที่ schema registry url มาใช้งาน<br>def get_schema_from_schema_registry(schema_registry_url, schema_registry_subject):<br>    sr = SchemaRegistryClient({&#39;url&#39;: schema_registry_url})<br>    latest_version = sr.get_latest_version(schema_registry_subject)<br>    return sr, latest_version<br><br># get schema using subject name จากข้อมูล<br># schema_registry_url = &quot;http://schema-registry:8081&quot; ซึ่ง run อยู่ใน docker ของเราที่รันในบทความตอนที่ 1<br># schema_registry_subject = f&quot;{kafka_topic}-value&quot;<br>_, latest_version_avro = get_schema_from_schema_registry(schema_registry_url, schema_registry_subject)<br><br># deserialize data <br># PERMISSIVE: Corrupt records are processed as null result. <br># Therefore, the data schema is forced to be fully nullable, <br># which might be different from the one user provided.<br>fromAvroOptions = {&quot;mode&quot;:&quot;PERMISSIVE&quot;}<br>decoded_output = df2.select(<br>    from_avro(<br>        func.col(&quot;fixedValue&quot;), latest_version_avro.schema.schema_str, fromAvroOptions<br>    )<br>    .alias(&quot;data&quot;)<br>)<br><br>#Select และ print schema data อีกรอบ<br>df3 = decoded_output.select(&quot;data.*&quot;)<br>df3.printSchema()<br><br># ถ้าเราต้องการทดสอบว่าทำถูกต้องหรือไม่ ใช้ uncomment ข้างล่างนี้แล้วรันแสดงผลลัพธ์ใน <br># console (terminal) <br># แต่ถ้าจะทำในลำดับต่อไป ให้ stop running df3 ก่อน <br>&#39;&#39;&#39;df3 \<br>    .writeStream \<br>    .format(&quot;console&quot;) \<br>    .trigger(processingTime=&#39;1 second&#39;) \<br>    .outputMode(&quot;append&quot;) \<br>    .option(&quot;truncate&quot;, &quot;false&quot;) \<br>    .start() \<br>    .awaitTermination()&#39;&#39;&#39;<br></pre><pre># Step ต่อมาเป็นการเตรียมทำ clean data แล้ว transform data ไปเป็น avro เพื่อส่งออกไปยัง<br># topic &quot;quickstart-clean&quot;<br># สร้าง UDF (A user-defined function)<br><br># function to convert binary to string<br>binary_to_string_udf = func.udf(lambda x: str(int.from_bytes(x, byteorder=&#39;big&#39;)), StringType())<br><br># function to convert int to binary<br>int_to_binary_udf = func.udf(lambda value, byte_size: (value).to_bytes(byte_size, byteorder=&#39;big&#39;), BinaryType())<br><br># กำหนดค่าต่างๆ ที่ต้องใช้เพิ่มเติม<br>kafka_analyzed_topic = &quot;quickstart-clean&quot;<br>schema_registry_analyzed_data_subject = f&quot;{kafka_analyzed_topic}-value&quot;<br><br>_, latest_version_analyzed_data = get_schema_from_schema_registry(schema_registry_url, schema_registry_analyzed_data_subject)<br><br># convert dataframe to binary data<br># ใน Step นี้ นศ สามารถ apply cleansing data ได้ ก่อนเก็บไว้ใน df3 อีกครั้ง<br># โดยเปลี่ยนแปลง code ใน .select ข้างล่างนี้<br>df3 = df3 \<br>.select(to_avro(func.struct(<br>    func.col(&quot;id&quot;),<br>    func.col(&quot;name&quot;),<br>    func.col(&quot;email&quot;),<br>    func.col(&quot;department&quot;),<br>    func.col(&quot;modified&quot;)<br>), latest_version_analyzed_data.schema.schema_str).alias(&quot;value&quot;))<br><br># add magicbyte &amp; schemaId to binary data<br># การสร้าง format avro ให้ data ของเรา<br>magicByteBinary = int_to_binary_udf(func.lit(0), func.lit(1))<br>schemaIdBinary = int_to_binary_udf(func.lit(latest_version_analyzed_data.schema_id), func.lit(4))<br>df3 = df3.withColumn(&quot;value&quot;, func.concat(magicByteBinary, schemaIdBinary, func.col(&quot;value&quot;)))<br>df3.printSchema()<br><br># Write to Kafka Sink<br># การส่ง data ที่ clean แล้วไปยัง kafka topic ต่อไป<br>df3 \<br>    .writeStream \<br>    .format(&quot;kafka&quot;) \<br>    .trigger(processingTime=&#39;1 second&#39;) \<br>    .outputMode(&quot;append&quot;) \<br>    .option(&quot;kafka.bootstrap.servers&quot;, kafka_url) \<br>    .option(&quot;topic&quot;, kafka_analyzed_topic) \<br>    .option(&quot;checkpointLocation&quot;, &quot;checkpoint1&quot;) \<br>    .start() \<br>    .awaitTermination()</pre><p>หมายเหตุ การรัน code ในบทความนี้ เราสามารถใช้ docker รันจาก week7 ได้เลย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eac967128518" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[การใช้งาน KsqlDB หรือ PySpark Structured Streaming ในการจัดการ Streaming data]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-ksqldb-%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD-pyspark-structured-streaming-%E0%B9%83%E0%B8%99%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3-streaming-data-eb165c46cf18?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb165c46cf18</guid>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Mon, 08 Apr 2024 15:56:49 GMT</pubDate>
            <atom:updated>2024-04-26T05:49:37.446Z</atom:updated>
            <content:encoded><![CDATA[<h4>การใช้งาน KsqlDB หรือ PySpark Structured Streaming ในการจัดการ Streaming data (ตอนที่ 1)</h4><p>บทความนี้เป็นการอธิบายเกี่ยวกับการติดตั้งและใช้งาน KsqlDB (<a href="https://ksqldb.io/quickstart.html">https://ksqldb.io/quickstart.html</a>) โดยสามารถทำตามขั้นตอนได้ดังนี้</p><p>บทความนี้จะใช้ Docker ในการรันระบบ Data Streaming &amp; Realtime Analytics โดยสามารถ Download ไฟล์ docker-compose.yml จาก Link <a href="https://github.com/ekaratnida/kafka-connect/blob/master/ksqldb/docker-compose.yml">https://github.com/ekaratnida/kafka-connect/blob/master/ksqldb/docker-compose.yml</a> และ<strong><em>ให้นำไฟล์ docker-compose.yml ไปไว้ในโฟลเดอร์ </em></strong><a href="https://github.com/ekaratnida/kafka-connect/tree/master"><strong><em>kafka-connect</em></strong></a><strong><em>-master ที่เรียนก่อนหน้านี้ (ในข้อ 2)</em></strong> จากนั้นให้รันโดยใช้ command: <strong>docker-compose up -d </strong>ถ้ารันสำเร็จจะมี service ดังแสดงในรูปด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cn53k07gNBPph3ySo9WW9Q.png" /></figure><p>ต่อมาให้เปิดเวบที่ URL localhost:8888 ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g53ohR7iL6T4Oj0OPQyYgA.png" /></figure><p>2. ระบบที่จะติดตั้งจะเป็นการส่งข้อความจาก Mysql (source) ไปยัง Mysql (sink) โดยใช้ Kafka connector ดังนั้นผู้ใช้งานต้องติดตั้ง Mysql (source+sink) และ connector ก่อนดังนี้<br>2.1 ให้ติดตั้ง Mysql (source) ให้ทำตามขั้นตอนที่ <a href="https://github.com/ekaratnida/kafka-connect/tree/master">https://github.com/ekaratnida/kafka-connect/tree/master</a> โดยให้เริ่มจากขั้นตอนที่ 6 ได้เลย (เป็นการส่ง source connector config ไปยัง Kafka) ดังนี้</p><pre>curl -d @&quot;source.json&quot; -H &quot;Content-Type: application/json&quot; -X POST http://localhost:8083/connectors</pre><p>หากทำสำเร็จ จะมีไฟล์ “quickstart-jdbc-source” ปรากฎในเวบตรงเมนู Kafka Connect ในหน้าเวบตามรูปข้างล่างนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KF68HAlH73Wk3reZSY3G_A.png" /><figcaption>มี quickstart-jdbc-source connector ในเมนู Kafka Connect</figcaption></figure><p>ต่อมาให้ทำต่อในขั้นตอนที่ 7 จะเป็นการติดตั้ง table และการ insert data (Sheldon) ใน Mysql โดยทำใน Docker ได้เลย หากทำสำเร็จจะเชคในเวบได้ดังรูปด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68FYtEnnUcgRp30HumHYMg.png" /><figcaption>1. มี quickstart-jdbc-test ในเมนู Topics</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvetaGB-NRsiizt_39eSLA.png" /><figcaption>2. มี quickstart-jdbc-test-value ในเมนู Schema Registry</figcaption></figure><p>2.2 ให้ติดตั้ง Mysql (sink) โดยให้ download ไฟล์ “docker-mysql.zip” จาก <a href="https://github.com/ekaratnida/kafka-connect/blob/master/docker-mysql.zip">https://github.com/ekaratnida/kafka-connect/blob/master/docker-mysql.zip</a><br>เมื่อ upzip ไฟล์แล้วให้แก้ IP address<strong> เป็น wifi ของตนเอง</strong> ดังตัวอย่างบรรทัดที่ 6 ของไฟล์ “<strong>sink2.json</strong>” และให้เปลี่ยน topics ในบรรทัดที่ 9 เป็นคำว่า “<strong>quickstart-clean</strong>” ดังรูปข้างล่างนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMxeQIFMKVrVypoNZmfaSw.png" /></figure><p>ต่อมาให้รัน docker-compose up -d ในโฟลเดอร์ docker-mysql หากสำเร็จจะเป็นดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycjB7B23sw7-5PEVdJuDiQ.png" /></figure><p>ต่อมาให้รัน curl ภายใต้ folder docker-mysql เพื่อติดตั้ง (mysql) sink connector</p><pre>curl -d @&quot;sink2.json&quot; -H &quot;Content-Type: application/json&quot; -X POST http://localhost:8083/connectors</pre><p>หากสำเร็จจะเชคได้ตามนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PH74w8_z95AVvIsT0YXL4w.png" /><figcaption>1. มี quickstart-avro-mysql-sink ในเมนู Kafka Connect</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*R3FmQiFX77Gim-C-mgJ3KA.png" /><figcaption>2. มี connect-quickstart-avro-mysql-sink ในเมนู Consumers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ziVBj9P-mJxWa5gZAEZ_kA.png" /><figcaption>3. มี quick-start-avro-mysql-sink (Connectors) ในเมนู Kafka Connect</figcaption></figure><p>ต่อมา create table <strong>test2 ใน docker Mysql sink</strong></p><pre>create table test2 (<br>      id int not null auto_increment,<br>      name varchar(100),<br>      email varchar(100),<br>      department varchar(100),<br>      modified timestamp not null default current_timestamp,<br>      primary key (id)<br>     );</pre><p>3. Run KsqlDB ด้วยคำสั่ง</p><pre>docker exec -it ksqldb-cli ksql http://ksqldb-server:8088</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y5mxF0-CInN3k1wk4eePXg.png" /><figcaption>หากรันสำเร็จจะมีหน้าตาดังรูปนี้ สังเกตคำว่า server status running</figcaption></figure><p>จากนั้นให้พิมพ์คำสั่ง print “quickstart-jdbc-test” from beginning; เพื่อเชคดูว่า มี sheldon อยู่ใน topic นี้หรือไม่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*P2P5EC49ZZngL0z-XPWMow.png" /><figcaption>แสดงข้อมูลที่ insert ไปยัง Mysql source แล้วไปอยู่ใน topic บน Kafka ( เราสามารถกด ctrl-c เพื่อ interrupt และกลับมา shell รอรับคำสั่งต่อไป )</figcaption></figure><p>ต่อมา สร้าง stream s1 บน topic “quickstart-jdbc-test” เพื่อนำมาใช้งานต่อ</p><pre>ksql&gt; CREATE STREAM s1 with (<br>          KAFKA_TOPIC=&#39;quickstart-jdbc-test&#39;,<br>          KEY_FORMAT=&#39;KAFKA&#39;,<br>          VALUE_FORMAT=&#39;AVRO&#39;<br>);</pre><p>เชคว่าสร้างสำเร็จหรือไม่ด้วยการพิมพ์คำสั่ง show streams จะมี s1 ปรากฎอยู่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwTCRF6VnY8PaTKROeRcjQ.png" /></figure><p>เรายังสามารถเชคข้อมูลใน s1 ได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SvpAX1wdCtOSfO5nlNV6eg.png" /></figure><p>ต่อมา สร้าง stream s2 บน topic “quickstart-clean” เพื่อนำมาใช้งานต่อ โดยข้อมูล s2 จะสัมพันธ์กับ s1 ดังนี้</p><pre>create stream s2<br> with (<br>  kafka_topic=&#39;quickstart-clean&#39;,<br>  value_format=&#39;avro&#39;<br> ) as<br>   select * from s1 emit changes;</pre><p>หากสร้าง stream s2 สำเร็จ จะมีข้อมูลในเวบ localhost:8888 ดังนี้</p><p>มี consumer เกิดขึ้นใหม่ในเมนู Consumers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hN0xx1KZzNkRpbGQwLkkgg.png" /></figure><p>มี quickstart-clean-value ในหน้าเมนู Schema Registry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ij1Nda-c2yo5kj9CTAGMpw.png" /></figure><p>ต่อมาให้ Insert data ใหม่เข้าไปใน Mysql (Source) ถ้าระบบที่เราติดตั้งสำเร็จ จะมีข้อความใหม่ใน Mysql (Sink) โดยเชคใน Mysql ใน Docker</p><p>ในตัวอย่างได้ insert ข้อมูลใหม่ดังรูปด้านล่าง</p><pre>INSERT INTO test (name, email, department) VALUES (&#39;sheldon2&#39;, &#39;sheldon2@bigbang.com&#39;, &#39;physicist2&#39;);</pre><p>กลับมาที่ KsqlDB เราเชค stream s1 และ s2 ได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3-eEAJAYtqxjEovvhrfGA.png" /></figure><p>มาถึงขั้นตอนนี้สรุปได้ว่า stream s1 จะเกี่ยวข้องกับ topic “quickstart-jdbc-test” ซึ่งเชื่อมกับ Mysql (Source) และ stream s2 จะเกี่ยวข้องกับ topic “quickstart-clean” ซึ่งเชื่อมกับ Mysql (Sink)</p><p>ถ้าเราต้องการ Modify data ก่อนส่งไปยัง sink เราสามารถปรับเปลี่ยนได้ที่ stream s2 (หมายเหต 1 topic kafka มีได้แค่ 1 stream สร้างโดย KsqlDB</p><p>ข้อมูลเพิ่มเติมในการใช้งานคำสั่ง KsqlDB <a href="https://ksqldb.io/examples.html#drop-a-stream">https://ksqldb.io/examples.html#drop-a-stream</a> และ</p><p>ตัวอย่างการ clean data <a href="https://www.confluent.io/blog/how-real-time-stream-processing-works-with-ksqldb/?_ga=2.65605806.1273066679.1712496378-1478735991.1712496378">https://www.confluent.io/blog/how-real-time-stream-processing-works-with-ksqldb/?_ga=2.65605806.1273066679.1712496378-1478735991.1712496378</a></p><p>PySpark ติดตามตอนต่อไปครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb165c46cf18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Web3 development from the Band Protocol tutorial]]></title>
            <link>https://pok-ekarat.medium.com/learn-web3-development-from-the-band-protocol-tutorial-5a3d83e32f12?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3d83e32f12</guid>
            <category><![CDATA[kovan-testnet]]></category>
            <category><![CDATA[band-protocol]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[solidity-tutorial]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 23:25:51 GMT</pubDate>
            <atom:updated>2022-03-22T23:30:27.026Z</atom:updated>
            <content:encoded><![CDATA[<p>I learned to create a web3 app (buy a ticket) with the Oracle (Band Protocol) from this Youtube, and these tutorial series are very great web3 development anyone must not miss it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXlZsy8v0sWU%3Fstart%3D3066%26feature%3Doembed%26start%3D3066&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXlZsy8v0sWU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXlZsy8v0sWU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cc0792dd80f3ea1db8179278a8b0ae4/href">https://medium.com/media/2cc0792dd80f3ea1db8179278a8b0ae4/href</a></iframe><p>However, it has one step in this tutorial that is difficult to follow up on. For example, I don’t know how to obtain the two currency addresses, shown below, from Youtube to my code, without looking &amp; typing each HEX character one by one. Moreover, it fixed just only THB/USD, and ETH/USD, I may want other currencies in the future apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NmHN7rJtvaoCGkSkkf6P9g.png" /></figure><p>So, I made it work by using the example from Band Protocol itself, integrated it into the code in the tutorial. In this solution, I used Koven Testnet to test the web3 app. The solidity shown below is my workable version. This code is still the workable version, but not a clean one, so anyone can improve or optimize it.</p><p><strong>BTW, Band protocol is a great Thai technology, and I’m very proud of it. Let’s use it :).</strong></p><pre>pragma solidity 0.6.11;</pre><pre>pragma experimental ABIEncoderV2;</pre><pre>interface IStdReference {</pre><pre>struct ReferenceData {</pre><pre>uint256 rate; // base/quote exchange rate, multiplied by 1e18.</pre><pre>uint256 lastUpdatedBase; // UNIX epoch of the last time when base price gets updated.</pre><pre>uint256 lastUpdatedQuote; // UNIX epoch of the last time when quote price gets updated.</pre><pre>}</pre><pre>function getReferenceData(string memory _base, string memory _quote)</pre><pre>external</pre><pre>view</pre><pre>returns (ReferenceData memory);</pre><pre>function getReferenceDataBulk(string[] memory _bases, string[] memory _quotes)</pre><pre>external</pre><pre>view</pre><pre>returns (ReferenceData[] memory);</pre><pre>}</pre><pre>contract TicketSeller {</pre><pre>IStdReference ref;</pre><pre>uint256 public price1;</pre><pre>uint256 public price2;</pre><pre>uint256 public remainingTickets;</pre><pre>mapping (address =&gt; uint256) private tickets;</pre><pre>//koven</pre><pre>//0xDA7a001b254CD22e46d3eAB04d937489c93174C3</pre><pre>//rikenby</pre><pre>//0x71046b955Cdd96bC54aCa5E66fd69cfb5780f3BB</pre><pre>constructor(uint256 totalTicket, IStdReference _ref) public {</pre><pre>remainingTickets = totalTicket;</pre><pre>ref = _ref;</pre><pre>}</pre><pre>function ticketCount(address owner) public view returns (uint256)</pre><pre>{</pre><pre>return tickets[owner];</pre><pre>}</pre><pre>function transfer(address to) public {</pre><pre>require(tickets[msg.sender]&gt;0,&quot;MUST_HAVE_TICKET&quot;);</pre><pre>tickets[msg.sender] -= 1;</pre><pre>tickets[to] += 1;</pre><pre>}</pre><pre>function buyTicket() public payable {</pre><pre>uint256 price = getTicketPrice();</pre><pre>require(msg.value &gt;= price, &quot;NOT_ENOUGH_PAYMENT&quot;);</pre><pre>require(remainingTickets &gt; 0, &quot;NO_MORE_TICKETS&quot;);</pre><pre>remainingTickets -= 1;</pre><pre>tickets[msg.sender] += 1;</pre><pre>}</pre><pre>function getPrice(string memory base, string memory quote) external view returns (uint256){</pre><pre>IStdReference.ReferenceData memory data = ref.getReferenceData(base,quote);</pre><pre>return data.rate;</pre><pre>}</pre><pre>function getRemainingTickets() public view returns (uint256)</pre><pre>{</pre><pre>return remainingTickets;</pre><pre>}</pre><pre>function getTicketPrice() public payable returns (uint256) {</pre><pre>IStdReference.ReferenceData memory data1 = ref.getReferenceData(&quot;THB&quot;,&quot;USD&quot;); //1 THB เท่ากับกี่ USD</pre><pre>price1 = data1.rate;</pre><pre>IStdReference.ReferenceData memory data2 = ref.getReferenceData(&quot;ETH&quot;,&quot;USD&quot;);</pre><pre>price2 = data2.rate;</pre><pre>return 100 * uint256(price1) * 1e18 / uint256(price2);</pre><pre>}</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3d83e32f12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[สร้างระบบ Real-time monitoring เบื้องต้นด้วย Python, InfluxDB และ Grafana]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A-real-time-monitoring-%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-python-influxdb-%E0%B9%81%E0%B8%A5%E0%B8%B0-grafana-625480a6e511?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/625480a6e511</guid>
            <category><![CDATA[influxdb]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Fri, 18 Mar 2022 00:39:09 GMT</pubDate>
            <atom:updated>2024-01-20T16:32:56.978Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ บทความนี้จะเป็น tutorial สำหรับการสร้างระบบ Real-time monitoring เบื้องต้น โดยใช้ script python และเขียนข้อมูลเก็บไว้ใน InfluxDB จากนั้นจะใช้ Grafana ในการดึงข้อมูลขึ้นมา</p><p><strong>หมายเหต</strong> โพสนี้เป็นส่วนหนึ่งของวิชา (วขวข 6005) การวิเคราะห์ข้อมูล ณ ขณะปัจจุบันและกระแสต่อเนื่องของข้อมูล</p><p><strong>หลักสูตร</strong> วท.ม. สาขาวิชาการวิเคราะห์ข้อมูลและวิทยาการข้อมูล (<a href="https://as.nida.ac.th/dads-1/"><strong>DADS</strong></a>) คณะสถิติประยุกต์ นิด้า</p><p><strong>Step 1 (Python)</strong></p><ol><li>ติดตั้ง library influxdb ดังนี้</li></ol><p>Ubuntu</p><blockquote># if no pip installed on your machine, sudo apt-get install python3-pip</blockquote><blockquote>python3 -m pip install influxdb</blockquote><p>window</p><blockquote>pip install influxdb-client</blockquote><p>Reference: <a href="https://pypi.org/project/influxdb-client/">https://pypi.org/project/influxdb-client/</a></p><p><strong>Step 2 ติดตั้ง InfluxDB</strong></p><p>2.1 ทำตามขั้นตอนจากเวบนี้</p><p><a href="https://docs.influxdata.com/influxdb/v2/install/?t=Docker">https://docs.influxdata.com/influxdb/v2/install/?t=Docker</a></p><p>2.2 Run InfluxDB จาก Powershell ดังนี้</p><blockquote>PS C:\Program Files\InfluxData\influxdb&gt; ./influxd</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1s3MJlZupmNOy3lhP2FKBQ.png" /><figcaption>Fig. 1</figcaption></figure><p>Start InfluxDB from <a href="http://localhost:8086/">http://localhost:8086/</a> and setup username and password, ตั้งชื่อ org และ bucket</p><ul><li>A bucket is a named location where time-series data is stored</li><li>org และ bucket อาจตั้งชื่ออะไรก็ได้เช่น “tmp”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jFyl7VMUMhP0bD1ptuuaQA.png" /><figcaption>Login</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEwCyFwhdM4N65faovOLWg.png" /><figcaption>First page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*uhclU1tLHO-um6h6DDyQfw.png" /><figcaption>Goto the 2nd button on the left menu</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bR6_Qdyasl3hZ0l2MO3noQ.png" /><figcaption>Click API Tokens and Generate API token</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BerfBj6YlpbacASxuE3rwQ.png" /><figcaption>Copy token to clipboard used in Step 3</figcaption></figure><p><strong>Step 3 (สร้าง python file ตั้งชื่อไฟล์ test.py)</strong></p><pre>import time<br>import random<br>import influxdb_client<br>from influxdb_client.client.write_api import SYNCHRONOUS</pre><pre>token = &quot;Your token&quot;<br>org = &quot;Your org&quot;<br>bucket = &quot;Your bucket&quot;</pre><pre># Store the URL of your InfluxDB instance<br>url=&quot;<a href="http://localhost:8086/">http://localhost:8086</a>&quot;</pre><pre>client = influxdb_client.InfluxDBClient(<br>    url=url,<br>    token=token,<br>    org=org<br>)</pre><pre>write_api = client.write_api(write_options=SYNCHRONOUS)</pre><pre>while True:<br>    <br>    time.sleep(5) # Delay for 1 minute (60 seconds).<br>    <br>    randomlist = random.sample(range(10, 30), 1)<br>    print(randomlist)<br>    <br>    p = influxdb_client.Point(&quot;my_measurement&quot;).tag(&quot;location&quot;,  <br>    &quot;Prague&quot;).field(&quot;temperature&quot;, float(randomlist[0]))<br>    <br>    write_api.write(bucket=bucket, org=org, record=p)</pre><p>Fig. 4 เป็นตัวอย่าง python ที่ใช้ในการสร้างข้อมูล time series แบบ random แล้วบันทึกใน influxdb ทุกๆ 5 วินาที ใน code จะมีการนำ token ที่สร้างจาก Fig. 3 และใส่ชื่อ org และ bucket ที่ได้ตั้งไว้</p><ul><li>Run python script “python test.py” ใน cmd terminal</li></ul><p><strong>Step 4 (Grafana)</strong></p><ul><li>Download and install Grafana from this link <a href="https://grafana.com/grafana/download?platform=windows">https://grafana.com/grafana/download?platform=windows</a></li><li>Goto: <a href="http://localhost:3000/">http://localhost:3000/</a> [ default username = “admin” and password = “admin” ]</li><li>ถ้า <a href="http://localhost:3000/">http://localhost:3000/</a> ไม่ทำงานให้ Double click “grafana-server.exe” ใน folder ที่ download ลงมา</li><li>เลือก data source “influxdb” ที่ <a href="http://localhost:3000/datasources/new?utm_source=grafana_gettingstarted">http://localhost:3000/datasources/new?utm_source=grafana_gettingstarted</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOv1jgw_84wRiyf1cJAMYw.png" /><figcaption>Fig. 5</figcaption></figure><ul><li>Click on ‘explore’ button (icon ตัวที่ 4 บนแถบ menu ด้านซ้ายมือ) and then insert the query script</li></ul><pre>from(bucket:&quot;Your bucket&quot;)</pre><pre>|&gt; range(start: -10m)</pre><pre>|&gt; filter(fn:(r) =&gt; r._measurement == &quot;my_measurement&quot;)</pre><pre>|&gt; filter(fn: (r) =&gt; r.location == &quot;Prague&quot;)</pre><pre>|&gt; filter(fn:(r) =&gt; r._field == &quot;temperature&quot; )</pre><p>ใน menu ขวาบน ให้เลือก<em> Last 15</em> minutes และ <em>Run query 5s</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zlsh57bPi8r0pZPfNitaMQ.gif" /><figcaption>Fig. 6 Animated gif file</figcaption></figure><p>ถ้าทุกอย่างถูกต้อง graph จะแสดงผลดังรูป gif ที่ Fig. 6</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=625480a6e511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GeoHot กับการช่วย Ethereum ในการเสกลไปเป็น Ethereum 2.0 (โชคชะตา ความบังเอิญ หรือ อะไร???)]]></title>
            <link>https://pok-ekarat.medium.com/geohot-%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%8A%E0%B9%88%E0%B8%A7%E0%B8%A2-ethereum-%E0%B9%83%E0%B8%99%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%AA%E0%B8%81%E0%B8%A5%E0%B9%84%E0%B8%9B%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99-ethereum-2-0-%E0%B9%82%E0%B8%8A%E0%B8%84%E0%B8%8A%E0%B8%B0%E0%B8%95%E0%B8%B2-%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%9A%E0%B8%B1%E0%B8%87%E0%B9%80%E0%B8%AD%E0%B8%B4%E0%B8%8D-%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD-%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-b39d760ca0d7?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b39d760ca0d7</guid>
            <category><![CDATA[geohot]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[blockchai]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Sun, 29 Aug 2021 02:58:30 GMT</pubDate>
            <atom:updated>2021-09-23T01:52:31.997Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>หมายเหตุ:</strong> บทความนี้ถูกเขียนออกมาจากการผสมผสานระหว่างการแปลแบบภาพรวมและการค้นคว้าโดยผู้เขียนเองเกี่ยวกับประวัติศาสตร์ของ Ethereum 2.0 ที่เกี่ยวข้องกับ Geohot หากผู้อ่านพบเจอข้อผิดพลาดหรือข้อผิดสังเกตประการใด ผู้อ่านสามารถส่งข้อความมาเพื่อที่จะได้ปรับปรุงบทความต่อๆ ไป</blockquote><p>เรื่องราวทั้งหมดถูกบันทึกไว้ใน Twitter ที่โพสโดย <a href="https://twitter.com/jinglanW">Jing</a> พนักงานของ Optimism (หมายเหตุ: Optimism <a href="https://optimism.io/">https://optimism.io/</a> เป็นบริษัทที่ช่วยในการเสกล Ethereum) เรื่องราวถูกบันทึกดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfooW-zYxCJgWk8lJPRwug.png" /><figcaption>Tweet ที่ กล่าวถึงเหตุการณ์</figcaption></figure><p>ครั้งหนึ่งทีมของเราได้ทำงานอย่างหนึ่ง นั่นคือ การเปลี่ยน <a href="https://en.wikipedia.org/wiki/Source-to-source_compiler">transpiler</a> ของ EVM (Ethereum Virtual Machine) ไปเป็น OVM (Optimistic Virtual Machine). ในการทำงานชิ้นนี้นั้น พบว่า 90% ของเนื้องานไม่ได้ยากมากนัก แต่ 10% ที่เหลือจะค่อนข้างยาก โชคไม่ค่อยดีที่เรามีกำลังคนไม่พอและทุกคนมีงานล้นมือ เราจึงได้ขอความช่วยเหลือจากกลุ่มนักพัฒนา Solidity แต่ก็ไม่เป็นผล เพราะว่าทางกลุ่มนั้นเองก็มีงานล้นมือเหมือนกัน</p><p>ฉัน (Jing) ได้แนะนำให้พวกเราในทีมช่วยกันค้นหาใครสักคนที่จะช่วยพวกเราได้ แต่ <a href="https://twitter.com/ben_chain">@ben_chain</a> เตือนว่าแทบจะเป็นไปไม่ได้เลยที่จะหาใครคนนั้นเจอ น้อยคนนักที่จะเป็นผู้เชี่ยวชาญทางด้าน EVM compiler แต่ฉันก็ต้องตามหาเพราะ deadline ที่กระชั้นเข้ามา ด้วยความกดดันและเหนื่อยล้า ทีมเราได้ไปพักกินอาหารกันข้างนอกการกินครั้งนี้เป็นครั้งแรกหลังจาก COVID เริ่มเข้ามา ทันใดนั้นเองฉันก็ได้เหลือบไปเห็นคนๆ นึงในร้าน ซึ่งมีลักษณะคล้ายกับ Geohot มาก เราจึงเรียกเขาและเขาก็ตอบรับเป็นอย่างดี เราเรียกเขามานั่งด้วยกันที่โต๊ะ แนะนำตัวเองและบริษัทของเรา</p><p>Geohot พูดออกมาว่า “พวกคุณกำลังเสกล Ethereum ใช่มั๊ย …” พวกเราถึงกับช๊อคกับสิ่งที่เขาพูด เราได้เริ่มอธิบายการออกแบบการเสกลใหม่ของ Ethereum ให้เขาฟัง เขารู้สึกทึ่ง และยิงคำถามเชิงลึกเกี่ยวกับ Ethereum และ EVM</p><p>ให้ตรงประเด็นกันไปเลย เราถามเขาว่าเขามีคำแนะนำใดๆ หรือไม่ที่จะทำให้งานที่เราทำอยู่เสร็จทันเวลา เขามองมาที่เราอย่างครุ่นคิดครู่หนึ่งแล้วยิ้มนิดๆ (ถ้าผู้อ่านรู้จัก Geohot ผู้อ่านน่าจะนึกหน้าของเขาออกในจังหวะนี้) พร้อมกับพูดว่า “เอาล่ะ คุณต้องการมันมากแค่ไหน”</p><p>วันแรกที่เขามาทำงานให้เรา เขาเพียงแค่นั่งจ้องมองหน้าคอมพิวเตอร์อยู่หลายชั่วโมง เราเฝ้ามองเขาอย่างสงสัย หลังจากแค่ “คิด” ในวันแรก วันต่อๆ มาจอร์จก็ทำงาน (พิมพ์) ด้วยความเร็วเหนือมนุษย์ ทุก ๆ สองสามชั่วโมงเขาแก้ปัญหาสำคัญๆ ที่ต้องใช้เวลาหลายวันสำหรับคนเก่งมากๆ</p><p>จากนั้นสามวันต่อมาเขาก็ส่งมอบ compiler ที่มี sourcecode แตกต่างจาก solc <a href="https://github.com/ethereum-optimism/solidity/pull/1">280 บรรทัด</a> เราถามเขาว่าเขาทำมันได้ยังไง เขาตอบว่า คุณแค่ต้องคิดและทำมันให้ถูกต้องด้วยความช่วยเหลือของเขา เราสามารถทำงานได้ทันเวลา เขาช่วยเราได้มากและเขาก็ยังเตือนเราว่า เรากำลังแก้ปัญหาที่น่าสนใจและเราควรที่จะสนุกไปกับมัน</p><p>นี้…..เป็นเรื่องราวของ George Hotz (GeoHotz) ที่ช่วยชีวิตพวกเราไว้!</p><p>ใครอยากฟังไอเดียของ GeoHot กับการช่วย optimism ลองฟังในนี้เพิ่มได้ครับ บทความหน้าผมจะมาเจาะลึกมากยิ่งขึ้น</p><p>“If you want to be a good programmer do it for 20 years.”</p><p>“No shortcuts”</p><p><a href="https://www.youtube.com/watch?v=1jurXjIX_eA">https://www.youtube.com/watch?v=1jurXjIX_eA</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b39d760ca0d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[การเรียกใช้งาน Python ด้วยภาษา Java]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%81%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-python-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2-java-16ed11e882a0?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/16ed11e882a0</guid>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jython]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Sat, 21 Mar 2020 09:55:41 GMT</pubDate>
            <atom:updated>2020-07-09T15:40:43.792Z</atom:updated>
            <content:encoded><![CDATA[<h3>เรียกใช้งาน Python ด้วยภาษา Java</h3><p>ภาษา Java นั้นถูกใช้ในการสร้าง Software applications ต่างๆ มากมาย เช่น IDE, ElasticSearch, Burp suite, หรืออภิมหาเกมส์อย่าง Minecraft, etc.. ส่วน Python นั้นถูกใช้อย่างกว้างขวางในงานทางด้าน AI</p><p>ปัจจัยที่ทำให้ Python ถูกใช้งานทางด้าน AI อย่างแพร่หลายเนื่องจากความสะดวกในการเรียกใช้ library ที่มีให้ใช้อย่างมากมาย จึงทำให้สามารถใช้ทำงานทดสอบสมมติฐานบางอย่างได้อย่างรวดเร็ว รวมไปถึงการสร้าง Mathematical models ในงานจำพวก Machine Learning อีกด้วย</p><p>แต่การจะสร้าง Desktop app ด้วย ภาษา python บวกกับ GUI library เช่น PyQT, Tkinter นั้น ตัวผู้เขียนเองรู้สึกว่าไม่ค่อยสนุกเท่าที่ควร ประกอบกับผู้เขียนได้เคยใช้ Java ในการสร้าง Desktop apps มาก่อน ดังนั้นผู้เขียนเองจึงได้หาวิธีที่จะผสมผสานการทำงานของสองภาษานี้ขึ้นมาโดยจะอธิบายวิธีการในบทความนี้ (เครื่องมือที่ใช้ในบทความนี้คือ MAC Catalina 10.15.3, Visual Studio Code, java version “1.8.0_191”, Python 3.7.4 โดยการ Compile และ Run จะใช้ Terminal เป็นหลัก ผู้เขียนขอละวิธีการ set path ให้ผู้อ่านไปหาวิธีกันเองนะครับ โอเคเรามาเริ่มต้นกันเลย</p><p>เริ่มต้นที่ Code Java (Main.java)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQJnoW7MVMW79aJgfqGfew.png" /><figcaption>Main.java</figcaption></figure><p>ต่อมา Code Python (PythonMain.py)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*cO6qyR10ooVrxG6_bHqJvA.png" /><figcaption>PythonMain.py</figcaption></figure><p>จากนั้นให้ไป download file “jython-standalone-2.7.1.jar” มาจาก website</p><p><a href="https://www.jython.org/download">Downloads</a></p><p>สรุปตอนนี้เรามีไฟล์ทั้งหมด 3 ไฟล์ โดยจะเก็บไว้ใน Folder ดังนี้ สมมติผู้เขียนได้สร้าง Folder ชื่อ javapython เป็น root สำหรับโปรเจคนี้ ดังนั้นใน Folder นี้จะประกอบด้วย</p><ol><li>ไฟล์ PythonMain.py</li><li>สร้าง Folder ใหม่ชื่อ jars และให้เก็บไฟล์ jython-standalone-2.7.1.jar ที่ดาวน์โหลดมาไว้ใน Folder jars นี้</li><li>สร้าง Folder ใหม่ชื่อ com และต่อมาให้สร้าง Folder ใหม่ชื่อ pok ใน Folder com อีกทีนึง (Folder com/pok เป็นชื่อตาม package com.pok ที่อยู่ในบรรดทัดแรกของ code java ซึ่งผู้อ่านสามารถเปลี่ยนตามความต้องการได้) ต่อมาให้เก็บไฟล์ Main.java ไว้ใน Folder com/pok/ อีกทีนึง</li></ol><p>ต่อมาจะแสดงวิธีการใช้ command line ในการ compile และ run โปรแกรมดังนี้</p><ol><li>การ Compile ให้เข้าไปใน Folder javapython โดยใช้ Terminal และให้พิมพ์คำสั่งดังนี้</li></ol><p><strong>javac -cp “.:./jars/jython-standalone-2.7.1.jar” com/pok/Main.java</strong></p><p><strong>2</strong>. การ Run ให้พิมพ์คำสั่งดังนี้</p><p><strong>java -cp “.:./jars/jython-standalone-2.7.1.jar” com.pok.Main</strong></p><p>ถ้าไม่มี error ใดๆ โปรแกรมก็จะแสดงผลลัพธ์ดังข้อความข้างล่างนี้ครับ</p><p><strong>Hello. Test Succeeded!</strong></p><p>ในตอนต่อไป ผู้เขียนจะแสดงวิธี ในการผ่านค่าเข้าไปใน function ของ python รวมไปถึงการสร้าง GUI บน Java ในลำดับต่อๆไป ขอบคุณครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16ed11e882a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[หัดใช้ Ghidra กันครับ]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B8%AB%E0%B8%B1%E0%B8%94%E0%B9%83%E0%B8%8A%E0%B9%89-ghidra-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%B1%E0%B8%9A-48597ceffe05?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/48597ceffe05</guid>
            <category><![CDATA[ghidra]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Mon, 19 Aug 2019 14:09:51 GMT</pubDate>
            <atom:updated>2022-03-13T11:39:40.970Z</atom:updated>
            <content:encoded><![CDATA[<p>ช่วงนี้สนใจลองเล่น Ghidra ในการ reverse engineering ครับ ใครสนใจลองดูได้ครับ</p><p>ลองใช้ครั้งแรกในการ crack password ของโปรแกรม easy_one ใน <a href="https://crackmes.one/crackme/5d443bb533c5d444ad3018b3">https://crackmes.one/crackme/5d443bb533c5d444ad3018b3</a></p><p>Video tutorial</p><p><a href="https://web.facebook.com/pok.pok.330467/videos/2382943035365643/">https://web.facebook.com/pok.pok.330467/videos/2382943035365643/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48597ceffe05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ใช้ Radare2 สำหรับ reverse engineering]]></title>
            <link>https://pok-ekarat.medium.com/%E0%B9%83%E0%B8%8A%E0%B9%89-radare2-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-reverse-engineering-c926aad21f64?source=rss-1e693fe42a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c926aad21f64</guid>
            <category><![CDATA[reverse-en]]></category>
            <category><![CDATA[radare2]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ekarat Rattagan]]></dc:creator>
            <pubDate>Sun, 21 Oct 2018 14:46:20 GMT</pubDate>
            <atom:updated>2018-10-21T15:01:52.557Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>จากการได้อ่านตัวอย่างวิธีการใช้ <a href="https://www.frida.re/docs/examples/android/">Frida</a> ก็มีการเชื่อมไปยังการ CTF ของ apk ตัวนึงที่ <a href="https://github.com/ctfs/write-ups-2015/tree/master/seccon-quals-ctf-2015/binary/reverse-engineering-android-apk-1">link</a> นี้ ซึ่งใน link ก็มี solution หลายวิธี แต่ว่าเมื่อลองทำตาม <a href="https://ascopectf.wordpress.com/2015/12/06/seccon2015reverse-engineering-android-apk-1binary100/">solution หนึ่ง</a>ดู ก็ไปติดตรงที่ต้องใช้โปรแกรม IDA (ซึ่งไม่น่าจะฟรี) ก็เลยใช้ <a href="https://rada.re/r/">Radare2</a> แทนดูครับ</blockquote><blockquote>การใช้งานเริ่มจาก step 3 (step 1 &amp; 2 เป็นการ reverse apk เพื่อเอา classes.jar)ใครสนใจลองทำดูได้ตามตัวอย่างข้างล่างนะครับ</blockquote><ol><li>unzip xxx.apk -d xxx</li></ol><p>2. d2j-dex2jar.sh classes.dex to classes.jar</p><p>3. r2 libcalc.so (ในตัวอย่างใช้ IDA)</p><p>4. aaa — analyzing the binary<br>5. afl — list the functions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cv5c1je9oQytpxVOHqe7IQ.png" /></figure><p>6. s — seeking the function</p><p>7. pdf —print disassemble function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLFXivt4n4bP5vBGTUSzNg.png" /></figure><p>จะเห็นว่าฟังก์ชั่น return ค่า 7 เช่นเดียวกับการใช้ IDA ใน solution ข้างต้น</p><p>Note: radare2 ใช้ <a href="http://www.unicorn-engine.org/showcase/">Unicorn</a> ซึ่งเป็น CPU emulator ที่ดีมากๆ ตัวหนึ่งในยุคนี้ ใครสนใจทางด้าน Reverse Engineering เทอมที่จะถึงนี้จะมีเปิดวิชานี้ที่ ปริญญาโท IT มหานคร สอนโดย อ ที่มีชื่อเสียงในวงการทางด้านนี้ น่าสนใจมากครับ เชิญชวนให้มาเรียนกัน</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c926aad21f64" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>