Skip to content

Instantly share code, notes, and snippets.

@john990
john990 / SelectImage.java
Created March 27, 2015 06:54
android select image from gallery or camera, and crop
private String cameraFileName;
@Override
public void choiceAvatarFromCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraFileName = Constants.DOWNLOAD_IMAGE_PATH + System.currentTimeMillis();
File file = new File(Constants.DOWNLOAD_IMAGE_PATH);
if(!file.exists()){
file.mkdirs();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(cameraFileName)));
@john990
john990 / flaskwithcron.py
Created January 24, 2016 03:25 — forked from chadselph/flaskwithcron.py
flask with "cron"-like loop
from flask import Flask, render_template, jsonify, request
from threading import Timer, Thread
from time import sleep
app = Flask(__name__)
@app.route("/api/<method>")
def api(method):
data = {
@john990
john990 / Upload.java
Created February 19, 2016 06:42
android upload file
public String commonUpload(Context cxt, String url, Map<String, String> params,
List<UploadFile> uploadFiles, Map<String, String> properties, String encoding) throws IOException {
// 定义POST体中分割线
String BOUNDARY = "124324471239807512395795";
String PREFIX = "--";
String ENDLINE = "\r\n";
String CONTENT_TYPE = "multipart/form-data";
// long contentLen = 0;
// 1. 拼接HTTP 请求头
HttpURLConnection httpConn = NetworkUtils.openHttpURLConnection(cxt, url);
@john990
john990 / PrintChar.java
Last active March 20, 2018 06:57
线程间通信,wait、notify的使用
package com.java.test.thread;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by John on 18/3/19.
* 使用三个线程使得ABC 循环输出十次
*/
public class PrintABC {
/**
* Attempts to get the ViewHolder for the given position, either from the Recycler scrap,
* cache, the RecycledViewPool, or creating it directly.
* <p>
* If a deadlineNs other than {@link #FOREVER_NS} is passed, this method early return
* rather than constructing or binding a ViewHolder if it doesn't think it has time.
* If a ViewHolder must be constructed and not enough time remains, null is returned. If a
* ViewHolder is aquired and must be bound but not enough time remains, an unbound holder is
* returned. Use {@link ViewHolder#isBound()} on the returned object to check for this.
*