Skip to content

Instantly share code, notes, and snippets.

Avatar

Aouoho ThanawatMas

View GitHub Profile
@ThanawatMas
ThanawatMas / ThaiEncodeIssue.java
Created Sep 14, 2020
Read Thai Character in DB
View ThaiEncodeIssue.java
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]);
View MergeOperation.java
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())
View Experiment.java
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();
View Api.java
public interface Api {
String getApiName();
}
View UserProfile.java
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"));
View LuckyCategory.java
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);
View FortuneQueue.java
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);
@ThanawatMas
ThanawatMas / ​LuckyLogic.java
Last active Dec 2, 2018
Lucky logic for RxOperation Merge & Zip
View ​LuckyLogic.java
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 Oct 31, 2018
Different between divide by int, and divide by double
View DivideExample.java
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;
View AskMonitor.java
AskMonitor am = new AskMonitor("Time Vortex Hocus", 2, alarm);
am.setValue(3);
if (am.getValue() > am.getLimit())
am.getAlarm().warn(am.getName() + " too high");