Skip to content

Instantly share code, notes, and snippets.

@HabaCo
HabaCo / proxy-server.js
Last active March 15, 2022 10:26
A simply proxy-server can handle web-based request across CORS (easy run with node js)
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const request = require('request');
const port = 8088;
const app = express();
app.use(cors())
@HabaCo
HabaCo / MainActivity.java
Created November 19, 2019 06:53
WebView interaction with Html
package com.habaco.test.js2webview
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.webkit.JavascriptInterface
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
@HabaCo
HabaCo / 0623_Q3捕魚.java
Last active August 29, 2015 14:02
Synchronized
//店鋪
public class FishShop {
int curFishAmount=0; // 魚當前的數量
int containment=10000; // 可存放魚獲最大容量(10000)
int times=0; // 交易次數
public synchronized void putFish(int amount, String fisherName){
if (curFishAmount+amount<=containment){ // 當前魚獲的存量若小於最大容量
curFishAmount+=amount; // 入存貨
System.out.println(fisherName + "進貨 "+ amount + " 條魚," + " 目前共有 " + curFishAmount + " 條魚.");
@HabaCo
HabaCo / 0623_Q2賽馬.java
Created June 23, 2014 12:07
Thread 執行緒並行
public class Horse implements Runnable{
static int rankh=1; // 利用 static 使其他 Horse 共用此變數(名次)
int runSpeed; // 跑速不大於 5
int sleepTime; // 休息不大於 1 秒
int totalSleepTime =0; // 總共是睡了多久啊
int range=0; // 起跑點
int end = 500; // 終點
String horseName;
@HabaCo
HabaCo / 0623_Q1購物.java
Last active August 29, 2015 14:02
使用 HashMap 計算
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
public class Shop {
public static void main(String[] args) throws IOException {
/* example data:
A,4
B,3
@HabaCo
HabaCo / ArrayList.java
Created June 16, 2014 11:26
Student 類別, HashSet 找值, TreeSet 排序找值, LinkedList 排序找值, ArrayList 排序找值
package Test01;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class StudentArrayList {
@HabaCo
HabaCo / Q8分數加減乘除.java
Created June 10, 2014 13:09
讀檔&2個分數加減乘除
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
// 2個分數加減乘除
public class Q940308 {
public static void main(String[] args) throws IOException{
String fileName = "940308.SM";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
@HabaCo
HabaCo / Q7車流量.java
Last active August 29, 2015 14:02
讀檔&計算車流量
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
// 車流量
public class Q940307 {
public static void main(String[] args) throws IOException {
String fileName = "940307.SM";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
@HabaCo
HabaCo / Q6身份證驗證.java
Last active August 29, 2015 14:02
讀檔&身份證驗證&排序
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
// 身份證驗證
public class Q940306 {
public static String sample = "ABCDEFGHJKLMNPQRSTUVXYWZIO";
public static void main(String[] args) throws IOException{
String fileName = "940306.SM";
FileReader fr = new FileReader(fileName);
@HabaCo
HabaCo / Q5矩陣相加.java
Created June 10, 2014 13:05
讀檔&矩陣相加
package Quiz;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
// 2矩陣相加 (等邊的方矩陣)
public class Q940305 {
public static void main(String[] args) throws IOException{
String fileName = "940305.SM";