Skip to content

Instantly share code, notes, and snippets.

/**
* 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.
*
@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 {
@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 / 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 / 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 / FlipAnimation.java
Created November 24, 2014 09:24
rotate 3d animation
package com.dianxinos.wifimgr.widget;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.Transformation;
@john990
john990 / HexMD5.java
Created October 11, 2014 02:38
获取字符串16进制MD5值(32位)
/**
* 16进制MD5值
* @param message
* @return
* @throws Exception
*/
private String hexdigest(String message) throws Exception {
String hd;
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(message.getBytes());
@john990
john990 / AESDecrypt.java
Created October 11, 2014 02:36
AES解密
public static String decrypt(String encryptedData) throws Exception {
Key key = new SecretKeySpec(KEY.getBytes(), "AES");
Cipher c = Cipher.getInstance("AES/CBC/NoPadding");
IvParameterSpec iv = new IvParameterSpec(IV.getBytes());
c.init(Cipher.DECRYPT_MODE, key,iv);
byte[] decValue = c.doFinal(encryptedData.getBytes());
String decryptedValue = new String(decValue);
return decryptedValue;
}
@john990
john990 / wifi_state.java
Created April 25, 2014 02:23
监听wifi状态(android)
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (null != parcelableExtra) {
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
if (networkInfo.getState() == State.CONNECTED) {
netManager.start(true);
} else if (networkInfo.getState() == State.DISCONNECTED) {
Const.IS_CONNECTED = false;
netManager.close();
Intent netDis = new Intent(Const.NET_STATE_DISCONNECT);
from selenium import selenium
from scrapy.spider import BaseSpider
from scrapy.http import Request
import time
import lxml.html
class SeleniumSprider(BaseSpider):
name = "selenium"
allowed_domains = ['selenium.com']
start_urls = ["http://localhost"]