Skip to content

Instantly share code, notes, and snippets.

View bindiego's full-sized avatar
🎸
be cool

Bin Wu bindiego

🎸
be cool
View GitHub Profile
@bindiego
bindiego / CoreServlet.java
Last active August 29, 2015 14:15
WeChat request check
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.liufeng.course.service.CoreService;
import org.liufeng.course.util.SignUtil;
@bindiego
bindiego / BaseMessage.java
Created February 12, 2015 07:34
WeChat Messages, User -> Public Service Platform
/**
* 消息基类(普通用户 -> 公众帐号)
*/
public class BaseMessage {
// 开发者微信号
private String ToUserName;
// 发送方帐号(一个OpenID)
private String FromUserName;
// 消息创建时间 (整型)
private long CreateTime;
@bindiego
bindiego / Article.java
Created February 12, 2015 07:38
WeChat Responses, Public Service Platform -> User
/**
* 图文model
*/
public class Article {
// 图文消息名称
private String Title;
// 图文消息描述
private String Description;
// 图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80,限制图片链接的域名需要与开发者填写的基本资料中的Url一致
private String PicUrl;
@bindiego
bindiego / isArray.js
Last active August 29, 2015 14:18
JavaScript Utility
/*
* Array utility
*/
function isArray(myArray) {
return myArray.constructor.toString().indexOf("Array") > -1;
}
@bindiego
bindiego / Code.js
Last active August 29, 2015 14:18
Google spreadsheet import data from mysql
/**
* @OnlyCurrentDoc Limits the script to only accessing the current spreadsheet.
*/
var DIALOG_TITLE = 'Example Dialog';
var SIDEBAR_TITLE = 'Example Sidebar';
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
@bindiego
bindiego / sp.sh
Created April 22, 2015 06:13
run MySQL stored procedure from shell
#/bin/bash -ex
# General settings
PWD=`pwd`
#DATE=`date +%Y-%m-%d:%H:%M:%S`
DATE=`date +%Y-%m-%d_%H%M%S`
# Log file
logfile="${PWD}/${DATE}.log"
@bindiego
bindiego / replace.sh
Created April 30, 2015 08:00
Search String in text files and replace them
#/bin/sh -ex
egrep -lRZ "http://rubygems.org|https://rubygems.org" . \
| xargs -0 -l sed -i -e 's/http:\/\/rubygems.org/http:\/\/ruby.taobao.org/g'
egrep -lRZ "http://rubygems.org|https://rubygems.org" . \
| xargs -0 -l sed -i -e 's/https:\/\/rubygems.org/http:\/\/ruby.taobao.org/g'
@bindiego
bindiego / format_xml.sh
Last active August 29, 2015 14:20
Shell script handling xml files
#!/bin/sh -ex
xmllint --format $@
/**
*
* @param lat1 The y coordinate of the first point, in radians
* @param lon1 The x coordinate of the first point, in radians
* @param lat2 The y coordinate of the second point, in radians
* @param lon2 The x coordinate of the second point, in radians
* @return The distance between the two points, as determined by the Haversine formula, in radians.
*/
public static double distHaversineRAD(double lat1, double lon1, double lat2, double lon2) {
//TODO investigate slightly different formula using asin() and min() http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
@bindiego
bindiego / time.js
Last active August 29, 2015 14:22
Get time by timezone offset.
var tz = 'GMT+10';
console.log(new Date( new Date().getTime() + tz.replace( "GMT", "" ) * 3600 * 1000).toUTCString().replace( / GMT$/, "" ));
// ------------------------------
var offset = +8;
console.log(new Date( new Date().getTime() + offset * 3600 * 1000).toUTCString().replace( / GMT$/, "" ));
console.log(new Date( new Date().getTime() + offset * 3600 * 1000).toUTCString());