Google reCapacha

<%@page import="java.net.*, java.io.*"%>

<%@page import="java.net.*, java.io.*"%>

<%@ page language="java" contentType="text/html; charset=UTF-8″ pageEncoding="UTF-8″%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%  response.setCharacterEncoding(“UTF-8″); request.setCharacterEncoding(“UTF-8″);%><html>

<header> <title></title> </header>

<body>

<form action = “#" method = “POST">

https://www.google.com/recaptcha/api.js

<input type = “submit" value = “Submit" />

</form>

<% String g_recaptcha_response = (String)request.getParameter(“g-recaptcha-response"); String secret="CCDDBBAA";

URL dest = new URL(“https://www.google.com/recaptcha/api/siteverify?secret="+secret+"&response="+g_recaptcha_response);

URLConnection yc = dest.openConnection();

BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream()));
StringBuffer sb = new StringBuffer();

String inputLine;

while ((inputLine = in.readLine()) != null){ sb.append(inputLine); }

if (!sb.toString().matches(“.+\"success\"\\s*:\\s*true\\s*.+") )

out.println(sb.toString());

in.close();

%>

</body>

</html>

張貼在 Uncategorized | 發表留言

Java 去除空白/控制字元

String content = new String(bytes, “UTF-8″).replaceAll(“\\u001A", “") String content = new String(bytes, “UTF-8″).replaceAll(“\\u001A", “") .replaceAll(“[^\\u0009\\u000A\\u000D\u0020-\\uD7FF\\uE000-\\uFFFD\\u10000-\\u10FFF]+","");

張貼在 Uncategorized | 發表留言

MySQL的recursive 遞迴SQL

參考:http://stackoverflow.com/questions/16513418/how-to-do-the-recursive-select-query-in-mysql

有一個Table 類似以下資料:

id        name        parentid
1          T1              NULL
2          T2              1
3          T3              2
4          T4              3

SQL語法:

SELECT * FROM (
select t.id, t.name, @pv := t.parentid parentid
from (select * from recursivetable order by id desc ) t
join (select @pv := 4) tmp
where t.id = @pv
) r

 

張貼在 Uncategorized | 發表留言

X-Mouse Button Control

前一陣子買了一個人體工學造型的滑鼠,價格合理。但唯一的缺點就是中鍵按鈕太淺,滾輪的時候很容易誤壓到,造成視窗內自由滑動的動作。

今天無意間看到有個免費的滑鼠驅動程式,可以關閉中鍵,非常的好用,而且支援正體中文。實在是太贊了!

http://www.highrez.co.uk/downloads/XMouseButtonControl.htm

 

張貼在 Uncategorized | 發表留言

Android AsyncTask 基本操作ProgressDialog

AsyncTask myTask = new AsyncTask<Void, Void, Void>() {
android.app.ProgressDialog myDialog;

@Override
protected void onPreExecute() {
// final android.app.ProgressDialog
myDialog = android.app.ProgressDialog.show(QueryMainActivity.this,"", “處理中,請稍候….", true);
}
protected Void doInBackground(Void… params){ // URL… urls) {
return null;
}
@Override
protected void onProgressUpdate(Void… values) {
super.onProgressUpdate(values);
}

@Override
protected void onPostExecute(Void args) {
myDialog.dismiss();
}
};
if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB)
myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
else
myTask.execute();

張貼在 Uncategorized | 發表留言

Android 當想要用 setBackgroundColor時,請以setColorFilter代替

當想要用 .setBackgroundColor時,請以setColorFilter代替

// 當想要用 .setBackgroundColor時,請以setColorFilter代替
.setBackgroundColor(Color.parseColor("#F8CCCC"));

.getBackground().setColorFilter(Color.parseColor("#F8CCCC"), android.graphics.PorterDuff.Mode.MULTIPLY);
張貼在 Uncategorized | 發表留言

Android RecycleView的基本式

參考自:http://givemepass.blogspot.tw/2015/12/recyclerview.html

在MainActivity中的onCreate()加入:

java.util.ArrayList<String> myDataset = new java.util.ArrayList<>();
for(int i = 0; i < 100; i++){
    myDataset.add(Integer.toString(i));
}
SearchRecycleAdapter mAdapter = new SearchRecycleAdapter(myDataset);
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.queryMainSearchView);
LinearLayoutManager layoutManager = new LinearLayoutManager(QueryMainSearchActivity.this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter);

在MainActivity中加入:

public class SearchRecycleAdapter extends android.support.v7.widget.RecyclerView.Adapter<SearchRecycleAdapter.ViewHolder> {
    private java.util.List<String> mData;
    public SearchRecycleAdapter(java.util.List<String> data) {
        this.mData = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.mTextView.setText(mData.get(position));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(QueryMainSearchActivity.this, "Item " + " is clicked.", Toast.LENGTH_SHORT).show();
            }
        });
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(QueryMainSearchActivity.this, "Item " + " is long clicked.", Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder {
        public TextView mTextView;
        public ViewHolder(View v) {
            super(v);
            mTextView = (TextView) v.findViewById(R.id.info_text);
        }
    }
}
張貼在 Uncategorized | 發表留言