Skip to content

Instantly share code, notes, and snippets.

View ThanawatMas's full-sized avatar

Aouoho ThanawatMas

View GitHub Profile
@ThanawatMas
ThanawatMas / ThaiEncodeIssue.java
Created September 14, 2020 06:26
Read Thai Character in DB
private static String convert2Round(String thaiString) throws UnsupportedEncodingException {
String result = "";
String[] charset = {"ISO-8859-1", "UTF-8", "TIS-620"};
for(int i=0; i<charset.length; i++) {
for(int j=0; j<charset.length; j++) {
if(charset[i].equals(charset[j])) {
continue;
}
String encode = "Style: algo=" + charset[i] + ">" + charset[j] + "\n";
encode += "Style: result=" + new String(thaiString.getBytes(charset[i]), charset[j]);
public class MergeOperation implements RxOperationCase {
@Override
public void runSmoothAtSilk() {
String TAG = "MergeOperation.runSmoothAtSilk";
System.out.println(TAG + " START >>>>>> ");
Observable.merge(UserProfile.mockApi(), LuckyCategory.mockApi(), FortuneQueue.mockApi())
.observeOn(Schedulers.io())
public class FortuneQueue implements Api {
private int entryNo;
private Date entryTime;
private int luckyScale;
public static Observable<Api> mockApi() {
FortuneQueue queue = new FortuneQueue();
queue.setEntryNo(25);
queue.setEntryTime(new Date(System.currentTimeMillis()));
queue.setLuckyScale(5);
public class LuckyCategory implements Api {
private String category;
private int entryNo;
private double discountRate;
public static Observable<Api> mockApi() {
LuckyCategory luckyCategory = new LuckyCategory();
luckyCategory.setCategory("Shoe");
luckyCategory.setEntryNo(25);
luckyCategory.setDiscountRate(10.5);
public class UserProfile implements Api {
private String id;
private String name;
private int level;
private long userExp;
private long expToNextLevel;
private String currentCategory;
public static Observable<Api> mockApi() {
return Observable.just(getUserFromSession("mocking"));
public class Experiment {
private static final long WAIT_TIME = TimeUnit.SECONDS.toMillis(1);
private static void wait1Seconds() {
try {
Thread.sleep(WAIT_TIME);
System.out.println();
} catch (InterruptedException e) {
e.printStackTrace();
public interface Api {
String getApiName();
}
@ThanawatMas
ThanawatMas / ​LuckyLogic.java
Last active December 2, 2018 16:41
Lucky logic for RxOperation Merge & Zip
boolean luckyUserFortuneQueue.enterNo(API 2) == LuckyCategory.enterNo(API 3) && 
UserProfile.currentCategory(API 1) == LuckyCategory.category(API 3);
if(luckyUser) {
boolean receiveSpecialDiscount =
((FortuneQueue.luckyScale(API 2) * UserProfile.userExp(API 1))/ UserProfile.expToNextLevel(API 1))
> 1;
if(receiveSpecialDiscount) {
discountAmount = totalBuy * LuckyCategory.discountRate(API 3);
payAmount = totalBuy - discountAmount;
@ThanawatMas
ThanawatMas / DivideExample.java
Last active October 31, 2018 02:17
Different between divide by int, and divide by double
public class DivideExample {
public static void main(String[] args) {
int a = 9;
int b = 2;
int c = 5;
double average1 = (a+b+c) / 3;
System.out.println("average1 of a+b+c = " + average1);
int x = 9;
int y = 2;
AskMonitor am = new AskMonitor("Time Vortex Hocus", 2, alarm);
am.setValue(3);
if (am.getValue() > am.getLimit())
am.getAlarm().warn(am.getName() + " too high");