Skip to content

Instantly share code, notes, and snippets.

@wendal
wendal / gist:f933db4de81b62aadb05
Created December 29, 2014 07:28
nutz访问https(就是证书不合格的12306)的方法
@Test
public void test_12306() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sc = SSLContext.getInstance("SSL");
TrustManager[] tmArr={new X509TrustManager(){
public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException{}
public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() {return null;}
}};
sc.init(null, tmArr, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
@wendal
wendal / nutz_yeelink.java
Created October 22, 2014 03:13
演示用nutz调用yeelink的http api
public static void main(String[] args) {
int count = 0;
int[] array = new int[]{0, 12, 56, 58, 100, 134, 180, 200}; // 添加头尾
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[j] - array[i] > 50) {
if (i + 1 == j) {
System.out.println("-1"); // 跳不过去了
System.out.println("BAD At " + array[i] + " TO " + array[j]);
return;
@wendal
wendal / TransAop.java
Created August 29, 2014 07:34
nutz演示一下自定义Loader来简化注解事务的配置
package org.nutz.trans.aop;
public interface TransAop {
String NONE = "txNONE";
String READ_UNCOMMITTED = "txREAD_UNCOMMITTED";
String READ_COMMITTED = "txREAD_COMMITTED";
String REPEATABLE_READ = "txREPEATABLE_READ";
String SERIALIZABLE = "txSERIALIZABLE";
@wendal
wendal / mqtt_led.ino
Last active August 29, 2015 14:05
Yeelink: W5500模块+mqtt 控制LED灯
#include <SPI.h>
#define WIZ550io_WITH_MACADDRESS 1
#include <Ethernet.h>
#include "EthernetClient.h"
#include "PubSubClient.h"
#define WIZ550io_WITH_MACADDRESS 1
#include <JsonParser.h>
using namespace ArduinoJson::Parser;
package org.nutz.ioc.impl;
import java.io.File;
/**
* 代理Properties文件,以便直接在Ioc配置文件中使用
*
* @author wendal(wendal1985@gmail.com)
* @author zozoh(zozohtnt@gmail.com)
*
@wendal
wendal / gist:f48dc7bc6a71f3bb76a5
Last active August 29, 2015 14:03
被坑了一天, Java类型的问题
// data is byte[]
// tmp is OutputStream
for (int i = 0; i < data.length; i++) {
int b = data[i];
switch (b) {
case 0x55:
case 0xAA:
case 0xBB:
log.info("Found sp=" + Integer.toHexString(b));
tmp.write(0xBB);
@wendal
wendal / DB1x.ino
Created June 21, 2014 11:30
arduino读取温度传感器数据,写入串口
#include <OneWire.h>
#include "DallasTemperature.h"
OneWire oneWire(8);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
}
@wendal
wendal / main.py
Last active August 29, 2015 14:01
快速打印南航的特价票
# -*- coding: UTF-8 -*-
'''
Created on 2014-5-28
快速打印南航的特价票
@author: wendal
'''
import json
@wendal
wendal / ExtDaos.java
Last active August 29, 2015 14:01
演示对Dao接口的封装,解决常见的FieldFilter的匿名内部类困扰
package org.nutz.dao.util;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.nutz.dao.Dao;
import org.nutz.dao.FieldFilter;
import org.nutz.dao.TableName;